afa 2 сар өмнө
parent
commit
2205561a61

+ 1 - 2
application/admin/controller/product/Lists.php

@@ -54,13 +54,12 @@ class Lists extends Backend
         }
 
         [$where, $sort, $order, $offset, $limit] = $this->buildparams();
-        $list = $this->model->with('products')->with('productarea')->with('productareastop')->with('productorder')
+        $list = $this->model->with('products')->with('productarea')->with('productareastop')//->with('productorder')
             ->where($where)
             ->order($sort, $order)
             ->paginate($limit);
 
         foreach ($list as &$item) {
-            $item['hold_num'] = $item->productorder? count($item->productorder): 0;//持有数量
             $item['total_num']= $item->productarea? count($item->productarea): 0;
             $item['sell_num'] = $item->productareastop? count($item->productareastop): 0;
         }

+ 12 - 0
application/admin/controller/product/Orders.php

@@ -55,6 +55,7 @@ class Orders extends Backend
             ->group('user_id')
             ->order($sort, $order)
             ->paginate($limit);
+
    
  
         $result = ['total' => $list->total(), 'rows' => $list->items()];
@@ -62,4 +63,15 @@ class Orders extends Backend
     }
 
 
+    //获取产品总数量
+    public function getTotalNum()
+    {
+        $product_id = $this->request->param('product_id');
+        $count = $this->model
+            ->where('product_id', $product_id)
+            ->where('status', 'in', [$this->model::Paid, $this->model::Transferred, $this->model::Freeze])
+            ->count();
+        return json(['totalNum'=>$count]);
+    }
+
 }

+ 3 - 3
application/admin/view/product/orders/index.html

@@ -7,9 +7,9 @@
                 <div class="widget-body no-padding">
                     <div id="toolbar" class="toolbar">
                         <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
-            
-
-                        
+                        <a href="javascript:;" class="btn btn-default" style="color:#27C24C;">
+                            <span class="extend">持有总数量:: <span id="total_num" >0</span></span>
+                        </a>
                     </div>
                     <table id="table" class="table table-striped table-bordered table-hover table-nowrap"
                 

+ 21 - 5
application/common/model/ProductOrder.php

@@ -60,13 +60,29 @@ class ProductOrder extends Model
     //抢购下单:未选择地区购买
     public static function setPopularNoAreaOrder($num, $orderId, $price, $productId, $uid, $typeId):bool
     {
+        $data = [];
+        //抢购订单
+        $time = time();
+        $is_popular = ($typeId == self::Popular)? self::Paid : 0;
         for ($i = 0; $i < $num; $i++) {
-            $order_arr['price']     = $price;
-            $order_arr['product_id']= $productId;
-            $order_arr['area_id']   = 0;
-            self::setCreateOrder($orderId, $order_arr, $typeId, $uid, 0, getOrderSN('R'.$i), 0, $price);
+            $data[] = [
+                'order_id' => $orderId, 
+                'product_id' => $productId, 
+                'type_id' => $typeId, 
+                'status' => self::Paid, 
+                'area_id' => 0, 
+                'price' => $price, 
+                'popular_price' => $price, 
+                'fees'          => 0, 
+                'num'           => 1, 
+                'user_id'    => $uid,
+                'order_no'   => getOrderSN('R'.$i),
+                'is_popular' => $is_popular,
+                'create_time' => $time,
+                'update_time' => $time
+            ];
         }
-        return true;
+        return self::insertAll($data);
     }
 
 

+ 1 - 1
public/assets/js/backend/product/lists.js

@@ -49,7 +49,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'area',  ], function
                         },
                         {field: 'total_num', title: __('总设置数量'), operate: false },
                         {field: 'sell_num', title: __('已出售数量'), operate: false },
-                        {field: 'hold_num', title: __('持有数量'), operate: false },
+                        //{field: 'hold_num', title: __('持有数量'), operate: false },
                         {field: 'min_transfer_fee', title: __('寄售转让费'), operate: false, formatter: function (value, row, index, field) {
                             return row.min_transfer_fee+ "~"+ row.max_transfer_fee;
                         }},

+ 11 - 4
public/assets/js/backend/product/orders.js

@@ -18,22 +18,19 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                 pk: 'id',
                 sortName: 'id',
                 fixedColumns: false,
-         
                 columns: [
                     [
                         {checkbox: true},
                         {field: 'user_id', title: __('用户Id'), operate: 'LIKE'},
                         {field: 'users.address', title: __('用户地址'), operate: 'LIKE'},
                         {field: 'total_num', title: __('持有数量'), operate: false},
-       
-                     
-
                     ]
                 ]
             });
 
             // 为表格绑定事件
             Table.api.bindevent(table);
+            //total_num
         },
   
         api: {
@@ -42,5 +39,15 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
             }
         }
     };
+    setTimeout(getTotalNum, 500);
     return Controller;
 });
+
+function getTotalNum(){
+
+    $.post("product/orders/getTotalNum",{'product_id':Config.ids},
+        function (data) {
+            $("#total_num").text(data.totalNum);
+    })
+
+}