Parcourir la source

添加拆分订单的信息

lvhao il y a 11 heures
Parent
commit
bf0aaf82f6
1 fichiers modifiés avec 143 ajouts et 0 suppressions
  1. 143 0
      core/CoreApp/controllers/Api.php

+ 143 - 0
core/CoreApp/controllers/Api.php

@@ -79,6 +79,12 @@ class Api extends Start_Controller {
         {
         {
              $this->_waybillfs($arg_array);
              $this->_waybillfs($arg_array);
         }
         }
+		else if($arg == 'waybillemailsplit'){
+			$this->_waybillemailSplit();
+		}
+		else if($arg == 'waybillfssplit'){
+			$this->_waybillfsSplit();
+		}
 		else if($arg == 'headgear')//传输头套信息
 		else if($arg == 'headgear')//传输头套信息
         {
         {
              $this->_headgear($arg_array);
              $this->_headgear($arg_array);
@@ -1182,7 +1188,144 @@ class Api extends Start_Controller {
 		    }
 		    }
 		}
 		}
 	}
 	}
+
+
+
+	/********************运单通知-拆分****开始****************************/
 	
 	
+	public function _waybillemailSplit(){
+		$urls = array();$sl = 0;$time = time();
+		$wid = 0;
+		if(date("H",time()) == '8' && date("i",time()) > '20' && date("i",time()) < '39')//USPS-USA单
+		{
+			$wid = 1;
+		}
+		else if(date("H",time()) == '20' && date("i",time()) > '20' && date("i",time()) < '39')//其他快递
+		{
+			$wid = 2;
+		}
+		else if(date("H",time()) == '21' && date("i",time()) > '20' && date("i",time()) < '39')//其他快递
+		{
+			$wid = 3;
+		}
+		else
+		{
+			//exit;
+		}
+		$notice = $this->notice->find_all("message = '1' and state = '1' and type = '5' and ktime < '$time' and jtime > '$time'");//已有自动发送,这个是物流发送
+		foreach ($notice as $key=>$var)
+		{
+			$rand = rand(11,50);
+			$urls[] = array('url'=>'http://a'.$rand.'.wepolicy.cn/api/waybillfssplit?v='.$var['id'],'data'=>array('var'=>$var,'wid'=>$wid));
+		}
+		// foreach($urls as $value) {
+		// 	$ch = curl_init();
+		// 	$url = $value['url'];
+		// 	curl_setopt($ch,CURLOPT_URL,$url);
+		// 	curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
+		// 	curl_setopt($ch,CURLOPT_HEADER,0);
+		// 	curl_setopt($ch,CURLOPT_POST, 1);
+		// 	curl_setopt($ch,CURLOPT_TIMEOUT,1);
+		// 	//设置post数据
+		// 	$post = array();
+		// 	$post['data'] = $value['data'];
+		// 	curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
+		// 	$res = curl_exec($ch);
+		// 	curl_close($ch);
+		// 	$sl++;
+		// }
+		// echo $sl;
+		echo "<pre>";
+		print_r($urls);
+	}
+	//发送邮件
+	public function _waybillfsSplit(){
+		$data = $this->input->post('data',true);
+		if($data)
+		{
+		    $notice = $data['var'];
+			$notice['email'] = $this->emaildata->read($notice['email']);
+			$wid = $data['wid'];
+			$fsjs = "";
+			if($wid == 1 && (stripos($notice['express'],',2,') !== false || stripos($notice['express'],',63,') !== false || stripos($notice['express'],',64,') !== false))
+			{
+				$js = explode(',',trim($notice['js'],','));
+				if(count($js) > 1)
+				{
+					$fsjs = " and (";
+				    foreach ($js as $v)
+				    {
+					    $fsjs .= "js = '$v' or ";
+				    }
+					$fsjs = trim($fsjs,' or ').")" ;
+				}
+				else if(count($js) == 1)
+				{
+					$fsjs = " and js = '$js[0]'";
+				}
+				$where = "(express = '2' or express = '63' or express = '64') and librarytime > '".strtotime(date("Y-m-d 8:30:0",strtotime("-6 day")))."' and librarytime < '".strtotime(date("Y-m-d 8:30:0",time()))."'".$fsjs;//3
+			}
+			else if($wid == 2 && stripos($notice['express'],',1,') !== false)
+			{
+			 	$where = "express != '2' and express != '63' and  express != '64'  and printtype = '1' and waybill != '' and librarytime > '".strtotime(date("Y-m-d 20:00:0",strtotime("-6 day")))."' and librarytime < '".strtotime(date("Y-m-d 20:00:0",time()))."'";//4
+			}
+			else if($wid == 3 && stripos($notice['express'],',1,') !== false)
+			{
+			 	$where = "express = '71'  and printtype = '2' and waybill != '' and librarytime > '".strtotime(date("Y-m-d 20:00:0",strtotime("-6 day")))."' and librarytime < '".strtotime(date("Y-m-d 20:00:0",time()))."'";//4
+			}
+			else
+			{
+				exit;
+			}
+		    $wlfs = array();
+		    $dd = $this->fullorder->find_all("source = '1' and extra_status = '1' and dlzemail < '1' and shop = '".$notice['shop']."' and library = 2 and ".$where);
+		    foreach ($dd as $v)
+		    {
+				$tmp_list = explode('-', $v['number']);
+				array_pop($tmp_list);
+				$tmp_number = implode('-', $tmp_list);
+				$info = $this->fullorder->find("number = '".$tmp_number."' and source != '1'","id,number,source");
+				if(empty($info)){
+					//如果不是线上的单子拆分的 就不发送邮箱
+					continue;
+				}
+				$this->logic_ding->sendToDing("拆分订单".$v['number']."发送订单邮件了");
+
+			    $shop = $this->shop->read($v['shop']);
+			    $express = $this->express->read($v['express']);
+				if(empty($v['send_email'])){
+					$fs = $this->notice->get_god($v,$shop,$express,$notice);
+				}else{
+					$email = $v['email'];
+					$v['email'] = $v['send_email'];
+					$fs = $this->notice->get_god($v,$shop,$express,$notice);
+					$v['email'] = $email;
+				}
+			    if($fs == 1)
+			    {
+				    $this->fullorder->save(array('dlzemail'=>1,'dlzemailtime'=>time()),$v['id']);
+			    }
+			    else
+			    {
+					if(!is_file("./data/dlzemail/".$v['number'].".txt"))
+					{
+						$myfile = fopen("./data/dlzemail/".$v['number'].".txt", "w") or die("Unable to open file!");
+						fwrite($myfile, json_encode($fs.';'.$v.';'.$shop.';'.$express.';'.$notice));
+						fclose($myfile);
+					}
+					else
+					{
+						$myfile = fopen("./data/dlzemail/".$v['number'].".txt", "a+") or die("Unable to open file!");
+						fwrite($myfile, json_encode($fs.';'.$v.';'.$shop.';'.$express.';'.$notice));
+						fclose($myfile);
+					}
+				    $this->fullorder->save(array('dlzemail'=>2,'dlzemailtime'=>time()),$v['id']);
+			    }
+			    sleep(50);
+		    }
+		}
+	}
+	/********************运单通知-拆分****结束****************************/
 	
 	
 	/**
 	/**
 	//更新独立站运单信息
 	//更新独立站运单信息