Przeglądaj źródła

feat(shipping-template): 调整运费模板关联逻辑与商品控制器集成
- 修改 ShippingTemplateController 中获取模板 ID 的位置以优化流程
- 更新 ShippingTemplateRelationEntity 中 setTemplateForBiz 方法参数顺序并移除时间字段
- 调整 ShippingTemplateRelationModel 返回值类型从 nullable 转为默认返回 0
- 在 Goods 控制器中新增运费模板保存逻辑并与商品关联
- 更新前端 GoodsForm 组件中的业务类型传参为 goods

runphp 5 miesięcy temu
rodzic
commit
fffd23701d

+ 5 - 3
src/Controller/ShippingTemplateController.php

@@ -28,7 +28,10 @@ class ShippingTemplateController
 
         // 参数验证
         if (empty($bizType) || $bizId <= 0) {
-            return error_response('参数错误:biz_type和biz_id不能为空且biz_id必须大于0');
+            $relatedTemplateId = 0;
+        } else {
+            // 获取当前业务实体关联的模板ID
+            $relatedTemplateId = ShippingTemplateRelationModel::getTemplateIdByBiz($bizType, $bizId);
         }
 
         // 获取所有启用的运费模板
@@ -37,8 +40,7 @@ class ShippingTemplateController
             ->order('id', 'asc')
             ->select();
 
-        // 获取当前业务实体关联的模板ID
-        $relatedTemplateId = ShippingTemplateRelationModel::getTemplateIdByBiz($bizType, $bizId);
+
 
         // 构造返回数据
         $result = [];

+ 1 - 4
src/Entity/ShippingTemplateRelationEntity.php

@@ -26,7 +26,7 @@ class ShippingTemplateRelationEntity extends BaseEntity
     /**
      * 为业务实体设置运费模板
      */
-    public function setTemplateForBiz(int $templateId, string $bizType, int $bizId): bool
+    public function setTemplateForBiz(int $templateId, int $bizId, string $bizType = 'goods'): bool
     {
         $relation = $this->where('biz_type', $bizType)
             ->where('biz_id', $bizId)
@@ -36,7 +36,6 @@ class ShippingTemplateRelationEntity extends BaseEntity
             // 更新已存在的关联
             return $relation->save([
                 'template_id' => $templateId,
-                'update_time' => date('Y-m-d H:i:s')
             ]);
         } else {
             // 创建新的关联
@@ -44,8 +43,6 @@ class ShippingTemplateRelationEntity extends BaseEntity
                 'template_id' => $templateId,
                 'biz_type' => $bizType,
                 'biz_id' => $bizId,
-                'create_time' => date('Y-m-d H:i:s'),
-                'update_time' => date('Y-m-d H:i:s')
             ]);
         }
     }

+ 2 - 2
src/Model/ShippingTemplateRelationModel.php

@@ -55,9 +55,9 @@ class ShippingTemplateRelationModel extends Model
     /**
      * 根据业务类型和业务ID获取运费模板ID
      */
-    public static function getTemplateIdByBiz(string $bizType, int $bizId): ?int
+    public static function getTemplateIdByBiz(string $bizType, int $bizId): int
     {
         $relation = self::getByBiz($bizType, $bizId);
-        return $relation ? $relation->template_id : null;
+        return $relation ? $relation->template_id : 0;
     }
 }