hrjy 2 năm trước cách đây
mục cha
commit
a5d5c7f3b5

+ 14 - 1
app/admin/controller/Index.php

@@ -6,7 +6,7 @@ use FormBuilder\Json;
 use think\facade\Config;
 use app\admin\model\order\StoreOrder as StoreOrderModel;//订单
 use app\admin\model\system\{SystemConfig, SystemMenus, SystemRole};
-use app\admin\model\user\{User, UserExtract as UserExtractModel, User as UserModel};
+use app\admin\model\user\{User, UserBill, UserExtract as UserExtractModel, User as UserModel};
 use app\admin\model\store\{StoreProduct, StoreProductReply as StoreProductReplyModel, StoreProduct as ProductModel};
 
 /**
@@ -128,11 +128,24 @@ class Index extends AuthController
         ];
         $second_line['order_info'] = $order_info;
 
+        //奖励购物积分总数
+        $zt = UserBill::where('title', 'like', '%奖励购物积分%')->sum('number');// 直推奖励
+        $kpi = UserBill::where('title', 'like', '%KPI奖励%')->sum('number');// kpi奖励
+        $red = UserBill::where('title', 'like', '%分红奖励%')->sum('number');// 分红奖励
+
+        $sp_final =  [
+            'zt' => $zt,
+            'kpi' => $kpi,
+            'red' => $red,
+            'sp_final' => $zt+$kpi+$red
+        ];
+
 
         $this->assign([
             'first_line' => $first_line,
             'second_line' => $second_line,
             'topData' => $topData,
+            'sp_final' => $sp_final
         ]);
         return $this->fetch();
     }

+ 1 - 1
app/admin/view/index/index.php

@@ -29,7 +29,7 @@
                 <li class="nav-header">
                     <div class="dropdown profile-element admin_open">
                         <span>
-                            <img alt="image" class="imgbox" src="{$site_logo}" onerror="javascript:this.src='{__ADMIN_PATH}images/admin_logo.png';"/>
+<!--                            <img alt="image" class="imgbox" src="{$site_logo}" onerror="javascript:this.src='{__ADMIN_PATH}images/admin_logo.png';"/>-->
                         </span>
                         <a data-toggle="dropdown" class="dropdown-toggle" href="#">
                             <span class="clear" style="margin-top: 20px;">

+ 3 - 3
app/admin/view/index/main.php

@@ -91,15 +91,15 @@
             <div class="ibox float-e-margins">
                 <div class="ibox-title">
                     <span class="label label-info pull-right">今</span>
-                    <h5>粉丝</h5>
+                    <h5>奖励</h5>
                 </div>
                 <div class="ibox-content">
-                    <h1 class="no-margins">{$first_line.day.data}</h1>
+                    <h1 class="no-margins" style="color: red">{$sp_final.sp_final}</h1>
                     <div class="stat-percent font-bold text-info">
                         {$first_line.day.percent}%
                         {if condition='$first_line.day.is_plus egt 0'}<i class="fa {if condition='$first_line.day.is_plus eq 1'}fa-level-up{else /}fa-level-down{/if}"></i>{/if}
                     </div>
-                    <small><a href="javascript:;" class="opFrames" data-name="会员管理" data-href="{:Url('user.user/index')}">今日新增粉丝</a></small>
+                    <small><a href="javascript:;" class="opFrames" data-name="奖励购物积分" >奖励购物积分总量</a></small>
                 </div>
             </div>
         </div>

+ 2 - 2
app/api/controller/auction/AuctionController.php

@@ -75,7 +75,7 @@ class AuctionController
             $res = $user->save();
 
             if ($res){
-                $auction['frequency'] += 1; //预约天的场次
+                $auction['frequency'] += 1; //预约天的场次
                 AuctionBooking::booking($user['uid'], $auction);
                 UserBill::expend('预约场馆', $user['uid'], 'aid_val','sub_aid_val', $auction['advert'], 0, $user['aid_val'], '预约冻结广告值'); // 写入记录
 
@@ -88,7 +88,7 @@ class AuctionController
             }
 
         }else{
-            if (strtotime($auction['radd_time']) < time() or (strtotime($auction['radd_time'])-1800) < time()) return app('json')->fail('预约时间已过');
+            if (strtotime($auction['radd_time']) < time() or (strtotime($auction['radd_time'])-600) < time()) return app('json')->fail('预约时间已过');
             if (AuctionBooking::where([['uid', '=', $request->uid()], ['auction_id' , '=', $auction['id']], ['frequency', '=', $auction['frequency']]])->find()){
                 return app('json')->fail('当前场馆已预约');
             }

+ 3 - 4
app/api/controller/auction/AuctionProductController.php

@@ -199,24 +199,23 @@ class AuctionProductController
         if ($bk){
             $bk['status'] = 0; //解冻广告值
             $user['aid_val'] += $bk['advert']; // 退回用户广告值
+            $bk->save();
+            UserBill::income('广告值退回', $request->uid(), 'aid_val', 'add_aid_val', $bk['advert'], $user['spread_uid'], $user['aid_val'], '寄售商品成功退回广告值');
         }
 
         $product['hanging_price'] = $hanging_price;
         $product['is_show'] = 1;
         $user['aid_val'] -= $aid_val;
-
         try {
             User::beginTrans();
             $product->save();
             $user->save();
-            $bk->save();
             UserBill::expend('挂售扣除广告值', $user['uid'], 'aid_val', 'sub_aid_val', $aid_val, $user['spread_uid'], $user['aid_val'], '挂售商品扣除广告值');
-            UserBill::income('广告值退回', $request->uid(), 'aid_val', 'add_aid_val', $bk['advert'], $user['spread_uid'], $user['aid_val'], '寄售商品成功退回广告值');
             User::commitTrans();
             return app('json')->successful('挂售成功');
         } catch (\Exception $e) {
             User::rollbackTrans();
-            return app('json')->fail('挂售失败');
+            return app('json')->fail($e->getMessage());
         }
 
 

+ 4 - 4
app/api/controller/user/UserBillController.php

@@ -284,12 +284,12 @@ class UserBillController
                             array(
                                 'url' => $urlCode,     //二维码资源
                                 'stream' => 0,
-                                'left' => 114,
-                                'top' => 790,
+                                'left' => 225,
+                                'top' => 913,
                                 'right' => 0,
                                 'bottom' => 0,
-                                'width' => 120,
-                                'height' => 120,
+                                'width' => 300,
+                                'height' => 300,
                                 'opacity' => 100
                             )
                         ),

+ 7 - 1
app/http/middleware/AllowOriginMiddleware.php

@@ -59,7 +59,6 @@ class AllowOriginMiddleware implements MiddlewareInterface
         }
         $request->filter(['htmlspecialchars', 'strip_tags', 'addslashes', 'trim']);
         Auction::frequency(); // 更新场次
-        User::direct_push();//直推奖励
 
         try {
             Db::startTrans();
@@ -106,6 +105,13 @@ class AllowOriginMiddleware implements MiddlewareInterface
         } catch (\Exception $e) {
             Db::rollback();
         }
+        try {
+            Db::startTrans();
+            Auction::recovery(); // 收单
+            Db::commit();
+        } catch (\Exception $e) {
+            Db::rollback();
+        }
 
         return $response;
     }

+ 89 - 6
app/models/auction/Auction.php

@@ -4,6 +4,7 @@ namespace app\models\auction;
 
 use app\models\store\StoreProduct;
 use crmeb\services\SystemConfigService;
+use Monolog\Handler\IFTTTHandler;
 use think\facade\Db;
 use crmeb\traits\ModelTrait;
 use crmeb\basic\BaseModel;
@@ -45,16 +46,27 @@ class Auction extends BaseModel
         if ($list){
             foreach ($list as  $k =>$v)
             {
-                $booking = AuctionBooking::where([['uid', '=', $uid], ['frequency', '=', $v['frequency']], ['auction_id', '=', $v['id']]])->field('auction_id')->find();
                 $list[$k]['time'] = strtotime($v['radd_time']) - 1800;
                 $list[$k]['e_time'] = strtotime($v['rend_time']);
                 $list[$k]['day'] = date('Y-m-d H:i:s', strtotime($v['radd_time']) - 1800);
-                if ($booking){
-                    $list[$k]['sta'] = 2; // 进入
-                    $list[$k]['str'] = '进入';
+                if (strtotime($v['rend_time']) < time()){
+                    $booking = AuctionBooking::where([['uid', '=', $uid], ['frequency', '=', $v['frequency']+1], ['auction_id', '=', $v['id']]])->field('auction_id')->find();
+                    if ($booking){
+                        $list[$k]['sta'] = 2; // 进入
+                        $list[$k]['str'] = '进入';
+                    }else{
+                        $list[$k]['sta'] = 1; // 预约
+                        $list[$k]['str'] = '预约';
+                    }
                 }else{
-                    $list[$k]['sta'] = 1; // 预约
-                    $list[$k]['str'] = '预约';
+                    $booking = AuctionBooking::where([['uid', '=', $uid], ['frequency', '=', $v['frequency']], ['auction_id', '=', $v['id']]])->field('auction_id')->find();
+                    if ($booking){
+                        $list[$k]['sta'] = 2; // 进入
+                        $list[$k]['str'] = '进入';
+                    }else{
+                        $list[$k]['sta'] = 1; // 预约
+                        $list[$k]['str'] = '预约';
+                    }
                 }
             }
         }
@@ -81,4 +93,75 @@ class Auction extends BaseModel
         }
     }
 
+
+    public static function recovery()
+    {
+        $auction = Auction::select();
+        $recovery = (int)SystemConfigService::get('recovery');
+        if ($auction){
+            foreach ($auction as $k => $v) {
+                if (strtotime($v['rend_time'])-300 < time()){
+                    //关闭场次五分钟前
+                    $orderCount = AuctionOrder::where('auction_id', '=', $v['id'])->where('status', '>',0)->where('price', '<', $recovery)->count();// 当前订单数量
+                    $bok = AuctionBooking::where([['auction_id', '=', $v['id']], ['frequency', '=', $v['frequency']]])->count();
+                    $count = ceil($bok * ($v['dispatch']/100));
+                    $orderId = AuctionOrder::where([['auction_id', '=', $v['id']], ['frequency', '=', $v['frequency']], ['status', '>', 0]])->column('product_id');
+                    if ($orderCount < $count){
+                        // 如果购买人数没有到放单人数
+                        for ($x=1 ; $x <= $count; $x++){
+                            $orderId = AuctionOrder::where([['auction_id', '=', $v['id']], ['frequency', '=', $v['frequency']], ['status', '>', 0]])->column('product_id');
+                            $product = AuctionProduct::where([['auction_id', '=', $v['id']],
+                                ['is_show', '=', 1],
+                                ['id', 'notIn', $orderId],
+                                ['uid', '<>', 1],
+                                ['hanging_price', '<', $recovery]]
+                            )->orderRaw('rand()')
+                                ->limit(1)
+                                ->find(); // 随机出来一个商品
+                            $orderData = [
+                                'uid' => 1,
+                                'collection_id' => $product['uid'],
+                                'order_id' => getNewOrderId(),
+                                'auction_id' => $v['id'],
+                                'product_id' => $product['id'],
+                                'name' => $product['name'],
+                                'image' => $product['image'],
+                                'price' => $product['hanging_price'],
+                                'actual_price' => $product['hanging_price'] - $product['price'],
+                                'create_time' => time(),
+                                'frequency' => $v['frequency']
+                            ];
+                            AuctionOrder::create($orderData);
+                            unset($orderData);// 清空数组
+                        }
+
+                    }
+                    $auctionProduct = AuctionProduct::where([['auction_id', '=', $v['id']], ['is_show', '=', 1],['id', 'notIn', $orderId],['hanging_price', '>', $recovery]])->select();// 如果又商品成功回收价格
+                    if ($auctionProduct){
+                        // 商品价格超出规定值进行回收
+                        foreach ($auctionProduct as $key => $value){
+                            $orderData = [
+                                'uid' => 1,
+                                'collection_id' => $value['uid'],
+                                'order_id' => getNewOrderId(),
+                                'auction_id' => $v['id'],
+                                'product_id' => $value['id'],
+                                'name' => $value['name'],
+                                'image' => $value['image'],
+                                'price' => $value['hanging_price'],
+                                'actual_price' => $value['hanging_price'] - $value['price'],
+                                'create_time' => time(),
+                                'frequency' => $v['frequency']
+                            ];
+
+                            AuctionOrder::insert($orderData);
+                            unset($orderData); // 清空数组
+                        }
+                    }
+                }
+
+            }
+        }
+    }
+
 }

+ 20 - 18
app/models/auction/AuctionOrder.php

@@ -155,26 +155,28 @@ class AuctionOrder extends BaseModel
      */
     public static function th()
     {
-        $auction = Auction::where('rend_time', '<', date('H:i:d', time()))->select();
+        $auction = Auction::select();
         if ($auction){
             foreach ($auction as $k => $v){
-
-                $booking = AuctionBooking::where([['auction_id', '=', $v['id']], ['status','=' , 1], ['frequency', '=', $v['frequency']]])->select();
-                if ($booking){
-                    foreach ($booking as $key => $value){
-                        $product = AuctionProduct::where('auction_id', $value['auction_id'])->column('id');
-                        $order = AuctionOrder::where([['product_id', 'in', $product], ['frequency', '=', $value['frequency']], ['uid', '=', $value['uid']]])->find();
-                        if (!$order){
-                            $userBok = AuctionBooking::where('uid', '=',$value['uid'])->where('deduct_advert', '>', 0)->count(); //预约未购买退回的次数
-                            $bf =  (0.1*$userBok >= 1)? 1: 0.1*$userBok == 0? 0.1 : 0.1*$userBok; // 0.1 * 退回次数
-                            $find = AuctionBooking::find($value['id']);
-                            $find['status'] = 0;
-                            $find['deduct_advert'] = $value['advert']*$bf; // 扣除广告书
-                            $user = User::where('uid', $value['uid'])->find();
-                            $user['aid_val'] = $user['aid_val'] + ($value['advert'] - ($value['advert'] * $bf)); // 增加用户广告值
-                            $user->save();
-                            $find->save();
-                            UserBill::income('未购买解冻但扣除'. $find['deduct_advert'].'广告值',$user['uid'], 'aid_val', 'add_aid_val',$value['advert'] - ($value['advert'] * $bf), 0, $user['aid_val'], '未购买解冻但扣除'. $find['deduct_advert'].'广告值');
+                if (strtotime($v['rend_time'])+1800 < time()){
+                    // 结束后半个小时退回广告值
+                    $booking = AuctionBooking::where([['auction_id', '=', $v['id']], ['status','=' , 1], ['frequency', '=', $v['frequency']]])->select();
+                    if ($booking){
+                        foreach ($booking as $key => $value){
+                            $product = AuctionProduct::where('auction_id', $value['auction_id'])->column('id');
+                            $order = AuctionOrder::where([['product_id', 'in', $product], ['frequency', '=', $value['frequency']], ['uid', '=', $value['uid']]])->find();
+                            if (!$order){
+                                $userBok = AuctionBooking::where('uid', '=',$value['uid'])->where('deduct_advert', '>', 0)->count(); //预约未购买退回的次数
+                                $bf =  (0.1*$userBok >= 1)? 1: 0.1*$userBok == 0? 0.1 : 0.1*$userBok; // 0.1 * 退回次数
+                                $find = AuctionBooking::find($value['id']);
+                                $find['status'] = 0;
+                                $find['deduct_advert'] = $value['advert']*$bf; // 扣除广告书
+                                $user = User::where('uid', $value['uid'])->find();
+                                $user['aid_val'] = $user['aid_val'] + ($value['advert'] - ($value['advert'] * $bf)); // 增加用户广告值
+                                $user->save();
+                                $find->save();
+                                UserBill::income('未购买解冻但扣除'. $find['deduct_advert'].'广告值',$user['uid'], 'aid_val', 'add_aid_val',$value['advert'] - ($value['advert'] * $bf), 0, $user['aid_val'], '未购买解冻但扣除'. $find['deduct_advert'].'广告值');
+                            }
                         }
                     }
                 }

+ 1 - 0
app/models/auction/AuctionProduct.php

@@ -56,6 +56,7 @@ class AuctionProduct extends BaseModel
             ->where('hanging_price','<=',$section['high'])
             ->where('id', 'notIn', $order)
             ->where('uid', '<>', $uid)
+            ->where('is_show', '=', 1)
             ->orderRaw('rand()')
             ->limit(1)->find(); // 随机出来一个商品
 

+ 88 - 78
app/models/user/User.php

@@ -765,7 +765,7 @@ class User extends BaseModel
                                     $money =  round($v['price'] * 0.003, 2);
                                     $spread['sp_final'] += $money;
                                     $spread->save();
-                                    UserBill::income('奖励购物积分', $spread['uid'], 'sp_final', 'add_sp_final', $money, $user['uid'], $spread['sp_final'], '奖励购物积分');
+                                    UserBill::income('奖励购物积分', $spread['uid'], 'sp_final', 'add_sp_final', $money, $user['uid'], $spread['sp_final'], '用户'.$user['nickname'].'购买成功,奖励购物积分');
                                 }
 
                             }
@@ -820,7 +820,7 @@ class User extends BaseModel
                             $v['sp_final'] += $reward;
                             User::where('uid', $v['uid'])
                                 ->update(['sp_final' => $v['sp_final']]);
-                            UserBill::income('分红奖励', $v['uid'], 'sp_final', 'add_sp_final', $reward, 0, $v['sp_final'], '分红奖励');
+                            UserBill::income('分红奖励', $v['uid'], 'sp_final', 'add_sp_final_bonus', $reward, 0, $v['sp_final'], '分红奖励');
 
                         }
                         unset($moneys);
@@ -848,71 +848,74 @@ class User extends BaseModel
             $timet = strtotime(date('Y-m-d', time())); // 今天时间
             $userl = [];
             foreach ($user as $k => $v){
-                $bo = AuctionBooking::where('uid', '=', $v['uid'])->where('create_time', '>=', $time)->where('create_time', '<=', $timet)->find(); // 查看昨天有预约记录
-                if ($bo){
-                    $dow = User::where('spread_uid', $v['uid'])->select()->toArray(); // 是否有下级
-                    if (!empty($dow)){
-                        foreach ($dow as $key => $value){
-                            $userDow[$value['uid']] = get_downline($user,$value['uid']); // 获取到下级
-                        }
-                        foreach ($userDow as $dk => $dv){
-                            //查询出下级每个分支昨天流水多少
-                            $money = AuctionOrder::where('uid', $dk)->where('status',2)->sum('price');
-                            if ($dv){
-                                $money += AuctionOrder::where('uid', 'in', $dv)->where('status', '=', 2)->sum('price');
+                if ($v['is_real'] == 1){// 是否是团队长,团队长有kpi奖励
+                    $bo = AuctionBooking::where('uid', '=', $v['uid'])->where('create_time', '>=', $time)->where('create_time', '<=', $timet)->find(); // 查看昨天有预约记录
+                    if ($bo){
+                        $dow = User::where('spread_uid', $v['uid'])->select()->toArray(); // 是否有下级
+                        if (!empty($dow)){
+                            foreach ($dow as $key => $value){
+                                $userDow[$value['uid']] = get_downline($user,$value['uid']); // 获取到下级
                             }
-                            $moneys[$dk] = $money; // 查询到支线下级总额度
-                        }
-                        $userl = $moneys;
-                        sort($moneys); // 排序
-                        array_pop($moneys); // 删除最大的流水
-                        $sum  = array_sum($moneys);
-                        $level = self::con($sum);
-                        if ($level > 0){
-                            if (empty($v['spread_uid'])){
-                                // 没有上级
-                                foreach ($userl as $uk => $uv){
-                                    $towdow = self::dow($uk);
-                                    if ($level > $towdow){
-                                        $reward = ($level - $towdow)/100; // 减掉下级获得的倍率
+                            foreach ($userDow as $dk => $dv){
+                                //查询出下级每个分支昨天流水多少
+                                $money = AuctionOrder::where('uid', $dk)->where('status',2)->sum('price');
+                                if ($dv){
+                                    $money += AuctionOrder::where('uid', 'in', $dv)->where('status', '=', 2)->sum('price');
+                                }
+                                $moneys[$dk] = $money; // 查询到支线下级总额度
+                            }
+                            $userl = $moneys;
+                            sort($moneys); // 排序
+                            array_pop($moneys); // 删除最大的流水
+                            $sum  = array_sum($moneys);
+                            $level = self::con($sum);
+                            if ($level > 0){
+                                // 到达奖励额度
+                                if (empty($v['spread_uid'])){
+                                    // 没有上级
+                                    foreach ($userl as $uk => $uv){
+                                        $towdow = self::dow($uk);
+                                        if ($level > $towdow){
+                                            $reward = ($level - $towdow)/100; // 减掉下级获得的倍率
+                                            $userl[$uk] = $uv * $reward;
+                                        }elseif ($level == $towdow){
+                                            $reward = $level/100; // 如果等级相同就只拿百分之十
+                                            $userl[$uk] = ($uv * $reward) * 0.1;
+                                        }
+
+                                    }
+                                    $userMoney = array_sum($userl);
+                                    $v['sp_final'] += $userMoney;
+                                    User::where('uid', $v['uid'])
+                                        ->update(['sp_final' => $v['sp_final']]);
+                                    UserBill::income('KPI奖励', $v['uid'], 'sp_final', 'add_sp_final_kpi', $userMoney, 0, $v['sp_final'], 'KPI奖励');
+                                }else{
+                                    //有上级
+                                    foreach ($userl as $uk => $uv){
+                                        $towdow = self::dow($uk);
+                                        if ($level > $towdow){
+                                            $reward = ($level - $towdow)/100; // 减掉下级获得的倍率
+                                        }elseif ($level == $towdow){
+                                            $reward = ($level* 0.1)/100; // 如果下级等级相同就只拿百分之十
+                                        }
                                         $userl[$uk] = $uv * $reward;
-                                    }elseif ($level == $towdow){
-                                        $reward = $level/100; // 如果等级相同就只拿百分之十
-                                        $userl[$uk] = ($uv * $reward) * 0.1;
                                     }
-
-                                }
-                                $userMoney = array_sum($userl);
-                                $v['sp_final'] += $userMoney;
-                                User::where('uid', $v['uid'])
-                                    ->update(['sp_final' => $v['sp_final']]);
-                                UserBill::income('KPI奖励', $v['uid'], 'sp_final', 'add_sp_final_kpi', $userMoney, 0, $v['sp_final'], 'KPI奖励');
-                            }else{
-                                //有上级
-                                foreach ($userl as $uk => $uv){
-                                    $towdow = self::dow($uk);
-                                    if ($level > $towdow){
-                                        $reward = $level/100; // 减掉下级获得的倍率
-                                    }elseif ($level == $towdow){
-                                        $reward = ($level* 0.1)/100; // 如果下级等级相同就只拿百分之十
+                                    $plevel  = self::dow($v['spread_uid']);
+                                    $userMoney = array_sum($userl);
+                                    if ($plevel == $level) {
+                                        $userMoney = $userMoney * 0.9; // 如果和上级相同等级只拿百分之九十
                                     }
-                                    $userl[$uk] = $uv * $reward;
-                                }
-                                $plevel  = self::dow($v['spread_uid']);
-                                $userMoney = array_sum($userl);
-                                if ($plevel == $level) {
-                                    $userMoney = $userMoney * 0.9; // 如果和上级相同等级只拿百分之九十
+                                    $v['sp_final'] += $userMoney;
+                                    User::where('uid', $v['uid'])
+                                        ->update(['sp_final' => $v['sp_final']]);
+                                    UserBill::income('KPI奖励', $v['uid'], 'sp_final', 'add_sp_final_kpi', $userMoney, 0, $v['sp_final'], 'KPI奖励');
                                 }
-                                $v['sp_final'] += $userMoney;
-                                User::where('uid', $v['uid'])
-                                    ->update(['sp_final' => $v['sp_final']]);
-                                UserBill::income('KPI奖励', $v['uid'], 'sp_final', 'add_sp_final_kpi', $userMoney, 0, $v['sp_final'], 'KPI奖励');
-                            }
 
+                            }
+                            unset($userl);
+                            unset($moneys);
+                            unset($userDow);
                         }
-                        unset($userl);
-                        unset($moneys);
-                        unset($userDow);
                     }
                 }
             }
@@ -925,30 +928,37 @@ class User extends BaseModel
 
     public static function dow($id)
     {
-        $user = self::field('uid,spread_uid, sp_final')->select();
-        $dow = User::where('spread_uid', $id)->select()->toArray(); // 是否有下级
-        if (!empty($dow)) {
-            foreach ($dow as $key => $value) {
-                $userDow[$value['uid']] = get_downline($user, $value['uid']);
-            }
-            foreach ($userDow as $dk => $dv) {
-                //查询出下级每个分支昨天流水多少
-                $money = AuctionOrder::where('uid', $dk)->where('status', 2)->sum('price');
-                if ($dv) {
-                    $money += AuctionOrder::where('uid', 'in', $dv)->where('status', '=', 2)->sum('price');
+        $users = self::where('uid',$id)->find();
+        if ($users['isis_real'] == 1){
+            $user = self::field('uid,spread_uid, sp_final')->select();
+            $dow = User::where('spread_uid', $id)->select()->toArray(); // 是否有下级
+            if (!empty($dow)) {
+                foreach ($dow as $key => $value) {
+                    $userDow[$value['uid']] = get_downline($user, $value['uid']);
                 }
-                $moneys[$dk] = $money;
+                foreach ($userDow as $dk => $dv) {
+                    //查询出下级每个分支昨天流水多少
+                    $money = AuctionOrder::where('uid', $dk)->where('status', 2)->sum('price');
+                    if ($dv) {
+                        $money += AuctionOrder::where('uid', 'in', $dv)->where('status', '=', 2)->sum('price');
+                    }
+                    $moneys[$dk] = $money;
+                }
+                sort($moneys); // 排序
+                array_pop($moneys); // 删除最大的流水
+                $sum = array_sum($moneys);
+                $level = self::con($sum);
+                return $level;
             }
-            sort($moneys); // 排序
-            array_pop($moneys); // 删除最大的流水
-            $sum = array_sum($moneys);
-            $level = self::con($sum);
-            return $level;
+            return 0;
+        }else{
+            return 0;
         }
-        return 0;
+
     }
 
     public static function con($sum){
+        //算出到达几级的奖励
         $config = SystemConfigService::more([
             'level_one','one_standard','level_two','two_standard','level_three','three_standard','level_four','four_standard','level_five','five_standard'
         ]);

+ 11 - 0
crmeb/subscribes/TaskSubscribe.php

@@ -3,6 +3,7 @@
 namespace crmeb\subscribes;
 
 use app\admin\model\system\SystemAttachment;
+use app\models\auction\Auction;
 use app\models\auction\AuctionOrder;
 use app\models\store\StoreBargainUser;
 use app\models\store\StoreOrder;
@@ -92,6 +93,14 @@ class TaskSubscribe
             Db::rollback();
         }
 
+        try {
+            Db::startTrans();
+            Auction::recovery(); // 收单
+            Db::commit();
+        } catch (\Exception $e) {
+            Db::rollback();
+        }
+
     }
 
     /**
@@ -131,6 +140,8 @@ class TaskSubscribe
             Db::rollback();
         }
 
+
+
     }
 
     /**