diff --git a/plugins/ahmadfatoni/apigenerator/controllers/api/BlogPostsApiController.php b/plugins/ahmadfatoni/apigenerator/controllers/api/BlogPostsApiController.php index cf7f4c4..0fb04aa 100644 --- a/plugins/ahmadfatoni/apigenerator/controllers/api/BlogPostsApiController.php +++ b/plugins/ahmadfatoni/apigenerator/controllers/api/BlogPostsApiController.php @@ -19,6 +19,7 @@ use TPS\Birzha\Models\Notification; use TPS\Birzha\Models\Comment; use TPS\Birzha\Models\Sections; use TPS\Birzha\Models\Category; +use TPS\Birzha\Models\Version; use RainLab\User\Models\User; use ToughDeveloper\ImageResizer\Classes\Image; @@ -37,6 +38,51 @@ class BlogPostsApiController extends Controller $this->helpers = $helpers; } + public function checkVersion(Request $request){ + + $data = $request->all(); + + $validator = Validator::make($data, [ + 'version' => 'required', + 'device' => 'required' + ]); + + if($validator->fails()) { + return $this->helpers->apiArrayResponseBuilder(400, 'fail', $validator->errors() ); + } + + + $update = false; + $dataq = []; + + $version = Version::orderBy('id', 'DESC')->first(); + + if($version->version == $data["version"]){ + + $update = false; + + $dataq = [ + "current_version" => $version->version, + "need_update" => $update, + "app_url" => null + ]; + + }elseif($version->version != $data["version"]){ + + $update = true; + + $dataq = [ + "current_version" => $version->version, + "need_update" => $update, + "app_url" => ($data["device"] == 'ios' ? $version->ios : $version->android) + ]; + + + } + + return $this->helpers->apiArrayResponseBuilder(200, 'ok', [$dataq]); + + } public function onGetCategorySubs($catId){ @@ -218,6 +264,14 @@ class BlogPostsApiController extends Controller $modified = $dataq->sections[$i]->section_type::where('id', $dataq->sections[$i]->item_id)->select('id', 'name', 'email', 'username', 'shop_title', 'banner', 'is_instagram')->get(); //$modified->makeHidden(['created_at', 'updated_at', 'deleted_at']); + + $modified->map(function ($banner) use($path) { + $image = new Image($path.$banner->banner); + $banner->compressed_image = $image->resize(510)->getCachedImagePath(true); + + return $banner; + }); + $product_section = array( "type"=> "vendor_banner", "contents"=> $modified @@ -226,12 +280,15 @@ class BlogPostsApiController extends Controller }else if ($dataq->sections[$i]->section_type == "TPS\Birzha\Models\Product") { - $modified = $dataq->sections[$i]->section_type::where('type', $dataq->sections[$i]->product_type)->select('id', 'name', 'price', 'description', 'place_id', 'vendor_id', 'number_of_views', 'is_home', 'short_description', 'type')->with("place")->with([ + $modified = $dataq->sections[$i]->section_type::where('type', $dataq->sections[$i]->product_type)->select('id', 'name', 'price', 'description', 'place_id', 'vendor_id', 'number_of_views', 'is_home', 'short_description', 'type', 'type_order')->with("place")->with([ 'translations:locale,model_id,attribute_data', 'images:attachment_id,attachment_type,disk_name,file_name', 'vendor:id,name,email,type,logo,banner,shop_title,slogan,is_instagram,web2', - ])->orderBy('ends_at', 'DESC')->limit(20)->get(); + ])->orderBy('type_order', 'ASC')->limit($data->type_count)->get(); // $modified->makeHidden(['created_at', 'updated_at', 'deleted_at']); + + + $product_section = array( "type"=> "product_section", "header" => $dataq->sections[$i]->header, @@ -541,16 +598,22 @@ class BlogPostsApiController extends Controller ->select('id', 'name', 'email', 'username', 'type', 'logo', 'shop_title', 'slogan', 'work_time', 'short_description', 'description', 'map', 'is_instagram', 'banner') ->with('categories:id,name,slug,icon') ->paginate(99); + + } //$dataSlider["img"] = $path.$dataSlider["img"]; - if($dataAccounts){ - $dataAccounts->each(function ($item, $key) { - $item->logo = 'https://gurlushyk.com.tm'.Config::get('cms.storage.media.path').$item->logo; - $item->banner = 'https://gurlushyk.com.tm'.Config::get('cms.storage.media.path').$item->banner; + $dataAccounts->map(function ($banner) { + + $image = new Image('https://gurlushyk.com.tm'.Config::get('cms.storage.media.path').$banner->banner); + $banner->compressed_image = $image->resize(510)->getCachedImagePath(true); + + $logo = new Image('https://gurlushyk.com.tm'.Config::get('cms.storage.media.path').$banner->logo); + $banner->logo = $logo->resize(510)->getCachedImagePath(true); + + return $banner; }); - } return response()->json($dataAccounts, 200); } diff --git a/plugins/ahmadfatoni/apigenerator/controllers/api/ProductsApiController.php b/plugins/ahmadfatoni/apigenerator/controllers/api/ProductsApiController.php index 70dc179..ddd6002 100644 --- a/plugins/ahmadfatoni/apigenerator/controllers/api/ProductsApiController.php +++ b/plugins/ahmadfatoni/apigenerator/controllers/api/ProductsApiController.php @@ -18,6 +18,8 @@ use TPS\Birzha\Classes\ProductResource; use DB; use Carbon\Carbon; use ToughDeveloper\ImageResizer\Classes\Image; +use RainLab\User\Models\User; +use Illuminate\Pagination\LengthAwarePaginator; class ProductsAPIController extends Controller { @@ -56,16 +58,15 @@ class ProductsAPIController extends Controller $products->map(function ($product) { $image = new Image($product->images[0]->path); $product->images[0]->compressed_image = $image->resize(510)->getCachedImagePath(true); + $product->is_vip = $product->type == 'vip' ? (bool) true : (bool) false; + $product->calc_vip_day = $product->type == 'vip' ? $currentDate->diffInDays($product->vip_ends_at) : 'not_vip'; + $product->type = $product->calc_vip_day == 0 ? '' : $product->type; + $product->type_title = $product->calc_vip_day == 0 ? '' : $product->type_title; return $product; }); - - // foreach($products as $product) { - /// $image = new Image($product->images[0]->path); - // $product->images[0]->path = $image->resize(200,200)->getCachedImagePath(true); - // } - // dd($products[0]->images[0]); + } catch (\Throwable $th) { return $this->helpers->apiArrayResponseBuilder(500, 'server error', ['message' => 'Something went wrong']); @@ -74,8 +75,84 @@ class ProductsAPIController extends Controller return response()->json($products, 200); } + public function productsBanner(){ + $main_path = 'https://gurlushyk.com.tm' . \Config::get('cms.storage.media.path'); + + $data = array(); + // Query for products + $products = Product::with([ + 'translations:locale,model_id,attribute_data', + 'images:attachment_id,attachment_type,disk_name,file_name', + 'vendor:id,name,email,type,logo,banner,shop_title,slogan,is_instagram,web2', + 'place', + ]) + ->withCount(['comments as rating_avg' => function ($query) { + $query->select(DB::raw('avg(rating)')); + }]) + ->approved() + ->orderBy('id', 'desc') + ->paginate(6); + + // Query for user banners + $userBanners = DB::table('users') + ->select('id', 'name', 'email', 'type', 'logo', 'banner', 'shop_title', 'slogan', 'is_instagram', 'web2', 'web3') + ->where('type', '!=', 'simple') + ->where('banner', '!=', '') + //->orderBy('web3', 'asc') + ->orderByRaw('CAST(web3 AS SIGNED) ASC') + ->paginate(1); + + + $mergedData = collect($products->items())->merge($userBanners->items()); + + $paginator = new LengthAwarePaginator( + $mergedData, + $products->total() + $userBanners->total(), + $products->perPage(), + $products->currentPage(), + [ + 'path' => LengthAwarePaginator::resolveCurrentPath(), + 'pageName' => 'page', + ] + ); + + // Return the merged paginator + $paginator->map(function ($product) use($main_path) { + + if($product->banner){ + + $product->content_type = 'banner'; + $image = new Image($main_path.$product->banner); + $product->banner = $image->resize(500)->getCachedImagePath(true); + + }else{ + + $product->content_type = 'product'; + $image = new Image($product->images[0]->path); + $product->images[0]->compressed_image = $product->images[0]->extension == 'heic' ? $product->images[0]->path : $image->resize(300)->getCachedImagePath(true); + $product->is_vip = $product->type == 'vip' ? (bool) true : (bool) false; + $product->calc_vip_day = $product->type == 'vip' ? $currentDate->diffInDays($product->vip_ends_at) : 'not_vip'; + $product->type = $product->calc_vip_day == 0 ? '' : $product->type; + $product->type_title = $product->calc_vip_day == 0 ? '' : $product->type_title; + + } + //dd($product->images[0]->path); + + return $product; + + + }); + + return response()->json($paginator, 200); + + } + public function index(){ + + $currentDate = Carbon::now(); + $currentDateFormat = $currentDate->format('Y-m-d'); + //dd("sdf"); $sortOrderParam = strtolower(input('sort_order')); @@ -116,11 +193,6 @@ class ProductsAPIController extends Controller - - if($type){ - $query = $query->where("type", $type)->orderBy('ends_at', $sortOrder); - } - if($sortPrice) { // fetch offers by the category of the product $query = $query->orderBy('price', $sortPrice)->orderBy('ends_at', $sortOrder); @@ -304,19 +376,26 @@ class ProductsAPIController extends Controller } + + if($type){ + $query->where("type", $type)->orderBy('type_order', 'ASC'); + } + + + $data = $query ? $query->orderBy('created_at', "DESC")->orderBy('id', "DESC")->paginate($perPage) : null; - $data->map(function ($product) { + $data->map(function ($product) use($currentDate) { $image = new Image($product->images[0]->path); - $product->images[0]->compressed_image = $image->resize(310)->getCachedImagePath(true); + $product->images[0]->compressed_image = $product->images[0]->extension == 'heic' ? $product->images[0]->path : $image->resize(300)->getCachedImagePath(true); + $product->is_vip = $product->type == 'vip' ? (bool) true : (bool) false; + $product->calc_vip_day = $product->type == 'vip' ? $currentDate->diffInDays($product->vip_ends_at) : 'not_vip'; + $product->type = $product->calc_vip_day == 0 ? '' : $product->type; + $product->type_title = $product->calc_vip_day == 0 ? '' : $product->type_title; return $product; - //foreach($product->images as $compressImage){ - // $image = new Image($compressImage->path); - // $compressImage->compressed_image = $image->resize([ 'quality' => 50])->getCachedImagePath(true); - //} }); @@ -443,6 +522,8 @@ class ProductsAPIController extends Controller $product->stock = $data['stock']; + $product->keyword = $product->name.', '.$product->slug; + $product->is_file_product = $data['is_file']; if($data['is_file'] == 1){ @@ -843,6 +924,9 @@ class ProductsAPIController extends Controller public function myProducts() { + $currentDate = Carbon::now(); + $currentDateFormat = $currentDate->format('Y-m-d'); + //dd("sdf"); $perPage = intval(input('custom_per_page')); // intval protects from injection @@ -855,10 +939,12 @@ class ProductsAPIController extends Controller ->paginate($perPage); - $products->map(function ($product) { + $products->map(function ($product) use($currentDate) { $image = new Image($product->images[0]->path); $product->images[0]->compressed_image = $image->resize(510)->getCachedImagePath(true); + $product->is_vip = $product->type == 'vip' ? (bool) true : (bool) false; + $product->calc_vip_day = $product->type == 'vip' ? $currentDate->diffInDays($product->vip_ends_at) : 'not_vip'; return $product; diff --git a/plugins/ahmadfatoni/apigenerator/routes.php b/plugins/ahmadfatoni/apigenerator/routes.php index 0ef7eec..0a01298 100644 --- a/plugins/ahmadfatoni/apigenerator/routes.php +++ b/plugins/ahmadfatoni/apigenerator/routes.php @@ -17,10 +17,12 @@ Route::group(['prefix' =>'api/v1','namespace' =>'AhmadFatoni\ApiGenerator\Contro Route::get('products', ['as' => 'products.index', 'uses' => 'ProductsApiController@index']); - + Route::get('products/with/banner', 'ProductsApiController@productsBanner'); Route::get('category/filters', 'CategoriesAPIController@getFilters'); + Route::get('check/version', 'BlogPostsApiController@checkVersion'); + Route::get('home', 'BlogPostsApiController@home'); // Route::get('products', 'ProductsApiController@index'); Route::get('products/{id}', ['as' => 'products.show', 'uses' => 'ProductsApiController@show']); diff --git a/plugins/rainlab/user/models/user/columns.yaml b/plugins/rainlab/user/models/user/columns.yaml index 6b3ca73..8b2be1d 100644 --- a/plugins/rainlab/user/models/user/columns.yaml +++ b/plugins/rainlab/user/models/user/columns.yaml @@ -52,3 +52,8 @@ columns: type: label: Gornushi type: text + banner: + label: Banner + type: text + searchable: true + sortable: true diff --git a/plugins/rainlab/user/models/user/fields.yaml b/plugins/rainlab/user/models/user/fields.yaml index ccc3aca..5450004 100644 --- a/plugins/rainlab/user/models/user/fields.yaml +++ b/plugins/rainlab/user/models/user/fields.yaml @@ -162,6 +162,12 @@ tabs: imageWidth: '200' type: mediafinder tab: Suratlar + web3: + label: 'Banner yzygiderliligi' + span: auto + default: '999' + type: number + tab: Suratlar tiktok: label: TikTok span: auto diff --git a/plugins/tps/birzha/components/OfferForm.php b/plugins/tps/birzha/components/OfferForm.php index 54fbf33..e8e4845 100644 --- a/plugins/tps/birzha/components/OfferForm.php +++ b/plugins/tps/birzha/components/OfferForm.php @@ -141,9 +141,9 @@ class OfferForm extends ComponentBase 'state_id' => 'required', 'stock' => 'required|', 'description' => 'required', - 'new_img' => 'array|required', + 'new_img' => 'array|required|max:10', // 'is_file' => 'required', - 'new_img.*' => 'mimes:jpg,png', + 'new_img.*' => 'image|mimes:jpeg,jpg,png', 'category_id' => [ 'required', 'exists:tps_birzha_categories,id', @@ -261,9 +261,9 @@ class OfferForm extends ComponentBase 'state_id' => 'required', 'stock' => 'required', 'description' => 'required', - 'new_img' => 'array', + 'new_img' => 'array|max:10', // 'is_file' => 'required', - 'new_img.*' => 'mimes:jpg,png', + 'new_img.*' => 'image|mimes:jpeg,jpg,png', 'category_id' => [ 'required', 'exists:tps_birzha_categories,id', diff --git a/plugins/tps/birzha/components/SearchOffers.php b/plugins/tps/birzha/components/SearchOffers.php index a3f5383..6a8f4fa 100644 --- a/plugins/tps/birzha/components/SearchOffers.php +++ b/plugins/tps/birzha/components/SearchOffers.php @@ -62,7 +62,7 @@ class SearchOffers extends ComponentBase protected function loadProducts() { $perPage = $this->property('perPage'); $sort = \Input::get('sort'); - $products = Product::query(); + $products = Product::query()->approved(); $title = \Input::get('name'); if (isset($sort) && $sort != '') { diff --git a/plugins/tps/birzha/components/VipProducts.php b/plugins/tps/birzha/components/VipProducts.php index c2b12b5..7afedee 100644 --- a/plugins/tps/birzha/components/VipProducts.php +++ b/plugins/tps/birzha/components/VipProducts.php @@ -134,7 +134,7 @@ class VipProducts extends ComponentBase $maxPrice = \Input::get('max_price'); $sort = \Input::get('sort'); - $products = Product::query(); + $products = Product::query()->approved(); if (isset($cSlug) && $cSlug != '') { $category = Category::transWhere('slug', $cSlug, Session::get('rainlab.translate.locale'))->first(); diff --git a/plugins/tps/birzha/controllers/Products.php b/plugins/tps/birzha/controllers/Products.php index 8e3652c..1fd5759 100644 --- a/plugins/tps/birzha/controllers/Products.php +++ b/plugins/tps/birzha/controllers/Products.php @@ -39,7 +39,7 @@ class Products extends Controller $smsSender = new SmsSender(); $smsSender->phone = (string)'+993'.$product->vendor->username; - $smsSender->message = strval('Gurluşyk platformasynda, <<'.(string) $product->name.'>> tassyklandy.'); + $smsSender->message = strval((string) $product->name.' tassyklandy.'); $smsSender->save(); if($smsSender){ diff --git a/plugins/tps/birzha/controllers/Version.php b/plugins/tps/birzha/controllers/Version.php new file mode 100644 index 0000000..1d53839 --- /dev/null +++ b/plugins/tps/birzha/controllers/Version.php @@ -0,0 +1,18 @@ + + = e(trans('backend::lang.form.create')) ?> + + diff --git a/plugins/tps/birzha/controllers/version/config_form.yaml b/plugins/tps/birzha/controllers/version/config_form.yaml new file mode 100644 index 0000000..1bff070 --- /dev/null +++ b/plugins/tps/birzha/controllers/version/config_form.yaml @@ -0,0 +1,10 @@ +name: Version +form: $/tps/birzha/models/version/fields.yaml +modelClass: TPS\Birzha\Models\Version +defaultRedirect: tps/birzha/version +create: + redirect: 'tps/birzha/version/update/:id' + redirectClose: tps/birzha/version +update: + redirect: tps/birzha/version + redirectClose: tps/birzha/version diff --git a/plugins/tps/birzha/controllers/version/config_list.yaml b/plugins/tps/birzha/controllers/version/config_list.yaml new file mode 100644 index 0000000..ff2892a --- /dev/null +++ b/plugins/tps/birzha/controllers/version/config_list.yaml @@ -0,0 +1,12 @@ +list: $/tps/birzha/models/version/columns.yaml +modelClass: TPS\Birzha\Models\Version +title: Version +noRecordsMessage: 'backend::lang.list.no_records' +showSetup: true +showCheckboxes: true +recordsPerPage: 20 +toolbar: + buttons: list_toolbar + search: + prompt: 'backend::lang.list.search_prompt' +recordUrl: 'tps/birzha/version/update/:id' diff --git a/plugins/tps/birzha/controllers/version/create.htm b/plugins/tps/birzha/controllers/version/create.htm new file mode 100644 index 0000000..fc0527e --- /dev/null +++ b/plugins/tps/birzha/controllers/version/create.htm @@ -0,0 +1,46 @@ + +
= e(trans('backend::lang.form.return_to_list')) ?>
+ \ No newline at end of file diff --git a/plugins/tps/birzha/controllers/version/index.htm b/plugins/tps/birzha/controllers/version/index.htm new file mode 100644 index 0000000..ea43a36 --- /dev/null +++ b/plugins/tps/birzha/controllers/version/index.htm @@ -0,0 +1 @@ += $this->listRender() ?> diff --git a/plugins/tps/birzha/controllers/version/preview.htm b/plugins/tps/birzha/controllers/version/preview.htm new file mode 100644 index 0000000..a1ceeed --- /dev/null +++ b/plugins/tps/birzha/controllers/version/preview.htm @@ -0,0 +1,22 @@ + ++ + = e(trans('backend::lang.form.return_to_list')) ?> + +
\ No newline at end of file diff --git a/plugins/tps/birzha/controllers/version/update.htm b/plugins/tps/birzha/controllers/version/update.htm new file mode 100644 index 0000000..0f8a154 --- /dev/null +++ b/plugins/tps/birzha/controllers/version/update.htm @@ -0,0 +1,54 @@ + +