middleware[SessionInit::class] = [ 'only' => ['accountLogin', 'getCaptcha'] ]; } /** * 客户账号登录/注册接口 * * @param Request $request * @return array * @date 2023-07-07 * @author xjh * @since 1.0.0 */ public function accountLoginRegister(Request $request): array { Db::startTrans(); try { $params = Validate::param([ 'customer_email|客户邮箱' => 'require|email', 'customer_password|客户密码' => 'require|alphaNum|min:8', // 'captcha|验证码' => $request->isProd() ? 'require|captcha' : false ]); $customer = ModelCustomer::where('customer_email', $params['customer_email'])->find(); $token = null; //登录 if ($customer) { $token = LogicCustomerLogin::accountLogin($params); } //注册 else { $token = LogicCustomerLogin::accountRegistration($params); } Db::commit(); return [ 'code' => 0, 'data' => [ 'token' => $token->token_content, 'exp_time' => $token->token_exp_time, ], 'msg' => $customer ? '登录成功!' : '注册成功!' ]; } catch (\Throwable $th) { Db::rollback(); throw $th; } } /** * 客户登出接口 * * @param Request $request * @return array * @date 2023-06-25 * @author xjh * @since 1.0.0 */ public function logout(Request $request): array { ModelToken::logout(); return msg('登出成功'); } /** * 生成验证码 * * @date 2023-06-25 * @author xjh * @since 1.0.0 */ public function getCaptcha() { return Captcha::create(); } }