牟新芬 4 years ago
parent
commit
aa812e9c3d

+ 1 - 1
app/api/controller/v1/Index.php

@@ -83,7 +83,7 @@ class Index extends BaseController
         $productValue = array_combine($keys, $productValue);
         $data['productValue'] = $productValue;
         $data['priceName'] = 0;
-        $data['good_list'] = Product::getGoodList(18, 'image,store_name,price,id,ot_price');
+        $data['good_list'] = Product::getGoodList(18, 'image,store_name,price,id,ot_price,stock,IFNULL(sales,0) + IFNULL(ficti,0) as fsales,unit_name');
         return app('json')->successful($data);
     }
 

+ 8 - 2
app/model/system/Product.php

@@ -37,8 +37,7 @@ class Product extends BaseModel
         $model = (new Product)->getWhere($where)->field([
             '*',
             '(SELECT SUM(stock) FROM table_product_attr_value WHERE product_id = table_product.id AND type = 0) as stock',
-            '(SELECT SUM(sales) FROM table_product_attr_value WHERE product_id = table_product.id AND type = 0) as sales',
-            '(SELECT stars FROM table_product_score WHERE product_id = table_product.id) as stars'
+            '(SELECT SUM(sales) FROM table_product_attr_value WHERE product_id = table_product.id AND type = 0) as sales'
         ]);
         $model = $model->page((int)$where['page'], (int)$where['limit']);
         $data = ($data = $model->select()) && count($data) ? $data->toArray() : [];
@@ -102,6 +101,13 @@ class Product extends BaseModel
             if (isset($where['cate_id']) && $where['cate_id'] != '') {
                 $model = $model->where('cate_id', $where['cate_id']);
             }
+            if (isset($where['label']) && $where['label'] != '') {
+                if($where['label'] == '3'){
+                    $model = $model->where('is_new', 1);
+                }else{
+                    $model = $model->where('stars', $where['label']);
+                }
+            }
             $model = $model->order('sort desc,id desc');
         }
         return $model;

+ 5 - 1
app/system/controller/v1/Product.php

@@ -52,6 +52,7 @@ class Product extends BaseController
             ['limit', 20],
             ['store_name', ''],
             ['cate_id', ''],
+            ['label', ''],
             ['excel', 0],
             ['type', 1]
         ]);
@@ -244,6 +245,7 @@ class Product extends BaseController
             ['issuing', 0],
             ['is_leftover', 0],
             ['is_hot', 0],
+            ['is_new', 0],
             ['is_best', 0],
             ['is_sub', 0],
             ['description', ''],
@@ -297,6 +299,7 @@ class Product extends BaseController
             $data['add_time'] = time();
             $data['code_path'] = '';
             $res = ProductModel::create($data);
+            ProductModel::where('id',$res['id'])->update(['code' => sprintf("%05d", $res['id'])]);
             if ($data['spec_type'] == 0) {
                 $attr = [
                     [
@@ -389,7 +392,7 @@ class Product extends BaseController
      */
     public function product_info($id)
     {
-        $info = ProductModel::where('id', $id)->field('id,image,price,ot_price,cost')->find()->toArray();
+        $info = ProductModel::where('id', $id)->field('id,store_name,image,price,ot_price,cost,postage')->find()->toArray();
         $score = Db::name("product_score")->where('product_id', $id)->find();
         if($score){
             $info['attribute'] = json_decode($score['attribute'], true);
@@ -409,6 +412,7 @@ class Product extends BaseController
             'stars'
         ]);
         $data["attribute"] = json_encode($data["attribute"]);
+        ProductModel::where('id', $data['product_id'])->update(['stars'=>$data["stars"]]);
         $score = Db::name("product_score")->where('product_id', $data['product_id'])->find();
         if($score){
             $res = Db::name("product_score")->where('product_id', $data['product_id'])->update($data);