<?php




namespace ln\listens\pay;


use app\common\repositories\store\order\StoreGroupOrderRepository;
use app\common\repositories\store\order\StoreOrderRepository;
use ln\interfaces\ListenerInterface;

class OrderPaySuccessListen implements ListenerInterface
{

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