<?php

namespace app\subscribe;

use app\common\model\Worker;
use app\common\service\RensheService;
use think\Event;
use think\facade\Log;

class SysRen
{
    /**
     * 岗位撮合结果信息提交
     */
    public function onJobMatch($param)
    {
        if ($param['status'] == 3) {
            if (empty($param['comjobs']['comjobsCate']['code'])) {
                Log::error('岗位撮合同步失败，工种编号不存在，撮合id：' . $param['id']);
            }

            //数据初始化
            $data           = [];
            $data['aca111'] = $param['comjobs']['comjobsCate']['code'];
            $data['aca112'] = $param['comjobs']['title'];
            $data['baz367'] = $param['comjobs']['id'];
            $data['aae036'] = date('Y-m-d H:i:s');
            $data['baz370'] = $param['id'];
            if (empty($param['worker']['third_id'])) {
                $data['aae136'] = $param['worker']['card_no'];
                $data['aab069'] = $param['worker']['title'];
                $data['aae004'] = $param['worker']['realname'];
            } else {
                $data['aae136'] = $param['worker']['third']['card_no'];
                $data['aab069'] = $param['worker']['third']['name'];
                $data['aae004'] = $param['worker']['third']['contact'];
            }
            $data['aae006'] = $param['worker']['province'] . $param['worker']['city'] . $param['worker']['district'] . $param['worker']['address'];
            $data['aae005'] = $param['worker']['mobile'];
            $data['aac002'] = $param['user']['idcard'];
            $data['aac003'] = $param['user']['nickname'];
            $data['bec001'] = $param['user']['address'];
            $data['bae025'] = $param['user']['mobile'];

            //发送请求
            $service = new RensheService($data);
            $service->MatchSubmit();
        }
    }

    /**
     * 自定义订阅列表
     */
    public function subscribe(Event $event)
    {
        $event->listen('JobMatch', [$this, 'onJobMatch']);
    }
}
