SystemNoticeConfig.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\admin\system\notice;
  12. use app\common\repositories\system\config\ConfigClassifyRepository;
  13. use app\common\repositories\system\config\ConfigRepository;
  14. use app\common\repositories\system\config\ConfigValueRepository;
  15. use app\validate\admin\SystemNoticeConfigValidate;
  16. use crmeb\basic\BaseController;
  17. use think\App;
  18. use app\common\repositories\system\notice\SystemNoticeConfigRepository;
  19. /**
  20. * 通知管理
  21. */
  22. class SystemNoticeConfig extends BaseController
  23. {
  24. /**
  25. * @var CommunityTopicRepository
  26. */
  27. protected $repository;
  28. /**
  29. * User constructor.
  30. * @param App $app
  31. * @param $repository
  32. */
  33. public function __construct(App $app, SystemNoticeConfigRepository $repository)
  34. {
  35. parent::__construct($app);
  36. $this->repository = $repository;
  37. }
  38. /**
  39. * 列表
  40. * @return mixed
  41. * @author Qinii
  42. */
  43. public function lst()
  44. {
  45. $where = $this->request->params(['keyword', 'type']);
  46. [$page, $limit] = $this->getPage();
  47. return app('json')->success($this->repository->getList($where, $page, $limit));
  48. }
  49. /**
  50. * 创建表单
  51. * @return \think\response\Json
  52. * @author Qinii
  53. * @day 10/26/21
  54. */
  55. public function createForm()
  56. {
  57. return app('json')->success(formToData($this->repository->form(null)));
  58. }
  59. /**
  60. * 创建
  61. * @return \think\response\Json
  62. * @author Qinii
  63. */
  64. public function create()
  65. {
  66. $data = $this->checkParams();
  67. $data['notice_key'] = trim($data['notice_key']);
  68. if ($this->repository->fieldExists('notice_key', $data['notice_key'], null))
  69. return app('json')->fail('通知键名称重复');
  70. $this->repository->create($data);
  71. return app('json')->success('添加成功');
  72. }
  73. /**
  74. * 修改表单
  75. * @param $id
  76. * @return \think\response\Json
  77. * @author Qinii
  78. */
  79. public function updateForm($id)
  80. {
  81. if (!$this->repository->exists($id))
  82. return app('json')->fail('数据不存在');
  83. return app('json')->success(formToData($this->repository->form($id)));
  84. }
  85. /**
  86. * 修改
  87. * @param $id
  88. * @return \think\response\Json
  89. * @author Qinii
  90. */
  91. public function update($id)
  92. {
  93. $data = $this->checkParams();
  94. if (!$this->repository->exists($id))
  95. return app('json')->fail('数据不存在');
  96. if ($this->repository->fieldExists('notice_key', $data['notice_key'], $id))
  97. return app('json')->fail('通知键名称重复');
  98. $this->repository->update($id, $data);
  99. return app('json')->success('编辑成功');
  100. }
  101. /**
  102. * 删除
  103. * @param $id
  104. * @return mixed
  105. * @author Qinii
  106. */
  107. public function delete($id)
  108. {
  109. if (!$this->repository->exists($id))
  110. return app('json')->fail('数据不存在');
  111. $this->repository->update($id, ['is_del' => 1]);
  112. return app('json')->success('删除成功');
  113. }
  114. /**
  115. * 验证
  116. * @return array|mixed|string|string[]
  117. * @author Qinii
  118. */
  119. public function checkParams()
  120. {
  121. $data = $this->request->params(['notice_title', 'notice_key', 'notice_info', 'notice_sys', 'notice_wechat', 'notice_routine', 'notice_sms', 'type']);
  122. app()->make(SystemNoticeConfigValidate::class)->check($data);
  123. return $data;
  124. }
  125. /**
  126. * 获取通知列表
  127. * @return mixed
  128. * @author Qinii
  129. */
  130. public function getOptions()
  131. {
  132. return app('json')->success($this->repository->options());
  133. }
  134. /**
  135. * 状态修改
  136. * @param $id
  137. * @return \think\response\Json
  138. * @author Qinii
  139. */
  140. public function switchStatus($id)
  141. {
  142. $status = $this->request->param('status', 0) == 1 ? 1 : 0;
  143. $key = $this->request->param('key', '');
  144. if (!in_array($key, ['notice_sys', 'notice_wechat', 'notice_routine', 'notice_sms']))
  145. return app('json')->fail('参数有误');
  146. if (!$this->repository->exists($id))
  147. return app('json')->fail('数据不存在');
  148. $this->repository->swithStatus($id, $key, $status);
  149. return app('json')->success('修改成功');
  150. }
  151. /**
  152. * 获取模板id
  153. * @param $id
  154. * @return \think\response\Json
  155. * @author Qinii
  156. */
  157. public function getTemplateId($id)
  158. {
  159. $data = $this->repository->changeForm($id);
  160. return app('json')->success(formToData($data));
  161. }
  162. /**
  163. * 设置模板id
  164. * @param $id
  165. * @return \think\response\Json
  166. * @author Qinii
  167. */
  168. public function setTemplateId($id)
  169. {
  170. $params = $this->request->params(['sms_tempid', 'sms_ali_tempid', 'routine_tempid', 'wechat_tempid', ['notice_routine', -1], ['notice_wechat', -1], ['notice_sms', -1]]);
  171. foreach ($params as $k => $v) {
  172. if (!empty($v)) {
  173. $data[$k] = $v;
  174. }
  175. }
  176. $this->repository->update($id, $data);
  177. return app('json')->success('修改成功');
  178. }
  179. }