SystemNotification.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\adminapi\controller\v1\setting;
  12. use app\adminapi\controller\AuthController;
  13. use app\services\message\SystemNotificationServices;
  14. use crmeb\services\CacheService;
  15. use think\facade\App;
  16. /**
  17. * Class SystemRole
  18. * @package app\adminapi\controller\v1\setting
  19. */
  20. class SystemNotification extends AuthController
  21. {
  22. /**
  23. * SystemRole constructor.
  24. * @param App $app
  25. * @param SystemNotificationServices $services
  26. */
  27. public function __construct(App $app, SystemNotificationServices $services)
  28. {
  29. parent::__construct($app);
  30. $this->services = $services;
  31. }
  32. /**
  33. * 显示资源列表
  34. * @return \think\Response
  35. * @throws \think\db\exception\DataNotFoundException
  36. * @throws \think\db\exception\DbException
  37. * @throws \think\db\exception\ModelNotFoundException
  38. */
  39. public function index()
  40. {
  41. $where = $this->request->getMore([
  42. ['type', ''],
  43. ]);
  44. return app('json')->success($this->services->getNotList($where));
  45. }
  46. /**
  47. * 添加消息
  48. * @return \think\Response
  49. * @throws \FormBuilder\Exception\FormBuilderException
  50. * @author wuhaotian
  51. * @email 442384644@qq.com
  52. * @date 2024/2/19
  53. */
  54. public function notForm($id)
  55. {
  56. return app('json')->success($this->services->getNotForm($id));
  57. }
  58. /**
  59. * 保存自定义消息
  60. * @param $id
  61. * @return \think\Response
  62. * @author wuhaotian
  63. * @email 442384644@qq.com
  64. * @date 2024/2/20
  65. */
  66. public function notFormSave($id)
  67. {
  68. $data = $this->request->postMore([
  69. ['custom_trigger', ''],
  70. ['name', ''],
  71. ['mark', ''],
  72. ]);
  73. $this->services->notFormSave($id, $data);
  74. return app('json')->success(100000);
  75. }
  76. /**
  77. * 删除消息
  78. * @param $id
  79. * @return \think\Response
  80. * @author wuhaotian
  81. * @email 442384644@qq.com
  82. * @date 2024/2/20
  83. */
  84. public function delNot($id)
  85. {
  86. if (!$id) return app('json')->fail(100100);
  87. $this->services->delete($id);
  88. return app('json')->success(100002);
  89. }
  90. /**
  91. * 显示编辑
  92. * @return \think\Response
  93. * @throws \think\db\exception\DataNotFoundException
  94. * @throws \think\db\exception\DbException
  95. * @throws \think\db\exception\ModelNotFoundException
  96. */
  97. public function info()
  98. {
  99. $where = $this->request->getMore([
  100. ['type', ''],
  101. ['id', 0]
  102. ]);
  103. if (!$where['id']) return app('json')->fail(100100);
  104. return app('json')->success($this->services->getNotInfo($where));
  105. }
  106. /**
  107. * 保存新建的资源
  108. * @return mixed
  109. * @throws \Psr\SimpleCache\InvalidArgumentException
  110. */
  111. public function save()
  112. {
  113. $data = $this->request->postMore([
  114. ['id', 0],
  115. ['type', ''],
  116. ['name', ''],
  117. ['title', ''],
  118. ['is_system', 0],
  119. ['is_app', 0],
  120. ['is_wechat', 0],
  121. ['is_routine', 0],
  122. ['is_sms', 0],
  123. ['is_ent_wechat', 0],
  124. ['system_title', ''],
  125. ['system_text', ''],
  126. ['tempid', ''],
  127. ['tempkey', ''],
  128. ['content', ''],
  129. ['ent_wechat_text', ''],
  130. ['url', ''],
  131. ['wechat_id', ''],
  132. ['routine_id', ''],
  133. ['mark', ''],
  134. ['sms_id', ''],
  135. ['key_list', ''],
  136. ['sms_text', ''],
  137. ['wechat_link', ''],
  138. ['routine_link', ''],
  139. ['wechat_to_routine', ''],
  140. ]);
  141. if ($data['mark'] == 'verify_code') $data['type'] = 'is_sms';
  142. if (!$data['id']) return app('json')->fail(100100);
  143. if ($this->services->saveData($data)) {
  144. CacheService::clear();
  145. return app('json')->success(100001);
  146. } else {
  147. return app('json')->fail(100007);
  148. }
  149. }
  150. /**
  151. * 修改消息状态
  152. * @param $type
  153. * @param $status
  154. * @param $id
  155. * @return mixed
  156. * @throws \Psr\SimpleCache\InvalidArgumentException
  157. * @throws \think\db\exception\DataNotFoundException
  158. * @throws \think\db\exception\DbException
  159. * @throws \think\db\exception\ModelNotFoundException
  160. */
  161. public function set_status($type, $status, $id)
  162. {
  163. if ($type == '' || $status == '' || $id == 0) return app('json')->fail(100100);
  164. $this->services->update($id, [$type => $status]);
  165. $res = $this->services->getOneNotce(['id' => $id]);
  166. CacheService::clear();
  167. return app('json')->success(100014);
  168. }
  169. }