NoticeController.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\adminapi\controller\notice;
  15. use app\adminapi\controller\BaseAdminController;
  16. use app\adminapi\lists\notice\NoticeSettingLists;
  17. use app\adminapi\logic\notice\NoticeLogic;
  18. use app\adminapi\validate\notice\NoticeValidate;
  19. use app\common\enum\notice\NoticeEnum;
  20. use app\common\model\notice\NoticeSetting;
  21. use app\common\service\OnlineCustomerService;
  22. use app\common\service\wechat\WeChatOaService;
  23. /**
  24. * 通知控制器
  25. * Class NoticeController
  26. * @package app\adminapi\controller\notice
  27. */
  28. class NoticeController extends BaseAdminController
  29. {
  30. public array $notNeedLogin = ['testNotice'];
  31. /**
  32. * @notes 查看通知设置列表
  33. * @return \think\response\Json
  34. * @author 段誉
  35. * @date 2022/3/29 11:18
  36. */
  37. public function settingLists()
  38. {
  39. return $this->dataLists(new NoticeSettingLists());
  40. }
  41. /**
  42. * @notes 查看通知设置详情
  43. * @return \think\response\Json
  44. * @author 段誉
  45. * @date 2022/3/29 11:18
  46. */
  47. public function detail()
  48. {
  49. $params = (new NoticeValidate())->goCheck('detail');
  50. $result = NoticeLogic::detail($params);
  51. return $this->data($result);
  52. }
  53. /**
  54. * @notes 通知设置
  55. * @return \think\response\Json
  56. * @author 段誉
  57. * @date 2022/3/29 11:18
  58. */
  59. public function set()
  60. {
  61. $params = $this->request->post();
  62. $result = NoticeLogic::set($params);
  63. if ($result) {
  64. return $this->success('设置成功');
  65. }
  66. return $this->fail(NoticeLogic::getError());
  67. }
  68. /**
  69. * @notes 获取通知弹框信息
  70. */
  71. public function getInformation()
  72. {
  73. $params = $this->request->post();
  74. $params['data_rules'] = $this->adminInfo['data_rules']??[];
  75. if(isset($params['business_codes']) && !empty($params['business_codes'])){
  76. $result = NoticeLogic::getInformationBatch($params);
  77. }else{
  78. $result = NoticeLogic::getInformation($params);
  79. }
  80. if ($result) {
  81. return $this->success('获取成功', $result);
  82. }
  83. return $this->fail(NoticeLogic::getError());
  84. }
  85. public function isOnline()
  86. {
  87. $params = $this->request->post();
  88. $params['admin_id'] = $this->adminId??0;
  89. return $this->success('', ['is_online' => OnlineCustomerService::isOnline($params['admin_id'])?1:0]);
  90. }
  91. public function serviceOnline()
  92. {
  93. $params = $this->request->post();
  94. $params['admin_id'] = $this->adminId??0;
  95. $result = OnlineCustomerService::addOnlineCustomerService($params['admin_id']);
  96. return $this->success('', $result?:[]);
  97. }
  98. public function serviceOffline()
  99. {
  100. $params = $this->request->post();
  101. $params['admin_id'] = $this->adminId??0;
  102. $result = OnlineCustomerService::subOnlineCustomerService($params['admin_id']);
  103. return $this->success('', $result?:[]);
  104. }
  105. public function getUnifiedNotific()
  106. {
  107. $params = $this->request->post();
  108. $params['admin_id'] = $this->adminId??0;
  109. $business_codes = [];
  110. isset($params['business_codes']) && $params['business_codes'] && $business_codes = explode(',',$params['business_codes']);
  111. $result = OnlineCustomerService::getAllNotificList($params['admin_id'],$business_codes,$params['prefix']??'',$params['is_test']??0);
  112. return $this->success('', $result?:[]);
  113. }
  114. /**
  115. * @notes 后台测试通知
  116. * http://api.weixiuloc.com:5175/adminapi/notice.notice/testNotice?scene_id=1&params={}
  117. */
  118. public function testNotice()
  119. {
  120. try {
  121. $params = $this->request->get();
  122. if(!isset($params['scene_id'])){
  123. throw new \Exception('scene_id不存在');
  124. }
  125. $noticeSetting = NoticeSetting::where('scene_id', $params['scene_id'])->findOrEmpty()->toArray();
  126. if(isset($noticeSetting['sms_notice']['status'])){
  127. $res = event('Notice', [
  128. 'scene_id' => $params['scene_id'],
  129. 'params' => json_decode($params['params'],true)
  130. /*[
  131. 'user_id' => $params['user_id'],
  132. ]*/
  133. ]);
  134. }
  135. if(isset($noticeSetting['oa_notice']['status'])){
  136. $res = event('Notice', [
  137. 'scene_id' => $params['scene_id'],
  138. 'params' => json_decode($params['params'],true)
  139. /*[
  140. 'user_id' => $params['user_id'],
  141. 'order_id' => $params['order_id']?:'',
  142. 'thing9' => '测试项目名称'.time(),
  143. 'time7' => date("Y-m-d H:i:s", time()),
  144. 'thing8' => '预约地址'.time(),
  145. 'phone_number6' => 18162757399,
  146. ]*/
  147. ]);
  148. }
  149. dd($params,json_decode($params['params'],true),$noticeSetting,$res??[]);
  150. } catch (\Exception $e) {
  151. dd($e->getMessage());
  152. }
  153. }
  154. }