Explorar o código

Merge branch 'master' into dev

gorden hai 1 semana
pai
achega
cb45251d42

+ 12 - 0
app/admin/controller/consultant/CustomController.php

@@ -212,4 +212,16 @@ class CustomController extends Curd
     {
         return CustomService::statisticsMonth();
     }
+
+    /**
+     * Notes: 导入客户
+     * User: yb
+     * Date: 2024/9/10
+     * Time: 10:29
+     */
+    public function importCustom(Request $request)
+    {
+        $params = $request->post();
+        return CustomService::import($params);
+    }
 }

+ 43 - 15
app/admin/controller/member/AccountController.php

@@ -17,7 +17,7 @@ class AccountController extends Curd
 
     public function my($id)
     {
-        $account = MemberAccount::where('join_account_member_id', $id)->where('member_account_status','ACTIVED')->get()->toArray();
+        $account = MemberAccount::where('join_account_member_id', $id)->get()->toArray();
         if (!$account) {
             // 账户表
             $accountData = [
@@ -39,13 +39,13 @@ class AccountController extends Curd
 
             $account = MemberAccount::where('join_account_member_id', $id)->get()->toArray();
         }
-        if ($account[0]['member_account_classify'] == 'POINTS'){
+        if ($account[0]['member_account_classify'] == 'POINTS') {
             $account = array_reverse($account);
         }
 
-        foreach ($account as &$item){
-            $item['member_account_duedate'] = !empty($item['member_account_duedate']) ? date('Y-m-d H:i:s',$item['member_account_duedate']) : '长期有效';
-            $item['member_account_surplus'] = round($item['member_account_surplus'] + $item['member_account_added'],2);
+        foreach ($account as &$item) {
+            $item['member_account_duedate'] = !empty($item['member_account_duedate']) ? date('Y-m-d H:i:s', $item['member_account_duedate']) : '长期有效';
+            $item['member_account_surplus'] = round($item['member_account_surplus'] + $item['member_account_added'], 2);
         }
 
         return json_success('', $account);
@@ -81,30 +81,58 @@ class AccountController extends Curd
     /**
      * 用户的账户
      */
-    public function selectMemberAccount(Request $request) 
+    public function selectMemberAccount(Request $request)
     {
-        $memberId = $request->get('member_id','');
-        if (!$memberId){
+        $memberId = $request->get('member_id', '');
+        if (!$memberId) {
             return json_fail('参数异常');
         }
-        
+
         $account = MemberAccount::where('join_account_member_id', $memberId)->get()->toArray();
 
         $data = [];
-        foreach ($account as $item){
-            $item['member_account_duedate'] = !empty($item['member_account_duedate']) ? date('Y-m-d H:i:s',$item['member_account_duedate']) : '长期有效';
+        foreach ($account as $item) {
+            $item['member_account_duedate'] = !empty($item['member_account_duedate']) ? date('Y-m-d H:i:s', $item['member_account_duedate']) : '长期有效';
 
-            if ($item['member_account_classify'] == 'POINTS'){
+            if ($item['member_account_classify'] == 'POINTS') {
                 $data['points'] = $item;
-            }elseif ($item['member_account_classify'] == 'CASH'){
+            } elseif ($item['member_account_classify'] == 'CASH') {
                 $data['cash'] = $item;
-            }elseif ($item['member_account_classify'] == 'CARD'){
+            } elseif ($item['member_account_classify'] == 'CARD') {
                 $data['card'][] = $item;
-            }elseif ($item['member_account_classify'] == 'WELFARE'){
+            } elseif ($item['member_account_classify'] == 'WELFARE') {
                 $data['welfare'] = $item;
             }
         }
 
         return json_success('', $data);
     }
+
+    /**
+     * @Desc 修改账户状态
+     * @Author Gorden
+     * @Date 2024/9/12 16:28
+     *
+     * @param Request $request
+     * @return \support\Response
+     */
+    public function updateStatus(Request $request)
+    {
+        $accountId = $request->post('account_id');
+        $status = $request->post('status');
+        if (!$accountId || !$status || !in_array($status,['DISABLED','ACTIVED','EXPIRED'])){
+            return json_fail('参数异常');
+        }
+        try {
+            $account = MemberAccount::where('member_account_id',$accountId)->first();
+            $account->member_account_status = $status;
+            $account->save();
+
+            _syslog("修改账户状态",'修改账户状态成功');
+            return json_success('账户状态修改成功');
+        }catch (\Exception $e){
+            _syslog("修改账户状态",'账户状态修改失败');
+            return json_fail('账户状态修改失败');
+        }
+    }
 }

+ 25 - 6
app/admin/controller/order/PayDetailController.php

@@ -53,11 +53,11 @@ class PayDetailController extends Curd
         //     $where['pay_category'] = 'RECHARGE';
         //     $where['pay_prepayid'] = ['in','WXPAY,ALIPAY'];
         // }
-        $query = $this->doSelect($where, $field, $order);
+        $query = $this->doSelect($where, $field, $order,$request->get());
         return $this->doFormat($query, $format, $limit);
     }
 
-    protected function doSelect(array $where, string $field = null, string $order = 'desc')
+    protected function doSelect(array $where, string $field = null, string $order = 'desc',$params=[])
     {
         $model = $this->model->with(['member', 'cert', 'memberAccount']);
         foreach ($where as $column => $value) {
@@ -89,10 +89,25 @@ class PayDetailController extends Curd
                 $model = $model->where($column, $value);
             }
         }
-        $model = $model->where(function ($query) {
-            $query->whereIn('pay_prepayid', ['ALIPAY', 'WXPAY','OFFLINE_WXPAY','OFFLINE_ALIPAY','MONEY'])
-                ->orWhere('pay_prepayid', 'like', '%CASH%');
-        });
+        if (empty($params['type'])){
+            $model = $model->where(function ($query) {
+                $query->whereIn('pay_prepayid', ['ALIPAY', 'WXPAY','OFFLINE_WXPAY','OFFLINE_ALIPAY','MONEY'])
+                    ->orWhere('pay_prepayid', 'like', '%CASH%')
+                    ->orWhere('pay_prepayid', 'like', '%WELFARE%');
+            });
+        }else{
+            if ($params['type'] == 'NORMAL'){
+                $model = $model->where(function ($query) {
+                    $query->whereIn('pay_prepayid', ['ALIPAY', 'WXPAY','OFFLINE_WXPAY','OFFLINE_ALIPAY','MONEY'])
+                        ->orWhere('pay_prepayid', 'like', '%CASH%');
+                });
+            }else{
+                $model = $model->where(function ($query) {
+                    $query->orWhere('pay_prepayid', 'like', '%WELFARE%');
+                });
+            }
+        }
+
 
         if ($field) {
             $model = $model->orderBy($field, $order);
@@ -168,6 +183,10 @@ class PayDetailController extends Curd
             if (count($prepayId) > 1) {
                 $item->pay_prepayid = $prepayId[1];
             }
+            $item->type = 'NORMAL';
+            if (isset($prepayId[1]) && $prepayId[1] == 'WELFARE'){
+                $item->type = 'WELFARE';
+            }
             $memberAccount = [];
             if (!empty($item->memberAccount)) {
                 foreach ($item->memberAccount as $account) {

+ 1 - 1
app/admin/service/consultant/ConsultantService.php

@@ -53,7 +53,7 @@ class ConsultantService
         $paginator = Consultant::where(function ($query) use ($whereDept, $whereTopDept) {
                 $query->orWhere($whereDept)
                 ->orWhere($whereTopDept);
-        })->where($where)->paginate($limit, '*', 'page', $page);
+        })->where($where)->orderBy('id', 'DESC')->paginate($limit, '*', 'page', $page);
         $total = $paginator->total();
         $items = $paginator->items();
         if (!empty($items)) {

+ 307 - 47
app/admin/service/consultant/CustomService.php

@@ -4,13 +4,14 @@
 namespace app\admin\service\consultant;
 
 
-use app\admin\service\member\MemberService;
 use app\model\Consultant;
 use app\model\MarketCustomer;
 use app\model\MarketCustomerFollow;
 use app\model\MarketCustomerLogs;
-use app\model\Member;
 use app\model\SysDept;
+use PhpOffice\PhpSpreadsheet\Reader\Csv;
+use PhpOffice\PhpSpreadsheet\Reader\Xls;
+use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
 use support\Db;
 use support\exception\BusinessException;
 use support\Request;
@@ -18,7 +19,7 @@ use Tinywan\Jwt\JwtToken;
 
 class CustomService
 {
-    const DIFF_TIME = (60 * 60 * 24 * 30);
+    const DIFF_TIME = (60 * 60 * 24 * 30); //调入团队公池 x4 = 调入集团公池
     /**
      * Notes: 返回选项配置信息
      * User: yb
@@ -37,6 +38,7 @@ class CustomService
         $currentTime = time();
         $diffNums = self::DIFF_TIME;
         $deptIds = TeamService::getIdsByUser();
+        $belongStatus = $params['belong_status'] ?? 1;
         if (false === $deptIds) {
             //无权限
             $where[] = ['dept_id', '=', 0];
@@ -49,6 +51,13 @@ class CustomService
             $where[] = [function($query) use ($deptIds) {
                 $query->whereIn('dept_id', $deptIds);
             }];
+            $where[] = [function($query) use ($diffNums, $currentTime){
+                $query->orWhereRaw("check_status IN (-1, 1)")
+                    ->orWhereRaw("check_status = 2 AND current_status IN (-1,3,4)")
+                    ->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} > 0 AND current_status = 2 AND check_status = 2)")
+                    ->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} <= 0 AND (visit_time + ({$diffNums} * 4)) - {$currentTime} > 0 AND current_status = 2 AND check_status = 2 AND belong_status = 1)")->whereOr('belong_status','<>', 1);
+            }];
+
         } else {
             if (!empty($params['dept_id'])) {
                 $deptId = end($params['dept_id']);
@@ -71,35 +80,20 @@ class CustomService
                 $query->where('mobile', 'like', "%{$mobile}%");
             }];
         }
-        if (!empty($params['report_status'])) {
-            $where[] = ['check_status', '=', $params['report_status']];
-//            if ($params['report_status'] == -1) {
-//                //待审核
-//                $where[] = ['check_status', '=', 1];
-//            } else {
-//                $where[] = ['check_status', '=', 2];
-//            }
-//            if ($params['report_status'] == 1) {
-//                //已报备
-//                $where[] = [function($query) use ($diffNums, $currentTime) {
-//                    $query->whereRaw("((visit_time + {$diffNums}) - {$currentTime} > 0)")->where('current_status', '=', 1);
-//                }];
-//            } else if ($params['report_status'] == 3) {
-//                //已锁定
-//                $where[] = [function($query) {
-//                    $query->whereIn('current_status', [2,3,4]);
-//                }];
-//            } else if ($params['report_status'] == 2) {
-//                //已失效
-//                $where[] = [function($query) use ($diffNums, $currentTime){
-//                    $query->orWhere('current_status', '=', -1)->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} <= 0 AND current_status = 1 AND check_status = 2)");
-//                }];
-//            }
-        }
         if (!empty($params['consultant_name'])) {
-            $consultantIds = Consultant::where('name', 'like', "%{$params['consultant_name']}%")->pluck('id');
+            $consultantIds = Consultant::where('name', 'like', "%{$params['consultant_name']}%")
+                ->where('mobile', 'like', "%{$params['consultant_name']}%")
+                ->pluck('id')->toArray();
+            $where[] = [function($query) use ($consultantIds) {
+                $query->whereIn('consultant_id', $consultantIds);
+            }];
+        }
+        if (!empty($params['report_name'])) {
+            $consultantIds = Consultant::where('name', 'like', "%{$params['report_name']}%")
+                ->where('mobile', 'like', "%{$params['report_name']}%")
+                ->pluck('id')->toArray();
             $where[] = [function($query) use ($consultantIds) {
-                $query->orWhereIn('consultant_id', $consultantIds)->orWhereIn('report_consultant_id', $consultantIds);
+                $query->whereIn('report_consultant_id', $consultantIds);
             }];
         }
         if (!empty($params['type'])) {
@@ -132,11 +126,17 @@ class CustomService
 
         if (!empty($params['current_status'])) {
             $currentStatus = $params['current_status'];
-            if ($currentStatus == 1) {
-                $where[] = ['current_status', '=', $currentStatus];
+            if ($currentStatus == -2) {
+                //检索公池状态
+                $where[] = [function($query) use ($diffNums, $currentTime){
+                    $query->whereRaw("((visit_time + {$diffNums}) - {$currentTime} <= 0 AND (visit_time + ({$diffNums} * 4)) - {$currentTime} > 0 AND current_status = 2 AND check_status = 2 AND belong_status = 1)");
+                }];
             } else {
-                $where[] = [function($query) use ($currentStatus){
-                    $query->where('current_status', '=', $currentStatus)->where('check_status', '<>', 1);
+                $where[] = ['current_status', '=', $currentStatus];
+                $where[] = [function($query) use ($diffNums, $currentTime){
+                    $query->orWhereRaw("check_status IN (-1, 1)")
+                        ->orWhereRaw("check_status = 2 AND current_status IN (-1,3,4)")
+                        ->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} > 0 AND current_status = 2 AND check_status = 2)");
                 }];
             }
         }
@@ -222,10 +222,35 @@ class CustomService
                         ->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} > 0 AND current_status = 2 AND check_status = 2)");
                 }];
             } else {
-                //已经流入公池
-                $where[] = [function($query) use ($diffNums, $currentTime){
-                    $query->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} <= 0 AND current_status = 2 AND check_status = 2 AND belong_status = 1)")->whereOr('belong_status','<>', 1);
-                }];
+                if (true === $deptIds) {
+                    if (!empty($params['pub_status'])) {
+                        if ($params['pub_status'] == 2) {
+                            //仅检索团队公池
+                            $where[] = [function($query) use ($diffNums, $currentTime){
+                                $query->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} <= 0 AND (visit_time + ({$diffNums} * 4)) - {$currentTime} > 0 AND current_status = 2 AND check_status = 2 AND belong_status = 1)")->whereOr('belong_status','<>', 1);
+                            }];
+                        } else {
+                            //仅检索集团公池
+                            $where[] = [function($query) use ($diffNums, $currentTime){
+                                $query->orWhereRaw("((visit_time + ({$diffNums} * 4)) - {$currentTime} <= 0 AND current_status = 2 AND check_status = 2 AND belong_status = 1)")->whereOr('belong_status','<>', 1);
+                            }];
+                        }
+                    } else {
+                        //超管权限
+                        $where[] = [function($query) use ($diffNums, $currentTime){
+                            $query->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} <= 0 AND current_status = 2 AND check_status = 2 AND belong_status = 1)")->whereOr('belong_status','<>', 1);
+                        }];
+                    }
+
+                } else if (is_array($deptIds)) {
+                    //团队权限
+                    $where[] = [function($query) use ($diffNums, $currentTime){
+                        $query->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} <= 0 AND (visit_time + ({$diffNums} * 4)) - {$currentTime} > 0 AND current_status = 2 AND check_status = 2 AND belong_status = 1)")->whereOr('belong_status','<>', 1);
+                    }];
+                } else {
+                    //无权限
+                }
+
             }
         }
 
@@ -289,6 +314,15 @@ class CustomService
                 $visitTime = $item->visit_time;
                 $visitTimeStamp = strtotime($visitTime);
                 $diff = ($visitTimeStamp + $diffNums) - $currentTime;
+                if ($diff > 0) {
+                    $item->belong_status = 1;
+                } else {
+                    if (abs($diff) - (4*$diffNums) > 0) {
+                        $item->belong_status = 3;
+                    } else {
+                        $item->belong_status = 2;
+                    }
+                }
                 $item->diff_nums =  ($diff > 0) ? $diff : 0;
                 $item->consultant_name = $consultantKeys[$item->consultant_id]['name'] ?? '';
                 $item->consultant_mobile = $consultantKeys[$item->consultant_id]['mobile'] ?? '';
@@ -455,13 +489,20 @@ class CustomService
         if (!is_array($ids)) {
             $ids = [$ids];
         }
+        Db::beginTransaction();
         try {
             if (is_array($ids)) {
                 MarketCustomer::whereIn('id', $ids)->delete();
+                MarketCustomerFollow::whereIn('market_customer_id', $ids)->delete();//删除跟进记录
+                MarketCustomerLogs::whereIn('market_customer_id', $ids)->delete();//删除移交记录
             } else {
                 MarketCustomer::where('id', $ids)->delete();
+                MarketCustomerFollow::where('market_customer_id', $ids)->delete();//删除跟进记录
+                MarketCustomerLogs::where('market_customer_id', $ids)->delete();//删除移交记录
             }
+            Db::commit();
         } catch (\Exception $e) {
+            Db::rollBack();
             return json_fail('删除失败');
         }
 
@@ -606,7 +647,7 @@ class CustomService
                 $query->whereIn('consultant_id', $consultantIds);
             }];
         }
-        $customList = MarketCustomer::where($whereCustom)->select(['id','consultant_id','dept_id'])->get();
+        $customList = MarketCustomer::where($whereCustom)->select(['id','consultant_id','dept_id','visit_time','check_status','current_status'])->get();
         if (!$customList->isEmpty()) {
             foreach ($customList as$item) {
                 $logsInertData[] = [
@@ -627,13 +668,21 @@ class CustomService
         if (empty($logsInertData)) {
             return json_fail('移交记录不能为空');
         }
+        $diffTime = self::DIFF_TIME;
         Db::beginTransaction();
         $result = false;
         try {
             foreach ($customList as $item) {
                 if ($currentConsultantId != 0) {
                     //移交至指定顾问
-                    $item->visit_time = time();
+                    //判断一下是否到了到访的过期时间,如果过期了就更新到访时间,没过期时间就不变
+                    if ($item->check_status == 2 && $item->current_status == 2) {
+                        $visitTime = $item->visit_time;
+                        $diff = strtotime($visitTime) + $diffTime - time();
+                        if ($diff <= 0) {
+                            $item->visit_time = time();
+                        }
+                    }
                 } else {
                     //移交至其他团队
                     $item->visit_time = time() - self::DIFF_TIME;
@@ -1064,13 +1113,6 @@ class CustomService
         return substr_replace($val, '****', 3, 4);
     }
 
-    /**
-     * Notes: 判客指定顾问
-     * User: yb
-     * Date: 2024/9/5
-     * Time: 15:50
-     * @param $params
-     */
     /**
      * Notes: 指定顾问
      * User: yb
@@ -1131,4 +1173,222 @@ class CustomService
 
 
     }
+
+    /**
+     * Notes: 导入客户
+     * User: yb
+     * Date: 2024/9/10
+     * Time: 10:30
+     * @param $params
+     */
+    public static function import($params)
+    {
+        if (empty($params['path'])) {
+            return json_fail('文件地址不能为空');
+        }
+        $path = 'public'.$params['path'];
+        if (is_file($path)) {
+            $teamKeys = [];
+            //查询顾问信息
+            $teamData = Db::table('consultant')
+                ->leftJoin('sys_dept', 'consultant.dept_id', '=', 'sys_dept.dept_id')
+                ->select(['consultant.id', 'consultant.name', 'sys_dept.dept_name', 'sys_dept.dept_id'])
+                ->whereNull('consultant.deleted_at')
+                ->get();
+            if (!($teamData->isEmpty())) {
+                foreach ($teamData as $item) {
+                    $key = $item->name.'-'.$item->dept_name;
+                    $teamKeys[$key] = [
+                        'consultant_id' => $item->id,
+                        'dept_id' => $item->dept_id,
+                        'name' => $item->name,
+                        'dept_name' => $item->dept_name
+                    ];
+                }
+            }
+            $data = self::readExcel($path);
+//            $fields = ['到访时间', '客户姓名', '客户手机号', 'A类', 'B类', 'C类', 'D类', '健康顾问', '报备人', '团队'];
+            if (empty($data)) {
+                return json_fail('无可导入内容');
+            } else {
+                $sucNums = 0;
+                $errNums = 0;
+                $validate = '/^1\d{10}$/';
+                $errorData = [];
+                Db::beginTransaction();
+                try {
+                    foreach ($data as $key => $val) {
+                        if ($val[3] == 1) {$level = 1;} else if ($val[4] == 1) {$level = 2;} else if ($val[5] == 1) {$level = 3;} else if ($val[6] == 1) {$level = 4;}
+                        $line = '姓名:'.$val[1].' 第'.($key + 2).'行:';
+                        $mobile = $val[2] ?? '';
+                        $mobile = trim($mobile);
+                        $error = [];
+                        $msg = '';
+                        if (empty($val[7]) && empty($val[8])) {
+                            $msg = $line.'报备人和顾问必须存在其中之一';
+                            $val[10] = '报备人和顾问必须存在其中之一';
+//                            throw new \Exception($line.'报备人和顾问必须存在其中之一');
+                        }
+                        if (empty($val[9])) {
+                            $msg = $line.'无团队信息';
+                            $val[10] = '无团队信息';
+//                            throw new \Exception($line.'无团队信息');
+                        }
+                        if ($val[0] == '1970-01-01 08:00:00') {
+                            $msg = $line.'日期格式错误';
+                            $val[10] = '日期格式错误';
+//                            throw new \Exception($line.'日期格式错误');
+                        }
+                        if (empty($mobile)) {
+                            $msg = $line.'手机号不能为空';
+                            $val[10] = '手机号不能为空';
+//                            throw new \Exception($line.'手机号不能为空');
+                        }
+                        if (!preg_match($validate, $mobile)) {
+                            $msg = $line.'手机号格式非法';
+                            $val[10] = '手机号格式非法';
+//                            throw new \Exception($line.'手机号格式非法');
+                        }
+                        $consultantName = $val[7];
+                        $reportName = $val[8];
+                        $teamName = $val[9];
+                        $consultantKey = $consultantName.'-'.$teamName;
+                        $consultantId = $teamKeys[$consultantKey]['consultant_id'] ?? 0;
+                        $reportKey = $reportName.'-'.$teamName;
+                        $reportConsultantId = $teamKeys[$reportKey]['consultant_id'] ?? 0;
+                        if ($consultantId <= 0 && $reportConsultantId <= 0) {
+                            $msg = $line.'健康顾问或报备人都不存在';
+                            $val[10] = '健康顾问或报备人都不存在';
+//                            throw new \Exception($line.'健康顾问或报备人都不存在');
+                        }
+                        if ($consultantId > 0) {
+                            $deptId = $teamKeys[$consultantKey]['dept_id'] ?? 0;
+                        }
+                        if ($reportConsultantId > 0) {
+                            $deptId = $teamKeys[$reportKey]['dept_id'] ?? 0;
+                        } else {
+                            if ($consultantId > 0) {
+                                $reportConsultantId = $consultantId;
+                            }
+                        }
+                        if (empty($deptId)) {
+                            $msg =  $line.'健康顾问或报备人都不存在';
+                            $val[10] = '健康顾问或报备人都不存在';
+//                            throw new \Exception($line.'团队不存在');
+                        }
+                        if (MarketCustomer::checkCustomExists($val[2])) {
+                            $msg =  $line.'客户已转到访,无法二次录入';
+                            $val[10] = '客户已转到访,无法二次录入';
+//                            throw new \Exception($line.'客户已转到访,无法二次录入');
+                        }
+
+                        $result = false;
+                        if (empty($msg)) {
+                            //查看手机号是否存在
+                            $insertData = [
+                                'name' => $val[1],
+                                'mobile' => $mobile,
+                                'level' => $level ?? null,
+                                'consultant_id' => $consultantId,
+                                'report_consultant_id' => $reportConsultantId,
+                                'create_consultant_id' => $reportConsultantId,
+                                'dept_id' => $deptId ?? 0,
+                                'belong_status' => 1,
+                                'current_status' => 2,
+                                'check_status' => 2,
+                                'check_note' => '导入的客户信息,无审核人员',
+                                'type' => 1,
+                                'visit_time' => strtotime($val[0]),
+                                'created_at' => strtotime($val[0])
+                            ];
+                            $result = Db::table('market_customer')->insert($insertData);
+                        } else {
+                            $val[11] = $line;
+                            $errorData[] = $val;
+                        }
+                        if ($result) {
+                            $sucNums++;
+                        } else {
+                            $errNums++;
+                        }
+                    }
+                    Db::commit();
+                }catch (\Exception $e) {
+                    Db::rollBack();
+                    return json_fail($e->getMessage());
+                }
+
+            }
+        } else {
+            return json_fail('文件不存在');
+        }
+        $total = count($data);
+        return json_success("全部数据:{$total},成功:{$sucNums},失败:{$errNums}", ['data' => $errorData]);
+    }
+
+    /**
+     * Notes: 读取excel文件
+     * User: yb
+     * Date: 2024/9/10
+     * Time: 10:41
+     * @param $filePath
+     */
+    public static function readExcel($filePath)
+    {
+        set_time_limit(0);
+        ini_set('memory_limit', '1024M');
+        $ext = pathinfo($filePath, PATHINFO_EXTENSION);
+        if (!in_array($ext, ['csv', 'xls', 'xlsx'])) {
+            return json_fail('未知的导入文件类型');
+        }
+        if ($ext === 'csv') {
+            $file = fopen($filePath, 'r');
+            $filePath = tempnam(sys_get_temp_dir(), 'import_csv');
+            $fp = fopen($filePath, "w");
+            $n = 0;
+            while ($line = fgets($file)) {
+                $line = rtrim($line, "\n\r\0");
+                $encoding = mb_detect_encoding($line, ['utf-8', 'gbk', 'latin1', 'big5']);
+                if ($encoding != 'utf-8') {
+                    $line = mb_convert_encoding($line, 'utf-8', $encoding);
+                }
+                if ($n == 0 || preg_match('/^".*"$/', $line)) {
+                    fwrite($fp, $line . "\n");
+                } else {
+                    fwrite($fp, '"' . str_replace(['"', ','], ['""', '","'], $line) . "\"\n");
+                }
+                $n++;
+            }
+            fclose($file) || fclose($fp);
+            $reader = new Csv();
+        } else if ($ext === 'xls') {
+            $reader = new Xls();
+        } else {
+            $reader = new Xlsx();
+        }
+        try {
+            if (!$PHPExcel = $reader->load($filePath)) {
+                return json_fail('未知的导入文件类型');
+            }
+            $currentSheet = $PHPExcel->getSheet(0);  //读取文件中的第一个工作表
+            $allColumn = $currentSheet->getHighestDataColumn(); //取得最大的列号
+            $allRow = $currentSheet->getHighestRow(); //取得一共有多少行
+            $maxColumnNumber = 10;
+            $insertData = [];
+            for ($currentRow = 2; $currentRow <= $allRow; $currentRow++) {
+                $values = [];
+                for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) {
+                    $val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getFormattedValue();
+                    if ($currentColumn == 1) {
+                       $val = date('Y-m-d H:i:s', strtotime($val)); //时间
+                    }
+                    $values[] = is_null($val) ? '' : $val;
+                }
+                $insertData[] = $values;
+            }
+        }catch (\Exception $e) {
+            return json_fail($e->getMessage());
+        }
+        return $insertData;
+    }
 }

+ 12 - 12
app/admin/service/member/MemberService.php

@@ -1015,18 +1015,18 @@ class MemberService
                 MemberInfo::where('join_info_member_id', $params['member_id'])->update($infoData);
             }
             // 福利账户
-//            if (!empty($params['member_classify']) && $params['member_classify'] == 'EMPLOY' && !MemberAccount::where('member_account_nbr',$memberId.'-WELFARE')->exists()){
-//                $welfareData = [
-//                    'join_account_member_id'=>$memberId,
-//                    'member_account_classify'=>'WELFARE',
-//                    'member_account_status'=>'ACTIVED',
-//                    'member_account_category'=>'NORMAL',
-//                    'member_account_nbr'=>$memberId.'-WELFARE',
-//                    'member_account_name'=>'福利账户',
-//                    'member_account_addtimes'=>time()
-//                ];
-//                MemberAccount::insert($welfareData);
-//            }
+            if (!empty($params['member_classify']) && $params['member_classify'] == 'EMPLOY' && !MemberAccount::where('member_account_nbr',$memberId.'-WELFARE')->exists()){
+                $welfareData = [
+                    'join_account_member_id'=>$memberId,
+                    'member_account_classify'=>'WELFARE',
+                    'member_account_status'=>'ACTIVED',
+                    'member_account_category'=>'NORMAL',
+                    'member_account_nbr'=>$memberId.'-WELFARE',
+                    'member_account_name'=>'福利账户',
+                    'member_account_addtimes'=>time()
+                ];
+                MemberAccount::insert($welfareData);
+            }
 
             Db::commit();
         } catch (\Exception $e) {

+ 1 - 1
app/admin/service/sys_manage/RoleService.php

@@ -33,7 +33,7 @@ class RoleService
                 $query->where('role_status', $roleStatus);
             })
             ->orderBy('role_addtimes', 'DESC')
-            ->forPage($page, $pageSize)
+//            ->forPage($page, $pageSize)
             ->get()
             ->toArray();
         $total = SysRole::when($keyword != '', function ($query) use ($keyword) {

+ 18 - 13
app/common/storage/LocalAdapter.php

@@ -32,14 +32,18 @@ class LocalAdapter extends AdapterAbstract
         }
 
         $baseUrl = $this->config['domain'] . $this->config['uri'] . str_replace(DIRECTORY_SEPARATOR, '/', $this->config['dirname']) . DIRECTORY_SEPARATOR;
+        $imageType = ['jpeg', 'jpg', 'png', 'gif'];
         foreach ($this->files as $key => $file) {
-            // 缩略
-            $image = Image::make($file);
-
+            //读取文件后缀
+            $extension = strtolower($file->getUploadExtension());
+            if (in_array($extension, $imageType)) {
+                // 缩略
+                $image = Image::make($file);
+            }
             $uniqueId = hash_file($this->algo, $file->getPathname());
             $saveFilename = $uniqueId . '.' . $file->getUploadExtension();
             $originSavePath = $basePath . $saveFilename;
-            $thumbSavePath = $basePath . 'thumb' . DIRECTORY_SEPARATOR . $saveFilename;
+            $thumbSavePath = in_array($extension, $imageType) ? ($basePath . 'thumb' . DIRECTORY_SEPARATOR . $saveFilename) : ($basePath . DIRECTORY_SEPARATOR . $saveFilename);
             $temp = [
                 'key' => $key,
                 'origin_name' => $file->getUploadName(),
@@ -53,15 +57,16 @@ class LocalAdapter extends AdapterAbstract
             ];
             // 保存原图
             $file->move($originSavePath);
-            // 保存缩略图
-            $imgWidth = $image->width();
-            $imgHeight = $image->height();
-            $rate = round($imgWidth / 200, 2);
-            $height = intval($imgHeight / $rate);
-            $image = $image->resize(200, $height);
-            $encoded = $image->encode('jpg');
-            $encoded->save($thumbSavePath);
-
+            if (in_array($extension, $imageType)) {
+                // 保存缩略图
+                $imgWidth = $image->width();
+                $imgHeight = $image->height();
+                $rate = round($imgWidth / 200, 2);
+                $height = intval($imgHeight / $rate);
+                $image = $image->resize(200, $height);
+                $encoded = $image->encode('jpg');
+                $encoded->save($thumbSavePath);
+            }
 //            $file->move($savePath);
             array_push($result, $temp);
         }

+ 55 - 13
app/wechat/service/CustomService.php

@@ -58,14 +58,20 @@ class CustomService
         $type = $consultantInfo->type;
         $currentTime = time();
         $diffNums = self::DIFF_TIME;
-        $where = [
-            [function($query) use ($diffNums, $currentTime){
-            $query->orWhereRaw("check_status IN (-1, 1)")
-                ->orWhereRaw("check_status = 2 AND current_status IN (-1,3,4)")
-                ->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} > 0 AND current_status = 2 AND check_status = 2)");
-        }]
-        ];
+        $where = [];
         $whereFollow = [];
+        if (!empty($params['belong_status'])) {
+            //团队权限
+            $where[] = [function($query) use ($diffNums, $currentTime){
+                $query->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} <= 0 AND (visit_time + ({$diffNums} * 4)) - {$currentTime} > 0 AND current_status = 2 AND check_status = 2 AND belong_status = 1)")->whereOr('belong_status','<>', 1);
+            }];
+        } else {
+            $where[] = [function($query) use ($diffNums, $currentTime){
+                $query->orWhereRaw("check_status IN (-1, 1)")
+                    ->orWhereRaw("check_status = 2 AND current_status IN (-1,3,4)")
+                    ->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} > 0 AND current_status = 2 AND check_status = 2)");
+            }];
+        }
         if ($type == 1) {
             //团队下所有的
             $deptIds = TeamService::getIds($deptId);
@@ -95,11 +101,39 @@ class CustomService
             //所有团队的
 
         }
