From 758083780cf1a27e11d4dad5f842f1cba2675b39 Mon Sep 17 00:00:00 2001 From: wang hou sheng <76928547+wanghousheng@users.noreply.github.com> Date: Sat, 20 Apr 2024 22:11:46 +0800 Subject: [PATCH] 1 --- app/api/controller/Goods.php | 7 ++- app/api/model/Store.php | 5 +++ app/api/service/Goods.php | 78 ++++++++++++++++++++++----------- app/common/model/Store.php | 60 +++++++++++++++---------- app/common/model/UploadFile.php | 8 ++++ 5 files changed, 106 insertions(+), 52 deletions(-) diff --git a/app/api/controller/Goods.php b/app/api/controller/Goods.php index fb6119c4..4b15b7c6 100644 --- a/app/api/controller/Goods.php +++ b/app/api/controller/Goods.php @@ -292,13 +292,12 @@ class Goods extends Controller public function getCommonConfig(): Json { $service = new GoodsService; - // 获取店铺信息 - $storeid = request()->header()['storeid']; - $storeInfo = StoreModel::where("store_id", $storeid)->find(); + $storeInfo = StoreModel::info(); if (empty($storeInfo)) { return $this->renderError("商铺信息不存在"); } - $goodsList = $service->getCommonConfig($storeInfo); + $type = intval($this->request->get('type', 1)); + $goodsList = $service->getCommonConfig($storeInfo, $type); return $this->renderSuccess($goodsList); } diff --git a/app/api/model/Store.php b/app/api/model/Store.php index ed700a96..cb65ba5b 100644 --- a/app/api/model/Store.php +++ b/app/api/model/Store.php @@ -52,4 +52,9 @@ class Store extends StoreModel { return static::detail(static::$storeId); } + + public static function info() + { + return self::find(static::$storeId); + } } diff --git a/app/api/service/Goods.php b/app/api/service/Goods.php index 341c0041..1be938a2 100644 --- a/app/api/service/Goods.php +++ b/app/api/service/Goods.php @@ -47,47 +47,75 @@ class Goods extends GoodsService return $detail; } - public function getCommonConfig($storeInfo) + /** + * @notes:获取店铺相关图片信息 + * @param $storeInfo + * @param $type + * @return array + * @author: wanghousheng + */ + public function getCommonConfig($storeInfo, $type): array { - //todo wmc1新品首发背景图 2限时秒杀背景图 3排行榜背景图 4大牌正品是轮播 5预售规则 6 新人首单 - $type = request()->get('type'); + //1新品首发背景图 2限时秒杀背景图 3排行榜背景图 4大牌正品是轮播 5预售规则 6 新人首单 + $data['imgurl'] = []; switch ($type) { case 1: - $data['imgurl'] = $this->getStoreImgUrl($storeInfo['new_product_img_id']); - //$data['imgurl'] = 'https://www.saas.njrenzhou.com/uploads/10001/20240131/bdc5f17f3ff8c53ce0853177bc4f1917.png'; - return $data; + if (!empty($storeInfo['new_product_img_id'])) { + $img_ids = explode(",", $storeInfo['new_product_img_id']); + $img_list = UploadFile::getFileList($img_ids); + if (!empty($img_list)) { + $data['imgurl'] = array_column($img_list->toArray(), 'preview_url'); + } + } break; case 2: - $data['imgurl'] = 'https://www.saas.njrenzhou.com/uploads/10001/20240131/e8e10653875e779bc72dbee65b8072c0.png'; - return $data; + if (!empty($storeInfo['flash_sale_img_id'])) { + $img_ids = explode(",", $storeInfo['flash_sale_img_id']); + $img_list = UploadFile::getFileList($img_ids); + if (!empty($img_list)) { + $data['imgurl'] = array_column($img_list->toArray(), 'preview_url'); + } + } break; case 3: - $data['imgurl'] = 'https://www.saas.njrenzhou.com/uploads/10001/20240131/5c4ec6ffeb23223936295e290dc3d1f9.png'; - return $data; + if (!empty($storeInfo['ranking_img_id'])) { + $img_ids = explode(",", $storeInfo['ranking_img_id']); + $img_list = UploadFile::getFileList($img_ids); + if (!empty($img_list)) { + $data['imgurl'] = array_column($img_list->toArray(), 'preview_url'); + } + } break; case 4: - $data['imgurl'] = $this->getStoreImgUrl($storeInfo['big_brand_img_id']); -// $data['imgurl'] = [ -// 'https://www.saas.njrenzhou.com/uploads/10001/20240131/5c4ec6ffeb23223936295e290dc3d1f9.png', -// ]; - return $data; + if (!empty($storeInfo['big_brand_img_id'])) { + $img_ids = explode(",", $storeInfo['big_brand_img_id']); + $img_list = UploadFile::getFileList($img_ids); + if (!empty($img_list)) { + $data['imgurl'] = array_column($img_list->toArray(), 'preview_url'); + } + } break; case 5: - $data['imgurl'] = [ - 'http://qiniu.shop.royaum.com.cn/10001/20240201/13f2e675794e25176352fc039dfb6dcb.jpg', - ]; - return $data; + if (!empty($storeInfo['presale_img_id'])) { + $img_ids = explode(",", $storeInfo['presale_img_id']); + $img_list = UploadFile::getFileList($img_ids); + if (!empty($img_list)) { + $data['imgurl'] = array_column($img_list->toArray(), 'preview_url'); + } + } break; case 6: - $data['imgurl'] = $this->getStoreImgUrl($storeInfo['new_people_order_img_id']); -// $data['imgurl'] = [ -// 'http://qiniu.shop.royaum.com.cn/10001/20240201/13f2e675794e25176352fc039dfb6dcb.jpg', -// ]; - return $data; + if (!empty($storeInfo['new_people_order_img_id'])) { + $img_ids = explode(",", $storeInfo['new_people_order_img_id']); + $img_list = UploadFile::getFileList($img_ids); + if (!empty($img_list)) { + $data['imgurl'] = array_column($img_list->toArray(), 'preview_url'); + } + } break; } - return []; + return $data; } /** diff --git a/app/common/model/Store.php b/app/common/model/Store.php index dca74c01..2b3d19c2 100644 --- a/app/common/model/Store.php +++ b/app/common/model/Store.php @@ -45,41 +45,55 @@ class Store extends BaseModel public static function detail(int $storeId) { try { - $list = self::withoutGlobalScope() + $list = self::withoutGlobalScope() ->with(['logoImage']) ->where('store_id', '=', $storeId) ->find(); - if($list){ - if($list['new_product_img_id']){ - $new_product_img_id = explode(",",$list['new_product_img_id']); - $file1 = UploadFile::where('file_id','in' ,$new_product_img_id)->select(); - $list['newProductImg'] = $file1 ?: null; - }else{ + if ($list) { + if ($list['new_product_img_id']) { + $img_ids = explode(",", $list['new_product_img_id']); + $files = UploadFile::getFileList($img_ids); + $list['newProductImg'] = $files ?: null; + } else { $list['newProductImg'] = null; } - if($list['big_brand_img_id']){ - $big_brand_img_id = explode(",",$list['big_brand_img_id']); - $file2 = UploadFile::where('file_id','in' ,$big_brand_img_id)->select(); - $list['bigBrandImg'] = $file2 ?: null; - }else{ + if ($list['big_brand_img_id']) { + $img_ids = explode(",", $list['big_brand_img_id']); + $files = UploadFile::getFileList($img_ids); + $list['bigBrandImg'] = $files ?: null; + } else { $list['bigBrandImg'] = null; } - if($list['new_people_order_img_id']){ - $new_people_order_img_id = explode(",",$list['new_people_order_img_id']); - $file3 = UploadFile::where('file_id','in' ,$new_people_order_img_id)->select(); - $list['newPeopleOrderImg'] = $file3 ?: null; - }else{ + if ($list['new_people_order_img_id']) { + $img_ids = explode(",", $list['new_people_order_img_id']); + $files = UploadFile::getFileList($img_ids); + $list['newPeopleOrderImg'] = $files ?: null; + } else { $list['newPeopleOrderImg'] = null; } - if($list['presale_img_id']){ - $presale_img_id = explode(",",$list['presale_img_id']); - $file3 = UploadFile::where('file_id','in' ,$presale_img_id)->select(); - $list['presaleImg'] = $file3 ?: null; - }else{ + if ($list['presale_img_id']) { + $img_ids = explode(",", $list['presale_img_id']); + $files = UploadFile::getFileList($img_ids); + $list['presaleImg'] = $files ?: null; + } else { $list['presaleImg'] = null; } + if ($list['flash_sale_img_id']) { + $img_ids = explode(",", $list['flash_sale_img_id']); + $files = UploadFile::getFileList($img_ids); + $list['flashSaleImg'] = $files ?: null; + } else { + $list['flashSaleImg'] = null; + } + if ($list['ranking_img_id']) { + $img_ids = explode(",", $list['ranking_img_id']); + $files = UploadFile::getFileList($img_ids); + $list['rankingImg'] = $files ?: null; + } else { + $list['rankingImg'] = null; + } } - return $list ?? null; + return $list ?? null; } catch (\Exception $e) { return null; } diff --git a/app/common/model/UploadFile.php b/app/common/model/UploadFile.php index 7a2f1be5..8ece87d7 100644 --- a/app/common/model/UploadFile.php +++ b/app/common/model/UploadFile.php @@ -102,4 +102,12 @@ class UploadFile extends BaseModel ->where('is_delete', '=', 0) ->column('file_id'); } + + public static function getFileList(array $fileIds, int $storeId = null) + { + return (new static)->where('file_id', 'in', $fileIds) + ->where('store_id', '=', $storeId ?: self::$storeId) + ->where('is_delete', '=', 0) + ->select(); + } }