SystemNotification.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 \think\db\exception\DataNotFoundException
  50. * @throws \think\db\exception\DbException
  51. * @throws \think\db\exception\ModelNotFoundException
  52. */
  53. public function info()
  54. {
  55. $where = $this->request->getMore([
  56. ['type', ''],
  57. ['id', 0]
  58. ]);
  59. if (!$where['id']) return app('json')->fail(100100);
  60. return app('json')->success($this->services->getNotInfo($where));
  61. }
  62. /**
  63. * 保存新建的资源
  64. * @return mixed
  65. * @throws \Psr\SimpleCache\InvalidArgumentException
  66. */
  67. public function save()
  68. {
  69. $data = $this->request->postMore([
  70. ['id', 0],
  71. ['type', ''],
  72. ['name', ''],
  73. ['title', ''],
  74. ['is_system', 0],
  75. ['is_app', 0],
  76. ['is_wechat', 0],
  77. ['is_routine', 0],
  78. ['is_sms', 0],
  79. ['is_ent_wechat', 0],
  80. ['system_title', ''],
  81. ['system_text', ''],
  82. ['tempid', ''],
  83. ['ent_wechat_text', ''],
  84. ['url', ''],
  85. ['wechat_id', ''],
  86. ['routine_id', ''],
  87. ['mark', ''],
  88. ['sms_id', ''],
  89. ]);
  90. if ($data['mark'] == 'verify_code') $data['type'] = 'is_sms';
  91. if (!$data['id']) return app('json')->fail(100100);
  92. if ($this->services->saveData($data)) {
  93. CacheService::clear();
  94. return app('json')->success(100001);
  95. } else {
  96. return app('json')->fail(100007);
  97. }
  98. }
  99. /**
  100. * 修改消息状态
  101. * @param $type
  102. * @param $status
  103. * @param $id
  104. * @return mixed
  105. * @throws \Psr\SimpleCache\InvalidArgumentException
  106. * @throws \think\db\exception\DataNotFoundException
  107. * @throws \think\db\exception\DbException
  108. * @throws \think\db\exception\ModelNotFoundException
  109. */
  110. public function set_status($type, $status, $id)
  111. {
  112. if ($type == '' || $status == '' || $id == 0) return app('json')->fail(100100);
  113. $this->services->update($id, [$type => $status]);
  114. $res = $this->services->getOneNotce(['id' => $id]);
  115. CacheService::clear();
  116. return app('json')->success(100014);
  117. }
  118. }