Explorar el Código

Merge branch 'zhongqi-lakala-jingjian' into dev

shizhongqi hace 2 meses
padre
commit
c6551a062e

+ 70 - 44
app-ghs/controllers/LakalaAccountController.php

@@ -2,9 +2,15 @@
 
 
 namespace ghs\controllers;
 namespace ghs\controllers;
 
 
-use bizGhs\lakala\classes\LakalaApplicationClass;
 use bizGhs\lakala\services\LakalaAccountService;
 use bizGhs\lakala\services\LakalaAccountService;
 use common\components\util;
 use common\components\util;
+use ghs\models\lakala\ApplicationIdForm;
+use ghs\models\lakala\CreateForm;
+use ghs\models\lakala\FormDataForm;
+use ghs\models\lakala\OcrResultForm;
+use ghs\models\lakala\OptionForm;
+use ghs\models\lakala\SetCurrentForm;
+use ghs\models\lakala\UploadFileForm;
 use Yii;
 use Yii;
 
 
 class LakalaAccountController extends BaseController
 class LakalaAccountController extends BaseController
@@ -17,111 +23,131 @@ class LakalaAccountController extends BaseController
 
 
     public function actionDetail()
     public function actionDetail()
     {
     {
-        $detail = LakalaAccountService::detail((int)Yii::$app->request->get('id'), $this->mainId, $this->shopId);
+        $form = new ApplicationIdForm();
+        $form->loadAndValidate();
+
+        $detail = LakalaAccountService::detail((int)$form->id, $this->mainId, $this->shopId);
         util::success($detail);
         util::success($detail);
     }
     }
 
 
     public function actionCreate()
     public function actionCreate()
     {
     {
-        $post = Yii::$app->request->post();
-        $type = $post['type'] ?? LakalaApplicationClass::TYPE_ONBOARDING;
-        if (!in_array($type, [LakalaApplicationClass::TYPE_ONBOARDING, LakalaApplicationClass::TYPE_SETTLEMENT_CHANGE], true)) {
-            util::fail('申请类型错误');
-        }
-        util::success(LakalaAccountService::create($this->mainId, $this->shopId, $this->shop, $type, (int)($post['accountId'] ?? 0)));
+        $form = new CreateForm();
+        $data = Yii::$app->request->post();
+        $form->load($data ?: ['type' => ''], '');
+        $form->validateForm();
+
+        util::success(LakalaAccountService::create(
+            $this->mainId,
+            $this->shopId,
+            $this->shop,
+            $form->type,
+            (int)$form->accountId
+        ));
     }
     }
 
 
     public function actionSaveDraft()
     public function actionSaveDraft()
     {
     {
-        $post = Yii::$app->request->post();
+        $form = new FormDataForm();
+        $form->loadAndValidate();
+
         util::success(LakalaAccountService::saveDraft(
         util::success(LakalaAccountService::saveDraft(
-            (int)($post['id'] ?? 0),
+            (int)$form->id,
             $this->mainId,
             $this->mainId,
             $this->shopId,
             $this->shopId,
-            $this->form($post),
-            (int)($post['currentStep'] ?? 1)
+            $form->getFormData(),
+            (int)$form->currentStep
         ));
         ));
     }
     }
 
 
     public function actionDeleteDraft()
     public function actionDeleteDraft()
     {
     {
-        LakalaAccountService::deleteDraft((int)Yii::$app->request->post('id'), $this->mainId, $this->shopId);
+        $form = new ApplicationIdForm();
+        $form->loadAndValidate();
+
+        LakalaAccountService::deleteDraft((int)$form->id, $this->mainId, $this->shopId);
         util::complete();
         util::complete();
     }
     }
 
 
     public function actionUploadFile()
     public function actionUploadFile()
     {
     {
-        $post = Yii::$app->request->post();
+        $form = new UploadFileForm();
+        $form->loadAndValidate();
+
         util::success(LakalaAccountService::upload(
         util::success(LakalaAccountService::upload(
-            (int)($post['id'] ?? 0),
+            (int)$form->id,
             $this->mainId,
             $this->mainId,
             $this->shopId,
             $this->shopId,
-            $post['content'] ?? '',
-            $post['imgType'] ?? '',
-            (int)($post['isOcr'] ?? 0)
+            $form->content,
+            $form->imgType,
+            (int)$form->isOcr
         ));
         ));
     }
     }
 
 
     public function actionOcrResult()
     public function actionOcrResult()
     {
     {
-        $get = Yii::$app->request->get();
+        $form = new OcrResultForm();
+        $form->loadAndValidate();
+
         util::success(LakalaAccountService::ocr(
         util::success(LakalaAccountService::ocr(
-            (int)($get['id'] ?? 0),
+            (int)$form->id,
             $this->mainId,
             $this->mainId,
             $this->shopId,
             $this->shopId,
-            $get['batchNo'] ?? '',
-            $get['imgType'] ?? ''
+            $form->batchNo,
+            $form->imgType
         ));
         ));
     }
     }
 
 
     public function actionOption()
     public function actionOption()
     {
     {
-        $get = Yii::$app->request->get();
-        $option = LakalaAccountService::option($get['type'] ?? '', $get['parentCode'] ?? '', $get['keyword'] ?? '');
+        $form = new OptionForm();
+        $form->loadAndValidate();
+
+        $option = LakalaAccountService::option($form->type, $form->parentCode, $form->keyword);
         util::success($option);
         util::success($option);
     }
     }
 
 
     public function actionApplyContract()
     public function actionApplyContract()
     {
     {
-        $contract = LakalaAccountService::applyContract((int)Yii::$app->request->post('id'), $this->mainId, $this->shopId);
+        $form = new ApplicationIdForm();
+        $form->loadAndValidate();
+
+        $contract = LakalaAccountService::applyContract((int)$form->id, $this->mainId, $this->shopId);
         util::success($contract);
         util::success($contract);
     }
     }
 
 
     public function actionContractStatus()
     public function actionContractStatus()
     {
     {
-        util::success(LakalaAccountService::contractStatus((int)Yii::$app->request->get('id'), $this->mainId, $this->shopId));
+        $form = new ApplicationIdForm();
+        $form->loadAndValidate();
+
+        util::success(LakalaAccountService::contractStatus((int)$form->id, $this->mainId, $this->shopId));
     }
     }
 
 
     public function actionSubmit()
     public function actionSubmit()
     {
     {
-        $post = Yii::$app->request->post();
-        $submit = LakalaAccountService::submit((int)($post['id'] ?? 0), $this->mainId, $this->shopId, $this->form($post));
+        $form = new FormDataForm();
+        $form->loadAndValidate();
+
+        $submit = LakalaAccountService::submit((int)$form->id, $this->mainId, $this->shopId, $form->getFormData());
         util::success($submit);
         util::success($submit);
     }
     }
 
 
     public function actionRefresh()
     public function actionRefresh()
     {
     {
-        $id = (int)Yii::$app->request->post('id');
-        $re = LakalaAccountService::refresh($id, $this->mainId, $this->shopId);
+        $form = new ApplicationIdForm();
+        $form->loadAndValidate();
+
+        $re = LakalaAccountService::refresh((int)$form->id, $this->mainId, $this->shopId);
         util::success($re);
         util::success($re);
     }
     }
 
 
     public function actionSetCurrent()
     public function actionSetCurrent()
     {
     {
-        $accountId = (int)Yii::$app->request->post('accountId');
-        LakalaAccountService::setCurrent($accountId, $this->mainId, $this->shopId);
-        util::complete('已设置为当前收款账户');
-    }
+        $form = new SetCurrentForm();
+        $form->loadAndValidate();
 
 
-    private function form(array $post)
-    {
-        $form = $post['formData'] ?? [];
-        if (is_string($form)) {
-            $form = json_decode($form, true);
-        }
-        if (!is_array($form)) {
-            util::fail('表单数据格式错误');
-        }
-        return $form;
+        LakalaAccountService::setCurrent((int)$form->accountId, $this->mainId, $this->shopId);
+        util::complete('已设置为当前收款账户');
     }
     }
 }
 }

