<?php




namespace ln\listens\pay;


use app\common\repositories\store\order\PresellOrderRepository;
use ln\interfaces\ListenerInterface;

class PresellPaySuccessListen implements ListenerInterface
{

    public function handle($data): void
    {
        $orderSn = $data['order_sn'];
        $is_combine = $data['is_combine'] ?? 0;
        $order = app()->make(PresellOrderRepository::class)->getWhere(['presell_order_sn' => $orderSn]);
        if (!$order || $order->paid == 1) return;
        $orders = [];
        if ($is_combine) {
            foreach ($data['data']['sub_orders'] as $_order) {
                $orders[$_order['out_trade_no']] = $_order;
            }
        }
        app()->make(PresellOrderRepository::class)->paySuccess($order, $is_combine, $orders);
    }
}