消息提醒提交
This commit is contained in:
16
Server/application/chukebao/model/NoticeModel.php
Normal file
16
Server/application/chukebao/model/NoticeModel.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace app\chukebao\model;
|
||||
|
||||
use think\Model;
|
||||
class NoticeModel extends Model
|
||||
{
|
||||
protected $pk = 'id';
|
||||
protected $name = 'kf_notice';
|
||||
|
||||
// 自动写入时间戳
|
||||
protected $autoWriteTimestamp = true;
|
||||
protected $createTime = 'createTime';
|
||||
protected $updateTime = 'updateTime';
|
||||
|
||||
}
|
||||
@@ -38,4 +38,5 @@ return [
|
||||
'workbench:groupPush' => 'app\command\WorkbenchGroupPushCommand', // 工作台群推送任务
|
||||
'workbench:groupCreate' => 'app\command\WorkbenchGroupCreateCommand', // 工作台群创建任务
|
||||
'workbench:import-contact' => 'app\command\WorkbenchImportContactCommand', // 工作台通讯录导入任务
|
||||
'kf:notice' => 'app\command\KfNoticeCommand', // 客服端消息通知
|
||||
];
|
||||
|
||||
117
Server/application/command/KfNoticeCommand.php
Normal file
117
Server/application/command/KfNoticeCommand.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
namespace app\command;
|
||||
|
||||
use app\chukebao\model\FollowUp;
|
||||
use app\chukebao\model\NoticeModel;
|
||||
use app\chukebao\model\ToDo;
|
||||
use library\ResponseHelper;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\console\input\Option;
|
||||
use think\Db;
|
||||
use think\facade\Log;
|
||||
use think\Queue;
|
||||
use app\job\AllotFriendJob;
|
||||
use think\facade\Cache;
|
||||
|
||||
class KfNoticeCommand extends Command
|
||||
{
|
||||
// 队列名称
|
||||
protected $queueName = 'kf_notice';
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('kfNotice:run')
|
||||
->setDescription('消息通知');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$output->writeln('开始处理消息通知任务...');
|
||||
|
||||
$where = [
|
||||
['isRemind', '=', 0],
|
||||
['reminderTime', '<=', time()],
|
||||
];
|
||||
$notice = [];
|
||||
Db::startTrans();
|
||||
try {
|
||||
$followUp = FollowUp::where($where)->alias('a')
|
||||
->field('a.*,f.nickname,f.avatar,f.alias,f.wechatId')
|
||||
->join(['s2_wechat_friend f'], 'a.friendId = f.id')
|
||||
->select();
|
||||
if (!empty($followUp)) {
|
||||
foreach ($followUp as $k => $v) {
|
||||
switch ($v['type']) {
|
||||
case 1:
|
||||
$title = '电话回访';
|
||||
break;
|
||||
case 2:
|
||||
$title = '发送消息';
|
||||
break;
|
||||
case 3:
|
||||
$title = '安排会议';
|
||||
break;
|
||||
case 4:
|
||||
$title = '发送邮件';
|
||||
break;
|
||||
default:
|
||||
$title = '其他';
|
||||
break;
|
||||
}
|
||||
|
||||
$wechatId = !empty($v['alias']) ? $v['alias'] : $v['wechatId'];
|
||||
$nickname = $v['nickname'] . '(' . $wechatId . ')';
|
||||
$message = $nickname . ':' . $v['description'];
|
||||
$notice[] = [
|
||||
'type' => 2,
|
||||
'userId' => $v['userId'],
|
||||
'companyId' => $v['companyId'],
|
||||
'bindId' => $v['id'],
|
||||
'title' => $title,
|
||||
'message' => $message,
|
||||
'createTime' => $v['reminderTime'],
|
||||
];
|
||||
}
|
||||
FollowUp::where($where)->update(['isRemind' => 1]);
|
||||
}
|
||||
|
||||
$toDo = ToDo::where($where)->alias('a')
|
||||
->field('a.*,f.nickname,f.avatar,f.alias,f.wechatId')
|
||||
->join(['s2_wechat_friend f'], 'a.friendId = f.id')
|
||||
->select();
|
||||
if (!empty($toDo)) {
|
||||
foreach ($toDo as $k => $v) {
|
||||
|
||||
$wechatId = !empty($v['alias']) ? $v['alias'] : $v['wechatId'];
|
||||
$nickname = $v['nickname'] . '(' . $wechatId . ')';
|
||||
$message = $nickname . ':' . $v['description'];
|
||||
|
||||
|
||||
$notice[] = [
|
||||
'type' => 1,
|
||||
'userId' => $v['userId'],
|
||||
'companyId' => $v['companyId'],
|
||||
'bindId' => $v['id'],
|
||||
'title' => $v['title'],
|
||||
'message' => $message,
|
||||
'createTime' => $v['reminderTime'],
|
||||
];
|
||||
}
|
||||
FollowUp::where($where)->update(['isRemind' => 1]);
|
||||
}
|
||||
|
||||
$noticeModel = new NoticeModel();
|
||||
$noticeModel->insertAll($notice);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -78,6 +78,13 @@
|
||||
# 预防性切换好友
|
||||
*/2 * * * * cd /www/wwwroot/mckb_quwanzhi_com/Server && php think switch:friends >> /www/wwwroot/mckb_quwanzhi_com/Server/runtime/log/switch_friends.log 2>&1
|
||||
|
||||
# 消息提醒
|
||||
*/1 * * * * cd /www/wwwroot/mckb_quwanzhi_com/Server && php think kf:notice >> /www/wwwroot/mckb_quwanzhi_com/Server/runtime/log/kf_notice.log 2>&1
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user