+ 27 - 0
app-ghs/models/lakala/ApplicationIdForm.php

@@ -0,0 +1,27 @@
+<?php
+namespace ghs\models\lakala;
+
+use ghs\models\BaseForm;
+
+/**
+ * 拉卡拉进件申请 ID 表单模型
+ */
+class ApplicationIdForm extends BaseForm
+{
+    public $id;
+
+    public function rules()
+    {
+        return [
+            ['id', 'required', 'message' => '请填写申请ID'],
+            ['id', 'integer', 'min' => 1, 'message' => '申请ID格式错误', 'tooSmall' => '申请ID格式错误'],
+        ];
+    }
+
+    public function attributeLabels()
+    {
+        return [
+            'id' => '申请ID',
+        ];
+    }
+}

+ 35 - 0
app-ghs/models/lakala/CreateForm.php

@@ -0,0 +1,35 @@
+<?php
+namespace ghs\models\lakala;
+
+use bizGhs\lakala\classes\LakalaApplicationClass;
+use ghs\models\BaseForm;
+
+/**
+ * 创建拉卡拉进件申请表单模型
+ */
+class CreateForm extends BaseForm
+{
+    public $type;
+    public $accountId;
+
+    public function rules()
+    {
+        return [
+            ['type', 'default', 'value' => LakalaApplicationClass::TYPE_ONBOARDING],
+            ['type', 'in', 'range' => [
+                LakalaApplicationClass::TYPE_ONBOARDING,
+                LakalaApplicationClass::TYPE_SETTLEMENT_CHANGE,
+            ], 'message' => '申请类型错误'],
+            ['accountId', 'default', 'value' => 0],
+            ['accountId', 'integer', 'min' => 0, 'message' => '收款账户ID格式错误', 'tooSmall' => '收款账户ID格式错误'],
+        ];
+    }
+
+    public function attributeLabels()
+    {
+        return [
+            'type' => '申请类型',
+            'accountId' => '收款账户ID',
+        ];
+    }
+}

