master
zengyyh 4 months ago
parent b5da0608a1
commit 03fc2e5e3d
  1. 5
      app/api/controller/Goods.php
  2. 80
      app/api/model/Goods.php
  3. 12
      app/api/service/Goods.php
  4. 13
      app/common/model/PriceSet.php
  5. 7
      app/store/controller/Goods.php

@ -576,7 +576,7 @@ class Goods extends Controller
{ {
$id = $this->request->param('id'); $id = $this->request->param('id');
$detail = ModelTipoff::where('id', $id)->find(); $detail = ModelTipoff::where('id', $id)->find();
$goodsList = GoodsModel::whereIn("goods_id", $detail['goods_id'])->field('goods_id,goods_name,goods_price_min,cost_price_min,goods_no,link')->select(); $goodsList = GoodsModel::whereIn("goods_id", $detail['goods_id'])->field('goods_id,store_id,goods_name,goods_price_min,cost_price_min,goods_no,link')->select();
$goods_no = []; $goods_no = [];
$JdModel = new jd(); $JdModel = new jd();
@ -607,13 +607,14 @@ class Goods extends Controller
//会员价 //会员价
$cates = GoodsCategoryRel::where('goods_id', $value['goods_id'])->select()->toArray(); $cates = GoodsCategoryRel::where('goods_id', $value['goods_id'])->select()->toArray();
$value['jd_short_url'] = $jd_url[$value['goods_no']]['link']; $value['jd_short_url'] = $jd_url[$value['goods_no']]['link'];
$value['membership_price'] = $value['goods_price_min'];
if (empty($value['jd_short_url'])) { if (empty($value['jd_short_url'])) {
$value['jd_short_url'] = $jd_url[$value['goods_no']]['copy']; $value['jd_short_url'] = $jd_url[$value['goods_no']]['copy'];
} }
//分类 //分类
if ($cates) { if ($cates) {
//会员价 //会员价
$value['membership_price'] = \app\common\model\PriceSet::membershipPrice($value['goods_price_min'], $value['cost_price_min'], array_column($cates, 'category_id')); $value['membership_price'] = \app\common\model\PriceSet::membershipPrice($value['goods_price_min'], $value['cost_price_min'], array_column($cates, 'category_id'),$value['store_id']);
} }
} }

