Browse Source

购物车,商城首页搜索

lizhen_gitee 10 months ago
parent
commit
cc444114bd
2 changed files with 13 additions and 7 deletions
  1. 7 7
      addons/unishop/controller/Cart.php
  2. 6 0
      addons/unishop/controller/Product.php

+ 7 - 7
addons/unishop/controller/Cart.php

@@ -117,7 +117,7 @@ class Cart extends Base
      */
     public function add()
     {
-        $id = $this->request->get('id', 0);
+        $id = input('id', 0);
 
         $id = \addons\unishop\extend\Hashids::decodeHex($id);
 
@@ -126,7 +126,7 @@ class Cart extends Base
             $this->error('产品不存在或已下架');
         }
 
-        $spec = $this->request->get('spec', '');
+        $spec = input('spec', '');
         $productBase = (new \addons\unishop\extend\Product())->getBaseData($product->getData(), $spec);
         if (!$productBase['stock'] || $productBase['stock'] <= 0) {
             $this->error('库存不足');
@@ -169,7 +169,7 @@ class Cart extends Base
      */
     public function delete()
     {
-        $id = $this->request->post('id', 0);
+        $id = input('id', 0);
         $userId = $this->auth->id;
         $result = CartModel::destroy(function ($query) use ($id, $userId) {
             $query->whereIn('id', $id)->where(['user_id' => $userId]);
@@ -192,8 +192,8 @@ class Cart extends Base
      */
     public function number_change()
     {
-        $cart_id = $this->request->get('id', 0);
-        $number = $this->request->get('number', 1);
+        $cart_id = input('id', 0);
+        $number = input('number', 1);
         $cart = CartModel::get(['id' => $cart_id, 'user_id' => $this->auth->id]);
         if (empty($cart)) {
             $this->error('此商品不存在购物车');
@@ -218,8 +218,8 @@ class Cart extends Base
      */
     public function choose_change()
     {
-        $trueArr = $this->request->post('trueArr', false);
-        $falseArr = $this->request->post('falseArr', false);
+        $trueArr = input('trueArr', false);
+        $falseArr = input('falseArr', false);
         $user_id = $this->auth->id;
         try {
             $cart = new CartModel();

+ 6 - 0
addons/unishop/controller/Product.php

@@ -142,6 +142,8 @@ class Product extends Base
         $sid = input('sid'); // 二级分类Id
         $fid = input('fid'); // 一级分类Id
 
+        $keyword = input('keyword','');//搜索
+
         $productModel = new productModel();
 
         if ($fid && !$sid) {
@@ -154,6 +156,10 @@ class Product extends Base
             $sid && $productModel->where(['category_id' => $sid]);
         }
 
+        if(!empty($keyword)){
+            $productModel->where('title', 'LIKE', '%'.$keyword.'%');
+        }
+
         $result = $productModel
             ->where(['switch' => productModel::SWITCH_ON])
             ->page($page, $pagesize)