from server

This commit is contained in:
root 2023-08-10 10:25:14 +05:00
parent dbaae959a0
commit e9b2c4e809
16 changed files with 244 additions and 13 deletions

View File

@ -138,7 +138,7 @@ class BlogPostsApiController extends Controller
return $this->helpers->apiArrayResponseBuilder(400, 'fail', $validator->errors() );
}
$comment = $this->Comment::where('product_id', $data["product_id"])->where('is_approve', 1)->paginate(15);
$comment = $this->Comment::where('product_id', $data["product_id"])->where('is_approve', 1)->with('user')->paginate(15);
//dd($favourite);
return response()->json($comment, 200);

View File

@ -161,7 +161,7 @@ class MessagesapiController extends Controller
return $this->helpers->apiArrayResponseBuilder(404, 'not found', ['error' => 'Resource id=' . $id . ' could not be found']);
}
$messages = $chatroom::find($id)->messages()->latest('send_at')->skip($skipParam)->limit(5)->get()->reverse();
$messages = $chatroom::find($id)->messages()->latest('send_at')->skip($skipParam)->limit(10)->get();
return $this->helpers->apiArrayResponseBuilder(200, 'success', ['messages' => $messages]);
}
@ -206,7 +206,7 @@ class MessagesapiController extends Controller
\Event::fire('tps.message.received', [User::find($newMsg->reciver_id), $currentUser]);
return $this->helpers->apiArrayResponseBuilder(200, 'ok', ['message' => 'message sent successfully']);
return $this->helpers->apiArrayResponseBuilder(200, 'ok', ['message' => $newMsg]);
}
/**
@ -288,8 +288,8 @@ class MessagesapiController extends Controller
->readAtNull()
->update(['read_at'=>\Carbon\Carbon::now()]);
$messages = $chatroom->messages()->latest('send_at')->limit(5)->get()->reverse();
$messages = $chatroom->messages()->latest('send_at')->limit(10)->get();
return $messages;
}

View File

@ -14,6 +14,7 @@ use October\Rain\Support\Facades\Event;
use TPS\Birzha\Classes\ErrorResponseApi;
use TPS\Birzha\Classes\MeasureResource;
use TPS\Birzha\Classes\ProductResource;
use DB;
class ProductsAPIController extends Controller
{
@ -45,6 +46,9 @@ class ProductsAPIController extends Controller
$is_home = intval(input('is_home'));
$queryString = input('q');
$locale = input('locale');
$seller = input('seller_id');
$categorySeller = input('seller_category_id');
// $query = $this->Product::with('categories:id,name')
$query = Product::with([
@ -53,6 +57,9 @@ class ProductsAPIController extends Controller
'vendor:id,name,email,type,logo,banner,shop_title,slogan,is_instagram',
'place',
])
->withCount(['comments as rating_avg' => function($query) {
$query->select(DB::raw('avg(rating)'));
}])
->approved()
->orderBy('ends_at', $sortOrder);
@ -65,6 +72,9 @@ class ProductsAPIController extends Controller
'translations:locale,model_id,attribute_data',
'images:attachment_id,attachment_type,disk_name,file_name',
])
->withCount(['comments as rating_avg' => function($query) {
$query->select(DB::raw('avg(rating)'));
}])
->approved()
->orderBy('ends_at', $sortOrder);
} else {
@ -80,6 +90,9 @@ class ProductsAPIController extends Controller
'place',
'vendor:id,name,email,type,logo,banner,shop_title,slogan,is_instagram'
])
->withCount(['comments as rating_avg' => function($query) {
$query->select(DB::raw('avg(rating)'));
}])
->where('is_home', 1)
->approved()
->orderBy('ends_at', $sortOrder);
@ -99,6 +112,9 @@ class ProductsAPIController extends Controller
'translations:locale,model_id,attribute_data',
'images:attachment_id,attachment_type,disk_name,file_name',
])
->withCount(['comments as rating_avg' => function($query) {
$query->select(DB::raw('avg(rating)'));
}])
// ->approvedAndFreshEndDate()
->approved()
->orderBy('ends_at', $sortOrder);
@ -113,6 +129,9 @@ class ProductsAPIController extends Controller
'translations:locale,model_id,attribute_data',
'images:attachment_id,attachment_type,disk_name,file_name',
])
->withCount(['comments as rating_avg' => function($query) {
$query->select(DB::raw('avg(rating)'));
}])
->orderBy('ends_at', $sortOrder);
}
@ -136,13 +155,14 @@ class ProductsAPIController extends Controller
'vendor:id,name,surname,email,username,logo,banner',
'files', 'place',
])
->withCount('comments')->withAvg('comments', 'rating')
// ->withCount(['comments as comments_avg_votes' => function($query) {
// $query->select(DB::raw('avg(rating)'));
// }])
//->withCount('comments')->withAvg('comments', 'rating')
->withCount(['comments as rating_avg' => function($query) {
$query->select(DB::raw('avg(rating)'));
}])
->find($id);
$data->main_path = 'http://78.111.88.8:9086' . \Config::get('cms.storage.media.path');
//$data->rating_avg = number_format((float)$data->rating_avg, 1, '.', '');;
if ($data && $data->status == 'approved' /*&& $data->ends_at >= \Carbon\Carbon::now()*/){
return response()->json($data, 200);

View File

@ -63,6 +63,7 @@ class User extends UserBase
'sliders' => ['TPS\Birzha\Models\UserSliders', 'softDelete' => true],
'favourites' => ['TPS\Birzha\Models\Favourites', 'softDelete' => true, 'table' => 'tps_birzha_favourites'],
'comments' => ['TPS\Birzha\Models\Comment','table' => 'tps_birzha_comments'],
'orders' => ['TPS\Birzha\Models\Orders','table' => 'tps_birzha_orders'],
];

