Browse Source

产品热销

afa 11 months ago
parent
commit
4152311353

+ 4 - 7
application/admin/controller/product/Lists.php

@@ -61,7 +61,7 @@ class Lists extends Backend
     }
 
 
-        /**
+    /**
      * 添加
      *
      * @return string
@@ -90,11 +90,9 @@ class Lists extends Backend
                 $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
                 $this->model->validateFailException()->validate($validate);
             }
-           
-            $areaArr = json_decode($params['product_area']);
+            $areaArr = json_decode($params['product_area'], true);
             if(empty($areaArr)) throw new ValidateException('请添加商品关联地区');
             if(self::isEqualArea($areaArr) == false) throw new ValidateException('该商品地区存在重复');
-           
             unset($params['product_area']);
             //商品
             $add   = $this->model->create($params);
@@ -152,9 +150,8 @@ class Lists extends Backend
                 $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
                 $row->validateFailException()->validate($validate);
             }
-            $areaArr = json_decode($params['product_area']);
-
-            dump($params );die;
+            
+            $areaArr = json_decode($params['product_area'], true);
             if(empty($areaArr)) throw new ValidateException('请添加商品关联地区');
             if(self::isEqualArea($areaArr) == false) throw new ValidateException('该商品地区存在重复');
             unset($params['product_area']);

+ 5 - 2
application/admin/controller/product/Popular.php

@@ -51,7 +51,7 @@ class Popular extends Backend
             return $this->selectpage();
         }
         [$where, $sort, $order, $offset, $limit] = $this->buildparams();
-        $list = $this->model
+        $list = $this->model->with('productsList')
             ->where($where)
             ->order($sort, $order)
             ->paginate($limit);
@@ -89,7 +89,8 @@ class Popular extends Backend
                 $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
                 $this->model->validateFailException()->validate($validate);
             }
-        
+            if(time() >= strtotime($params['start_time'])) $params['status'] = $this->model::NORMAL;
+            if(time() >= strtotime($params['end_time'])) $params['status'] = $this->model::STOP;
             $params['stock'] = ProductArea::getProductStock($params['product_id']);
             $result = $this->model->allowField(true)->save($params);
             Db::commit();
@@ -138,6 +139,8 @@ class Popular extends Backend
                 $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
                 $row->validateFailException()->validate($validate);
             }
+            if(time() >= strtotime($params['start_time'])) $params['status'] = $this->model::NORMAL;
+            if(time() >= strtotime($params['end_time'])) $params['status'] = $this->model::STOP;
             $params['stock'] = ProductArea::getProductStock($params['product_id']);
             $result = $row->allowField(true)->save($params);
             Db::commit();

+ 1 - 1
application/api/controller/User.php

@@ -78,7 +78,7 @@ class User extends Api
               ->join("product_list b", "b.id = a.product_id", "left")
               ->join("products c", "c.id = b.type_id", "left")
               ->field('a.id as order_id,a.product_id,'.'b.'.$this->lan.'_name,b.images as img_url,a.price,a.status,a.type_id,c.'.$this->lan.'_title')
-              ->where('a.user_id', 1008)
+              ->where('a.user_id', $this->auth->id)
               ->order('a.id DESC')
               ->paginate($this->pageSize);
      

+ 1 - 1
application/common/model/ProductLists.php

@@ -40,7 +40,7 @@ class ProductLists extends Model
     //分类
     public function products()
     {
-        return $this->belongsTo('ProductsModel', 'id', 'zh_name', [], 'LEFT')->setEagerlyType(0);
+        return $this->hasOne('ProductsModel', 'id', 'type_id', [], 'LEFT')->setEagerlyType(0);
     }
 
 

+ 4 - 2
application/common/model/ProductPopular.php

@@ -60,10 +60,12 @@ class ProductPopular extends Model
 
 
 
-    public function employees()//yewu为第一张表的字段,employee_num为第二张表的字段
+    //分类
+    public function productsList()
     {
-        return $this->belongsTo('app\admin\model\setting\Employees', 'yewu', 'employee_num', [], 'LEFT')->setEagerlyType(0);
+        return $this->hasOne('ProductLists', 'id', 'product_id', [], 'LEFT')->setEagerlyType(0);
     }
+ 
 
     protected static function init()
     {

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

@@ -11,6 +11,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'selectpage'], functi
                     del_url: 'product/lists/del',
                     multi_url: 'product/lists/multi',
                     import_url: 'product/lists/import',
+                    dragsort_url: "",
                     table: 'product_list',
                 }
             });
@@ -28,7 +29,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'selectpage'], functi
                     [
                         {checkbox: true},
                         {field: 'id', title: __('Id')},
-                        {field: 'type_id', title: __('Type_id')},
+                        {field: 'products.zh_title', title: __('Type_id'), operate: false},
                         {field: 'zh_name', title: __('Zh_name'), operate: false,
                             formatter : function(value, row, index, field){
                                 return "<span style='display: block;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;' title='" + row.zh_name + "'>" + value + "</span>";

+ 2 - 2
public/assets/js/backend/product/popular.js

@@ -28,7 +28,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                     [
                         {checkbox: true},
                         {field: 'id', title: __('Id')},
-                        {field: 'product_id', title: __('Product_id')},
+                        {field: 'products_list.zh_name', title: __('Product_id'), operate: false},
                         {field: 'title', title: __('期数')},
                         {field: 'price', title: __('Price'), operate: false},
                         {field: 'cost_price', title: __('Cost_price'), operate:false},
@@ -36,7 +36,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                         {field: 'weigh', title: __('Weigh'), operate: false},
                         {field: 'start_time', title: __('Start_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                         {field: 'end_time', title: __('End_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
-                        {field: 'status', title: __('Status')},
+                        {field: 'status', title: __('Status'), searchList: {'0': '未开始','1': '进行中',   '2': '已结束'}, operate: 'FIND_IN_SET', formatter: Table.api.formatter.label},
                         {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                         {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                         {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}

+ 0 - 1
public/assets/js/backend/product/products.js

@@ -8,7 +8,6 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                     index_url: 'product/products/index' + location.search,
                     add_url: 'product/products/add',
                     edit_url: 'product/products/edit',
-
                     multi_url: 'product/products/multi',
                     import_url: 'product/products/import',
                     table: 'products',