You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
159 lines
5.8 KiB
159 lines
5.8 KiB
<?php |
|
|
|
|
|
namespace app\api\controller; |
|
|
|
use app\common\controller\Api; |
|
use app\common\ResponseJson; |
|
use sdModule\common\Sc; |
|
use think\exception\ValidateException; |
|
|
|
class Member extends Api |
|
{ |
|
|
|
/** |
|
* @return \think\response\Json |
|
* @author Deng |
|
* @date 2021-01-13 19:55 |
|
* 个人中心 |
|
*/ |
|
public function getMember(){ |
|
$member = \app\api\model\Member::getMember(); |
|
if(!$member){ |
|
return ResponseJson::fail('用户不存在或者尚未注册'); |
|
} |
|
if($member['status']==0){ |
|
return ResponseJson::fail('您被限制登录,请联系管理员'); |
|
} |
|
return ResponseJson::success($member); |
|
} |
|
|
|
/** |
|
* @param \app\api\model\Member $member |
|
* @param $page |
|
* @param $limit |
|
* @param int $member_id |
|
* @return \think\response\Json |
|
* @author Deng |
|
* @date 2020-12-23 9:31 |
|
* 关注项目 |
|
*/ |
|
public function getMyCollectList(\app\api\model\Member $member,$page,$limit,$type=1){ |
|
$member_info = \app\api\model\Member::getMember(); |
|
if(!$member_info){ |
|
return ResponseJson::fail('用户不存在或者尚未注册'); |
|
} |
|
if($member_info['status']==0){ |
|
return ResponseJson::fail('您被限制登录,请联系管理员'); |
|
} |
|
return ResponseJson::success($member->getMyCollectList($page,$limit,$member_info['id'],$type)); |
|
} |
|
|
|
/** |
|
* @param \app\api\model\Member $member |
|
* @param $page |
|
* @param $limit |
|
* @param int $member_id |
|
* @return \think\response\Json |
|
* @author Deng |
|
* @date 2020-12-23 9:59 |
|
* 我的消息 |
|
*/ |
|
public function getMyNotice(\app\api\model\Member $member,$page,$limit){ |
|
$member_info = \app\api\model\Member::getMember(); |
|
if(!$member_info){ |
|
return ResponseJson::fail('用户不存在或者尚未注册'); |
|
} |
|
if($member_info['status']==0){ |
|
return ResponseJson::fail('您被限制登录,请联系管理员'); |
|
} |
|
return ResponseJson::success($member->getMyNotice($page,$limit,$member_info['id'])); |
|
} |
|
|
|
/** |
|
* @author Deng |
|
* @date 2020-12-23 10:18 |
|
*/ |
|
public function UpMyInfo(\app\api\model\Member $member){ |
|
$getPost = $this->request->post(); |
|
$member_info = \app\api\model\Member::getMember(); |
|
if(!$member_info){ |
|
return ResponseJson::fail('用户不存在或者尚未注册'); |
|
} |
|
if($member_info['status']==0){ |
|
return ResponseJson::fail('您被限制登录,请联系管理员'); |
|
} |
|
unset($getPost['member_id'],$getPost['v']); |
|
$getPost['update_time'] = date('Y-m-d H:i:s'); |
|
$result = $member->where(['id'=>$member_info['id']])->update($getPost); |
|
return $result ? ResponseJson::success('','修改成功') : ResponseJson::fail('修改失败'); |
|
} |
|
|
|
|
|
/** |
|
* @param \app\api\model\Member $member |
|
* @return \think\response\Json |
|
* @throws \think\db\exception\DataNotFoundException |
|
* @throws \think\db\exception\DbException |
|
* @throws \think\db\exception\ModelNotFoundException |
|
* @author Deng |
|
* @date 2021-01-11 9:58 |
|
* 验证密保 |
|
*/ |
|
public function verifySecurity(\app\api\model\Member $member){ |
|
$getPost = $this->request->post(); |
|
$member_id = request()->middleware('token.member_id'); |
|
if($member_id){//修改密码 |
|
$userData = $member->where(['delete_time'=>0,'id'=>$member_id])->find()->toArray(); |
|
if($userData){ |
|
if($userData['security_question'] == $getPost['security_question'] && $userData['security_answer'] == $getPost['security_answer']){ |
|
return ResponseJson::success('','验证成功'); |
|
}else{ |
|
return ResponseJson::fail('密保问题或者回答有误'); |
|
} |
|
}else{ |
|
return ResponseJson::fail('尚未注册'); |
|
} |
|
}else{//找回密码 |
|
$userData = $member->where(['delete_time'=>0,'mobile'=>$getPost['mobile']])->find()->toArray(); |
|
if($userData['security_question'] == $getPost['security_question'] && $userData['security_answer'] == $getPost['security_answer'] && $userData['mobile'] == $getPost['mobile']){ |
|
return ResponseJson::success('','验证成功'); |
|
}else{ |
|
return ResponseJson::fail('密保问题或者回答有误'); |
|
} |
|
} |
|
} |
|
/** |
|
* @param \app\api\model\Member $member |
|
* @return \think\response\Json |
|
* @throws \think\db\exception\DataNotFoundException |
|
* @throws \think\db\exception\DbException |
|
* @throws \think\db\exception\ModelNotFoundException |
|
* @author Deng |
|
* @date 2021-01-11 9:45 |
|
* 修改密码 |
|
*/ |
|
public function editPassword(\app\api\model\Member $member){ |
|
$getPost = $this->request->post(); |
|
$user_id = request()->middleware('token.member_id'); |
|
$userData = $member->where('id',$user_id)->find()->toArray(); |
|
if($userData){ |
|
/* if(isset($getPost['old_password']) && !empty($getPost['old_password'])){ |
|
if(!Sc::password()->verify($getPost['old_password'], $userData['password'])){ |
|
return ResponseJson::fail('旧密码输入错误'); |
|
} |
|
}*/ |
|
try{ |
|
Validate(\app\api\validate\Member::class)->scene('edit_password')->check($getPost); |
|
}catch (ValidateException $e){ |
|
return ResponseJson::fail($e->getError()); |
|
} |
|
$result = $member->where('id',$user_id)->update([ |
|
'password' => SC::password()->encryption($getPost['password']) |
|
]); |
|
return $result ? ResponseJson::success($result) : ResponseJson::fail('修改密码失败'); |
|
}else{ |
|
return ResponseJson::fail('用户尚未注册'); |
|
} |
|
} |
|
} |