Browse Source

fix:订单支付信息

super-yimizi 1 month ago
parent
commit
75757ecf82

+ 12 - 0
application/api/controller/Order.php

@@ -15,6 +15,8 @@ use app\common\Service\OrderService;
 use app\common\Service\ParentOrderService;
 use app\common\Enum\OrderEnum;
 use app\common\Service\CartService;
+use app\common\Service\Pay\PayOperService;
+
 /**
  * 订单接口
  */
@@ -292,6 +294,9 @@ class Order extends Base
         foreach ($order->order_goods as $item) {
             $item->express_image = json_decode($item->express_image, true);
         }
+        //  查询支付信息
+        $payInfo = PayOperService::getPayInfoByOrderId($orderId, 1);
+        $order->pay_info = $payInfo;
         $this->success('', $order);
     }
 
@@ -314,12 +319,19 @@ class Order extends Base
         $param['keywords'] = $this->request->param('keywords', '', 'trim');
         $status   = OrderEnum::SHOW_TYPE_STATUS_MAP[$status];
         $list = OrderService::getOrderList($userId ,$param, $status);
+
+        //  查询支付信息
+        $orderIds = array_column(collection($list)->toArray(), 'id');
+        $payInfo = PayOperService::getPayInfoByOrderIds($orderIds, 1);
+           
         foreach ($list as $item) {
            // $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';
             $item->visible(explode(',', $field));
             $item->order_status_text = OrderEnum::STATUS_TEXT_MAP[$item->order_status];
+            $item->pay_info = $payInfo->where('order_id', $item->id)->find();
         }
+    
         $this->success('获取成功', $list);
     }
 

+ 38 - 0
application/common/Service/Pay/PayOperService.php

@@ -432,5 +432,43 @@ class PayOperService
     }
 
 
+    // 根据订单id 获取支付信息
+    /**
+     * 根据订单id获取支付信息
+     *
+     * @param int $orderId 订单ID
+     * @param int $orderType 订单类型,默认为 1
+     * @return \think\Collection
+     */
+    public static function getPayInfoByOrderId($orderId = 0, $orderType = 1)
+    {
+        $pays = PayModel::where('order_type', $orderType)
+            ->field('id,pay_type,pay_fee,real_fee,transaction_id,paid_time')
+            ->where('order_id', $orderId)
+            ->order('id', 'desc')
+            ->find();
+        
+        return $pays;
+    }
 
+    /**
+     * 根据订单ids批量获取支付信息
+     *
+     * @param array $orderIds 订单ID数组
+     * @param int $orderType 订单类型,默认为 1
+     * @return \think\Collection
+     */
+    public static function getPayInfoByOrderIds($orderIds =[], $orderType = 1)
+    {
+        if (empty($orderIds) || !is_array($orderIds)) {
+            return collection([]);
+        }
+
+        $pays = PayModel::where('order_type', $orderType)
+        ->field('id,pay_type,pay_fee,real_fee,transaction_id,paid_time')
+            ->where('order_id', 'in', $orderIds)
+            ->select();
+        
+        return collection($pays);
+    }
 }