From fad622eead03129e518d53c605ea9ddc829dd3c8 Mon Sep 17 00:00:00 2001 From: lqmac Date: Tue, 21 May 2024 18:29:58 +0800 Subject: [PATCH] q --- app/api/controller/Controller.php | 3 +++ app/api/controller/Goods.php | 5 ++++ app/common/model/Goods.php | 38 +++++++++++++++++++++++++------ app/store/controller/Goods.php | 8 +++---- 4 files changed, 43 insertions(+), 11 deletions(-) diff --git a/app/api/controller/Controller.php b/app/api/controller/Controller.php index 67127e6a..828292ed 100644 --- a/app/api/controller/Controller.php +++ b/app/api/controller/Controller.php @@ -32,6 +32,8 @@ class Controller extends BaseController // 当前商城ID protected int $storeId; + protected $storeInfo; + /** * API基类初始化 * @throws BaseException @@ -82,6 +84,7 @@ class Controller extends BaseController if ($store['is_recycle'] || $store['is_delete']) { throwError('很抱歉,当前商城已删除'); } + $this->storeInfo = $store; } /** diff --git a/app/api/controller/Goods.php b/app/api/controller/Goods.php index cd7e6057..d94d3570 100644 --- a/app/api/controller/Goods.php +++ b/app/api/controller/Goods.php @@ -39,9 +39,14 @@ class Goods extends Controller */ public function list(): Json { + // 获取列表数据 $model = new GoodsModel; $param = $this->request->param(); + //限制过滤条件-渠道 + $param['channels'] = $this->storeInfo['open_channel'] ? array_merge(['zy'], explode(",", $this->storeInfo['open_channel'])) : []; + //分类利润-利润率 + $param['fliter_condition'] = $this->storeInfo['fliter_condition']; $list = $model->getList($param); return $this->renderSuccess(compact('list')); } diff --git a/app/common/model/Goods.php b/app/common/model/Goods.php index 271ca05d..880bbc3b 100644 --- a/app/common/model/Goods.php +++ b/app/common/model/Goods.php @@ -329,13 +329,36 @@ class Goods extends BaseModel $query = $query->whereRaw('goods_name like ? or goods_no like ?', ["%{$val}%", "%{$val}%"]); } } - // 执行查询 - $list = $query->with(['images.file']) - ->alias($this->name) - ->field($field) - ->where('is_delete', '=', 0) - ->order($sort) - ->paginate($listRows); + if (isset($param['fliter_condition']) && $param['fliter_condition']) { + $fliter_condition = json_decode($param['fliter_condition'], true); + + $str = ""; + foreach ($fliter_condition as $value) { + $strConditon = "("; + $strConditon .= "goods_category_rel.category_id in (".implode(",", $value['category']).")"; + $strConditon .= " and goods.profit >= ".$value['profit']; + $strConditon .= " and goods.profit_rate >= ".$value['profit_rate'] . ") or "; + $str .= $strConditon; + } + $str = trim($str, "or "); + // 执行查询 + $list = $query->with(['images.file']) + ->alias($this->name) + ->field($field) + ->where('is_delete', '=', 0) + ->where($str) + ->order($sort) + ->paginate($listRows); + } else { + // 执行查询 + $list = $query->with(['images.file']) + ->alias($this->name) + ->field($field) + ->where('is_delete', '=', 0) + ->order($sort) + ->paginate($listRows); + } + // 整理列表数据并返回 return $this->setGoodsListData($list); @@ -526,6 +549,7 @@ class Goods extends BaseModel if (isset($param['is_has_detail']) && $param['is_has_detail'] !== '') { $filter[] = ['goods.is_has_detail', '=', $params['is_has_detail']]; } + // 实例化新查询对象 return $query->where($filter); } diff --git a/app/store/controller/Goods.php b/app/store/controller/Goods.php index aa9e368f..03d3c89c 100644 --- a/app/store/controller/Goods.php +++ b/app/store/controller/Goods.php @@ -158,10 +158,10 @@ class Goods extends Controller $params['goods_no'] = $model->goods_no; } - echo "
";
-        print_r($params);
-        print_r($model->toArray());
-        exit();
+        // echo "
";
+        // print_r($params);
+        // print_r($model->toArray());
+        // exit();
         // 更新记录
         if ($model->edit($params)) {
             return $this->renderSuccess('更新成功');