Explorar o código

feat(lakala): add index controller and update ledger service

- Add IndexController with notify method for handling requests
- Update LedgerService to improve queryBindApplyList response handling
- Modify ProfitShareReceiverEntity to support binding status checks
- Adjust routing configuration to include new index endpoint
- Improve error handling and data processing in entity methods
- Fix spacing and formatting issues in multiple files
runphp hai 4 meses
pai
achega
58a6b14f32

+ 7 - 2
route/api.php

@@ -2,7 +2,10 @@
 declare(strict_types=1);
 
 use think\facade\Route;
-use SixShop\Lakala\Controller\Api\ProfitShareReceiverController;
+use SixShop\Lakala\Controller\Api\{
+    IndexController,
+    ProfitShareReceiverController
+};
 use SixShop\System\Middleware\MacroPageMiddleware;
 // API路由
 // 路由前缀: /api/lakala
@@ -10,4 +13,6 @@ use SixShop\System\Middleware\MacroPageMiddleware;
 // 如果需要登录请添加认证中间件auth
 // ->middleware(['auth'])
 Route::resource('profit_share_receiver', ProfitShareReceiverController::class)
-    ->middleware(['auth', MacroPageMiddleware::class]);
+    ->middleware(['auth', MacroPageMiddleware::class]);
+
+Route::post('', IndexController::class);

+ 15 - 0
src/Controller/Api/IndexController.php

@@ -0,0 +1,15 @@
+<?php
+declare(strict_types=1);
+namespace SixShop\Lakala\Controller\Api;
+
+use SixShop\Core\Request;
+use think\facade\Log;
+
+class IndexController
+{
+    public function notify(Request $request)
+    {
+        // todo
+        Log::debug('lakala notify'.json_encode($request->param()));
+    }
+}

+ 26 - 9
src/Entity/ProfitShareReceiverEntity.php

@@ -41,14 +41,14 @@ class ProfitShareReceiverEntity extends BaseEntity
         return $entity;
     }
 
-    public function getReceiverList(array $params, array $pageAndLimit):Paginator
+    public function getReceiverList(array $params, array $pageAndLimit): Paginator
     {
         return $this->withSearch(['order_no', 'status', 'user_id'], $params)
             ->append(['status_text'])
             ->paginate($pageAndLimit);
     }
 
-    public function getReceiver(array $params):self
+    public function getReceiver(array $params): self
     {
         $entity = $this->where($params)
             ->append(['status_text'])
@@ -57,17 +57,34 @@ class ProfitShareReceiverEntity extends BaseEntity
             throw_logic_exception('分账接收方申请记录不存在!');
         }
         if ($entity->receiver_no && $entity->status == ReceiverStatusEnum::SUBMITTING) {
-            $response = LedgerService::queryReceiverDetail($entity->order_no, $entity->receiver_no);
+            $response = LedgerService::queryReceiverDetail($entity->order_no, $entity->receiver_no, $entity->org_code);
             if ($response->rowStatus == 'VALID') {
                 $entity->status = ReceiverStatusEnum::VERIFIED;
                 $entity->wallet_id = $response->walletId;
             }
             $entity->save();
         }
+        if ($entity->status == ReceiverStatusEnum::BINDING) {
+            $response = LedgerService::queryBindApplyList([
+                'orderNo' => $entity->order_no,
+                'orgCode' => $entity->org_code,
+                'receiverNo' => $entity->receiver_no,
+            ], $entity->org_code);
+            if (isset($response->list[0])
+                && $response->list[0]->rowSno == $entity->order_no) {
+                $entity->status = match ($response->list[0]->auditStatus) {
+                    '0' => ReceiverStatusEnum::BINDING,
+                    '1' => ReceiverStatusEnum::BOUND,
+                    '2' => ReceiverStatusEnum::BIND_FAILED
+                };
+                $entity->fail_reason = $response->list[0]->remark;
+                $entity->save();
+            }
+        }
         return $entity;
     }
 
-    public function apply(int $id):self
+    public function apply(int $id): self
     {
         $entity = $this->getReceiver(['id' => $id]);
         if ($entity->status != ReceiverStatusEnum::PENDING) {
@@ -94,7 +111,7 @@ class ProfitShareReceiverEntity extends BaseEntity
                 // 系统异常,请稍后重试
                 // 创建新的申请记录
                 $newEntity = $entity->clone()->toArray();
-                unset($newEntity['id'],$newEntity['order_no']);
+                unset($newEntity['id'], $newEntity['order_no']);
                 $this->save($newEntity);
                 $entity->delete();
             }
@@ -108,7 +125,7 @@ class ProfitShareReceiverEntity extends BaseEntity
         return $entity;
     }
 
-    public function bind(int $id):self
+    public function bind(int $id): self
     {
         $entity = $this->getReceiver(['id' => $id]);
         if ($entity->status != ReceiverStatusEnum::VERIFIED) {
@@ -125,15 +142,15 @@ class ProfitShareReceiverEntity extends BaseEntity
                 $entity->save();
             }
             // 上传协议文件
-            $entrustLocalPath = public_path().$entity->entrust_local_path;
+            $entrustLocalPath = public_path() . $entity->entrust_local_path;
             $pathInfo = pathinfo($entrustLocalPath);
             $response = MMSService::uploadFile(
                 orderNo: $entity->order_no,
                 attType: UploadFileTypeEnum::SPLIT_COOPERATION_FILE,
-                attExtName  : $pathInfo['extension'],
+                attExtName: $pathInfo['extension'],
                 fileContent: file_get_contents($entrustLocalPath),
             );
-            $entity->entrust_file_name = '合作协议'.$pathInfo['extension'];
+            $entity->entrust_file_name = '合作协议' . $pathInfo['extension'];
             $entity->entrust_file_path = $response->attFileId;
             $entity->save();
         }

+ 9 - 12
src/Service/LedgerService.php

@@ -126,28 +126,25 @@ class LedgerService
      *
      * @link https://o.lakala.com/#/home/document/detail?id=939
      */
-    public function queryBindApplyList(array $reqData, int $pageNum = 1, int $pageSize = 10, string $orgCode = '1', string $version = '1.0')
+    public function queryBindApplyList(array $reqData, int $pageNum = 1, int $pageSize = 10, string $version = '1.0'):object
     {
         $request = new V2ModelRequest();
         $reqData = array_merge($reqData, [
             'version' => $version,
-            'orgCode' => $orgCode,
             'pageNum' => $pageNum,
             'pageSize' => $pageSize,
+            'merCupNo' => $this->config->merchant_no,
         ]);
         $request->setReqData($reqData);
         $response = $this->v2LakalaApi->tradeApi('/api/v2/mms/openApi/ledger/openWeb/listRelationApply', $request);
-        if ($response->getRespData()) {
-            print_r($response->getRespData());
+        if ($response->getRetCode() == '000000') {
+            return $response->getRespData();
         } else {
-            print_r($response);
+            throw_logic_exception(
+                msg:$response->getRetMsg(),
+                code: (int)$response->getRetCode(),
+                data: $response->getRespData(),
+            );
         }
-        echo $response->getRetCode();
-
-        # 响应头信息
-        print_r($response->getHeaders());
-
-        # 响应原文
-        echo $response->getOriginalText();
     }
 }