ソースを参照

库存详情优化,增加关于商品的字段

wufeng 2 年 前
コミット
7298733c56

+ 11 - 2
app/admin/logic/InventoryExchangeLogic.php

@@ -119,8 +119,17 @@ class InventoryExchangeLogic extends BaseLogic
     //获取兑换商品库存详情
     public static function read(int $id = 0): Json
     {
-        $res = InventoryExchangeModel::field(true)
-            ->where(['id' => $id])
+        $res = InventoryExchangeModel::alias('a')
+            ->field('a.*,b.good_cover_img,b.moq,b.step,b.type,b.price,b.good_banner_img,b.good_img,b.good_param,b.good_remark,b.unit_id,b.status as good_status')
+            ->leftJoin('good b', 'b.id=a.good_id AND b.is_del=' . CommonModel::$del_normal)
+            ->withAttr('good_banner_img', function ($val) {
+                return explode(',', $val);
+            })->withAttr('good_img', function ($val) {
+                return explode(',', $val);
+            })->withAttr('good_param', function ($val) {
+                return json_decode($val);
+            })
+            ->where(['a.id' => $id])
             ->findOrEmpty()
             ->toArray();
 

+ 12 - 2
app/admin/logic/InventoryShoppingLogic.php

@@ -97,11 +97,21 @@ class InventoryShoppingLogic extends BaseLogic
     //获取商城商品库存详情
     public static function read(int $id = 0): Json
     {
-        $res = InventoryShoppingModel::field(true)
-            ->where('id', $id)
+        $res = InventoryShoppingModel::alias('a')
+            ->field('a.*,b.good_cover_img,b.moq,b.step,b.type,b.price,b.good_banner_img,b.good_img,b.good_param,b.good_remark,b.unit_id,b.status as good_status')
+            ->leftJoin('good b', 'b.id=a.good_id AND b.is_del=' . CommonModel::$del_normal)
+            ->withAttr('good_banner_img', function ($val) {
+                return explode(',', $val);
+            })->withAttr('good_img', function ($val) {
+                return explode(',', $val);
+            })->withAttr('good_param', function ($val) {
+                return json_decode($val);
+            })
+            ->where(['a.id' => $id])
             ->findOrEmpty()
             ->toArray();
 
+
         if (empty($res)) throw new ValidateException('该商城商品库存为空');
 
         return json_show(CommonModel::$success, '获取商城商品库存详情成功', $res);