+ 61 - 0
app-ghs/models/lakala/FormDataForm.php

@@ -0,0 +1,61 @@
+<?php
+namespace ghs\models\lakala;
+
+use ghs\models\BaseForm;
+
+/**
+ * 拉卡拉进件表单数据模型
+ */
+class FormDataForm extends BaseForm
+{
+    public $id;
+    public $formData;
+    public $currentStep;
+
+    public function rules()
+    {
+        return [
+            ['id', 'required', 'message' => '请填写申请ID'],
+            ['id', 'integer', 'min' => 1, 'message' => '申请ID格式错误', 'tooSmall' => '申请ID格式错误'],
+            ['formData', 'required', 'message' => '请填写表单数据'],
+            ['formData', 'validateFormData'],
+            ['currentStep', 'default', 'value' => 1],
+            [
+                'currentStep',
+                'integer',
+                'min' => 1,
+                'max' => 5,
+                'message' => '当前步骤格式错误',
+                'tooSmall' => '当前步骤格式错误',
+                'tooBig' => '当前步骤格式错误',
+            ],
+        ];
+    }
+
+    public function attributeLabels()
+    {
+        return [
+            'id' => '申请ID',
+            'formData' => '表单数据',
+            'currentStep' => '当前步骤',
+        ];
+    }
+
+    public function validateFormData($attribute)
+    {
+        $formData = $this->$attribute;
+        if (is_string($formData)) {
+            $formData = json_decode($formData, true);
+        }
+        if (!is_array($formData)) {
+            $this->addError($attribute, '表单数据格式错误');
+            return;
+        }
+        $this->$attribute = $formData;
+    }
+
+    public function getFormData()
+    {
+        return $this->formData;
+    }
+}

+ 32 - 0
app-ghs/models/lakala/OcrResultForm.php

