<?php


namespace crmeb\jobs;


use crmeb\interfaces\JobInterface;
use think\queue\Job;

/**
 * 订单消息队列
 * Class OrderJob
 * @package crmeb\jobs
 */
class OrderJob implements JobInterface
{
    public function fire(Job $job, $data): void
    {
        $job->delete();
        $action = $data['action'] ?? '';
        $infoData = $data['data'] ?? [];
        if (!$action) {
            $action = 'doHelloJob';
        }

        if ($this->{$action}($infoData))
            $job->delete();
        else {
            if ($job->attempts() > 3)
                $job->delete();
        }
    }

    /**
     * 执行
     * @param $data
     * @return bool
     */
    public function doHelloJob($data)
    {
        event('OrderPaySuccess', $data);
        return true;
    }
}