Browse Source

fix: 商品详情增加是否有定制规格选项

super-yimizi 1 month ago
parent
commit
d359123921

+ 2 - 0
application/api/controller/Goods.php

@@ -99,6 +99,8 @@ class Goods extends Base
         //查询折扣信息   以及倒计时
         $row['discount_info'] = DiscountService::getGoodsDiscountDetail($row['id']);
         $row['comment_total'] = $comment_count;
+        // 查询是否有定制规格
+        $row['is_customized_spec'] = GoodService::getGoodsCustomizedSpec($id, 2) ? 1: 0;
         $this->success('获取成功', $row);
     }
 

+ 10 - 0
application/common/Service/Goods/GoodService.php

@@ -3,6 +3,7 @@
 namespace app\common\Service\Goods;
 use app\common\model\Goods;
 use app\common\Enum\GoodsEnum;
+use app\common\model\GoodsSkuSpec;
 class GoodService
 {
     /**
@@ -35,4 +36,13 @@ class GoodService
         $arrGoods = collection($goodsList)->toArray();
         return $arrGoods;
     }
+    //  查询商品关联规格
+    public static function getGoodsCustomizedSpec($goods_id = 0, $type = 0)
+    {
+        $goodsSkuSpec = GoodsSkuSpec::where('id', $goods_id)
+             ->where('type', $type)
+             ->find();
+  
+        return $goodsSkuSpec;
+    }
 }

+ 27 - 0
application/common/model/GoodsSkuSpec.php

@@ -0,0 +1,27 @@
+<?php
+
+namespace app\common\model;
+
+use think\Model;
+
+
+class GoodsSkuSpec extends Model
+{
+
+
+    // 表名
+    protected $name = 'shop_goods_sku_spec';
+
+    // 自动写入时间戳字段
+    protected $autoWriteTimestamp = 'int';
+
+    // 定义时间戳字段名
+    protected $createTime = 'createtime';
+    protected $updateTime = 'updatetime';
+    protected $deleteTime = false;
+
+    // 追加属性
+    protected $append = [];
+
+    
+}