From f40cf08d2dc5f5d77b63e0affaa843a40138f723 Mon Sep 17 00:00:00 2001 From: Shohrat Date: Fri, 2 Feb 2024 14:21:07 +0000 Subject: [PATCH] from server --- .env.save | 36 +++ .../api/BlogPostsApiController.php | 47 ++- .../controllers/api/ProductsApiController.php | 155 ++++++--- plugins/ahmadfatoni/apigenerator/routes.php | 1 + plugins/tps/birzha/components/OfferForm.php | 81 +++++ .../tps/birzha/components/SearchOffers.php | 4 +- plugins/tps/birzha/components/UserOffers.php | 15 +- plugins/tps/birzha/components/VipProducts.php | 4 +- .../components/categoryprofile/default.htm | 8 +- .../birzha/components/myoffers/default.htm | 4 +- .../birzha/components/singleoffer/default.htm | 6 + themes/gurlushyk/meta/menus/top-menu.yaml | 294 +----------------- themes/gurlushyk/pages/addProduct.htm | 23 +- .../gurlushyk/partials/home/vip-section.htm | 2 +- 14 files changed, 326 insertions(+), 354 deletions(-) create mode 100644 .env.save diff --git a/.env.save b/.env.save new file mode 100644 index 0000000..0be94bd --- /dev/null +++ b/.env.save @@ -0,0 +1,36 @@ +APP_DEBUG=true +APP_URL=https://gurlushyk.com.tm +APP_KEY=HkZf470nFMajFnuvwrQqv7fsP8kFLxcz + +DB_CONNECTION=mysql +DB_HOST=127.0.0.1 +DB_PORT=3306 +DB_DATABASE=gurlushyk +DB_USERNAME=root +DB_PASSWORD=bt110226** +REDIS_HOST=127.0.0.1 +REDIS_PASSWORD=null +REDIS_PORT=6379 +DB_USE_CONFIG_FOR_TESTING=false + +CACHE_DRIVER=file + +JWT_TTL=527040 + +SESSION_DRIVER=file + +QUEUE_CONNECTION=sync + +MAIL_DRIVER=smtp +MAIL_HOST=smtp.mailgun.org +MAIL_PORT=587 +MAIL_ENCRYPTION=tls +MAIL_USERNAME=null +MAIL_PASSWORD=null + +ROUTES_CACHE=false +ASSET_CACHE=false +DATABASE_TEMPLATES=false +LINK_POLICY=detect +ENABLE_CSRF=true + diff --git a/plugins/ahmadfatoni/apigenerator/controllers/api/BlogPostsApiController.php b/plugins/ahmadfatoni/apigenerator/controllers/api/BlogPostsApiController.php index 0fb04aa..7eab3f9 100644 --- a/plugins/ahmadfatoni/apigenerator/controllers/api/BlogPostsApiController.php +++ b/plugins/ahmadfatoni/apigenerator/controllers/api/BlogPostsApiController.php @@ -161,7 +161,7 @@ class BlogPostsApiController extends Controller $products->map(function ($product) { $image = new Image($product->images[0]->path); - $product->images[0]->compressed_image = $image->resize(510)->getCachedImagePath(true); + $product->images[0]->compressed_image = $image->resize(280)->getCachedImagePath(true); return $product; //foreach($product->images as $compressImage){ @@ -511,25 +511,56 @@ class BlogPostsApiController extends Controller public function getPlaces(Request $request) { - $data = $request->all(); + $dataq = $request->all(); //$id = $data["primary"] ?? 0; $data = City::with([ 'translations:locale,model_id,attribute_data', ]) - ->where('primary_key', $data["primary"] ?? 0) + ->where('primary_key', $dataq["primary"] ?? 0) ->paginate(100)->toArray(); - // array_unshift($data["data"], array( - // "id" => 0, - // "name" => "Ählisi", - // "order" => 0, - // )); + + //dd($data); + $prim = $dataq["primary"] ?? 0; + if($prim){ + $joined = (string) "0".($prim); + array_unshift($data["data"], array( + "id" => (int) $joined, + "created_at" => "2023-10-09 12:41:41", + "updated_at"=> "2023-10-09 12:41:41", + "deleted_at"=> null, + "name"=> "Ählisi", + "note"=> "", + "order"=> 1, + "primary_key"=> 3, + )); + + } + return response()->json($data, 200); } + + public function getPlacesForAdd(Request $request) + { + $dataq = $request->all(); + + //$id = $data["primary"] ?? 0; + + $data = City::with([ + 'translations:locale,model_id,attribute_data', + ]) + ->where('primary_key', $dataq["primary"] ?? 0) + ->paginate(100)->toArray(); + + + return response()->json($data, 200); + } + + public function getSubPlaces($id) { $data = City::where('primary_key', $id)->get()->toArray(); diff --git a/plugins/ahmadfatoni/apigenerator/controllers/api/ProductsApiController.php b/plugins/ahmadfatoni/apigenerator/controllers/api/ProductsApiController.php index ddd6002..ce746fa 100644 --- a/plugins/ahmadfatoni/apigenerator/controllers/api/ProductsApiController.php +++ b/plugins/ahmadfatoni/apigenerator/controllers/api/ProductsApiController.php @@ -57,7 +57,7 @@ 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->images[0]->compressed_image = $image->resize(280)->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; @@ -76,6 +76,13 @@ class ProductsAPIController extends Controller } public function productsBanner(){ + $categoryId = intval(input('category_id')); + $sortPrice = input('price'); + $place = input('place'); + + $currentDate = Carbon::now(); + $currentDateFormat = $currentDate->format('Y-m-d'); + $main_path = 'https://gurlushyk.com.tm' . \Config::get('cms.storage.media.path'); $data = array(); @@ -86,12 +93,12 @@ class ProductsAPIController extends Controller 'vendor:id,name,email,type,logo,banner,shop_title,slogan,is_instagram,web2', 'place', ]) + //->with('categories:id,name') ->withCount(['comments as rating_avg' => function ($query) { $query->select(DB::raw('avg(rating)')); }]) - ->approved() - ->orderBy('id', 'desc') - ->paginate(6); + ->approved(); + //->paginate(6); // Query for user banners $userBanners = DB::table('users') @@ -101,9 +108,101 @@ class ProductsAPIController extends Controller //->orderBy('web3', 'asc') ->orderByRaw('CAST(web3 AS SIGNED) ASC') ->paginate(1); + + if($place) { // fetch offers by the category of the product + if($place == "0".$place){ + + $allCity = City::where('primary_key', $place)->select("id")->get()->pluck('id')->toArray(); + + $products = $products->whereIn("place_id", $allCity)->orderBy('ends_at', 'desc'); + + }else{ + + $products = $products->where('place_id', $place)->orderBy('ends_at', 'desc'); + + } + } + + if($sortPrice) { // fetch offers by the category of the product + $products = $products->orderBy('price', $sortPrice)->orderBy('ends_at', 'desc'); + } + + if($categoryId) { // fetch offers by the category of the product + $category = Category::find($categoryId); + if($category) { + + $products = $category->products() + ->with('categories:id,name') + ->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(); + + if($place) { // fetch offers by the category of the product + $mainCity = City::where('id', $place)->first(); + //dd($mainCity->id); + if($place == (string) "0".$mainCity->id){ + + $allCity = City::where('primary_key', $place)->select("id")->get()->pluck('id')->toArray(); + + $products = $products->whereIn("place_id", $allCity)->orderBy('ends_at', 'desc'); + + }else{ + + $products = $products->whereIn('place_id', $place)->orderBy('ends_at', 'desc'); + + } + } + + if($sortPrice){ + + $products = $products->orderBy('price', $sortPrice)->orderBy('ends_at', 'desc'); + } + + + } else { + $query = null; + } + } + + $products = $products ? $products->orderBy('created_at', "DESC")->orderBy('id', "DESC")->paginate(6) : null; - - $mergedData = collect($products->items())->merge($userBanners->items()); + $contents = []; + + $products->map(function ($productq) use($main_path, $currentDate) { + + $productq->content_type = 'product'; + $image = new Image($productq->images[0]->path); + $productq->images[0]->compressed_image = $productq->images[0]->extension == 'heic' ? $productq->images[0]->path : $image->resize(150)->getCachedImagePath(true); + $productq->is_vip = $productq->type == 'vip' ? (bool) true : (bool) false; + $productq->calc_vip_day = $productq->type == 'vip' ? $currentDate->diffInDays($productq->vip_ends_at) : 'not_vip'; + $productq->type = $productq->calc_vip_day == 0 ? '' : $productq->type; + $productq->type_title = $productq->calc_vip_day == 0 ? '' : $productq->type_title; + + return $productq; + }); + + + $userBanners->map(function ($banner) use($main_path) { + + $banner->content_type = 'banner'; + $image = new Image($main_path.$banner->banner); + $banner->banner = $image->resize(360)->getCachedImagePath(true); + + return $banner; + + }); + + $products_collected = [["type" => "product", "contents" => $products->items()]]; + $banner_collected = [["type" => "banner", "contents" => $userBanners->items()]]; + + $mergedData = collect($products_collected)->merge($banner_collected); $paginator = new LengthAwarePaginator( $mergedData, @@ -115,33 +214,11 @@ class ProductsAPIController extends Controller '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); @@ -202,7 +279,7 @@ class ProductsAPIController extends Controller if($place) { // fetch offers by the category of the product - if($place == (0).$place){ + if($place == "0".$place){ $allCity = City::where('primary_key', $place)->select("id")->get()->pluck('id')->toArray(); @@ -297,7 +374,7 @@ class ProductsAPIController extends Controller if($place) { // fetch offers by the category of the product - if($place == (0).$place){ + if($place == "0".$place){ $allCity = City::where('primary_key', $place)->select("id")->get()->pluck('id')->toArray(); @@ -388,7 +465,7 @@ class ProductsAPIController extends Controller $data->map(function ($product) use($currentDate) { $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->images[0]->compressed_image = $product->images[0]->extension == 'heic' ? $product->images[0]->path : $image->resize(280)->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; @@ -404,6 +481,9 @@ class ProductsAPIController extends Controller public function show($id){ + $currentDate = Carbon::now(); + $currentDateFormat = $currentDate->format('Y-m-d'); + $product = Product::find($id); $product->number_of_views++; @@ -412,7 +492,7 @@ class ProductsAPIController extends Controller $data = $this->Product::with([ 'translations:locale,model_id,attribute_data', 'images:id,attachment_id,attachment_type,disk_name,file_name', - 'vendor:id,name,surname,email,username,logo,banner,type,web2', + 'vendor:id,name,email,type,logo,banner,shop_title,slogan,is_instagram,web2', 'files', 'place', 'categories:id,name,slug,primary_key,icon' ]) //->withCount('comments')->withAvg('comments', 'rating') @@ -422,6 +502,11 @@ class ProductsAPIController extends Controller ->find($id); $data->main_path = 'https://gurlushyk.com.tm' . \Config::get('cms.storage.media.path'); + + $data->is_vip = $data->type == 'vip' ? (bool) true : (bool) false; + $data->calc_vip_day = $data->type == 'vip' ? $currentDate->diffInDays($data->vip_ends_at) : 'not_vip'; + $data->type = $data->calc_vip_day == 0 ? '' : $data->type; + $data->type_title = $data->calc_vip_day == 0 ? '' : $data->type_title; //$data->rating_avg = number_format((float)$data->rating_avg, 1, '.', '');; if ($data && $data->status == 'approved' /*&& $data->ends_at >= \Carbon\Carbon::now()*/){ diff --git a/plugins/ahmadfatoni/apigenerator/routes.php b/plugins/ahmadfatoni/apigenerator/routes.php index 0a01298..a613c9b 100644 --- a/plugins/ahmadfatoni/apigenerator/routes.php +++ b/plugins/ahmadfatoni/apigenerator/routes.php @@ -44,6 +44,7 @@ Route::group(['prefix' =>'api/v1','namespace' =>'AhmadFatoni\ApiGenerator\Contro Route::get('sliders', 'BlogPostsApiController@getSliders'); Route::get('places', 'BlogPostsApiController@getPlaces'); + Route::get('places/for/add', 'BlogPostsApiController@getPlacesForAdd'); Route::get('places/{id}/subs', ['as' => 'place.subs', 'uses' => 'BlogPostsApiController@getSubPlaces']); Route::get('accounts', 'BlogPostsApiController@getAccounts'); diff --git a/plugins/tps/birzha/components/OfferForm.php b/plugins/tps/birzha/components/OfferForm.php index e8e4845..605e8d9 100644 --- a/plugins/tps/birzha/components/OfferForm.php +++ b/plugins/tps/birzha/components/OfferForm.php @@ -28,6 +28,7 @@ class OfferForm extends ComponentBase */ public $categories; public $subcategories; + public $vipRemainingDay; /** * @var string A collection of countries in dropdown @@ -453,6 +454,81 @@ class OfferForm extends ComponentBase } } + + public function onUpdateEndsAt(){ + $id = Input::get('id'); + $product = Product::find($id); + + $currentDate = Carbon::now()->timezone('UTC +05:00'); + $currentDateFormat = $currentDate->format('Y-m-d'); + + $user = \Auth::user(); + + + if($product->vendor_id != $user->id) { + Flash::error(trans('Product not found')); + } + + + try { + + if($product){ + $product->created_at = $currentDateFormat; + $product->save(); + } + + } catch(\Throwable $e) { + Flash::error(trans('Server error')); + } + + Flash::success(trans('Updated successfully')); + } + + public function onUpdateStatus(){ + $id = Input::get('id'); + $product = Product::find($id); + + $user = \Auth::user(); + + if($product->vendor_id != $user->id) { + Flash::error(trans('Product not found')); + } + + if($product){ + if($product->status == "disabled"){ + $product->status = "new"; + $product->save(); + }else{ + $product->status = "disabled"; + $product->save(); + } + }else{ + Flash::error(trans('Product not found')); + } + + Flash::success(trans('Updated successfully')); + } + + public function onMakeVIP(){ + $id = Input::get('id'); + $product = Product::find($id); + + $user = \Auth::user(); + + if($product->vendor_id != $user->id) { + Flash::error(trans('Product not found')); + } + + if($product){ + $product->type = "vip"; + $product->save(); + }else{ + Flash::error(trans('Product not found')); + } + + Flash::success(trans('Updated successfully')); + + } // after deleting a photo go the second form_step @@ -507,15 +583,20 @@ class OfferForm extends ComponentBase } public function onRun() { + $currentDate = Carbon::now(); + $this->categories = Category::where('status',1)->where('primary_key', 0)->get(); $this->subcategories = Category::where('primary_key','>', 0)->get(); $this->states = City::where('primary_key','=', 0)->get(); $this->cities = City::where('primary_key','>', 0)->get(); $this->productIdOption = $this->property('productId'); + $this->vipRemainingDay = 0; + if($this->productIdOption) { $this->productForEditing = Product::where("vendor_id", \Auth::user()->id)->with('categories')->where("id", $this->productIdOption)->first(); + $this->vipRemainingDay = $currentDate->diffInDays($this->productForEditing->vip_ends_at); if(!$this->productForEditing){ return \Redirect::to('/'); } diff --git a/plugins/tps/birzha/components/SearchOffers.php b/plugins/tps/birzha/components/SearchOffers.php index 6a8f4fa..2330abf 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()->approved(); + $products = Product::query(); $title = \Input::get('name'); if (isset($sort) && $sort != '') { @@ -72,7 +72,7 @@ class SearchOffers extends ComponentBase $products = $products->where('keyword', 'like', '%'.$title.'%')->withCount("images"); } - $products = $products->with("vendor")->paginate($perPage); + $products = $products->where('status', 'approved')->with("vendor")->paginate($perPage); return $products; } diff --git a/plugins/tps/birzha/components/UserOffers.php b/plugins/tps/birzha/components/UserOffers.php index 726c868..51ebf1f 100644 --- a/plugins/tps/birzha/components/UserOffers.php +++ b/plugins/tps/birzha/components/UserOffers.php @@ -103,24 +103,22 @@ class UserOffers extends ComponentBase if($categorySlug){ $category = Category::where('slug', $categorySlug)->first(); } - $products = Product::query()->approved(); + $products = Product::query(); if($category){ if (isset($sort) && $sort != '') { $sort = self::getSort($sort); - $products = $category->products()->where('vendor_id', $vendor_id)->withCount("images")->orderBy( $sort[0], $sort[1]); + $products = $category->products()->where('status', 'approved')->where('vendor_id', $vendor_id)->withCount("images")->orderBy( $sort[0], $sort[1]); }else{ - $products = $category->products()->where('vendor_id', $vendor_id)->withCount("images"); + $products = $category->products()->where('status', 'approved')->where('vendor_id', $vendor_id)->withCount("images"); } }else{ if (isset($sort) && $sort != '') { $sort = self::getSort($sort); - $products = $products->where("vendor_id", $vendor_id)->withCount("images")->orderBy( $sort[0], $sort[1]); + $products = $products->where("vendor_id", $vendor_id)->where('status', 'approved')->withCount("images")->orderBy( $sort[0], $sort[1]); }else{ - - $products = $products->where("vendor_id", $vendor_id)->withCount("images")->orderBy( "id", "DESC"); - + $products = $products->where("vendor_id", $vendor_id)->where('status', 'approved')->withCount("images")->orderBy( "id", "DESC"); } } $products = $products->paginate($perPage); @@ -130,13 +128,10 @@ class UserOffers extends ComponentBase private static function getSort($sort): array { - // dd($sort); $sort_key = trim($sort, '-'); - if (str_contains($sort, '-') && strpos($sort, '-') == 0) { $sort_direction = 'desc'; } - return [ $sort_key, $sort_direction ?? 'asc' diff --git a/plugins/tps/birzha/components/VipProducts.php b/plugins/tps/birzha/components/VipProducts.php index 7afedee..9234ee3 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()->approved(); + $products = Product::query(); if (isset($cSlug) && $cSlug != '') { $category = Category::transWhere('slug', $cSlug, Session::get('rainlab.translate.locale'))->first(); @@ -159,7 +159,7 @@ class VipProducts extends ComponentBase $products = $products->orderBy( $sort[0], $sort[1]); } - $products = $products->where("type", $type)->with('vendor')->withCount("images"); + $products = $products->where("type", $type)->where('status', 'approved')->with('vendor')->withCount("images"); return $products ? $products->paginate($perPage) : null; } diff --git a/plugins/tps/birzha/components/categoryprofile/default.htm b/plugins/tps/birzha/components/categoryprofile/default.htm index af505a1..cd03da5 100644 --- a/plugins/tps/birzha/components/categoryprofile/default.htm +++ b/plugins/tps/birzha/components/categoryprofile/default.htm @@ -275,7 +275,7 @@ {% for subcategory in category.subs %} {% if subcategory.subs.count() > 0 %} {% for subsubcategory in subcategory.subs %} - {% for product in subsubcategory.products %} + {% for product in subsubcategory.products.where('status', 'approved') %}
@@ -342,7 +342,7 @@ {% else %} - {% for product in subcategory.products %} + {% for product in subcategory.products.where('status', 'approved') %}
@@ -415,7 +415,7 @@ {% for subcategory in category.subs %} {% if subcategory.subs.count() > 0 %} {% for subsubcategory in subcategory.subs %} - {% for product in subsubcategory.products %} + {% for product in subsubcategory.products.where('status', 'approved') %}