multi-store/app/admin/service/ProductPriceService.php
2025-03-18 15:20:56 +08:00

39 lines
1.5 KiB
PHP

<?php
namespace app\admin\service;
class ProductPriceService
{
/**
* 设置商品价格
* @param $purchasePrice float 采购价
* @param $productPriceRate array 价格比例
* @return array
*/
public function setProductPrice(float $purchasePrice, array $productPriceRate)
{
$result = [];
$result['purchase_lv'] = bcdiv($productPriceRate['supply_rate'], 100, 2);
$result['purchase'] = bcmul($purchasePrice, $result['purchase_lv'], 2);
$result['cost_lv'] = bcdiv($productPriceRate['merchant_rate'], 100, 2);
$result['cost'] = bcmul($result['purchase'], $result['cost_lv'], 2);
$result['vip_lv'] = bcdiv($productPriceRate['vip_rate'], 100, 2);
$result['vip_price'] = bcmul($result['purchase'], $result['vip_lv'], 2);
$result['price_lv'] = bcdiv($productPriceRate['price_rate'], 100, 2);
$result['price'] = bcmul($result['purchase'], $result['price_lv'], 2);
// 暂时不处理零售价,零售价使用会员价
// $lastNum = substr($result['price'], -1);
// if ($lastNum > 0) {
// $result['price'] = ceil($result['price'] * 10);
// $result['price'] = bcdiv($result['price'], 10, 2);
// }
$lastNum = substr($result['vip_price'], -1);
if ($lastNum > 0) {
$result['vip_price'] = ceil($result['vip_price'] * 10);
$result['vip_price'] = bcdiv($result['vip_price'], 10, 2);
}
return $result;
}
}