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(); } }