load->_model("Model_express_tt","express_tt");
$this->load->_model("Model_shop","shop");
$this->load->_model("Model_fullordertt","fullordertt");
}
private $ip = ['127.0.0.1','47.105.156.18'];
//定义方法的调用规则 获取URI第二段值
public function _remap($arg,$arg_array)
{
$ip = $_SERVER['REMOTE_ADDR'];
if(!in_array($ip,$this->ip)){
exit("No direct script access allowed");
}
if($arg == 'cbt_create_label')//添加
{
//创建快递面单
$this->_cbtCreateLabel();
}else if($arg == 'get_service'){
//获取订单的服务信息
$this->_getService();
}
else
{
exit('No direct script access allowed');
}
}
//tiktok的cbt发货模式 按照定时任务先创建标签
//订单状态要求 已审核 未打印 未出库 允许出库 允许打印 快递必须要是cbt
// 当前店铺为tt-wk
private function _cbtCreateLabel(){
if(date("H") != 20){
exit("当前不是20点执行".date("H"));
}
//允许长时间运行
set_time_limit(0);
$where_arr = [
//"shop"=>35,//当前店铺为tt-wk
"express"=>83,//快递为tt-cbt
"print"=>2,//未打印
"printnumber"=>0,//打印次数
'library'=>1,//未出库
'printtype'=>1,//打运单
//'libraryconfirm'=>2,//允许出库
"review >"=>4,//审核通过或自动审核
];
//$shop_info = $this->shop->read(35);
$shop_list = $this->shop->find_all('1 = 1');
$shop_list = array_column($shop_list,null,'id');
// if(empty($shop_info)){
// exit("当前店铺不存在");
// }
$list = $this->db->from("fullordertt")
->select("id,orderinfo,shop,express,print,printnumber,library,review,state")
->where($where_arr)
->where_not_in('state',[214,217])
->get()->result_array();
if(empty($list)){
exit("没有符合条件的订单");
}
foreach($list as $k=>$v){
$info = $this->fullordertt->read($v['id']);
if(empty($info['extra_text'])){
continue;
}
$extra_text = json_decode($info['extra_text'],true);
if(isset($extra_text['label_info'])){
continue;
}
if(isset($shop_list[$info['shop']])){
$r = $this->express_tt->doCreateCBTLabel($info,$shop_list[$info['shop']]);
print_r($info['orderinfo']);
print_r("|");
usleep(10);
}
}
var_dump(date("
执行完成
"));
sleep(3);
$this->_cbtCreateLabelAgain();
}
private function _cbtCreateLabelAgain(){
$where_arr = [
//"shop"=>35,//当前店铺为tt-wk
"express"=>83,//快递为tt-cbt
"print"=>2,//未打印
'printtype'=>1,//打运单
"printnumber"=>0,//打印次数
'library'=>1,//未出库
//'libraryconfirm'=>2,//允许出库
"review >"=>4,//审核通过或自动审核
];
//$shop_info = $this->shop->read(35);
$shop_list = $this->shop->find_all('1 = 1');
$shop_list = array_column($shop_list,null,'id');
// if(empty($shop_info)){
// exit("当前店铺不存在");
// }
$list = $this->db->from("fullordertt")
->select("id,orderinfo,shop,express,print,printnumber,library,review,state")
->where($where_arr)
->where_not_in('state',[214,217])
->get()->result_array();
if(empty($list)){
exit("没有符合条件的订单");
}
foreach($list as $k=>$v){
$info = $this->fullordertt->read($v['id']);
if(empty($info['extra_text'])){
continue;
}
$extra_text = json_decode($info['extra_text'],true);
if(isset($extra_text['label_info'])){
continue;
}
if(isset($shop_list[$info['shop']])){
$r = $this->express_tt->doCreateCBTLabel($info,$shop_list[$info['shop']]);
print_r($info['orderinfo']);
print_r("|");
usleep(10);
}
}
echo "
";
exit("执行完成again");
}
public function _getService(){
if(date("H") != 19){
exit("当前不是19点执行".date("H"));
}
//允许长时间运行
set_time_limit(0);
$where_arr = [
//"shop"=>35,//当前店铺为tt-wk
"express"=>83,//快递为tt-cbt
"print"=>2,//未打印
'printtype'=>1,//打运单
"printnumber"=>0,//打印次数
'library'=>1,//未出库
//'libraryconfirm'=>2,//允许出库
"review >"=>4,//审核通过或自动审核
];
//$shop_info = $this->shop->read(35);
$shop_list = $this->shop->find_all('1 = 1');
$shop_list = array_column($shop_list,null,'id');
// if(empty($shop_info)){
// exit("当前店铺不存在");
// }
$list = $this->db->from("fullordertt")
->select("id,orderinfo,shop,express,print,printnumber,library,review,state")
->where($where_arr)
->where_not_in('state',[214,217])
->get()->result_array();
if(empty($list)){
exit("没有符合条件的订单");
}
foreach($list as $k=>$v){
$info = $this->fullordertt->read($v['id']);
if(empty($info['extra_text'])){
continue;
}
$extra_text = json_decode($info['extra_text'],true);
if(isset($extra_text['server_info'])){
continue;
}
if(isset($shop_list[$info['shop']])){
$r = $this->express_tt->getExpressInfo($info,$shop_list[$info['shop']]);
print_r($info['orderinfo']);
print_r("|");
usleep(10);
}
if(date("H") == 20){
exit("执行到20点了 不能在执行了");
}
}
echo "
";
exit("执行完成");
}
}