This commit is contained in:
mkm 2024-01-21 14:31:34 +08:00
parent 41618f37bf
commit dce8d2bdbe

View File

@ -35,7 +35,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
protected $store_consumption_user;
protected $consumption_money;
public function v2CartIdByOrderInfo($user, array $cartId, array $takes = null, array $useCoupon = null, bool $useIntegral = false, int $addressId = null, $createOrder = false,$consumption_id=0)
public function v2CartIdByOrderInfo($user, array $cartId, array $takes = null, array $useCoupon = null, bool $useIntegral = false, int $addressId = null, $createOrder = false, $consumption_id = 0)
{
$uid = $user->uid;
$userIntegral = $user->integral;
@ -150,8 +150,8 @@ class StoreOrderCreateRepository extends StoreOrderRepository
$orderDeliveryStatus = true;
$order_svip_discount = 0;
if($consumption_id>0){
$this->store_consumption_user=Db::name('store_consumption_user')->where('coupon_user_id',$consumption_id)->where('uid',$uid)->find();
if ($consumption_id > 0) {
$this->store_consumption_user = Db::name('store_consumption_user')->where('coupon_user_id', $consumption_id)->where('uid', $uid)->find();
}
// 循环计算每个店铺的订单数据 委托商品是否设置收货方式 ?
foreach ($merchantCartList as &$merchantCart) {
@ -489,7 +489,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
// if ($total_true_price > 0) {
$StoreCouponUser = app()->make(StoreCouponUserRepository::class);
$platformCoupon = $StoreCouponUser->validUserPlatformCoupon($uid);
$platformConsumption=[];
$platformConsumption = [];
//消费金
if ($source == 103) {
$ConsumptionWhere = [
@ -497,13 +497,13 @@ class StoreOrderCreateRepository extends StoreOrderRepository
'status' => 0,
'is_fail' => 0
];
$platformConsumption = Db::name('store_consumption_user')->where($ConsumptionWhere)->limit(100)->order('create_time', 'desc')
->field('coupon_user_id,uid,coupon_title,coupon_price,start_time,end_time')
->select()->each(function($item){
$item['describe']='仅限平台指定商家商品可使用';
return $item;
});
->field('coupon_user_id,uid,coupon_title,coupon_price,start_time,end_time')
->select()->each(function ($item) {
$item['describe'] = '仅限平台指定商家商品可使用';
return $item;
});
}
// }
@ -563,32 +563,32 @@ class StoreOrderCreateRepository extends StoreOrderRepository
$pay_price = $org_price;
}
//计算总红包金额
$a=0;
if($consumption_id>0){
if($this->store_consumption_user){
if($this->store_consumption_user['type']==2){
$a=bcdiv($pay_price,6);
if($this->store_consumption_user['balance']>$a){
$a = 0;
if ($consumption_id > 0) {
if ($this->store_consumption_user) {
if ($this->store_consumption_user['type'] == 2) {
$a = bcdiv($pay_price, 6);
if ($this->store_consumption_user['balance'] > $a) {
$pay_price = bcsub($pay_price, $a, 2);
$this->consumption_money= bcadd($this->consumption_money,$a);
$this->store_consumption_user['balance']= bcsub($this->store_consumption_user['balance'],$a);
}else{
$a= $this->store_consumption_user['balance'];
$this->consumption_money = bcadd($this->consumption_money, $a);
$this->store_consumption_user['balance'] = bcsub($this->store_consumption_user['balance'], $a);
} else {
$a = $this->store_consumption_user['balance'];
$pay_price = bcsub($pay_price, $this->store_consumption_user['balance'], 2);
$this->consumption_money= bcadd($this->consumption_money,$this->store_consumption_user['balance']);
$this->store_consumption_user['balance']= 0;
$this->consumption_money = bcadd($this->consumption_money, $this->store_consumption_user['balance']);
$this->store_consumption_user['balance'] = 0;
}
}
if($this->store_consumption_user['type']==1){
if($pay_price > $this->store_consumption_user['balance']){
$pay_price = bcsub($pay_price, $this->store_consumption_user['balance'], 2);
$this->consumption_money=$this->store_consumption_user['balance'];
$a=$this->store_consumption_user['balance'];
}else{
$pay_price=0;
$this->consumption_money=$pay_price;
$a=$this->consumption_money;
}
if ($this->store_consumption_user['type'] == 1) {
if ($pay_price > $this->store_consumption_user['balance']) {
$pay_price = bcsub($pay_price, $this->store_consumption_user['balance'], 2);
$this->consumption_money = $this->store_consumption_user['balance'];
$a = $this->store_consumption_user['balance'];
} else {
$this->consumption_money = $pay_price;
$pay_price = 0;
$a = $this->consumption_money;
}
}
}
}
@ -599,7 +599,6 @@ class StoreOrderCreateRepository extends StoreOrderRepository
foreach ($fn as $callback) {
$callback();
}
$merchantCart['order']['order_type'] = $order_type;
$merchantCart['order']['total_give_integral'] = $total_give_integral;
$merchantCart['order']['total_integral_price'] = $total_integral_price;
@ -636,7 +635,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
$total_price = $order_total_price;
$openIntegral = $merIntegralFlag && !$order_type && $sysIntegralConfig['integral_status'] && $sysIntegralConfig['integral_money'] > 0;
$total_coupon = bcadd($order_svip_discount, bcadd(bcadd($total_platform_coupon_price, $order_coupon_price, 2), $order_total_integral_price, 2), 2);
$is_self_pickup=true;
$is_self_pickup = true;
return compact(
'is_self_pickup',
'order_type',
@ -669,10 +668,10 @@ class StoreOrderCreateRepository extends StoreOrderRepository
) + ['allow_address' => !$allow_no_address, 'order_delivery_status' => $orderDeliveryStatus];
}
public function v2CreateOrder(int $pay_type, $user, array $cartId, array $extend, array $mark, array $receipt_data, array $takes = null, array $useCoupon = null, bool $useIntegral = false, int $addressId = null, array $post, int $product_type = 0,$consumption_id=0)
public function v2CreateOrder(int $pay_type, $user, array $cartId, array $extend, array $mark, array $receipt_data, array $takes = null, array $useCoupon = null, bool $useIntegral = false, int $addressId = null, array $post, int $product_type = 0, $consumption_id = 0)
{
$uid = $user->uid;
$orderInfo = $this->v2CartIdByOrderInfo($user, $cartId, $takes, $useCoupon, $useIntegral, $addressId, true,$consumption_id);
$orderInfo = $this->v2CartIdByOrderInfo($user, $cartId, $takes, $useCoupon, $useIntegral, $addressId, true, $consumption_id);
$order_model = $orderInfo['order_model'];
$order_extend = $orderInfo['order_extend'];
if (!$orderInfo['order_delivery_status']) {
@ -745,7 +744,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
$merchantRepository = app()->make(MerchantRepository::class);
$giveCouponIds = [];
$ex = systemConfig('extension_status');//是否开启分销
$ex = systemConfig('extension_status'); //是否开启分销
$address = $orderInfo['address'];
$allUseCoupon = $orderInfo['usePlatformCouponId'] ? [$orderInfo['usePlatformCouponId']] : [];
$totalNum = 0;
@ -946,22 +945,21 @@ class StoreOrderCreateRepository extends StoreOrderRepository
]);
$user->save();
}
if ($groupOrder['consumption_money'] > 0) {
$balance=0;
$store_consumption_user= Db::name('store_consumption_user')->where('coupon_user_id',$groupOrder['coupon_user_id'])->where('status',0)->find();
if($store_consumption_user){
if($store_consumption_user['type']==1){
if($store_consumption_user['balance']>$groupOrder['consumption_money']){
$balance=['balance'=>bcsub($store_consumption_user['balance'],$groupOrder['consumption_money'],2)];
Db::name('store_consumption_user')->where('coupon_user_id',$groupOrder['coupon_user_id'])->update();
}else{
$balance=['balance'=>0,'status'=>1];
Db::name('store_consumption_user')->where('coupon_user_id',$groupOrder['coupon_user_id'])->update();
$balance = 0;
$store_consumption_user = Db::name('store_consumption_user')->where('coupon_user_id', $groupOrder['coupon_user_id'])->where('status', 0)->find();
if ($store_consumption_user) {
if ($store_consumption_user['type'] == 1) {
if ($store_consumption_user['balance'] > $groupOrder['consumption_money']) {
$balance = bcsub($store_consumption_user['balance'], $groupOrder['consumption_money'], 2);
$balanceArr = ['balance' => $balance];
Db::name('store_consumption_user')->where('coupon_user_id', $groupOrder['coupon_user_id'])->update($balanceArr);
} else {
$balanceArr = ['balance' => 0, 'status' => 1];
Db::name('store_consumption_user')->where('coupon_user_id', $groupOrder['coupon_user_id'])->update($balanceArr);
}
}
}
}
app()->make(UserBillRepository::class)->decBill($user['uid'], 'consumption', 'deduction', [
'link_id' => $groupOrder['group_order_id'],
'status' => 1,
@ -1013,7 +1011,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
'type' => 'deduction',
'number' => $order['consumption_money'],
'balance' => 0,
'mark' => '购买商品使用积分抵扣' .$order['consumption_money']. '元',
'mark' => '购买商品使用积分抵扣' . $order['consumption_money'] . '元',
'mer_id' => $order['mer_id'],
'status' => 1
];
@ -1087,14 +1085,14 @@ class StoreOrderCreateRepository extends StoreOrderRepository
$order_cart['active'] = $cart['productDiscount'];
$order_cart['activeSku'] = $cart['productDiscountAttr'];
}
$product_source_id=0;
$product_mer_id=0;
if($cart['source']==103){
$old_product_id=Db::name('store_product')->where('product_id',$cart['product_id'])->value('old_product_id');
if($old_product_id){
$old_mer_id=Db::name('store_product')->where('product_id',$old_product_id)->value('mer_id');
$product_mer_id=$old_mer_id;
$product_source_id=$old_product_id;
$product_source_id = 0;
$product_mer_id = 0;
if ($cart['source'] == 103) {
$old_product_id = Db::name('store_product')->where('product_id', $cart['product_id'])->value('old_product_id');
if ($old_product_id) {
$old_mer_id = Db::name('store_product')->where('product_id', $old_product_id)->value('mer_id');
$product_mer_id = $old_mer_id;
$product_source_id = $old_product_id;
}
}
$orderProduct[] = [