Parcourir la source

feat(lakala): add profit share receiver binding functionality

- Increased column limits for entrust file fields in migration
- Added "分账关系绑定申请" button and handler in Vue component
- Registered new `/bind` route endpoint for profit share receivers
- Implemented `bind` method in controller and entity with file upload logic
- Created Config facade and added receiver agreement file configuration
- Updated MMSService to properly handle file uploads and responses
- Adjusted uploadFile parameter name from `$data` to `$fileContent`
- Added default agreement file handling during binding process
runphp il y a 4 mois
Parent
commit
eba7cd7f58

+ 3 - 3
database/migrations/20251109121623_profit_share_receiver.php

@@ -39,9 +39,9 @@ final class ProfitShareReceiver extends AbstractMigration
             ->addColumn('receiver_no', 'string', ['null' => true, 'limit' => 32, 'comment' => '接收方编号'])
             ->addColumn('status', 'integer', ['signed' => false, 'default' => 1, 'comment' => '状态 1: 待审核 2:提交中 3: 验证通过 4: 验证失败 5:绑定中 6: 绑定成功 7: 绑定失败'])
             ->addColumn('fail_reason', 'string', ['null' => true, 'limit' => 255, 'comment' => '失败原因'])
-            ->addColumn('entrust_file_name', 'string', ['null' => true, 'limit' => 32, 'comment' => '合作协议附件名称'])
-            ->addColumn('entrust_file_path', 'string', ['null' => true, 'limit' => 32, 'comment' => '合作协议附件路径'])
-            ->addColumn('entrust_local_path', 'string', ['null' => true, 'limit' => 32, 'comment' => '合作协议附件本地路径'])
+            ->addColumn('entrust_file_name', 'string', ['null' => true, 'limit' => 100, 'comment' => '合作协议附件名称'])
+            ->addColumn('entrust_file_path', 'string', ['null' => true, 'limit' => 255, 'comment' => '合作协议附件路径'])
+            ->addColumn('entrust_local_path', 'string', ['null' => true, 'limit' => 255, 'comment' => '合作协议附件本地路径'])
             ->addColumn('wallet_id', 'string', ['null' => true, 'limit' => 32, 'comment' => '钱包ID'])
             ->addTimestamps('create_time', 'update_time')
             ->addColumn('delete_time', 'timestamp', ['null' => true, 'comment' => '删除时间'])

+ 34 - 0
resource/admin/ProfitShareReceiver.vue

@@ -145,6 +145,14 @@
           >
             分账接收方创建申请
           </el-button>
+          <el-button 
+            v-if="detailData.status === 3"
+            type="success" 
+            @click="handleBindApplication"
+            :loading="applyLoading"
+          >
+            分账关系绑定申请
+          </el-button>
           <el-button @click="handleCloseDetailDialog">关闭</el-button>
         </span>
       </template>
@@ -324,6 +332,32 @@ export default {
       }
     },
     
+    // 分账关系绑定申请
+    async handleBindApplication() {
+      if (!this.axiosInstance) {
+        this.$message.error('无法获取请求实例')
+        return
+      }
+
+      this.applyLoading = true
+      try {
+        const res = await this.axiosInstance.put(`/lakala/profit_share_receiver/${this.detailData.id}/bind`)
+        if (res.code === 200) {
+          this.$message.success('分账关系绑定申请已提交')
+          this.handleCloseDetailDialog()
+          // 重新加载列表数据以更新状态
+          await this.fetchData()
+        } else {
+          this.$message.error(res.msg || res.message || '申请提交失败')
+        }
+      } catch (error) {
+        console.error('分账关系绑定申请失败:', error)
+        this.$message.error('申请提交失败: ' + (error.message || '未知错误'))
+      } finally {
+        this.applyLoading = false
+      }
+    },
+    
     // 分页相关
     handleSizeChange(val) {
       this.pagination.limit = val

+ 1 - 0
route/admin.php

@@ -15,6 +15,7 @@ use SixShop\System\Middleware\MacroPageMiddleware;
 
 Route::resource('profit_share_receiver', ProfitShareReceiverController::class, function () {
     Route::put('apply', [ProfitShareReceiverController::class, 'apply']);
+    Route::put('bind', [ProfitShareReceiverController::class, 'bind']);
 })
     ->middleware(['auth', MacroPageMiddleware::class]);
 

+ 1 - 0
src/Config.php

@@ -14,6 +14,7 @@ use SixShop\System\Trait\ConfigTrait;
  * @property string $complete_notify_url 收货确认通知地址
  * @property string $environment 环境
  * @property string $org_code 机构代码
+ * @property string $receiver_agreement_file 默认合作协议文件
  */
 class Config
 {

+ 8 - 2
src/Controller/Admin/ProfitShareReceiverController.php

@@ -1,5 +1,6 @@
 <?php
 declare(strict_types=1);
+
 namespace SixShop\Lakala\Controller\Admin;
 
 use SixShop\Core\Request;
@@ -20,13 +21,18 @@ class ProfitShareReceiverController
         return page_response(page: $entity->getReceiverList($params, $request->pageAndLimit()));
     }
 
-    public function read(int $id, Request $request, ProfitShareReceiverEntity $entity):Response
+    public function read(int $id, Request $request, ProfitShareReceiverEntity $entity): Response
     {
         return success_response($entity->getReceiver(['id' => $id]));
     }
 
-    public function apply(int $id, ProfitShareReceiverEntity $entity):Response
+    public function apply(int $id, ProfitShareReceiverEntity $entity): Response
     {
         return success_response($entity->apply($id));
     }
+
+    public function bind(int $id, ProfitShareReceiverEntity $entity): Response
+    {
+        return success_response($entity->bind($id));
+    }
 }

