master
zengyyh 4 months ago
parent b5da0608a1
commit 03fc2e5e3d
  1. 5
      app/api/controller/Goods.php
  2. 62
      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');
$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 = [];
$JdModel = new jd();
@ -607,13 +607,14 @@ class Goods extends Controller
//会员价
$cates = GoodsCategoryRel::where('goods_id', $value['goods_id'])->select()->toArray();
$value['jd_short_url'] = $jd_url[$value['goods_no']]['link'];
$value['membership_price'] = $value['goods_price_min'];
if (empty($value['jd_short_url'])) {
$value['jd_short_url'] = $jd_url[$value['goods_no']]['copy'];
}
//分类
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>
// +----------------------------------------------------------------------
declare (strict_types=1);
declare(strict_types=1);
namespace app\api\model;
@ -318,7 +318,6 @@ class Goods extends GoodsModel
$v['image'] = getUrl($file_path['file_path'], $file_path['domain']);
//$v['end_time'] = strtotime($info->p_time) - time();
$v['end_time'] = $info->p_time ? strtotime($info->p_time) - time() : 0;
}
return $list;
}
@ -400,7 +399,6 @@ class Goods extends GoodsModel
}
$goodsInfo->goods_images = $goods_images;
$goodsInfo->goods_image = $res['mainImageList'][0];
}
if ($res['infoImageList']) {
@ -410,7 +408,6 @@ class Goods extends GoodsModel
}
$goodsInfo->content = $content;
}
}
break;
case 'sn':
@ -420,7 +417,6 @@ class Goods extends GoodsModel
// code...
break;
}
}
/**
@ -478,7 +474,7 @@ class Goods extends GoodsModel
$goodsInfo['merchant'] = null;
//商户信息
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);
if ($merchant) {
if ($merchant['license_img_id']) {
@ -497,7 +493,7 @@ class Goods extends GoodsModel
$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['goods_no'] = $goodsInfo['goods_no_other'];
}
@ -582,7 +578,7 @@ class Goods extends GoodsModel
$goodsInfo = static::detail($goodsId, $with);
//处理子商户的成本价
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;
@ -593,12 +589,12 @@ class Goods extends GoodsModel
}
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'];
}
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));
}
}
//使用总后台的商品的图片作为商城商品的图片
@ -617,7 +613,7 @@ class Goods extends GoodsModel
}
//是否展示看同款按钮
$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;
}
// 判断商品是否存在
@ -646,7 +642,7 @@ class Goods extends GoodsModel
foreach ($data as $key => &$goods) {
//处理子商户的成本价
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);
//处理子商户的成本价
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);
// $catService = new GoodsCategoryRel();
// $catIds = $catService->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();
if ($goods->getAttr('skuInfo')) {
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()) {
$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'];
}
//处理店长临时设置的秒杀价
@ -734,32 +730,33 @@ class Goods extends GoodsModel
$goods['line_price_min'] = $goods['goods_price_min'];
return;
}
$user = UserService::getCurrentLoginUser();
$currtime = time();
// $catService = new GoodsCategoryRel();
// $catIds = $catService->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;
//价格判断
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['goods_price_min_plus'] = $priceArr['membershipPrice'];
$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;
} 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['goods_price_min'] = $membershipPrice;
} 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['goods_price_min'] = $membershipPrice;
$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) {
$goods['goods_price_min'] = $goods['seckill_price'];
}
@ -782,21 +779,19 @@ class Goods extends GoodsModel
//价格判断
if (UserService::isstore()) {
$priceArr = \app\common\model\PriceSet::distributionPrice($skuItem['goods_price'], $skuItem['cost_price'], $catIds);
$skuItem['goods_price'] = $skuItem['cost_price'];//店长售价,展示为成本价
$priceArr = \app\common\model\PriceSet::distributionPrice($skuItem['goods_price'], $skuItem['cost_price'], $catIds,$user->store_id);
$skuItem['goods_price'] = $skuItem['cost_price']; //店长售价,展示为成本价
} 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()) {
$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'];
}
//处理店长临时设置的秒杀价
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'];
}
}
}
// 折扣价: 已选择的商品sku(用于购物车)
@ -808,15 +803,14 @@ class Goods extends GoodsModel
// $sku_price_plus[] = GoodsPriceModel::getDiscountPrice($v, 1, $goods['skuInfo']['goods_price']);
// }
// $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()) {
// $sku_price_dealer = [];
// foreach ($catIds as $k => $v) {
// $sku_price_dealer[] = GoodsPriceModel::getDiscountPrice($v, 2, $goods['skuInfo']['goods_price']);
// }
//$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'];
}
//处理店长临时设置的秒杀价
@ -933,9 +927,9 @@ class Goods extends GoodsModel
return false;
}
//批量修改秒杀价格
// var_dump($data['sku_id']);
// var_dump($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']]);
if ($skuData) {
$up_data = [
@ -949,7 +943,7 @@ class Goods extends GoodsModel
$skuData->save($up_data);
GoodsModel::where('goods_id', $data['goods_id'])->update($up_data);
}
// }
// }
return true;
}
}

@ -380,14 +380,15 @@ class Goods extends GoodsService
public static function getGoodsPrice($goods_id, $price, $cost_price)
{
$user = UserService::getCurrentLoginUser();
$catService = new \app\store\model\GoodsCategoryRel();
$catIds = $catService->where(['goods_id' => $goods_id])->column('category_id');
if (UserService::isstore()) {
$price = $cost_price;
} 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()) {
$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'];
}
return $price;
@ -402,6 +403,7 @@ class Goods extends GoodsService
{
$data = [];
$user = UserService::getCurrentLoginUser();
foreach ($goodsList as $goods) {
$temp = [
'goods_id' => $goods['goods_id'],
@ -421,14 +423,14 @@ class Goods extends GoodsService
$catIds = $catService->where(['goods_id' => $goods['goods_id']])->column('category_id');
//价格判断
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_dealer'] = $priceArr['distributionPrice'];
$temp['goods_price_min'] = $goods['goods_price_min_plus'];//$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,$user->store_id);
} 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'];
}
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]
* @return [type] [description]
*/
public static function membershipPrice($market_price, $cost_price, $category_ids){
$addPriceRate = self::getAddPriceRate(0, $category_ids, $cost_price);
public static function membershipPrice($market_price, $cost_price, $category_ids ,$storeId=0){
$addPriceRate = self::getAddPriceRate(0, $category_ids, $cost_price,$storeId);
//没有加价率返回市场价
if (!$addPriceRate) {
//return sprintf("%.2f", $market_price);
@ -62,13 +62,13 @@ class PriceSet extends BaseModel
* @param [type] $category_ids [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 = [];
//会员价
$membershipPrice = self::membershipPrice($market_price, $cost_price, $category_ids);
$membershipPrice = self::membershipPrice($market_price, $cost_price, $category_ids,$storeId);
$arr['membershipPrice'] = $membershipPrice;
//分销价
$addPriceRate = self::getAddPriceRate(1, $category_ids, $cost_price);
$addPriceRate = self::getAddPriceRate(1, $category_ids, $cost_price,$storeId);
//没有加价率返回市场价
if (!$addPriceRate) {
@ -100,11 +100,12 @@ class PriceSet extends BaseModel
* @param [type] $goods_price [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)
->whereIn('code', $category_ids)
->where('min', '<=', $cost_price)
->where('max', '>', $cost_price)
->where('store_id', $storeId)
->order('id desc')
->column('add_price_rate');
if (!$info) {

@ -496,6 +496,7 @@ class Goods extends Controller
set_time_limit(0);
$model = new GoodsModel;
$params = $this->request->param();
$storeId = $this->storeId;
//$params['store_id'] = $this->storeId;
$perSize = 10000;
$params['page'] = 1;
@ -555,7 +556,7 @@ class Goods extends Controller
$value['category_3'] = $cateList[0]['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');
$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 = [];
$JdModel = new jd();
@ -803,7 +804,7 @@ class Goods extends Controller
//分类
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']);
}

Loading…
Cancel
Save