This commit is contained in:
yaosen 2024-06-25 18:30:50 +08:00
parent 69d900b1f9
commit 617cabbe4c
7 changed files with 106 additions and 11 deletions

View File

@ -98,7 +98,7 @@ export const asyncRoutes = [
component: () => import('@/views/onlines/online.vue'), component: () => import('@/views/onlines/online.vue'),
name: 'onlines', name: 'onlines',
meta: { meta: {
title: '客服在线列表', title: '在线客服列表',
roles: ['admin'] roles: ['admin']
} }
}/*, }/*,

View File

@ -10,12 +10,6 @@
<el-tag v-if="scope.row.isOnline === 2" type="info">没上线</el-tag> <el-tag v-if="scope.row.isOnline === 2" type="info">没上线</el-tag>
</template> </template>
</el-table-column> </el-table-column>
<!-- <el-table-column align="center" label="是否分单" width="100">
<template slot-scope="scope">
<el-tag v-if="scope.row.isEndWork === 0" type="border-card"></el-tag>
<el-tag v-if="scope.row.isEndWork === 1" type="success"></el-tag>
</template>
</el-table-column>-->
<el-table-column align="center" label="是否分单" width="100"> <el-table-column align="center" label="是否分单" width="100">
<template #default="scope"> <template #default="scope">
<el-switch v-model="scope.row.isEndWork" :active-value="1" :inactive-value="0" @change="updateStatus(scope.row)" /> <el-switch v-model="scope.row.isEndWork" :active-value="1" :inactive-value="0" @change="updateStatus(scope.row)" />
@ -31,12 +25,12 @@
{{ Math.floor((scope.row.data ? scope.row.data.onlineTime : scope.row.onlineTime) / 3600) || '--' }} 分钟 {{ Math.floor((scope.row.data ? scope.row.data.onlineTime : scope.row.onlineTime) / 3600) || '--' }} 分钟
</template> </template>
</el-table-column> </el-table-column>
<el-table-column width="138px" align="center" label="上班时间"> <el-table-column width="138px" align="center" label="开始分单的时间">
<template slot-scope="scope"> <template slot-scope="scope">
<span>{{ scope.row.start_work_time | parseTime('{y}-{m}-{d} {h}:{i}') }}</span> <span>{{ scope.row.start_work_time | parseTime('{y}-{m}-{d} {h}:{i}') }}</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column width="138px" align="center" label="下班时间"> <el-table-column width="138px" align="center" label="停止分单的时间">
<template slot-scope="scope"> <template slot-scope="scope">
<span>{{ scope.row.end_work_time | parseTime('{y}-{m}-{d} {h}:{i}') }}</span> <span>{{ scope.row.end_work_time | parseTime('{y}-{m}-{d} {h}:{i}') }}</span>
</template> </template>

View File

@ -17,6 +17,7 @@ class IndexController extends base
public function isWork(Request $request) public function isWork(Request $request)
{ {
Redis::set('CRM:USER:ONLINE:WATCH:' . $request->admin->id, time());
$lastTime = Redis::get('CRM:USER:ONLINE:' . $request->admin->id); $lastTime = Redis::get('CRM:USER:ONLINE:' . $request->admin->id);
$end = Redis::hGet('CRM:USER:ONLINE:END', $request->admin->id); $end = Redis::hGet('CRM:USER:ONLINE:END', $request->admin->id);

View File

@ -0,0 +1,39 @@
<?php
namespace app\admin\controller;
use app\model\Admins;
use support\Log;
use support\Redis;
use think\db\exception\DbException;
class WatchController extends base
{
public static function watchIsWork()
{
$nowTime = time();
$datas = Admins::order('create_time desc')->select();
foreach ($datas as $data) {
$item = [];
$watch = Redis::get('CRM:USER:ONLINE:WATCH:'.$data->id);
if (empty($data->start_work_time)){
$item['start_work_time'] = $nowTime;
}
if (($nowTime - $watch) > 0 && ($nowTime - $watch) <= 6*60){
$item['end_work_time'] = $nowTime;
}
Log::warning('watchIsWork',['data'=>$item]);
if (!empty($item)){
try {
Admins::where('id', $data->id)->update($item);
} catch (DbException $e) {
Log::error('watchIsWork',['error'=>$e]);
continue;
}
}
}
echo "========watchIsWork end======\n";
return;
}
}

View File

@ -34,7 +34,8 @@
"vlucas/phpdotenv": "^5.5", "vlucas/phpdotenv": "^5.5",
"qiniu/php-sdk": "^7.12", "qiniu/php-sdk": "^7.12",
"webman/console": "^1.3", "webman/console": "^1.3",
"mk-j/php_xlsxwriter": "^0.39.0" "mk-j/php_xlsxwriter": "^0.39.0",
"workerman/crontab": "^1.0"
}, },
"suggest": { "suggest": {
"ext-event": "For better performance. " "ext-event": "For better performance. "

52
service/composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "ea0dd6c24e2c79f4af8509724c30fa0f", "content-hash": "c5d73376efb82db5d880157187b7a430",
"packages": [ "packages": [
{ {
"name": "carbonphp/carbon-doctrine-types", "name": "carbonphp/carbon-doctrine-types",
@ -2768,6 +2768,56 @@
}, },
"time": "2023-04-23T14:40:18+00:00" "time": "2023-04-23T14:40:18+00:00"
}, },
{
"name": "workerman/crontab",
"version": "v1.0.6",
"source": {
"type": "git",
"url": "https://github.com/walkor/crontab.git",
"reference": "b78f1556f2977715b9cb5653129e6d9cf160d966"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/walkor/crontab/zipball/b78f1556f2977715b9cb5653129e6d9cf160d966",
"reference": "b78f1556f2977715b9cb5653129e6d9cf160d966",
"shasum": ""
},
"require": {
"php": ">=7.0",
"workerman/workerman": ">=4.0.20"
},
"type": "library",
"autoload": {
"psr-4": {
"Workerman\\Crontab\\": "./src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "walkor",
"email": "walkor@workerman.net",
"homepage": "http://www.workerman.net",
"role": "Developer"
}
],
"description": "A crontab written in PHP based on workerman",
"homepage": "http://www.workerman.net",
"keywords": [
"crontab"
],
"support": {
"email": "walkor@workerman.net",
"forum": "http://wenda.workerman.net/",
"issues": "https://github.com/walkor/workerman/issues",
"source": "https://github.com/walkor/crontab",
"wiki": "http://doc.workerman.net/"
},
"time": "2022-10-17T01:59:19+00:00"
},
{ {
"name": "workerman/webman-framework", "name": "workerman/webman-framework",
"version": "v1.5.18", "version": "v1.5.18",

View File

@ -14,10 +14,12 @@
namespace process; namespace process;
use app\admin\controller\WatchController;
use FilesystemIterator; use FilesystemIterator;
use RecursiveDirectoryIterator; use RecursiveDirectoryIterator;
use RecursiveIteratorIterator; use RecursiveIteratorIterator;
use SplFileInfo; use SplFileInfo;
use Workerman\Crontab\Crontab;
use Workerman\Timer; use Workerman\Timer;
use Workerman\Worker; use Workerman\Worker;
@ -240,4 +242,12 @@ class Monitor
} }
return $memoryLimit; return $memoryLimit;
} }
public function onWorkerStart()
{
// 每秒钟执行一次
new Crontab('*/1 * * * * *', function(){
WatchController::watchIsWork();
});
}
} }