-        if (!empty($params['custom'])) {
-            $keywords = $params['custom'];
-            $where[] = [function($query) use ($keywords) {
-                $query->orWhere('name', 'like', "%{$keywords}%")->orWhere('mobile', 'like', "%{$keywords}%");
-            }];
+        if (!empty($params['search_type'])) {
+            $searchType = $params['search_type'];
+            // 1 = 仅搜索客户
+            if ($searchType == 1) {
+                if (!empty($params['custom'])) {
+                    $keywords = $params['custom'];
+                    $where[] = [function($query) use ($keywords) {
+                        $query->orWhere('name', 'like', "%{$keywords}%")->orWhere('mobile', 'like', "%{$keywords}%");
+                    }];
+                }
+            } else {
+                if (!empty($params['custom'])) {
+                    $keywords = $params['custom'];
+                    $consultantIds = Consultant::orWhere('name', 'like', "%{$keywords}%")->orWhere('mobile', 'like', "%{$keywords}%")->pluck('id')->toArray();
+                    if ($searchType == 2) {
+                        $searchKey = 'consultant_id';
+                    } else {
+                        $searchKey = 'report_consultant_id';
+                    }
+                    $where[] = [function($query) use ($consultantIds, $searchKey) {
+                        $query->orWhereIn($searchKey, $consultantIds);
+                    }];
+                }
+            }
+        } else {
+            if (!empty($params['custom'])) {
+                $keywords = $params['custom'];
+                $consultantIds = Consultant::orWhere('name', 'like', "%{$keywords}%")->orWhere('mobile', 'like', "%{$keywords}%")->pluck('id')->toArray();
+                $where[] = [function($query) use ($keywords, $consultantIds) {
+                    $query->orWhere('name', 'like', "%{$keywords}%")->orWhere('mobile', 'like', "%{$keywords}%")
+                        ->orWhereIn('consultant_id', $consultantIds)->orWhereIn('report_consultant_id', $consultantIds);
+                }];
+            }
         }
         if (!empty($params['report_status'])) {
             if ($params['report_status'] == 1) {
@@ -587,7 +621,7 @@ class CustomService
         if (!empty($consultantId)) {
             $whereCustom[] = ['consultant_id', '=', $consultantId];
         }
-        $customList = MarketCustomer::where($whereCustom)->select(['id','consultant_id','dept_id'])->get();
+        $customList = MarketCustomer::where($whereCustom)->select(['id','consultant_id','dept_id','visit_time','check_status','current_status'])->get();
         if (!$customList->isEmpty()) {
             foreach ($customList as$item) {
                 $logsInertData[] = [
@@ -609,10 +643,18 @@ class CustomService
         if (empty($logsInertData)) {
             return json_fail('移交记录不能为空');
         }
+        $diffTime = self::DIFF_TIME;
         Db::beginTransaction();
         $result = false;
         try {
             foreach ($customList as $item) {
+                if ($item->check_status == 2 && $item->current_status == 2) {
+                    $visitTime = $item->visit_time;
+                    $diff = strtotime($visitTime) + $diffTime - time();
+                    if ($diff <= 0) {
+                        $item->visit_time = time();
+                    }
+                }
                 $item->consultant_id = $currentConsultantId;
                 $item->dept_id = $currentDeptId;
                 $item->save();

+ 2 - 1
app/wechat/service/UserService.php

@@ -374,7 +374,8 @@ class UserService
         $where[] = [function($query) use ($diffNums, $currentTime){
             $query->orWhereRaw("check_status IN (-1, 1)")
                 ->orWhereRaw("check_status = 2 AND current_status IN (-1,3,4)")
-                ->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} > 0 AND current_status = 2 AND check_status = 2)");
+                ->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} > 0 AND current_status = 2 AND check_status = 2)")
+                ->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} <= 0 AND (visit_time + ({$diffNums} * 4)) - {$currentTime} > 0 AND current_status = 2 AND check_status = 2 AND belong_status = 1)")->whereOr('belong_status','<>', 1);
         }];
         //客户总量
         $customNums = MarketCustomer::where($where)->count();

+ 2 - 1
composer.json

@@ -45,7 +45,8 @@
     "webman/console": "^1.3",
     "yansongda/pay": "v2.10",
     "webman/event": "^1.0",
-    "endroid/qr-code": "^4.6"
+    "endroid/qr-code": "^4.6",
+    "phpoffice/phpspreadsheet": "^1.12"
   },
   "suggest": {
     "ext-event": "For better performance. "

+ 2 - 0
route/admin.php

@@ -642,6 +642,7 @@ Route::group('/admin', function () {
             Route::get('/statistics_month', [\app\admin\controller\consultant\CustomController::class, 'statisticsByMonth']);
             Route::get('/export', [\app\admin\controller\consultant\CustomController::class, 'exportData']);
             Route::post('/appoint', [\app\admin\controller\consultant\CustomController::class, 'appointConsultant']);
+            Route::post('/import', [\app\admin\controller\consultant\CustomController::class, 'importCustom']);
         });
     });
     Route::group('/customer', function () {
@@ -665,6 +666,7 @@ Route::group('/admin', function () {
         Route::group('/account', function () {
             Route::get('/my/{id:\w+}', [\app\admin\controller\member\AccountController::class, 'my']);
             Route::post('/incomeExpend', [\app\admin\controller\member\AccountController::class, 'incomeExpend']);
+            Route::post('/updateStatus', [\app\admin\controller\member\AccountController::class, 'updateStatus']);
             Route::get('/selectMemberAccount', [\app\admin\controller\member\AccountController::class, 'selectMemberAccount']);
         })->middleware([
             \app\middleware\AdminAuthCheck::class