NoticeController.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Name: 芸众商城系统
  5. * Author: 广州市芸众信息科技有限公司
  6. * Profile: 广州市芸众信息科技有限公司位于国际商贸中心的广州,专注于移动电子商务生态系统打造,拥有芸众社交电商系统、区块链数字资产管理系统、供应链管理系统、电子合同等产品/服务。官网 :www.yunzmall.com www.yunzshop.com
  7. * Date: 2022/8/5
  8. * Time: 9:42
  9. */
  10. namespace business\admin\controllers;
  11. use business\common\controllers\components\BaseController;
  12. use business\common\models\MessageNotice;
  13. use business\common\notice\BusinessNoticeFactory;
  14. use business\common\services\customers\CustomerNoticeService;
  15. class NoticeController extends BaseController
  16. {
  17. public function preAction()
  18. {
  19. parent::preAction(); // TODO: Change the autogenerated stub
  20. }
  21. //未读列表
  22. public function unread()
  23. {
  24. $search = [
  25. 'status' => 0,
  26. 'recipient_id' => BusinessNoticeFactory::loginUserStaffId(),
  27. 'notice_type' => request()->input('notice_type'),
  28. 'plugin' => request()->input('plugin'),
  29. ];
  30. $list = MessageNotice::getList($search)->paginate(20);
  31. $toArrayList = $this->mapList($list);
  32. return $this->successJson('list', $toArrayList);
  33. }
  34. //已读列表
  35. public function read()
  36. {
  37. $search = [
  38. 'status' => 1,
  39. 'recipient_id' => BusinessNoticeFactory::loginUserStaffId(),
  40. 'notice_type' => request()->input('notice_type'),
  41. 'plugin' => request()->input('plugin'),
  42. ];
  43. $list = MessageNotice::getList($search)->paginate(20);
  44. $toArrayList = $this->mapList($list);
  45. return $this->successJson('list', $toArrayList);
  46. }
  47. //待处理列表
  48. public function waitHandle()
  49. {
  50. $search = [
  51. 'handle_status' => 1,
  52. 'recipient_id' => BusinessNoticeFactory::loginUserStaffId(),
  53. 'notice_type' => request()->input('notice_type'),
  54. 'plugin' => request()->input('plugin'),
  55. ];
  56. $list = MessageNotice::getList($search)->paginate(20);
  57. $toArrayList = $this->mapList($list);
  58. return $this->successJson('list', $toArrayList);
  59. }
  60. protected function mapList($list)
  61. {
  62. $list = $list->toArray();
  63. list($list['unreadMum'],$list['waitHandleNum']) = $this->countQuantity();
  64. return $list;
  65. }
  66. protected function countQuantity()
  67. {
  68. $waitHandle = [
  69. 'handle_status' => 1,
  70. 'recipient_id' => BusinessNoticeFactory::loginUserStaffId(),
  71. 'plugin' => request()->input('plugin'),
  72. 'notice_type' => request()->input('notice_type'),
  73. ];
  74. $unread = [
  75. 'status' => 0,
  76. 'recipient_id' => BusinessNoticeFactory::loginUserStaffId(),
  77. 'plugin' => request()->input('plugin'),
  78. 'notice_type' => request()->input('notice_type'),
  79. ];
  80. $unreadMum = MessageNotice::getList($unread)->count();
  81. $waitHandleNum = MessageNotice::getList($waitHandle)->count();
  82. return [$unreadMum,$waitHandleNum];
  83. }
  84. //待处理
  85. public function laterHandle()
  86. {
  87. $taskNotice = MessageNotice::find(intval(request()->input('notice_id')));
  88. if ($taskNotice) {
  89. $taskNotice->fill(['handle_status'=>1])->save();
  90. }
  91. return $this->successJson('加入待处理');
  92. }
  93. //已处理
  94. public function alreadyHandle()
  95. {
  96. $taskNotice = MessageNotice::find(intval(request()->input('notice_id')));
  97. if ($taskNotice) {
  98. $taskNotice->fill(['handle_status'=>0])->save();
  99. }
  100. return $this->successJson('已处理');
  101. }
  102. //操作已读
  103. public function markRead()
  104. {
  105. $taskNotice = MessageNotice::find(intval(request()->input('notice_id')));
  106. if ($taskNotice) {
  107. $taskNotice->fill(['status'=>1])->save();
  108. }
  109. return $this->successJson('已读');
  110. }
  111. //操作全部已读
  112. public function batchMarkRead()
  113. {
  114. $search = [
  115. 'status' => 0,
  116. 'recipient_id' => BusinessNoticeFactory::loginUserStaffId(),
  117. ];
  118. $list = MessageNotice::getList($search)->get();
  119. if ($list->isNotEmpty()) {
  120. $list->map(function (MessageNotice $taskNotice) {
  121. $taskNotice->fill(['status'=>1])->save();
  122. });
  123. }
  124. return $this->successJson('全部已读');
  125. }
  126. public function allAppModule()
  127. {
  128. $a = [
  129. 'app_module' => BusinessNoticeFactory::allModule(),
  130. 'type' => BusinessNoticeFactory::getFormatAllType(request('plugin')),
  131. ];
  132. return $this->successJson('eee', $a);
  133. }
  134. public function ttt()
  135. {
  136. $html = request()->input('html', '测试消息通知'.time());
  137. $data = [
  138. 'user_ids' => [BusinessNoticeFactory::loginUserStaffId()],
  139. 'param'=> [
  140. 'head' => '商城消息通知测试'.time(),
  141. 'title' => '测试测试哈哈哈',
  142. ],
  143. 'html' => $html,
  144. ];
  145. BusinessNoticeFactory::createInstance('shop', 'shop')->create($data);
  146. return $this->successJson('success', $data);
  147. }
  148. }