hrjy 2 سال پیش
والد
کامیت
261bfb58e3
3فایلهای تغییر یافته به همراه146 افزوده شده و 44 حذف شده
  1. 1 1
      app/api/controller/order/StoreOrderController.php
  2. 107 33
      app/api/controller/user/UserController.php
  3. 38 10
      app/models/store/StoreOrder.php

+ 1 - 1
app/api/controller/order/StoreOrderController.php

@@ -263,7 +263,7 @@ class StoreOrderController
         foreach ($order['cartInfo'] as $v) {
             if ($v['combination_id']) return app('json')->fail('拼团产品不能再来一单,请在拼团产品内自行下单!');
             else if ($v['bargain_id']) return app('json')->fail('砍价产品不能再来一单,请在砍价产品内自行下单!');
-            else if ($v['seckill_id']) return app('json')->ail('秒杀产品不能再来一单,请在秒杀产品内自行下单!');
+            else if ($v['seckill_id']) return app('json')->fail('秒杀产品不能再来一单,请在秒杀产品内自行下单!');
             else $res[] = StoreCart::setCart($request->uid(), $v['product_id'], $v['cart_num'], isset($v['productInfo']['attrInfo']['unique']) ? $v['productInfo']['attrInfo']['unique'] : '', 'product', 0, 0);
         }
         $cateId = [];

+ 107 - 33
app/api/controller/user/UserController.php

@@ -636,10 +636,9 @@ class UserController
 //            UserSingleAward::where('uid', $item['uid'])->dec('grant', $item['number'])->update();
 //        }
 //        halt(111);
-        $start = strtotime('yesterday');
-        $end = strtotime('today');
+        $start = strtotime('today');
+        $end = strtotime('tomorrow');
         $money = StoreOrder::where('paid', 1)->whereBetweenTime('add_time',  $start, $end)->where('is_explosion_order', 1)->sum('pay_price'); // 全网业绩
-
         $userUid = User::where('level', 1)->column('uid');//当前是会员的用户
         $userOrder = StoreOrder::where('paid', 1)->where('is_explosion_order', 1)->sum('total_num');
         $partnerCount = User::where('level', '>=',2)->count();//合伙人总数
