Преглед изворни кода

超时未上门和未完成的工单标记异常、客服登录设置30分钟会话时间

dongxiaoqin пре 10 месеци
родитељ
комит
c28af2d808

+ 9 - 2
app/adminapi/http/middleware/LoginMiddleware.php

@@ -56,8 +56,15 @@ class LoginMiddleware
 
         //token临近过期,自动续期
         if ($adminInfo) {
-            //获取临近过期自动续期时长
-            $beExpireDuration = Config::get('project.admin_token.be_expire_duration');
+            //客服派单员
+            if (isset($adminInfo['role_name']) && (strpos($adminInfo['role_name'], '派单') !== false || strpos($adminInfo['role_name'], '客服') !== false)) {  
+                //获取临近过期自动续期时长
+                $beExpireDuration = Config::get('project.kefu_admin_token.be_expire_duration');
+            } else {
+                //获取临近过期自动续期时长
+                $beExpireDuration = Config::get('project.admin_token.be_expire_duration');
+            }
+
             //token续期
             if (time() > ($adminInfo['expire_time'] - $beExpireDuration)) {
                 $result = AdminTokenService::overtimeToken($token);

+ 17 - 2
app/adminapi/service/AdminTokenService.php

@@ -17,6 +17,7 @@ namespace app\adminapi\service;
 
 use app\common\cache\AdminTokenCache;
 use app\common\model\auth\AdminSession;
+use app\common\model\auth\AdminRole;
 use think\facade\Config;
 
 /**
@@ -44,7 +45,7 @@ class AdminTokenService
         $adminSession = AdminSession::where([['admin_id', '=', $adminId], ['terminal', '=', $terminal]])->find();
 
         //获取token延长过期的时间
-        $expireTime = $time + Config::get('project.admin_token.expire_duration');
+        $expireTime = $time + self::getExpireDuration($adminId);
         $adminTokenCache = new AdminTokenCache();
 
         //token处理
@@ -90,12 +91,26 @@ class AdminTokenService
             return false;
         }
         //延长token过期时间
-        $adminSession->expire_time = $time + Config::get('project.admin_token.expire_duration');
+        $adminSession->expire_time = $time + self::getExpireDuration($adminSession->admin_id);
         $adminSession->update_time = $time;
         $adminSession->save();
         return (new AdminTokenCache())->setAdminInfo($adminSession->token);
     }
 
+    public static function getExpireDuration($adminId)
+    {
+        $roolName = AdminRole::alias('a')
+            ->join('system_role b', 'a.role_id = b.id')
+            ->where('a.admin_id', $adminId)
+            ->value('b.name');
+
+        if (strpos($roolName, '客服') !== false || strpos($roolName, '派单') !== false) {
+            return Config::get('project.kefu_admin_token.expire_duration');
+        } else {
+            return Config::get('project.admin_token.expire_duration');
+        }
+    }
+
     /**
      * @notes 设置token为过期
      * @param $token

+ 60 - 7
app/common/command/AutomaticDispatch.php

@@ -55,26 +55,36 @@ class AutomaticDispatch extends Command
             $this->startTask();
         }
 
-        //异常工单:上门时间超过两小时状态未变更已上门
+        //异常工单:已过预约时间工程师未确认上门
         $this->workAnomalous();
+
+        //异常工单:上门时间超过两小时工单未确认完成
+        $this->unFinishedWorkAnomalous();
     }
 
     /**
-     * 异常工单:上门时间超过两小时状态未变更已上门
+     * 异常工单:已过预约时间工程师未确认上门
      */
     protected function workAnomalous() 
     {
         $size = 100;
-        $startTime = time() - 7200;  // 当前时间减去7200秒(2小时)
+        $startTime = strtotime(date('Y-m-d 00:00:00'));
+        $endTime = time();  // 当前时间戳
+
         $list = ServiceWork::alias("a")
             ->leftJoin('service_work_anomalous b','a.id = b.work_id')
             ->where('a.work_status',3)
             ->where('a.service_status','<',2)
             ->where('a.refund_approval',0)
             ->where('a.work_pay_status',1)
-            ->where('a.appointment_time','<=', $startTime)
-            ->whereNull('b.id')
-            ->field('a.id,a.appointment_time,b.id as anomalous_id')
+            ->where('a.appointment_time','between', [$startTime, $endTime])
+            ->whereNotExists(function($query) {
+                $query->table('la_service_work_anomalous c')
+                      ->whereRaw('a.id = c.work_id')
+                      ->where('c.reason_type', 3);
+            })
+            ->field('a.id,a.appointment_time,b.id as anomalous_id,b.reason_type')
+            ->group('a.id')
             ->order('a.create_time','asc')
             ->limit($size)
             ->select()
@@ -88,7 +98,50 @@ class AutomaticDispatch extends Command
                 ServiceWorkAnomalous::create([
                     'work_id' => $item['id'],
                     'reason_type' => 3,
-                    'reason' => '上门时间超过两小时状态未变更已上门',
+                    'reason' => '已过预约时间工程师未确认上门',
+                ]);
+            } catch (\Exception $e) {
+                Log::write('异常工单:'.$e->getMessage());
+            }
+        }
+    }
+
+    /**
+     * 异常工单:上门时间超过两小时工单未确认完成
+     */
+    protected function unFinishedWorkAnomalous() 
+    {
+        $size = 100;
+        $startTime = strtotime(date('Y-m-d 00:00:00'));
+        $endTime = time() - 7200;  // 当前时间减去7200秒(2小时)
+        $list = ServiceWork::alias("a")
+            ->leftJoin('service_work_anomalous b','a.id = b.work_id')
+            ->where('a.work_status', '>=', 4)
+            ->where('a.service_status','<',3)
+            ->where('a.refund_approval',0)
+            ->where('a.work_pay_status',1)
+            ->where('a.appointment_time','between', [$startTime, $endTime])
+            ->whereNotExists(function($query) {
+                $query->table('la_service_work_anomalous c')
+                      ->whereRaw('a.id = c.work_id')
+                      ->where('c.reason_type', 4);
+            })
+            ->field('a.id,a.appointment_time,b.id as anomalous_id')
+            ->group('a.id')
+            ->order('a.create_time','asc')
+            ->limit($size)
+            ->select()
+            ->toArray();
+        if (!$list) {
+            return ;
+        }
+
+        foreach($list as $item) {     
+            try {
+                ServiceWorkAnomalous::create([
+                    'work_id' => $item['id'],
+                    'reason_type' => 4,
+                    'reason' => '上门时间超过两小时工单未确认完成',
                 ]);
             } catch (\Exception $e) {
                 Log::write('异常工单:'.$e->getMessage());

+ 32 - 0
app/common/service/call/VirtualCallService.php

@@ -0,0 +1,32 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+namespace app\common\service\call;
+
+class VirtualCallService
+{
+    /**
+     * @notes 设置配置值
+     * @param $type
+     * @param $name
+     * @param $value
+     * @return mixed
+     * @author 段誉
+     * @date 2021/12/27 15:00
+     */
+    public static function set(string $type, string $name, $value)
+    {
+        return '';
+    }
+}

+ 6 - 0
config/project.php

@@ -58,6 +58,12 @@ return [
         'be_expire_duration' => 3600,//管理后台token临时过期前时长,自动续期
     ],
 
+    //后台客服管理员token(登录令牌)配置
+    'kefu_admin_token' => [
+        'expire_duration' => 30*60,//管理后台token过期时长(单位秒)
+        'be_expire_duration' => 0,//不自动续期
+    ],
+
     // 商城用户token(登录令牌)配置
     'user_token' => [
         'expire_duration' => 3600 * 24 * 30,//用户token过期时长(单位秒)