收银机同步小程序采购款支付vip逻辑

This commit is contained in:
liu 2024-06-18 09:44:13 +08:00
parent c8d20b33d6
commit 5091d0a6bb

View File

@ -4,6 +4,7 @@ namespace app\common\logic\store_order;
use app\common\enum\OrderEnum; use app\common\enum\OrderEnum;
use app\common\enum\PayEnum; use app\common\enum\PayEnum;
use app\common\enum\UserShipEnum;
use app\common\logic\BaseLogic; use app\common\logic\BaseLogic;
use app\common\enum\YesNoEnum; use app\common\enum\YesNoEnum;
use app\common\model\dict\DictType; use app\common\model\dict\DictType;
@ -25,6 +26,7 @@ class StoreOrderLogic extends BaseLogic
public static $pay_price; public static $pay_price;
public static $cost; public static $cost;
public static $profit; public static $profit;
public static $store_price;//门店零售价
public static $activity_price; public static $activity_price;
/** /**
* @notes 获取购物车商品信息 * @notes 获取购物车商品信息
@ -46,32 +48,37 @@ class StoreOrderLogic extends BaseLogic
self::$cost = 0; //成本 self::$cost = 0; //成本
self::$profit = 0; //利润 self::$profit = 0; //利润
self::$activity_price = 0; //活动减少 self::$activity_price = 0; //活动减少
self::$store_price = 0; //门店零售价
/** 计算价格 */ /** 计算价格 */
foreach ($cart_select as $k => $v) { foreach ($cart_select as $k => $v) {
$find = StoreBranchProduct::where(['product_id' => $v['product_id'],'store_id'=>$params['store_id']])->field('id branch_product_id,store_name,image,unit,price,cost,product_id')->withTrashed()->find(); $find = StoreBranchProduct::where(['product_id' => $v['product_id'],'store_id'=>$params['store_id']])->field('id branch_product_id,store_name,image,unit,price,vip_price,cost,purchase,product_id')->withTrashed()->find();
if (!$find) { if (!$find) {
continue; continue;
} }
unset($cart_select[$k]['id']); unset($cart_select[$k]['id']);
$cart_select[$k]['price'] = $find['price']; $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]['total_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单总价
$cart_select[$k]['deduction_price'] =self::$activity_price;//抵扣金额 $cart_select[$k]['deduction_price'] =self::$activity_price;//抵扣金额
if ($user && $user['user_ship'] == 4) { // if ($user && $user['user_ship'] == 4) {
$deduction_price_count=bcmul(bcsub($find['price'], $find['cost'], 2),$v['cart_num'],2); // $deduction_price_count=bcmul(bcsub($find['price'], $find['cost'], 2),$v['cart_num'],2);
$cart_select[$k]['deduction_price'] =$deduction_price_count; // $cart_select[$k]['deduction_price'] =$deduction_price_count;
self::$activity_price = bcadd(self::$activity_price, $deduction_price_count, 2); // self::$activity_price = bcadd(self::$activity_price, $deduction_price_count, 2);
} // }
//利润 //利润
// $cart_select[$k]['profit'] = bcmul($cart_select[$k]['total_price'],0.05,2); //利润 // $cart_select[$k]['profit'] = bcmul($cart_select[$k]['total_price'],0.05,2); //利润
$cart_select[$k]['cost'] = bcmul($v['cart_num'], $find['cost'], 2) ?? 0; //成本 $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]['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]['product_id'] = $find['product_id'];
$cart_select[$k]['old_cart_id'] = $v['id']; $cart_select[$k]['old_cart_id'] = $v['id'];
$cart_select[$k]['cart_num'] = $v['cart_num']; $cart_select[$k]['cart_num'] = $v['cart_num'];
$cart_select[$k]['verify_code'] = $params['verify_code'] ?? ''; $cart_select[$k]['verify_code'] = $params['verify_code'] ?? '';
//vip1待返回金额
$cart_select[$k]['vip_frozen_price'] = bcsub($cart_select[$k]['pay_price'],$cart_select[$k]['store_price'],2);
$cartInfo = $cart_select[$k]; $cartInfo = $cart_select[$k];
$cartInfo['name'] = $find['store_name']; $cartInfo['name'] = $find['store_name'];
$cartInfo['image'] = $find['image']; $cartInfo['image'] = $find['image'];
@ -80,7 +87,7 @@ class StoreOrderLogic extends BaseLogic
// if ($vipPrice) { // if ($vipPrice) {
// $cartInfo['price'] = $vipPrice; // $cartInfo['price'] = $vipPrice;
// } // }
$cartInfo['vip_price'] = 0;//$cart_select[$k]['total'] - $vipPrice ?? 0; //$cart_select[$k]['total'] - $vipPrice ?? 0;
$cart_select[$k]['cart_info'] = json_encode($cartInfo); $cart_select[$k]['cart_info'] = json_encode($cartInfo);
$cart_select[$k]['branch_product_id'] = $find['branch_product_id']; $cart_select[$k]['branch_product_id'] = $find['branch_product_id'];
//理论上每笔都是拆分了 //理论上每笔都是拆分了
@ -91,10 +98,16 @@ class StoreOrderLogic extends BaseLogic
self::$total_price = bcadd(self::$total_price, $cart_select[$k]['total_price'], 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::$pay_price = bcadd(self::$pay_price, $cart_select[$k]['pay_price'], 2);
self::$cost = bcadd(self::$cost, $cart_select[$k]['cost'], 2); self::$cost = bcadd(self::$cost, $cart_select[$k]['cost'], 2);
self::$store_price = bcadd(self::$store_price, $cart_select[$k]['store_price'], 2);//门店零售价格
// self::$profit = bcadd(self::$profit, $cart_select[$k]['profit'], 2); // self::$profit = bcadd(self::$profit, $cart_select[$k]['profit'], 2);
} }
//TODO 收单打9.9折 会员按照比例打折 等级按照充值去升级 $preferential_amount = 0;//差价(用户为UserShipEnum::DISCOUNT_ARRAY 的时候的优惠差价)
$pay_price = bcsub(self::$pay_price, self::$activity_price, 2); //减去活动优惠金额
$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; $vipPrice = 0;
//成本价 收益 //成本价 收益
$order = [ $order = [
@ -116,12 +129,11 @@ class StoreOrderLogic extends BaseLogic
'activities' => self::$activity_price>0?1:0, 'activities' => self::$activity_price>0?1:0,
'default_delivery'=>1, 'default_delivery'=>1,
'original_price'=>self::$total_price, 'original_price'=>self::$total_price,
'deduction_price' => self::$activity_price 'deduction_price' => self::$activity_price,
'preferential_amount' => $preferential_amount,
]; ];
if($user){ if($user && $user['user_ship']!=4){
if($user['user_ship']!=4){ $order['is_vip']=1;
$order['is_vip']=1;
}
} }
} catch (\Exception $e) { } catch (\Exception $e) {