WIN-2308041133\Administrator 4 months ago
parent
commit
0cdd171be6

+ 9 - 1
app/common/model/user/User.php

@@ -20,6 +20,7 @@ use app\common\model\store\staff\Staffs;
 use app\common\model\wechat\WechatUser;
 use app\common\repositories\store\coupon\StoreCouponUserRepository;
 use app\common\repositories\store\order\StoreGroupOrderRepository;
+use app\common\repositories\store\order\StoreOrderRepository;
 use app\common\repositories\store\service\StoreServiceLogRepository;
 use app\common\repositories\system\config\ConfigValueRepository;
 use app\common\repositories\user\UserBillRepository;
@@ -379,6 +380,13 @@ class User extends BaseModel
         $extensionInfo = get_extension_info($data);//获取用户是否可以分销以及是否内购
         return $extensionInfo['isPromoter'];
     }
-
+//    判断是否有推荐订单(推荐下级是否有订单)
+    public function spread_order($uid){
+//        $user = User::find($uid);
+//        $group_users = app()->make(GiftLevel::class)->get_group_user($uid);
+        $group_users = User::where('spread_uid',$uid)->column('uid');
+        $order_count = app()->make(StoreOrderRepository::class)->getWhereCount(['uid' => ['in',$group_users],'paid' => 1]);
+        return $order_count;
+    }
 
 }

+ 128 - 40
app/common/repositories/store/order/StoreOrderRepository.php

@@ -1080,7 +1080,8 @@ class StoreOrderRepository extends BaseRepository
         event('order.take', compact('order'));
 //        订单赠送的分红额度和积分处理还是礼包购买数处理,顺便检测升级
         @file_put_contents('quanju.txt', "-村上春树1\r\n", 8);
-        $this->getOrderAward($order);
+        $this->getOrderAward($order); //订单收货赠送分红额度等等
+        $this->spreadOrder($order['uid'],$order['id']);  //查找上级是否有冻结份额
     }
 
 //    订单收货赠送分红额度
@@ -1101,19 +1102,56 @@ class StoreOrderRepository extends BaseRepository
         $make = app()->make(UserBillRepository::class);
         $user = User::where('uid', $order['uid'])->find();
         $award_range = $user['award_range'];