@@ -0,0 +1,32 @@
+<?php
+namespace ghs\models\lakala;
+
+use ghs\models\BaseForm;
+
+/**
+ * 拉卡拉 OCR 结果查询表单模型
+ */
+class OcrResultForm extends BaseForm
+{
+    public $id;
+    public $batchNo;
+    public $imgType;
+
+    public function rules()
+    {
+        return [
+            [['id', 'batchNo', 'imgType'], 'required', 'message' => '请填写{attribute}'],
+            ['id', 'integer', 'min' => 1, 'message' => '申请ID格式错误', 'tooSmall' => '申请ID格式错误'],
+            [['batchNo', 'imgType'], 'string', 'max' => 64],
+        ];
+    }
+
+    public function attributeLabels()
+    {
+        return [
+            'id' => '申请ID',
+            'batchNo' => '批次号',
+            'imgType' => '图片类型',
+        ];
+    }
+}

+ 33 - 0
app-ghs/models/lakala/OptionForm.php

@@ -0,0 +1,33 @@
+<?php
+namespace ghs\models\lakala;
+
+use ghs\models\BaseForm;
+
+/**
+ * 拉卡拉选项查询表单模型
+ */
+class OptionForm extends BaseForm
+{
+    public $type;
+    public $parentCode;
+    public $keyword;
+
+    public function rules()
+    {
+        return [
+            ['type', 'required', 'message' => '请填写选项类型'],
+            ['type', 'in', 'range' => ['region', 'bank-region', 'bank'], 'message' => '选项类型错误'],
+            [['parentCode', 'keyword'], 'default', 'value' => ''],
+            [['parentCode', 'keyword'], 'string', 'max' => 100],
+        ];
+    }
+
+    public function attributeLabels()
+    {
+        return [
+            'type' => '选项类型',
+            'parentCode' => '父级编码',
+            'keyword' => '关键字',
+        ];
+    }
+}

+ 27 - 0
app-ghs/models/lakala/SetCurrentForm.php

@@ -0,0 +1,27 @@
+<?php
+namespace ghs\models\lakala;
+
+use ghs\models\BaseForm;
+
+/**
+ * 设置当前拉卡拉收款账户表单模型
+ */
+class SetCurrentForm extends BaseForm
+{
+    public $accountId;
+
+    public function rules()
+    {
+        return [
+            ['accountId', 'required', 'message' => '请填写收款账户ID'],
+            ['accountId', 'integer', 'min' => 1, 'message' => '收款账户ID格式错误', 'tooSmall' => '收款账户ID格式错误'],
+        ];
+    }
+
+    public function attributeLabels()
+    {
+        return [
+            'accountId' => '收款账户ID',
+        ];
+    }
+}

+ 37 - 0
app-ghs/models/lakala/UploadFileForm.php

@@ -0,0 +1,37 @@
+<?php
+namespace ghs\models\lakala;
+
+use ghs\models\BaseForm;
+
+/**
+ * 拉卡拉资料图片上传表单模型
+ */
+class UploadFileForm extends BaseForm
+{
+    public $id;
+    public $content;
+    public $imgType;
+    public $isOcr;
+
+    public function rules()
+    {
+        return [
+            [['id', 'content', 'imgType'], 'required', 'message' => '请填写{attribute}'],
+            ['id', 'integer', 'min' => 1, 'message' => '申请ID格式错误', 'tooSmall' => '申请ID格式错误'],
+            ['content', 'string'],
+            ['imgType', 'string', 'max' => 64],
+            ['isOcr', 'default', 'value' => 0],
+            ['isOcr', 'boolean', 'message' => '是否OCR格式错误'],
+        ];
+    }
+
+    public function attributeLabels()
+    {
+        return [
+            'id' => '申请ID',
+            'content' => '图片内容',
+            'imgType' => '图片类型',
+            'isOcr' => '是否OCR',
+        ];
+    }
+}

+ 7 - 7
biz-ghs/lakala/classes/LakalaApplicationClass.php

