| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 | 
							- <?php
 
- defined('BASEPATH') or exit('No direct script access allowed');
 
- /**
 
-  * 此类是为了解决erp没有队列的问题,为了解决这个问题,先写一下这个类,避免后期写那么多定时任务类   这里只能解决每间隔多少时间执行一会的
 
-  */
 
- class Apidsyskxcx extends Start_Controller
 
- {
 
-     private $serect_str = "yskxcx";
 
-     private $user_agent = 'Xcly251618/Yskxcx (Erp)';
 
-     private $api = "Yskxcx25.424";
 
-     private $ip = ['127.0.0.1', '47.105.156.18'];
 
-     public function __construct()
 
-     {
 
-         parent::__construct();
 
-         $this->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()
 
-     {
 
-         $list = $this->zzjobs->find_all("status = 0 and quque = 'ysgjcx'", "*",null, 0, 40);
 
-         if(empty($list)){
 
-             exit("There is no executable data available");
 
-         }
 
-         $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(1);
 
-         }
 
-     }
 
-     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']
 
-                 ]
 
-             ]
 
-         );
 
-         
 
-         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']);
 
-                 }else{
 
-                     $this->fullorder->save(array('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 );
 
-                         $this->_sdfs($info,$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->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("云尚轨迹获取快递信息暂时中断"."【".json_encode($fullorder)."】{".json_encode($notice)."}");
 
-         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']);
 
- 				}
 
- 		    }
 
- 		}
 
- 	}
 
- }
 
 
  |