下单时校验用户为当用户为摊贩/酒店/食堂时,返回优惠价

This commit is contained in:
liu 2024-06-17 17:38:55 +08:00
parent 4bf661fba0
commit c0c61dd042

View File

@ -47,6 +47,7 @@ class OrderLogic extends BaseLogic
public static $pay_price;
public static $cost;
public static $profit;
public static $store_price;//门店零售价
public static $activity_price;
/**
@ -69,6 +70,7 @@ class OrderLogic extends BaseLogic
self::$cost = 0; //成本由采购价替代原成本为门店零售价
self::$profit = 0; //利润
self::$activity_price = 0; //活动减少
self::$store_price = 0; //门店零售价
/** 计算价格 */
foreach ($cart_select as $k => $v) {
@ -77,11 +79,9 @@ class OrderLogic extends BaseLogic
continue;
}
unset($cart_select[$k]['id']);
if($user && in_array($user['user_ship'],UserShipEnum::DISCOUNT_ARRAY)){
$find['price'] = $find['cost'];
}
$cart_select[$k]['price'] = $find['price'];
$cart_select[$k]['cost'] = $find['cost'];
$cart_select[$k]['total_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单总价
$cart_select[$k]['deduction_price'] =self::$activity_price;//抵扣金额
@ -94,6 +94,7 @@ class OrderLogic extends BaseLogic
// $cart_select[$k]['profit'] = bcmul($v['cart_num'], $onePrice, 2); //利润
$cart_select[$k]['purchase'] = bcmul($v['cart_num'], $find['purchase'], 2) ?? 0; //成本
$cart_select[$k]['pay_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单支付金额
$cart_select[$k]['store_price'] = bcmul($v['cart_num'], $find['cost'], 2)??0; //门店零售价
$cart_select[$k]['product_id'] = $find['product_id'];
$cart_select[$k]['old_cart_id'] = $v['id'];
$cart_select[$k]['cart_num'] = $v['cart_num'];
@ -114,9 +115,17 @@ class OrderLogic extends BaseLogic
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]['purchase'], 2);
self::$store_price = bcadd(self::$store_price, $cart_select[$k]['store_price'], 2);//门店零售价格
// self::$profit = bcadd(self::$profit, $cart_select[$k]['profit'], 2);
}
$preferential_amount = 0;//差价(用户为UserShipEnum::DISCOUNT_ARRAY 的时候的优惠差价)
$pay_price =bcsub(self::$pay_price, self::$activity_price, 2); //减去活动优惠金额
if($user && in_array($user['user_ship'],UserShipEnum::DISCOUNT_ARRAY)){
$pay_price =bcsub(self::$store_price, self::$activity_price, 2); //减去活动优惠金额
$preferential_amount = bcsub(self::$pay_price,self::$store_price,2);
}
$vipPrice = 0;
//成本价 收益
$order = [
@ -138,6 +147,7 @@ class OrderLogic extends BaseLogic
'activities' => self::$activity_price>0?1:0,
'deduction_price' => self::$activity_price,
'is_vip' => 0,
'preferential_amount' => $preferential_amount,
];
$order['default_delivery'] = 0;