<?php

namespace Daemon;

use Api\PhpServices\Daemon\DaemonServiceInterface;
use App\Models\order\mysql\PayOrderItem;
use App\Services\pay\PayService;

class Wallet implements DaemonServiceInterface
{
    /**
     * 核销、支付后直接到钱包补偿任务
     */
    public function run()
    {
        $where['notify_account_status'] = 0;
        $where['can_notify_account'] = 1;
        $where['notify_account_times[<]'] = 10;
        $start = date('Y-m-d H:i:s', time() - 2 * 86400);
        $end = date('Y-m-d H:i:s', time());
        $where['can_notify_account_time[<>]'] = [$start, $end];
        $where['ORDER'] = ['can_notify_account_time'=>'ASC'];
        $where['LIMIT'] = [0, 50];

        $list = PayOrderItem::selectMaster('*', $where);

        $payService = new PayService();
        foreach ($list as $row) {
            $payService->sync_account_wallet($row['order_item_id']);
        }

        $step = empty($list) ? 120 : 5;
        sleep($step);
    }
}