|
@@ -218,35 +218,52 @@ class User extends Api
|
|
/**
|
|
/**
|
|
* 修改会员个人信息
|
|
* 修改会员个人信息
|
|
*
|
|
*
|
|
- * @param string $avatar 头像地址
|
|
|
|
|
|
+ * @ApiMethod (POST)
|
|
|
|
+ * @param string $avatar 头像地址
|
|
* @param string $username 用户名
|
|
* @param string $username 用户名
|
|
* @param string $nickname 昵称
|
|
* @param string $nickname 昵称
|
|
- * @param string $bio 个人简介
|
|
|
|
|
|
+ * @param string $bio 个人简介
|
|
*/
|
|
*/
|
|
public function profile()
|
|
public function profile()
|
|
{
|
|
{
|
|
- $user = $this->auth->getUser();
|
|
|
|
- $username = $this->request->request('username');
|
|
|
|
- $nickname = $this->request->request('nickname');
|
|
|
|
- $bio = $this->request->request('bio');
|
|
|
|
- $avatar = $this->request->request('avatar', '', 'trim,strip_tags,htmlspecialchars');
|
|
|
|
- if ($username) {
|
|
|
|
- $exists = \app\common\model\User::where('username', $username)->where('id', '<>', $this->auth->id)->find();
|
|
|
|
- if ($exists) {
|
|
|
|
- $this->error(__('Username already exists'));
|
|
|
|
|
|
+ $field_array = ['avatar','nickname','desc','age_id','gender','job_id','province_id','city_id','has_info'];
|
|
|
|
+
|
|
|
|
+ $data = [];
|
|
|
|
+ foreach($field_array as $key => $field){
|
|
|
|
+
|
|
|
|
+ //前端传不了post,改了
|
|
|
|
+ if(!request()->has($field,'post')){
|
|
|
|
+ continue;
|
|
}
|
|
}
|
|
- $user->username = $username;
|
|
|
|
- }
|
|
|
|
- if ($nickname) {
|
|
|
|
- $exists = \app\common\model\User::where('nickname', $nickname)->where('id', '<>', $this->auth->id)->find();
|
|
|
|
- if ($exists) {
|
|
|
|
- $this->error(__('Nickname already exists'));
|
|
|
|
|
|
+ /*if(!input('?'.$field)){
|
|
|
|
+ continue;
|
|
|
|
+ }*/
|
|
|
|
+
|
|
|
|
+ $newone = input($field);
|
|
|
|
+
|
|
|
|
+ if($field == 'avatar'){
|
|
|
|
+ $newone = input('avatar', '', 'trim,strip_tags,htmlspecialchars');
|
|
}
|
|
}
|
|
- $user->nickname = $nickname;
|
|
|
|
|
|
+
|
|
|
|
+ $data[$field] = $newone;
|
|
}
|
|
}
|
|
- $user->bio = $bio;
|
|
|
|
- $user->avatar = $avatar;
|
|
|
|
- $user->save();
|
|
|
|
|
|
+
|
|
|
|
+ if(empty($data)){
|
|
|
|
+ $this->error('没有任何改变');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /*if (!empty($data['nickname']) && !empty($data['avatar']) && !empty($data['age_id']) && $data['has_info']==0) {
|
|
|
|
+ $data['has_info'] = 1;
|
|
|
|
+ }*/
|
|
|
|
+
|
|
|
|
+ Db::startTrans();
|
|
|
|
+ $update_rs = Db::name('user')->where('id',$this->auth->id)->update($data);
|
|
|
|
+ if($update_rs === false){
|
|
|
|
+ Db::rollback();
|
|
|
|
+ $this->error('修改资料失败');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Db::commit();
|
|
$this->success();
|
|
$this->success();
|
|
}
|
|
}
|
|
|
|
|