Просмотр исходного кода

wesmiler 更新第5期更新代码合并

wesmiler 4 лет назад
Родитель
Сommit
583e905155

+ 113 - 19
app/api/controller/TaskController.php

@@ -3,6 +3,7 @@
 namespace app\api\controller;
 
 use app\portal\model\UserModel;
+use app\user\model\PoolModel;
 use app\weixin\model\AccountLog;
 use app\weixin\model\Books;
 use app\weixin\model\Devices;
@@ -13,6 +14,7 @@ use app\weixin\service\Award;
 use app\weixin\service\Export;
 use app\weixin\service\PRedis;
 use think\Controller;
+use think\Db;
 
 class TaskController extends Controller
 {
@@ -60,8 +62,6 @@ class TaskController extends Controller
     }
 
 
-
-
     /**
      * 认识申请超时处理
      */
@@ -146,7 +146,8 @@ class TaskController extends Controller
     /**
      * 清除过期签到爱心
      */
-    public function clearSignHeart(){
+    public function clearSignHeart()
+    {
         set_time_limit(0);
         $key = input('key', '');
         $checkKey = config('task.clearHeartKey');
@@ -155,22 +156,22 @@ class TaskController extends Controller
         }
         try {
             $month = date('Y-m-01', time() - 2 * 86400);
-            $users = AccountLog::where(['type'=> 12,'status'=> 2])
-                ->where('created_at','>=', $month)
-                ->order('created_at','asc')
+            $users = AccountLog::where(['type' => 12, 'status' => 2])
+                ->where('created_at', '>=', $month)
+                ->order('created_at', 'asc')
                 ->column('user_id');
 
             $userIds = [];
-            if($users){
-                foreach($users as $userId){
+            if ($users) {
+                foreach ($users as $userId) {
                     // 清除签到爱心
-                    if($userId && \app\weixin\service\Member::clearSignRedHeart($userId)){
+                    if ($userId && \app\weixin\service\Member::clearSignRedHeart($userId)) {
                         $userIds[] = $userId;
                     }
                 }
             }
 
-            $msg = "清除签到爱心数据结果,共".count($users)."个,累计处理" . count($userIds) . "个会员数据更新";
+            $msg = "清除签到爱心数据结果,共" . count($users) . "个,累计处理" . count($userIds) . "个会员数据更新";
             return showJson(1005, $msg, "\n");
         } catch (\Exception $exception) {
             return showJson(1004, $exception->getMessage(), '', "\n");
@@ -313,24 +314,24 @@ class TaskController extends Controller
                 $inviteInfo = Member::getInviteInfo($userId);
                 $inviteId = isset($inviteInfo['invite_id']) ? $inviteInfo['invite_id'] : 0;
                 //$item['invite'] = $inviteInfo;
-                PRedis::set('markets:activity:book_temp_' . $aid . ':' . $userId . '_' . $inviteId, ['info' => $item, 'inviteInfo' => $inviteInfo], 5*86400);
-                
+                PRedis::set('markets:activity:book_temp_' . $aid . ':' . $userId . '_' . $inviteId, ['info' => $item, 'inviteInfo' => $inviteInfo], 5 * 86400);
+
                 if ($inviteInfo && $inviteId > 0 && $aid > 0 && $money > 0) {
                     if (!UserBalanceLog::checkHasMarketBySource($inviteId, $userId, $aid, 9)) {
                         $catchList[] = $item;
-                        PRedis::set('markets:activity:book_' . $aid . ':' .$userId  . '_' . $inviteId, ['info' => $item, 'inviteInfo' => $inviteInfo], 7200);
+                        PRedis::set('markets:activity:book_' . $aid . ':' . $userId . '_' . $inviteId, ['info' => $item, 'inviteInfo' => $inviteInfo], 7200);
                         Award::marketAward($inviteId, $userId, 9, $money);
                         $catchIds[] = $item['id'];
                     }
                 }
             });
 
-        if($catchIds){
-            Books::whereIn('id', $catchIds)->update(['is_market'=> 1,'remark'=> '分销已结算']);
+        if ($catchIds) {
+            Books::whereIn('id', $catchIds)->update(['is_market' => 1, 'remark' => '分销已结算']);
         }
 
-        $bookList = $bookList? $bookList->toArray() : [];
-        showJson(1005, 1001, ['total'=> $bookList['total'],'bookList' => $bookList['data'], 'catchList' => $catchList]);
+        $bookList = $bookList ? $bookList->toArray() : [];
+        showJson(1005, 1001, ['total' => $bookList['total'], 'bookList' => $bookList['data'], 'catchList' => $catchList]);
     }
 
     /**
@@ -338,7 +339,8 @@ class TaskController extends Controller
      * @throws \think\Exception
      * @throws \think\exception\PDOException
      */
-    public function updateExport(){
+    public function updateExport()
+    {
         set_time_limit(0);
         $key = input('key', '');
         $checkKey = config('task.updateExport');
@@ -347,7 +349,99 @@ class TaskController extends Controller
         }
 
         $result = Export::updateData();
-        showJson(1005, 1001, ['ids'=> $result, 'date'=> date('Y-m-d H:i:s')]);
+        showJson(1005, 1001, ['ids' => $result, 'date' => date('Y-m-d H:i:s')]);
+
+    }
+
+    /**
+     * 更新销售资源过期数据
+     * @throws \think\Exception
+     * @throws \think\exception\PDOException
+     */
+    public function salesExpired()
+    {
+        set_time_limit(0);
+        $key = input('key', '');
+        $checkKey = config('task.salesExpired');
+        if ($key != $checkKey) {
+            showJson(1004, 2009, '', "\n");
+        }
+
+        if(date("H:i") >= '05:00'){
+            showJson(1004, 2009, '', "\n");
+        }
+
+        $count = 0;
+        $datas = [];
+        $result = PoolModel::alias('p')
+//            ->where('p.expire_at', '<', date('Y-m-d H:i:s'))
+            ->where(['p.type' => 0, 'p.status' => 1])
+            ->field('id,sale_uid,user_id,followup_num,expire_at')
+            ->limit(100)
+            ->order('p.expire_at asc,p.id asc')
+            ->select()
+            ->each(function ($item, $k) use ($count, $datas) {
+                $userId = isset($item['user_id']) ? $item['user_id'] : 0;
+                $expireAt = isset($item['expire_at']) ? $item['expire_at'] : '';
+                $updateData = ['updated_at' => date('Y-m-d H:i:s')];
+
+                // 到期数据处理
+                if($expireAt && $expireAt <= date('Y-m-d H:i:s')){
+                    $data = [
+                        'sale_uid' => 0,
+                        'user_id' => $userId,
+                        'type' => 2,
+                        'followup_num' => 0,
+                        'intention' => 0,
+                        'create_time' => date('Y-m-d H:i:s'),
+                        'updated_at' => date('Y-m-d H:i:s'),
+                        'expire_at' => 0,
+                        'status' => 1,
+                    ];
+                    $info = PoolModel::checkData($userId);
+                    if (empty($info)) {
+                        $datas[] = $data;
+                    } else {
+                        PoolModel::where(['id' => $info['id'], 'user_id' => $userId])->update($data);
+                    }
+
+                    // 到期未跟进
+                    $updateData['stop_time'] = date('Y-m-d H:i:s');
+                    if($item['followup_num'] <= 0){
+                        $updateData['agency'] = 3;
+                    }
+                    $count++;
+                }else if ($expireAt){
+                    // 今日坠海
+                    $time = strtotime($expireAt);
+                    $dayTime = strtotime(date('Y-m-d'));
+                    if($time >= time() && $time < $dayTime + 86400){
+                        $item['expire_text'] = '今天坠海';
+                        $updateData['agency'] = 4;
+                    }else if($time>=$dayTime+86400 && $time < $dayTime + 2 * 86400){
+                        $item['expire_text'] = '明天坠海';
+                        $updateData['agency'] = 5;
+                    }else if($time>=$dayTime+7*86400 && $time < $dayTime + 15 * 86400){
+                        $item['expire_text'] = '一礼拜后坠海';
+                    }
+                    $updateData = [];
+
+                }
+
+                // 更新待办事项
+                if($updateData){
+                    $count++;
+                    PoolModel::where(['id' => $item['id']])->update($updateData);
+                }
+            });
+
+        if ($datas) {
+            PoolModel::insertAll($datas);
+        }
+
+        // 缓存
+        PRedis::set("caches:sales:expired", ['datas'=> $datas,'result'=> $result, 'date'=> date('Y-m-d H:i:s')], 86400);
+        showJson(1005, 1008, ['count' => $count, 'date' => date('Y-m-d H:i:s')]);
 
     }
 }

+ 1 - 0
data/config/task.php

@@ -13,5 +13,6 @@ return [
     'catchBookMarket'=> 'Baiybe6db4H2xKL65MAbNb83a07PPTsc', // 报名分销结算
     'clearHeartKey'=> 'Baiybe6db4H2xKL65C1bNb83a07HJCCk', // 清除签到爱心
     'updateExport'=> 'Expybe6db4H2xKL65C1bNb83a07HJVV', // 更新报表数据
+    'salesExpired'=> 'Saleybe6db4H2xKL65C1bNb83a07HJTT', // 更新到期销售资源数据
 
 ];

+ 15 - 4
public/themes/admin_simpleboot3/admin/pools/customized.html

@@ -49,6 +49,9 @@
         font-style: normal;
         color: red;
     }
+    .layui-layer-page .layui-layer-content {
+        overflow: hidden !important;
+    }
 </style>
 <body>
 <div class="wrap js-check-wrap">
@@ -75,7 +78,9 @@
         <input type="submit" class="btn btn-primary margin-left-10 " value="搜索"/>
 
         <a class="btn btn-default margin-left-10" href="{:url('admin/pools/customized')}">清空</a>
-        <a class="btn btn-warning margin-left-10" href="{:url('admin/pools/export',['type'=>5])}">导出</a>
+        <if condition="$is_admin eq 1">
+            <a class="btn btn-warning margin-left-10" href="{:url('admin/pools/export',['type'=>5])}">导出</a>
+        </if>
     </form>
     <form class="form-horizontal js-ajax-form margin-top-20" role="form">
         <div class="table-actions">
@@ -155,6 +160,12 @@
                             </select>
                         </div>
                     </div>
+                    <div class="form-group">
+                        <label class="col-sm-3 control-label"><span class="form-required"></span>到期时间(天)</label>
+                        <div class="col-sm-8">
+                            <input type="text" class="form-control" id="expire_at" name="expire_at" placeholder="默认取平台设置">
+                        </div>
+                    </div>
                 </form>
             </div>
         </div>
@@ -214,7 +225,7 @@
             shade: 0.8, //遮罩
             offset: 'auto',
             area: ['480px', '260px'],
-            content: $("#distribute").html(),
+            content: $("#distribute"),
             btn: ['确定分配','取消'],
             btnAlign: 'c',
             yes: function(){
@@ -222,9 +233,9 @@
                     layer.msg('请选择分配的销售用户')
                     return false;
                 }
-
+                var expire_at = $("#expire_at").val();
                 if (confirm('确定批量分配选择项?不可恢复')) {
-                    $.post('/admin/pools/distribute', {ids: ids, sale_uid: saleUid, type: 2}, function (res) {
+                    $.post('/admin/pools/distribute', {ids: ids, sale_uid: saleUid, expire_at: expire_at, type: 2}, function (res) {
                         if (res.code == 1) {
                             layer.msg(res.msg)
                             setTimeout(function () {

+ 15 - 4
public/themes/admin_simpleboot3/admin/pools/phone.html

@@ -49,6 +49,9 @@
         font-style: normal;
         color: red;
     }
+    .layui-layer-page .layui-layer-content {
+        overflow: hidden !important;
+    }
 </style>
 <body>
 <div class="wrap js-check-wrap">
@@ -75,7 +78,9 @@
         <input type="submit" class="btn btn-primary margin-left-10 " value="搜索"/>
 
         <a class="btn btn-default margin-left-10" href="{:url('admin/pools/phone')}">清空</a>
-        <a class="btn btn-warning margin-left-10" href="{:url('admin/pools/export',['type'=>4])}">导出</a>
+        <if condition="$is_admin eq 1">
+            <a class="btn btn-warning margin-left-10" href="{:url('admin/pools/export',['type'=>4])}">导出</a>
+        </if>
     </form>
     <form class="form-horizontal js-ajax-form margin-top-20" role="form">
         <div class="table-actions">
@@ -155,6 +160,12 @@
                             </select>
                         </div>
                     </div>
+                    <div class="form-group">
+                        <label class="col-sm-3 control-label"><span class="form-required"></span>到期时间(天)</label>
+                        <div class="col-sm-8">
+                            <input type="text" class="form-control" id="expire_at" name="expire_at" placeholder="默认取平台设置">
+                        </div>
+                    </div>
                 </form>
             </div>
         </div>
@@ -214,7 +225,7 @@
             shade: 0.8, //遮罩
             offset: 'auto',
             area: ['480px', '260px'],
-            content: $("#distribute").html(),
+            content: $("#distribute"),
             btn: ['确定分配','取消'],
             btnAlign: 'c',
             yes: function(){
@@ -222,9 +233,9 @@
                     layer.msg('请选择分配的销售用户')
                     return false;
                 }
-
+                var expire_at = $("#expire_at").val();
                 if (confirm('确定批量分配选择项?不可恢复')) {
-                    $.post('/admin/pools/distribute', {ids: ids, sale_uid: saleUid, type: 4}, function (res) {
+                    $.post('/admin/pools/distribute', {ids: ids, sale_uid: saleUid, expire_at: expire_at, type: 4}, function (res) {
                         if (res.code == 1) {
                             layer.msg(res.msg)
                             setTimeout(function () {

+ 14 - 3
public/themes/admin_simpleboot3/admin/pools/presale.html

@@ -49,6 +49,9 @@
         font-style: normal;
         color: red;
     }
+    .layui-layer-page .layui-layer-content {
+        overflow: hidden !important;
+    }
 </style>
 <body>
 <div class="wrap js-check-wrap">
@@ -75,7 +78,9 @@
         <input type="submit" class="btn btn-primary margin-left-10 " value="搜索"/>
 
         <a class="btn btn-default margin-left-10" href="{:url('admin/pools/presale')}">清空</a>
+        <if condition="$is_admin eq 1">
         <a class="btn btn-warning margin-left-10" href="{:url('admin/pools/export',['type'=>1])}">导出</a>
+        </if>
     </form>
     <form class="form-horizontal js-ajax-form margin-top-20" role="form">
         <div class="table-actions">
@@ -158,6 +163,12 @@
                             </select>
                         </div>
                     </div>
+                    <div class="form-group">
+                        <label class="col-sm-3 control-label"><span class="form-required"></span>到期时间(天)</label>
+                        <div class="col-sm-8">
+                            <input type="text" class="form-control" id="expire_at" name="expire_at" placeholder="默认取平台设置">
+                        </div>
+                    </div>
                 </form>
             </div>
         </div>
@@ -217,7 +228,7 @@
             shade: 0.8, //遮罩
             offset: 'auto',
             area: ['480px', '260px'],
-            content: $("#distribute").html(),
+            content: $("#distribute"),
             btn: ['确定分配','取消'],
             btnAlign: 'c',
             yes: function(){
@@ -225,9 +236,9 @@
                     layer.msg('请选择分配的销售用户')
                     return false;
                 }
-
+                var expire_at = $("#expire_at").val();
                 if (confirm('确定批量分配选择项?不可恢复')) {
-                    $.post('/admin/pools/distribute', {ids: ids, sale_uid: saleUid, type: 1}, function (res) {
+                    $.post('/admin/pools/distribute', {ids: ids, sale_uid: saleUid, expire_at: expire_at, type: 1}, function (res) {
                         if (res.code == 1) {
                             layer.msg(res.msg)
                             setTimeout(function () {

+ 15 - 4
public/themes/admin_simpleboot3/admin/pools/reserve.html

@@ -49,6 +49,9 @@
         font-style: normal;
         color: red;
     }
+    .layui-layer-page .layui-layer-content {
+        overflow: hidden !important;
+    }
 </style>
 <body>
 <div class="wrap js-check-wrap">
@@ -75,7 +78,9 @@
         <input type="submit" class="btn btn-primary margin-left-10 " value="搜索"/>
 
         <a class="btn btn-default margin-left-10" href="{:url('admin/pools/reserve')}">清空</a>
-        <a class="btn btn-warning margin-left-10" href="{:url('admin/pools/export',['type'=>3])}">导出</a>
+        <if condition="$is_admin eq 1">
+            <a class="btn btn-warning margin-left-10" href="{:url('admin/pools/export',['type'=>3])}">导出</a>
+        </if>
     </form>
     <form class="form-horizontal js-ajax-form margin-top-20" role="form">
         <div class="table-actions">
@@ -157,6 +162,12 @@
                             </select>
                         </div>
                     </div>
+                    <div class="form-group">
+                        <label class="col-sm-3 control-label"><span class="form-required"></span>到期时间(天)</label>
+                        <div class="col-sm-8">
+                            <input type="text" class="form-control" id="expire_at" name="expire_at" placeholder="默认取平台设置">
+                        </div>
+                    </div>
                 </form>
             </div>
         </div>
@@ -216,7 +227,7 @@
             shade: 0.8, //遮罩
             offset: 'auto',
             area: ['480px', '260px'],
-            content: $("#distribute").html(),
+            content: $("#distribute"),
             btn: ['确定分配','取消'],
             btnAlign: 'c',
             yes: function(){
@@ -224,9 +235,9 @@
                     layer.msg('请选择分配的销售用户')
                     return false;
                 }
-
+                var expire_at = $("#expire_at").val();
                 if (confirm('确定批量分配选择项?不可恢复')) {
-                    $.post('/admin/pools/distribute', {ids: ids, sale_uid: saleUid, type: 3}, function (res) {
+                    $.post('/admin/pools/distribute', {ids: ids, sale_uid: saleUid, expire_at: expire_at, type: 3}, function (res) {
                         if (res.code == 1) {
                             layer.msg(res.msg)
                             setTimeout(function () {

+ 15 - 4
public/themes/admin_simpleboot3/admin/pools/resource.html

@@ -49,6 +49,9 @@
         font-style: normal;
         color: red;
     }
+    .layui-layer-page .layui-layer-content {
+        overflow: hidden !important;
+    }
 </style>
 <body>
 <div class="wrap js-check-wrap">
@@ -75,7 +78,9 @@
         <input type="submit" class="btn btn-primary margin-left-10 " value="搜索"/>
 
         <a class="btn btn-default margin-left-10" href="{:url('admin/pools/resource')}">清空</a>
-        <a class="btn btn-warning margin-left-10" href="{:url('admin/pools/export',['type'=>2])}">导出</a>
+        <if condition="$is_admin eq 1">
+            <a class="btn btn-warning margin-left-10" href="{:url('admin/pools/export',['type'=>2])}">导出</a>
+        </if>
     </form>
     <form class="form-horizontal js-ajax-form margin-top-20" role="form">
         <div class="table-actions">
@@ -156,6 +161,12 @@
                             </select>
                         </div>
                     </div>
+                    <div class="form-group">
+                        <label class="col-sm-3 control-label"><span class="form-required"></span>到期时间(天)</label>
+                        <div class="col-sm-8">
+                            <input type="text" class="form-control" id="expire_at" name="expire_at" placeholder="默认取平台设置">
+                        </div>
+                    </div>
                 </form>
             </div>
         </div>
@@ -215,7 +226,7 @@
             shade: 0.8, //遮罩
             offset: 'auto',
             area: ['480px', '260px'],
-            content: $("#distribute").html(),
+            content: $("#distribute"),
             btn: ['确定分配','取消'],
             btnAlign: 'c',
             yes: function(){
@@ -223,9 +234,9 @@
                     layer.msg('请选择分配的销售用户')
                     return false;
                 }
-
+                var expire_at = $("#expire_at").val();
                 if (confirm('确定批量分配选择项?不可恢复')) {
-                    $.post('/admin/pools/distribute', {ids: ids, sale_uid: saleUid, type: 2}, function (res) {
+                    $.post('/admin/pools/distribute', {ids: ids, sale_uid: saleUid, expire_at: expire_at, type: 2}, function (res) {
                         if (res.code == 1) {
                             layer.msg(res.msg)
                             setTimeout(function () {

+ 391 - 0
public/themes/admin_simpleboot3/admin/sales/agency.html

@@ -0,0 +1,391 @@
+<include file="public@header"/>
+</head>
+<style>
+    .form-inline .form-control {
+        margin: 10px 0;
+        vertical-align: middle;
+    }
+
+    .form-inline span {
+        margin-left: 5px;
+        vertical-align: middle;
+    }
+    .margin-left-10 {
+        margin-left: 10px;
+    }
+
+    .profile em {
+        font-style: normal;
+        color: #0b6cbc;
+    }
+
+    .profile em.red {
+        color: red;
+    }
+
+    span.sort {
+        color: red;
+        display: inline-block;
+        margin-left: 2px;
+        vertical-align: middle;
+    }
+    td img.avatar, td img.sex {
+        width: 24px;
+        height: 24px;
+        vertical-align: middle;
+        border-radius: 100%;
+    }
+    .form .form-control {
+        margin-bottom: 20px;
+    }
+    .form .control-label {
+        text-align: center;
+    }
+
+    .form label {
+        text-align: left;
+        margin-bottom: 10px;
+        margin-right: 10px;
+    }
+
+    .radio-inline+.radio-inline, .checkbox-inline+.checkbox-inline {
+        margin-left: 0;
+    }
+
+    .table-actions span {
+        margin-right: 10px;
+        font-weight: bold;
+    }
+    .table-actions span em {
+        font-style: normal;
+        color: red;
+    }
+
+    .layui-layer-page .layui-layer-content {
+        overflow: hidden !important;
+    }
+
+    span.expired {
+        color: red;
+    }
+</style>
+<body>
+<div class="wrap js-check-wrap">
+    <ul class="nav nav-tabs">
+        <li class="active"><a>代办事项资源</a>
+        </li>
+    </ul>
+    <form id="search" class="well form-inline margin-top-20" method="post" action="{:url('admin/sales/agency')}">
+        <span>会员ID:</span>
+        <input class="form-control" type="text" name="uid" style="width: 150px;" value="{:input('request.uid')}"
+               placeholder="会员ID">
+        <span>用户昵称:</span>
+        <input class="form-control" type="text" name="user_nickname" style="width: 200px;"
+               value="{:input('request.user_nickname')}" placeholder="用户昵称"><br>
+        <span>用户姓名:</span>
+        <input class="form-control" type="text" name="real_name" style="width: 200px;"
+               value="{:input('request.real_name')}" placeholder="用户姓名">
+        <span>手机号:</span>
+        <input class="form-control" type="text" name="mobile" style="width: 200px;" value="{:input('request.mobile')}"
+               placeholder="手机号">
+
+        <input id="sort" type="hidden" name="sort" value="{$params.sort?$params.sort: 1}">
+        <input id="sortType" type="hidden" name="sort_type" value="{$params.sort_type?$params.sort_type: 'desc'}">
+        <input type="submit" class="btn btn-primary margin-left-10 " value="搜索"/>
+
+        <a class="btn btn-default margin-left-10" href="{:url('admin/sales/agency')}">清空</a>
+<!--        <a class="btn btn-warning margin-left-10" href="{:url('admin/sales/export')}">导出</a>-->
+    </form>
+    <form class="form-horizontal js-ajax-form margin-top-20" role="form">
+        <div class="table-actions">
+            <foreach name="agencyCounts" item="vo" key="k">
+                <if condition="$k gt 0">
+                    <a  href="{:url('admin/sales/agency',['agency'=> $k])}" <if condition="$k eq $params.agency">class="btn btn-primary margin-left-10"<else>class="btn btn-default margin-left-10"</if>>{$vo.name}({$vo.num})</a>
+                    <else>
+                        <a  href="{:url('admin/sales/agency',['agency'=> $k])}" <if condition="$k eq $params.agency">class="btn btn-primary margin-left-10"<else>class="btn btn-default margin-left-10"</if>>全部({$total})</a>
+                </if>
+            </foreach>
+        </div>
+        <table class="table table-hover table-bordered">
+            <thead>
+            <tr>
+<!--                <th width="60"><input type="checkbox" class="js-check-all" data-direction="x" data-checklist="js-check-x">全选</th>-->
+                <th>ID</th>
+                <th width="120">用户名</th>
+                <th>基本资料</th>
+                <th>姓名</th>
+                <th>手机号</th>
+                <th width="100">VIP会员</th>
+                <th width="100">充值过</th>
+                <th width="100">消费过</th>
+                <th width="100">跟进</th>
+                <th width="100">意向标签</th>
+                <th width="180">加入时间 <span class="row sort join-time" data-status="{$params.sort == 1? $params.sort_type : 'desc'}" onclick="sort(this,1)"><if condition="$params.sort eq 1 && $params.sort_type eq 'asc'">&#8595;<else>&#8593;</if></span></th>
+                <th width="140">坠海倒计时 <span class="row sort pool-time" data-status="{$params.sort == 2? $params.sort_type : 'desc'}" onclick="sort(this,2)"><if condition="$params.sort eq 2 && $params.sort_type eq 'asc'">&#8595;<else>&#8593;</if></span></th>
+                <th width="150">最后联系<span class="row sort last-time" data-status="{$params.sort == 3? $params.sort_type : 'desc'}" onclick="sort(this,3)"><if condition="$params.sort eq 3 && $params.sort_type eq 'asc'">&#8595;<else>&#8593;</if></span></th>
+                <th>操作</th>
+            </tr>
+            </thead>
+            <tbody>
+            <foreach name="list" item="vo">
+                <tr>
+<!--                    <td><input type="checkbox" class="js-check" data-yid="js-check-y" data-xid="js-check-x" name="ids[]" value="{$vo.id}" title="ID:{$vo.id}"></td>-->
+                    <td>{$vo.user_id}</td>
+                    <td>
+                        <img class="avatar" src="/upload/{$vo.avatar}"> <if condition="$vo['sex'] eq 1"><img class="sex" src="/static/images/male.png" alt=""><else><img class="sex" src="/static/images/fmale.png" alt=""></if> <span>{$vo['user_nickname']}</span>
+                    </td>
+                    <td>
+                        <p class="profile">{$vo.profile_text}</p>
+                    </td>
+                    <td>{$vo['real_name']}</td>
+                    <td><span <if condition="$vo.is_expired">class="expired"</if>>{$vo['mobile']? $vo['mobile']:'无'}</span></td>
+                    <td>
+                        <if condition="$vo['is_vip'] eq 1">
+                            <span style="color: green;">是</span>
+                            <else>
+                                <span style="color: red;">否</span>
+                        </if>
+                    </td>
+                    <td>
+                        <if condition="$vo['is_recharge'] eq 1">
+                            <span style="color: green;">是</span>
+                            <else>
+                                <span style="color: red;">否</span>
+                        </if>
+                    </td>
+                    <td>
+                        <if condition="$vo['is_cost'] eq 1">
+                            <span style="color: green;">是</span>
+                            <else>
+                                <span style="color: red;">否</span>
+                        </if>
+                    </td>
+                    <td><span id="follow-num{$vo.pool_id}">{$vo['followup_num']}</span></td>
+                    <td>
+                        <a onclick="setTag('{$vo.pool_id}','{$vo.real_name}','{$vo.intention}')" >{$vo.intention_text? $vo.intention_text: '设置'}</a>
+                    </td>
+                    <td>{$vo['create_time']}</td>
+                    <td><span <if condition="$vo.is_expired">class="expired"</if>>{$vo['expire_text']}</span></td>
+                    <td><span id="follow-time{$vo.pool_id}">{$vo['last_follow_time']? $vo['last_follow_time'] : '-'}</span></td>
+                    <td>
+                        <a onclick="setAgency('{$vo.pool_id}','{$vo.real_name}','{$vo.remark}','{$vo.agency}')" >跟进</a>
+                    </td>
+            </foreach>
+            </tbody>
+        </table>
+        <div class="pagination">{$page}</div>
+
+        <div id="tag" class="dialog" style="display: none; margin-top: 20px;">
+            <div class="form">
+                <form method="post" class="form-horizontal js-ajax-form margin-top-20" >
+                    <div class="form-group">
+                        <label class="col-sm-3 control-label"><span class="form-required">*</span>选择标签</label>
+                        <div class="col-sm-8">
+                            <foreach name="tags" item="vo" key="k">
+                            <label for="input-tag{$k}" class="radio-inline">
+                                <input type="radio" id="input-tag{$k}" name="tag" onchange="selectTag(this)" value="{$k}" data-name="{$vo}">{$vo}
+                            </label>
+                            </foreach>
+                        </div>
+                    </div>
+                </form>
+            </div>
+        </div>
+
+        <div id="agency" class="dialog" style="display: none; margin-top: 20px;">
+            <div class="form">
+                <form method="post" class="form-horizontal js-ajax-form margin-top-20" >
+                    <div class="form-group">
+                        <label class="col-sm-3 control-label"><span class="form-required"></span>真实姓名</label>
+                        <div class="col-sm-8">
+                            <input type="text" class="form-control" id="real_name" name="real_name" readonly value="">
+                        </div>
+                    </div>
+                    <div class="form-group">
+                        <label class="col-sm-3 control-label"><span class="form-required">*</span>跟进情况</label>
+                        <div class="col-sm-8">
+                            <foreach name="agencys" item="vo" key="k">
+                                <label for="input-agency{$k}" class="radio-inline">
+                                    <input type="radio" id="input-agency{$k}" name="agency" onchange="selectAgency(this)" value="{$k}">{$vo}
+                                </label>
+                            </foreach>
+                        </div>
+                    </div>
+                    <div class="form-group">
+                        <label class="col-sm-3 control-label"><span class="form-required"></span>备注</label>
+                        <div class="col-sm-8">
+                                <textarea class="form-control" id="remark" name="content" maxlength="150" style="height: 80px;" placeholder="跟进备注"></textarea>
+                        </div>
+                    </div>
+                </form>
+            </div>
+        </div>
+    </form>
+</div>
+<script src="__STATIC__/js/admin.js"></script>
+<script src="__STATIC__/js/clipboard.min.js"></script>
+<script src="__STATIC__/js/layer/layer.js"></script>
+<script src="__STATIC__/js/position/position1.js" type="text/javascript"></script>
+<script src="__STATIC__/js/height/height.js" type="text/javascript"></script>
+<script>
+    var tagId = 0;
+    var agencyId = 0;
+
+    /**
+     * 排序
+     * @param type
+     */
+    function sort(ele,type){
+        $("#sort").val(type);
+        var status = $(ele).attr('data-status');
+        $("#sortType").val(status=='desc'? 'asc': 'desc');
+        $(ele).html(status == 'desc'? '&#8595;' : '&#8593;');
+        $(ele).attr('data-status', status=='desc'? 'asc': 'desc');
+
+        $("#search").submit();
+
+    }
+
+    /**
+     * 选择销售用户
+     * @param ele
+     */
+    function selectTag(ele){
+        tagId = $(ele).val();
+    }
+
+    /**
+     * 跟进
+     * */
+    function selectAgency(ele){
+        agencyId = $(ele).val();
+    }
+
+    /**
+     * 设置标签
+     * @returns {boolean}
+     */
+    function setTag(pool_id,real_name,tagId){
+        $("input[name=tag]").attr('checked', false);
+        $("#input-tag"+tagId).attr('checked', "checked");
+        layer.open({
+            type: 1, //1:页面层,2:iframe层,3:加载层,4:tips层。
+            title: '设置[ID:'+pool_id+'-'+real_name+']用户资源的标签',
+            shadeClose: false, //不开启遮罩关闭,也就是说,点击弹出层其它地方不会关闭弹出框
+            shade: 0.8, //遮罩
+            offset: 'auto',
+            area: ['600px', '260px'],
+            content: $("#tag"),
+            btn: ['确定设置','取消'],
+            btnAlign: 'c',
+            yes: function(){
+                if(tagId<=0){
+                    layer.msg('请选择标签')
+                    return false;
+                }
+
+                if (confirm('确定设置标签吗?请谨慎操作')) {
+                    $.post('/admin/sales/setTag', {pool_id: pool_id, tagId: tagId}, function (res) {
+                        if (res.code == 1) {
+                            layer.msg(res.msg)
+                            var tagName = $("input-tag"+tagId).attr('data-name');
+                            $("#tag-row"+pool_id).text(tagName);
+                            /*setTimeout(function () {
+                                location.reload();
+                            }, 2000)*/
+                        } else {
+                            layer.msg(res.msg);
+                        }
+                    }, "json")
+                }
+            },
+            cancel: function(){
+
+            }
+        });
+        return false;
+    }
+
+    /**
+     * 设置跟进情况
+     * @returns {boolean}
+     */
+    function setAgency(pool_id,real_name,remark,agencyId){
+        console.log(5346)
+        $("input[name=agency]").attr('checked', false);
+        $("#input-agency"+agencyId).prop('checked', "true");
+        console.log(agency)
+        console.log($("#real_name"))
+        $("#real_name").val(real_name);
+        $("#remark").text(remark);
+
+        layer.open({
+            type: 1, //1:页面层,2:iframe层,3:加载层,4:tips层。
+            title: '设置[ID:'+pool_id+'-'+real_name+']用户跟进情况',
+            shadeClose: false, //不开启遮罩关闭,也就是说,点击弹出层其它地方不会关闭弹出框
+            shade: 0.8, //遮罩
+            offset: 'auto',
+            area: ['780px', '480px'],
+            content: $("#agency"),
+            btn: ['确定设置','取消'],
+            btnAlign: 'c',
+            yes: function(){
+                if(agencyId<=0){
+                    layer.msg('请选择跟进情况')
+                    return false;
+                }
+                remark = $("#remark").val();
+                console.log(remark)
+                if (confirm('确定设置跟进情况吗?请谨慎操作')) {
+                    $.post('/admin/sales/setAgency', {pool_id: pool_id, agencyId: agencyId, remark: remark}, function (res) {
+                        if (res.code == 1) {
+                            layer.msg(res.msg)
+                            $("#follow-num"+pool_id).text(res.data.num);
+                            $("#follow-time"+pool_id).text(res.data.time);
+                        } else {
+                            layer.msg(res.msg);
+                        }
+                    }, "json")
+                }
+            },
+            cancel: function(){
+
+            }
+        });
+        return false;
+    }
+
+    /**
+     * 清除
+     * @returns {boolean}
+     */
+    function doDelete() {
+        var ids = [];
+        $(".js-check:checked").each(function () {
+            var id = $(this).val();
+            if (id > 0) {
+                ids.push(id);
+            }
+        });
+        if (ids.length <= 0) {
+            layer.msg('请先选择操作项');
+            return false;
+        }
+        if (confirm('确定批量清除选择项?不可恢复')) {
+            $.post('/admin/pools/clear', {ids: ids}, function (res) {
+                if (res.code == 1) {
+                    layer.msg(res.msg);
+                    setTimeout(function () {
+                        location.reload();
+                    }, 800)
+                } else {
+                    layer.msg(res.msg);
+                }
+            }, "json")
+        }
+
+    }
+</script>
+
+</body>
+</html>

+ 113 - 16
public/themes/admin_simpleboot3/admin/sales/index.html

@@ -60,6 +60,14 @@
         font-style: normal;
         color: red;
     }
+
+    .layui-layer-page .layui-layer-content {
+        overflow: hidden !important;
+    }
+
+    span.expired {
+        color: red;
+    }
 </style>
 <body>
 <div class="wrap js-check-wrap">
@@ -86,7 +94,7 @@
         <input type="submit" class="btn btn-primary margin-left-10 " value="搜索"/>
 
         <a class="btn btn-default margin-left-10" href="{:url('admin/sales/index')}">清空</a>
-        <a class="btn btn-warning margin-left-10" href="{:url('admin/sales/export')}">导出</a>
+<!--        <a class="btn btn-warning margin-left-10" href="{:url('admin/sales/export')}">导出</a>-->
     </form>
     <form class="form-horizontal js-ajax-form margin-top-20" role="form">
         <div class="table-actions">
@@ -124,7 +132,7 @@
                         <p class="profile">{$vo.profile_text}</p>
                     </td>
                     <td>{$vo['real_name']}</td>
-                    <td>{$vo['mobile']? $vo['mobile']:'无'}</td>
+                    <td><span <if condition="$vo.is_expired">class="expired"</if>>{$vo['mobile']? $vo['mobile']:'无'}</span></td>
                     <td>
                         <if condition="$vo['is_vip'] eq 1">
                             <span style="color: green;">是</span>
@@ -146,13 +154,15 @@
                                 <span style="color: red;">否</span>
                         </if>
                     </td>
-                    <td>{$vo['followup_num']}</td>
-                    <td><a title="点击设置标签" onclick="setTag('{$vo.pool_id}','{$vo.real_name}','{$vo.intention}')">{$vo['intention_text']?$vo['intention_text']:'设置'}</a></td>
+                    <td><span id="follow-num{$vo.pool_id}">{$vo['followup_num']}</span></td>
+                    <td>
+                        <a onclick="setTag('{$vo.pool_id}','{$vo.real_name}','{$vo.intention}')" >{$vo.intention_text? $vo.intention_text: '设置'}</a>
+                    </td>
                     <td>{$vo['create_time']}</td>
-                    <td>{$vo['expire_text']}</td>
-                    <td>{$vo['last_follow_time']? $vo['last_follow_time'] : '-'}</td>
+                    <td><span <if condition="$vo.is_expired">class="expired"</if>>{$vo['expire_text']}</span></td>
+                    <td><span id="follow-time{$vo.pool_id}">{$vo['last_follow_time']? $vo['last_follow_time'] : '-'}</span></td>
                     <td>
-                        <a onclick="follow('{$vo.pool_id}','{$vo.real_name}','{$vo.pool_id}','{$vo.agency}')">跟进</a>
+                        <a onclick="setAgency('{$vo.pool_id}','{$vo.real_name}','{$vo.remark}','{$vo.agency}')" >跟进</a>
                     </td>
             </foreach>
             </tbody>
@@ -167,7 +177,7 @@
                         <div class="col-sm-8">
                             <foreach name="tags" item="vo" key="k">
                             <label for="input-tag{$k}" class="radio-inline">
-                                <input type="radio" id="input-tag{$k}" name="tag" onchange="selectTag(this)" value="{$k}" <if condition="$k eq 0">checked="checked"</if>>{$vo}
+                                <input type="radio" id="input-tag{$k}" name="tag" onchange="selectTag(this)" value="{$k}" data-name="{$vo}">{$vo}
                             </label>
                             </foreach>
                         </div>
@@ -175,6 +185,35 @@
                 </form>
             </div>
         </div>
+
+        <div id="agency" class="dialog" style="display: none; margin-top: 20px;">
+            <div class="form">
+                <form method="post" class="form-horizontal js-ajax-form margin-top-20" >
+                    <div class="form-group">
+                        <label class="col-sm-3 control-label"><span class="form-required"></span>真实姓名</label>
+                        <div class="col-sm-8">
+                            <input type="text" class="form-control" id="real_name" name="real_name" readonly value="">
+                        </div>
+                    </div>
+                    <div class="form-group">
+                        <label class="col-sm-3 control-label"><span class="form-required">*</span>跟进情况</label>
+                        <div class="col-sm-8">
+                            <foreach name="agencys" item="vo" key="k">
+                                <label for="input-agency{$k}" class="radio-inline">
+                                    <input type="radio" id="input-agency{$k}" name="agency" onchange="selectAgency(this)" value="{$k}">{$vo}
+                                </label>
+                            </foreach>
+                        </div>
+                    </div>
+                    <div class="form-group">
+                        <label class="col-sm-3 control-label"><span class="form-required"></span>备注</label>
+                        <div class="col-sm-8">
+                                <textarea class="form-control" id="remark" name="content" maxlength="150" style="height: 80px;" placeholder="跟进备注"></textarea>
+                        </div>
+                    </div>
+                </form>
+            </div>
+        </div>
     </form>
 </div>
 <script src="__STATIC__/js/admin.js"></script>
@@ -184,6 +223,7 @@
 <script src="__STATIC__/js/height/height.js" type="text/javascript"></script>
 <script>
     var tagId = 0;
+    var agencyId = 0;
 
     /**
      * 排序
@@ -209,13 +249,19 @@
     }
 
     /**
-     * 分配资源
+     * 跟进
+     * */
+    function selectAgency(ele){
+        agencyId = $(ele).val();
+    }
+
+    /**
+     * 设置标签
      * @returns {boolean}
      */
-    function setTag(pool_id,real_name,intention){
+    function setTag(pool_id,real_name,tagId){
         $("input[name=tag]").attr('checked', false);
-        $("#input-tag"+intention).attr('checked', "checked");
-
+        $("#input-tag"+tagId).attr('checked', "checked");
         layer.open({
             type: 1, //1:页面层,2:iframe层,3:加载层,4:tips层。
             title: '设置[ID:'+pool_id+'-'+real_name+']用户资源的标签',
@@ -223,7 +269,7 @@
             shade: 0.8, //遮罩
             offset: 'auto',
             area: ['600px', '260px'],
-            content: $("#tag").html(),
+            content: $("#tag"),
             btn: ['确定设置','取消'],
             btnAlign: 'c',
             yes: function(){
@@ -232,13 +278,64 @@
                     return false;
                 }
 
-                if (confirm('确定批量分配选择项?不可恢复')) {
+                if (confirm('确定设置标签吗?请谨慎操作')) {
                     $.post('/admin/sales/setTag', {pool_id: pool_id, tagId: tagId}, function (res) {
                         if (res.code == 1) {
                             layer.msg(res.msg)
-                            setTimeout(function () {
+                            var tagName = $("input-tag"+tagId).attr('data-name');
+                            $("#tag-row"+pool_id).text(tagName);
+                            /*setTimeout(function () {
                                 location.reload();
-                            }, 2000)
+                            }, 2000)*/
+                        } else {
+                            layer.msg(res.msg);
+                        }
+                    }, "json")
+                }
+            },
+            cancel: function(){
+
+            }
+        });
+        return false;
+    }
+
+    /**
+     * 设置跟进情况
+     * @returns {boolean}
+     */
+    function setAgency(pool_id,real_name,remark,agencyId){
+        console.log(5346)
+        $("input[name=agency]").attr('checked', false);
+        $("#input-agency"+agencyId).prop('checked', "true");
+        console.log(agency)
+        console.log($("#real_name"))
+        $("#real_name").val(real_name);
+        $("#remark").text(remark);
+
+        layer.open({
+            type: 1, //1:页面层,2:iframe层,3:加载层,4:tips层。
+            title: '设置[ID:'+pool_id+'-'+real_name+']用户跟进情况',
+            shadeClose: false, //不开启遮罩关闭,也就是说,点击弹出层其它地方不会关闭弹出框
+            shade: 0.8, //遮罩
+            offset: 'auto',
+            area: ['780px', '480px'],
+            content: $("#agency"),
+            btn: ['确定设置','取消'],
+            btnAlign: 'c',
+            yes: function(){
+                if(agencyId<=0){
+                    layer.msg('请选择跟进情况')
+                    return false;
+                }
+                remark = $("#remark").val();
+                console.log(remark)
+                if (confirm('确定设置跟进情况吗?请谨慎操作')) {
+                    $.post('/admin/sales/setAgency', {pool_id: pool_id, agencyId: agencyId, remark: remark}, function (res) {
+                        if (res.code == 1) {
+                            layer.msg(res.msg)
+                            $("#follow-num"+pool_id).text(res.data.num);
+                            $("#follow-time"+pool_id).text(res.data.time);
                         } else {
                             layer.msg(res.msg);
                         }

+ 391 - 0
public/themes/admin_simpleboot3/admin/sales/tips.html

@@ -0,0 +1,391 @@
+<include file="public@header"/>
+</head>
+<style>
+    .form-inline .form-control {
+        margin: 10px 0;
+        vertical-align: middle;
+    }
+
+    .form-inline span {
+        margin-left: 5px;
+        vertical-align: middle;
+    }
+    .margin-left-10 {
+        margin-left: 10px;
+    }
+
+    .profile em {
+        font-style: normal;
+        color: #0b6cbc;
+    }
+
+    .profile em.red {
+        color: red;
+    }
+
+    span.sort {
+        color: red;
+        display: inline-block;
+        margin-left: 2px;
+        vertical-align: middle;
+    }
+    td img.avatar, td img.sex {
+        width: 24px;
+        height: 24px;
+        vertical-align: middle;
+        border-radius: 100%;
+    }
+    .form .form-control {
+        margin-bottom: 20px;
+    }
+    .form .control-label {
+        text-align: center;
+    }
+
+    .form label {
+        text-align: left;
+        margin-bottom: 10px;
+        margin-right: 10px;
+    }
+
+    .radio-inline+.radio-inline, .checkbox-inline+.checkbox-inline {
+        margin-left: 0;
+    }
+
+    .table-actions span {
+        margin-right: 10px;
+        font-weight: bold;
+    }
+    .table-actions span em {
+        font-style: normal;
+        color: red;
+    }
+
+    .layui-layer-page .layui-layer-content {
+        overflow: hidden !important;
+    }
+
+    span.expired {
+        color: red;
+    }
+</style>
+<body>
+<div class="wrap js-check-wrap">
+    <ul class="nav nav-tabs">
+        <li class="active"><a>标签分类资源</a>
+        </li>
+    </ul>
+    <form id="search" class="well form-inline margin-top-20" method="post" action="{:url('admin/sales/tips')}">
+        <span>会员ID:</span>
+        <input class="form-control" type="text" name="uid" style="width: 150px;" value="{:input('request.uid')}"
+               placeholder="会员ID">
+        <span>用户昵称:</span>
+        <input class="form-control" type="text" name="user_nickname" style="width: 200px;"
+               value="{:input('request.user_nickname')}" placeholder="用户昵称"><br>
+        <span>用户姓名:</span>
+        <input class="form-control" type="text" name="real_name" style="width: 200px;"
+               value="{:input('request.real_name')}" placeholder="用户姓名">
+        <span>手机号:</span>
+        <input class="form-control" type="text" name="mobile" style="width: 200px;" value="{:input('request.mobile')}"
+               placeholder="手机号">
+
+        <input id="sort" type="hidden" name="sort" value="{$params.sort?$params.sort: 1}">
+        <input id="sortType" type="hidden" name="sort_type" value="{$params.sort_type?$params.sort_type: 'desc'}">
+        <input type="submit" class="btn btn-primary margin-left-10 " value="搜索"/>
+
+        <a class="btn btn-default margin-left-10" href="{:url('admin/sales/tips')}">清空</a>
+<!--        <a class="btn btn-warning margin-left-10" href="{:url('admin/sales/export')}">导出</a>-->
+    </form>
+    <form class="form-horizontal js-ajax-form margin-top-20" role="form">
+        <div class="table-actions tags">
+            <foreach name="tagCounts" item="vo" key="k">
+                <if condition="$k gt 0">
+                    <a  href="{:url('admin/sales/tips',['intention'=> $k])}" <if condition="$k eq $params.intention">class="btn btn-primary margin-left-10"<else>class="btn btn-default margin-left-10"</if>>{$vo.name}({$vo.num})</a>
+                <else>
+                    <a  href="{:url('admin/sales/tips',['intention'=> $k])}" <if condition="$k eq $params.intention">class="btn btn-primary margin-left-10"<else>class="btn btn-default margin-left-10"</if>>全部({$total})</a>
+                </if>
+            </foreach>
+        </div>
+        <table class="table table-hover table-bordered">
+            <thead>
+            <tr>
+<!--                <th width="60"><input type="checkbox" class="js-check-all" data-direction="x" data-checklist="js-check-x">全选</th>-->
+                <th>ID</th>
+                <th width="120">用户名</th>
+                <th>基本资料</th>
+                <th>姓名</th>
+                <th>手机号</th>
+                <th width="100">VIP会员</th>
+                <th width="100">充值过</th>
+                <th width="100">消费过</th>
+                <th width="100">跟进</th>
+                <th width="100">意向标签</th>
+                <th width="180">加入时间 <span class="row sort join-time" data-status="{$params.sort == 1? $params.sort_type : 'desc'}" onclick="sort(this,1)"><if condition="$params.sort eq 1 && $params.sort_type eq 'asc'">&#8595;<else>&#8593;</if></span></th>
+                <th width="140">坠海倒计时 <span class="row sort pool-time" data-status="{$params.sort == 2? $params.sort_type : 'desc'}" onclick="sort(this,2)"><if condition="$params.sort eq 2 && $params.sort_type eq 'asc'">&#8595;<else>&#8593;</if></span></th>
+                <th width="150">最后联系<span class="row sort last-time" data-status="{$params.sort == 3? $params.sort_type : 'desc'}" onclick="sort(this,3)"><if condition="$params.sort eq 3 && $params.sort_type eq 'asc'">&#8595;<else>&#8593;</if></span></th>
+                <th>操作</th>
+            </tr>
+            </thead>
+            <tbody>
+            <foreach name="list" item="vo">
+                <tr>
+<!--                    <td><input type="checkbox" class="js-check" data-yid="js-check-y" data-xid="js-check-x" name="ids[]" value="{$vo.id}" title="ID:{$vo.id}"></td>-->
+                    <td>{$vo.user_id}</td>
+                    <td>
+                        <img class="avatar" src="/upload/{$vo.avatar}"> <if condition="$vo['sex'] eq 1"><img class="sex" src="/static/images/male.png" alt=""><else><img class="sex" src="/static/images/fmale.png" alt=""></if> <span>{$vo['user_nickname']}</span>
+                    </td>
+                    <td>
+                        <p class="profile">{$vo.profile_text}</p>
+                    </td>
+                    <td>{$vo['real_name']}</td>
+                    <td><span <if condition="$vo.is_expired">class="expired"</if>>{$vo['mobile']? $vo['mobile']:'无'}</span></td>
+                    <td>
+                        <if condition="$vo['is_vip'] eq 1">
+                            <span style="color: green;">是</span>
+                            <else>
+                                <span style="color: red;">否</span>
+                        </if>
+                    </td>
+                    <td>
+                        <if condition="$vo['is_recharge'] eq 1">
+                            <span style="color: green;">是</span>
+                            <else>
+                                <span style="color: red;">否</span>
+                        </if>
+                    </td>
+                    <td>
+                        <if condition="$vo['is_cost'] eq 1">
+                            <span style="color: green;">是</span>
+                            <else>
+                                <span style="color: red;">否</span>
+                        </if>
+                    </td>
+                    <td><span id="follow-num{$vo.pool_id}">{$vo['followup_num']}</span></td>
+                    <td>
+                        <a onclick="setTag('{$vo.pool_id}','{$vo.real_name}','{$vo.intention}')" >{$vo.intention_text? $vo.intention_text: '设置'}</a>
+                    </td>
+                    <td>{$vo['create_time']}</td>
+                    <td><span <if condition="$vo.is_expired">class="expired"</if>>{$vo['expire_text']}</span></td>
+                    <td><span id="follow-time{$vo.pool_id}">{$vo['last_follow_time']? $vo['last_follow_time'] : '-'}</span></td>
+                    <td>
+                        <a onclick="setAgency('{$vo.pool_id}','{$vo.real_name}','{$vo.remark}','{$vo.agency}')" >跟进</a>
+                    </td>
+            </foreach>
+            </tbody>
+        </table>
+        <div class="pagination">{$page}</div>
+
+        <div id="tag" class="dialog" style="display: none; margin-top: 20px;">
+            <div class="form">
+                <form method="post" class="form-horizontal js-ajax-form margin-top-20" >
+                    <div class="form-group">
+                        <label class="col-sm-3 control-label"><span class="form-required">*</span>选择标签</label>
+                        <div class="col-sm-8">
+                            <foreach name="tags" item="vo" key="k">
+                            <label for="input-tag{$k}" class="radio-inline">
+                                <input type="radio" id="input-tag{$k}" name="tag" onchange="selectTag(this)" value="{$k}" data-name="{$vo}">{$vo}
+                            </label>
+                            </foreach>
+                        </div>
+                    </div>
+                </form>
+            </div>
+        </div>
+
+        <div id="agency" class="dialog" style="display: none; margin-top: 20px;">
+            <div class="form">
+                <form method="post" class="form-horizontal js-ajax-form margin-top-20" >
+                    <div class="form-group">
+                        <label class="col-sm-3 control-label"><span class="form-required"></span>真实姓名</label>
+                        <div class="col-sm-8">
+                            <input type="text" class="form-control" id="real_name" name="real_name" readonly value="">
+                        </div>
+                    </div>
+                    <div class="form-group">
+                        <label class="col-sm-3 control-label"><span class="form-required">*</span>跟进情况</label>
+                        <div class="col-sm-8">
+                            <foreach name="agencys" item="vo" key="k">
+                                <label for="input-agency{$k}" class="radio-inline">
+                                    <input type="radio" id="input-agency{$k}" name="agency" onchange="selectAgency(this)" value="{$k}">{$vo}
+                                </label>
+                            </foreach>
+                        </div>
+                    </div>
+                    <div class="form-group">
+                        <label class="col-sm-3 control-label"><span class="form-required"></span>备注</label>
+                        <div class="col-sm-8">
+                                <textarea class="form-control" id="remark" name="content" maxlength="150" style="height: 80px;" placeholder="跟进备注"></textarea>
+                        </div>
+                    </div>
+                </form>
+            </div>
+        </div>
+    </form>
+</div>
+<script src="__STATIC__/js/admin.js"></script>
+<script src="__STATIC__/js/clipboard.min.js"></script>
+<script src="__STATIC__/js/layer/layer.js"></script>
+<script src="__STATIC__/js/position/position1.js" type="text/javascript"></script>
+<script src="__STATIC__/js/height/height.js" type="text/javascript"></script>
+<script>
+    var tagId = 0;
+    var agencyId = 0;
+
+    /**
+     * 排序
+     * @param type
+     */
+    function sort(ele,type){
+        $("#sort").val(type);
+        var status = $(ele).attr('data-status');
+        $("#sortType").val(status=='desc'? 'asc': 'desc');
+        $(ele).html(status == 'desc'? '&#8595;' : '&#8593;');
+        $(ele).attr('data-status', status=='desc'? 'asc': 'desc');
+
+        $("#search").submit();
+
+    }
+
+    /**
+     * 选择销售用户
+     * @param ele
+     */
+    function selectTag(ele){
+        tagId = $(ele).val();
+    }
+
+    /**
+     * 跟进
+     * */
+    function selectAgency(ele){
+        agencyId = $(ele).val();
+    }
+
+    /**
+     * 设置标签
+     * @returns {boolean}
+     */
+    function setTag(pool_id,real_name,tagId){
+        $("input[name=tag]").attr('checked', false);
+        $("#input-tag"+tagId).attr('checked', "checked");
+        layer.open({
+            type: 1, //1:页面层,2:iframe层,3:加载层,4:tips层。
+            title: '设置[ID:'+pool_id+'-'+real_name+']用户资源的标签',
+            shadeClose: false, //不开启遮罩关闭,也就是说,点击弹出层其它地方不会关闭弹出框
+            shade: 0.8, //遮罩
+            offset: 'auto',
+            area: ['600px', '260px'],
+            content: $("#tag"),
+            btn: ['确定设置','取消'],
+            btnAlign: 'c',
+            yes: function(){
+                if(tagId<=0){
+                    layer.msg('请选择标签')
+                    return false;
+                }
+
+                if (confirm('确定设置标签吗?请谨慎操作')) {
+                    $.post('/admin/sales/setTag', {pool_id: pool_id, tagId: tagId}, function (res) {
+                        if (res.code == 1) {
+                            layer.msg(res.msg)
+                            var tagName = $("input-tag"+tagId).attr('data-name');
+                            $("#tag-row"+pool_id).text(tagName);
+                            /*setTimeout(function () {
+                                location.reload();
+                            }, 2000)*/
+                        } else {
+                            layer.msg(res.msg);
+                        }
+                    }, "json")
+                }
+            },
+            cancel: function(){
+
+            }
+        });
+        return false;
+    }
+
+    /**
+     * 设置跟进情况
+     * @returns {boolean}
+     */
+    function setAgency(pool_id,real_name,remark,agencyId){
+        console.log(5346)
+        $("input[name=agency]").attr('checked', false);
+        $("#input-agency"+agencyId).prop('checked', "true");
+        console.log(agency)
+        console.log($("#real_name"))
+        $("#real_name").val(real_name);
+        $("#remark").text(remark);
+
+        layer.open({
+            type: 1, //1:页面层,2:iframe层,3:加载层,4:tips层。
+            title: '设置[ID:'+pool_id+'-'+real_name+']用户跟进情况',
+            shadeClose: false, //不开启遮罩关闭,也就是说,点击弹出层其它地方不会关闭弹出框
+            shade: 0.8, //遮罩
+            offset: 'auto',
+            area: ['780px', '480px'],
+            content: $("#agency"),
+            btn: ['确定设置','取消'],
+            btnAlign: 'c',
+            yes: function(){
+                if(agencyId<=0){
+                    layer.msg('请选择跟进情况')
+                    return false;
+                }
+                remark = $("#remark").val();
+                console.log(remark)
+                if (confirm('确定设置跟进情况吗?请谨慎操作')) {
+                    $.post('/admin/sales/setAgency', {pool_id: pool_id, agencyId: agencyId, remark: remark}, function (res) {
+                        if (res.code == 1) {
+                            layer.msg(res.msg)
+                            $("#follow-num"+pool_id).text(res.data.num);
+                            $("#follow-time"+pool_id).text(res.data.time);
+                        } else {
+                            layer.msg(res.msg);
+                        }
+                    }, "json")
+                }
+            },
+            cancel: function(){
+
+            }
+        });
+        return false;
+    }
+
+    /**
+     * 清除
+     * @returns {boolean}
+     */
+    function doDelete() {
+        var ids = [];
+        $(".js-check:checked").each(function () {
+            var id = $(this).val();
+            if (id > 0) {
+                ids.push(id);
+            }
+        });
+        if (ids.length <= 0) {
+            layer.msg('请先选择操作项');
+            return false;
+        }
+        if (confirm('确定批量清除选择项?不可恢复')) {
+            $.post('/admin/pools/clear', {ids: ids}, function (res) {
+                if (res.code == 1) {
+                    layer.msg(res.msg);
+                    setTimeout(function () {
+                        location.reload();
+                    }, 800)
+                } else {
+                    layer.msg(res.msg);
+                }
+            }, "json")
+        }
+
+    }
+</script>
+
+</body>
+</html>

+ 8 - 2
vendor/thinkcmf/cmf-app/src/admin/controller/PoolsController.php

@@ -128,6 +128,7 @@ class PoolsController extends AdminBaseController
         PRedis::set("caches:export:pools", $params, 86400);
         $this->assign('params', $params);
         $this->assign('total', $total);
+        $this->assign('is_admin', cmf_get_current_admin_id());
         $this->assign('list', $datas['data']);
         $this->assign('sales', UserModel::getSales());
         $this->assign('page', $page);
@@ -245,6 +246,7 @@ class PoolsController extends AdminBaseController
         $this->assign('params', $params);
         $this->assign('total', $total);
         $this->assign('list', $datas['data']);
+        $this->assign('is_admin', cmf_get_current_admin_id());
         $this->assign('sales', UserModel::getSales());
         $this->assign('page', $page);
         return $this->fetch();
@@ -361,6 +363,7 @@ class PoolsController extends AdminBaseController
         $this->assign('params', $params);
         $this->assign('total', $total);
         $this->assign('list', $datas['data']);
+        $this->assign('is_admin', cmf_get_current_admin_id());
         $this->assign('sales', UserModel::getSales());
         $this->assign('page', $page);
         return $this->fetch();
@@ -482,6 +485,7 @@ class PoolsController extends AdminBaseController
         $this->assign('total', $total);
         $this->assign('list', $datas['data']);
         $this->assign('sales', UserModel::getSales());
+        $this->assign('is_admin', cmf_get_current_admin_id());
         $this->assign('page', $page);
         return $this->fetch();
     }
@@ -600,6 +604,7 @@ class PoolsController extends AdminBaseController
         $this->assign('total', $total);
         $this->assign('list', $datas['data']);
         $this->assign('sales', UserModel::getSales());
+        $this->assign('is_admin', cmf_get_current_admin_id());
         $this->assign('page', $page);
         return $this->fetch();
     }
@@ -652,11 +657,12 @@ class PoolsController extends AdminBaseController
         
         $saleUid = input('sale_uid', 0);
         $type = input('type', 1);
+        $expireAt = input('expire_at', 0);
         if($saleUid<=0){
             $this->error("请选择分配给的销售用户!", '');
         }
-        
-        if($result = PoolModel::distributeMore($saleUid, $ids, $type)){
+        $expireAt = $expireAt>0? $expireAt : -1;
+        if($result = PoolModel::distributeMore($saleUid, $ids, $type, $expireAt)){
             $this->success('分配成功!');
         }else if($result == -1){
             $this->error('请先正确设置坠海参数');

+ 388 - 4
vendor/thinkcmf/cmf-app/src/admin/controller/SalesController.php

@@ -14,11 +14,19 @@ use app\user\model\UserModel;
 use app\weixin\model\AccountLog;
 use app\weixin\model\UserRechargeLog;
 use cmf\controller\AdminBaseController;
+use think\Db;
 
 class SalesController extends AdminBaseController
 {
+    /**
+     * 我的资源库
+     * @return mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
     public function index(){
-        $content = hook_one('admin_pools_presale_view');
+        $content = hook_one('admin_sales_index_view');
 
         if (!empty($content)) {
             return $content;
@@ -32,6 +40,7 @@ class SalesController extends AdminBaseController
             ->leftJoin('user u','p.user_id=u.id')
             ->leftJoin('user s','s.id=p.sale_uid')
             ->leftJoin('user_profile up','up.userid=u.id')
+            ->where('p.expire_at','>=', date('Y-m-d H:i:s', time() - 3* 86400))
             ->where(['u.user_status'=> 1,'u.user_type'=> 2,'p.sale_uid'=> session('ADMIN_ID'),'p.status'=>1])
             ->where(function($query) use($params){
                 $uid = isset($params['uid'])? $params['uid'] : 0;
@@ -54,7 +63,7 @@ class SalesController extends AdminBaseController
                     $query->where('u.mobile','like',"{$mobile}%");
                 }
             })
-            ->field('p.id,p.user_id,u.openid,u.user_nickname,u.real_name,u.avatar,u.vip_auth,u.vip_expire,u.user_status,u.mobile,up.graduate,up.age,u.birthday,u.sex,up.married,up.education,up.city,p.id as pool_id,p.intention,p.followup_num,p.agency,p.create_time,p.last_follow_time,p.expire_at')
+            ->field('p.id,p.user_id,u.openid,u.user_nickname,u.real_name,u.avatar,u.vip_auth,u.vip_expire,u.user_status,u.mobile,up.graduate,up.age,u.birthday,u.sex,up.married,up.education,up.city,p.id as pool_id,p.intention,p.followup_num,p.agency,p.remark,p.create_time,p.last_follow_time,p.expire_at')
             ->order($sort);
 
         $total = $list->count('p.id');
@@ -64,6 +73,312 @@ class SalesController extends AdminBaseController
         $page = $list->render();
         $datas = $list ? $list->toArray() : [];
         $tags = ['无','意向强','有意向','完全不考虑','已到店','已成交','其他'];
+        $agencys = ['无','今天需跟进','明天需跟进','到期未跟进','今天坠海','明天坠海','一礼拜后坠海','其他'];
+        if ($datas) {
+            $educations = config('weixin.educations');
+            $marrieds = config('weixin.marrieds');
+            foreach ($datas['data'] as $k => &$item) {
+                $item['avatar'] = $item['avatar']? cmf_get_image_preview_url($item['avatar']):'';
+
+                $isVip = isset($item['vip_auth'])? $item['vip_auth'] : 0;
+                $vipExpire = isset($item['vip_expire'])? $item['vip_expire'] : 0;
+                $item['is_vip'] = $isVip && time() < $vipExpire? 1 : 0;
+
+                // 是否充值和消费过
+                $item['is_recharge'] = UserRechargeLog::check($item['id'], 2);
+                $item['is_cost'] = AccountLog::check($item['id']);
+
+                $profile = [];
+                $birthday = isset($item['birthday'])? $item['birthday'] : 0;
+                $year = $birthday? date('Y', $birthday) : '';
+                if($year){
+                    $profile[] =  '<em class="red">'.(date('Y') - $year).'</em>岁(<em class="primary">'.$year.'</em>)';
+                }
+
+                $married = isset($item['married'])? $item['married'] : 0;
+                $marriedText = isset($marrieds[$married])? $marrieds[$married] : '';
+                if($marriedText){
+                    $profile[] = $marriedText;
+                }
+
+                $education = isset($item['education'])? $item['education'] : 0;
+                $educationText = $education && isset($educations[$education])? $educations[$education] : '';
+                if($educationText){
+                    $profile[] = $educationText;
+                }
+
+                if(isset($item['graduate']) && $item['graduate']){
+                    $profile[] = $item['graduate'];
+                }
+
+                $city = isset($item['city'])? $item['city'] : '';
+                if($city){
+                    $profile[] = $city;
+                }
+
+                $item['profile_text'] = $profile? join(' ', $profile) : '';
+
+                $dayTime = strtotime(date('Y-m-d'));
+                $expireAt = isset($item['expire_at'])? $item['expire_at'] : '';
+                $time = strtotime($expireAt);
+                $expireTime = $expireAt? strtotime($expireAt) - time() : 0;
+                $day = $expireTime>0? intval($expireTime/(24*3600)) : 0;
+                $hour = $expireTime>0? intval(($expireTime-($day*24*3600))/3600) : 0;
+                $item['expire_text'] = $day? $day.'天'.$hour.'小时' : '已坠海';
+                $item['is_expired'] = 0;
+                if($time >= time() && $time < $dayTime + 86400){
+                    $item['expire_text'] = '今天坠海';
+                    $item['is_expired'] = 1;
+                }else if($time>=$dayTime+86400 && $time < $dayTime + 2 * 86400){
+                    $item['expire_text'] = '明天坠海';
+                    $item['is_expired'] = 1;
+                }else if($time>=$dayTime+7*86400 && $time < $dayTime + 15 * 86400){
+                    $item['expire_text'] = '一礼拜后坠海';
+                }else if($expireTime <= 0 ){
+                    $item['mobile'] = formatStr($item['mobile']);
+                    $item['is_expired'] = 1;
+                    $item['expire_text'] = '已坠海';
+                }
+
+                $intention = isset($item['intention'])? $item['intention'] : 0;
+                $item['intention_text'] = $intention && isset($tags[$intention])? $tags[$intention] : '';
+
+            }
+            unset($item);
+        }
+
+        $this->assign('params', $params);
+        $this->assign('tags', $tags);
+        $this->assign('agencys', $agencys);
+        $this->assign('total', $total);
+        $this->assign('list', $datas['data']);
+        $this->assign('sales', UserModel::getSales());
+        $this->assign('page', $page);
+        return $this->fetch();
+    }
+
+    /**
+     * 我的标签分类资源库
+     * @return mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function tips(){
+        $content = hook_one('admin_sales_agency_view');
+
+        if (!empty($content)) {
+            return $content;
+        }
+
+        $params = input();
+        $params['sort'] = isset($params['sort'])? $params['sort'] : 0;
+        $params['intention'] = isset($params['intention'])? $params['intention'] : 0;
+        $params['sort_type'] = isset($params['sort_type'])? $params['sort_type'] : 'desc';
+        $sort = $params['sort']==1? "p.create_time {$params['sort_type']}" : ($params['sort']==2? "p.expire_at {$params['sort_type']}" : "p.last_follow_time {$params['sort_type']}");
+        $list  = PoolModel::alias('p')
+            ->leftJoin('user u','p.user_id=u.id')
+            ->leftJoin('user s','s.id=p.sale_uid')
+            ->leftJoin('user_profile up','up.userid=u.id')
+            ->where('p.expire_at','>=', date('Y-m-d H:i:s', time() - 3* 86400))
+            ->where(['u.user_status'=> 1,'u.user_type'=> 2,'p.sale_uid'=> session('ADMIN_ID'),'p.status'=>1])
+            ->where(function($query) use($params){
+                $uid = isset($params['uid'])? $params['uid'] : 0;
+                if($uid){
+                    $query->where(['u.id'=> $uid]);
+                }
+
+                $intention = isset($params['intention'])? intval($params['intention']) : 0;
+                if($intention){
+                    $query->where('p.intention',$intention);
+                }
+
+                $nickname = isset($params['user_nickname'])? trim($params['user_nickname']) : '';
+                if($nickname){
+                    $query->where('u.user_nickname','like',"{$nickname}%");
+                }
+
+                $realname = isset($params['real_name'])? trim($params['real_name']) : '';
+                if($realname){
+                    $query->where('u.real_name','like',"{$realname}%");
+                }
+
+                $mobile = isset($params['mobile'])? trim($params['mobile']) : '';
+                if($mobile){
+                    $query->where('u.mobile','like',"{$mobile}%");
+                }
+            })
+            ->field('p.id,p.user_id,u.openid,u.user_nickname,u.real_name,u.avatar,u.vip_auth,u.vip_expire,u.user_status,u.mobile,up.graduate,up.age,u.birthday,u.sex,up.married,up.education,up.city,p.id as pool_id,p.intention,p.followup_num,p.agency,p.remark,p.create_time,p.last_follow_time,p.expire_at')
+            ->order($sort)
+            ->paginate(30, false, ['query' => request()->param()]);
+
+        // 获取分页显示
+        $page = $list->render();
+        $datas = $list ? $list->toArray() : [];
+        $tags = ['无','意向强','有意向','完全不考虑','已到店','已成交','其他'];
+        $agencys = ['无','今天需跟进','明天需跟进','到期未跟进','今天坠海','明天坠海','一礼拜后坠海','其他'];
+        if ($datas) {
+            $educations = config('weixin.educations');
+            $marrieds = config('weixin.marrieds');
+            foreach ($datas['data'] as $k => &$item) {
+                $item['avatar'] = $item['avatar']? cmf_get_image_preview_url($item['avatar']):'';
+
+                $isVip = isset($item['vip_auth'])? $item['vip_auth'] : 0;
+                $vipExpire = isset($item['vip_expire'])? $item['vip_expire'] : 0;
+                $item['is_vip'] = $isVip && time() < $vipExpire? 1 : 0;
+
+                // 是否充值和消费过
+                $item['is_recharge'] = UserRechargeLog::check($item['id'], 2);
+                $item['is_cost'] = AccountLog::check($item['id']);
+
+                $profile = [];
+                $birthday = isset($item['birthday'])? $item['birthday'] : 0;
+                $year = $birthday? date('Y', $birthday) : '';
+                if($year){
+                    $profile[] =  '<em class="red">'.(date('Y') - $year).'</em>岁(<em class="primary">'.$year.'</em>)';
+                }
+
+                $married = isset($item['married'])? $item['married'] : 0;
+                $marriedText = isset($marrieds[$married])? $marrieds[$married] : '';
+                if($marriedText){
+                    $profile[] = $marriedText;
+                }
+
+                $education = isset($item['education'])? $item['education'] : 0;
+                $educationText = $education && isset($educations[$education])? $educations[$education] : '';
+                if($educationText){
+                    $profile[] = $educationText;
+                }
+
+                if(isset($item['graduate']) && $item['graduate']){
+                    $profile[] = $item['graduate'];
+                }
+
+                $city = isset($item['city'])? $item['city'] : '';
+                if($city){
+                    $profile[] = $city;
+                }
+
+                $item['profile_text'] = $profile? join(' ', $profile) : '';
+
+                $dayTime = strtotime(date('Y-m-d'));
+                $expireAt = isset($item['expire_at'])? $item['expire_at'] : '';
+                $time = strtotime($expireAt);
+                $expireTime = $expireAt? strtotime($expireAt) - time() : 0;
+                $day = $expireTime>0? intval($expireTime/(24*3600)) : 0;
+                $hour = $expireTime>0? intval(($expireTime-($day*24*3600))/3600) : 0;
+                $item['expire_text'] = $day? $day.'天'.$hour.'小时' : '已坠海';
+                $item['is_expired'] = 0;
+                if($time >= time() && $time < $dayTime + 86400){
+                    $item['expire_text'] = '今天坠海';
+                    $item['is_expired'] = 1;
+                }else if($time>=$dayTime+86400 && $time < $dayTime + 2 * 86400){
+                    $item['expire_text'] = '明天坠海';
+                    $item['is_expired'] = 1;
+                }else if($time>=$dayTime+7*86400 && $time < $dayTime + 15 * 86400){
+                    $item['expire_text'] = '一礼拜后坠海';
+                }else if($expireTime <= 0 ){
+                    $item['mobile'] = formatStr($item['mobile']);
+                    $item['is_expired'] = 1;
+                    $item['expire_text'] = '已坠海';
+                }
+
+                $intention = isset($item['intention'])? $item['intention'] : 0;
+                $item['intention_text'] = $intention && isset($tags[$intention])? $tags[$intention] : '';
+
+            }
+            unset($item);
+        }
+
+        $total = 0;
+        $tagCounts = [];
+        $counts = PoolModel::getCounts($params,'intention');
+        foreach($tags as $k => $v){
+            $tagCounts[$k] = [
+                'name'=> $v,
+                'num'=> 0,
+            ];
+        }
+        
+        foreach ($counts as $v){
+            $total += $v['count'];
+            $intention = isset($v['intention'])? $v['intention'] : 0;
+            if(isset($tagCounts[$intention])){
+                $tagCounts[$intention]['num'] = $v['count'];
+            }
+        }
+
+        $this->assign('params', $params);
+        $this->assign('tags', $tags);
+        $this->assign('tagCounts', $tagCounts);
+        $this->assign('agencys', $agencys);
+        $this->assign('total', $total);
+        $this->assign('list', $datas['data']);
+        $this->assign('sales', UserModel::getSales());
+        $this->assign('page', $page);
+        return $this->fetch();
+    }
+
+    /**
+     * 我的资源库
+     * @return mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function agency(){
+        $content = hook_one('admin_sales_agency_view');
+
+        if (!empty($content)) {
+            return $content;
+        }
+
+        $params = input();
+        $params['agency'] = isset($params['agency'])? $params['agency'] : 0;
+        $params['sort'] = isset($params['sort'])? $params['sort'] : 0;
+        $params['sort_type'] = isset($params['sort_type'])? $params['sort_type'] : 'desc';
+        $sort = $params['sort']==1? "p.create_time {$params['sort_type']}" : ($params['sort']==2? "p.expire_at {$params['sort_type']}" : "p.last_follow_time {$params['sort_type']}");
+        $list  = PoolModel::alias('p')
+            ->leftJoin('user u','p.user_id=u.id')
+            ->leftJoin('user s','s.id=p.sale_uid')
+            ->leftJoin('user_profile up','up.userid=u.id')
+            ->where('p.expire_at','>=', date('Y-m-d H:i:s', time() - 3* 86400))
+            ->where(['u.user_status'=> 1,'u.user_type'=> 2,'p.sale_uid'=> session('ADMIN_ID'),'p.status'=>1])
+            ->where(function($query) use($params){
+                $uid = isset($params['uid'])? $params['uid'] : 0;
+                if($uid){
+                    $query->where(['u.id'=> $uid]);
+                }
+
+                $agency = isset($params['agency'])? intval($params['agency']) : 0;
+                if($agency){
+                    $query->where('p.agency',$agency);
+                }
+
+                $nickname = isset($params['user_nickname'])? trim($params['user_nickname']) : '';
+                if($nickname){
+                    $query->where('u.user_nickname','like',"{$nickname}%");
+                }
+
+                $realname = isset($params['real_name'])? trim($params['real_name']) : '';
+                if($realname){
+                    $query->where('u.real_name','like',"{$realname}%");
+                }
+
+                $mobile = isset($params['mobile'])? trim($params['mobile']) : '';
+                if($mobile){
+                    $query->where('u.mobile','like',"{$mobile}%");
+                }
+            })
+            ->field('p.id,p.user_id,u.openid,u.user_nickname,u.real_name,u.avatar,u.vip_auth,u.vip_expire,u.user_status,u.mobile,up.graduate,up.age,u.birthday,u.sex,up.married,up.education,up.city,p.id as pool_id,p.intention,p.followup_num,p.agency,p.remark,p.create_time,p.last_follow_time,p.expire_at')
+            ->order($sort)
+            ->paginate(30, false, ['query' => request()->param()]);
+        
+        // 获取分页显示
+        $page = $list->render();
+        $datas = $list ? $list->toArray() : [];
+        $tags = ['无','意向强','有意向','完全不考虑','已到店','已成交','其他'];
+        $agencys = ['无','今天需跟进','明天需跟进','到期未跟进','今天坠海','明天坠海','一礼拜后坠海','其他'];
         if ($datas) {
             $educations = config('weixin.educations');
             $marrieds = config('weixin.marrieds');
@@ -108,11 +423,27 @@ class SalesController extends AdminBaseController
 
                 $item['profile_text'] = $profile? join(' ', $profile) : '';
 
+                $dayTime = strtotime(date('Y-m-d'));
                 $expireAt = isset($item['expire_at'])? $item['expire_at'] : '';
+                $time = strtotime($expireAt);
                 $expireTime = $expireAt? strtotime($expireAt) - time() : 0;
                 $day = $expireTime>0? intval($expireTime/(24*3600)) : 0;
-                $hour = $expireTime>0? intval($expireTime%(24*3600)/3600) : 0;
-                $item['expire_text'] = $day? $day.'天'.$hour.'小时' : '已到期';
+                $hour = $expireTime>0? intval(($expireTime-($day*24*3600))/3600) : 0;
+                $item['expire_text'] = $day? $day.'天'.$hour.'小时' : '已坠海';
+                $item['is_expired'] = 0;
+                if($time >= time() && $time < $dayTime + 86400){
+                    $item['expire_text'] = '今天坠海';
+                    $item['is_expired'] = 1;
+                }else if($time>=$dayTime+86400 && $time < $dayTime + 2 * 86400){
+                    $item['expire_text'] = '明天坠海';
+                    $item['is_expired'] = 1;
+                }else if($time>=$dayTime+7*86400 && $time < $dayTime + 15 * 86400){
+                    $item['expire_text'] = '一礼拜后坠海';
+                }else if($expireTime <= 0 ){
+                    $item['mobile'] = formatStr($item['mobile']);
+                    $item['is_expired'] = 1;
+                    $item['expire_text'] = '已坠海';
+                }
 
                 $intention = isset($item['intention'])? $item['intention'] : 0;
                 $item['intention_text'] = $intention && isset($tags[$intention])? $tags[$intention] : '';
@@ -121,8 +452,28 @@ class SalesController extends AdminBaseController
             unset($item);
         }
 
+        $total = 0;
+        $agencyCounts = [];
+        $counts = PoolModel::getCounts($params,'agency');
+        foreach($agencys as $k => $v){
+            $agencyCounts[$k] = [
+                'name'=> $v,
+                'num'=> 0,
+            ];
+        }
+
+        foreach ($counts as $v){
+            $total += $v['count'];
+            $agency = isset($v['agency'])? $v['agency'] : -1;
+            if($agency>0 && isset($agencyCounts[$agency])){
+                $agencyCounts[$agency]['num'] = $v['count'];
+            }
+        }
+        
         $this->assign('params', $params);
         $this->assign('tags', $tags);
+        $this->assign('agencys', $agencys);
+        $this->assign('agencyCounts', $agencyCounts);
         $this->assign('total', $total);
         $this->assign('list', $datas['data']);
         $this->assign('sales', UserModel::getSales());
@@ -157,4 +508,37 @@ class SalesController extends AdminBaseController
         }
     }
 
+    /**
+     * 设置跟进情况(待办)
+     * @throws \think\Exception
+     * @throws \think\exception\PDOException
+     */
+    public function setAgency(){
+        $poolId = input('pool_id', 0);
+        if(empty($poolId)){
+            $this->error("请选择操作项!", '');
+        }
+
+        if(session('ADMIN_ID')<=0){
+            $this->error("非法操作!", '');
+        }
+
+        $agencyId = input('agencyId', 0);
+        $remark = input('remark','');
+        if($agencyId <= 0){
+            $this->error("请设置跟进情况!", '');
+        }
+
+        $time = date('Y-m-d H:i:s');
+        $where = ['sale_uid'=> session('ADMIN_ID'),'id'=> $poolId,'type'=>0];
+        $info = PoolModel::where($where)->find();
+        $expireAt = isset($info['expired_at'])? $info['expired_at'] : '';
+        $followNum = isset($info['followup_num'])? $info['followup_num'] : 0;
+        if(PoolModel::where($where)->update(['agency'=> $agencyId,'remark'=> $remark,'last_follow_time'=> $time])){
+            PoolModel::where($where)->setInc('followup_num', 1);
+            $this->success('设置跟进情况成功!', '',['num'=> $followNum+1, 'time'=> $time]);
+        }else{
+            $this->error('设置跟进情况失败');
+        }
+    }
 }

+ 68 - 0
vendor/thinkcmf/cmf-app/src/user/model/PoolModel.php

@@ -88,6 +88,9 @@ class PoolModel extends Model
                 'create_time'=> date('Y-m-d H:i:s'),
                 'updated_at'=> date('Y-m-d H:i:s'),
                 'expire_at'=> $poolTime==0? null : $expireAt,
+                'last_follow_time'=> 0,
+                'stop_time'=> 0,
+                'remark'=> '',
                 'status'=> 1,
             ];
 
@@ -109,6 +112,52 @@ class PoolModel extends Model
     }
 
     /**
+     * 分组统计数据
+     * @param $params
+     * @return array|\PDOStatement|string|\think\Collection|\think\model\Collection
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public static function getCounts($params, $key='intention'){
+        $counts = PoolModel::alias('p')
+            ->leftJoin('user u','p.user_id=u.id')
+            ->leftJoin('user s','s.id=p.sale_uid')
+            ->leftJoin('user_profile up','up.userid=u.id')
+            ->where('p.expire_at','>=', date('Y-m-d H:i:s', time() - 3* 86400))
+            ->where(['u.user_status'=> 1,'u.user_type'=> 2,'p.sale_uid'=> session('ADMIN_ID'),'p.status'=>1])
+            ->where(function($query) use($params){
+                $uid = isset($params['uid'])? $params['uid'] : 0;
+                if($uid){
+                    $query->where(['u.id'=> $uid]);
+                }
+
+                $nickname = isset($params['user_nickname'])? trim($params['user_nickname']) : '';
+                if($nickname){
+                    $query->where('u.user_nickname','like',"{$nickname}%");
+                }
+
+                $realname = isset($params['real_name'])? trim($params['real_name']) : '';
+                if($realname){
+                    $query->where('u.real_name','like',"{$realname}%");
+                }
+
+                $mobile = isset($params['mobile'])? trim($params['mobile']) : '';
+                if($mobile){
+                    $query->where('u.mobile','like',"{$mobile}%");
+                }
+            })
+            ->group('p.'.$key)
+            ->field('COUNT(p.id) as count,p.intention,p.agency,p.id')
+            ->select();
+
+        $datas = [];
+        $counts = $counts? $counts->toArray() : [];
+        //var_dump($counts);
+        return $counts;
+    }
+
+    /**
      * 批量移动用户资源到售前公海
      * @param $saleUid 销售用户ID
      * @param $userId 资源用户ID
@@ -204,4 +253,23 @@ class PoolModel extends Model
 
         return $info;
     }
+
+    /**
+     * 是否存在记录
+     * @param $userId
+     * @return PoolModel|bool|mixed
+     */
+    public static function checkData($userId){
+        $cacheKey = "caches:pools:sale—_2_{$userId}";
+        $info = PRedis::get($cacheKey);
+        if($info){
+            return $info;
+        }
+
+        if($info = PoolModel::where(['sale_uid'=>0,'user_id'=> $userId])->order('updated_at desc')->find()){
+            PRedis::set($cacheKey, $info, rand(300, 600));
+        }
+
+        return $info;
+    }
 }