-        if ($type == 5) {  //节能油商品
-            @file_put_contents('quanju.txt', "-村上春树2\r\n", 8);
-            $number = systemConfig('award_energy_saving_oil', 1);
+        $mark = '';
+        $integral_type = '';
+        $range_type = '';
+        if ($type == 5){
+            $mark = '节能油';
+            $range_type = 'energy_saving_oil';
+            $integral_type = 'spread_oil_integral';
+            //            发放分红积分
+            $number2 = systemConfig('award_integral_energy_saving_oil', 1);
+        }elseif ($type == 0){
+            $mark = '普通';
+            $range_type = 'ordinary';
+            $integral_type = 'ordinary_integral';
+            $number2 = systemConfig('award_integral_ordinary', 1);
+        }elseif ($type == 6){
+            $mark = '礼包';
+            $range_type = 'award_gift_pack';
+            $integral_type = 'spread_pack_integral';
+            $number2 = systemConfig('award_integral_gift_pack', 1);
+        }
+        if ($type == 5||$type == 0) {  //节能油商品和普通商品
+            $number = systemConfig('award_energy_saving_oil', 1);  //获得份额的基准线
             if ($order['pay_price'] >= $number) {
-                $order_award_range = bcmul($order['pay_price'], 3, 2);
+                $count = app()->make(User::class)->spread_order($order['uid']);  //获取推荐下级订单数
+                if ($count>0){
+                    $order_award_range = bcmul($order['pay_price'], 3, 2);
+                }else{
+                    $order_award_range = bcmul($order['pay_price'], 1, 2);
+                    $unclaimed_range = bcmul($order['pay_price'], 2, 2);
+                    $unclaimed_range_after = bcadd($user['unclaimed_range'], $unclaimed_range, 2);
+                    //                发放冻结份额
+                    $make->incBill($order['uid'], 'award_unclaimed_range', 'unclaimed_range', [
+                        'number' => $unclaimed_range,
+                        'title' => '下单商品获得冻结份额',
+                        'balance' => $unclaimed_range_after,
+                        'status' => 1,
+                        'link_id' => $order['order_id'],
+                        'mark' => $user['nickname'] . '成功消费' .$mark.'商品'. floatval($order['pay_price']) . '元,奖励冻结分红额度' . $order_award_range,
+                    ]);
+                    User::where('uid', $order['uid'])->update(['unclaimed_range' => $unclaimed_range_after]);
+                }
+//                发放分红份额
                 $after = bcadd($award_range, $order_award_range, 2);
-                $make->incBill($order['uid'], 'award_range', 'energy_saving_oil', [
+                $make->incBill($order['uid'], 'award_range', $range_type, [
                     'number' => $order_award_range,
-                    'title' => '下单节能油获得分红额度',
+                    'title' => '下单' .$mark.'商品获得分红额度',
                     'balance' => $after,
                     'status' => 1,
                     'link_id' => $order['order_id'],
-                    'mark' => $user['nickname'] . '成功消费节能油商品' . floatval($order['pay_price']) . '元,奖励分红额度' . $order_award_range,
+                    'mark' => $user['nickname'] . '成功消费' .$mark.'商品'. floatval($order['pay_price']) . '元,奖励分红额度' . $order_award_range,
                 ]);
                 User::where('uid', $order['uid'])->update(['award_range' => $after]);
             }
@@ -1137,39 +1175,58 @@ class StoreOrderRepository extends BaseRepository
             }
 //            礼包购买数
             $this->pack_count($order['uid']);
-        } else {
-//            普通商品获取分红额度
-            $number = systemConfig('award_ordinary', 1);
-            if ($order['pay_price'] >= $number) {
-                $order_award_range = bcmul($order['pay_price'], 1, 2);
-                $after = bcadd($award_range, $order_award_range, 2);
-                $make->incBill($order['uid'], 'award_range', 'ordinary', [
-                    'number' => $order_award_range,
-                    'title' => '下单普通商品获得分红额度',
-                    'balance' => $after,
-                    'status' => 1,
-                    'link_id' => $order['order_id'],
-                    'mark' => $user['nickname'] . '成功消费普通商品' . floatval($order['pay_price']) . '元,奖励分红额度' . $order_award_range,
-                ]);
-                User::where('uid', $order['uid'])->update(['award_range' => $after]);
-            }
-//            普通商品获得分红积分
-            $number2 = systemConfig('award_integral_ordinary', 1);
-            $award_integral = $user['award_integral'];
-            if ($order['pay_price'] >= $number2) {
-                $order_award_range = bcmul($order['pay_price'], 0.2, 2);
-                $after2 = bcadd($award_integral, $order_award_range, 2);
-                $make->incBill($order['uid'], 'award_integral', 'ordinary_integral', [
-                    'number' => $order_award_range,
-                    'title' => '下单普通商品获得分红积分',
-                    'balance' => $after2,
-                    'status' => 1,
-                    'link_id' => $order['order_id'],
-                    'mark' => $user['nickname'] . '成功消费普通商品' . floatval($order['pay_price']) . '元,奖励分红积分' . $order_award_range,
-                ]);
-                User::where('uid', $order['uid'])->update(['award_integral' => $after2]);
-            }
         }
+
+        $award_integral = $user['award_integral'];
+        if ($order['pay_price'] >= $number2) {
+            $order_award_range = bcmul($order['pay_price'], 0.2, 2);
+            $after2 = bcadd($award_integral, $order_award_range, 2);
+            $make->incBill($order['uid'], 'award_integral', $integral_type, [
+                'number' => $order_award_range,
+                'title' => '下单'.$mark.'商品获得分红积分',
+                'balance' => $after2,
+                'status' => 1,
+                'link_id' => $order['order_id'],
+                'mark' => $user['nickname'] . '成功消费'.$mark.'商品' . floatval($order['pay_price']) . '元,奖励分红积分' . $order_award_range,
+            ]);
+            User::where('uid', $order['uid'])->update(['award_integral' => $after2]);
+        }
+//        解冻冻结奖金
+        $UserRepository = app()->make(UserRepository::class);
+        $UserRepository->extractBrokerage($order['uid']);
+//        else {
+////            普通商品获取分红额度
+//            $number = systemConfig('award_ordinary', 1);
+//            if ($order['pay_price'] >= $number) {
+//                $order_award_range = bcmul($order['pay_price'], 1, 2);
+//                $after = bcadd($award_range, $order_award_range, 2);
+//                $make->incBill($order['uid'], 'award_range', 'ordinary', [
+//                    'number' => $order_award_range,
+//                    'title' => '下单普通商品获得分红额度',
+//                    'balance' => $after,
+//                    'status' => 1,
+//                    'link_id' => $order['order_id'],
+//                    'mark' => $user['nickname'] . '成功消费普通商品' . floatval($order['pay_price']) . '元,奖励分红额度' . $order_award_range,
+//                ]);
+//                User::where('uid', $order['uid'])->update(['award_range' => $after]);
+//            }
+//            普通商品获得分红积分
+//            $number2 = systemConfig('award_integral_ordinary', 1);
+//            $award_integral = $user['award_integral'];
+//            if ($order['pay_price'] >= $number2) {
+//                $order_award_range = bcmul($order['pay_price'], 0.2, 2);
+//                $after2 = bcadd($award_integral, $order_award_range, 2);
+//                $make->incBill($order['uid'], 'award_integral', 'ordinary_integral', [
+//                    'number' => $order_award_range,
+//                    'title' => '下单普通商品获得分红积分',
+//                    'balance' => $after2,
+//                    'status' => 1,
+//                    'link_id' => $order['order_id'],
+//                    'mark' => $user['nickname'] . '成功消费普通商品' . floatval($order['pay_price']) . '元,奖励分红积分' . $order_award_range,
+//                ]);
+//                User::where('uid', $order['uid'])->update(['award_integral' => $after2]);
+//            }
+//        }
         //份额和积分变动时触发
         @file_put_contents('quanju.txt', "-村上春树3\r\n", 8);
         $UserRepository = app()->make(UserRepository::class);
@@ -1287,6 +1344,37 @@ class StoreOrderRepository extends BaseRepository
         User::where('uid', $uid)->update(['award_integral'=>$after]);
     }
 
+//    看看上级有没有冻结份额
+    public function spreadOrder($uid,$order_id){
+        $spread_uid = User::where('uid', $uid)->value('spread_uid');
+        if ($spread_uid!=0){
+            $user = User::where('uid', $spread_uid)->find();
+            if ($user['unclaimed_range']>0){
+                $after=bcadd($user['award_range'], $user['unclaimed_range'], 2);
+                $make = app()->make(UserBillRepository::class);
+                $make->incBill($user['spread_uid'], 'award_unclaimed_range', 'spread_oil_integral', [
+                    'number' => $user['unclaimed_range'],
+                    'title' => '推荐订单解冻分红额度',
+                    'balance' => 0,
+                    'status' => 0,
+                    'link_id' => $order_id,
+                    'mark' => '下级用户'.$user['nickname'] . '成功消费,解冻上级分红份额' . $user['unclaimed_range'],
+                ]);
+                $make->decBill($user['spread_uid'], 'award_range', 'thaw_range', [
+                    'number' => $user['unclaimed_range'],
+                    'title' => '推荐订单解冻分红额度',
+                    'balance' => $after,
+                    'status' => 1,
+                    'link_id' => $order_id,
+                    'mark' => '下级用户'.$user['nickname'] . '成功消费,解冻上级分红份额' . $user['unclaimed_range'],
+                ]);
+                User::where('uid', $spread_uid)->update(['award_range' => $after,'unclaimed_range' => 0]);
+                //        解冻冻结奖金
+                $UserRepository = app()->make(UserRepository::class);
+                $UserRepository->extractBrokerage($spread_uid);
+            }
+        }
+    }
     /**
      *  获取订单列表头部统计数据
      * @Author:Qinii

+ 13 - 1
app/common/repositories/user/UserBillRepository.php

@@ -92,6 +92,9 @@ class UserBillRepository extends BaseRepository
             'award/energy_saving_oil' =>'下单节能油获得分红额度',
             'award/award_gift_pack' =>'下单礼包获得分红额度',
             'award/ordinary' =>'下单普通商品获得分红额度',
+//            'award/unclaimed_range' =>'下单商品获得冻结份额',
+            'award/thaw_range' =>'下级下单解冻份额',
+            'award/thaw_brokerage' =>'解冻冻结奖金',
         ],
         'award_integral' =>[
             'award/spread_oil_integral' =>'下级节能油订单获得分红积分',
@@ -100,7 +103,16 @@ class UserBillRepository extends BaseRepository
             'award/oil_integral' =>'节能油分红积分',
             'award/pack_integral' =>'礼包分红积分',
             'award/confirm_oil_integral' =>'核销节能油获得积分',
-        ]
+        ],
+        'award_unclaimed_range' =>[
+            'award/unclaimed_range' =>'下单商品获得冻结份额',
+            'award/thaw_range' =>'下级下单解冻份额',
+            'award/thaw_brokerage' =>'解冻冻结奖金',
+        ],
+        'freeze_brokerage' =>[
+            'freeze_brokerage/freeze_brokerage' =>'冻结奖金',
+            'freeze_brokerage/thaw_brokerage' =>'解冻冻结奖金',
+        ],
     ];
 
     const CATEGORY_SVIP_PAY = 'svip_pay';

+ 70 - 11
app/common/repositories/user/UserRepository.php

@@ -2675,17 +2675,18 @@ class UserRepository extends BaseRepository
     {
         return app()->make(AwardIntegralPriceRepository::class)->awardIntegralPrice();
     }
+
 //检测用户积分乘积分价格后是否超过分红额度,如果超过则提取分红积分
     public function checkAward($uid)
     {
         $info = $this->dao->get($uid);
         if ($info['award_range'] > 0) {
             $price = $this->awardIntegralPrice();
-            @file_put_contents('quanju.txt',$price."-积分价格\r\n",8);
+            @file_put_contents('quanju.txt', $price . "-积分价格\r\n", 8);
             if ($price['price'] > 0) {
                 $all_price = bcmul($info['award_integral'], $price['price']);
-                @file_put_contents('quanju.txt',$all_price."-积分乘价格\r\n",8);
-                @file_put_contents('quanju.txt',$info['award_range']."-份额\r\n",8);
+                @file_put_contents('quanju.txt', $all_price . "-积分乘价格\r\n", 8);
+                @file_put_contents('quanju.txt', $info['award_range'] . "-份额\r\n", 8);
                 if ($all_price >= $info['award_range']) {
                     $this->extractIntegral($uid);
                 }
@@ -2696,6 +2697,60 @@ class UserRepository extends BaseRepository
         }
     }
 
+//    添加冻结奖金
+    public function addFrozenBrokerage($uid, $num)
+    {
+        $info = $this->dao->get($uid);
+        $after_brokerage = bcadd($info['brokerage_price'], $num, 2);
+        $userBillRepository = app()->make(UserBillRepository::class);
+        $userBillRepository->incBill($uid, 'freeze_brokerage', 'freeze_brokerage', [
+            'link_id' => 0,
+            'status' => 1,
+            'title' => '冻结奖金',
+            'number' => $num,
+            'mark' => '积分自动提现,超出份额'.$num.'元,作为冻结奖金',
+            'balance' =>$after_brokerage
+        ]);
+
+    }
+//    检测到份额后扣除份额提出冻结奖金
+    public function extractBrokerage($uid){
+        $info = $this->dao->get($uid);
+        if ($info['freeze_brokerage'] <=0){
+            return true;
+        }
+        $freeze_brokerage = $info['freeze_brokerage'];
+        if ($info['award_range'] > $freeze_brokerage) {  //如果份额大于冻结奖金
+            $range = bcsub($info['award_range'], $freeze_brokerage, 2);  //剩余份额
+            $num = $freeze_brokerage; //冻结多少奖金
+            $freeze_brokerage=0; //剩余冻结奖金
+        }else{  //如果份额小于冻结奖金
+            $range = 0;  //剩余份额
+            $num = bcsub($freeze_brokerage, $info['award_range'], 2); //冻结多少奖金
+            $freeze_brokerage = bcsub($info['award_range'], $freeze_brokerage, 2); //剩余冻结奖金
+        }
+        $userBillRepository = app()->make(UserBillRepository::class);
+//        扣除冻结金额
+        $userBillRepository->decBill($uid, 'freeze_brokerage', 'thaw_brokerage', [
+            'link_id' => 0,
+            'status' => 1,
+            'title' => '解冻冻结奖金',
+            'number' => $num,
+            'mark' => '用户获得分红份额'.$info['award_range'].'元,冻结对应奖金',
+            'balance' =>$freeze_brokerage
+        ]);
+//        扣除分红额度
+        $userBillRepository->decBill($uid, 'award_range', 'thaw_brokerage', [
+            'link_id' => 0,
+            'status' => 1,
+            'title' => '解冻冻结奖金',
+            'number' => $num,
+            'mark' => '用户获得分红份额'.$info['award_range'].'元,冻结对应奖金',
+            'balance' =>$freeze_brokerage
+        ]);
+        User::where('uid', $uid)->update(['freeze_brokerage' => $freeze_brokerage,'award_range'=>$range]);
+    }
+
     /**
      * 提取分红积分
      * @param $uid
@@ -2713,21 +2768,25 @@ class UserRepository extends BaseRepository
             // 实例化用户账单仓库,用于处理用户账单相关操作。
             $userBillRepository = app()->make(UserBillRepository::class);
             $price = $this->awardIntegralPrice();
-            @file_put_contents('quanju.txt',json_encode($price)."-积分金额\r\n",8);
-            $all_price = bcmul($num, $price['price'],2);
+            @file_put_contents('quanju.txt', json_encode($price) . "-积分金额\r\n", 8);
+            $all_price = bcmul($num, $price['price'], 2);
             if ($all_price > $info['award_range']) $all_price = $info['award_range'];
 
             if ($all_price > 0) {
                 $commission2 = $all_price;
                 $commission = systemConfig('extract_commission', 0.06);
-                @file_put_contents('quanju2.txt',$commission."-手续费比例\r\n",8);
-                if ($commission > 0){
-                    $all_price2 = bcmul((string)$all_price, (string)$commission,2);  //手续费
-                    @file_put_contents('quanju2.txt',$commission."-手续费\r\n",8);
+                @file_put_contents('quanju2.txt', $commission . "-手续费比例\r\n", 8);
+                if ($commission > 0) {
+                    $all_price2 = bcmul((string)$all_price, (string)$commission, 2);  //手续费
+                    @file_put_contents('quanju2.txt', $commission . "-手续费\r\n", 8);
 //                $commission2 = bcsub($commission2,$all_price,2);  //回奖池的手续费
-                    $all_price = bcsub($all_price,$all_price2,2);  //奖金减手续费
-                    @file_put_contents('quanju2.txt',$all_price."-减掉手续费的金额\r\n",8);
+                    $all_price = bcsub($all_price, $all_price2, 2);  //奖金减手续费
+                    @file_put_contents('quanju2.txt', $all_price . "-减掉手续费的金额\r\n", 8);
                 }
+//                可提现奖金和份额
+                $award = bcsub($all_price, $info['award_range'], 2);
+                $all_price = $info['award_range'];
+                $this->addFrozenBrokerage($uid, $award);  //冻结奖金
 
                 //用户获得$all_price的佣金
                 $userBillRepository->incBill($uid, 'brokerage', 'extract_award', [

+ 40 - 0
app/controller/api/user/User.php

@@ -262,6 +262,46 @@ class User extends BaseController
         app()->make(UserRepository::class)->extractIntegral($user['uid'],$where['num']);
         return app('json')->success('已提现至佣金');
     }
+    /**
+     * 冻结分红份额明细
+     * @param UserBillRepository $billRepository
+     * @return mixed
+     * @author xaboy
+     * @day 2020/6/22
+     */
+    public function award_unclaimed_range_list(UserBillRepository $billRepository)
+    {
+        [$page, $limit] = $this->getPage();
+        [$start,$stop]= $this->request->params(['start','stop'],true);
+        $pm =  $this->request->param('pm', '');
+        return app('json')->success($billRepository->userList([
+//            'award_range' => $this->request->param('type', 0),
+            'date'=> $start&&$stop ? date('Y/m/d',$start).'-'.date('Y/m/d',$stop) : '',
+            'status' => 1,
+            'category' => 'award_unclaimed_range',
+            'pm'=> $pm
+        ], $this->request->uid(), $page, $limit));
+    }
+    /**
+     * 冻结奖金明细
+     * @param UserBillRepository $billRepository
+     * @return mixed
+     * @author xaboy
+     * @day 2020/6/22
+     */
+    public function freeze_brokerage_list(UserBillRepository $billRepository)
+    {
+        [$page, $limit] = $this->getPage();
+        [$start,$stop]= $this->request->params(['start','stop'],true);
+        $pm =  $this->request->param('pm', '');
+        return app('json')->success($billRepository->userList([
+//            'award_range' => $this->request->param('type', 0),
+            'date'=> $start&&$stop ? date('Y/m/d',$start).'-'.date('Y/m/d',$stop) : '',
+            'status' => 1,
+            'category' => 'freeze_brokerage',
+            'pm'=> $pm
+        ], $this->request->uid(), $page, $limit));
+    }
     /**
      * @return mixed
      * @throws DataNotFoundException

+ 4 - 0
route/api.php

@@ -208,6 +208,10 @@ Route::group('api/', function () {
             Route::get('award/integral_list', 'User/award_integral_list');
             //分红份额明细
             Route::get('award/range_list', 'User/award_range_list');
+            //冻结分红份额明细
+            Route::get('award/unclaimed_range_list', 'User/award_unclaimed_range_list');
+            //冻结奖金明细
+            Route::get('award/freeze_brokerage_list', 'User/freeze_brokerage_list');
 //            分红积分提现
             Route::get('award/create', 'User/award_create');
 //            最新的积分价格