From a6407048b753892ecca396434dc164a9dfee0700 Mon Sep 17 00:00:00 2001 From: wangxiaowei Date: Mon, 16 Dec 2024 14:20:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=93=81=E6=90=9C=E7=B4=A2=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=95=86=E5=93=81=E5=88=86=E7=B1=BB=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/logic/GoodsLogic.php | 42 +++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/app/api/logic/GoodsLogic.php b/app/api/logic/GoodsLogic.php index 4eab5e20..c0fd1fe0 100755 --- a/app/api/logic/GoodsLogic.php +++ b/app/api/logic/GoodsLogic.php @@ -907,6 +907,20 @@ class GoodsLogic extends Logic return []; } + SearchRecord::create([ + 'user_id'=>$user_id, + 'keyword'=>$shop_name, + 'count' => 1, + 'update_time' => time(), + 'del' => 0 + ]); + + $category = GoodsCategory::where(['is_show' => 1, 'del' => 0]) + ->where([['name', 'like', '%' . trim($shop_name) . '%']]) + ->field('id') + ->select() + ->toArray(); + $onSaleWhere = [ 'del' => GoodsEnum::DEL_NORMAL, // 未删除 'status' => GoodsEnum::STATUS_SHELVES, // 上架中 @@ -921,19 +935,23 @@ class GoodsLogic extends Logic $where[] = ['name', 'like', '%' . trim($shop_name) . '%']; - SearchRecord::create([ - 'user_id'=>$user_id, - 'keyword'=>$shop_name, - 'count' => 1, - 'update_time' => time(), - 'del' => 0 - ]); + if (empty($category)) { + $goods = Goods::field('id, name') + ->where($onSaleWhere) + ->where($where) + ->order('sort_weight asc, sort asc, id desc') + ->select()->toArray(); + + } else { + foreach ($category as &$v) { + $goods = Goods::where([['first_cate_id|second_cate_id|third_cate_id', 'like', '%' . $v['id'] . '%']]) + ->where($onSaleWhere) + ->order('sort_weight asc, sort asc, id desc') + ->select() + ->toArray(); + } + } - $goods = Goods::field('id, name') - ->where($onSaleWhere) - ->where($where) - ->order('sort_weight asc, sort asc, id desc') - ->select()->toArray(); if ($goods) { return $goods; }