app_id)->where('user_id', $data['userId'])->first(); if ($user) { throw new BusinessException('用户已存在'); } $emial = $data['email']; $memberId = $this->generateMemberId($app->app_id, $data['userId']); $baofu = new Baofu(); $url = $baofu->apply($memberId, $emial, $token); return $url; } public function register(array $data, App $app, string $token) { $user = User::where('app_id', $app->app_id)->where('user_id', $data['userId'])->first(); if ($user) { throw new BusinessException('用户已存在'); } $memberId = $this->generateMemberId($app->app_id, $data['userId']); $baofu = new Baofu(); $url = $baofu->register($memberId, $token); return $url; } public function rsyncUser($memberId, $appId, $userId) { $baofu = new Baofu(); $userInfo = $baofu->queryCustomerInfo($memberId); return $this->saveUser($userInfo, $appId, $userId); } public function saveUser($userInfo, $appId, $userId) { $memberId = $userInfo['loginNo'] ?? $userInfo['loginMobile']; $user = User::where('app_id', $appId)->where('member_id', $memberId)->first(); if ($user) { $user->contract_no = $userInfo['contractNo']; $user->realname_flag = $userInfo['realNameFlag'] ?? 'Y'; $user->bind_card_flag = $userInfo['bindCardFlag']; $user->set_pwd_flag = $userInfo['setPwdFlag']; $user->status = $userInfo['operatorStatus'] ?? $userInfo['status']; $user->email = $userInfo['email'] ?? ''; $user->mobile = $userInfo['mobile'] ?? ''; $user->real_name = $userInfo['customerName'] ?? ''; $user->certificate_no = $userInfo['certificateNo'] ?? ''; $user->user_type = $userInfo['customerType']; $user->apply_no = $userInfo['applyNo'] ?? ''; } else { $user = new User(); $user->user_id = $userId; $user->app_id = $appId; $user->member_id = $memberId; $user->contract_no = $userInfo['contractNo']; $user->realname_flag = $userInfo['realNameFlag'] ?? 'Y'; $user->bind_card_flag = $userInfo['bindCardFlag']; $user->set_pwd_flag = $userInfo['setPwdFlag']; $user->status = $userInfo['operatorStatus'] ?: $userInfo['status']; $user->email = $userInfo['email'] ?? ''; $user->mobile = $userInfo['mobile'] ?? ''; $user->real_name = $userInfo['customerName'] ?? ''; $user->certificate_no = $userInfo['certificateNo'] ?? ''; $user->user_type = $userInfo['customerType']; $user->apply_no = $userInfo['applyNo'] ?? ''; } $user->save(); return $user; } public function rsyncBankCards($memberId) { $user = User::where('member_id', $memberId)->first(); if (empty($user)) { throw new BusinessException('用户不存在'); } $baofu = new Baofu(); $bankCards = $baofu->findBindBankCards([ 'loginNo' => $memberId, 'contractNo' => $user->contract_no, ]); foreach ($bankCards as $bankCard) { $this->saveBankCard($bankCard, $user); } } public function saveBankCard(array $data, User $user) { $appId = $user->app_id; $userId = $user->user_id; $bankCard = BankCard::where('app_id', $appId) ->where('member_id', $user->member_id) ->where('agreement_no', $data['agreementNo']) ->first(); if ($bankCard) { $bankCard->agreement_no = $data['agreementNo']; $bankCard->card_user_name = $data['cardUserName']; $bankCard->last_card_no = $data['lastCardNo']; $bankCard->bank_mobile = $data['bankMobile'] ?: ''; $bankCard->bank_code = $data['bankCode']; $bankCard->bank_name = $data['bankName']; $bankCard->card_type = $data['cardType']; $bankCard->cnaps_code = $data['cnapsCode'] ?: ''; $bankCard->public_flag = $data['publicFlag']; $bankCard->repayment_date = $data['repaymentDate'] ?: ''; $bankCard->main_flag = $data['mainFlag']; $bankCard->status = $data['status']; $bankCard->ava_flag = $data['avaFlag'] ?: ''; $bankCard->remark = $data['remark'] ?: ''; } else { $bankCard = new BankCard(); $bankCard->app_id = $appId; $bankCard->user_id = $userId; $bankCard->member_id = $user->member_id; $bankCard->agreement_no = $data['agreementNo']; $bankCard->card_user_name = $data['cardUserName']; $bankCard->last_card_no = $data['lastCardNo']; $bankCard->bank_mobile = $data['bankMobile'] ?: ''; $bankCard->bank_code = $data['bankCode']; $bankCard->bank_name = $data['bankName']; $bankCard->card_type = $data['cardType']; $bankCard->cnaps_code = $data['cnapsCode'] ?: ''; $bankCard->public_flag = $data['publicFlag']; $bankCard->repayment_date = $data['repaymentDate'] ?: ''; $bankCard->main_flag = $data['mainFlag']; $bankCard->status = $data['status']; $bankCard->ava_flag = $data['avaFlag'] ?: ''; $bankCard->remark = $data['remark'] ?: ''; } $bankCard->save(); return $bankCard; } public function generateMemberId($appId, $userId) { return md5($appId . '-' . $userId); } public function bindCard(array $data, App $app, string $token) { $user = User::where('app_id', $app->app_id)->where('user_id', $data['userId'])->first(); if (empty($user)) { throw new BusinessException('用户不存在'); } $baofu = new Baofu(); $url = $baofu->cardBind($user->member_id, $token); return $url; } public function unbindCard(array $data, App $app) { $user = User::where('app_id', $app->app_id)->where('user_id', $data['userId'])->first(); if (empty($user)) { throw new BusinessException('用户不存在'); } $baofu = new Baofu(); $result = $baofu->cardUnbind($user->member_id, $data['agreementNo']); if ($result && $result != 'false') { $this->rsyncBankCards($user->member_id) ; return true; } return false; } public function pwdForget(array $data, App $app, $token) { $user = User::where('app_id', $app->app_id)->where('user_id', $data['userId'])->first(); if (empty($user)) { throw new BusinessException('用户不存在'); } $baofu = new Baofu(); return $baofu->pwdForget($user->member_id, $token); } public function pwdModify(array $data, App $app, $token) { $user = User::where('app_id', $app->app_id)->where('user_id', $data['userId'])->first(); if (empty($user)) { throw new BusinessException('用户不存在'); } $baofu = new Baofu(); return $baofu->pwdModify($user->member_id, $token); } }