Browse Source

fix:没有收货地址不要报错,正常返回,允许用户在确认订单页去选择收货地址。

super-yimizi 1 month ago
parent
commit
8bed328cff
2 changed files with 9 additions and 9 deletions
  1. 4 4
      application/api/controller/Order.php
  2. 5 5
      application/api/validate/Order.php

+ 4 - 4
application/api/controller/Order.php

@@ -31,10 +31,10 @@ class Order extends Base
             $this->error($validate->getError());
         }        
         $config = get_addon_config('shop');
-        $address_id = $this->request->post('address_id/d'); // 地址id
-        $user_coupon_id = $this->request->post('user_coupon_id/d'); // 优惠券
-        $cart_ids = $this->request->post('cart_ids/a'); // 购物车ID数组
-        $goods_list = $this->request->post('goods_list/a'); // 商品列表
+        $address_id = $postData['address_id'] ?? 0; // 地址id
+        $user_coupon_id = $postData['user_coupon_id'] ?? 0; // 优惠券
+        $cart_ids = $postData['cart_ids'] ?? []; // 购物车ID数组
+        $goods_list = $postData['goods_list'] ?? []; // 商品列表
         
         $address = Address::get($address_id);
         $area_id = !empty($address) ? $address->area_id : 0;

+ 5 - 5
application/api/validate/Order.php

@@ -55,6 +55,7 @@ class Order extends Validate
         'address_id.require'    => '收货地址不能为空',
         'address_id.integer'    => '收货地址ID必须是整数',
         'address_id.gt'         => '收货地址ID必须大于0',
+        'address_id.egt'        => '收货地址ID格式错误',
         'user_coupon_id.integer' => '优惠券ID必须是整数',
         'user_coupon_id.gt'     => '优惠券ID必须大于0',
         'memo.max'              => '备注长度不能超过500个字符',
@@ -77,9 +78,6 @@ class Order extends Validate
         'goods_list.*.nums.integer'     => '商品数量必须是整数',
         'goods_list.*.nums.gt'          => '商品数量必须大于0',
         
-        // 计算类型(已废弃,保持兼容性)
-        'type.in'           => '计算类型只能是cart或goods',
-        
         // 订单操作相关
         'order_sn.require'      => '订单号不能为空',
         'order_sn.alphaNum'     => '订单号格式错误',
@@ -107,8 +105,8 @@ class Order extends Validate
     protected $scene = [
         // 统一创建订单接口(支持购物车和商品规格两种模式)
         'create'            => ['address_id', 'user_coupon_id', 'memo', 'create_data'],
-        // 计算订单(支持购物车和商品规格两种模式)
-        'calculate'         => ['address_id', 'user_coupon_id', 'calculate_data'],
+        // 计算订单(支持购物车和商品规格两种模式) 地址不是必填
+        'calculate'         => ['address_id' => 'integer|egt:0', 'user_coupon_id', 'calculate_data'],
         // 订单详情、确认收货、查询物流
         'detail'            => ['orderId'],
         // 取消订单
@@ -119,6 +117,8 @@ class Order extends Validate
         'lists'             => ['page', 'pageSize', 'status', 'keywords', 'start_time', 'end_time', 'time_range'],
     ];
 
+
+
     /**
      * 自定义验证规则:验证商品列表格式
      * @param $value