@@ -8,12 +8,12 @@ class LakalaApplicationClass extends BaseClass
 {
 {
     public static $baseFile = '\bizGhs\lakala\models\LakalaApplication';
     public static $baseFile = '\bizGhs\lakala\models\LakalaApplication';
 
 
-    const TYPE_ONBOARDING = 'onboarding';
-    const TYPE_SETTLEMENT_CHANGE = 'settlement_change';
+    const TYPE_ONBOARDING = 'onboarding'; // 首次进件
+    const TYPE_SETTLEMENT_CHANGE = 'settlement_change'; // 结算账户变更
 
 
-    const STATUS_DRAFT = 'DRAFT';
-    const STATUS_CONTRACT_PENDING = 'CONTRACT_PENDING';
-    const STATUS_WAIT_AUDIT = 'WAIT_AUDIT';
-    const STATUS_REJECT = 'REJECT';
-    const STATUS_APPROVED = 'APPROVED';
+    const STATUS_DRAFT = 'DRAFT'; // 草稿
+    const STATUS_CONTRACT_PENDING = 'CONTRACT_PENDING'; // 合同待签
+    const STATUS_WAIT_AUDIT = 'WAIT_AUDIT'; // 待审核
+    const STATUS_REJECT = 'REJECT'; // 审核驳回
+    const STATUS_APPROVED = 'APPROVED'; // 审核通过
 }
 }

+ 76 - 26
biz-ghs/lakala/services/LakalaAccountService.php

