<?php

namespace app\job;

use think\queue\Job;
use think\facade\Log;
use think\facade\Db;
use app\common\api\ChuanglanSmsApi;

/**
 * Description of Messenger
 *
 * @author sgq
 */
class Messenger {

    public function fire(Job $job, $data) {
        if ($this->deal($data)) {
            Log::info(json_encode($data));
            $job->delete();
            return true;
        }
        Log::error(json_encode($data));
        if ($job->attempts() >= 3) {
            $job->delete();
            return false;
        }
        $job->release(10); //10秒后重试
    }

    /**
     * 处理业务逻辑
     * @param type $data
     * @return bool
     */
    public function deal($data): bool {
        $type = $data["type"];
        switch ($type) {
            case 1:
                //通知单位审核注册
                $enterprise = $data["info"]; //企业信息
                $msg["createTime"] = date("Y-m-d H:i:s");
                $sender = new ChuanglanSmsApi();
                $sender->sendSMS($mobile, $msg);
            case 2:
                break;
        }
        return false;
    }

}
