Merge branch 'dev' of https://gitea.lihaink.cn/mkm/shop-php into dev
This commit is contained in:
commit
e066be0bbc
@ -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;
|
||||
@ -633,10 +632,10 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
||||
$status = ($address || $order_model || $allow_no_address) ? ($noDeliver ? 'noDeliver' : 'finish') : 'noAddress';
|
||||
$order = $merchantCartList;
|
||||
$consumption_money = $this->consumption_money;
|
||||
$total_price = bcsub($order_total_price,$consumption_money,2);
|
||||
$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)
|
||||
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);
|
||||
$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;
|
||||
@ -948,20 +947,20 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
||||
}
|
||||
|
||||
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('uid',$uid)->where('coupon_user_id', $groupOrder['consumption_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', $store_consumption_user['coupon_user_id'])->update($balanceArr);
|
||||
} else {
|
||||
$balanceArr = ['balance' => 0, 'status' => 1];
|
||||
Db::name('store_consumption_user')->where('coupon_user_id', $store_consumption_user['coupon_user_id'])->update($balanceArr);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
app()->make(UserBillRepository::class)->decBill($user['uid'], 'consumption', 'deduction', [
|
||||
'link_id' => $groupOrder['group_order_id'],
|
||||
'status' => 1,
|
||||
@ -1003,22 +1002,6 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
||||
];
|
||||
}
|
||||
|
||||
if ($order['consumption_money'] > 0) {
|
||||
$bills[] = [
|
||||
'uid' => $uid,
|
||||
'link_id' => $_order->order_id,
|
||||
'pm' => 0,
|
||||
'title' => '红包抵扣',
|
||||
'category' => 'mer_integral',
|
||||
'type' => 'deduction',
|
||||
'number' => $order['consumption_money'],
|
||||
'balance' => 0,
|
||||
'mark' => '购买商品使用积分抵扣' .$order['consumption_money']. '元',
|
||||
'mer_id' => $order['mer_id'],
|
||||
'status' => 1
|
||||
];
|
||||
}
|
||||
|
||||
//创建发票信息
|
||||
if (isset($receipt_data[$_order['mer_id']])) {
|
||||
app()->make(StoreOrderReceiptRepository::class)->add($receipt_data[$_order['mer_id']], $_order);
|
||||
@ -1087,14 +1070,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[] = [
|
||||
|
@ -86,6 +86,7 @@ class StoreOrder extends BaseController
|
||||
$mark = (array)$this->request->param('mark', []);
|
||||
$payType = $this->request->param('pay_type');
|
||||
$post = (array)$this->request->param('post');
|
||||
$consumption_id = (int)$this->request->param('consumption_id',0);
|
||||
$isPc = $payType === 'pc';
|
||||
if ($isPc) {
|
||||
$payType = 'balance';
|
||||
@ -103,8 +104,8 @@ class StoreOrder extends BaseController
|
||||
if (!($count = count($cartId)) || $count != count($cartRepository->validIntersection($cartId, $uid)))
|
||||
return app('json')->fail('数据无效');
|
||||
|
||||
$groupOrder = app()->make(LockService::class)->exec('order.create', function () use ($orderCreateRepository, $receipt_data, $mark, $extend, $cartId, $payType, $takes, $couponIds, $useIntegral, $addressId, $post) {
|
||||
return $orderCreateRepository->v2CreateOrder(array_search($payType, StoreOrderRepository::PAY_TYPE), $this->request->userInfo(), $cartId, $extend, $mark, $receipt_data, $takes, $couponIds, $useIntegral, $addressId, $post);
|
||||
$groupOrder = app()->make(LockService::class)->exec('order.create', function () use ($orderCreateRepository, $receipt_data, $mark, $extend, $cartId, $payType, $takes, $couponIds, $useIntegral, $addressId, $post,$consumption_id) {
|
||||
return $orderCreateRepository->v2CreateOrder(array_search($payType, StoreOrderRepository::PAY_TYPE), $this->request->userInfo(), $cartId, $extend, $mark, $receipt_data, $takes, $couponIds, $useIntegral, $addressId, $post,0,$consumption_id);
|
||||
});
|
||||
|
||||
if ($groupOrder['pay_price'] == 0) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user