SystemNotification.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 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::delete('NOTICE_SMS_' . $data['mark']);
  90. CacheService::delete('wechat_' . $data['mark']);
  91. CacheService::delete('routine_' . $data['mark']);
  92. CacheService::delete('TEMP_IDS_LIST');
  93. return app('json')->success(100001);
  94. } else {
  95. return app('json')->fail(100007);
  96. }
  97. }
  98. /**
  99. * 修改消息状态
  100. * @param $type
  101. * @param $status
  102. * @param $id
  103. * @return mixed
  104. * @throws \Psr\SimpleCache\InvalidArgumentException
  105. * @throws \think\db\exception\DataNotFoundException
  106. * @throws \think\db\exception\DbException
  107. * @throws \think\db\exception\ModelNotFoundException
  108. */
  109. public function set_status($type, $status, $id)
  110. {
  111. if ($type == '' || $status == '' || $id == 0) return app('json')->fail(100100);
  112. $this->services->update($id, [$type => $status]);
  113. $res = $this->services->getOneNotce(['id' => $id]);
  114. CacheService::delete('NOTICE_SMS_' . $res->mark);
  115. CacheService::delete('wechat_' . $res->mark);
  116. CacheService::delete('routine_' . $res->mark);
  117. CacheService::delete('TEMP_IDS_LIST');
  118. return app('json')->success(100014);
  119. }
  120. }