From 8463a37e154d14e90d45214b731e4df37288909a Mon Sep 17 00:00:00 2001 From: wang hou sheng <76928547+wanghousheng@users.noreply.github.com> Date: Thu, 18 Apr 2024 00:23:59 +0800 Subject: [PATCH] 1 --- app/api/controller/Goods.php | 2 +- app/api/model/Goods.php | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/app/api/controller/Goods.php b/app/api/controller/Goods.php index a4c7f96f..fb6119c4 100644 --- a/app/api/controller/Goods.php +++ b/app/api/controller/Goods.php @@ -196,7 +196,7 @@ class Goods extends Controller { $param = $this->request->param(); $model = new GoodsModel; - $list = $model->presaleGoodss($param); + $list = $model->presaleGoods($param); return $this->renderSuccess(compact('list')); } diff --git a/app/api/model/Goods.php b/app/api/model/Goods.php index 8de87f3d..b5cd0d0e 100644 --- a/app/api/model/Goods.php +++ b/app/api/model/Goods.php @@ -24,6 +24,7 @@ use app\common\model\Goods as GoodsModel; use app\common\model\GoodsCategoryRel as GoodsCategoryRelModel; use app\common\model\GoodsImage as GoodsImageModel; use app\common\model\UploadFile as UploadFileModel; +use app\store\model\GoodsCategoryRel; use cores\exception\BaseException; use think\db\exception\DataNotFoundException; use think\db\exception\DbException; @@ -238,23 +239,25 @@ class Goods extends GoodsModel * @throws ModelNotFoundException * @author: wanghousheng */ - public function presaleGoodss(array $param): array + public function presaleGoods(array $param): array { $list = []; $cate_goods_id = []; - if (!empty($param['category_id'])) { - $cate_model = new \app\store\model\GoodsCategoryRel(); - $cate_goods_id = $cate_model - ->where(['category_id' => $param['category_id']]) - ->column('goods_id'); - } + $model = new PreSale(); $info = $model->where(['is_change' => 0, 'status' => 1])->field('goods_list,p_time')->find(); if (!$info->isEmpty()) { $info = $info->toArray(); $goods_ids = explode(',', $info['goods_list']); + if (!empty($param['category_id'])) { + $cate_model = new GoodsCategoryRel(); + $cate_goods_id = $cate_model + ->where(['category_id' => $param['category_id']]) + ->whereIn('goods_id', $goods_ids) + ->column('distinct goods_id'); + } if ($cate_goods_id) { - $goods_ids = array_unique(array_values(array_intersect($cate_goods_id, $goods_ids))); + $goods_ids = $cate_goods_id; } $result = $this->getListByIds($goods_ids); if (!$result->isEmpty()) { @@ -633,7 +636,7 @@ class Goods extends GoodsModel return; } - $catService = new \app\store\model\GoodsCategoryRel(); + $catService = new GoodsCategoryRel(); $catIds = $catService->where(['goods_id' => $goods->goods_id])->column('category_id'); $goods['line_price_min'] = $goods['goods_price_min'];//划线价格等于市场价 $goods['discount'] = 0.0;