123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?php
- namespace app\common\dao\system\attachment;
- use app\common\dao\BaseDao;
- use app\common\model\BaseModel;
- use app\common\model\system\attachment\Attachment;
- use think\db\BaseQuery;
- use think\db\exception\DbException;
- /**
- * Class AttachmentDao
- * @package app\common\dao\system\attachment
- * @author zfy
- * @day 2020-04-16
- */
- class AttachmentDao extends BaseDao
- {
- /**
- * @return BaseModel
- * @author zfy
- * @day 2020-03-30
- */
- protected function getModel(): string
- {
- return Attachment::class;
- }
- /**
- * @param array $where
- * @return BaseQuery
- * @author zfy
- * @day 2020-04-15
- */
- public function search(array $where)
- {
- $query = Attachment::getDB()->order('create_time DESC');
- if (isset($where['user_type'])) $query->where('user_type', (int)$where['user_type']);
- if (isset($where['upload_type'])) $query->where('upload_type', (int)$where['upload_type']);
- if (isset($where['attachment_category_id']) && $where['attachment_category_id'])
- $query->where('attachment_category_id', (int)$where['attachment_category_id']);
- if (isset($where['attachment_name']) && $where['attachment_name'])
- $query->whereLike('attachment_name', "%{$where['attachment_name']}%");
- $query->order('create_time DESC');
- return $query;
- }
- /**
- * @param int $id
- * @param int $userType
- * @return int
- * @throws DbException
- * @author zfy
- * @day 2020-04-16
- */
- public function delete(int $id, $userType = 0)
- {
- return ($this->getModel())::getDB()->where('user_type', $userType)->where($this->getPk(), $id)->delete();
- }
- /**
- * @param array $ids
- * @param int $userType
- * @return int
- * @throws DbException
- * @author zfy
- * @day 2020-04-15
- */
- public function batchDelete(array $ids, $userType = 0)
- {
- return ($this->getModel())::getDB()->where('user_type', $userType)->whereIn($this->getPk(), $ids)->delete();
- }
- /**
- * @param int $id
- * @param int $userType
- * @return bool
- * @author zfy
- * @day 2020-04-16
- */
- public function exists(int $id, $userType = 0)
- {
- return ($this->getModel())::getDB()->where($this->getPk(), $id)->count() > 0;
- }
- /**
- * @param array $ids
- * @param array $data
- * @param int $user_type
- * @return int
- * @throws DbException
- * @author zfy
- * @day 2020-04-16
- */
- public function batchChange(array $ids, array $data, int $user_type = 0)
- {
- return ($this->getModel())::getDB()->where('user_type', $user_type)->whereIn($this->getPk(), $ids)->update($data);
- }
- public function clearCache()
- {
- return Attachment::getDB()->where('user_type', -1)->delete();
- }
- }
|