From 64a2efeca8ff321077b5713f7b2e6cf6f456d7d3 Mon Sep 17 00:00:00 2001 From: "wangmingchuan321@qq.com" Date: Mon, 5 Feb 2024 11:33:13 +0800 Subject: [PATCH] 111 --- app/api/model/Goods.php | 18 +++++++++++++++++- app/common/model/Goods.php | 2 -- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/api/model/Goods.php b/app/api/model/Goods.php index 0a04f6bd..013dfc69 100644 --- a/app/api/model/Goods.php +++ b/app/api/model/Goods.php @@ -21,6 +21,8 @@ use app\api\model\store\Module as StoreModuleModel; use app\common\model\GoodsCategoryRel as GoodsCategoryRelModel; use app\api\model\GoodsSpecRel as GoodsSpecRelModel; use app\common\model\Goods as GoodsModel; +use app\common\model\GoodsImage as GoodsImageModel; +use app\common\model\UploadFile as UploadFileModel; use app\common\enum\goods\Status as GoodsStatusEnum; use cores\exception\BaseException; use think\db\exception\DataNotFoundException; @@ -209,12 +211,26 @@ class Goods extends GoodsModel $goods = explode(',', $info->goods_list); $list = goods::alias('a') - ->join('goods_category_rel b', 'a.goods_id = b.goods_id')->where([ + ->join('goods_category_rel b', 'a.goods_id = b.goods_id') + ->where([ 'a.store_id' => request()->header()['storeid'], 'a.status' => 10, 'b.category_id' => $_GET['category_id'] ])->whereIn('a.goods_id', $goods)->field('a.goods_id,a.goods_name,a.goods_price_min,b.category_id,a.sales_initial,a.sales_actual')->select()->toArray(); + //暂时 要优化 + foreach ($list as &$v) { + $file_id = GoodsImageModel::where([ + 'store_id' => request()->header()['storeid'], + 'goods_id' => $v['goods_id'], + ])->field('image_id')->find()->image_id; + + $file_path = UploadFileModel::where([ + 'store_id' => request()->header()['storeid'], + 'file_id' => $file_id, + ])->field('file_path')->find()->file_path; + $v['image'] = $_SERVER['HTTP_HOST'] . '/uploads/' . $file_path; + } return $list; } return []; diff --git a/app/common/model/Goods.php b/app/common/model/Goods.php index 5afd7112..f5dadeef 100644 --- a/app/common/model/Goods.php +++ b/app/common/model/Goods.php @@ -178,7 +178,6 @@ class Goods extends BaseModel public function getList(array $param = [], int $listRows = 15) { // 筛选条件 - $query = $this->getQueryFilter($param); // 设置显示的销量 goods_sales $query->field(['(sales_initial + sales_actual) as goods_sales', '(line_price_max - goods_price_min) as discount']); @@ -321,7 +320,6 @@ class Goods extends BaseModel $query->order('paihang asc'); } - // 实例化新查询对象 return $query->where($filter); }