1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- namespace App\Traits;
- use App\Http\Api\Forms\LoginMobileForm;
- use App\Services\LoginService;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Request;
- /**
- * 手机号快捷登录
- *
- * Trait MobileLoginTrait
- * @package App\Traits
- */
- trait MobileLoginTrait
- {
- /**
- * 是否开启登录日志记录
- *
- * @var bool
- */
- private $is_open_login_log = false;
- public function loginInMobile()
- {
- $formHandler = new LoginMobileForm();
- $authorize = $formHandler->authorize(Request::all());
- if ($authorize) {
- return response()->json(['result' => false, 'code' => 2001, 'msg' => $authorize[0] ?? '']);
- }
- $data = $formHandler->getData();
- //判断手机号是否正确和存在
- $resultObj = DB::table('users')->where('store_id', $this->storeId)->where('mobile', $data['mobile'])->first();
- if ($resultObj) {
- $result = get_object_vars($resultObj);
- //设置登录状态
- $loginService = new LoginService($this->siteAliasName);
- $loginService->setLoginCookie($result);
- unset($result['password']);
- unset($result['wx_info']);
- unset($result['wx_openid']);
- $msg = array('result' => true, 'code' => 1001, 'msg' => '登录成功', 'data' => $result);
- } else {
- $msg = array('result' => false, 'code' => 2006, 'msg' => '帐号不存在,请先注册!');
- }
- return response()->json($msg);
- }
- }
|