Просмотр исходного кода

订单评论列表-增加订单、商户信息

sunxiaobiao 1 год назад
Родитель
Сommit
82cc7869f2
1 измененных файлов с 45 добавлено и 2 удалено
  1. 45 2
      app/common/repositories/store/product/ProductReplyRepository.php

+ 45 - 2
app/common/repositories/store/product/ProductReplyRepository.php

@@ -256,8 +256,51 @@ class ProductReplyRepository extends BaseRepository
256 256
 
257 257
     /*用户评价列表*/
258 258
     public function  getReplyList($where=[],$page=1, $limit=10){
259
-        $count =  Db::name("store_product_reply")->where($where)->count();
260
-        $list = Db::name("store_product_reply")->page($page, $limit)->where($where)->select();
259
+        $count = Db::name("store_product_reply")
260
+            ->where($where)
261
+            ->count();
262
+        $list = Db::name("store_product_reply")
263
+            //            ->alias('spr')  // 给主表起个别名
264
+            //            ->join('store_order_product rsop', 'spr.order_product_id = rsop.order_product_id', 'LEFT')  // 左连接
265
+            //            ->field('spr.*, rsop.*')
266
+            ->where($where)
267
+            ->page($page, $limit)
268
+            ->select()
269
+            ->toArray();
270
+
271
+        $order_product_id_list = array_column($list,'order_product_id');
272
+        $order_product_info_list = Db::name("store_order_product")
273
+            ->whereIn('order_product_id',$order_product_id_list)
274
+            ->select()
275
+            ->toArray();
276
+        $order_product_info_map = array_column($order_product_info_list, null, 'order_product_id');
277
+
278
+        $mer_id_list = array_column($list,'mer_id');
279
+        $mer_info_list = Db::name("merchant")
280
+            ->whereIn('mer_id',$mer_id_list)
281
+            ->select()
282
+            ->toArray();
283
+        $mer_info_map = array_column($mer_info_list, null, 'mer_id');
284
+
285
+        foreach ($list as &$item) {
286
+            if (!empty($order_product_info_map[$item['order_product_id']])) {
287
+                if (!empty($order_product_info_map[$item['order_product_id']]['cart_info'])) {
288
+                    $cart_info = json_decode($order_product_info_map[$item['order_product_id']]['cart_info']);
289
+                    if (json_last_error() == JSON_ERROR_NONE) {
290
+                        $order_product_info_map[$item['order_product_id']]['cart_info'] = $cart_info;
291
+                    }
292
+                }
293
+                $item['order_product_info'] = $order_product_info_map[$item['order_product_id']];
294
+            } else {
295
+                $item['order_product_info'] = new \stdClass();
296
+            }
297
+
298
+            if (!empty($mer_info_map[$item['mer_id']])) {
299
+                $item['mer_info'] = $mer_info_map[$item['mer_id']];
300
+            } else {
301
+                $item['mer_info'] = new \stdClass();
302
+            }
303
+        }
261 304
         return compact('count', 'list');
262 305
     }
263 306
 }