diff --git a/app/Http/Controllers/Api/ImageController.php b/app/Http/Controllers/Api/ImageController.php index 69e5ac4..67c99fa 100644 --- a/app/Http/Controllers/Api/ImageController.php +++ b/app/Http/Controllers/Api/ImageController.php @@ -8,22 +8,26 @@ use App\Common\Helper; class ImageController extends CommonController { + public $path; + public function __construct() { parent::__construct(); + + $this->path = '/uploads/'.date('Y/m',time()); } - //文件上传,成功返回路径,不含域名 + //单文件/图片上传,成功返回路径,不含域名 public function imageUpload(Request $request) { $file = $_FILES['file'];//得到传输的数据 $type = strtolower(substr(strrchr($file["name"], '.'), 1)); //文件后缀 - $image_path = '/uploads/'.date('Y/m',time()).'/'.date('Ymdhis',time()).rand(1000,9999).'.'.$type; - $uploads_path = '/uploads/'.date('Y/m',time()); //存储路径 + $image_path = $this->path.'/'.date('Ymdhis',time()).rand(1000,9999).'.'.$type; + $uploads_path = $this->path; //存储路径 - $allow_type = array('jpg','jpeg','gif','png','doc','docx','txt'); //定义允许上传的类型 + $allow_type = array('jpg','jpeg','gif','png','doc','docx','txt','pdf'); //定义允许上传的类型 //判断文件类型是否被允许上传 if(!in_array($type, $allow_type)) @@ -40,7 +44,7 @@ class ImageController extends CommonController } //文件小于1M - if ($file["size"] < 1024000) + if ($file["size"] < 2048000) { if ($file["error"] > 0) { @@ -58,9 +62,141 @@ class ImageController extends CommonController } else { - return ReturnData::create(ReturnData::SYSTEM_FAIL,null,'文件不得超过1M'); + return ReturnData::create(ReturnData::SYSTEM_FAIL,null,'文件不得超过2M'); } return ReturnData::create(ReturnData::SUCCESS,$image_path); } + + /** + * 多文件上传,成功返回路径,不含域名 + * 多文件上传格式: + * + * + * + */ + public function multipleImageUpload(Request $request) + { + $res = []; + $file = $_FILES['file'];//得到传输的数据 + + if($file) + { + foreach($file['name'] as $key=>$value) + { + $type = strtolower(substr(strrchr($file["name"][$key], '.'), 1)); //文件后缀 + + $image_path = $this->path.'/'.date('Ymdhis',time()).rand(1000,9999).'.'.$type; + $uploads_path = $this->path; //存储路径 + + $allow_type = array('jpg','jpeg','gif','png','doc','docx','txt','pdf'); //定义允许上传的类型 + + //判断文件类型是否被允许上传 + if(!in_array($type, $allow_type)) + { + //如果不被允许,则直接停止程序运行 + return ReturnData::create(ReturnData::SYSTEM_FAIL,null,'文件格式不正确'); + } + + //判断是否是通过HTTP POST上传的 + if(!is_uploaded_file($file['tmp_name'][$key])) + { + //如果不是通过HTTP POST上传的 + return ReturnData::create(ReturnData::SYSTEM_FAIL); + } + + //文件小于2M + if ($file["size"][$key] < 2048000) + { + if ($file["error"][$key] > 0) + { + return ReturnData::create(ReturnData::SYSTEM_FAIL,null,$file["error"][$key]); + } + else + { + if(!file_exists(base_path('public').$uploads_path)) + { + Helper::createDir(base_path('public').$uploads_path); //创建文件夹; + } + + move_uploaded_file($file["tmp_name"][$key], base_path('public').$image_path); + } + } + else + { + return ReturnData::create(ReturnData::SYSTEM_FAIL,null,'文件不得超过2M'); + } + + $res[] = $image_path; + } + } + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + /** + * 多文件上传,成功返回路径,不含域名 + * 多文件上传格式: + * + * + * + */ + public function multipleFileUpload(Request $request) + { + $res = []; + $files = $_FILES;//得到传输的数据 + + if($files) + { + foreach($files as $key=>$file) + { + $type = strtolower(substr(strrchr($file["name"], '.'), 1)); //文件后缀 + + $image_path = $this->path.'/'.date('Ymdhis',time()).rand(1000,9999).'.'.$type; + $uploads_path = $this->path; //存储路径 + + $allow_type = array('jpg','jpeg','gif','png','doc','docx','txt','pdf'); //定义允许上传的类型 + + //判断文件类型是否被允许上传 + if(!in_array($type, $allow_type)) + { + //如果不被允许,则直接停止程序运行 + return ReturnData::create(ReturnData::SYSTEM_FAIL,null,'文件格式不正确'); + } + + //判断是否是通过HTTP POST上传的 + if(!is_uploaded_file($file['tmp_name'])) + { + //如果不是通过HTTP POST上传的 + return ReturnData::create(ReturnData::SYSTEM_FAIL); + } + + //文件小于1M + if ($file["size"] < 2048000) + { + if ($file["error"] > 0) + { + return ReturnData::create(ReturnData::SYSTEM_FAIL,null,$file["error"]); + } + else + { + if(!file_exists(base_path('public').$uploads_path)) + { + Helper::createDir(base_path('public').$uploads_path); //创建文件夹; + } + + move_uploaded_file($file["tmp_name"], base_path('public').$image_path); + } + } + else + { + return ReturnData::create(ReturnData::SYSTEM_FAIL,null,'文件不得超过2M'); + } + + $res[] = $image_path; + } + } + + return ReturnData::create(ReturnData::SUCCESS,$res); + } } \ No newline at end of file diff --git a/app/Http/Controllers/Api/UserWithdrawController.php b/app/Http/Controllers/Api/UserWithdrawController.php new file mode 100644 index 0000000..ba35b30 --- /dev/null +++ b/app/Http/Controllers/Api/UserWithdrawController.php @@ -0,0 +1,114 @@ +input('limit', 10); + $data['offset'] = $request->input('offset', 0); + if($request->input('status', '') != ''){$data['status'] = $request->input('status');} + if($request->input('method', '') != ''){$data['method'] = $request->input('method');} + $data['user_id'] = Token::$uid; + + $res = UserWithdraw::getList($data); + if(!$res) + { + return ReturnData::create(ReturnData::SYSTEM_FAIL); + } + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //添加提现 + public function userWithdrawAdd(Request $request) + { + //参数 + $data['method'] = $request->input('method',''); + $data['money'] = $request->input('money',''); + $data['account'] = $request->input('account',''); + if($request->input('note', '') != ''){$data['note'] = $request->input('note');} + if($request->input('status', '') != ''){$data['status'] = $request->input('status');} + if($request->input('bank_name', '') != ''){$data['bank_name'] = $request->input('bank_name');} + if($request->input('bank_place', '') != ''){$data['bank_place'] = $request->input('bank_place');} + $data['add_time'] = time(); + $data['user_id'] = Token::$uid; + + if($data['method']=='' || $data['money']=='' || $data['account']=='') + { + return ReturnData::create(ReturnData::PARAMS_ERROR); + } + + if($data['method'] == 'bank' && (!isset($data['bank_name']) || !isset($data['bank_place']))) + { + return ReturnData::create(ReturnData::PARAMS_ERROR); + } + + $res = UserWithdraw::add($data); + if(!$res) + { + return ReturnData::create(ReturnData::SYSTEM_FAIL); + } + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //修改提现 + public function userWithdrawUpdate(Request $request) + { + //参数 + $where['user_id'] = Token::$uid; + $where['id'] = $request->input('id',null); + + if($request->input('status',null)!==null){$data['status'] = $request->input('status');} + if($request->input('money',null)!==null){$data['money'] = $request->input('money');} + if($request->input('re_note',null)!==null){$data['re_note'] = $request->input('re_note');} + if($request->input('note',null)!==null){$data['note'] = $request->input('note');} + if($request->input('account',null)!==null){$data['account'] = $request->input('account');} + if($request->input('method',null)!==null){$data['method'] = $request->input('method');} + if($request->input('is_delete',null)!==null){$data['is_delete'] = $request->input('is_delete');} + if($request->input('bank_name',null)!==null){$data['bank_name'] = $request->input('bank_name');} + if($request->input('bank_place',null)!==null){$data['bank_place'] = $request->input('bank_place');} + + if(!isset($data)) + { + return ReturnData::create(ReturnData::SUCCESS); + } + + $res = UserWithdraw::modify($where,$data); + if($res === false) + { + return ReturnData::create(ReturnData::SYSTEM_FAIL); + } + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //删除一条提现 + public function userWithdrawDelete(Request $request) + { + //参数 + $id = $request->input('id',null); + + $res = UserWithdraw::remove($id,Token::$uid); + if($res === false) + { + return ReturnData::create(ReturnData::SYSTEM_FAIL); + } + + return ReturnData::create(ReturnData::SUCCESS,$res); + } +} \ No newline at end of file diff --git a/app/Http/Model/UserWithdraw.php b/app/Http/Model/UserWithdraw.php index 0066d87..8b728c6 100644 --- a/app/Http/Model/UserWithdraw.php +++ b/app/Http/Model/UserWithdraw.php @@ -23,13 +23,15 @@ class UserWithdraw extends BaseModel { extract($param); //参数:limit,offset - $where['user_id'] = Token::$uid; $limit = isset($limit) ? $limit : 10; $offset = isset($offset) ? $offset : 0; + $where['user_id'] = $user_id; + $where['is_delete'] = 0; - $model = new UserWithdraw; + $model = new self; - if(isset($type)){$where['type'] = $type;} + if(isset($status) && !empty($status)){if($status==-1){}else{$where['status'] = $status;}} + if(isset($method)){$where['method'] = $method;} $model = $model->where($where); @@ -38,7 +40,7 @@ class UserWithdraw extends BaseModel if($res['count']>0) { - $res['list'] = $model->skip($offset)->take($limit)->orderBy('id','desc')->get()->toArray(); + $res['list'] = $model->skip($offset)->take($limit)->orderBy('id','desc')->get(); } else { @@ -48,9 +50,14 @@ class UserWithdraw extends BaseModel return $res; } - public static function getOne($id) + public static function getOne(array $param) { - return self::where('id', $id)->first()->toArray(); + extract($param); + + $where['id'] = $id; + $where['is_delete'] = 0; + + return self::where($where)->first(); } public static function add(array $data) @@ -74,9 +81,9 @@ class UserWithdraw extends BaseModel } //删除一条记录 - public static function remove($id) + public static function remove($id,$user_id) { - if (!self::whereIn('id', explode(',', $id))->delete()) + if (!self::whereIn('id', explode(',', $id))->where('user_id',$user_id)->update(array('is_delete'=>1))) { return false; }