ソースを参照

商品,下单等

lizhen_gitee 1 年間 前
コミット
145acf64c7

+ 4 - 2
addons/unishop/controller/Order.php

@@ -93,6 +93,7 @@ class Order extends Base
     {
         $productId = $this->request->post('id', 0);
 
+
         try {
             $user_id = $this->auth->id;
 
@@ -104,8 +105,9 @@ class Order extends Base
                 $spec = $this->request->post('spec', '');
                 $productData[0] = $product->getDataOnCreateOrder($spec);
             } else {
+                $this->error();
                 // 多个商品
-                $cart = $this->request->post('cart');
+                /*$cart = $this->request->post('cart');
                 $carts = (new \addons\unishop\model\Cart)
                     ->whereIn('id', $cart)
                     ->with(['product'])
@@ -115,7 +117,7 @@ class Order extends Base
                     if ($cart->product instanceof Product) {
                         $productData[] = $cart->product->getDataOnCreateOrder($cart->spec ? $cart->spec : '', $cart->number);
                     }
-                }
+                }*/
             }
 
             if (empty($productData) || !$productData) {

+ 72 - 62
addons/unishop/controller/Product.php

@@ -16,7 +16,7 @@ use think\Db;
  */
 class Product extends Base
 {
-    protected $noNeedLogin = ['detail', 'lists','index_sifang'];
+    protected $noNeedLogin = ['detail', 'lists','index_sifang','cate_list'];
 
     /**
      * @ApiTitle    (产品详情)
@@ -49,69 +49,68 @@ class Product extends Base
      */
     public function detail()
     {
-        $productId = $this->request->get('id');
-//        $productId = \addons\unishop\extend\Hashids::decodeHex($productId);
+        $productId = $this->request->request('id');
+        $productId = \addons\unishop\extend\Hashids::decodeHex($productId);
 
-        try {
 
-            $productModel = new productModel();
-            $data = $productModel->where(['id' => $productId])->cache(10)->find();
-            if (!$data) {
-                $this->error(__('Goods not exist'));
-            }
-            if ($data['switch'] == productModel::SWITCH_OFF) {
-                $this->error(__('Goods are off the shelves'));
-            }
 
-            // 真实浏览量加一
-            $data->real_look++;
-            $data->look++;
-            $data->save();
-
-            //服务
-            $server = explode(',', $data->server);
-            $configServer = json_decode(Config::getByName('server')['value'],true);
-            $serverValue = [];
-            foreach ($server as $k => $v) {
-                if (isset($configServer[$v])) {
-                    $serverValue[] = $configServer[$v];
-                }
+        $productModel = new productModel();
+        $data = $productModel->where(['id' => $productId])->cache(10)->find();
+        if (!$data) {
+            $this->error(__('Goods not exist'));
+        }
+        if ($data['switch'] == productModel::SWITCH_OFF) {
+            $this->error(__('Goods are off the shelves'));
+        }
+
+        // 真实浏览量加一
+        $data->real_look++;
+        $data->look++;
+        $data->save();
+
+        //服务
+        /*$server = explode(',', $data->server);
+        $configServer = json_decode(Config::getByName('server')['value'],true);
+        $serverValue = [];
+        foreach ($server as $k => $v) {
+            if (isset($configServer[$v])) {
+                $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])
-                ->field('COUNT(*) as count, IFNULL(CEIL(AVG(rate)/5*100),0) as avg')
-                ->cache(10)->find();
+        // 评价
+        $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();
 
-            //优惠券
-            $data->coupon = (new Coupon)->where('endtime', '>', time())
-                ->where(['switch' => Coupon::SWITCH_ON])->cache(10)->order('weigh DESC')->select();
 
-            // 是否已收藏
-            if ($this->auth->id) {
-                $data->favorite = (new Favorite)->where(['user_id' => $this->auth->id, 'product_id' => $productId])->count();
-            }
+        //优惠券
+        /*$data->coupon = (new Coupon)->where('endtime', '>', time())
+            ->where(['switch' => Coupon::SWITCH_ON])->cache(10)->order('weigh DESC')->select();*/
 
-            // 购物车数量
-            $data->cart_num = (new \addons\unishop\model\Cart)->where(['user_id' => $this->auth->id])->count();
-
-            // 评价信息
-            $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());
+        // 是否已收藏
+        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();
+
+        // 评价信息
+        $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'])->limit(2)->select();
+        if ($evaluate) {
+            $data->evaluate_list = collection($evaluate)->append(['createtime_text'])->toArray();
+        }
+        $data = $data->append(['images_text', 'spec_list', 'spec_table_list'])->toArray();
+
         $this->success('', $data);
     }
 
@@ -141,12 +140,16 @@ class Product extends Base
         $desc = $this->request->request('desc', 'desc');
 
         $cate_id = $this->request->request('cate_id',0,'intval');
+        $tag_id  = $this->request->request('tag_id',0,'intval');
 
         $productModel = new productModel();
 
         if($cate_id != 0){
             $productModel->where(['cate_id' => $cate_id]);
         }
+        if($tag_id != 0){
+            $productModel->where('find_in_set(:tag_ids,tag_ids)', ['tag_ids' => $tag_id]);
+        }
 
         $result = $productModel
             ->where(['switch' => productModel::SWITCH_ON])
@@ -165,24 +168,31 @@ class Product extends Base
 
     //首页商品四方列表
     public function index_sifang(){
+        $productModel = new productModel();
         //四个标签的商品
-        $tag1 = Db::name('unishop_product')->field('id,image')->where('find_in_set(:tag_ids,tag_ids)', ['tag_ids' => 1])->where(['switch' => productModel::SWITCH_ON])->limit(2)->order('weigh desc,id desc')->select();
-        $tag2 = Db::name('unishop_product')->field('id,image')->where('find_in_set(:tag_ids,tag_ids)', ['tag_ids' => 2])->where(['switch' => productModel::SWITCH_ON])->limit(2)->order('weigh desc,id desc')->select();
-        $tag3 = Db::name('unishop_product')->field('id,image')->where('find_in_set(:tag_ids,tag_ids)', ['tag_ids' => 3])->where(['switch' => productModel::SWITCH_ON])->limit(2)->order('weigh desc,id desc')->select();
-        $tag4 = Db::name('unishop_product')->field('id,image')->where('find_in_set(:tag_ids,tag_ids)', ['tag_ids' => 4])->where(['switch' => productModel::SWITCH_ON])->limit(2)->order('weigh desc,id desc')->select();
+        $tag1 = $productModel->field('id,image')->where('find_in_set(:tag_ids,tag_ids)', ['tag_ids' => 1])->where(['switch' => productModel::SWITCH_ON])->limit(2)->order('weigh desc,id desc')->select();
+        $tag2 = $productModel->field('id,image')->where('find_in_set(:tag_ids,tag_ids)', ['tag_ids' => 2])->where(['switch' => productModel::SWITCH_ON])->limit(2)->order('weigh desc,id desc')->select();
+        $tag3 = $productModel->field('id,image')->where('find_in_set(:tag_ids,tag_ids)', ['tag_ids' => 3])->where(['switch' => productModel::SWITCH_ON])->limit(2)->order('weigh desc,id desc')->select();
+        $tag4 = $productModel->field('id,image')->where('find_in_set(:tag_ids,tag_ids)', ['tag_ids' => 4])->where(['switch' => productModel::SWITCH_ON])->limit(2)->order('weigh desc,id desc')->select();
 
 
 
         $result = [
-            'tuijian' => list_domain_image($tag1,['image']),
-            'remen'   => list_domain_image($tag2,['image']),
-            'shoufa'  => list_domain_image($tag3,['image']),
-            'cuxiao'  => list_domain_image($tag4,['image']),
+            'tuijian' => $tag1,
+            'remen'   => $tag2,
+            'shoufa'  => $tag3,
+            'cuxiao'  => $tag4,
         ];
 
         $this->success(1,$result);
     }
 
+    //分类列表
+    public function cate_list(){
+        $list = Db::name('unishop_cate')->order('id asc')->select();
+        $this->success(1,$list);
+    }
+
 
 
     /**

+ 0 - 1
addons/unishop/model/Ads.php

@@ -30,7 +30,6 @@ class Ads extends Model
      * 更改字段的值
      */
     public function getProductIdAttr($value) {
-        return $value;
         return Hashids::encodeHex($value);
     }
 }

+ 1 - 2
addons/unishop/model/Product.php

@@ -48,7 +48,7 @@ class Product extends Model
         //'images_text',
         //'spec_list',
         //'spec_table_list',
-//        'product_id'
+        'product_id'
     ];
 
     // 隐藏属性
@@ -77,7 +77,6 @@ class Product extends Model
      * @return string
      */
     public function getProductIdAttr($value, $data) {
-        return $data['id'];
         return Hashids::encodeHex($data['id']);
     }
 

+ 1 - 1
application/common/library/Auth.php

@@ -410,7 +410,7 @@ class Auth
 
         //追加
         $userinfo['avatar'] = one_domain_image($userinfo['avatar']);
-//        $userinfo['money'] = model('wallet')->getWallet($this->id,'money');
+        $userinfo['score'] = model('wallet')->getWallet($this->id,'score');
 
         return $userinfo;
     }

+ 2 - 0
application/config.php

@@ -310,6 +310,8 @@ return [
 
     //图片地址
     'domain_cdnurl' => 'http://mingxiang.huxiukeji.cn',
+    //h5页面地址
+    'h5_url' => 'http://mingxiangweb.huxiukeji.cn',
 
     //小程序
     'wxMiniProgram' => [