|
|
|
@ -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]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|