Browse Source

fix:初始化接口

super-yimizi 2 months ago
parent
commit
1f94512eac

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

@@ -28,8 +28,7 @@ class Order extends Base
         $postData['calculate_data'] = '1'; // 添加触发自定义验证的字段
         if (!$validate->scene('calculate')->check($postData)) {
             $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'); // 优惠券
@@ -43,7 +42,7 @@ class Order extends Base
             // 自动判断数据源类型并获取标准化的商品列表
             if (!empty($cart_ids)) {
                 // 购物车模式:先转换为商品列表
-                $goods_list = \app\common\Service\Cart::convertCartToGoodsList($cart_ids, $this->auth->id);
+                $goods_list = \app\common\Service\CartService::convertCartToGoodsList($cart_ids, $this->auth->id);
             } elseif (empty($goods_list)) {
                 throw new \Exception("请提供购物车ID或商品列表");
             }
@@ -64,7 +63,7 @@ class Order extends Base
         
         // 处理商品数据
         foreach ($goodsList as $item) {
-            $item->category_id = $item->goods->category_id;
+            //$item->category_id = $item->goods->category_id;
             $item->brand_id = $item->goods->brand_id;
             $item->goods->visible(explode(',', 'id,title,image,price,marketprice'));
         }

+ 6 - 37
application/common/model/Goods.php

@@ -26,7 +26,6 @@ class Goods extends Model
     protected $deleteTime = 'deletetime';
     // 追加属性
     protected $append = [
-        'url'
     ];
     protected static $config = [];
 
@@ -38,36 +37,6 @@ class Goods extends Model
         self::$config = $config;
     }
 
-    public function getUrlAttr($value, $data)
-    {
-        return $this->buildUrl($value, $data);
-    }
-
-    public function getFullurlAttr($value, $data)
-    {
-        return $this->buildUrl($value, $data, true);
-    }
-
-    private function buildUrl($value, $data, $domain = false)
-    {
-        $diyname = isset($data['diyname']) && $data['diyname'] ? $data['diyname'] : $data['id'];
-        $catename = isset($this->category) && $this->category ? $this->category->diyname : 'all';
-        $cateid = isset($this->category) && $this->category ? $this->category->id : 0;
-        $time = $data['publishtime'] ?? time();
-        $vars = [
-            ':id'       => $data['id'],
-            ':diyname'  => $diyname,
-            ':category' => $cateid,
-            ':catename' => $catename,
-            ':cateid'   => $cateid,
-            ':year'     => date("Y", $time),
-            ':month'    => date("m", $time),
-            ':day'      => date("d", $time),
-        ];
-        $suffix = static::$config['moduleurlsuffix']['goods'] ?? static::$config['urlsuffix'];
-        return addon_url('shop/goods/index', $vars, $suffix, $domain);
-    }
-
     public function getImageAttr($value, $data)
     {
         $value = $value ?: self::$config['default_goods_img'];
@@ -91,7 +60,7 @@ class Goods extends Model
     public function getContentAttr($value, $data)
     {
         //组装卡片信息
-        return \addons\shop\library\Service::formatSourceTpl($value);
+        return \app\common\library\Service::formatSourceTpl($value);
     }
 
     public static function getIndexGoodsList()
@@ -239,11 +208,11 @@ class Goods extends Model
     }
 
 
-    public function Category()
-    {
-        // 由于现在使用category_ids字段,这里返回主分类(第一个分类)
-        return $this->belongsTo('Category', 'category_id', 'id');
-    }
+    // public function Category()
+    // {
+    //     // 由于现在使用category_ids字段,这里返回主分类(第一个分类)
+    //     return $this->belongsTo('Category', 'category_id', 'id');
+    // }
     
     public function Categories()
     {

+ 22 - 22
application/common/service/OrderService.php

@@ -66,7 +66,7 @@ class OrderService
         // 批量查询商品信息
         $goodsData = [];
         if (!empty($goodsIds)) {
-            $goodsCollection = Goods::with(['category', 'brand'])
+            $goodsCollection = Goods::with(['brand'])
                 ->where('id', 'in', $goodsIds)
                 ->where('status', GoodsEnum::STATUS_ON_SALE)
                 ->select();
@@ -201,7 +201,7 @@ class OrderService
                 'comment_status'       => 0, // 评论状态:0=未评论
                 'status'               => 1, // 状态
                 // 添加分类和品牌信息用于优惠券计算 (临时字段,不会保存到数据库)
-                'category_id'          => $item->goods->category_id,
+                // 'category_id'          => $item->goods->category_ids,
                 'brand_id'             => $item->goods->brand_id,
             ];
             
@@ -219,26 +219,26 @@ class OrderService
         // 订单应付金额(暂时等于订单金额,后续会减去优惠)
         $orderInfo['amount'] = $orderInfo['order_amount'];
 
-        if (!empty($userCoupon)) {
-            // 校验优惠券
-            $goods_ids = array_column($orderItem, 'goods_id');
-            $category_ids = array_column($orderItem, 'category_id');
-            $brand_ids = array_column($orderItem, 'brand_id');
-            $couponModel = new Coupon();
-            $coupon = $couponModel->getCoupon($userCoupon['coupon_id'])
-                ->checkCoupon()
-                ->checkOpen()
-                ->checkUseTime($userCoupon['createtime'])
-                ->checkConditionGoods($goods_ids, $userId, $category_ids, $brand_ids);
-
-            // 计算折扣金额,判断是使用不含运费,还是含运费的金额
-            $amount = !isset($config['shippingfeecoupon']) || $config['shippingfeecoupon'] == 0 ? $orderInfo['goods_price'] : $orderInfo['order_amount'];
-            list($new_money, $coupon_money) = $coupon->doBuy($amount);
-
-            // 判断优惠金额是否超出总价,超出则直接设定优惠金额为总价
-            $orderInfo['coupon_discount_fee'] = $coupon_money > $amount ? $amount : $coupon_money;
-            $orderInfo['discount_fee'] = $orderInfo['coupon_discount_fee'];
-        }
+        // if (!empty($userCoupon)) {
+        //     // 校验优惠券
+        //     $goods_ids = array_column($orderItem, 'goods_id');
+        //     $category_ids = array_column($orderItem, 'category_id');
+        //     $brand_ids = array_column($orderItem, 'brand_id');
+        //     $couponModel = new Coupon();
+        //     $coupon = $couponModel->getCoupon($userCoupon['coupon_id'])
+        //         ->checkCoupon()
+        //         ->checkOpen()
+        //         ->checkUseTime($userCoupon['createtime'])
+        //         ->checkConditionGoods($goods_ids, $userId, $category_ids, $brand_ids);
+
+        //     // 计算折扣金额,判断是使用不含运费,还是含运费的金额
+        //     $amount = !isset($config['shippingfeecoupon']) || $config['shippingfeecoupon'] == 0 ? $orderInfo['goods_price'] : $orderInfo['order_amount'];
+        //     list($new_money, $coupon_money) = $coupon->doBuy($amount);
+
+        //     // 判断优惠金额是否超出总价,超出则直接设定优惠金额为总价
+        //     $orderInfo['coupon_discount_fee'] = $coupon_money > $amount ? $amount : $coupon_money;
+        //     $orderInfo['discount_fee'] = $orderInfo['coupon_discount_fee'];
+        // }
 
         // 计算最终应付金额【订单金额减去折扣】
         $orderInfo['amount'] = max(0, bcsub($orderInfo['order_amount'], $orderInfo['discount_fee'], 2));