<?php




namespace ln\listens;


use app\common\repositories\store\order\StoreGroupOrderRepository;
use ln\interfaces\ListenerInterface;
use ln\jobs\SendSmsJob;
use ln\services\TimerService;
use Swoole\Timer;
use think\facade\Queue;

class AutoSendPayOrderSmsListen extends TimerService implements ListenerInterface
{

    public function handle($event): void
    {
        $this->tick(1000 * 60 * 5, function () {
            $storeGroupOrderRepository = app()->make(StoreGroupOrderRepository::class);
            $time = date('Y-m-d H:i:s', strtotime("- 10 minutes"));
            $groupOrderIds = $storeGroupOrderRepository->getTimeOutIds($time, true);
            foreach ($groupOrderIds as $id) {
                Queue::push(SendSmsJob::class, [
                    'tempId' => 'ORDER_PAY_FALSE',
                    'id' => $id
                ]);
                $storeGroupOrderRepository->isRemind($id);
            }
        });
    }
}