From 7bbf063c8cddb09b170a7f56afeaa2cc07ac5fe1 Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Fri, 8 Mar 2024 15:43:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=9A=E5=95=86=E5=93=81?= =?UTF-8?q?=E5=88=86=E7=B1=BB=E6=9F=A5=E8=AF=A2=E6=8E=A5=E5=8F=A3=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=9A=E8=8E=B7=E5=8F=96=E9=85=92=E9=81=93?= =?UTF-8?q?=E9=A6=86=E5=88=97=E8=A1=A8=E6=8E=A5=E5=8F=A3=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=EF=BC=9A=E9=85=92=E9=81=93=E9=A6=86=E5=95=86=E5=93=81?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=95=86=E5=93=81=E5=93=81=E7=89=8C=E7=AD=9B?= =?UTF-8?q?=E9=80=89=E3=80=81=E5=95=86=E5=93=81=E5=88=86=E7=B1=BB=E7=AD=9B?= =?UTF-8?q?=E9=80=89=E3=80=81=E5=95=86=E6=88=B7=E7=AD=9B=E9=80=89=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E9=85=92=E9=81=93=E9=A6=86=E8=B4=AD?= =?UTF-8?q?=E7=89=A9=E8=BD=A6=E6=9C=AA=E5=8C=BA=E5=88=86=E7=94=A8=E6=88=B7?= =?UTF-8?q?=EF=BC=8C=E5=AF=BC=E8=87=B4=E6=89=80=E6=9C=89=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E5=90=8C=E4=B8=80=E4=B8=AA=E8=B4=AD=E7=89=A9?= =?UTF-8?q?=E8=BD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/model/store/StoreCategory.php | 5 ++ .../store/product/ProductRepository.php | 9 ++++ app/controller/api/Wine.php | 52 ++++++++++++++----- .../api/store/product/StoreCategory.php | 40 ++++++++++++++ route/api.php | 3 ++ 5 files changed, 96 insertions(+), 13 deletions(-) diff --git a/app/common/model/store/StoreCategory.php b/app/common/model/store/StoreCategory.php index e9d2201..5416299 100644 --- a/app/common/model/store/StoreCategory.php +++ b/app/common/model/store/StoreCategory.php @@ -93,4 +93,9 @@ class StoreCategory extends BaseModel $query->whereIn('mer_id',$value); } + + public function children(){ + return $this->hasMany(self::class, 'pid', 'store_category_id'); + } + } diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index c197db2..43ed81e 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -2505,6 +2505,15 @@ class ProductRepository extends BaseRepository ->where('Merchant.merchant_type', 1) ->when(isset($search['store_name']) && $search['store_name'] !== '', function ($query) use ($search) { $query->whereLike('Product.store_name', "%{$search['store_name']}%"); + }) + ->when(isset($search['store_category_id']) && $search['store_category_id'] !== '' && $search['store_category_id'] > 0, function ($query) use ($search) { + $query->whereLike('Product.cate_id', $search['store_category_id']); + }) + ->when(isset($search['mer_id']) && $search['mer_id'] !== '' && $search['mer_id'] > 0, function ($query) use ($search) { + $query->whereLike('Product.mer_id', $search['mer_id']); + }) + ->when(isset($search['brand_id']) && $search['brand_id'] !== '', function ($query) use ($search) { + $query->where('Product.brand_id', $search['brand_id']); }); // 查询内容 $field = [ diff --git a/app/controller/api/Wine.php b/app/controller/api/Wine.php index 6ab6a0c..b9c8fad 100644 --- a/app/controller/api/Wine.php +++ b/app/controller/api/Wine.php @@ -5,6 +5,7 @@ namespace app\controller\api; use app\common\repositories\store\order\StoreCartRepository; use app\common\repositories\store\product\ProductRepository; use app\common\repositories\store\product\SupplierProductRepository; +use app\common\repositories\system\merchant\MerchantRepository; use app\services\supplier\SystemSupplierApplyServices; use app\services\supplier\SystemSupplierServices; use crmeb\basic\BaseController; @@ -19,6 +20,26 @@ class Wine extends BaseController{ parent::__construct($app); $this->services = $services; } + /** + * Common: 获取酒道馆列表 + * Author: wu-hui + * Time: 2024/03/08 15:25 + * @return mixed + */ + public function merList(){ + // 商户类别:0=普通商户,1=酒道馆,2=供应商 + $where['merchant_type'] = 1; + $where['mer_state'] = 1; + $where['status'] = 1; + + $list = app()->make(MerchantRepository::class) + ->search($where) + ->field(['mer_id','mer_name','merchant_type']) + ->select() + ->toArray(); + + return app('json')->success($list); + } /** * Common: 获取全部酒道馆商品 * Author: wu-hui @@ -27,20 +48,21 @@ class Wine extends BaseController{ */ public function goodsList(){ // 参数获取 - $search = $this->request->params(['store_name','lat','lng']); + $search = $this->request->params(['store_name','lat','lng','brand_id','store_category_id','mer_id']); [$page, $limit] = $this->getPage(); $data = app()->make(ProductRepository::class)->getWineList($search, $page, $limit); return app('json')->success($data); } /** - * Common: 获取当前商户购物车列表 + * Common: 获取当前用户酒道馆商品购物车列表 * Author: wu-hui - * Time: 2024/03/01 15:06 + * Time: 2024/03/08 15:39 * @return mixed */ public function cartList(){ // 参数获取 + $uid = $this->request->uid(); $list = (array)app()->make(StoreCartRepository::class) ->getSearch([ 'is_pay' => 0, @@ -48,6 +70,7 @@ class Wine extends BaseController{ 'is_new' => 0, 'is_fail' => 0, 'product_type' => 36, + 'uid' => $uid, ]) ->field(['cart_id','product_type','product_id','product_attr_unique','cart_num','is_batch','batch_num']) ->with([ @@ -64,13 +87,14 @@ class Wine extends BaseController{ return app('json')->success($list); } /** - * Common: 获取购物车id列表 + * Common: 获取当前用户酒道馆购物车id列表 * Author: wu-hui - * Time: 2024/03/01 15:39 + * Time: 2024/03/08 15:40 * @return mixed */ public function cartIds(){ // 参数获取 + $uid = $this->request->uid(); $ids = (array)app()->make(StoreCartRepository::class) ->getSearch([ 'is_pay' => 0, @@ -78,18 +102,20 @@ class Wine extends BaseController{ 'is_new' => 0, 'is_fail' => 0, 'product_type' => 36, + 'uid' => $uid, ])->column('cart_id'); return app('json')->success($ids); } /** - * Common: 商户购物车 - 新增购买商品&修改购买商品数量 + * Common: 新增购买商品&修改购买商品数量 * Author: wu-hui - * Time: 2024/03/01 14:24 + * Time: 2024/03/08 15:41 * @return mixed */ public function cartAdd(){ // 参数获取 + $uid = $this->request->uid(); $data = $this->request->params([ 'cart_num', 'product_attr_unique', @@ -111,6 +137,7 @@ class Wine extends BaseController{ 'product_type' => 36, 'product_id' => $data['source_id'], 'product_attr_unique' => $data['product_attr_unique'], + 'uid' => $uid, ])->value('cart_id'); if($cartId > 0){ // 已经存在 修改数量 @@ -122,19 +149,21 @@ class Wine extends BaseController{ }else{ // 不存在 添加信息 $data['mer_id'] = $result['product']['mer_id']; + $data['uid'] = $uid; app()->make(StoreCartRepository::class)->create($data); } return app('json')->success(); } /** - * Common: 商户购物车 - 删除购买商品 + * Common: 删除购买商品 * Author: wu-hui - * Time: 2024/03/01 14:49 + * Time: 2024/03/08 15:42 * @return mixed */ public function cartDel(){ // 参数获取 + $uid = $this->request->uid(); $data = $this->request->params([ 'product_attr_unique', 'product_id', @@ -151,6 +180,7 @@ class Wine extends BaseController{ 'product_type' => 36, 'product_id' => $data['source_id'], 'product_attr_unique' => $data['product_attr_unique'], + 'uid' => $uid, ])->delete(); return app('json')->success(); @@ -158,8 +188,4 @@ class Wine extends BaseController{ - - - - } diff --git a/app/controller/api/store/product/StoreCategory.php b/app/controller/api/store/product/StoreCategory.php index 1e682a0..e499935 100644 --- a/app/controller/api/store/product/StoreCategory.php +++ b/app/controller/api/store/product/StoreCategory.php @@ -57,6 +57,46 @@ class StoreCategory extends BaseController return app('json')->success($this->repository->children($pid)); } + /** + * Common: 获取商品分类 + * Author: wu-hui + * Time: 2024/03/08 11:20 + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function productCate(){ + // 参数获取 + $pid = (int)$this->request->param('pid'); + // 获取分类列表 + $list = $this->repository->getSearch([]) + ->field(['store_category_id','pid','cate_name','level']) + ->where('pid', $pid) + ->where('mer_id', 0) + ->where('is_show', 1) + ->where('type', 0) + ->withCount(['children']) + ->order('sort DESC,store_category_id DESC') + ->select() + ->toArray(); + + $level = $list[0] ? $list[0]['level'] : 0; + if($level == 0){ + $list = array_merge([ + [ + 'store_category_id' => 0, + 'pid' => 0, + 'cate_name' => '全部', + 'level' => $list[0] ? $list[0]['level'] : 0, + 'children_count' => 0 + ] + ],$list); + } + + + return app('json')->success($list); + } public function cateHotRanking() { diff --git a/route/api.php b/route/api.php index 5dfb9b3..1be5ad4 100644 --- a/route/api.php +++ b/route/api.php @@ -426,6 +426,8 @@ Route::group('api/', function () { // 酒道馆商品兑换相关接口 Route::group('wine',function(){ + Route::get('list','merList');// 全部酒道馆 + // 商品相关 Route::get('goods_list','goodsList');// 全部商品 Route::get('cart_list','cartList');// 购物车列表 Route::get('cart_ids','cartIds');// 购物车IDS @@ -490,6 +492,7 @@ Route::group('api/', function () { Route::get('seckill/detail/:id', 'StoreProductSeckill/detail')->middleware(VisitProductMiddleware::class, 1); Route::get('category/lst', 'StoreCategory/lst'); Route::get('category', 'StoreCategory/children'); + Route::get('category/list', 'StoreCategory/productCate');// 获取全部商品分类 Route::get('brand/lst', 'StoreBrand/lst'); Route::get('detail/:id', 'StoreProduct/detail')->middleware(VisitProductMiddleware::class, 0); Route::get('show/:id', 'StoreProduct/show');