...
|
...
|
@@ -8,6 +8,7 @@ use app\common\library\Sms; |
|
|
use fast\Http;
|
|
|
use fast\Random;
|
|
|
use think\Config;
|
|
|
use think\Db;
|
|
|
use think\Validate;
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -15,7 +16,7 @@ use think\Validate; |
|
|
*/
|
|
|
class User extends Api
|
|
|
{
|
|
|
protected $noNeedLogin = ['login', 'mobilelogin', 'register', 'resetpwd', 'changeemail', 'changemobile', 'third'];
|
|
|
protected $noNeedLogin = ['third'];
|
|
|
protected $noNeedRight = '*';
|
|
|
|
|
|
public function _initialize()
|
...
|
...
|
@@ -30,23 +31,28 @@ class User extends Api |
|
|
|
|
|
/**
|
|
|
* 会员中心
|
|
|
* @ApiReturn (
|
|
|
* data:{
|
|
|
* nickname 昵称
|
|
|
* avatar 头像
|
|
|
* pay 待支付
|
|
|
* wait_send 待发货
|
|
|
* wait_collect 待收货
|
|
|
* wait_comment 待评价
|
|
|
* }
|
|
|
* )
|
|
|
*/
|
|
|
public function index()
|
|
|
{
|
|
|
$this->success('', ['welcome' => $this->auth->nickname]);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 退出登录
|
|
|
* @ApiMethod (POST)
|
|
|
*/
|
|
|
public function logout()
|
|
|
{
|
|
|
if (!$this->request->isPost()) {
|
|
|
$this->error(__('Invalid parameters'));
|
|
|
}
|
|
|
$this->auth->logout();
|
|
|
$this->success(__('Logout successful'));
|
|
|
$data = [];
|
|
|
$data['nickname'] = $this->auth->nickname;
|
|
|
$data['avatar'] = cdnurl($this->auth->avatar,true);
|
|
|
$data['mobile'] = $this->auth->mobile;
|
|
|
$data['pay'] = Db::name('litestore_order')->where('user_id',$this->auth->id)->where('pay_status','10')->count();
|
|
|
$data['wait_send'] = Db::name('litestore_order')->where('user_id',$this->auth->id)->where('freight_status','10')->count();
|
|
|
$data['wait_collect'] = Db::name('litestore_order')->where('user_id',$this->auth->id)->where('receipt_status','10')->count();
|
|
|
$data['wait_comment'] = Db::name('litestore_order')->where('user_id',$this->auth->id)->where('receipt_status','20')->count();
|
|
|
$this->success('会员中心', ['welcome' => $this->auth->nickname]);
|
|
|
}
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -54,106 +60,28 @@ class User extends Api |
|
|
*
|
|
|
* @ApiMethod (POST)
|
|
|
* @param string $avatar 头像地址
|
|
|
* @param string $username 用户名
|
|
|
* @param string $mobile 联系方式
|
|
|
* @param string $nickname 昵称
|
|
|
* @param string $bio 个人简介
|
|
|
*/
|
|
|
public function profile()
|
|
|
{
|
|
|
$user = $this->auth->getUser();
|
|
|
$username = $this->request->post('username');
|
|
|
$mobile = $this->request->post('mobile');
|
|
|
$nickname = $this->request->post('nickname');
|
|
|
$bio = $this->request->post('bio');
|
|
|
$avatar = $this->request->post('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'));
|
|
|
}
|
|
|
$user->username = $username;
|
|
|
if ($mobile) {
|
|
|
$user->mobile = $mobile;
|
|
|
}
|
|
|
if ($nickname) {
|
|
|
$exists = \app\common\model\User::where('nickname', $nickname)->where('id', '<>', $this->auth->id)->find();
|
|
|
if ($exists) {
|
|
|
$this->error(__('Nickname already exists'));
|
|
|
}
|
|
|
$user->nickname = $nickname;
|
|
|
}
|
|
|
$user->bio = $bio;
|
|
|
$user->avatar = $avatar;
|
|
|
$user->save();
|
|
|
$this->success();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 修改邮箱
|
|
|
*
|
|
|
* @ApiMethod (POST)
|
|
|
* @param string $email 邮箱
|
|
|
* @param string $captcha 验证码
|
|
|
*/
|
|
|
public function changeemail()
|
|
|
{
|
|
|
$user = $this->auth->getUser();
|
|
|
$email = $this->request->post('email');
|
|
|
$captcha = $this->request->post('captcha');
|
|
|
if (!$email || !$captcha) {
|
|
|
$this->error(__('Invalid parameters'));
|
|
|
if ($avatar) {
|
|
|
$user->avatar = $avatar;
|
|
|
}
|
|
|
if (!Validate::is($email, "email")) {
|
|
|
$this->error(__('Email is incorrect'));
|
|
|
}
|
|
|
if (\app\common\model\User::where('email', $email)->where('id', '<>', $user->id)->find()) {
|
|
|
$this->error(__('Email already exists'));
|
|
|
}
|
|
|
$result = Ems::check($email, $captcha, 'changeemail');
|
|
|
if (!$result) {
|
|
|
$this->error(__('Captcha is incorrect'));
|
|
|
}
|
|
|
$verification = $user->verification;
|
|
|
$verification->email = 1;
|
|
|
$user->verification = $verification;
|
|
|
$user->email = $email;
|
|
|
$user->save();
|
|
|
|
|
|
Ems::flush($email, 'changeemail');
|
|
|
$this->success();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 修改手机号
|
|
|
*
|
|
|
* @ApiMethod (POST)
|
|
|
* @param string $mobile 手机号
|
|
|
* @param string $captcha 验证码
|
|
|
*/
|
|
|
public function changemobile()
|
|
|
{
|
|
|
$user = $this->auth->getUser();
|
|
|
$mobile = $this->request->post('mobile');
|
|
|
$captcha = $this->request->post('captcha');
|
|
|
if (!$mobile || !$captcha) {
|
|
|
$this->error(__('Invalid parameters'));
|
|
|
}
|
|
|
if (!Validate::regex($mobile, "^1\d{10}$")) {
|
|
|
$this->error(__('Mobile is incorrect'));
|
|
|
}
|
|
|
if (\app\common\model\User::where('mobile', $mobile)->where('id', '<>', $user->id)->find()) {
|
|
|
$this->error(__('Mobile already exists'));
|
|
|
}
|
|
|
$result = Sms::check($mobile, $captcha, 'changemobile');
|
|
|
if (!$result) {
|
|
|
$this->error(__('Captcha is incorrect'));
|
|
|
}
|
|
|
$verification = $user->verification;
|
|
|
$verification->mobile = 1;
|
|
|
$user->verification = $verification;
|
|
|
$user->mobile = $mobile;
|
|
|
$user->save();
|
|
|
|
|
|
Sms::flush($mobile, 'changemobile');
|
|
|
$this->success();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 第三方登录
|
...
|
...
|
|