wang hou sheng 9 months ago
parent 57a45f1b0a
commit 758083780c
  1. 7
      app/api/controller/Goods.php
  2. 5
      app/api/model/Store.php
  3. 78
      app/api/service/Goods.php
  4. 60
      app/common/model/Store.php
  5. 8
      app/common/model/UploadFile.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);
}

@ -52,4 +52,9 @@ class Store extends StoreModel
{
return static::detail(static::$storeId);
}
public static function info()
{
return self::find(static::$storeId);
}
}

@ -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;
}
/**

@ -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;
}

@ -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();
}
}

Loading…
Cancel
Save