TemplateMessageDao.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace app\common\dao\wechat;
  3. use app\common\dao\BaseDao;
  4. use app\common\model\wechat\TemplateMessage;
  5. class TemplateMessageDao extends BaseDao
  6. {
  7. protected function getModel(): string
  8. {
  9. return TemplateMessage::class;
  10. }
  11. public function search(array $where)
  12. {
  13. return ($this->getModel()::getDB())->when(isset($where['status']) && $where['status'] !== '', function ($query) use ($where) {
  14. $query->where('status', $where['status']);
  15. })->when(isset($where['type']) && $where['type'] !== '', function ($query) use ($where) {
  16. $query->where('type', $where['type']);
  17. })->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use ($where) {
  18. $query->where(function($query)use($where) {
  19. $query->where('name', 'like', '%' . $where['keyword'] . '%');
  20. $query->whereOr('tempid', 'like', '%' . $where['keyword'] . '%');
  21. });
  22. })->order('create_time DESC');
  23. }
  24. public function getTempId($key, $type)
  25. {
  26. return TemplateMessage::getDB()->where(['type' => $type, 'tempkey' => $key, 'status' => 1])->value('tempid');
  27. }
  28. }