|
|
@@ -17,7 +17,7 @@ class LakalaAccountService
|
|
|
{
|
|
|
const RATE = '0.33';
|
|
|
const MCC = '5992';
|
|
|
- const ACTIVITY_ID = '37';
|
|
|
+ const ACTIVITY_ID = '208';
|
|
|
|
|
|
public static function list($mainId, $shopId)
|
|
|
{
|
|
|
@@ -29,11 +29,18 @@ class LakalaAccountService
|
|
|
$accounts = LakalaAccountClass::getAllByCondition(
|
|
|
['mainId' => $mainId, 'shopId' => $shopId],
|
|
|
['isCurrent' => SORT_DESC, 'id' => SORT_DESC],
|
|
|
- '*'
|
|
|
+ '*', null, true
|
|
|
);
|
|
|
foreach ($applications as &$application) {
|
|
|
$application['formData'] = self::decode($application['formData'] ?? '');
|
|
|
}
|
|
|
+ foreach ($accounts as &$account) {
|
|
|
+ if ($account['wxAuthorizeState'] == 1 && $account['zfbAuthorizeState'] == 1) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ self::refreshAuthorizeStates($account);
|
|
|
+ }
|
|
|
+
|
|
|
return ['applications' => $applications, 'accounts' => $accounts];
|
|
|
}
|
|
|
|
|
|
@@ -75,7 +82,7 @@ class LakalaAccountService
|
|
|
public static function saveDraft($id, $mainId, $shopId, array $form, $step)
|
|
|
{
|
|
|
$application = self::application($id, $mainId, $shopId, true);
|
|
|
- if (!in_array($application->status, [LakalaApplicationClass::STATUS_DRAFT, LakalaApplicationClass::STATUS_REJECT], true)) {
|
|
|
+ if (!in_array($application->status, [LakalaApplicationClass::STATUS_DRAFT, LakalaApplicationClass::STATUS_REJECT, LakalaApplicationClass::STATUS_CONTRACT_PENDING], true)) {
|
|
|
util::fail('当前申请不能修改');
|
|
|
}
|
|
|
$application->formData = self::encode($form);
|
|
|
@@ -211,6 +218,7 @@ class LakalaAccountService
|
|
|
if (empty($application->customerNo) && empty($application->merchantNo)) {
|
|
|
util::fail('申请尚未提交');
|
|
|
}
|
|
|
+
|
|
|
$client = new LakalaOnboardingClient();
|
|
|
$response = $client->query('/api/v3/tkbs/open_merchant_info', [
|
|
|
'customer_no' => $application->customerNo,
|
|
|
@@ -221,7 +229,6 @@ class LakalaAccountService
|
|
|
$application->status = LakalaApplicationClass::STATUS_REJECT;
|
|
|
$application->rejectReason = $customer['audit_remark'] ?? '拉卡拉审核驳回';
|
|
|
} elseif (in_array($status, ['OPEN', 'ACTIVITY'], true)) {
|
|
|
- $application->status = LakalaApplicationClass::STATUS_APPROVED;
|
|
|
$application->merchantNo = $customer['merchant_no'] ?? $application->merchantNo;
|
|
|
$application->customerNo = $customer['customer_no'] ?? $application->customerNo;
|
|
|
$shopInfo = $response['data']['shop_info_list'][0] ?? [];
|
|
|
@@ -229,6 +236,9 @@ class LakalaAccountService
|
|
|
$account = self::upsertAccount($application, $response['data']);
|
|
|
self::ensureTermOperations($application, $account, $client);
|
|
|
self::syncTerms($application, $account, $client);
|
|
|
+ if ($account->scanTermNo != '' && $account->b2bTermNo != '') {
|
|
|
+ $application->status = LakalaApplicationClass::STATUS_APPROVED;
|
|
|
+ }
|
|
|
} else {
|
|
|
$application->status = LakalaApplicationClass::STATUS_WAIT_AUDIT;
|
|
|
}
|
|
|
@@ -322,7 +332,7 @@ class LakalaAccountService
|
|
|
|
|
|
private static function ensureTermOperations($application, $account, $client)
|
|
|
{
|
|
|
- foreach (['WECHAT_PAY', 'B2B_SYT'] as $bizType) { // 'B2B_SYT' -- 聚合收银台已经有了,不需要额外创建
|
|
|
+ foreach (['B2B_SYT'] as $bizType) { // 'WECHAT_PAY' -- 专业化扫码已经有了,不需要额外创建
|
|
|
$operation = LakalaOperationClass::getByCondition([
|
|
|
'applicationId' => $application->id,
|
|
|
'operationType' => 'add_term',
|
|
|
@@ -382,16 +392,52 @@ class LakalaAccountService
|
|
|
$application->merchantNo = $merchantNo;
|
|
|
$account->merchantNo = $merchantNo;
|
|
|
}
|
|
|
- $account->scanTermNo = $terms['scanTermNo'][0];
|
|
|
- $account->b2bTermNo = $terms['b2BTermNo'][0];
|
|
|
+ $account->scanTermNo = $terms['scanTermNo'][0] ?? $account->scanTermNo;
|
|
|
+ $account->b2bTermNo = $terms['b2BTermNo'][0] ?? $account->b2bTermNo;
|
|
|
$account->updateTime = date('Y-m-d H:i:s');
|
|
|
$account->save();
|
|
|
$application->save();
|
|
|
+ self::refreshAuthorizeStates($account);
|
|
|
} catch (\Throwable $e) {
|
|
|
Yii::warning('Unable to sync Lakala merchant info terms: ' . $e->getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private static function refreshAuthorizeStates(&$account)
|
|
|
+ {
|
|
|
+ $merchantNo = $account['merchantNo'] ?? '';
|
|
|
+ $scanTermNo = $account['scanTermNo'] ?? '';
|
|
|
+ $b2bTermNo = $account['b2bTermNo'] ?? '';
|
|
|
+ if ($merchantNo === '' || $scanTermNo === '' || $b2bTermNo === '') {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ $client = new LakalaOnboardingClient();
|
|
|
+ $wxState = self::authorizeState($client, $merchantNo, 'WXZF');
|
|
|
+ $zfbState = self::authorizeState($client, $merchantNo, 'ZFBZF');
|
|
|
+ $account->wxAuthorizeState = $wxState;
|
|
|
+ $account->zfbAuthorizeState = $zfbState;
|
|
|
+ $account->updateTime = date('Y-m-d H:i:s');
|
|
|
+ $account->save();
|
|
|
+ } catch (\Throwable $e) {
|
|
|
+ Yii::warning('Unable to refresh Lakala authorize state: ' . $e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static function authorizeState($client, $merchantNo, $registerType)
|
|
|
+ {
|
|
|
+ $response = $client->query('/api/v3/tkbs/open_merchant_register_status_query', [
|
|
|
+ 'merchant_no' => $merchantNo,
|
|
|
+ 'register_type' => $registerType,
|
|
|
+ ], 'both');
|
|
|
+ $data = $response['data'] ?? [];
|
|
|
+ if (isset($data['authorize_state']) && $data['authorize_state'] == '') { // TODO 根据实际情况进行补充
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
private static function upsertAccount($application, array $remote)
|
|
|
{
|
|
|
$account = LakalaAccountClass::getByCondition(['mainId' => $application->mainId, 'merchantNo' => $application->merchantNo], true);
|
|
|
@@ -412,6 +458,8 @@ class LakalaAccountService
|
|
|
'accountType' => $settlement['accountType'] ?? '58',
|
|
|
'licenseName' => $license['licenseName'] ?? ($license['legalName'] ?? ''),
|
|
|
'identityExpire' => $license['legalIdEnd'] ?? '',
|
|
|
+ 'wxAuthorizeState' => $account->wxAuthorizeState ?? 0,
|
|
|
+ 'zfbAuthorizeState' => $account->zfbAuthorizeState ?? 0,
|
|
|
'status' => 'ACTIVE',
|
|
|
'updateTime' => date('Y-m-d H:i:s'),
|
|
|
];
|
|
|
@@ -423,6 +471,7 @@ class LakalaAccountService
|
|
|
$account->$key = $value;
|
|
|
}
|
|
|
$account->save();
|
|
|
+
|
|
|
return $account;
|
|
|
}
|
|
|
|
|
|
@@ -468,6 +517,7 @@ class LakalaAccountService
|
|
|
$m = $form['merchant'];
|
|
|
$s = $form['settlement'];
|
|
|
$shop = $form['shop'];
|
|
|
+ $fees = self::merchantFees();
|
|
|
|
|
|
return [
|
|
|
'org_code' => $client->orgCode(),
|
|
|
@@ -503,7 +553,7 @@ class LakalaAccountService
|
|
|
'account_id_dt_start' => $s['accountIdStart'] ?: $l['legalIdStart'],
|
|
|
'account_id_dt_end' => $s['accountIdEnd'] ?: $l['legalIdEnd'],
|
|
|
'settle_type' => 'D1', 'settlement_type' => 'AUTOMATIC', 'contract_no' => $contractNo,
|
|
|
- 'biz_content' => ['term_num' => '1', 'mcc' => self::MCC, 'activity_id' => self::activityId(), 'fees' => self::merchantFees()],
|
|
|
+ 'biz_content' => ['term_num' => '1', 'mcc' => self::MCC, 'activity_id' => self::activityId(), 'fees' => $fees],
|
|
|
'attchments' => self::attachments($form),
|
|
|
];
|
|
|
}
|
|
|
@@ -589,13 +639,13 @@ class LakalaAccountService
|
|
|
private static function merchantFees()
|
|
|
{
|
|
|
return [
|
|
|
- ['fee_code' => 'WECHAT', 'fee_value' => self::RATE],
|
|
|
- ['fee_code' => 'ALIPAY', 'fee_value' => self::RATE],
|
|
|
- ['fee_code' => 'SCAN_PAY', 'fee_value' => self::RATE],
|
|
|
- ['fee_code' => 'DEBIT_CARD', 'fee_value' => self::RATE, 'top_fee' => '20'],
|
|
|
- ['fee_code' => 'CREDIT_CARD', 'fee_value' => '0.60'],
|
|
|
- ['fee_code' => 'UNIONPAY_WALLET_DEBIT_FEE', 'fee_value' => self::RATE, 'top_fee' => '20'],
|
|
|
- ['fee_code' => 'UNIONPAY_WALLET_CREDIT_FEE', 'fee_value' => self::RATE],
|
|
|
+ ['fee_code' => 'WECHAT', 'fee_value' => self::RATE], //微信
|
|
|
+ ['fee_code' => 'ALIPAY', 'fee_value' => self::RATE], //支付宝
|
|
|
+ //['fee_code' => 'SCAN_PAY', 'fee_value' => self::RATE], //未知项
|
|
|
+ ['fee_code' => 'DEBIT_CARD', 'fee_value' => '0.50', 'top_fee' => '20'], //借记卡费率
|
|
|
+ ['fee_code' => 'CREDIT_CARD', 'fee_value' => '0.60'], //贷记卡费率
|
|
|
+ ['fee_code' => 'UNIONPAY_WALLET_DEBIT_FEE', 'fee_value' => self::RATE, 'top_fee' => '20'], //银联二维码借记卡
|
|
|
+ ['fee_code' => 'UNIONPAY_WALLET_CREDIT_FEE', 'fee_value' => '0.60'], //银联二维码贷记卡
|
|
|
];
|
|
|
}
|
|
|
|
|
|
@@ -607,8 +657,8 @@ class LakalaAccountService
|
|
|
private static function termFees()
|
|
|
{
|
|
|
return [
|
|
|
- ['fee' => (float)self::RATE, 'top_fee' => 20, 'fee_type' => 'DEBIT_CARD'],
|
|
|
- ['fee' => (float)self::RATE, 'fee_type' => 'CREDIT_CARD'],
|
|
|
+ ['fee' => 0.5, 'top_fee' => 20, 'fee_type' => 'DEBIT_CARD'],
|
|
|
+ ['fee' => 0.6, 'fee_type' => 'CREDIT_CARD'],
|
|
|
];
|
|
|
}
|
|
|
|
|
|
@@ -737,16 +787,16 @@ class LakalaAccountService
|
|
|
private static function merchantInfoTermMap($value)
|
|
|
{
|
|
|
$result = [];
|
|
|
- $terminalInfos = $value['terminal_info'];
|
|
|
- foreach($terminalInfos as $term) {
|
|
|
- if ($term['term_type_name'] == '专业化扫码') {
|
|
|
- $result['scanTermNo'][] = $term['active_no_vo_list'][0]['term_no'];
|
|
|
+ $terminalInfos = $value['terminal_info'] ?? [];
|
|
|
+ foreach ($terminalInfos as $term) {
|
|
|
+ if (($term['term_type_name'] ?? '') == '专业化扫码') {
|
|
|
+ $result['scanTermNo'][] = $term['active_no_vo_list'][0]['term_no'] ?? '';
|
|
|
}
|
|
|
- if ($term['term_type_name'] == '聚合收银台') {
|
|
|
- $list = $term['active_no_vo_list'];
|
|
|
- foreach($list as $item) {
|
|
|
- if ($item['busi_type_code'] == 'QR_CODE_CARD') {
|
|
|
- $result['b2BTermNo'][] = $item['term_no'];
|
|
|
+ if (($term['term_type_name'] ?? '') == '聚合收银台') {
|
|
|
+ $list = $term['active_no_vo_list'] ?? [];
|
|
|
+ foreach ($list as $item) {
|
|
|
+ if (($item['busi_type_code'] ?? '') == 'QR_CODE_CARD') {
|
|
|
+ $result['b2BTermNo'][] = $item['term_no'] ?? '';
|
|
|
}
|
|
|
}
|
|
|
}
|