wang hou sheng 10 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 public function getCommonConfig(): Json
{ {
$service = new GoodsService; $service = new GoodsService;
// 获取店铺信息 $storeInfo = StoreModel::info();
$storeid = request()->header()['storeid'];
$storeInfo = StoreModel::where("store_id", $storeid)->find();
if (empty($storeInfo)) { if (empty($storeInfo)) {
return $this->renderError("商铺信息不存在"); return $this->renderError("商铺信息不存在");
} }
$goodsList = $service->getCommonConfig($storeInfo); $type = intval($this->request->get('type', 1));
$goodsList = $service->getCommonConfig($storeInfo, $type);
return $this->renderSuccess($goodsList); return $this->renderSuccess($goodsList);
} }

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

@ -47,47 +47,75 @@ class Goods extends GoodsService
return $detail; 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 新人首单 //1新品首发背景图 2限时秒杀背景图 3排行榜背景图 4大牌正品是轮播 5预售规则 6 新人首单
$type = request()->get('type'); $data['imgurl'] = [];
switch ($type) { switch ($type) {
case 1: case 1:
$data['imgurl'] = $this->getStoreImgUrl($storeInfo['new_product_img_id']); if (!empty($storeInfo['new_product_img_id'])) {
//$data['imgurl'] = 'https://www.saas.njrenzhou.com/uploads/10001/20240131/bdc5f17f3ff8c53ce0853177bc4f1917.png'; $img_ids = explode(",", $storeInfo['new_product_img_id']);
return $data; $img_list = UploadFile::getFileList($img_ids);
if (!empty($img_list)) {
$data['imgurl'] = array_column($img_list->toArray(), 'preview_url');
}
}
break; break;
case 2: case 2:
$data['imgurl'] = 'https://www.saas.njrenzhou.com/uploads/10001/20240131/e8e10653875e779bc72dbee65b8072c0.png'; if (!empty($storeInfo['flash_sale_img_id'])) {
return $data; $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; break;
case 3: case 3:
$data['imgurl'] = 'https://www.saas.njrenzhou.com/uploads/10001/20240131/5c4ec6ffeb23223936295e290dc3d1f9.png'; if (!empty($storeInfo['ranking_img_id'])) {
return $data; $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; break;
case 4: case 4:
$data['imgurl'] = $this->getStoreImgUrl($storeInfo['big_brand_img_id']); if (!empty($storeInfo['big_brand_img_id'])) {
// $data['imgurl'] = [ $img_ids = explode(",", $storeInfo['big_brand_img_id']);
// 'https://www.saas.njrenzhou.com/uploads/10001/20240131/5c4ec6ffeb23223936295e290dc3d1f9.png', $img_list = UploadFile::getFileList($img_ids);
// ]; if (!empty($img_list)) {
return $data; $data['imgurl'] = array_column($img_list->toArray(), 'preview_url');
}
}
break; break;
case 5: case 5:
$data['imgurl'] = [ if (!empty($storeInfo['presale_img_id'])) {
'http://qiniu.shop.royaum.com.cn/10001/20240201/13f2e675794e25176352fc039dfb6dcb.jpg', $img_ids = explode(",", $storeInfo['presale_img_id']);
]; $img_list = UploadFile::getFileList($img_ids);
return $data; if (!empty($img_list)) {
$data['imgurl'] = array_column($img_list->toArray(), 'preview_url');
}
}
break; break;
case 6: case 6:
$data['imgurl'] = $this->getStoreImgUrl($storeInfo['new_people_order_img_id']); if (!empty($storeInfo['new_people_order_img_id'])) {
// $data['imgurl'] = [ $img_ids = explode(",", $storeInfo['new_people_order_img_id']);
// 'http://qiniu.shop.royaum.com.cn/10001/20240201/13f2e675794e25176352fc039dfb6dcb.jpg', $img_list = UploadFile::getFileList($img_ids);
// ]; if (!empty($img_list)) {
return $data; $data['imgurl'] = array_column($img_list->toArray(), 'preview_url');
}
}
break; break;
} }
return []; return $data;
} }
/** /**

@ -45,41 +45,55 @@ class Store extends BaseModel
public static function detail(int $storeId) public static function detail(int $storeId)
{ {
try { try {
$list = self::withoutGlobalScope() $list = self::withoutGlobalScope()
->with(['logoImage']) ->with(['logoImage'])
->where('store_id', '=', $storeId) ->where('store_id', '=', $storeId)
->find(); ->find();
if($list){ if ($list) {
if($list['new_product_img_id']){ if ($list['new_product_img_id']) {
$new_product_img_id = explode(",",$list['new_product_img_id']); $img_ids = explode(",", $list['new_product_img_id']);
$file1 = UploadFile::where('file_id','in' ,$new_product_img_id)->select(); $files = UploadFile::getFileList($img_ids);
$list['newProductImg'] = $file1 ?: null; $list['newProductImg'] = $files ?: null;
}else{ } else {
$list['newProductImg'] = null; $list['newProductImg'] = null;
} }
if($list['big_brand_img_id']){ if ($list['big_brand_img_id']) {
$big_brand_img_id = explode(",",$list['big_brand_img_id']); $img_ids = explode(",", $list['big_brand_img_id']);
$file2 = UploadFile::where('file_id','in' ,$big_brand_img_id)->select(); $files = UploadFile::getFileList($img_ids);
$list['bigBrandImg'] = $file2 ?: null; $list['bigBrandImg'] = $files ?: null;
}else{ } else {
$list['bigBrandImg'] = null; $list['bigBrandImg'] = null;
} }
if($list['new_people_order_img_id']){ if ($list['new_people_order_img_id']) {
$new_people_order_img_id = explode(",",$list['new_people_order_img_id']); $img_ids = explode(",", $list['new_people_order_img_id']);
$file3 = UploadFile::where('file_id','in' ,$new_people_order_img_id)->select(); $files = UploadFile::getFileList($img_ids);
$list['newPeopleOrderImg'] = $file3 ?: null; $list['newPeopleOrderImg'] = $files ?: null;
}else{ } else {
$list['newPeopleOrderImg'] = null; $list['newPeopleOrderImg'] = null;
} }
if($list['presale_img_id']){ if ($list['presale_img_id']) {
$presale_img_id = explode(",",$list['presale_img_id']); $img_ids = explode(",", $list['presale_img_id']);
$file3 = UploadFile::where('file_id','in' ,$presale_img_id)->select(); $files = UploadFile::getFileList($img_ids);
$list['presaleImg'] = $file3 ?: null; $list['presaleImg'] = $files ?: null;
}else{ } else {
$list['presaleImg'] = null; $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) { } catch (\Exception $e) {
return null; return null;
} }

@ -102,4 +102,12 @@ class UploadFile extends BaseModel
->where('is_delete', '=', 0) ->where('is_delete', '=', 0)
->column('file_id'); ->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