diff --git a/app/Http/Controllers/Api/UserController.php b/app/Http/Controllers/Api/UserController.php index 3952e46..bae8163 100644 --- a/app/Http/Controllers/Api/UserController.php +++ b/app/Http/Controllers/Api/UserController.php @@ -31,8 +31,15 @@ class UserController extends CommonController //修改用户信息 public function userInfoUpdate(Request $request) { - $data = ''; - if($request->input('user_name', null)!==null){$data['user_name'] = $request->input('user_name');} + if($request->input('user_name', null)!==null) + { + $data['user_name'] = $request->input('user_name'); + + if(User::getOneUser($data)) + { + return ReturnData::create(ReturnData::PARAMS_ERROR,null,'用户名已存在'); + } + } if($request->input('email', null)!==null){$data['email'] = $request->input('email');} if($request->input('sex', null)!==null){$data['sex'] = $request->input('sex');} if($request->input('birthday', null)!==null){$data['birthday'] = $request->input('birthday');} @@ -49,13 +56,47 @@ class UserController extends CommonController if($request->input('password', null)!==null){$data['password'] = $request->input('password');} if($request->input('head_img', null)!==null){$data['head_img'] = $request->input('head_img');} - if ($data != '') + if (isset($data)) { - User::modify(['id'=>Token::$uid],$data); + User::modify(array('id'=>Token::$uid),$data); } return ReturnData::create(ReturnData::SUCCESS); } + + //修改用户密码、支付密码 + public function userPasswordUpdate(Request $request) + { + if($request->input('password', '')!='' && $request->input('old_password', '')!='') + { + $data['password'] = $request->input('password'); + $data['old_password'] = $request->input('old_password'); + + if($data['password'] == $data['old_password']){return ReturnData::create(ReturnData::PARAMS_ERROR,null,'新旧密码相同');} + } + + if($request->input('pay_password', '')!='') + { + $data['pay_password'] = $request->input('pay_password'); + $data['old_pay_password'] = $request->input('old_pay_password',''); + + if($data['pay_password'] == $data['old_pay_password']){return ReturnData::create(ReturnData::PARAMS_ERROR,null,'新旧密码相同');} + } + + if (isset($data)) + { + $res = User::userPasswordUpdate(array('id'=>Token::$uid),$data); + + if($res === false) + { + return ReturnData::create(ReturnData::SYSTEM_FAIL,null,$res); + } + + return ReturnData::create(ReturnData::SUCCESS); + } + + return ReturnData::create(ReturnData::PARAMS_ERROR); + } //用户列表 public function userList(Request $request) diff --git a/app/Http/Model/User.php b/app/Http/Model/User.php index fad8ab2..521d03b 100644 --- a/app/Http/Model/User.php +++ b/app/Http/Model/User.php @@ -128,14 +128,46 @@ class User extends BaseModel } //获取用户信息 - public static function getUserInfo($user_id) + public static function getUserInfo($user_id) { $user = self::where('id', $user_id)->first(); if(!$user){return false;} $user->reciever_address = UserAddress::getOne($user->address_id); $user->collect_goods_count = CollectGoods::where('user_id', $user_id)->count(); - - return $user; + + $userinfo = $user->makeVisible(array('pay_password'))->toArray(); + $user->pay_password = 0; + if($userinfo['pay_password']){$user->pay_password = 1;} + + return $user; + } + + //修改用户密码、支付密码 + public static function userPasswordUpdate($where,array $param) + { + extract($param); + $data = ''; + + $user = self::where($where)->first(); + if(!$user){return false;} + + $user = $user->makeVisible(array('password','pay_password'))->toArray(); + + if(isset($old_password) && $old_password!=$user['password']){return false;} //旧密码错误 + if(isset($password) && $password==''){return false;} //新密码为空 + + if(isset($old_pay_password) && $old_pay_password!=$user['pay_password']){return false;} + if(isset($pay_password) && $pay_password==''){return false;} + + if(isset($password)){$data['password'] = $password;} + if(isset($pay_password)){$data['pay_password'] = $pay_password;} + + if ($data != '' && self::where($where)->update($data)) + { + return true; + } + + return false; } //注册 diff --git a/public/images/weixin/ad_tit.png b/public/images/weixin/ad_tit.png index 9ecc662..f492eaa 100644 Binary files a/public/images/weixin/ad_tit.png and b/public/images/weixin/ad_tit.png differ diff --git a/resources/views/weixin/user/userinfo.blade.php b/resources/views/weixin/user/userinfo.blade.php index dbc8e57..84ef829 100644 --- a/resources/views/weixin/user/userinfo.blade.php +++ b/resources/views/weixin/user/userinfo.blade.php @@ -22,7 +22,7 @@