<?php
/**
 * Created by PhpStorm.
 * User: zhoujun
 * Date: 2018/9/1
 * Time: 11:40
 */

namespace addons\faqueue\library\jobs;

use addons\faqueue\model\FaqueueLog;
use app\admin\model\AdminMessage;
use app\admin\model\UserMessage;
use app\common\library\Sms;
use app\common\library\Trtcim;
use app\common\library\weChat\weChatMp;
use app\common\model\Party;
use think\Log;
use think\queue\job;

class SendImMsessageJob
{
    public function fire(Job $job, $data)
    {
        if($data['type'] == 71){
            Trtcim::sendGroupMsg($data['content']['party_info']['party_id'], $data);
        }else{
            $partyIds = Party::where(['status' => 1, 'is_online' => 1, 'is_close' => 0])->column('id');
            foreach ($partyIds as $key => $value) {
                Trtcim::sendGroupMsg($value, $data);
            }
        }

        $job->delete();
        (new FaqueueLog())->log($job->getQueue(), $job->getName(), $data);

    }

    public function failed($data)
    {
        Log::write("任务失败：" . print_r(['data' => $data,], true), 'error');
    }
}