WIN-2308041133\Administrator 5 months ago
parent
commit
35d0865aac

+ 30 - 20
app/common/repositories/store/order/StoreOrderRepository.php

@@ -1036,6 +1036,7 @@ class StoreOrderRepository extends BaseRepository
     {
         // 根据订单ID和用户ID(如果存在)查询订单,排除已删除的订单。
         $order = $this->dao->searchAll(!$user ? [] : ['uid' => $user->uid])->where('order_id', $id)->where('StoreOrder.is_del', '<>', 1)->find();
+        $this->getOrderAward($order);
         // 如果订单不存在,则抛出验证异常。
         if (!$order)
             throw new ValidateException('订单不存在');
@@ -1076,7 +1077,7 @@ class StoreOrderRepository extends BaseRepository
         // 触发订单领取后的事件。
         event('order.take', compact('order'));
 //        订单赠送的分红额度和积分处理还是礼包购买数处理
-        $this->getOrderAward($order);
+//        $this->getOrderAward($order);
     }
 
 //    订单收货赠送分红额度
@@ -1084,7 +1085,7 @@ class StoreOrderRepository extends BaseRepository
     {
         $cartIdArray = explode(',', $order['cart_id']); // 使用逗号分割字符串
         $product_id = StoreCart::where('id', $cartIdArray[0])->value('product_id');
-        $product_type = StoreProduct::where('id', $product_id)->value('type');
+        $product_type = StoreProduct::where('product_id', $product_id)->value('type');
         // 创建用户账单仓库实例
         $make = app()->make(UserBillRepository::class);
         $user = User::where('uid', $order['uid'])->find();
@@ -1170,6 +1171,7 @@ class StoreOrderRepository extends BaseRepository
     public function getSpreadIntegral($order, $type,$user)
     {
 //        $spread_uid = User::where('uid', $order['uid'])->value('spread_uid');
+        $order_award_range=0;
         if ($user['spread_uid']!=0){
             $make = app()->make(UserBillRepository::class);
             switch ($type) {
@@ -1178,15 +1180,17 @@ class StoreOrderRepository extends BaseRepository
                 case 5:  //节能油商品
                     $award_integral = User::where('uid',$user['spread_uid'])->value('award_integral');
                     $order_award_range = bcmul($order['pay_price'], 0.06, 2);
-                    $after = bcadd($award_integral, $order_award_range, 2);
-                    $make->incBill($user['spread_uid'], 'award_integral', 'spread_oil_integral', [
-                        'number' => $order['pay_price'],
-                        'title' => '下级节能油订单获得分红积分',
-                        'balance' => $after,
-                        'status' => 1,
-                        'link_id' => $order['id'],
-                        'mark' => $user['nickname'] . '成功消费节能油商品' . floatval($order['pay_price']) . '元,奖励上级分红积分' . $order_award_range,
-                    ]);
+                    if ($order_award_range>0){
+                        $after = bcadd($award_integral, $order_award_range, 2);
+                        $make->incBill($user['spread_uid'], 'award_integral', 'spread_oil_integral', [
+                            'number' => $order['pay_price'],
+                            'title' => '下级节能油订单获得分红积分',
+                            'balance' => $after,
+                            'status' => 1,
+                            'link_id' => $order['id'],
+                            'mark' => $user['nickname'] . '成功消费节能油商品' . floatval($order['pay_price']) . '元,奖励上级分红积分' . $order_award_range,
+                        ]);
+                    }
                     break;
                 case 6:  //礼包商品
                     $remainder = bcmod($user['pack_count'], 3);  //取余
@@ -1202,17 +1206,23 @@ class StoreOrderRepository extends BaseRepository
                                 $order_award_range = bcmul($order['pay_price'], 0.5, 2);
                             break;
                     }
-                    $after = bcadd($award_integral, $order_award_range, 2);
-                    $make->incBill($user['spread_uid'], 'award_integral', 'spread_oil_integral', [
-                        'number' => $order['pay_price'],
-                        'title' => '下级礼包订单获得分红积分',
-                        'balance' => $after,
-                        'status' => 1,
-                        'link_id' => $order['id'],
-                        'mark' => $user['nickname'] . '成功消费礼包商品' . floatval($order['pay_price']) . '元,奖励上级分红积分' . $order_award_range,
-                    ]);
+                    if ($order_award_range>0){
+                        $after = bcadd($award_integral, $order_award_range, 2);
+                        $make->incBill($user['spread_uid'], 'award_integral', 'spread_oil_integral', [
+                            'number' => $order['pay_price'],
+                            'title' => '下级礼包订单获得分红积分',
+                            'balance' => $after,
+                            'status' => 1,
+                            'link_id' => $order['id'],
+                            'mark' => $user['nickname'] . '成功消费礼包商品' . floatval($order['pay_price']) . '元,奖励上级分红积分' . $order_award_range,
+                        ]);
+                    }
                     break;
             }
+            if ($order_award_range>0){//检查上级积分是否达到提现条件
+                $UserRepository = app()->make(UserRepository::class);
+                $UserRepository->checkAward($user['spread_uid']);
+            }
             User::where('uid', $user['spread_uid'])->update(['award_integral'=>$after]);
         }
     }

+ 1 - 1
app/common/repositories/user/UserRepository.php

@@ -2675,7 +2675,7 @@ class UserRepository extends BaseRepository
     {
         return app()->make(AwardIntegralPriceRepository::class)->awardIntegralPrice();
     }
-
+//检测用户积分乘积分价格后是否超过分红额度,如果超过则提取分红积分
     public function checkAward($uid)
     {
         $info = $this->dao->get($uid);