消息中心提交
This commit is contained in:
@@ -140,6 +140,12 @@ Route::group('v1/', function () {
|
||||
});
|
||||
|
||||
|
||||
//自动问候
|
||||
Route::group('notice/', function () {
|
||||
Route::get('list', 'app\chukebao\controller\NoticeController@getList');
|
||||
Route::get('readMessage', 'app\chukebao\controller\NoticeController@readMessage');
|
||||
Route::get('readAll', 'app\chukebao\controller\NoticeController@readAll');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
113
Server/application/chukebao/controller/NoticeController.php
Normal file
113
Server/application/chukebao/controller/NoticeController.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace app\chukebao\controller;
|
||||
|
||||
use app\chukebao\model\FollowUp;
|
||||
use app\chukebao\model\NoticeModel;
|
||||
use app\chukebao\model\ToDo;
|
||||
use library\ResponseHelper;
|
||||
use think\Db;
|
||||
|
||||
class NoticeController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 列表
|
||||
* @return \think\response\Json
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getList()
|
||||
{
|
||||
$page = $this->request->param('page', 1);
|
||||
$limit = $this->request->param('limit', 10);
|
||||
$keyword = $this->request->param('keyword', '');
|
||||
$accountId = $this->getUserInfo('s2_accountId');
|
||||
$userId = $this->getUserInfo('id');
|
||||
$companyId = $this->getUserInfo('companyId');
|
||||
|
||||
if (empty($accountId)) {
|
||||
return ResponseHelper::error('请先登录');
|
||||
}
|
||||
$query = NoticeModel::where(['userId' => $userId, 'companyId' => $companyId])
|
||||
->order('id desc');
|
||||
if (!empty($keyword)) {
|
||||
$query->where('title|message', 'like', '%' . $keyword . '%');
|
||||
}
|
||||
$total = $query->count();
|
||||
$list = $query->page($page, $limit)->order('isRead ASC,id DESC')->select()->toArray();
|
||||
|
||||
|
||||
foreach ($list as $k => &$v) {
|
||||
|
||||
if ($v['type'] == 1) {
|
||||
$friendId = ToDo::where(['id' => $v['bindId']])->value('friendId');
|
||||
} elseif ($v['type'] == 2) {
|
||||
$friendId = FollowUp::where(['id' => $v['bindId']])->value('friendId');
|
||||
}
|
||||
|
||||
if (!empty($friendId)) {
|
||||
$friend = Db::table('s2_wechat_friend')->where(['id' => $friendId])->field('nickname,avatar')->find();
|
||||
} else {
|
||||
$friend = ['nickname' => '', 'avatar' => ''];
|
||||
}
|
||||
|
||||
$v['friendData'] = $friend;
|
||||
}
|
||||
unset($v);
|
||||
return ResponseHelper::success(['list' => $list, 'total' => $total]);
|
||||
}
|
||||
|
||||
|
||||
public function readMessage()
|
||||
{
|
||||
$id = $this->request->param('id', '');
|
||||
$userId = $this->getUserInfo('id');
|
||||
$companyId = $this->getUserInfo('companyId');
|
||||
|
||||
if (empty($id)) {
|
||||
return ResponseHelper::error('参数缺失');
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
$notice = NoticeModel::where(['userId' => $userId, 'companyId' => $companyId, 'id' => $id, 'isRead' => 0])->find();
|
||||
if (empty($notice)) {
|
||||
return ResponseHelper::error('该消息不存在或标记已读');
|
||||
}
|
||||
$notice->isRead = 1;
|
||||
$notice->readTime = time();
|
||||
$notice->save();
|
||||
if ($notice->type == 1) {
|
||||
ToDo::where(['userId' => $userId, 'companyId' => $companyId, 'id' => $notice->bindId])->update(['isProcess' => 1, 'updateTime' => time()]);
|
||||
} elseif ($notice->type == 2) {
|
||||
FollowUp::where(['userId' => $userId, 'companyId' => $companyId, 'id' => $notice->bindId])->update(['isProcess' => 1, 'updateTime' => time()]);
|
||||
}
|
||||
Db::commit();
|
||||
return ResponseHelper::success(' ', '处理成功');
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
return ResponseHelper::error('处理失败:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function readAll()
|
||||
{
|
||||
$userId = $this->getUserInfo('id');
|
||||
$companyId = $this->getUserInfo('companyId');
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
$noticeData = NoticeModel::where(['userId' => $userId, 'companyId' => $companyId, 'isRead' => 0])->select()->toArray();
|
||||
if (empty($noticeData)) {
|
||||
return ResponseHelper::error('暂未有新消息');
|
||||
}
|
||||
FollowUp::where(['userId' => $userId, 'companyId' => $companyId, 'isProcess' => 0])->update(['isProcess' => 1, 'updateTime' => time()]);
|
||||
ToDo::where(['userId' => $userId, 'companyId' => $companyId, 'isProcess' => 0])->update(['isProcess' => 1, 'updateTime' => time()]);
|
||||
Db::commit();
|
||||
return ResponseHelper::success(' ', '全部已读');
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
return ResponseHelper::error('处理失败:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,7 +14,12 @@ class WechatGroupController extends BaseController
|
||||
$userId = $this->getUserInfo('id');
|
||||
$companyId = $this->getUserInfo('companyId');
|
||||
|
||||
$query = Db::table('s2_wechat_group')->where(['accountId' => $accountId])->whereIn('groupType',[1,2])->order('sortIndex desc,id desc');
|
||||
$query = Db::table('s2_wechat_group')
|
||||
->where(function ($query) use ($accountId,$companyId) {
|
||||
$query->where('accountId', $accountId)->whereOr('departmentId', $companyId);
|
||||
})
|
||||
->whereIn('groupType',[1,2])
|
||||
->order('groupType desc,sortIndex desc,id desc');
|
||||
$list = $query->select();
|
||||
$total = $query->count();
|
||||
|
||||
|
||||
@@ -30,7 +30,6 @@ class KfNoticeCommand extends Command
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$output->writeln('开始处理消息通知任务...');
|
||||
|
||||
$where = [
|
||||
['isRemind', '=', 0],
|
||||
['reminderTime', '<=', time()],
|
||||
@@ -41,6 +40,7 @@ class KfNoticeCommand extends Command
|
||||
$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')
|
||||
->where('isRemind',0)
|
||||
->select();
|
||||
if (!empty($followUp)) {
|
||||
foreach ($followUp as $k => $v) {
|
||||
@@ -81,6 +81,7 @@ class KfNoticeCommand extends Command
|
||||
$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')
|
||||
->where('isRemind',0)
|
||||
->select();
|
||||
if (!empty($toDo)) {
|
||||
foreach ($toDo as $k => $v) {
|
||||
|
||||
Reference in New Issue
Block a user