SystemNotification.php 3.6 KB

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