123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
- declare (strict_types=1);
- namespace app\dao\wechat;
- use think\model;
- use app\dao\BaseDao;
- use app\model\wechat\WechatReply;
- use app\model\wechat\WechatKey;
- class WechatReplyKeyDao extends BaseDao
- {
-
- protected $alias = 'r';
-
- protected $joinAlis = 'k';
-
- protected function setModel(): string
- {
- return WechatReply::class;
- }
-
- protected function setJoinModel(): string
- {
- return WechatKey::class;
- }
-
- protected function getModel(string $key = 'id', string $join = 'LEFT')
- {
-
- $keys = app()->make($this->setJoinModel());
- $name = $keys->getName();
- return parent::getModel()->join($name . ' ' . $this->joinAlis, $this->alias . '.' . $key . ' = ' . $this->joinAlis . '.reply_id', $join)->alias($this->alias);
- }
-
- protected function search(array $where = [])
- {
- return $this->getModel()->when(isset($where['key']) && $where['key'], function ($query) use ($where) {
- $query->where($this->joinAlis . '.keys', 'LIKE', "%$where[key]%");
- })->when(isset($where['type']) && $where['type'], function ($query) use ($where) {
- $query->where($this->alias . '.type', $where['type']);
- })->where($this->joinAlis . '.keys', '<>', 'subscribe')
- ->where($this->joinAlis . '.keys', '<>', 'default');
- }
-
- public function getReplyKeyList(array $where, int $page, int $limit)
- {
- return $this->search($where)->page($page, $limit)->group($this->alias . '.id')->field($this->alias . '.*,' . $this->joinAlis . '.keys')->select()->toArray();
- }
-
- public function count(array $where = [], string $field = '*'): int
- {
- return $this->search($where)->group($this->alias . '.id')->count($field);
- }
- }
|