ソースを参照

商品库存列表优化,增加商品相关字段

wufeng 2 年 前
コミット
71ed28e97f
1 ファイル変更9 行追加7 行削除
  1. 9 7
      app/admin/logic/InventoryShoppingLogic.php

+ 9 - 7
app/admin/logic/InventoryShoppingLogic.php

@@ -17,19 +17,21 @@ class InventoryShoppingLogic extends BaseLogic
     //获取商城商品库存列表
     public static function list(array $data = []): Json
     {
-        $db = new InventoryShoppingModel();
+        $db = InventoryShoppingModel::alias('a')
+            ->leftJoin('good b', 'b.id=a.good_id AND b.is_del=' . CommonModel::$del_normal)
+            ->leftJoin('unit c', 'c.id=b.unit_id AND c.is_del=' . CommonModel::$del_normal);
 
-        if ($data['good_name'] != '') $db = $db->whereLike('good_name', '%' . $data['good_name'] . '%');
+        if ($data['good_name'] != '') $db = $db->whereLike('a.good_name', '%' . $data['good_name'] . '%');
         if (($data['inventory_start'] != '') && ($data['inventory_end'] != '')) {
-            $db = $db->whereBetween('inventory', [$data['inventory_start'], $data['inventory_end']]);
+            $db = $db->whereBetween('a.inventory', [$data['inventory_start'], $data['inventory_end']]);
 
         }
 
-        $count = $db->count('id');
+        $count = $db->count('a.id');
 
-        $list = $db->field(true)
+        $list = $db->field('a.*,b.good_cover_img,b.moq,b.step,b.type,b.price,b.good_remark,c.unit')
             ->page($data['page'], $data['size'])
-            ->order(['id' => 'desc'])
+            ->order(['a.id' => 'desc'])
             ->select()
             ->toArray();
 
@@ -100,7 +102,7 @@ class InventoryShoppingLogic extends BaseLogic
         $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,c.unit,b.status as good_status')
             ->leftJoin('good b', 'b.id=a.good_id AND b.is_del=' . CommonModel::$del_normal)
-            ->leftJoin('unit c','c.id=b.unit_id AND c.is_del='.CommonModel::$del_normal)
+            ->leftJoin('unit c', 'c.id=b.unit_id AND c.is_del=' . CommonModel::$del_normal)
             ->withAttr('good_banner_img', function ($val) {
                 return explode(',', $val);
             })->withAttr('good_img', function ($val) {