View File

@ -109,9 +109,9 @@ tabs:
tab: Gurlushyk
description:
label: Maglumat
size: ''
span: auto
type: textarea
size: huge
type: richeditor
tab: Gurlushyk
categories:
label: Relation

View File

@ -0,0 +1,31 @@
<?php namespace TPS\Birzha\Models;
use Model;
/**
* Model
*/
class OrderItems extends Model
{
use \October\Rain\Database\Traits\Validation;
use \October\Rain\Database\Traits\SoftDelete;
protected $dates = ['deleted_at'];
/**
* @var string The database table used by the model.
*/
public $table = 'tps_birzha_order_items';
public $belongsTo = [
'order' => ['TPS\Birzha\Models\Orders', 'table' => 'tps_birzha_orders'],
];
/**
* @var array Validation rules
*/
public $rules = [
];
}

View File

@ -0,0 +1,35 @@
<?php namespace TPS\Birzha\Models;
use Model;
/**
* Model
*/
class Orders extends Model
{
use \October\Rain\Database\Traits\Validation;
use \October\Rain\Database\Traits\SoftDelete;
protected $dates = ['deleted_at'];
/**
* @var string The database table used by the model.
*/
public $table = 'tps_birzha_orders';
public $belongsTo = [
'user' => ['RainLab\User\Models\User', 'table' => 'users'],
];
public $hasMany = [
'order_items' => ['TPS\Birzha\Models\OrderItems', 'key' => 'order_id', 'softDelete' => true],
];
/**
* @var array Validation rules
*/
public $rules = [
];
}

View File

@ -0,0 +1,16 @@
columns:
id:
label: id
type: number
items:
label: items
type: text
note:
label: note
type: text
created_at:
label: created_at
type: datetime
order_id:
label: order_id
type: number

View File

@ -0,0 +1,19 @@
fields:
note:
label: Note
span: auto
type: textarea
items:
label: Items
span: auto
type: repeater
form:
fields:
product_id:
label: Product
span: auto
type: number
qty:
label: Quantity
span: auto
type: number

View File

@ -0,0 +1,13 @@
columns:
id:
label: id
type: number
created_at:
label: created_at
type: datetime
user_id:
label: user_id
type: number
note:
label: note
type: text

View File

@ -0,0 +1,11 @@
fields:
user:
label: 'User id'
span: auto
nameFrom: name
descriptionFrom: description
type: relation
note:
label: Note
span: auto
type: textarea

View File

@ -0,0 +1,26 @@
<?php namespace TPS\Birzha\Updates;
use Schema;
use October\Rain\Database\Updates\Migration;
class BuilderTableCreateTpsBirzhaOrderItems extends Migration
{
public function up()
{
Schema::create('tps_birzha_order_items', function($table)
{
$table->engine = 'InnoDB';
$table->increments('id')->unsigned();
$table->timestamp('created_at')->nullable();
$table->timestamp('updated_at')->nullable();
$table->timestamp('deleted_at')->nullable();
$table->text('items');
$table->text('note');
});
}
public function down()
{
Schema::dropIfExists('tps_birzha_order_items');
}
}

View File

@ -0,0 +1,26 @@
<?php namespace TPS\Birzha\Updates;
use Schema;
use October\Rain\Database\Updates\Migration;
class BuilderTableCreateTpsBirzhaOrders extends Migration
{
public function up()
{
Schema::create('tps_birzha_orders', function($table)
{
$table->engine = 'InnoDB';
$table->increments('id')->unsigned();
$table->timestamp('created_at')->nullable();
$table->timestamp('updated_at')->nullable();
$table->timestamp('deleted_at')->nullable();
$table->integer('user_id');
$table->text('note');
});
}
public function down()
{
Schema::dropIfExists('tps_birzha_orders');
}
}

View File

@ -0,0 +1,23 @@
<?php namespace TPS\Birzha\Updates;
use Schema;
use October\Rain\Database\Updates\Migration;
class BuilderTableUpdateTpsBirzhaOrderItems extends Migration
{
public function up()
{
Schema::table('tps_birzha_order_items', function($table)
{
$table->integer('order_id');
});
}
public function down()
{
Schema::table('tps_birzha_order_items', function($table)
{
$table->dropColumn('order_id');
});
}
}

View File

@ -395,3 +395,12 @@
1.0.138:
- 'Created table tps_birzha_notifications'
- builder_table_create_tps_birzha_notifications.php
1.0.139:
- 'Created table tps_birzha_orders'
- builder_table_create_tps_birzha_orders.php
1.0.140:
- 'Created table tps_birzha_order_items'
- builder_table_create_tps_birzha_order_items.php
1.0.141:
- 'Updated table tps_birzha_order_items'
- builder_table_update_tps_birzha_order_items.php

View File

@ -8,8 +8,9 @@ Route::group(['prefix' => 'api'], function() {
Route::get('me', function() {
$me = \JWTAuth::parseToken()->authenticate()
->only(['name','surname','email','username','type', 'logo', 'banner', 'shop_title', 'slogan', 'is_instagram']);
->only(['id','name','surname','email','username','type', 'logo', 'banner', 'shop_title', 'slogan', 'is_instagram']);
$user["path"] = 'http://78.111.88.8:9086' . \Config::get('cms.storage.media.path');
return Response::json(compact('me'));
})->middleware('\Tymon\JWTAuth\Middleware\GetUserFromToken');