@@ -17,7 +17,7 @@ class LakalaAccountService
 {
 {
     const RATE = '0.33';
     const RATE = '0.33';
     const MCC = '5992';
     const MCC = '5992';
-    const ACTIVITY_ID = '37';
+    const ACTIVITY_ID = '208';
 
 
     public static function list($mainId, $shopId)
     public static function list($mainId, $shopId)
     {
     {
@@ -29,11 +29,18 @@ class LakalaAccountService
         $accounts = LakalaAccountClass::getAllByCondition(
         $accounts = LakalaAccountClass::getAllByCondition(
             ['mainId' => $mainId, 'shopId' => $shopId],
             ['mainId' => $mainId, 'shopId' => $shopId],
             ['isCurrent' => SORT_DESC, 'id' => SORT_DESC],
             ['isCurrent' => SORT_DESC, 'id' => SORT_DESC],
-            '*'
+            '*', null, true
         );
         );
         foreach ($applications as &$application) {
         foreach ($applications as &$application) {
             $application['formData'] = self::decode($application['formData'] ?? '');
             $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];
         return ['applications' => $applications, 'accounts' => $accounts];
     }
     }
 
 
@@ -75,7 +82,7 @@ class LakalaAccountService
     public static function saveDraft($id, $mainId, $shopId, array $form, $step)
     public static function saveDraft($id, $mainId, $shopId, array $form, $step)
     {
     {
         $application = self::application($id, $mainId, $shopId, true);
         $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('当前申请不能修改');
             util::fail('当前申请不能修改');
         }
         }
         $application->formData = self::encode($form);
         $application->formData = self::encode($form);
@@ -211,6 +218,7 @@ class LakalaAccountService
         if (empty($application->customerNo) && empty($application->merchantNo)) {
         if (empty($application->customerNo) && empty($application->merchantNo)) {
             util::fail('申请尚未提交');
             util::fail('申请尚未提交');
         }
         }
+
         $client = new LakalaOnboardingClient();
         $client = new LakalaOnboardingClient();
         $response = $client->query('/api/v3/tkbs/open_merchant_info', [
         $response = $client->query('/api/v3/tkbs/open_merchant_info', [
             'customer_no' => $application->customerNo,
             'customer_no' => $application->customerNo,
@@ -221,7 +229,6 @@ class LakalaAccountService
             $application->status = LakalaApplicationClass::STATUS_REJECT;
             $application->status = LakalaApplicationClass::STATUS_REJECT;
             $application->rejectReason = $customer['audit_remark'] ?? '拉卡拉审核驳回';
             $application->rejectReason = $customer['audit_remark'] ?? '拉卡拉审核驳回';
         } elseif (in_array($status, ['OPEN', 'ACTIVITY'], true)) {
         } elseif (in_array($status, ['OPEN', 'ACTIVITY'], true)) {
-            $application->status = LakalaApplicationClass::STATUS_APPROVED;
             $application->merchantNo = $customer['merchant_no'] ?? $application->merchantNo;
             $application->merchantNo = $customer['merchant_no'] ?? $application->merchantNo;
             $application->customerNo = $customer['customer_no'] ?? $application->customerNo;
             $application->customerNo = $customer['customer_no'] ?? $application->customerNo;
             $shopInfo = $response['data']['shop_info_list'][0] ?? [];
             $shopInfo = $response['data']['shop_info_list'][0] ?? [];
@@ -229,6 +236,9 @@ class LakalaAccountService
             $account = self::upsertAccount($application, $response['data']);
             $account = self::upsertAccount($application, $response['data']);
             self::ensureTermOperations($application, $account, $client);
             self::ensureTermOperations($application, $account, $client);
             self::syncTerms($application, $account, $client);
             self::syncTerms($application, $account, $client);
+            if ($account->scanTermNo != '' && $account->b2bTermNo != '') {
+                $application->status = LakalaApplicationClass::STATUS_APPROVED;
+            }
         } else {
         } else {
             $application->status = LakalaApplicationClass::STATUS_WAIT_AUDIT;
             $application->status = LakalaApplicationClass::STATUS_WAIT_AUDIT;
         }
         }
@@ -322,7 +332,7 @@ class LakalaAccountService
 
 
     private static function ensureTermOperations($application, $account, $client)
     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([
             $operation = LakalaOperationClass::getByCondition([
                 'applicationId' => $application->id,
                 'applicationId' => $application->id,
                 'operationType' => 'add_term',
                 'operationType' => 'add_term',
@@ -382,16 +392,52 @@ class LakalaAccountService
                 $application->merchantNo = $merchantNo;
                 $application->merchantNo = $merchantNo;
                 $account->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->updateTime = date('Y-m-d H:i:s');
             $account->save();
             $account->save();
             $application->save();
             $application->save();
+            self::refreshAuthorizeStates($account);
         } catch (\Throwable $e) {
         } catch (\Throwable $e) {
             Yii::warning('Unable to sync Lakala merchant info terms: ' . $e->getMessage());
             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)
     private static function upsertAccount($application, array $remote)
     {
     {
         $account = LakalaAccountClass::getByCondition(['mainId' => $application->mainId, 'merchantNo' => $application->merchantNo], true);
         $account = LakalaAccountClass::getByCondition(['mainId' => $application->mainId, 'merchantNo' => $application->merchantNo], true);
@@ -412,6 +458,8 @@ class LakalaAccountService
             'accountType' => $settlement['accountType'] ?? '58',
             'accountType' => $settlement['accountType'] ?? '58',
             'licenseName' => $license['licenseName'] ?? ($license['legalName'] ?? ''),
             'licenseName' => $license['licenseName'] ?? ($license['legalName'] ?? ''),
             'identityExpire' => $license['legalIdEnd'] ?? '',
             'identityExpire' => $license['legalIdEnd'] ?? '',
+            'wxAuthorizeState' => $account->wxAuthorizeState ?? 0,
+            'zfbAuthorizeState' => $account->zfbAuthorizeState ?? 0,
             'status' => 'ACTIVE',
             'status' => 'ACTIVE',
             'updateTime' => date('Y-m-d H:i:s'),
             'updateTime' => date('Y-m-d H:i:s'),
         ];
         ];
@@ -423,6 +471,7 @@ class LakalaAccountService
             $account->$key = $value;
             $account->$key = $value;
         }
         }
         $account->save();
         $account->save();
+
         return $account;
         return $account;
     }
     }
 
 
@@ -468,6 +517,7 @@ class LakalaAccountService
         $m = $form['merchant'];
         $m = $form['merchant'];
         $s = $form['settlement'];
         $s = $form['settlement'];
         $shop = $form['shop'];
         $shop = $form['shop'];
+        $fees = self::merchantFees();
 
 
         return [
         return [
             'org_code' => $client->orgCode(),
             'org_code' => $client->orgCode(),
@@ -503,7 +553,7 @@ class LakalaAccountService
             'account_id_dt_start' => $s['accountIdStart'] ?: $l['legalIdStart'],
             'account_id_dt_start' => $s['accountIdStart'] ?: $l['legalIdStart'],
             'account_id_dt_end' => $s['accountIdEnd'] ?: $l['legalIdEnd'],
             'account_id_dt_end' => $s['accountIdEnd'] ?: $l['legalIdEnd'],
             'settle_type' => 'D1', 'settlement_type' => 'AUTOMATIC', 'contract_no' => $contractNo,
             '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),
             'attchments' => self::attachments($form),
         ];
         ];
     }
     }
@@ -589,13 +639,13 @@ class LakalaAccountService
     private static function merchantFees()
     private static function merchantFees()
     {
     {
         return [
         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()
     private static function termFees()
     {
     {
         return [
         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)
     private static function merchantInfoTermMap($value)
     {
     {
         $result = [];
         $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'] ?? '';
                     }
                     }
                 }
                 }
             }
             }

+ 19 - 13
common/components/lakala/LakalaOnboardingClient.php

@@ -7,6 +7,9 @@ use Lakala\OpenAPISDK\V3\Configuration;
 use Lakala\OpenAPISDK\V3\Model\ModelRequest;
 use Lakala\OpenAPISDK\V3\Model\ModelRequest;
 use Yii;
 use Yii;
 
 
+/**
+ * 拉卡拉进件客户端
+ */
 class LakalaOnboardingClient
 class LakalaOnboardingClient
 {
 {
     private $config;
     private $config;
@@ -29,15 +32,17 @@ class LakalaOnboardingClient
         if (!$production) {
         if (!$production) {
             $params = array_merge($defaults, $params);
             $params = array_merge($defaults, $params);
         }
         }
-        $params = array_merge($params, array_filter([
-            'app_id' => getenv('LAKALA_ONBOARDING_APP_ID'),
-            'serial_no' => getenv('LAKALA_ONBOARDING_SERIAL_NO'),
-            'sm4_key' => getenv('LAKALA_ONBOARDING_SM4_KEY'),
-            'org_code' => getenv('LAKALA_ONBOARDING_ORG_CODE'),
-            'user_no' => getenv('LAKALA_ONBOARDING_USER_NO'),
-            'merchant_private_key_path' => getenv('LAKALA_ONBOARDING_PRIVATE_KEY_PATH'),
-            'lkl_certificate_path' => getenv('LAKALA_ONBOARDING_CERTIFICATE_PATH'),
-        ]));
+        if ($production) { // 生产环境才使用配置环境变量
+            $params = array_merge($params, array_filter([
+                'app_id' => getenv('LAKALA_APP_ID'),
+                'serial_no' => getenv('LAKALA_SERIAL_NO'),
+                'sm4_key' => getenv('LAKALA_SM4_KEY'),
+                'org_code' => getenv('LAKALA_ORG_CODE'),
+                'user_no' => getenv('LAKALA_USER_NO'),
+                'merchant_private_key_path' => Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem',
+                'lkl_certificate_path' => Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer',
+            ]));
+        }
         foreach (['app_id', 'serial_no', 'sm4_key', 'org_code', 'user_no', 'merchant_private_key_path', 'lkl_certificate_path'] as $key) {
         foreach (['app_id', 'serial_no', 'sm4_key', 'org_code', 'user_no', 'merchant_private_key_path', 'lkl_certificate_path'] as $key) {
             if (empty($params[$key])) {
             if (empty($params[$key])) {
                 throw new \RuntimeException('缺少拉卡拉进件生产配置:' . $key);
                 throw new \RuntimeException('缺少拉卡拉进件生产配置:' . $key);
@@ -85,18 +90,19 @@ class LakalaOnboardingClient
                 'raw' => $raw,
                 'raw' => $raw,
             ];
             ];
         } catch (\Throwable $e) {
         } catch (\Throwable $e) {
-            Yii::error('Lakala onboarding ' . $path . ': ' . $e->getMessage());
+            Yii::error('Lakala onboarding ' . $path . ': ' . $e->getResponseHeaders() . $e->getMessage()); // . $e->getResponseHeaders()
             throw new \RuntimeException('拉卡拉接口请求失败:' . $e->getMessage());
             throw new \RuntimeException('拉卡拉接口请求失败:' . $e->getMessage());
         }
         }
     }
     }
 
 
     public function upload($base64, $imgType, $ocr = false)
     public function upload($base64, $imgType, $ocr = false)
     {
     {
+        $base = $base64;
         return $this->call('/api/v3/tkbs/customer/file/upload', [
         return $this->call('/api/v3/tkbs/customer/file/upload', [
-            'file_base64' => $base64,
+            'file_base64' => $base,
             'img_type' => $imgType,
             'img_type' => $imgType,
-            'prefix' => 'reg',
-            'sourcechnl' => 1,
+            //'prefix' => 'reg',
+            'sourcechnl' => 0,
             'is_ocr' => $ocr ? 'true' : 'false',
             'is_ocr' => $ocr ? 'true' : 'false',
         ]);
         ]);
     }
     }

+ 5 - 0
scripts/sql/add_lakala_account_authorize_state.sql

@@ -0,0 +1,5 @@
+-- 拉卡拉收款账户认证状态字段
+
+ALTER TABLE `xhLakalaAccount`
+    ADD COLUMN `wxAuthorizeState` tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT '微信认证状态: 0未认证,1已认证(来自支付宝微信认证状态查询接口)' AFTER `b2bTermNo`,
+    ADD COLUMN `zfbAuthorizeState` tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT '支付宝认证状态:0未认证,1已认证(来自支付宝微信认证状态查询接口)' AFTER `wxAuthorizeState`;

+ 2 - 0
scripts/sql/add_lakala_onboarding.sql

@@ -56,6 +56,8 @@ CREATE TABLE IF NOT EXISTS `xhLakalaAccount` (
     `identityExpire` varchar(32) NOT NULL DEFAULT '' COMMENT '法人或结算人身份证有效期',
     `identityExpire` varchar(32) NOT NULL DEFAULT '' COMMENT '法人或结算人身份证有效期',
     `scanTermNo` varchar(64) NOT NULL DEFAULT '' COMMENT 'WECHAT_PAY扫码终端号',
     `scanTermNo` varchar(64) NOT NULL DEFAULT '' COMMENT 'WECHAT_PAY扫码终端号',
     `b2bTermNo` varchar(64) NOT NULL DEFAULT '' COMMENT 'B2B_SYT批发终端号',
     `b2bTermNo` varchar(64) NOT NULL DEFAULT '' COMMENT 'B2B_SYT批发终端号',
+    `wxAuthorizeState` tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT '微信认证状态: 0未认证,1已认证(来自支付宝微信认证状态查询接口)',
+    `zfbAuthorizeState` tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT '支付宝认证状态:0未认证,1已认证(来自支付宝微信认证状态查询接口)',
     `status` varchar(32) NOT NULL DEFAULT 'ACTIVE' COMMENT '账户状态',
     `status` varchar(32) NOT NULL DEFAULT 'ACTIVE' COMMENT '账户状态',
     `isCurrent` tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT '是否为当前门店收款账户:0否,1是',
     `isCurrent` tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT '是否为当前门店收款账户:0否,1是',
     `createTime` datetime NOT NULL COMMENT '创建时间',
     `createTime` datetime NOT NULL COMMENT '创建时间',