diff --git a/app/api/controller/Goods.php b/app/api/controller/Goods.php index 961ba51d..9d44a554 100644 --- a/app/api/controller/Goods.php +++ b/app/api/controller/Goods.php @@ -306,7 +306,20 @@ class Goods extends Controller //Cache::set($cache_key, $goodsList, 60*60); return $this->renderSuccess(compact('goodsList')); } - + /** + * 推荐的商品列表 + * @return Json + * @throws \think\db\exception\DataNotFoundException + * @throws DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function recommendedNew(): Json + { + $service = new GoodsService; + + $goodsList = $service->recommendedNew(); + return $this->renderSuccess(compact('goodsList')); + } /** * 商品大牌和新品 * @return Json diff --git a/app/api/service/Goods.php b/app/api/service/Goods.php index 9de7aca7..be61e22d 100644 --- a/app/api/service/Goods.php +++ b/app/api/service/Goods.php @@ -170,7 +170,42 @@ class Goods extends GoodsService } return $this->formatGoodsList($goodsList); } - + /** + * 推荐的商品列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function recommendedNew(): array + { + // 获取商品推荐数据 + $setting = $this->getRecommendedSetting(); + // 获取商品数据 + $model = new GoodsModel; + if ($setting['params']['source'] === 'choice') { + // 数据来源:手动 + // if (empty($setting['params']['goodsIds'])) return []; + // $goodsList = $model->getListByIdsFromApi($setting['params']['goodsIds']); + // 数据来源:自动 + $goodsList = $model->getList([ + 'status' => 10, + 'goodsIds' => implode(",",$setting['params']['goodsIds']), + 'sortType' => "all", + ], 10); + } else { + // 数据来源:自动 + $goodsList = $model->getList([ + 'status' => 10, + 'categoryId' => $setting['params']['auto']['category'], + 'sortType' => $setting['params']['auto']['goodsSort'], + ], 10); + + } + + return $this->formatGoodsList($goodsList); + } + //大牌正品列表 public function brandList(): array { diff --git a/app/common/model/Goods.php b/app/common/model/Goods.php index 10c30cb6..1ab759c5 100644 --- a/app/common/model/Goods.php +++ b/app/common/model/Goods.php @@ -312,6 +312,7 @@ class Goods extends BaseModel $query = $query->whereRaw('goods_name like ? or goods_no like ?', ["%{$val}%", "%{$val}%"]); } } + //数据渠道过滤特殊处理 if (isset($param['fliter_condition']) && $param['fliter_condition']) { $fliter_condition = json_decode($param['fliter_condition'], true); @@ -571,7 +572,6 @@ class Goods extends BaseModel if (isset($param['is_jd_remove']) && $param['is_jd_remove'] !== '') { $filter[] = ['goods.is_jd_remove', '=', $params['is_jd_remove']]; } - // 实例化新查询对象 return $query->where($filter); } diff --git a/app/store/model/Store.php b/app/store/model/Store.php index 32fcc630..92973910 100644 --- a/app/store/model/Store.php +++ b/app/store/model/Store.php @@ -30,7 +30,10 @@ class Store extends StoreModel { // 是否删除图片 !isset($data['logo_image_id']) && $data['logo_image_id'] = 0; - $data['fliter_condition'] = isset($data['fliter_condition']) ? json_encode($data['fliter_condition'], JSON_UNESCAPED_UNICODE) : ""; + if (isset($data['fliter_condition'])) { + $data['fliter_condition'] = json_encode($data['fliter_condition'], JSON_UNESCAPED_UNICODE); + } + return $this->save($data) !== false; } }