You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TemplateMessageDao.php 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace app\dao\message;
  3. use app\dao\BaseDao;
  4. use app\model\message\TemplateMessage;
  5. /**
  6. * 模板消息
  7. * Class TemplateMessageDao
  8. * @package app\dao\message
  9. */
  10. class TemplateMessageDao extends BaseDao
  11. {
  12. /**
  13. * 设置模型
  14. * @return string
  15. */
  16. protected function setModel(): string
  17. {
  18. return TemplateMessage::class;
  19. }
  20. /**
  21. * 获取一条数据
  22. * @param array $where
  23. * @param string $filed
  24. * @param bool $is_search
  25. * @return array|\think\Model|null
  26. * @throws \think\db\exception\DataNotFoundException
  27. * @throws \think\db\exception\DbException
  28. * @throws \think\db\exception\ModelNotFoundException
  29. */
  30. public function getTemplateOne(array $where, string $filed = '*', bool $is_search = true)
  31. {
  32. if ($is_search) {
  33. return $this->search($where)->field($filed)->find();
  34. } else {
  35. return $this->getModel()->where($where)->find();
  36. }
  37. }
  38. /**
  39. * 获取模板消息列表
  40. * @param array $where
  41. * @param int $page
  42. * @param int $limit
  43. * @return \think\Collection
  44. * @throws \think\db\exception\DataNotFoundException
  45. * @throws \think\db\exception\DbException
  46. * @throws \think\db\exception\ModelNotFoundException
  47. */
  48. public function getTemplateList(array $where, int $page, int $limit)
  49. {
  50. return $this->getModel()->when(isset($where['name']) && $where['name'] != '', function ($query) use ($where) {
  51. $query->where('name', 'LIKE', "%$where[name]%");
  52. })->when(isset($where['status']) && $where['status'] != '', function ($query) use ($where) {
  53. $query->where('status', $where['status']);
  54. })->where('type', $where['type'])->page($page, $limit)->select()->toArray();
  55. }
  56. }