@@ -705,32 +704,70 @@ class UserController
                 $award = $model->where('uid', $vo['uid'])->where('status', 0)->select()->toArray();
                 if ($award) {
                     $bdjl = 0; // 爆单剩余奖励
+                    $moneyjl = 0;//余额奖励
                     foreach ($award as &$item) {
+                        $bs = $item['money'] /7000;
+                        $brokerage = $bs * 4000;//该订单应改获得的佣金
                         $surplus = $item['money'] - $item['grant'];
-                        if ($jl > 0){
-                            if ($surplus < $jl) {
-                                $bdjl += $surplus;
-                                $jl -= $surplus;
-                                $item['status'] = 1;
-                                $item['grant'] = $item['money'];
-                            } else {
-                                $bdjl += $jl;
-                                $item['grant'] += $jl;
-                                $jl = 0;
+                        if($jl > 0){
+                            if ($item['grant'] < $brokerage){
+                                if ($item['grant'] + $jl > $brokerage){
+                                    $bdjl += $brokerage - $item['grant'];//能够发放的佣金
+                                    $moneyjl += $jl - $bdjl;// 能够发放的余额
+                                    $item['grant'] += $jl;
+                                    $jl = 0;
+
+                                }else{
+                                    $bdjl = $jl;//能够发放的佣金
+                                    $item['grant'] += $jl;
+                                    $jl = 0;
+                                }
+                            }else{
+                                if ($surplus < $jl){
+                                    $moneyjl += $surplus;
+                                    $jl -= $surplus;
+                                    $item['status'] = 1;
+                                    $item['grant'] = $item['money'];
+                                }else{
+                                    $moneyjl += $jl;
+                                    $item['grant'] += $jl;
+                                    $jl = 0;
+                                }
                             }
+
                         }
+
                     }
+//                        $surplus = $item['money'] - $item['grant'];
+//                        if ($jl > 0){
+//                            if ($surplus < $jl) {
+//                                $bdjl += $surplus;
+//                                $jl -= $surplus;
+//                                $item['status'] = 1;
+//                                $item['grant'] = $item['money'];
+//                            } else {
+//                                $bdjl += $jl;
+//                                $item['grant'] += $jl;
+//                                $jl = 0;
+//                            }
+//                        }
                     $model->saveAll($award);
-                    UserBill::income('佣金', $vo['uid'], 'now_money', 'brokerage', $userjl, '', $vo['brokerage_price'] + $userjl, '会员分红');
-                    if ($vo['level'] == 3){
-//                        UserBill::income('佣金', $vo['uid'], 'now_money', 'brokerage', $partnerjl, '', $vo['brokerage_price'] + $bdjl, '合伙人分红');
-                        UserBill::income('佣金', $vo['uid'], 'now_money', 'brokerage', $shareholderjl, '', $vo['brokerage_price'] + $userjl+ $shareholderjl, '股东分红');
-                    }elseif ($vo['level'] == 4){
-//                        UserBill::income('佣金', $vo['uid'], 'now_money', 'brokerage', $partnerjl, '', $vo['brokerage_price'] + $bdjl, '合伙人分红');
-                        UserBill::income('佣金', $vo['uid'], 'now_money', 'brokerage', $shareholderjl, '', $vo['brokerage_price'] + $userjl + $shareholderjl, '股东分红');
-                        UserBill::income('佣金', $vo['uid'], 'now_money', 'brokerage', $directorjl, '', $vo['brokerage_price'] + $userjl + $shareholderjl + $directorjl, '董事分红');
+                    $nowUser = User::where('uid', $vo['uid'])->find();
+                    if ($bdjl > 0){
+                        UserBill::income('佣金', $vo['uid'], 'now_money', 'brokerage', $userjl, '', $nowUser['brokerage_price'] + $bdjl, '会员分红');
+                        if ($vo['level'] == 3){
+                            UserBill::income('佣金', $vo['uid'], 'now_money', 'brokerage', $shareholderjl, '', $nowUser['brokerage_price'] + $bdjl, '股东分红');
+                        }elseif ($vo['level'] == 4){
+                            UserBill::income('佣金', $vo['uid'], 'now_money', 'brokerage', $shareholderjl, '', $nowUser['brokerage_price'] + $bdjl, '股东分红');
+                            UserBill::income('佣金', $vo['uid'], 'now_money', 'brokerage', $directorjl, '', $nowUser['brokerage_price'] + $bdjl, '董事分红');
+                        }
+                        User::where('uid', $vo['uid'])->inc('brokerage_price', $bdjl)->update();
                     }
-                    User::where('uid', $vo['uid'])->inc('brokerage_price', $bdjl)->update();
+                    if ($moneyjl > 0){
+                        UserBill::income('余额', $vo['uid'], 'now_money', 'fhjl', $moneyjl, '', $nowUser['now_money']+$moneyjl, '分红余额奖励');
+                        User::where('uid', $vo['uid'])->inc('now_money', $moneyjl)->update();
+                    }
+
 
 //                    if ($vo['level'] == 1){
                     // 如果是会员
@@ -741,24 +778,61 @@ class UserController
                             $award = $model->where('uid', $spread['uid'])->where('status', 0)->select()->toArray();
                             if ($award){
                                 $bdjl = 0; // 爆单剩余奖励
+                                $moneyjl = 0;//余额奖励
                                 foreach ($award as &$item){
+                                    $bs = $item['money'] /7000;
+                                    $brokerage = $bs * 4000;//该订单应改获得的佣金
                                     $surplus = $item['money'] - $item['grant'];
-                                    if ($sp_jl > 0){
-                                        if ($surplus < $sp_jl){
-                                            $bdjl += $surplus;
-                                            $sp_jl -= $surplus;
-                                            $item['status'] = 1;
-                                            $item['grant'] = $item['money'];
+                                    if($sp_jl > 0){
+                                        if ($item['grant'] < $brokerage){
+                                            if ($item['grant'] + $sp_jl > $brokerage){
+                                                $bdjl += $brokerage - $item['grant'];//能够发放的佣金
+                                                $moneyjl += $sp_jl - $bdjl;// 能够发放的余额
+                                                $item['grant'] += $sp_jl;
+                                                $sp_jl = 0;
+
+                                            }else{
+                                                $bdjl = $sp_jl;//能够发放的佣金
+                                                $item['grant'] += $sp_jl;
+                                                $sp_jl = 0;
+                                            }
                                         }else{
-                                            $bdjl += $sp_jl;
-                                            $item['grant'] += $sp_jl;
-                                            $sp_jl = 0;
+                                            if ($surplus < $sp_jl){
+                                                $moneyjl += $surplus;
+                                                $sp_jl -= $surplus;
+                                                $item['status'] = 1;
+                                                $item['grant'] = $item['money'];
+                                            }else{
+                                                $moneyjl += $sp_jl;
+                                                $item['grant'] += $sp_jl;
+                                                $sp_jl = 0;
+                                            }
                                         }
+
                                     }
+//                                    if ($sp_jl > 0){
+//                                        if ($surplus < $sp_jl){
+//                                            $bdjl += $surplus;
+//                                            $sp_jl -= $surplus;
+//                                            $item['status'] = 1;
+//                                            $item['grant'] = $item['money'];
+//                                        }else{
+//                                            $bdjl += $sp_jl;
+//                                            $item['grant'] += $sp_jl;
+//                                            $sp_jl = 0;
+//                                        }
+//                                    }
                                 }
                                 $model->saveAll($award);
-                                UserBill::income('佣金', $spread['uid'], 'now_money', 'brokerage', $userjl, '', $spread['brokerage_price']+$userjl, '合伙人分红');
-                                User::where('uid', $spread['uid'])->inc('brokerage_price', $bdjl)->update();
+                                if ($bdjl > 0){
+                                    UserBill::income('佣金', $spread['uid'], 'now_money', 'brokerage', $bdjl, '', $spread['brokerage_price']+$bdjl, '合伙人分红');
+                                    User::where('uid', $spread['uid'])->inc('brokerage_price', $bdjl)->update();
+                                }
+                                if ($moneyjl > 0){
+                                    UserBill::income('余额', $spread['uid'], 'now_money', 'fhjl', $moneyjl, '', $spread['now_money']+$moneyjl, '合伙人余额奖励');
+                                    User::where('uid', $spread['uid'])->inc('now_money', $moneyjl)->update();
+                                }
+
                             }
                         }
 //                        }

+ 38 - 10
app/models/store/StoreOrder.php

@@ -807,22 +807,50 @@ class StoreOrder extends BaseModel
                     $group_purchase = sys_config('push');
                     $jl = round($order['pay_price'] * ($group_purchase/100), 2); // 应奖励金额
                     $bdjl = 0; // 爆单剩余奖励
+                    $moneyjl = 0;//余额奖励
                     foreach ($award as &$item){
+                        $bs = $item['money'] /7000;
+                        $brokerage = $bs * 4000;//该订单应改获得的佣金
                         $surplus = $item['money'] - $item['grant'];
-                        if ($surplus < $jl){
-                            $bdjl += $surplus;
-                            $jl -= $surplus;
-                            $item['status'] = 1;
-                            $item['grant'] = $item['money'];
-                        }else{
-                            $bdjl += $jl;
-                            $item['grant'] += $jl;
+                        if($jl > 0){
+                            if ($item['grant'] < $brokerage){
+                                if ($item['grant'] + $jl > $brokerage){
+                                    $bdjl += $brokerage - $item['grant'];//能够发放的佣金
+                                    $moneyjl += $jl - $bdjl;// 能够发放的余额
+                                    $item['grant'] += $jl;
+                                    $jl = 0;
+
+                                }else{
+                                    $bdjl = $jl;//能够发放的佣金
+                                    $item['grant'] += $jl;
+                                    $jl = 0;
+                                }
+                            }else{
+                                if ($surplus < $jl){
+                                    $moneyjl += $surplus;
+                                    $jl -= $surplus;
+                                    $item['status'] = 1;
+                                    $item['grant'] = $item['money'];
+                                }else{
+                                    $moneyjl += $jl;
+                                    $item['grant'] += $jl;
+                                    $jl = 0;
+                                }
+                            }
+
                         }
+
                     }
                     $model->saveAll($award);
+                    if ($bdjl > 0){
+                        UserBill::income('佣金', $spread['uid'], 'now_money', 'brokerage', $bdjl, '', $spread['brokerage_price']+$bdjl, '分享佣金奖励');
+                        User::where('uid', $spread['uid'])->inc('brokerage_price', $bdjl)->update();
+                    }
+                    if ($moneyjl > 0){
+                        UserBill::income('余额', $spread['uid'], 'now_money', 'yujl', $moneyjl, '', $spread['now_money']+$moneyjl, '分享余额奖励');
+                        User::where('uid', $spread['uid'])->inc('now_money', $moneyjl)->update();
+                    }
 
-                    UserBill::income('佣金', $spread['uid'], 'now_money', 'brokerage', $bdjl, '', $spread['brokerage_price']+$bdjl, '分享佣金奖励');
-                    User::where('uid', $spread['uid'])->inc('brokerage_price', $bdjl)->update();
                 }
                 User::where('uid', $spread['uid'])->inc('stock_right', 1)->update();
             }