+ 36 - 2
src/Entity/ProfitShareReceiverEntity.php

@@ -5,7 +5,8 @@ namespace SixShop\Lakala\Entity;
 
 use SixShop\Core\Entity\BaseEntity;
 use SixShop\Core\Exception\LogicException;
-use SixShop\Lakala\Config;
+use SixShop\Lakala\Enum\UploadFileTypeEnum;
+use SixShop\Lakala\Facade\Config;
 use SixShop\Lakala\Enum\ProfitShareOrderStatusEnum;
 use SixShop\Lakala\Enum\ReceiverStatusEnum;
 use SixShop\Lakala\Facade\LedgerService;
@@ -70,7 +71,7 @@ class ProfitShareReceiverEntity extends BaseEntity
     {
         $entity = $this->getReceiver(['id' => $id]);
         if ($entity->status != ReceiverStatusEnum::PENDING) {
-            throw_logic_exception('请不要重复提交申请!');
+            throw_logic_exception('待审核状态才可以申请!');
         }
         $reqData = [
             'orderNo' => $entity->order_no,
@@ -106,4 +107,37 @@ class ProfitShareReceiverEntity extends BaseEntity
         $entity->save();
         return $entity;
     }
+
+    public function bind(int $id):self
+    {
+        $entity = $this->getReceiver(['id' => $id]);
+        if ($entity->status != ReceiverStatusEnum::VERIFIED) {
+            throw_logic_exception('验证通过状态才可以绑定!');
+        }
+        if (!$entity->entrust_file_path) {
+            if (!$entity->entrust_local_path) {
+                // 添加默认合作协议
+                $defaultReceiverAgreementFile = Config::getConfig('receiver_agreement_file');
+                if (!$defaultReceiverAgreementFile) {
+                    throw_logic_exception('请先添加默认合作协议!');
+                }
+                $entity->entrust_local_path = Config::getConfig('receiver_agreement_file')[0];
+                $entity->save();
+            }
+            // 上传协议文件
+            $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'],
+                fileContent: file_get_contents($entrustLocalPath),
+            );
+            $entity->entrust_file_name = '合作协议'.$pathInfo['extension'];
+            $entity->entrust_file_path = $response->attFileId;
+            $entity->save();
+        }
+        // todo 绑定申请
+        return $entity;
+    }
 }

+ 16 - 0
src/Facade/Config.php

@@ -0,0 +1,16 @@
+<?php
+declare(strict_types=1);
+namespace SixShop\Lakala\Facade;
+
+use think\Facade;
+
+/**
+ * @mixin \SixShop\Lakala\Config
+ */
+class Config extends Facade
+{
+    protected static function getFacadeClass()
+    {
+        return \SixShop\Lakala\Config::class;
+    }
+}

+ 12 - 12
src/Service/MMSService.php

@@ -59,16 +59,16 @@ class MMSService
      * @param string $orderNo
      * @param UploadFileTypeEnum $attType
      * @param string $attExtName
-     * @param string $data
+     * @param string $fileContent
      * @param string $orgCode
      * @param string $version
      *
      * @link https://o.lakala.com/#/home/document/detail?id=90
      */
-    public function uploadFile(string $orderNo, UploadFileTypeEnum $attType, string  $attExtName, string $data, string $orgCode = '1',  string $version = '1.0')
+    public function uploadFile(string $orderNo, UploadFileTypeEnum $attType, string $attExtName, string $fileContent, string $orgCode = '1',  string $version = '1.0')
     {
         $request = new V2ModelRequest();
-        $attContext = base64_encode($data);
+        $attContext = base64_encode($fileContent);
         $request->setReqData([
             'attContext' => $attContext,
             'attType' => $attType->value,
@@ -79,14 +79,14 @@ class MMSService
         ]);
         $response = $this->v2LakalaApi->tradeApi('/api/v2/mms/openApi/uploadFile', $request);
 
-        print_r($response);
-        echo $response->getRetCode();
-
-        # 响应头信息
-        print_r($response->getHeaders());
-
-        # 响应原文
-        echo $response->getOriginalText();
-
+        if ($response->getRetCode() == '000000') {
+            return $response->getRespData();
+        } else {
+            throw_logic_exception(
+                msg:$response->getRetMsg(),
+                code: (int)$response->getRetCode(),
+                data: $response->getRespData(),
+            );
+        }
     }
 }