SystemNotificationServices.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. declare (strict_types=1);
  12. namespace app\services\message;
  13. use app\dao\system\SystemNotificationDao;
  14. use app\services\BaseServices;
  15. use crmeb\exceptions\AdminException;
  16. /**
  17. * 消息管理类
  18. * Class SystemNotificationServices
  19. * @package app\services\system
  20. * @method value($where, $value) 条件获取某个字段的值
  21. */
  22. class SystemNotificationServices extends BaseServices
  23. {
  24. /**
  25. * SystemNotificationServices constructor.
  26. * @param SystemNotificationDao $dao
  27. */
  28. public function __construct(SystemNotificationDao $dao)
  29. {
  30. $this->dao = $dao;
  31. }
  32. /**
  33. * 单个配置
  34. * @param int $where
  35. * @return array
  36. * @throws \think\db\exception\DataNotFoundException
  37. * @throws \think\db\exception\DbException
  38. * @throws \think\db\exception\ModelNotFoundException
  39. */
  40. public function getOneNotce(array $where)
  41. {
  42. return $this->dao->getOne($where);
  43. }
  44. /**
  45. * 后台获取列表
  46. * @param array $where
  47. * @return array
  48. * @throws \think\db\exception\DataNotFoundException
  49. * @throws \think\db\exception\DbException
  50. * @throws \think\db\exception\ModelNotFoundException
  51. */
  52. public function getNotList(array $where)
  53. {
  54. return $this->dao->getList($where);
  55. }
  56. /**
  57. * 获取单条数据
  58. * @param array $where
  59. * @return array
  60. * @throws \think\db\exception\DataNotFoundException
  61. * @throws \think\db\exception\DbException
  62. * @throws \think\db\exception\ModelNotFoundException
  63. */
  64. public function getNotInfo(array $where)
  65. {
  66. $type = $where['type'];
  67. unset($where['type']);
  68. $info = $this->dao->getOne($where);
  69. if (!$info) return [];
  70. $info = $info->toArray();
  71. switch ($type) {
  72. case 'is_system':
  73. $info['content'] = $info['system_text'] ?? '';
  74. break;
  75. case 'is_sms':
  76. $info['content'] = $info['sms_text'];
  77. break;
  78. case 'is_wechat':
  79. $info['tempkey'] = $info['wechat_tempkey'] ?? '';
  80. $info['tempid'] = $info['wechat_tempid'] ?? '';
  81. $info['content'] = $info['wechat_content'] ?? '';
  82. break;
  83. case 'is_routine':
  84. $info['tempkey'] = $info['routine_tempkey'] ?? '';
  85. $info['tempid'] = $info['routine_tempid'] ?? '';
  86. $info['content'] = $info['routine_content'] ?? '';
  87. break;
  88. }
  89. return $info;
  90. }
  91. /**
  92. * 保存数据
  93. * @param array $data
  94. * @return bool|\crmeb\basic\BaseModel|null
  95. * @throws \think\db\exception\DataNotFoundException
  96. * @throws \think\db\exception\DbException
  97. * @throws \think\db\exception\ModelNotFoundException
  98. */
  99. public function saveData(array $data)
  100. {
  101. $type = $data['type'];
  102. $id = $data['id'];
  103. $info = $this->dao->get($id);
  104. if (!$info) {
  105. throw new AdminException(100026);
  106. }
  107. $res = null;
  108. switch ($type) {
  109. case 'is_system':
  110. $update = [];
  111. $update['name'] = $data['name'];
  112. $update['title'] = $data['title'];
  113. $update['is_system'] = $data['is_system'];
  114. $update['is_app'] = $data['is_app'];
  115. $update['system_title'] = $data['system_title'];
  116. $update['system_text'] = $data['system_text'];
  117. $res = $this->dao->update((int)$id, $update);
  118. break;
  119. case 'is_sms':
  120. $update = [];
  121. $update['name'] = $data['name'];
  122. $update['title'] = $data['title'];
  123. $update['is_sms'] = $data['is_sms'];
  124. $update['sms_id'] = $data['sms_id'];
  125. $res = $this->dao->update((int)$id, $update);
  126. break;
  127. case 'is_wechat':
  128. $update['is_wechat'] = $data['is_wechat'];
  129. $update['wechat_tempid'] = $data['tempid'];
  130. $res = $this->dao->update((int)$id, $update);
  131. break;
  132. case 'is_routine':
  133. $update['is_routine'] = $data['is_routine'];
  134. $update['routine_tempid'] = $data['tempid'];
  135. $res = $this->dao->update((int)$id, $update);
  136. break;
  137. case 'is_ent_wechat':
  138. $update['name'] = $data['name'];
  139. $update['title'] = $data['title'];
  140. $update['is_ent_wechat'] = $data['is_ent_wechat'];
  141. $update['ent_wechat_text'] = $data['ent_wechat_text'];
  142. $update['url'] = $data['url'];
  143. $res = $this->dao->update((int)$id, $update);
  144. break;
  145. }
  146. return $res;
  147. }
  148. /**
  149. * 获取tempid
  150. * @param $type
  151. * @return array
  152. * @author: 吴汐
  153. * @email: 442384644@qq.com
  154. * @date: 2023/8/16
  155. */
  156. public function getTempId($type)
  157. {
  158. return $this->dao->getTempId($type);
  159. }
  160. /**
  161. * 获取tempkey
  162. * @param $type
  163. * @return array
  164. * @throws \think\db\exception\DataNotFoundException
  165. * @throws \think\db\exception\DbException
  166. * @throws \think\db\exception\ModelNotFoundException
  167. * @author: 吴汐
  168. * @email: 442384644@qq.com
  169. * @date: 2023/8/16
  170. */
  171. public function getTempKey($type)
  172. {
  173. return $this->dao->getTempKey($type);
  174. }
  175. }