194 lines
4.9 KiB
PHP
194 lines
4.9 KiB
PHP
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
*
|
|
*
|
|
*
|
|
* Date: 2022/8/5
|
|
* Time: 9:42
|
|
*/
|
|
|
|
namespace business\admin\controllers;
|
|
|
|
|
|
use business\common\controllers\components\BaseController;
|
|
use business\common\models\MessageNotice;
|
|
use business\common\notice\BusinessNoticeFactory;
|
|
use business\common\services\customers\CustomerNoticeService;
|
|
|
|
class NoticeController extends BaseController
|
|
{
|
|
|
|
public function preAction()
|
|
{
|
|
parent::preAction(); // TODO: Change the autogenerated stub
|
|
}
|
|
|
|
//未读列表
|
|
public function unread()
|
|
{
|
|
$search = [
|
|
'status' => 0,
|
|
'recipient_id' => BusinessNoticeFactory::loginUserStaffId(),
|
|
'notice_type' => request()->input('notice_type'),
|
|
'plugin' => request()->input('plugin'),
|
|
];
|
|
$list = MessageNotice::getList($search)->paginate(20);
|
|
$toArrayList = $this->mapList($list);
|
|
|
|
return $this->successJson('list', $toArrayList);
|
|
}
|
|
|
|
//已读列表
|
|
public function read()
|
|
{
|
|
|
|
$search = [
|
|
'status' => 1,
|
|
'recipient_id' => BusinessNoticeFactory::loginUserStaffId(),
|
|
'notice_type' => request()->input('notice_type'),
|
|
'plugin' => request()->input('plugin'),
|
|
];
|
|
|
|
$list = MessageNotice::getList($search)->paginate(20);
|
|
|
|
$toArrayList = $this->mapList($list);
|
|
|
|
return $this->successJson('list', $toArrayList);
|
|
}
|
|
|
|
//待处理列表
|
|
public function waitHandle()
|
|
{
|
|
$search = [
|
|
'handle_status' => 1,
|
|
'recipient_id' => BusinessNoticeFactory::loginUserStaffId(),
|
|
'notice_type' => request()->input('notice_type'),
|
|
'plugin' => request()->input('plugin'),
|
|
];
|
|
|
|
$list = MessageNotice::getList($search)->paginate(20);
|
|
|
|
$toArrayList = $this->mapList($list);
|
|
|
|
return $this->successJson('list', $toArrayList);
|
|
}
|
|
|
|
protected function mapList($list)
|
|
{
|
|
$list = $list->toArray();
|
|
|
|
list($list['unreadMum'],$list['waitHandleNum']) = $this->countQuantity();
|
|
|
|
return $list;
|
|
}
|
|
|
|
protected function countQuantity()
|
|
{
|
|
$waitHandle = [
|
|
'handle_status' => 1,
|
|
'recipient_id' => BusinessNoticeFactory::loginUserStaffId(),
|
|
'plugin' => request()->input('plugin'),
|
|
'notice_type' => request()->input('notice_type'),
|
|
];
|
|
|
|
$unread = [
|
|
'status' => 0,
|
|
'recipient_id' => BusinessNoticeFactory::loginUserStaffId(),
|
|
'plugin' => request()->input('plugin'),
|
|
'notice_type' => request()->input('notice_type'),
|
|
];
|
|
|
|
$unreadMum = MessageNotice::getList($unread)->count();
|
|
$waitHandleNum = MessageNotice::getList($waitHandle)->count();
|
|
|
|
|
|
return [$unreadMum,$waitHandleNum];
|
|
}
|
|
|
|
|
|
//待处理
|
|
public function laterHandle()
|
|
{
|
|
$taskNotice = MessageNotice::find(intval(request()->input('notice_id')));
|
|
|
|
if ($taskNotice) {
|
|
$taskNotice->fill(['handle_status'=>1])->save();
|
|
}
|
|
|
|
return $this->successJson('加入待处理');
|
|
}
|
|
|
|
//已处理
|
|
public function alreadyHandle()
|
|
{
|
|
$taskNotice = MessageNotice::find(intval(request()->input('notice_id')));
|
|
|
|
if ($taskNotice) {
|
|
$taskNotice->fill(['handle_status'=>0])->save();
|
|
}
|
|
|
|
return $this->successJson('已处理');
|
|
}
|
|
|
|
|
|
//操作已读
|
|
public function markRead()
|
|
{
|
|
$taskNotice = MessageNotice::find(intval(request()->input('notice_id')));
|
|
|
|
if ($taskNotice) {
|
|
$taskNotice->fill(['status'=>1])->save();
|
|
}
|
|
|
|
return $this->successJson('已读');
|
|
}
|
|
|
|
//操作全部已读
|
|
public function batchMarkRead()
|
|
{
|
|
$search = [
|
|
'status' => 0,
|
|
'recipient_id' => BusinessNoticeFactory::loginUserStaffId(),
|
|
];
|
|
|
|
$list = MessageNotice::getList($search)->get();
|
|
if ($list->isNotEmpty()) {
|
|
$list->map(function (MessageNotice $taskNotice) {
|
|
$taskNotice->fill(['status'=>1])->save();
|
|
});
|
|
}
|
|
|
|
return $this->successJson('全部已读');
|
|
}
|
|
|
|
public function allAppModule()
|
|
{
|
|
$a = [
|
|
'app_module' => BusinessNoticeFactory::allModule(),
|
|
'type' => BusinessNoticeFactory::getFormatAllType(request('plugin')),
|
|
];
|
|
|
|
return $this->successJson('eee', $a);
|
|
}
|
|
|
|
public function ttt()
|
|
{
|
|
|
|
$html = request()->input('html', '测试消息通知'.time());
|
|
|
|
$data = [
|
|
'user_ids' => [BusinessNoticeFactory::loginUserStaffId()],
|
|
'param'=> [
|
|
'head' => '商城消息通知测试'.time(),
|
|
'title' => '测试测试哈哈哈',
|
|
],
|
|
'html' => $html,
|
|
];
|
|
|
|
BusinessNoticeFactory::createInstance('shop', 'shop')->create($data);
|
|
|
|
return $this->successJson('success', $data);
|
|
}
|
|
}
|