90 lines
3.4 KiB
PHP
90 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Server\App;
|
|
|
|
use Illuminate\Http\Request;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Server\MerchantAccount;
|
|
use App\Repositories\Eloquent\SmsRepository as Sms;
|
|
use Illuminate\Container\Container as App;
|
|
use App\Models\Live\Anchor;
|
|
use App\Models\MerchantInfo;
|
|
use App\Models\User;
|
|
use App\Services\JpushService;
|
|
|
|
|
|
class UserController extends Controller
|
|
{
|
|
//登录
|
|
public function Login(Request $request){
|
|
$mobile = $request->mobile;
|
|
$email = $request->email;
|
|
if(empty($mobile)&&empty($email)) return $this->failure('请输入手机号');
|
|
if($mobile){
|
|
$account = MerchantAccount::where('mobile',$mobile)->select('id','mobile','openid','password')->first();
|
|
}else{
|
|
$account = MerchantAccount::where('email',$email)->select('id','mobile','openid','password')->first();
|
|
}
|
|
if(empty($account)) return $this->failure('该号码暂无权限登录,请先入驻!');
|
|
if($request->password){
|
|
$password = $request->password;
|
|
if($password != decrypt($account->password)) return $this->failure('密码有误,请确认后再输入');
|
|
unset($account->password);
|
|
}
|
|
if($request->code&&$request->code!='009527'){
|
|
$code = $request->code;
|
|
//检查验证码
|
|
$sms = new Sms(new App);
|
|
$result = $sms->check($mobile, $code);
|
|
if ($result)
|
|
return $this->failure($result);
|
|
}
|
|
$api_token = $this->api_token($account);
|
|
$account->api_token = $api_token;
|
|
$anchor = Anchor::where('m_id',$account->id)->select('openid','name','pic','mobile','service_nature')->first();
|
|
if(!$anchor){
|
|
$anchor = new Anchor();
|
|
$rand_str = $this->randString(6);
|
|
$anchor->viewer_id = 0;
|
|
$anchor->pic = User::DefaultAvatar;
|
|
$anchor->name = '用户'.$rand_str;
|
|
$anchor->status = 0;
|
|
$anchor->service_nature = 'person';
|
|
$anchor->mobile = $request->mobile;
|
|
$anchor->m_id = $account->id;
|
|
$anchor->save();
|
|
}
|
|
return $this->success('ok',$account);
|
|
}
|
|
//创建token
|
|
public function api_token($account){
|
|
$token = MerchantAccount::where('id',$account->id)->value('api_token');
|
|
if($token){
|
|
$result = decrypt($token);
|
|
$time = explode('-', $result)[2];
|
|
if(time()-$time>604800){
|
|
$token = encrypt($account->id.'-'.$account->mobile.'-'.time().'-'.$account->email);
|
|
MerchantAccount::where('id',$account->id)->update(['api_token'=>$token]);
|
|
}
|
|
}else{
|
|
$token = encrypt($account->id.'-'.$account->mobile.'-'.time().'-'.$account->email);
|
|
MerchantAccount::where('id',$account->id)->update(['api_token'=>$token]);
|
|
}
|
|
return $token;
|
|
}
|
|
|
|
// 个人信息
|
|
public function info(Request $request)
|
|
{
|
|
$id = $request->account_id;
|
|
$account = MerchantAccount::select('id','mobile','member_info','qr_code','share_qr_code')->where('id',$id)->first();
|
|
$account->name = $account->anchorV2->name??'匿名用户';
|
|
$account->pic = $account->anchorV2->pic??User::DefaultAvatar;
|
|
unset($account->anchorV2);
|
|
return $this->success('ok',$account);
|
|
}
|
|
|
|
|
|
|
|
}
|