NoticeLogic.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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\logic\notice;
  15. use app\common\enum\notice\NoticeEnum;
  16. use app\common\logic\BaseLogic;
  17. use app\common\model\master_worker_register\MasterWorkerRegister;
  18. use app\common\model\notice\NoticeSetting;
  19. use app\common\model\works\ServiceWork;
  20. /**
  21. * 通知逻辑层
  22. * Class NoticeLogic
  23. * @package app\adminapi\logic\notice
  24. */
  25. class NoticeLogic extends BaseLogic
  26. {
  27. /**
  28. * @notes 查看通知设置详情
  29. * @param $params
  30. * @return array
  31. * @author 段誉
  32. * @date 2022/3/29 11:34
  33. */
  34. public static function detail($params)
  35. {
  36. $field = 'id,type,scene_id,scene_name,scene_desc,system_notice,sms_notice,oa_notice,mnp_notice,support';
  37. $noticeSetting = NoticeSetting::field($field)->findOrEmpty($params['id'])->toArray();
  38. if (empty($noticeSetting)) {
  39. return [];
  40. }
  41. if (empty($noticeSetting['system_notice'])) {
  42. $noticeSetting['system_notice'] = [
  43. 'title' => '',
  44. 'content' => '',
  45. 'status' => 0,
  46. ];
  47. }
  48. $noticeSetting['system_notice']['tips'] = NoticeEnum::getOperationTips(NoticeEnum::SYSTEM, $noticeSetting['scene_id']);
  49. if (empty($noticeSetting['sms_notice'])) {
  50. $noticeSetting['sms_notice'] = [
  51. 'template_id' => '',
  52. 'content' => '',
  53. 'status' => 0,
  54. ];
  55. }
  56. $noticeSetting['sms_notice']['tips'] = NoticeEnum::getOperationTips(NoticeEnum::SMS, $noticeSetting['scene_id']);
  57. if (empty($noticeSetting['oa_notice'])) {
  58. $noticeSetting['oa_notice'] = [
  59. 'template_id' => '',
  60. 'template_sn' => '',
  61. 'name' => '',
  62. 'first' => '',
  63. 'remark' => '',
  64. 'tpl' => [],
  65. 'status' => 0,
  66. ];
  67. }
  68. $noticeSetting['oa_notice']['tips'] = NoticeEnum::getOperationTips(NoticeEnum::OA, $noticeSetting['scene_id']);
  69. if (empty($noticeSetting['mnp_notice'])) {
  70. $noticeSetting['mnp_notice'] = [
  71. 'template_id' => '',
  72. 'template_sn' => '',
  73. 'name' => '',
  74. 'tpl' => [],
  75. 'status' => 0,
  76. ];
  77. }
  78. $noticeSetting['mnp_notice']['tips'] = NoticeEnum::getOperationTips(NoticeEnum::MNP, $noticeSetting['scene_id']);
  79. $noticeSetting['system_notice']['is_show'] = in_array(NoticeEnum::SYSTEM, explode(',', $noticeSetting['support']));
  80. $noticeSetting['sms_notice']['is_show'] = in_array(NoticeEnum::SMS, explode(',', $noticeSetting['support']));
  81. $noticeSetting['oa_notice']['is_show'] = in_array(NoticeEnum::OA, explode(',', $noticeSetting['support']));
  82. $noticeSetting['mnp_notice']['is_show'] = in_array(NoticeEnum::MNP, explode(',', $noticeSetting['support']));
  83. $noticeSetting['default'] = '';
  84. $noticeSetting['type'] = NoticeEnum::getTypeDesc($noticeSetting['type']);
  85. return $noticeSetting;
  86. }
  87. /**
  88. * @notes 通知设置
  89. * @param $params
  90. * @return bool
  91. * @author 段誉
  92. * @date 2022/3/29 11:34
  93. */
  94. public static function set($params)
  95. {
  96. try {
  97. // 校验参数
  98. //self::checkSet($params);
  99. // 拼装更新数据
  100. $updateData = [];
  101. foreach ($params['template'] as $item) {
  102. if($item['type']??0) $updateData[$item['type'] . '_notice'] = json_encode($item, JSON_UNESCAPED_UNICODE);
  103. }
  104. // 更新通知设置
  105. NoticeSetting::where('id', $params['id'])->update($updateData);
  106. return true;
  107. } catch (\Exception $e) {
  108. self::setError($e->getMessage());
  109. return false;
  110. }
  111. }
  112. /**
  113. * @notes 校验参数
  114. * @param $params
  115. * @throws \Exception
  116. * @author 段誉
  117. * @date 2022/3/29 11:35
  118. */
  119. public static function checkSet($params)
  120. {
  121. $noticeSetting = NoticeSetting::findOrEmpty($params['id'] ?? 0);
  122. if ($noticeSetting->isEmpty()) {
  123. throw new \Exception('通知配置不存在');
  124. }
  125. if (!isset($params['template']) || !is_array($params['template']) || count($params['template']) == 0) {
  126. throw new \Exception('模板配置不存在或格式错误');
  127. }
  128. // 通知类型
  129. $noticeType = ['system', 'sms', 'oa', 'mnp'];
  130. foreach ($params['template'] as $item) {
  131. if (!is_array($item)) {
  132. throw new \Exception('模板项格式错误');
  133. }
  134. if (!isset($item['type']) || !in_array($item['type'], $noticeType)) {
  135. throw new \Exception('模板项缺少模板类型或模板类型有误');
  136. }
  137. switch ($item['type']) {
  138. case "system";
  139. self::checkSystem($item);
  140. break;
  141. case "sms";
  142. self::checkSms($item);
  143. break;
  144. case "oa";
  145. self::checkOa($item);
  146. break;
  147. case "mnp";
  148. self::checkMnp($item);
  149. break;
  150. }
  151. }
  152. }
  153. /**
  154. * @notes 校验系统通知参数
  155. * @param $item
  156. * @throws \Exception
  157. * @author 段誉
  158. * @date 2022/3/29 11:35
  159. */
  160. public static function checkSystem($item)
  161. {
  162. if (!isset($item['title']) || !isset($item['content']) || !isset($item['status'])) {
  163. throw new \Exception('系统通知必填参数:title、content、status');
  164. }
  165. }
  166. /**
  167. * @notes 校验短信通知必填参数
  168. * @param $item
  169. * @throws \Exception
  170. * @author 段誉
  171. * @date 2022/3/29 11:35
  172. */
  173. public static function checkSms($item)
  174. {
  175. if (!isset($item['template_id']) || !isset($item['content']) || !isset($item['status'])) {
  176. throw new \Exception('短信通知必填参数:template_id、content、status');
  177. }
  178. }
  179. /**
  180. * @notes 校验微信模板消息参数
  181. * @param $item
  182. * @throws \Exception
  183. * @author 段誉
  184. * @date 2022/3/29 11:35
  185. */
  186. public static function checkOa($item)
  187. {
  188. if (!isset($item['template_id']) || !isset($item['template_sn']) || !isset($item['name']) || !isset($item['first']) || !isset($item['remark']) || !isset($item['tpl']) || !isset($item['status'])) {
  189. throw new \Exception('微信模板消息必填参数:template_id、template_sn、name、first、remark、tpl、status');
  190. }
  191. }
  192. /**
  193. * @notes 校验微信小程序提醒必填参数
  194. * @param $item
  195. * @throws \Exception
  196. * @author 段誉
  197. * @date 2022/3/29 11:35
  198. */
  199. public static function checkMnp($item)
  200. {
  201. if (!isset($item['template_id']) || !isset($item['template_sn']) || !isset($item['name']) || !isset($item['tpl']) || !isset($item['status'])) {
  202. throw new \Exception('微信模板消息必填参数:template_id、template_sn、name、tpl、status');
  203. }
  204. }
  205. public static function getInformation($adminId)
  206. {
  207. try {
  208. $noticeInfo = [
  209. 'confirm_code' => 0,
  210. 'massage' => '',
  211. 'to_router' => '',
  212. ];
  213. if(!in_array($adminId,[1,2])){
  214. return $noticeInfo;
  215. }
  216. // 用户下单待派单
  217. $serviceWorkCount = ServiceWork::where('work_status', 0)->where('work_pay_status','>', 0)->count('id');
  218. if($serviceWorkCount){
  219. $noticeInfo['confirm_code'] = 101;
  220. $noticeInfo['massage'] .= '您有'.$serviceWorkCount.'个工单待派单';
  221. $noticeInfo['to_router'] = '/works/service_work';
  222. return $noticeInfo;
  223. }
  224. // 师傅入驻待审核
  225. $workerRegisterCount = MasterWorkerRegister::where('status', 0)->count('id');
  226. if($workerRegisterCount){
  227. $noticeInfo['confirm_code'] = 101;
  228. $noticeInfo['massage'] .= '您有'.$workerRegisterCount.'个师傅入驻待审核';
  229. $noticeInfo['to_router'] = '/worker/master_worker_register';
  230. return $noticeInfo;
  231. }
  232. return $noticeInfo;
  233. } catch (\Exception $e) {
  234. self::setError($e->getMessage());
  235. return false;
  236. }
  237. }
  238. }