QueueCbt.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. /**
  3. * 此列一般在执行 24个小时中的一个 时候执行一次
  4. */
  5. class QueueCbt extends Start_Controller {
  6. public function __construct(){
  7. parent::__construct();
  8. $this->load->_model("Model_express_tt","express_tt");
  9. $this->load->_model("Model_shop","shop");
  10. $this->load->_model("Model_fullordertt","fullordertt");
  11. }
  12. private $ip = ['127.0.0.1','47.105.156.18'];
  13. //定义方法的调用规则 获取URI第二段值
  14. public function _remap($arg,$arg_array)
  15. {
  16. $ip = $_SERVER['REMOTE_ADDR'];
  17. if(!in_array($ip,$this->ip)){
  18. exit("No direct script access allowed");
  19. }
  20. if($arg == 'cbt_create_label')//添加
  21. {
  22. //创建快递面单
  23. $this->_cbtCreateLabel();
  24. }else if($arg == 'get_service'){
  25. //获取订单的服务信息
  26. $this->_getService();
  27. }
  28. else
  29. {
  30. exit('No direct script access allowed');
  31. }
  32. }
  33. //tiktok的cbt发货模式 按照定时任务先创建标签
  34. //订单状态要求 已审核 未打印 未出库 允许出库 允许打印 快递必须要是cbt
  35. // 当前店铺为tt-wk
  36. private function _cbtCreateLabel(){
  37. if(date("H") != 20){
  38. exit("当前不是20点执行".date("H"));
  39. }
  40. //允许长时间运行
  41. set_time_limit(0);
  42. $where_arr = [
  43. //"shop"=>35,//当前店铺为tt-wk
  44. "express"=>83,//快递为tt-cbt
  45. "print"=>2,//未打印
  46. "printnumber"=>0,//打印次数
  47. 'library'=>1,//未出库
  48. //'libraryconfirm'=>2,//允许出库
  49. "review >"=>4,//审核通过或自动审核
  50. ];
  51. //$shop_info = $this->shop->read(35);
  52. $shop_list = $this->shop->find_all('1 = 1');
  53. $shop_list = array_column($shop_list,null,'id');
  54. // if(empty($shop_info)){
  55. // exit("当前店铺不存在");
  56. // }
  57. $list = $this->db->from("fullordertt")
  58. ->select("id,orderinfo,shop,express,print,printnumber,library,review,state")
  59. ->where($where_arr)
  60. ->where_not_in('state',[214,217])
  61. ->get()->result_array();
  62. if(empty($list)){
  63. exit("没有符合条件的订单");
  64. }
  65. foreach($list as $k=>$v){
  66. $info = $this->fullordertt->read($v['id']);
  67. if(empty($info['extra_text'])){
  68. continue;
  69. }
  70. $extra_text = json_encode($info['extra_text'],true);
  71. if(isset($extra_text['label_info'])){
  72. continue;
  73. }
  74. if(isset($shop_list[$info['shop']])){
  75. $r = $this->express_tt->doCreateCBTLabel($info,$shop_list[$info['shop']]);
  76. print_r($info['orderinfo']);
  77. print_r("|");
  78. usleep(10);
  79. }
  80. }
  81. echo "<br/>";
  82. exit("执行完成");
  83. }
  84. public function _getService(){
  85. if(date("H") != 19){
  86. exit("当前不是19点执行".date("H"));
  87. }
  88. //允许长时间运行
  89. set_time_limit(0);
  90. $where_arr = [
  91. //"shop"=>35,//当前店铺为tt-wk
  92. "express"=>83,//快递为tt-cbt
  93. "print"=>2,//未打印
  94. "printnumber"=>0,//打印次数
  95. 'library'=>1,//未出库
  96. //'libraryconfirm'=>2,//允许出库
  97. "review >"=>4,//审核通过或自动审核
  98. ];
  99. //$shop_info = $this->shop->read(35);
  100. $shop_list = $this->shop->find_all('1 = 1');
  101. $shop_list = array_column($shop_list,null,'id');
  102. // if(empty($shop_info)){
  103. // exit("当前店铺不存在");
  104. // }
  105. $list = $this->db->from("fullordertt")
  106. ->select("id,orderinfo,shop,express,print,printnumber,library,review,state")
  107. ->where($where_arr)
  108. ->where_not_in('state',[214,217])
  109. ->get()->result_array();
  110. if(empty($list)){
  111. exit("没有符合条件的订单");
  112. }
  113. foreach($list as $k=>$v){
  114. $info = $this->fullordertt->read($v['id']);
  115. if(empty($info['extra_text'])){
  116. continue;
  117. }
  118. $extra_text = json_encode($info['extra_text'],true);
  119. if(isset($extra_text['server_info'])){
  120. continue;
  121. }
  122. if(isset($shop_list[$info['shop']])){
  123. $r = $this->express_tt->getExpressInfo($info,$shop_list[$info['shop']]);
  124. print_r($info['orderinfo']);
  125. print_r("|");
  126. usleep(10);
  127. }
  128. if(date("H") == 20){
  129. exit("执行到20点了 不能在执行了");
  130. }
  131. }
  132. echo "<br/>";
  133. exit("执行完成");
  134. }
  135. }