<?php




namespace ln\listens;

use ln\services\TimerService;
use Swoole\Timer;
use think\facade\Log;
use ln\interfaces\ListenerInterface;
use app\common\repositories\store\order\StoreRefundOrderRepository;

class RefundOrderAgreeListen extends TimerService implements ListenerInterface
{
    public function handle($event): void
    {
        $this->tick(1000 * 60 * 5, function () {
            $make = app()->make(StoreRefundOrderRepository::class);
            request()->clearCache();
            $merAgree = systemConfig('mer_refund_order_agree') ?? 7;
            $time = date('Y-m-d H:i:s', strtotime('-' . $merAgree . ' day'));
            $data = $make->getTimeOutIds($time);
            foreach ($data as $id) {
                try {
                    $make->adminRefund($id, 0);
                } catch (\Exception $e) {
                    Log::info('自动退款失败' . var_export($id, true));
                }
            }
        });
    }
}
