where(['file_path' => $file_path])->value('file_id'); } /** * 查询文件id */ public static function getFileName($fileId) { return (new static)->where(['file_id' => $fileId])->value('file_path'); } /** * 获取列表记录 */ public function getList($applet_id=0,$shop_id = 0,$user_id = 0,$group_id = 0, string $file_type = 'image') { $filter = [ 'file_type' => $file_type, 'is_delete' => 0, 'applet_id' => $applet_id, 'user_id' => $user_id, 'shop_id' => $shop_id ]; $group_id > 0 && $filter['group_id'] = $group_id;//已分组条件 $group_id < 0 && $filter['group_id'] = 0; //未分组条件 return $this->where($filter)->order(['file_id' => 'desc'])->paginate(32); } /** * 文件详情 */ public static function get($fileId) { return self::where('file_id',$fileId)->find(); } /** * 添加新记录 */ public function add(array $data) { return $this->save($data); } /** * 批量软删除 */ public function softDelete(array $fileIds) { return $this->where('file_id','in',$fileIds)->update(['is_delete' => 1]); } /** * 批量移动文件分组 */ public function moveGroup($group_id, array $fileIds) { return $this->where('file_id','in',$fileIds)->update(compact('group_id')); } /** * 删除 */ public function remove($imageId) { $list = $this->where('file_id','in',$imageId)->select(); foreach ($list as $vo){ @unlink('./uploads/' . $vo['file_path']); } return $this->where('file_id','in',$imageId)->delete(); } }