TemplateMessageServices.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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\services\message;
  12. use app\dao\other\TemplateMessageDao;
  13. use app\services\BaseServices;
  14. /**
  15. * 模板消息管理类
  16. * Class TemplateMessageServices
  17. * @package app\services\other
  18. * @method getOne(array $where, ?string $field = '*') 获取一条信息
  19. * @method save(array $data) 添加
  20. * @method get(int $id, ?array $field = []) 获取一条信息
  21. * @method update($id, array $data, ?string $key = null) 更新数据
  22. * @method delete($id, ?string $key = null) 删除
  23. */
  24. class TemplateMessageServices extends BaseServices
  25. {
  26. /**
  27. * 模板消息
  28. * TemplateMessageServices constructor.
  29. * @param TemplateMessageDao $dao
  30. */
  31. public function __construct(TemplateMessageDao $dao)
  32. {
  33. $this->dao = $dao;
  34. }
  35. /**
  36. * 获取模板消息列表
  37. * @param array $where
  38. * @return array
  39. * @throws \think\db\exception\DataNotFoundException
  40. * @throws \think\db\exception\DbException
  41. * @throws \think\db\exception\ModelNotFoundException
  42. */
  43. public function getTemplateList(array $where)
  44. {
  45. [$page, $limit] = $this->getPageValue();
  46. $list = $this->dao->getTemplateList($where, $page, $limit);
  47. foreach ($list as &$item) {
  48. if ($item['content']) $item['content'] = explode("\n", $item['content']);
  49. }
  50. $count = $this->dao->count($where);
  51. return compact('list', 'count');
  52. }
  53. /**
  54. * 获取模板消息id
  55. * @param string $templateId
  56. * @param int $type
  57. * @return mixed
  58. */
  59. public function getTempId(string $templateId, int $type = 0)
  60. {
  61. return $this->dao->value(['type' => $type, 'tempkey' => $templateId, 'status' => 1], 'tempid');
  62. }
  63. }