lqmac 11 months ago
parent 0b124ad10b
commit 14dae90237
  1. 51
      app/api/controller/Store.php
  2. 69
      app/common/model/PriceSet.php

@ -139,20 +139,25 @@ class Store extends Controller
PriceSet::where('store_id', $storeid)->where('type', $params['type']??0)->delete();
$inDatas = [];
foreach ($params['list'] as $value) {
foreach ($value['price_list'] as $price) {
$temp = [
'category' => $value['category'],
'store_id' => $storeid,
'type' => $params['type'],
'min' => $price['min'],
'max' => $price['max'],
'add_price_rate' => $price['add_price_rate'],
'create_time' => time(),
'update_time' => time(),
];
$inDatas[] = $temp;
$categorys = explode(",", $value['category']);
foreach ($categorys as $category) {
foreach ($value['price_list'] as $price) {
$temp = [
'category' => $value['category'],
'code' => $category,
'store_id' => $storeid,
'type' => $params['type'],
'min' => $price['min'],
'max' => $price['max'],
'add_price_rate' => $price['add_price_rate'],
'create_time' => time(),
'update_time' => time(),
];
$inDatas[] = $temp;
}
}
}
// echo "<pre>";
// print_r($inDatas);
@ -165,7 +170,7 @@ class Store extends Controller
public function getStorePriceInfo(int $type): Json
{
$storeid = request()->header()['storeid'];
$list = PriceSet::where('store_id',$storeid)->where('type', $params['type'] ?? 0)->field('category,min,max,add_price_rate')->select()->toArray();
$list = PriceSet::where('store_id',$storeid)->where('type', $params['type'] ?? 0)->field('category,code,min,max,add_price_rate')->group("category, min")->select()->toArray();
$data = [];
$arr = [];
foreach ($list as $value) {
@ -185,20 +190,12 @@ class Store extends Controller
public function test(int $type): Json
{
$storeid = request()->header()['storeid'];
$list = PriceSet::where('store_id',$storeid)->where('type', $params['type'] ?? 0)->field('category,min,max,add_price_rate')->select()->toArray();
$data = [];
$arr = [];
foreach ($list as $value) {
$arr[$value['category']][] = $value;
}
foreach ($arr as $key => $item) {
$data['list'][] = [
'category' => $key,
'price_list' => $item,
];
}
$data['type'] = $type;
return $this->renderSuccess($data);
$categoryIds = [1001,1002];
$list = PriceSet::distributionPrice(90, 50, $categoryIds);
return $this->renderSuccess($list);
}

@ -28,4 +28,73 @@ class PriceSet extends BaseModel
// 定义主键
protected $pk = 'id';
/**
* 会员价
* [membershipPrice description]
* @param [type] $market_price [description]
* @param [type] $cost_price [description]
* @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);
$membershipPrice = $cost_price * (1 + $addPriceRate * 0.01);
//当加价率生效后,会员价高于市场价
if ($membershipPrice > $market_price) {
$membershipPrice = ($market_price - $cost_price) * $addPriceRate * 0.01 + $cost_price;
}
return sprintf("%.2f", $membershipPrice);
}
/**
* 分销价
* [distributionPrice description]
* @param [type] $market_price [description]
* @param [type] $cost_price [description]
* @param [type] $type [description]
* @param [type] $category_ids [description]
* @return [type] [description]
*/
public static function distributionPrice($market_price, $cost_price, $category_ids){
//会员价
$membershipPrice = self::membershipPrice($market_price, $cost_price, $category_ids);
//分销价
$addPriceRate = self::getAddPriceRate(1, $category_ids, $cost_price);
$distributionPrice = $cost_price * (1 + $addPriceRate * 0.01);
$price = $distributionPrice;
//当加价率生效后,分销价高于市场价
if ($distributionPrice > $market_price) {
$price = ($market_price - $cost_price) * $addPriceRate * 0.01 + $cost_price;
}
//当加价率生效后,分销价高于会员价
if ($distributionPrice > $membershipPrice) {
$price = ($membershipPrice - $cost_price) * $addPriceRate * 0.01 + $cost_price;
}
return sprintf("%.2f", $price);
}
/**
* 获取商品加价率
* [getAddPriceRate description]
* @param [type] $store_id [description]
* @param [type] $type [description]
* @param [type] $category_ids [description]
* @param [type] $goods_price [description]
* @return [type] [description]
*/
public static function getAddPriceRate($type, $category_ids, $cost_price){
$info = static::where('type',$type)
->whereIn('code', $category_ids)
->where('min', '<=', $cost_price)
->where('max', '>', $cost_price)
->order('id desc')
->column('add_price_rate');
if (!$info) {
return 0;
}
return $info[0];
}
}

Loading…
Cancel
Save