wanghousheng 8 months ago
parent 2629917d98
commit 8f5c604529
  1. 19
      app/api/controller/Goods.php
  2. 69
      app/api/service/Goods.php

@ -14,12 +14,12 @@ namespace app\api\controller;
use app\api\model\{Goods as GoodsModel, Store as StoreModel};
use app\api\service\{Goods as GoodsService, User as UserService};
use app\common\model\GoodsImage as GoodsImageModel;
use app\common\model\UploadFile as UploadFileModel;
use app\common\service\qrcode\Goods as GoodsPoster;
use cores\exception\BaseException;
use think\facade\Cache;
use think\response\Json;
use app\common\model\GoodsImage as GoodsImageModel;
use app\common\model\UploadFile as UploadFileModel;
/**
* 商品控制器
* Class Goods
@ -224,8 +224,8 @@ class Goods extends Controller
$service = new GoodsService;
// 获取店铺信息
$storeid = request()->header()['storeid'];
$storeInfo = StoreModel::where("store_id",$storeid)->find();
if(empty($storeInfo)){
$storeInfo = StoreModel::where("store_id", $storeid)->find();
if (empty($storeInfo)) {
return $this->renderError("商铺信息不存在");
}
$goodsList = $service->getCommonConfig($storeInfo);
@ -270,9 +270,8 @@ class Goods extends Controller
public function cityInfo(): Json
{
$service = new GoodsService;
$storeid = request()->header()['storeid'];
$goodsList = $service->cityInfo($storeid);
$storeId = $this->request->storeId();
$goodsList = $service->cityInfo($storeId);
return $this->renderSuccess($goodsList);
}
@ -305,8 +304,4 @@ class Goods extends Controller
}
}

@ -12,25 +12,18 @@ declare (strict_types=1);
namespace app\api\service;
use app\api\model\Category as CategoryModel;
use app\api\model\Goods as GoodsModel;
use app\api\model\Setting as SettingModel;
use app\api\model\GoodsSku as GoodsSkuModel;
use app\api\model\Category as CategoryModel;
use app\api\model\Setting as SettingModel;
use app\api\model\UploadFile;
use app\api\service\User as UserService;
use app\common\enum\Setting as SettingEnum;
use app\common\library\helper;
use app\common\model\Help;
use app\common\model\store\Shop as ShopModel;
use app\common\model\goods\GoodsHotWord;
use app\api\service\sharp\Active as ActiveService;
use app\common\enum\Setting as SettingEnum;
use app\common\model\store\Shop as ShopModel;
use app\common\model\store\shop\Comment;
use app\common\service\Goods as GoodsService;
use app\api\model\sharp\Active as SharpActiveModel;
use app\api\model\sharp\ActiveTime as ActiveTimeModel;
use app\api\controller\sharp\Goods as miaosha;
use app\store\model\goods\GoodsPrice as GoodsPriceModel;
use app\common\model\store\ShopParking as ParkingModel;
/**
* 商品服务类
@ -100,13 +93,14 @@ class Goods extends GoodsService
/**
* 获取(新品首发,大牌正品,新人首单)商铺的url
*/
public function getStoreImgUrl($img_id){
public function getStoreImgUrl($img_id)
{
$data = [];
if(!empty($img_id)){
$img_ids = explode(",",$img_id);
$infos = \app\common\model\UploadFile::where('file_id','in' ,$img_ids)->field('file_path,domain')->select();
if(!empty($infos)){
foreach($infos as $info){
if (!empty($img_id)) {
$img_ids = explode(",", $img_id);
$infos = \app\common\model\UploadFile::where('file_id', 'in', $img_ids)->field('file_path,domain')->select();
if (!empty($infos)) {
foreach ($infos as $info) {
$data[] = getUrl($info['file_path'], $info['domain']);
}
}
@ -255,47 +249,35 @@ class Goods extends GoodsService
return [];
}
$info = $info->toArray();
//todo wmc
$info['remark'] = json_decode($info['remark'],true);
$arr = explode(" ", $info['shop_hours']);
$arr = explode("-", $arr[1] ?? "");
$info['remark'] = json_decode($info['remark'], true);
$info['is_open'] = 0;
$info['service_num_for_me'] = 5;
// if ($arr && count($arr) == 2) {
// $start = explode(":", $arr[0]);
// $end = explode(":", $arr[1]);
// $start_time = ($start[0] ?? 0)
// if ($start[0]) {
// // code...
// }
// $info['is_open'] = 0;
// }
// $info['is_open'] = $arr && $arr[]
// $info['fuwu_hours'] = 5;
// $info['fuwu_num'] = 15;
// $info['wechat'] = 'https://www.saas.njrenzhou.com/uploads/10001/20240127/12bb1b1747e652d258443247a5c4777c.png';
$info['history'] = json_decode($info['history'], true);
$info['evaluate'] = Comment::with('file')
->field(['nickname,content,image_id'])
->hidden(['file'])
->where('is_delete', '=', 0)
->where('shop_id','=', $info['shop_id'])
->where('shop_id', '=', $info['shop_id'])
->select();
$file = UploadFile::whereIn('file_id', explode(',', $info['shop_image_id']))->select();
$info['imageList'] = helper::getArrayColumn($file, 'preview_url');
$info['service_num_for_me'] = 0;
//当前用户门店自提订单数
$userId = UserService::getCurrentLoginUserId(false);
if ($userId) {
$info['service_num_for_me'] = (new \app\api\model\Order())->where(['user_id' => $userId, 'extract_shop_id' => $info['shop_id']])->count();
}
return $info;
}
public function hotWord($page): array
{
if(empty($page) || $page == 1){
if (empty($page) || $page == 1) {
$offset = 0;
}else{
} else {
$offset = $page * 5;
}
return GoodsHotWord::order('sort desc')->limit($offset,5)->select()->toArray();
return GoodsHotWord::order('sort desc')->limit($offset, 5)->select()->toArray();
}
// //抢购会场列表
@ -338,7 +320,8 @@ class Goods extends GoodsService
// return $list;
// }
public static function getGoodsPrice($goods_id, $price, $cost_price){
public static function getGoodsPrice($goods_id, $price, $cost_price)
{
$catService = new \app\store\model\GoodsCategoryRel();
$catIds = $catService->where(['goods_id' => $goods_id])->column('category_id');
if (UserService::isstore()) {
@ -351,6 +334,7 @@ class Goods extends GoodsService
}
return $price;
}
/**
* 格式化商品列表
* @param $goodsList
@ -381,7 +365,7 @@ class Goods extends GoodsService
if (UserService::isstore()) {
$temp['goods_price_min'] = $goods['cost_price_min'];
} elseif (UserService::isPlusMember()) {
$temp['goods_price_min'] = \app\common\model\PriceSet::membershipPrice($goods['goods_price_min'], $goods['cost_price_min'], $catIds);
$temp['goods_price_min'] = \app\common\model\PriceSet::membershipPrice($goods['goods_price_min'], $goods['cost_price_min'], $catIds);
} elseif (UserService::isDealerMember()) {
$priceArr = \app\common\model\PriceSet::distributionPrice($goods['goods_price_min'], $goods['cost_price_min'], $catIds);
$temp['goods_price_min'] = $priceArr['distributionPrice'];
@ -391,6 +375,7 @@ class Goods extends GoodsService
}
return $data;
}
/**
* 格式化商品列表
* @param $goodsList

Loading…
Cancel
Save