TemplateMessageServices.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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\message\TemplateMessageDao;
  13. use app\services\BaseServices;
  14. /**
  15. * 模板消息
  16. * Class TemplateMessageServices
  17. * @package app\services\other
  18. * @mixin TemplateMessageDao
  19. */
  20. class TemplateMessageServices extends BaseServices
  21. {
  22. /**
  23. * 模板消息
  24. * TemplateMessageServices constructor.
  25. * @param TemplateMessageDao $dao
  26. */
  27. public function __construct(TemplateMessageDao $dao)
  28. {
  29. $this->dao = $dao;
  30. }
  31. /**
  32. * 获取模板消息列表
  33. * @param array $where
  34. * @return array
  35. * @throws \think\db\exception\DataNotFoundException
  36. * @throws \think\db\exception\DbException
  37. * @throws \think\db\exception\ModelNotFoundException
  38. */
  39. public function getTemplateList(array $where)
  40. {
  41. [$page, $limit] = $this->getPageValue();
  42. $list = $this->dao->getTemplateList($where, $page, $limit);
  43. foreach ($list as &$item) {
  44. if ($item['content']) $item['content'] = explode("\n", $item['content']);
  45. }
  46. $count = $this->dao->count($where);
  47. return compact('list', 'count');
  48. }
  49. /**
  50. * 获取模板消息id
  51. * @param string $templateId
  52. * @param int $type
  53. * @return mixed
  54. */
  55. public function getTempId(string $templateId, int $type = 0)
  56. {
  57. return $this->dao->value(['type' => $type, 'tempkey' => $templateId, 'status' => 1], 'tempid');
  58. }
  59. }