feat: 修改了StoreOrderLogic类,添加了订单支付金额和原始价格的计算,以及活动减少的金额计算。
This commit is contained in:
parent
c2119f8132
commit
1dc29d6145
@ -19,7 +19,8 @@ use think\facade\Db;
|
||||
|
||||
class StoreOrderLogic extends BaseLogic
|
||||
{
|
||||
public static $total;
|
||||
public static $total_price;
|
||||
public static $pay_price;
|
||||
public static $cost;
|
||||
public static $profit;
|
||||
public static $activity_price;
|
||||
@ -38,10 +39,11 @@ class StoreOrderLogic extends BaseLogic
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
self::$total = 0;
|
||||
self::$cost = 0;//成本
|
||||
self::$profit = 0;//利润
|
||||
self::$activity_price = 0;//活动减少
|
||||
self::$total_price = 0;
|
||||
self::$pay_price = 0;
|
||||
self::$cost = 0; //成本
|
||||
self::$profit = 0; //利润
|
||||
self::$activity_price = 0; //活动减少
|
||||
|
||||
/** 计算价格 */
|
||||
$check = DictType::where('type', 'activities')->find();
|
||||
@ -53,18 +55,21 @@ class StoreOrderLogic extends BaseLogic
|
||||
unset($cart_select[$k]['id']);
|
||||
|
||||
$cart_select[$k]['price'] = $find['price'];
|
||||
$cart_select[$k]['total_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单总价
|
||||
$cart_select[$k]['deduction_price'] =self::$activity_price;//抵扣金额
|
||||
if (isset($check) && $check['status'] == 1) {
|
||||
//零售价*折扣率
|
||||
$activity_price=bcmul($find['price'],0.9,2);
|
||||
self::$activity_price = bcadd(self::$activity_price, bcsub($find['price'],$activity_price,2), 2);
|
||||
$activity_price = bcmul($find['price'], 0.9, 2);
|
||||
$deduction_price_count=bcmul(bcsub($find['price'], $activity_price, 2),$v['cart_num'], 2);
|
||||
$cart_select[$k]['deduction_price'] =$deduction_price_count;
|
||||
self::$activity_price = bcadd(self::$activity_price, $deduction_price_count, 2);
|
||||
$find['price'] = $activity_price;
|
||||
}
|
||||
//利润
|
||||
$onePrice = bcsub($find['price'], $find['cost'], 2);
|
||||
$cart_select[$k]['profit'] = bcmul($v['cart_num'], $onePrice, 2);//利润
|
||||
$cart_select[$k]['cost'] = bcmul($v['cart_num'], $find['cost'], 2) ?? 0;
|
||||
$cart_select[$k]['total'] = bcmul($v['cart_num'], $find['price'], 2);//钱
|
||||
$cart_select[$k]['total_price'] = bcmul($v['cart_num'], $find['price'], 2);//钱
|
||||
$cart_select[$k]['profit'] = bcmul($v['cart_num'], $onePrice, 2); //利润
|
||||
$cart_select[$k]['cost'] = bcmul($v['cart_num'], $find['cost'], 2) ?? 0; //成本
|
||||
$cart_select[$k]['pay_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单支付金额
|
||||
$cart_select[$k]['product_id'] = $find['product_id'];
|
||||
$cart_select[$k]['old_cart_id'] = $v['id'];
|
||||
$cart_select[$k]['cart_num'] = $v['cart_num'];
|
||||
@ -82,19 +87,21 @@ class StoreOrderLogic extends BaseLogic
|
||||
//理论上每笔都是拆分了
|
||||
$cart_select[$k]['name'] = $find['store_name'];
|
||||
$cart_select[$k]['imgs'] = $find['image'];
|
||||
$cart_select[$k]['store_id'] = $params['store_id'] ?? 0;
|
||||
$cart_select[$k]['unit_name'] = StoreProductUnit::where(['id' => $find['unit']])->value('name');
|
||||
self::$total = bcadd(self::$total, $cart_select[$k]['total'], 2);
|
||||
self::$total_price = bcadd(self::$total_price, $cart_select[$k]['total_price'], 2);
|
||||
self::$pay_price = bcadd(self::$pay_price, $cart_select[$k]['pay_price'], 2);
|
||||
self::$cost = bcadd(self::$cost, $cart_select[$k]['cost'], 2);
|
||||
self::$profit = bcadd(self::$profit, $cart_select[$k]['profit'], 2);
|
||||
}
|
||||
//TODO 收单打9.9折 会员按照比例打折 等级按照充值去升级
|
||||
$pay_price = self::$total;
|
||||
$pay_price = self::$pay_price;
|
||||
$vipPrice = 0;
|
||||
//成本价 收益
|
||||
$order = [
|
||||
'create_time' => time(),
|
||||
'order_id' => getNewOrderId('PF'),
|
||||
'total_price' => self::$total,//总价
|
||||
'total_price' => self::$total_price, //总价
|
||||
'cost' => self::$cost,//成本价
|
||||
'profit' => self::$profit,//利润
|
||||
'pay_price' => $pay_price,//后期可能有降价抵扣
|
||||
@ -109,7 +116,9 @@ class StoreOrderLogic extends BaseLogic
|
||||
'activity_price' =>self::$activity_price,
|
||||
'activities'=>$check['status'],
|
||||
'default_delivery'=>1,
|
||||
'original_price'=>bcadd(self::$activity_price,self::$total,2),
|
||||
'original_price'=>self::$total_price,
|
||||
'deduction_price' => self::$activity_price
|
||||
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
|
Loading…
x
Reference in New Issue
Block a user