Browse Source

fix:订单支付信息

super-yimizi 1 month ago
parent
commit
3068ba3751

+ 11 - 4
application/api/controller/Order.php

@@ -321,15 +321,22 @@ class Order extends Base
         $list = OrderService::getOrderList($userId ,$param, $status);
         $list = OrderService::getOrderList($userId ,$param, $status);
 
 
         //  查询支付信息
         //  查询支付信息
-        $orderIds = array_column(collection($list)->toArray(), 'id');
+        $orderIds = $list->column('id');
         $payInfo = PayOperService::getPayInfoByOrderIds($orderIds, 1);
         $payInfo = PayOperService::getPayInfoByOrderIds($orderIds, 1);
-           
+        // 形成kv
+        $payInfoKV = [];
+        foreach ($payInfo as $item) {
+            $payInfoKV[$item->order_id] = $item;
+        }
+        $list->each(function($row) use ($payInfoKV) {
+            $row->pay_info = $payInfoKV[$row->id] ?? [];             
+        });    
+
         foreach ($list as $item) {
         foreach ($list as $item) {
            // $item->append(['order_status_text']);
            // $item->append(['order_status_text']);
-            $field = 'id,order_sn,amount,goods_price,order_amount,express_name,express_no,order_goods,order_status_text,order_status';
+            $field = 'id,order_sn,amount,goods_price,order_amount,express_name,express_no,order_goods,order_status_text,order_status,pay_info';
             $item->visible(explode(',', $field));
             $item->visible(explode(',', $field));
             $item->order_status_text = OrderEnum::STATUS_TEXT_MAP[$item->order_status];
             $item->order_status_text = OrderEnum::STATUS_TEXT_MAP[$item->order_status];
-            $item->pay_info = $payInfo->where('order_id', $item->id)->find();
         }
         }
     
     
         $this->success('获取成功', $list);
         $this->success('获取成功', $list);

+ 1 - 1
application/common/Service/Pay/PayOperService.php

@@ -465,7 +465,7 @@ class PayOperService
         }
         }
 
 
         $pays = PayModel::where('order_type', $orderType)
         $pays = PayModel::where('order_type', $orderType)
-        ->field('id,pay_type,pay_fee,real_fee,transaction_id,paid_time')
+        ->field('id,order_id,pay_type,pay_fee,real_fee,transaction_id,paid_time')
             ->where('order_id', 'in', $orderIds)
             ->where('order_id', 'in', $orderIds)
             ->select();
             ->select();