NoticeService.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Niucloud-admin 企业快速开发的saas管理平台
  4. // +----------------------------------------------------------------------
  5. // | 官方网址:https://www.niucloud.com
  6. // +----------------------------------------------------------------------
  7. // | niucloud团队 版权所有 开源版本可自由商用
  8. // +----------------------------------------------------------------------
  9. // | Author: Niucloud Team
  10. // +----------------------------------------------------------------------
  11. namespace app\service\admin\notice;
  12. use app\dict\notice\NoticeDict;
  13. use app\dict\notice\NoticeTypeDict;
  14. use app\model\sys\SysNotice;
  15. use app\service\core\notice\CoreNoticeService;
  16. use core\base\BaseAdminService;
  17. use core\exception\AdminException;
  18. /**
  19. * 消息管理服务层
  20. */
  21. class NoticeService extends BaseAdminService
  22. {
  23. public function __construct()
  24. {
  25. parent::__construct();
  26. $this->model = new SysNotice();
  27. }
  28. /**
  29. * 获取当前站点消息
  30. * @return array
  31. */
  32. public function getList()
  33. {
  34. return (new CoreNoticeService())->getAddonList();
  35. }
  36. /**
  37. * 获取消息内容
  38. * @param string $key
  39. * @return array
  40. */
  41. public function getInfo(string $key)
  42. {
  43. return (new CoreNoticeService())->getInfo($key);
  44. }
  45. /**
  46. * 修改消息模板字段(todo 注意 仅限程序内部调用,故不做验证)
  47. * @param string $key
  48. * @param string $field_type
  49. * @param $value
  50. * @return bool
  51. */
  52. public function modify(string $key, string $field_type, $value){
  53. $data = [
  54. $field_type => $value
  55. ];
  56. return (new CoreNoticeService())->edit($key, $data);
  57. }
  58. /**
  59. * 修改消息状态
  60. * @param string $key
  61. * @param string $type
  62. * @param int $status
  63. */
  64. public function editMessageStatus(string $key, string $type, int $status)
  65. {
  66. if(!array_key_exists($type, NoticeTypeDict::getType())) throw new AdminException('NOTICE_TYPE_NOT_EXIST');
  67. if(!array_key_exists($key, NoticeDict::getNotice())) return fail('NOTICE_TYPE_NOT_EXIST');
  68. return (new CoreNoticeService())->edit($key, ['is_'.$type => $status]);
  69. }
  70. /**
  71. * 消息编辑
  72. * @param string $key
  73. * @param string $type
  74. * @param array $data
  75. */
  76. public function edit(string $key, string $type, array $data)
  77. {
  78. if(!array_key_exists($type, NoticeTypeDict::getType())) throw new AdminException('NOTICE_TYPE_NOT_EXIST');
  79. if(!array_key_exists($key, NoticeDict::getNotice())) return fail('NOTICE_TYPE_NOT_EXIST');
  80. $save_data = ['is_'.$type => $data['status']];
  81. switch ($type)
  82. {
  83. case NoticeTypeDict::SMS:
  84. $save_data['sms_id'] = $data['sms_id'] ?? '';
  85. break;
  86. case NoticeTypeDict::WECHAT:
  87. $save_data['wechat_first'] = $data['wechat_first'] ?? '';
  88. $save_data['wechat_remark'] = $data['wechat_remark'] ?? '';
  89. break;
  90. case NoticeTypeDict::WEAPP:
  91. break;
  92. }
  93. return (new CoreNoticeService())->edit($key, $save_data);
  94. }
  95. }