hehao vor 1 Jahr
Ursprung
Commit
bccba4d938

+ 52 - 37
app/common/repositories/store/order/StoreOrderRepository.php

@@ -117,7 +117,7 @@ class StoreOrderRepository extends BaseRepository
117 117
      * @author xaboy
118 118
      * @day 2020/8/1
119 119
      */
120
-    public function createOrder(User $user, int $pay_type, array $cartId, int $addressId, array $coupons, array $takes, array $mark, bool $psType = true, $table_id = null, $share_id = 0, $payType, $mer_id = 0, $dacang_id = 0, $distribution_mode = 1, $ziti_address = '', $area_manage_address_ids = '',$youhui_price_key='',$decScore=0,$decJingScore=0)
120
+    public function createOrder(User $user, int $pay_type, array $cartId, int $addressId, array $coupons, array $takes, array $mark, bool $psType = true, $table_id = null, $share_id = 0, $payType, $mer_id = 0, $dacang_id = 0, $distribution_mode = 1, $ziti_address = '', $area_manage_address_ids = '',$youhui_price_key='',$cartIdAndPayTypMap)
121 121
     {
122 122
         $test_user = $user['test_user'] ?? 0;
123 123
         $address = Db::name('user_address')->field('code_list,village_id')->where('address_id', $addressId)->find();
@@ -784,7 +784,7 @@ class StoreOrderRepository extends BaseRepository
784 784
             $productRepository = app()->make(ProductRepository::class);
785 785
             $storeOrderProductRepository = app()->make(StoreOrderProductRepository::class);
786 786
 
787
-            $group = Db::transaction(function () use ($topUid, $spreadUid, $uid, $productCouponList, $storeCouponList, $allUseCoupon, $couponUserRepository, $storeOrderProductRepository, $productRepository, $attrValueRepository, $storeCartRepository, $storeGroupOrderRepository, $groupOrder, $orderList, $orderInfo ,$decJingScore, $decScore, $payType) {
787
+            $group = Db::transaction(function () use ($topUid, $spreadUid, $uid, $productCouponList, $storeCouponList, $allUseCoupon, $couponUserRepository, $storeOrderProductRepository, $productRepository, $attrValueRepository, $storeCartRepository, $storeGroupOrderRepository, $groupOrder, $orderList, $orderInfo ,$cartIdAndPayTypMap) {
788 788
                 $cartIds = [];
789 789
                 $uniqueList = [];
790 790
                 //更新库存
@@ -827,6 +827,8 @@ class StoreOrderRepository extends BaseRepository
827 827
                     $_orderInfo = $order['orderInfo'];
828 828
                     unset($order['cartInfo'], $order['orderInfo']);
829 829
                     $_order = $this->dao->create($order);
830
+
831
+                    $decScore = $decJingScore = 0;
830 832
                     foreach ($cartInfo as $k => $cart) {
831 833
 //                        $is_dacang=Db::name('da_cang_user')->where('status',1)->where('uid',$uid)->find();
832 834
 //                        $is_dacang_product = Db::name('store_product')->where('product_id',$cart['product_id'])->field('type,seckill')->find();
@@ -892,44 +894,57 @@ class StoreOrderRepository extends BaseRepository
892 894
                                 'product_type' => $cart['product_type']
893 895
                             ])
894 896
                         ];
897
+
898
+                        $cartId = $cart['cart_id'];
899
+                        $storeProduct = Db::name('store_product')->where('product_id', $cartInfo['product_id'])->find();
900
+                        $productDecScore = $storeProduct['score'];
901
+                        $productDecJingdou = $storeProduct['jingdou'];
902
+                        if ($cartIdAndPayTypMap[$cartId] == 'score') {
903
+                            $decScore += $productDecScore;
904
+                        } else if ($cartIdAndPayTypMap[$cartId] == 'jingdou') {
905
+                            $decJingScore += $productDecJingdou;
906
+                        }
895 907
                     }
896
-                }
897 908
 
898
-                if ($decScore) {
899
-                    //更新用户积分
900
-                    $user = Db::name('user')->where('uid', $uid)->find();
901
-                    $user_score = $user['score'];
902
-                    $ins_data['uid'] = $uid;
903
-                    $ins_data['reward_socre'] = $decScore;
904
-                    $ins_data['addtime'] = time();
905
-                    $ins_data['status'] = -1;//京豆状态1-有效 0-失效 -1待确认 创建的时候-1待确认 取消订单返还积分变为0 支付成功变为1
906
-                    $ins_data['order_type'] = 'store_order';
907
-                    $ins_data['order_id'] = $_order->order_id;
908
-                    $ins_data['mark'] = "兑换商品预扣积分";
909
-                    $ins_data['desc'] = '';
910
-                    $ins_data['surplus'] = $user_score - $decScore;
911
-                    $ins_data['type'] = 4;
912
-                    $ins_data['pm'] = 2;
913
-                    Db::name('user_sign_score')->insertGetId($ins_data);
914
-                    Db::name('user')->where('uid', $uid)->dec('score', $decScore)->update();
915
-                }
916
-                if ($decJingScore) {
917
-                    //更新用户京豆
918
-                    $user = Db::name('user')->where('uid', $uid)->find();
919
-                    $userJingdou = $user['jingdou'];
920
-                    $ins_data['uid'] = $uid;
921
-                    $ins_data['number'] = $decJingScore;
922
-                    $ins_data['status'] = -1;//京豆状态1-有效 0-失效 -1待确认 创建的时候-1待确认 取消订单返还积分变为0 支付成功变为1
923
-                    $ins_data['mark'] = "购买商品预扣京豆";
924
-                    $ins_data['desc'] = "购买商品预扣京豆";
925
-                    $ins_data['order_id'] = $_order->order_id;
926
-                    $ins_data['surplus'] = $userJingdou - $decJingScore;
927
-                    $ins_data['order_type'] = 'store_order';
928
-                    $ins_data['type'] = 2;
929
-                    $ins_data['addtime'] = time();
930
-                    Db::name('user_sign_jingdou')->insertGetId($ins_data);
931
-                    Db::name('user')->where('uid', $uid)->dec('jingdou', $decJingScore)->update();
909
+
910
+                    if ($decScore) {
911
+                        $decScore = $productDecScore;
912
+                        //更新用户积分
913
+                        $user = Db::name('user')->where('uid', $uid)->find();
914
+                        $user_score = $user['score'];
915
+                        $ins_data['uid'] = $uid;
916
+                        $ins_data['reward_socre'] = $decScore;
917
+                        $ins_data['addtime'] = time();
918
+                        $ins_data['status'] = -1;//京豆状态1-有效 0-失效 -1待确认 创建的时候-1待确认 取消订单返还积分变为0 支付成功变为1
919
+                        $ins_data['order_type'] = 'store_order';
920
+                        $ins_data['order_id'] = $_order->order_id;
921
+                        $ins_data['mark'] = "兑换商品预扣积分";
922
+                        $ins_data['desc'] = '';
923
+                        $ins_data['surplus'] = $user_score - $decScore;
924
+                        $ins_data['type'] = 4;
925
+                        $ins_data['pm'] = 2;
926
+                        Db::name('user_sign_score')->insertGetId($ins_data);
927
+                        Db::name('user')->where('uid', $uid)->dec('score', $decScore)->update();
928
+                    }
929
+                    if ($decJingScore) {
930
+                        //更新用户京豆
931
+                        $user = Db::name('user')->where('uid', $uid)->find();
932
+                        $userJingdou = $user['jingdou'];
933
+                        $ins_data['uid'] = $uid;
934
+                        $ins_data['number'] = $decJingScore;
935
+                        $ins_data['status'] = -1;//京豆状态1-有效 0-失效 -1待确认 创建的时候-1待确认 取消订单返还积分变为0 支付成功变为1
936
+                        $ins_data['mark'] = "购买商品预扣京豆";
937
+                        $ins_data['desc'] = "购买商品预扣京豆";
938
+                        $ins_data['order_id'] = $_order->order_id;
939
+                        $ins_data['surplus'] = $userJingdou - $decJingScore;
940
+                        $ins_data['order_type'] = 'store_order';
941
+                        $ins_data['type'] = 2;
942
+                        $ins_data['addtime'] = time();
943
+                        Db::name('user_sign_jingdou')->insertGetId($ins_data);
944
+                        Db::name('user')->where('uid', $uid)->dec('jingdou', $decJingScore)->update();
945
+                    }
932 946
                 }
947
+
933 948
                 $storeOrderStatusRepository->insertAll($orderStatus);
934 949
                 $storeOrderProductRepository->insertAll($orderProduct);
935 950
                 return $groupOrder;

+ 5 - 4
app/controller/api/store/order/StoreOrder.php

@@ -122,6 +122,7 @@ class StoreOrder extends BaseController
122 122
         $ziti_address = $this->request->param('distribution_address','');//自提地址
123 123
         $youhui_price_key = $this->request->param('youhui_price_key','');//优惠key
124 124
         $cartIdAndPayTypMap = (array)$this->request->param('cartIdAndPayTypMap', []);
125
+
125 126
         if(!$cartIdAndPayTypMap){
126 127
             return app('json')->fail('支付方式不正确');
127 128
         }
@@ -162,9 +163,9 @@ class StoreOrder extends BaseController
162 163
 //            13664 => 'jingdou',
163 164
 //        ];
164 165
 //        $cartId = [
165
-//            13662,
166
-//            13663,
167
-//            13664
166
+//            13662, 订单1
167
+//            13663, 订单1
168
+//            13664  订单2
168 169
 //        ];
169 170
 
170 171
         // 商品A 后台设置是扣除60积分 或者 扣除120京豆
@@ -414,7 +415,7 @@ class StoreOrder extends BaseController
414 415
 
415 416
         makeLock()->lock();
416 417
         try {
417
-            $groupOrder = $this->repository->createOrder($this->request->userInfo(), array_search($payType, StoreOrderRepository::PAY_TYPE), $cartId, $addressId, $coupon, $take, $mark,$psType,$table_id,$share_id,$payType,$mer_id,$dacang_id,$distribution_mode,$ziti_address,$area_manage_address_ids,$youhui_price_key,$decScore,$decJingScore);
418
+            $groupOrder = $this->repository->createOrder($this->request->userInfo(), array_search($payType, StoreOrderRepository::PAY_TYPE), $cartId, $addressId, $coupon, $take, $mark,$psType,$table_id,$share_id,$payType,$mer_id,$dacang_id,$distribution_mode,$ziti_address,$area_manage_address_ids,$youhui_price_key,$cartIdAndPayTypMap);
418 419
         } catch (\Throwable $e) {
419 420
             makeLock()->unlock();
420 421
             throw $e;