Browse Source

产品接口

lizhen_gitee 7 months ago
parent
commit
b0b1e7459a

+ 13 - 3
addons/unishop/controller/Category.php

@@ -3,7 +3,7 @@
 namespace addons\unishop\controller;
 
 use app\common\controller\Api;
-
+use think\Db;
 /**
  * 分类
  */
@@ -42,7 +42,6 @@ class Category extends Api
             ->where('status','normal')
             ->field('id,name,pid,image,type,flag,weigh')
             ->order('weigh ASC')
-            ->cache(20)
             ->select();
         if ($all) {
             $all = collection($all)->toArray();
@@ -50,6 +49,18 @@ class Category extends Api
         $this->success('',$all);
     }
 
+    public function inlist(){
+        $list = Db::name('unishop_category')
+            ->where('status','normal')
+            ->field('id,name,image')
+            ->order('weigh ASC')
+            ->select();
+        $list = list_domain_image($list,['image']);
+
+        $this->success(1,$list);
+    }
+
+
 
     /**
      * @ApiTitle    (首页广告下面的分类)
@@ -72,7 +83,6 @@ class Category extends Api
         $list = $this->model
             ->where('flag','index')
             ->where('status','normal')
-            ->cache(20)
             ->select();
         if ($list) {
             $list = collection($list)->toArray();

+ 26 - 26
addons/unishop/controller/Product.php

@@ -48,13 +48,13 @@ class Product extends Base
      */
     public function detail()
     {
-        $productId = $this->request->get('id');
+        $productId = input('id');
         $productId = \addons\unishop\extend\Hashids::decodeHex($productId);
 
         try {
 
             $productModel = new productModel();
-            $data = $productModel->where(['id' => $productId])->cache(10)->find();
+            $data = $productModel->where(['id' => $productId])->find();
             if (!$data) {
                 $this->error(__('Goods not exist'));
             }
@@ -68,7 +68,7 @@ class Product extends Base
             $data->save();
 
             //服务
-            $server = explode(',', $data->server);
+            /*$server = explode(',', $data->server);
             $configServer = json_decode(Config::getByName('server')['value'],true);
             $serverValue = [];
             foreach ($server as $k => $v) {
@@ -76,37 +76,37 @@ class Product extends Base
                     $serverValue[] = $configServer[$v];
                 }
             }
-            $data->server = count($serverValue) ? implode(' · ', $serverValue) : '';
+            $data->server = count($serverValue) ? implode(' · ', $serverValue) : '';*/
 
             // 默认没有收藏
-            $data->favorite = false;
+//            $data->favorite = false;
 
             // 评价
-            $data['evaluate_data'] = (new Evaluate)->where(['product_id' => $productId])
+            /*$data['evaluate_data'] = (new Evaluate)->where(['product_id' => $productId])
                 ->field('COUNT(*) as count, IFNULL(CEIL(AVG(rate)/5*100),0) as avg')
-                ->cache(10)->find();
+                ->find();*/
 
             //优惠券
             $data->coupon = (new Coupon)->where('endtime', '>', time())
-                ->where(['switch' => Coupon::SWITCH_ON])->cache(10)->order('weigh DESC')->select();
+                ->where(['switch' => Coupon::SWITCH_ON])->order('weigh DESC')->select();
 
             // 是否已收藏
-            if ($this->auth->id) {
+            /*if ($this->auth->id) {
                 $data->favorite = (new Favorite)->where(['user_id' => $this->auth->id, 'product_id' => $productId])->count();
-            }
+            }*/
 
             // 购物车数量
-            $data->cart_num = (new \addons\unishop\model\Cart)->where(['user_id' => $this->auth->id])->count();
+//            $data->cart_num = (new \addons\unishop\model\Cart)->where(['user_id' => $this->auth->id])->count();
 
             // 评价信息
-            $evaluate = (new Evaluate)->alias('e')
+            /*$evaluate = (new Evaluate)->alias('e')
                 ->join('user u', 'e.user_id = u.id')
                 ->where(['e.product_id' => $productId, 'toptime' => ['>', Evaluate::TOP_OFF]])
                 ->field('u.username,u.avatar,e.*')
                 ->order(['toptime' => 'desc', 'createtime' => 'desc'])->select();
             if ($evaluate) {
                 $data->evaluate_list = collection($evaluate)->append(['createtime_text'])->toArray();
-            }
+            }*/
             $data = $data->append(['images_text', 'spec_list', 'spec_table_list'])->toArray();
         } catch (Exception $e) {
             $this->error($e->getMessage());
@@ -134,13 +134,13 @@ class Product extends Base
      */
     public function lists()
     {
-        $page = $this->request->get('page', 1);
-        $pagesize = $this->request->get('pagesize', 20);
-        $by = $this->request->get('by', 'weigh');
-        $desc = $this->request->get('desc', 'desc');
+        $page = input('page', 1);
+        $pagesize = input('pagesize', 20);
+        $by = input('by', 'weigh');
+        $desc = input('desc', 'desc');
 
-//        $sid = $this->request->get('sid'); // 二级分类Id
-        $fid = $this->request->get('fid'); // 一级分类Id
+//        $sid = input('sid'); // 二级分类Id
+        $fid = input('fid'); // 一级分类Id
 
         $productModel = new productModel();
 
@@ -160,7 +160,7 @@ class Product extends Base
             ->where(['switch' => productModel::SWITCH_ON])
             ->page($page, $pagesize)
             ->order($by, $desc)
-            ->field('id,title,image,sales_price,sales,real_sales')
+            ->field('id,title,info,image,sales_price,use_spec')
             ->select();
 
         if ($result) {
@@ -182,7 +182,7 @@ class Product extends Base
      */
     public function favorite()
     {
-        $id = $this->request->get('id', 0);
+        $id = input('id', 0);
         $id = \addons\unishop\extend\Hashids::decodeHex($id);
 
         $user_id = $this->auth->id;
@@ -235,8 +235,8 @@ class Product extends Base
      */
     public function favoriteList()
     {
-        $page = $this->request->get('page', 1);
-        $pageSize = $this->request->get('pagesize', 20);
+        $page = input('page', 1);
+        $pageSize = input('pagesize', 20);
 
         $list = (new Favorite)->where(['user_id' => $this->auth->id])->with(['product'])->page($page, $pageSize)->select();
 
@@ -281,9 +281,9 @@ class Product extends Base
      */
     public function evaluate()
     {
-        $page = $this->request->get('page', 1);
-        $pageSize = $this->request->get('pagesize', 20);
-        $productId = $this->request->get('product_id');
+        $page = input('page', 1);
+        $pageSize = input('pagesize', 20);
+        $productId = input('product_id');
         $productId = \addons\unishop\extend\Hashids::decodeHex($productId);
 
         // 评价信息

+ 1 - 0
application/admin/lang/zh-cn/unishop/product.php

@@ -4,6 +4,7 @@ return [
     'Category_id'    => '分类ID',
     'Category name'    => '分类名称',
     'Title'          => '产品标题',
+    'Info'          => '产品简介',
     'Image'          => '主图',
     'Images'         => '组图',
     'Desc'           => '详情',

+ 6 - 0
application/admin/view/unishop/product/add.html

@@ -18,6 +18,12 @@
         </div>
     </div>
     <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Info')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-info"  class="form-control" name="row[info]" type="text">
+        </div>
+    </div>
+    <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">{:__('Image')}:</label>
         <div class="col-xs-12 col-sm-8">
             <div class="input-group">

+ 6 - 0
application/admin/view/unishop/product/edit.html

@@ -18,6 +18,12 @@
         </div>
     </div>
     <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Info')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-info"  class="form-control" name="row[info]" type="text" value="{$row.info}">
+        </div>
+    </div>
+    <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">{:__('Image')}:</label>
         <div class="col-xs-12 col-sm-8">
             <div class="input-group">