WIN-2308041133\Administrator 1 день назад
Родитель
Сommit
ad7be55c46
1 измененных файлов с 37 добавлено и 15 удалено
  1. 37 15
      app/system/controller/Shop.php

+ 37 - 15
app/system/controller/Shop.php

@@ -103,8 +103,8 @@ class Shop extends BaseController
             $where[] = ['o.time', 'between', "{$startTime},{$endTime}"];
         }
 
-        $order = Db::name('store_order');
-        $data = $order
+//        $order = Db::name('store_order');
+        $order = Db::name('store_order')
             ->alias('o')
             ->field('o.*,u.mobile,u.nickname')
             ->leftJoin('user u', 'u.uid = o.uid')
@@ -114,24 +114,46 @@ class Shop extends BaseController
             ->select()
             ->toArray();
 
-        $pageCount = $order->where($where)->count();
+        // 关联订单商品信息
+        foreach ($order as &$item) {
+            $cartInfo = Db::name('store_order_cart_info')
+                ->where('oid', $item['id'])
+                ->select()
+                ->toArray();
+            foreach ($cartInfo as &$cart) {
+                if (!empty($cart['cart_info'])) {
+                    $innerCartInfo = json_decode($cart['cart_info'], true);
+                    unset($cart['cart_info']);
+                    $cart = array_merge($cart, $innerCartInfo);
+                }
+            }
+            $item['cart_info'] = $cartInfo;
+
+            // 关联收货地址信息
+            if (!empty($item['address_id'])) {
+                $address = Db::name('user_address')->where('id', $item['address_id'])->find();
+                $item['address'] = $address ?: [];
+            } else {
+                $item['address'] = [];
+            }
+        }
+
+        $pageCount = Db::name('store_order')
+            ->alias('o')
+            ->leftJoin('user u', 'u.uid = o.uid')
+            ->where($where)
+            ->count();
 
         $result = UtilService::getParam([
             'id',
             'order_id',
             'uid',
+            'mobile',
+            'nickname',
             'real_name',
-            'user_phone',
-            'address_id',
-            'user_address',
-//            'mobile',
-//            'nickname',
-//            'real_name',
-//            'tel',
-//            'province',
-//            'city',
-//            'district',
-//            'detail',
+            'tel',
+            'address',
+            'cart_info',
             'total_price',
             'pay_price',
             'total_postage',
@@ -145,7 +167,7 @@ class Shop extends BaseController
             ['confirm_time', 'confirm_time', function ($item) {
                 return empty($item) ? "-" : date('Y-m-d H:i:s', $item);
             }],
-        ], $data);
+        ], $order);
 
         return app('json')->success([
             'list' => $result,