load->_model('Model_fullorder', 'fullorder'); $this->load->_model("Model_logic_ding", "logic_ding"); $this->load->_model("Model_cne", "cne"); $this->load->_model("Model_zzjobs", "zzjobs"); $this->load->_model('Model_notice','notice'); $this->load->_model('Model_shop','shop'); $this->load->_model('Model_express','express'); $this->load->_model('Model_emaildata','emaildata'); } public function _remap($arg, $arg_array) { $ip = $_SERVER['REMOTE_ADDR']; // if (!in_array($ip, $this->ip)) { // exit("Unauthorized access"); // } $user_agent = empty($_SERVER['HTTP_USER_AGENT']) ? "" : $_SERVER['HTTP_USER_AGENT']; $token = empty($_SERVER['HTTP_X_AUTH_TOKEN']) ? "" : $_SERVER['HTTP_X_AUTH_TOKEN']; $time = $this->input->get('time', true); $api = $this->input->get('api', true); // $this->checkAuth($user_agent, $token, $time, $api); if ($arg == 'jobs') //调出单 { $this->_doRenwu(); } else { $this->_index(); } } /** * 校验是否有权限可以执行 * $user_agent 自定义的请求客户端名称 * $token 自定义的清华客户端的token * $time 请求的时间 * */ private function checkAuth($user_agent, $token, $time, $api) { if ($api != $this->api) { exit("Access denied due to insufficient permissions"); } $check_str = date("Ymd") . "¥_" . $this->serect_str . "_¥" . $time; if (empty($user_agent)) { exit('No direct script access allowed'); } if ($user_agent != $this->user_agent) { exit('Illegal request'); } if (empty($token)) { exit('No access permission'); } $sercet_str = md5($check_str); if ($sercet_str != $token) { exit("Request permission is illegal"); } } private function _index() {} private function _doRenwu() { echo "
";
        $list = $this->zzjobs->find_all("status = 0 and quque = 'ysgjcx'", "*",null, 0, 1);
        $ids = array_column($list, 'id');
        $this->db->query("update crowd_zzjobs set status = 10 where id  in (" . implode(",", $ids) . ")");
        foreach ($list as $v) {
            $this->doAction($v);
            sleep(2);
        }
    }
    private function doAction($v)
    {
        $param = json_decode($v['payload'], true);
        
        
        $info = $param['v'];
       
        $notice_id = $param['id'];
        
        $notice_info = $this->notice->read($notice_id);

        $rr = $this->cne->get_logistics_yskx(
            [
                [
                    'TrackNumber' => $info['waybill']
                ]
            ]
        );
        var_dump($rr);
        if($rr['code'] != 1){
            return  $this->zzjobs->save(['status'=>20,'last_time'=>time(),'result'=>json_encode($rr,JSON_UNESCAPED_UNICODE)],$v['id']);;
        }
        $fs = $rr['data'][0];

        $wlfs = [];
        if (!isset($fs['f'])) {
            $this->fullorder->save(array('wlerror' => $fs['content']),  $info['id']);
        } else {
            if ($fs['f'] == '1') {
                if ($fs['exstate'] > $info['expressstate'] || isset($fs['webhookregister'])) {
                    $this->fullorder->save(array('expressstate' => $fs['exstate'], 'excontent' => $fs['data'], 'webhookregister' => 0, 'wlerror' => ''), $info['id']);
                }
                if ($fs['exstate'] == $notice_info['logisticstatus'] && $info['wlyc'] == '0' && $info['wltype'] != '1' && $info['source'] != '1') //获取快递状态等于模板状态、订单状态等于模板状态、出库时间大于-、未加入物流异常、允许发送邮件状态、非线下单
                {
                    if ($info['shop'] < '7') // && $v['shouldmoney'] > 100)
                    {
                        $wlfs[] = array('v' => $info, 'id' => $notice_id );
                        //$go = $this->_sdfs($v,$var['id']);//更新顺带发送
                    }
                }
            } else {
                $this->fullorder->save(array('wlerror' => $fs['content']), $v['id']);
            }
        }
        $this->zzjobs->save(['status'=>30,'last_time'=>time(),'result'=>json_encode($fs,JSON_UNESCAPED_UNICODE)],$v['id']);
        // if(!empty($wlfs)){
        //     $this->_sdfs($v['v'],$v['id']);
        // }
        // @$this->allocation->insert(array('title'=>$shopid.'-'.json_encode($csck)));
		// if($wlfs)
		// {
		//     foreach ($wlfs as $k=>$v)
		//     {
		// 		$t1 = microtime(true);
        //         $this->_sdfs($v['v'],$v['id']);
        //         $t2 = microtime(true);
		// 		$t3 = (40-($t2-$t1) < 1)?1:round(40-($t2-$t1));
		// 	    sleep($t3);
		//     }
		// }
    }

    public function _sdfs($fullorder,$id)//手动发送信息
	{
		$time = time();
		$notice = $this->notice->read($id);//无条件同模板匹配
		$notice['email'] = $this->emaildata->read($notice['email']);
		$shop = $this->shop->read($fullorder['shop']);
		$express = $this->express->read($fullorder['express']);
		if($notice['type'] == '1')
		{
			$fslx = 'tab';
			$content = '自动发送';
			$stripos = '1-';
		}
		else if ($notice['type'] == '2')
		{
			$fslx = 'logisticstatus';
			$content = $notice['title'];
			$stripos = $notice['type'].'-'.$notice[$fslx].'|';
		}
        $this->logic_ding->sendToDing("云尚轨迹获取快递信息暂时中断");
        return ;
		if(stripos($fullorder['zdstate'],$stripos) === false && $fullorder['wltype'] == '0')//如果没发送过并且允许发送
		{
		    $go = $this->notice->get_god($fullorder,$shop,$express,$notice);
            $this->logic_ding->sendToDing("云尚轨迹获取快递信息".json_encode($go,JSON_UNESCAPED_UNICODE));
		    if($go == 1)
		    {
				if($notice['type'] == '1')
				{
			       $this->fullorder->save(array('content'=>$fullorder['content'].$content.'-成功;','zdstate'=>$fullorder['zdstate'].$notice['type'].'-'.$notice[$fslx].'|','exstateerror'=>'','wlerror'=>''),$fullorder['id']);
				}
				else if ($notice['type'] == '2')
				{
					$this->fullorder->save(array('wlcontent'=>$fullorder['wlcontent'].$content.'-成功;','wlfstime'=>time(),'zdstate'=>$fullorder['zdstate'].$notice['type'].'-'.$notice[$fslx].'|','exstateerror'=>'','wlerror'=>''),$fullorder['id']);
				}
			     return 1;
		    }
		    else
		    {
				if($notice['type'] == '1')
				{
			        $this->fullorder->save(array('exstateerror'=>$content.'发送失败1:'.date('Y-m-d H',time()).'-'.$go.'('.$notice['type'].'-'.$notice[$fslx].')'),$fullorder['id']);
				}
				else if ($notice['type'] == '2')
				{
					$this->fullorder->save(array('wlerror'=>$content.'发送失败2:'.date('Y-m-d H',time()).'-'.$go.'('.$notice['type'].'-'.$notice[$fslx].')'),$fullorder['id']);
				}
		    }
		}
	}

}