瀏覽代碼

设置商品数量显示

afa 9 月之前
父節點
當前提交
dcc6dd9973

+ 5 - 0
application/admin/controller/product/Lists.php

@@ -57,6 +57,11 @@ class Lists extends Backend
             ->where($where)
             ->order($sort, $order)
             ->paginate($limit);
+        foreach ($list as &$item) {
+            $item['total_num']= $this->productArea::where('product_id', $item->id)->count();
+            $item['sell_num'] = $this->productArea::where('product_id', $item->id)->where('status', $this->productArea::STOP)->count();
+        }
+
         $result = ['total' => $list->total(), 'rows' => $list->items()];
         return json($result);
     }

+ 6 - 0
application/common/model/ProductLists.php

@@ -37,6 +37,12 @@ class ProductLists extends Model
         self::NORMAL            => '正常'
     ];
 
+    //地区
+    public function productArea()
+    {
+        return $this->hasMany('ProductArea', 'product_id', 'id');
+    }
+
     //分类
     public function products()
     {

+ 2 - 0
public/assets/js/backend/product/lists.js

@@ -63,6 +63,8 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'area', 'vue', 'ELEME
                                 };
                             }
                         },
+                        { field: 'total_num', title: __('总设置数量'), operate: false },
+                        { field: 'sell_num', title: __('已出售数量'), operate: false },
                         { field: 'thum', title: __('Thum'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images },
                         { field: 'weigh', title: __('Weigh'), operate: false },
                         { field: 'status', title: __('Status'), searchList: { "1": __('上架'), "0": __('下架') }, formatter: Table.api.formatter.toggle },