@ -8,7 +8,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com> // | Author: 萤火科技 <admin@yiovo.com>
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
declare (strict_types=1); declare(strict_types=1);
namespace app\api\model; namespace app\api\model;
@ -167,7 +167,7 @@ class Goods extends GoodsModel
$origin_goods_ids[] = $value['goods']['origin_goods_id'] ?? 0; $origin_goods_ids[] = $value['goods']['origin_goods_id'] ?? 0;
} }
$goods_images = $this->storeUsePlatformGoodsImage($origin_goods_ids); $goods_images = $this->storeUsePlatformGoodsImage($origin_goods_ids);
$data = []; $data = [];
$array = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"]; $array = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
if (!$list->isEmpty()) { if (!$list->isEmpty()) {
@ -318,7 +318,6 @@ class Goods extends GoodsModel
$v['image'] = getUrl($file_path['file_path'], $file_path['domain']); $v['image'] = getUrl($file_path['file_path'], $file_path['domain']);
//$v['end_time'] = strtotime($info->p_time) - time(); //$v['end_time'] = strtotime($info->p_time) - time();
$v['end_time'] = $info->p_time ? strtotime($info->p_time) - time() : 0; $v['end_time'] = $info->p_time ? strtotime($info->p_time) - time() : 0;
} }
return $list; return $list;
} }
@ -400,7 +399,6 @@ class Goods extends GoodsModel
} }
$goodsInfo->goods_images = $goods_images; $goodsInfo->goods_images = $goods_images;
$goodsInfo->goods_image = $res['mainImageList'][0]; $goodsInfo->goods_image = $res['mainImageList'][0];
} }
if ($res['infoImageList']) { if ($res['infoImageList']) {
@ -410,7 +408,6 @@ class Goods extends GoodsModel
} }
$goodsInfo->content = $content; $goodsInfo->content = $content;
} }
} }
break; break;
case 'sn': case 'sn':
@ -420,7 +417,6 @@ class Goods extends GoodsModel
// code... // code...
break; break;
} }
} }
/** /**
@ -457,7 +453,7 @@ class Goods extends GoodsModel
} else { } else {
$goodsInfo['specList'] = GoodsSpecRelModel::getSpecList($goodsInfo['goods_id']); $goodsInfo['specList'] = GoodsSpecRelModel::getSpecList($goodsInfo['goods_id']);
} }
// $GoodsCategoryRelModel = new GoodsCategoryRelModel(); // $GoodsCategoryRelModel = new GoodsCategoryRelModel();
// $category = $GoodsCategoryRelModel // $category = $GoodsCategoryRelModel
@ -478,7 +474,7 @@ class Goods extends GoodsModel
$goodsInfo['merchant'] = null; $goodsInfo['merchant'] = null;
//商户信息 //商户信息
if ($goodsInfo['merchant_id'] && !in_array($goodsInfo['channel'], config('app.not_show_merchant'))) { if ($goodsInfo['merchant_id'] && !in_array($goodsInfo['channel'], config('app.not_show_merchant'))) {
//if ($goodsInfo['merchant_id']) { //if ($goodsInfo['merchant_id']) {
$merchant = \app\common\model\Merchant::detail($goodsInfo['merchant_id'], $goodsInfo->store_id); $merchant = \app\common\model\Merchant::detail($goodsInfo['merchant_id'], $goodsInfo->store_id);
if ($merchant) { if ($merchant) {
if ($merchant['license_img_id']) { if ($merchant['license_img_id']) {
@ -491,13 +487,13 @@ class Goods extends GoodsModel
$merchant['logoImage'] = $files ?: null; $merchant['logoImage'] = $files ?: null;
} }
} }
$goodsInfo['merchant'] = $merchant; $goodsInfo['merchant'] = $merchant;
} else { } else {
$goodsInfo['merchant_id'] = 0; $goodsInfo['merchant_id'] = 0;
} }
//处理苏宁商品,京东价拖的问题 //处理苏宁商品,京东价拖的问题
if (in_array($goodsInfo['channel'], ['sn','sn1']) && $goodsInfo['link_other']) { if (in_array($goodsInfo['channel'], ['sn', 'sn1']) && $goodsInfo['link_other']) {
$goodsInfo['link'] = $goodsInfo['link_other']; $goodsInfo['link'] = $goodsInfo['link_other'];
$goodsInfo['goods_no'] = $goodsInfo['goods_no_other']; $goodsInfo['goods_no'] = $goodsInfo['goods_no_other'];
} }
@ -582,7 +578,7 @@ class Goods extends GoodsModel
$goodsInfo = static::detail($goodsId, $with); $goodsInfo = static::detail($goodsId, $with);
//处理子商户的成本价 //处理子商户的成本价
if ($storeInfo && $storeInfo['p_store_id'] > 0) { if ($storeInfo && $storeInfo['p_store_id'] > 0) {
$goodsInfo->cost_price_min = round($goodsInfo->cost_price_min / (1 - $storeInfo['markup_rate'] * 0.01)); $goodsInfo->cost_price_min = round($goodsInfo->cost_price_min / (1 - $storeInfo['markup_rate'] * 0.01));
} }
//单规格和多规格处理不一致 //单规格和多规格处理不一致
$goodsInfo->skuList = $goodsInfo->skuList1 ? $goodsInfo->skuList1 : $goodsInfo->skuList; $goodsInfo->skuList = $goodsInfo->skuList1 ? $goodsInfo->skuList1 : $goodsInfo->skuList;
@ -593,16 +589,16 @@ class Goods extends GoodsModel
} }
foreach ($goodsInfo->skuList as &$value) { foreach ($goodsInfo->skuList as &$value) {
//处理苏宁商品,京东价拖的问题 //处理苏宁商品,京东价拖的问题
if (in_array($goodsInfo['channel'], ['sn','sn1']) && $goodsInfo['link_other'] && $value->goods_id == $goodsId) { if (in_array($goodsInfo['channel'], ['sn', 'sn1']) && $goodsInfo['link_other'] && $value->goods_id == $goodsId) {
$value->goods_sku_no = $goodsInfo['goods_no_other']; $value->goods_sku_no = $goodsInfo['goods_no_other'];
} }
if ($storeInfo && $storeInfo['p_store_id'] > 0) { if ($storeInfo && $storeInfo['p_store_id'] > 0) {
$value->cost_price = round($value->cost_price / (1 - $storeInfo['markup_rate'] * 0.01)); $value->cost_price = round($value->cost_price / (1 - $storeInfo['markup_rate'] * 0.01));
} }
} }
//使用总后台的商品的图片作为商城商品的图片 //使用总后台的商品的图片作为商城商品的图片
if ($goodsInfo->origin_goods_id && $goodsInfo->store_id > 0) { if ($goodsInfo->origin_goods_id && $goodsInfo->store_id > 0) {
$goods_images = $this->storeUsePlatformGoodsImage([$goodsInfo->origin_goods_id]); $goods_images = $this->storeUsePlatformGoodsImage([$goodsInfo->origin_goods_id]);
@ -617,7 +613,7 @@ class Goods extends GoodsModel
} }
//是否展示看同款按钮 //是否展示看同款按钮
$goodsInfo->is_show_ktk = 1; $goodsInfo->is_show_ktk = 1;
if (in_array($goodsInfo['channel'], ['sn','sn1']) && !$goodsInfo['link_other']) { if (in_array($goodsInfo['channel'], ['sn', 'sn1']) && !$goodsInfo['link_other']) {
$goodsInfo->is_show_ktk = 0; $goodsInfo->is_show_ktk = 0;
} }
// 判断商品是否存在 // 判断商品是否存在
@ -642,11 +638,11 @@ class Goods extends GoodsModel
{ {
// 获取商品列表 // 获取商品列表
$data = $this->getListByIds($goodsIds, GoodsStatusEnum::ON_SALE); $data = $this->getListByIds($goodsIds, GoodsStatusEnum::ON_SALE);
foreach ($data as $key => &$goods) { foreach ($data as $key => &$goods) {
//处理子商户的成本价 //处理子商户的成本价
if ($storeInfo && $storeInfo['p_store_id'] > 0) { if ($storeInfo && $storeInfo['p_store_id'] > 0) {
$goods->cost_price_min = round($goods->cost_price_min / (1 - $storeInfo['markup_rate'] * 0.01)); $goods->cost_price_min = round($goods->cost_price_min / (1 - $storeInfo['markup_rate'] * 0.01));
} }
} }
// 整理列表数据并返回 // 整理列表数据并返回
@ -666,20 +662,20 @@ class Goods extends GoodsModel
$goods['skuInfo'] = GoodsService::getSkuInfo($goods['goods_id'], $goodsSkuId); $goods['skuInfo'] = GoodsService::getSkuInfo($goods['goods_id'], $goodsSkuId);
//处理子商户的成本价 //处理子商户的成本价
if ($storeInfo && $storeInfo['p_store_id'] > 0) { if ($storeInfo && $storeInfo['p_store_id'] > 0) {
$goods->skuInfo->cost_price = round($goods->skuInfo->cost_price / (1 - $storeInfo['markup_rate'] * 0.01)); $goods->skuInfo->cost_price = round($goods->skuInfo->cost_price / (1 - $storeInfo['markup_rate'] * 0.01));
} }
//$enableGradeMoney && (new static)->setGoodsGradeMoney($goodsInfo); //$enableGradeMoney && (new static)->setGoodsGradeMoney($goodsInfo);
// $catService = new GoodsCategoryRel(); // $catService = new GoodsCategoryRel();
// $catIds = $catService->where(['goods_id' => $goods->goods_id])->column('category_id'); // $catIds = $catService->where(['goods_id' => $goods->goods_id])->column('category_id');
$catIds = GoodsCategoryRel::withoutGlobalScope()->where(['goods_id' => $goods->goods_id])->column('category_id'); $catIds = GoodsCategoryRel::withoutGlobalScope()->where(['goods_id' => $goods->goods_id])->column('category_id');
$user = UserService::getCurrentLoginUser();
$currtime = time(); $currtime = time();
if ($goods->getAttr('skuInfo')) { if ($goods->getAttr('skuInfo')) {
if (UserService::isPlusMember()) { if (UserService::isPlusMember()) {
$goods['skuInfo']['goods_price'] = \app\common\model\PriceSet::membershipPrice($goods['skuInfo']['goods_price'], $goods['skuInfo']['cost_price'], $catIds); $goods['skuInfo']['goods_price'] = \app\common\model\PriceSet::membershipPrice($goods['skuInfo']['goods_price'], $goods['skuInfo']['cost_price'], $catIds,$user->store_id);
} elseif (UserService::isDealerMember()) { } elseif (UserService::isDealerMember()) {
$priceArr = \app\common\model\PriceSet::distributionPrice($goods['skuInfo']['goods_price'], $goods['skuInfo']['cost_price'], $catIds); $priceArr = \app\common\model\PriceSet::distributionPrice($goods['skuInfo']['goods_price'], $goods['skuInfo']['cost_price'], $catIds,$user->store_id);
$goods['skuInfo']['goods_price'] = $priceArr['distributionPrice']; $goods['skuInfo']['goods_price'] = $priceArr['distributionPrice'];
} }
//处理店长临时设置的秒杀价 //处理店长临时设置的秒杀价
@ -734,43 +730,44 @@ class Goods extends GoodsModel
$goods['line_price_min'] = $goods['goods_price_min']; $goods['line_price_min'] = $goods['goods_price_min'];
return; return;
} }
$user = UserService::getCurrentLoginUser();
$currtime = time(); $currtime = time();
// $catService = new GoodsCategoryRel(); // $catService = new GoodsCategoryRel();
// $catIds = $catService->where(['goods_id' => $goods->goods_id])->column('category_id'); // $catIds = $catService->where(['goods_id' => $goods->goods_id])->column('category_id');
$catIds = GoodsCategoryRel::withoutGlobalScope()->where(['goods_id' => $goods->goods_id])->column('category_id'); $catIds = GoodsCategoryRel::withoutGlobalScope()->where(['goods_id' => $goods->goods_id])->column('category_id');
$goods['line_price_min'] = $goods['goods_price_min'];//划线价格等于市场价 $goods['line_price_min'] = $goods['goods_price_min']; //划线价格等于市场价
$goods['discount'] = 0.0; $goods['discount'] = 0.0;
//价格判断 //价格判断
if (UserService::isstore()) { if (UserService::isstore()) {
$priceArr = \app\common\model\PriceSet::distributionPrice($goods['goods_price_min'], $goods['cost_price_min'], $catIds); $priceArr = \app\common\model\PriceSet::distributionPrice($goods['goods_price_min'], $goods['cost_price_min'], $catIds, $user->store_id);
$goods_price_min = $goods['goods_price_min']; $goods_price_min = $goods['goods_price_min'];
$goods['goods_price_min_plus'] = $priceArr['membershipPrice']; $goods['goods_price_min_plus'] = $priceArr['membershipPrice'];
$goods['goods_price_min_dealer'] = $priceArr['distributionPrice']; $goods['goods_price_min_dealer'] = $priceArr['distributionPrice'];
$goods['goods_price_min'] = $goods['goods_price_min_plus'];//$goods['cost_price_min'];//店长售价,展示为成本价 $goods['goods_price_min'] = $goods['goods_price_min_plus']; //$goods['cost_price_min'];//店长售价,展示为成本价
$goods['discount'] = $goods_price_min > 0 ? bcdiv((string)($priceArr['membershipPrice'] * 10), (string)$goods_price_min, 1) : 0; $goods['discount'] = $goods_price_min > 0 ? bcdiv((string)($priceArr['membershipPrice'] * 10), (string)$goods_price_min, 1) : 0;
} elseif (UserService::isPlusMember()) { } elseif (UserService::isPlusMember()) {
$membershipPrice = \app\common\model\PriceSet::membershipPrice($goods['goods_price_min'], $goods['cost_price_min'], $catIds); $membershipPrice = \app\common\model\PriceSet::membershipPrice($goods['goods_price_min'], $goods['cost_price_min'], $catIds, $user->store_id);
$goods['discount'] = $goods['goods_price_min'] > 0 ? bcdiv((string)($membershipPrice * 10), (string)$goods['goods_price_min'], 1) : 0; $goods['discount'] = $goods['goods_price_min'] > 0 ? bcdiv((string)($membershipPrice * 10), (string)$goods['goods_price_min'], 1) : 0;
$goods['goods_price_min'] = $membershipPrice; $goods['goods_price_min'] = $membershipPrice;
} elseif (UserService::isDealerMember()) { } elseif (UserService::isDealerMember()) {
$priceArr = \app\common\model\PriceSet::distributionPrice($goods['goods_price_min'], $goods['cost_price_min'], $catIds); $priceArr = \app\common\model\PriceSet::distributionPrice($goods['goods_price_min'], $goods['cost_price_min'], $catIds, $user->store_id);
$goods['discount'] = $goods['goods_price_min'] > 0 ? bcdiv((string)($priceArr['distributionPrice'] * 10), (string)$goods['goods_price_min'], 1) : 0; $goods['discount'] = $goods['goods_price_min'] > 0 ? bcdiv((string)($priceArr['distributionPrice'] * 10), (string)$goods['goods_price_min'], 1) : 0;
//$goods['goods_price_min'] = $membershipPrice; //$goods['goods_price_min'] = $membershipPrice;
$goods['goods_price_min'] = $priceArr['distributionPrice']; $goods['goods_price_min'] = $priceArr['distributionPrice'];
} }
//处理店长临时设置的秒杀价 //处理店长临时设置的秒杀价
if ($goods['sec_start_time'] && strtotime($goods['sec_start_time']) <= $currtime && (strtotime($goods['sec_start_time']) + 24 * 3600) >= $currtime) { if ($goods['sec_start_time'] && strtotime($goods['sec_start_time']) <= $currtime && (strtotime($goods['sec_start_time']) + 24 * 3600) >= $currtime) {
$goods['goods_price_min'] = $goods['seckill_price']; $goods['goods_price_min'] = $goods['seckill_price'];
} }
if ($goods['discount'] == 10) { if ($goods['discount'] == 10) {
$goods['discount'] = 0.0; $goods['discount'] = 0.0;
} }
// 会员折扣价: 商品sku列表 // 会员折扣价: 商品sku列表
if ($goods->getRelation('skuList') || $goods->getRelation('skuList1')) { if ($goods->getRelation('skuList') || $goods->getRelation('skuList1')) {
foreach ($goods['skuList'] as &$skuItem) { foreach ($goods['skuList'] as &$skuItem) {
//处理图片和库 //处理图片和库
$goods_image = GoodsImage::where('goods_id', $skuItem['goods_id'])->order("id asc")->find(); $goods_image = GoodsImage::where('goods_id', $skuItem['goods_id'])->order("id asc")->find();
@ -782,21 +779,19 @@ class Goods extends GoodsModel
//价格判断 //价格判断
if (UserService::isstore()) { if (UserService::isstore()) {
$priceArr = \app\common\model\PriceSet::distributionPrice($skuItem['goods_price'], $skuItem['cost_price'], $catIds); $priceArr = \app\common\model\PriceSet::distributionPrice($skuItem['goods_price'], $skuItem['cost_price'], $catIds,$user->store_id);
$skuItem['goods_price'] = $skuItem['cost_price'];//店长售价,展示为成本价 $skuItem['goods_price'] = $skuItem['cost_price']; //店长售价,展示为成本价
} elseif (UserService::isPlusMember()) { } elseif (UserService::isPlusMember()) {
$skuItem['goods_price'] = \app\common\model\PriceSet::membershipPrice($skuItem['goods_price'], $skuItem['cost_price'], $catIds); $skuItem['goods_price'] = \app\common\model\PriceSet::membershipPrice($skuItem['goods_price'], $skuItem['cost_price'], $catIds,$user->store_id);
} elseif (UserService::isDealerMember()) { } elseif (UserService::isDealerMember()) {
$priceArr = \app\common\model\PriceSet::distributionPrice($skuItem['goods_price'], $skuItem['cost_price'], $catIds); $priceArr = \app\common\model\PriceSet::distributionPrice($skuItem['goods_price'], $skuItem['cost_price'], $catIds,$user->store_id);
$skuItem['goods_price'] = $priceArr['distributionPrice']; $skuItem['goods_price'] = $priceArr['distributionPrice'];
} }
//处理店长临时设置的秒杀价 //处理店长临时设置的秒杀价
if ($skuItem['sec_start_time'] && strtotime($skuItem['sec_start_time']) <= $currtime && (strtotime($skuItem['sec_start_time']) + 24 * 3600) >= $currtime) { if ($skuItem['sec_start_time'] && strtotime($skuItem['sec_start_time']) <= $currtime && (strtotime($skuItem['sec_start_time']) + 24 * 3600) >= $currtime) {
$skuItem['goods_price'] = $skuItem['seckill_price']; $skuItem['goods_price'] = $skuItem['seckill_price'];
} }
} }
} }
// 折扣价: 已选择的商品sku(用于购物车) // 折扣价: 已选择的商品sku(用于购物车)
@ -808,15 +803,14 @@ class Goods extends GoodsModel
// $sku_price_plus[] = GoodsPriceModel::getDiscountPrice($v, 1, $goods['skuInfo']['goods_price']); // $sku_price_plus[] = GoodsPriceModel::getDiscountPrice($v, 1, $goods['skuInfo']['goods_price']);
// } // }
// $goods['skuInfo']['goods_price'] = min($sku_price_plus); // $goods['skuInfo']['goods_price'] = min($sku_price_plus);
$goods['skuInfo']['goods_price'] = \app\common\model\PriceSet::membershipPrice($goods['skuInfo']['goods_price'], $goods['skuInfo']['cost_price'], $catIds); $goods['skuInfo']['goods_price'] = \app\common\model\PriceSet::membershipPrice($goods['skuInfo']['goods_price'], $goods['skuInfo']['cost_price'], $catIds,$user->store_id);
} elseif (UserService::isDealerMember()) { } elseif (UserService::isDealerMember()) {
// $sku_price_dealer = []; // $sku_price_dealer = [];
// foreach ($catIds as $k => $v) { // foreach ($catIds as $k => $v) {
// $sku_price_dealer[] = GoodsPriceModel::getDiscountPrice($v, 2, $goods['skuInfo']['goods_price']); // $sku_price_dealer[] = GoodsPriceModel::getDiscountPrice($v, 2, $goods['skuInfo']['goods_price']);
// } // }
//$goods['skuInfo']['goods_price'] = min($sku_price_dealer); //$goods['skuInfo']['goods_price'] = min($sku_price_dealer);
$priceArr = \app\common\model\PriceSet::distributionPrice($goods['skuInfo']['goods_price'], $goods['skuInfo']['cost_price'], $catIds); $priceArr = \app\common\model\PriceSet::distributionPrice($goods['skuInfo']['goods_price'], $goods['skuInfo']['cost_price'], $catIds, $user->store_id);
$goods['skuInfo']['goods_price'] = $priceArr['distributionPrice']; $goods['skuInfo']['goods_price'] = $priceArr['distributionPrice'];
} }
//处理店长临时设置的秒杀价 //处理店长临时设置的秒杀价
@ -933,9 +927,9 @@ class Goods extends GoodsModel
return false; return false;
} }
//批量修改秒杀价格 //批量修改秒杀价格
// var_dump($data['sku_id']); // var_dump($data['sku_id']);
$sku_id = $data['sku_id']; $sku_id = $data['sku_id'];
// foreach ($sku_ids as $sku_id) { // foreach ($sku_ids as $sku_id) {
$skuData = GoodsSkuModel::get(['id' => $sku_id, 'goods_id' => $data['goods_id']]); $skuData = GoodsSkuModel::get(['id' => $sku_id, 'goods_id' => $data['goods_id']]);
if ($skuData) { if ($skuData) {
$up_data = [ $up_data = [
@ -949,7 +943,7 @@ class Goods extends GoodsModel
$skuData->save($up_data); $skuData->save($up_data);
GoodsModel::where('goods_id', $data['goods_id'])->update($up_data); GoodsModel::where('goods_id', $data['goods_id'])->update($up_data);
} }
// } // }
return true; return true;
} }
} }

@ -380,14 +380,15 @@ class Goods extends GoodsService
public static function getGoodsPrice($goods_id, $price, $cost_price) public static function getGoodsPrice($goods_id, $price, $cost_price)
{ {
$user = UserService::getCurrentLoginUser();
$catService = new \app\store\model\GoodsCategoryRel(); $catService = new \app\store\model\GoodsCategoryRel();
$catIds = $catService->where(['goods_id' => $goods_id])->column('category_id'); $catIds = $catService->where(['goods_id' => $goods_id])->column('category_id');
if (UserService::isstore()) { if (UserService::isstore()) {
$price = $cost_price; $price = $cost_price;
} elseif (UserService::isPlusMember()) { } elseif (UserService::isPlusMember()) {
$price = \app\common\model\PriceSet::membershipPrice($price, $cost_price, $catIds); $price = \app\common\model\PriceSet::membershipPrice($price, $cost_price, $catIds, $user->store_id);
} elseif (UserService::isDealerMember()) { } elseif (UserService::isDealerMember()) {
$priceArr = \app\common\model\PriceSet::distributionPrice($price, $cost_price, $catIds); $priceArr = \app\common\model\PriceSet::distributionPrice($price, $cost_price, $catIds, $user->store_id);
$price = $priceArr['distributionPrice']; $price = $priceArr['distributionPrice'];
} }
return $price; return $price;
@ -402,6 +403,7 @@ class Goods extends GoodsService
{ {
$data = []; $data = [];
$user = UserService::getCurrentLoginUser();
foreach ($goodsList as $goods) { foreach ($goodsList as $goods) {
$temp = [ $temp = [
'goods_id' => $goods['goods_id'], 'goods_id' => $goods['goods_id'],
@ -421,14 +423,14 @@ class Goods extends GoodsService
$catIds = $catService->where(['goods_id' => $goods['goods_id']])->column('category_id'); $catIds = $catService->where(['goods_id' => $goods['goods_id']])->column('category_id');
//价格判断 //价格判断
if (UserService::isstore()) { if (UserService::isstore()) {
$priceArr = \app\common\model\PriceSet::distributionPrice($goods['goods_price_min'], $goods['cost_price_min'], $catIds); $priceArr = \app\common\model\PriceSet::distributionPrice($goods['goods_price_min'], $goods['cost_price_min'], $catIds,$user->store_id);
$temp['goods_price_min_plus'] = $priceArr['membershipPrice']; $temp['goods_price_min_plus'] = $priceArr['membershipPrice'];
$temp['goods_price_min_dealer'] = $priceArr['distributionPrice']; $temp['goods_price_min_dealer'] = $priceArr['distributionPrice'];
$temp['goods_price_min'] = $goods['goods_price_min_plus'];//$goods['cost_price_min'];//店长售价,展示为成本价 $temp['goods_price_min'] = $goods['goods_price_min_plus'];//$goods['cost_price_min'];//店长售价,展示为成本价
} elseif (UserService::isPlusMember()) { } 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,$user->store_id);
} elseif (UserService::isDealerMember()) { } elseif (UserService::isDealerMember()) {
$priceArr = \app\common\model\PriceSet::distributionPrice($goods['goods_price_min'], $goods['cost_price_min'], $catIds); $priceArr = \app\common\model\PriceSet::distributionPrice($goods['goods_price_min'], $goods['cost_price_min'], $catIds,$user->store_id);
$temp['goods_price_min'] = $priceArr['distributionPrice']; $temp['goods_price_min'] = $priceArr['distributionPrice'];
} }
if ($goods['sec_start_time'] && strtotime($goods['sec_start_time']) <= $currtime && (strtotime($goods['sec_start_time']) + 24 * 3600) >= $currtime) { if ($goods['sec_start_time'] && strtotime($goods['sec_start_time']) <= $currtime && (strtotime($goods['sec_start_time']) + 24 * 3600) >= $currtime) {

@ -36,8 +36,8 @@ class PriceSet extends BaseModel
* @param [type] $category_ids [description] * @param [type] $category_ids [description]
* @return [type] [description] * @return [type] [description]
*/ */
public static function membershipPrice($market_price, $cost_price, $category_ids){ public static function membershipPrice($market_price, $cost_price, $category_ids ,$storeId=0){
$addPriceRate = self::getAddPriceRate(0, $category_ids, $cost_price); $addPriceRate = self::getAddPriceRate(0, $category_ids, $cost_price,$storeId);
//没有加价率返回市场价 //没有加价率返回市场价
if (!$addPriceRate) { if (!$addPriceRate) {
//return sprintf("%.2f", $market_price); //return sprintf("%.2f", $market_price);
@ -62,13 +62,13 @@ class PriceSet extends BaseModel
* @param [type] $category_ids [description] * @param [type] $category_ids [description]
* @return [type] [description] * @return [type] [description]
*/ */
public static function distributionPrice($market_price, $cost_price, $category_ids){ public static function distributionPrice($market_price, $cost_price, $category_ids,$storeId=0){
$arr = []; $arr = [];
//会员价 //会员价
$membershipPrice = self::membershipPrice($market_price, $cost_price, $category_ids); $membershipPrice = self::membershipPrice($market_price, $cost_price, $category_ids,$storeId);
$arr['membershipPrice'] = $membershipPrice; $arr['membershipPrice'] = $membershipPrice;
//分销价 //分销价
$addPriceRate = self::getAddPriceRate(1, $category_ids, $cost_price); $addPriceRate = self::getAddPriceRate(1, $category_ids, $cost_price,$storeId);
//没有加价率返回市场价 //没有加价率返回市场价
if (!$addPriceRate) { if (!$addPriceRate) {
@ -100,11 +100,12 @@ class PriceSet extends BaseModel
* @param [type] $goods_price [description] * @param [type] $goods_price [description]
* @return [type] [description] * @return [type] [description]
*/ */
public static function getAddPriceRate($type, $category_ids, $cost_price){ public static function getAddPriceRate($type, $category_ids, $cost_price,$storeId = 0){
$info = static::where('type',$type) $info = static::where('type',$type)
->whereIn('code', $category_ids) ->whereIn('code', $category_ids)
->where('min', '<=', $cost_price) ->where('min', '<=', $cost_price)
->where('max', '>', $cost_price) ->where('max', '>', $cost_price)
->where('store_id', $storeId)
->order('id desc') ->order('id desc')
->column('add_price_rate'); ->column('add_price_rate');
if (!$info) { if (!$info) {

@ -496,6 +496,7 @@ class Goods extends Controller
set_time_limit(0); set_time_limit(0);
$model = new GoodsModel; $model = new GoodsModel;
$params = $this->request->param(); $params = $this->request->param();
$storeId = $this->storeId;
//$params['store_id'] = $this->storeId; //$params['store_id'] = $this->storeId;
$perSize = 10000; $perSize = 10000;
$params['page'] = 1; $params['page'] = 1;
@ -555,7 +556,7 @@ class Goods extends Controller
$value['category_3'] = $cateList[0]['name'] ?? "无"; $value['category_3'] = $cateList[0]['name'] ?? "无";
$value['category_4'] = $cateList[1]['name'] ?? "无"; $value['category_4'] = $cateList[1]['name'] ?? "无";
//会员价 //会员价
$value['membership_price'] = \app\common\model\PriceSet::membershipPrice($value['goods_price_min'], $value['cost_price_min'], array_column($cates, 'category_id')); $value['membership_price'] = \app\common\model\PriceSet::membershipPrice($value['goods_price_min'], $value['cost_price_min'], array_column($cates, 'category_id'),$storeId);
} }
//销售区域 //销售区域
@ -764,7 +765,7 @@ class Goods extends Controller
{ {
$id = $this->request->param('id'); $id = $this->request->param('id');
$detail = ModelTipoff::where('id', $id)->find(); $detail = ModelTipoff::where('id', $id)->find();
$goodsList = GoodsModel::whereIn("goods_id", $detail['goods_id'])->field('goods_id,goods_name,goods_price_min,cost_price_min,goods_no,link')->select(); $goodsList = GoodsModel::whereIn("goods_id", $detail['goods_id'])->field('goods_id,store_id,goods_name,goods_price_min,cost_price_min,goods_no,link')->select();
$goods_no = []; $goods_no = [];
$JdModel = new jd(); $JdModel = new jd();
@ -803,7 +804,7 @@ class Goods extends Controller
//分类 //分类
if ($cates) { if ($cates) {
//会员价 //会员价
$value['membership_price'] = \app\common\model\PriceSet::membershipPrice($value['goods_price_min'], $value['cost_price_min'], array_column($cates, 'category_id')); $value['membership_price'] = \app\common\model\PriceSet::membershipPrice($value['goods_price_min'], $value['cost_price_min'], array_column($cates, 'category_id'),$value['store_id']);
} }
unset($goodsList[$key]['cost_price_min']); unset($goodsList[$key]['cost_price_min']);
} }

Loading…
Cancel
Save