Selaa lähdekoodia

购物车列表

linshuohong 3 vuotta sitten
vanhempi
commit
67bb416d3e
3 muutettua tiedostoa jossa 36 lisäystä ja 17 poistoa
  1. 33 14
      app/common/cart/CartRepository.php
  2. 2 2
      app/controller/cart/Index.php
  3. 1 1
      route/app.php

+ 33 - 14
app/common/cart/CartRepository.php

@@ -110,23 +110,42 @@ class CartRepository extends BaseRepository
110 110
      * @return array
111 111
      */
112 112
     public function getListFromUid($uid){
113
-        //SELECT * FROM `rrx_store_product` `rsp` INNER JOIN `rrx_store_product_attr_value` `rspav` ON `rsp`.`product_id`=`rspav`.`product_id` WHERE  `rsp`.`product_id` = '434'  AND `rspav`.`unique` = 'f53eccfdd090' LIMIT 1
114
-        $list = Db::query("select * from `rrx_store_cart` `rsc`
115
-         INNER JOIN `rrx_store_product_attr` `rspa` on `rsc`.``
116
-         where 
117
-             `uid`=? and 
118
-             `is_del`=? and 
119
-             `is_new`=? and 
120
-             `is_pay`=?"
121
-            ,[$uid,0,0,0]);
122
-        $this -> formatCartList($list);
123
-        return [];
113
+        $list = Db::query("select
114
+                `rsc`.`cart_num`,`rsc`.`cart_id`,
115
+                `rm`.`mer_id`,`rm`.`mer_name`,`rm`.`mer_avatar`,
116
+                 `rspav`.`product_id`,`rspav`.`price`,`rspav`.`unique`,`rspav`.`sku`,`rspav`.`image`
117
+                 from `rrx_store_cart` `rsc`
118
+                 left JOIN `rrx_store_product_attr_value` `rspav` on `rsc`.`product_attr_unique` = `rspav`.`unique`
119
+                 left JOIN `rrx_merchant` `rm` on `rsc`.`mer_id` = `rm`.`mer_id`
120
+                 where
121
+                     `rsc`.`uid`=? and
122
+                     `rsc`.`is_del`=? and
123
+                     `rsc`.`is_new`=? and
124
+                     `rsc`.`is_pay`=?"
125
+                    ,[$uid,0,0,0]);
126
+//        $list = Db::query("select * from `rrx_store_cart` where `uid`=? and `is_del`=? and `is_new`=? and `is_pay`=?",[$uid,0,0,0]);
127
+        return $this -> formatCartList($list);
124 128
     }
125 129
 
126 130
     //购物车列表格式化
127
-    public function formatCartList(&$list){
128
-        dump($list);
129
-//        foreach
131
+    public function formatCartList($list){
132
+        $arr = [];
133
+        foreach($list as $key => $item){
134
+            if (empty($item['image']))$item['image'] = $this -> getProductImage($item['product_id']);
135
+//            $arr[$item['mer_id']]['list'][] = $item;
136
+            $mer_id = $item['mer_id'];
137
+            $arr[$mer_id]['mer_id'] = $item['mer_id'];
138
+            $arr[$mer_id]['mer_name'] = $item['mer_name'];
139
+            $arr[$mer_id]['mer_avatar'] = $item['mer_avatar'];
140
+            unset($item['mer_id'],$item['mer_name'],$item['mer_avatar']);
141
+            $arr[$mer_id]['list'][] = $item;
142
+        }
143
+        return array_values($arr);
144
+    }
145
+
146
+    public function getProductImage($productId){
147
+        $product = Db::query("select image from `rrx_store_product` where `product_id`=?",[$productId]);
148
+        return $product[0]['image']??'';
130 149
     }
131 150
 
132 151
 }

+ 2 - 2
app/controller/cart/Index.php

@@ -64,7 +64,7 @@ class Index extends BaseController
64 64
     public function cartList(){
65 65
         $uid = $this -> request -> uid();
66 66
         $cartRepository = new CartRepository();
67
-        $cartRepository -> getListFromUid($uid);
68
-
67
+        $list = $cartRepository -> getListFromUid($uid);
68
+        return app('json')->success($list);
69 69
     }
70 70
 }

+ 1 - 1
route/app.php

@@ -20,6 +20,6 @@ Route::group(function (){
20 20
 
21 21
     Route::post('createCart','cart.Index/createCart');//创建购物车
22 22
     Route::post('changeCart','cart.Index/changeCart');//修改购物车数量
23
-    Route::get('cartList','cart.Index/cartList');//购物车列表
23
+    Route::post('cartList','cart.Index/cartList');//购物车列表
24 24
 
25 25
 })->middleware(\app\middleware\UserTokenMiddleware::class);