QueueCbt.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. 'printtype'=>1,//打运单
  49. //'libraryconfirm'=>2,//允许出库
  50. "review >"=>4,//审核通过或自动审核
  51. ];
  52. //$shop_info = $this->shop->read(35);
  53. $shop_list = $this->shop->find_all('1 = 1');
  54. $shop_list = array_column($shop_list,null,'id');
  55. // if(empty($shop_info)){
  56. // exit("当前店铺不存在");
  57. // }
  58. $list = $this->db->from("fullordertt")
  59. ->select("id,orderinfo,shop,express,print,printnumber,library,review,state")
  60. ->where($where_arr)
  61. ->where_not_in('state',[214,217])
  62. ->get()->result_array();
  63. if(empty($list)){
  64. exit("没有符合条件的订单");
  65. }
  66. foreach($list as $k=>$v){
  67. $info = $this->fullordertt->read($v['id']);
  68. if(empty($info['extra_text'])){
  69. continue;
  70. }
  71. $extra_text = json_decode($info['extra_text'],true);
  72. if(isset($extra_text['label_info'])){
  73. continue;
  74. }
  75. if(isset($shop_list[$info['shop']])){
  76. $r = $this->express_tt->doCreateCBTLabel($info,$shop_list[$info['shop']]);
  77. print_r($info['orderinfo']);
  78. print_r("|");
  79. usleep(10);
  80. }
  81. }
  82. var_dump(date("<br/>执行完成<br/>"));
  83. sleep(3);
  84. $this->_cbtCreateLabelAgain();
  85. }
  86. private function _cbtCreateLabelAgain(){
  87. $where_arr = [
  88. //"shop"=>35,//当前店铺为tt-wk
  89. "express"=>83,//快递为tt-cbt
  90. "print"=>2,//未打印
  91. 'printtype'=>1,//打运单
  92. "printnumber"=>0,//打印次数
  93. 'library'=>1,//未出库
  94. //'libraryconfirm'=>2,//允许出库
  95. "review >"=>4,//审核通过或自动审核
  96. ];
  97. //$shop_info = $this->shop->read(35);
  98. $shop_list = $this->shop->find_all('1 = 1');
  99. $shop_list = array_column($shop_list,null,'id');
  100. // if(empty($shop_info)){
  101. // exit("当前店铺不存在");
  102. // }
  103. $list = $this->db->from("fullordertt")
  104. ->select("id,orderinfo,shop,express,print,printnumber,library,review,state")
  105. ->where($where_arr)
  106. ->where_not_in('state',[214,217])
  107. ->get()->result_array();
  108. if(empty($list)){
  109. exit("没有符合条件的订单");
  110. }
  111. foreach($list as $k=>$v){
  112. $info = $this->fullordertt->read($v['id']);
  113. if(empty($info['extra_text'])){
  114. continue;
  115. }
  116. $extra_text = json_decode($info['extra_text'],true);
  117. if(isset($extra_text['label_info'])){
  118. continue;
  119. }
  120. if(isset($shop_list[$info['shop']])){
  121. $r = $this->express_tt->doCreateCBTLabel($info,$shop_list[$info['shop']]);
  122. print_r($info['orderinfo']);
  123. print_r("|");
  124. usleep(10);
  125. }
  126. }
  127. echo "<br/>";
  128. exit("执行完成again");
  129. }
  130. public function _getService(){
  131. if(date("H") != 19){
  132. exit("当前不是19点执行".date("H"));
  133. }
  134. //允许长时间运行
  135. set_time_limit(0);
  136. $where_arr = [
  137. //"shop"=>35,//当前店铺为tt-wk
  138. "express"=>83,//快递为tt-cbt
  139. "print"=>2,//未打印
  140. 'printtype'=>1,//打运单
  141. "printnumber"=>0,//打印次数
  142. 'library'=>1,//未出库
  143. //'libraryconfirm'=>2,//允许出库
  144. "review >"=>4,//审核通过或自动审核
  145. ];
  146. //$shop_info = $this->shop->read(35);
  147. $shop_list = $this->shop->find_all('1 = 1');
  148. $shop_list = array_column($shop_list,null,'id');
  149. // if(empty($shop_info)){
  150. // exit("当前店铺不存在");
  151. // }
  152. $list = $this->db->from("fullordertt")
  153. ->select("id,orderinfo,shop,express,print,printnumber,library,review,state")
  154. ->where($where_arr)
  155. ->where_not_in('state',[214,217])
  156. ->get()->result_array();
  157. if(empty($list)){
  158. exit("没有符合条件的订单");
  159. }
  160. foreach($list as $k=>$v){
  161. $info = $this->fullordertt->read($v['id']);
  162. if(empty($info['extra_text'])){
  163. continue;
  164. }
  165. $extra_text = json_decode($info['extra_text'],true);
  166. if(isset($extra_text['server_info'])){
  167. continue;
  168. }
  169. if(isset($shop_list[$info['shop']])){
  170. $r = $this->express_tt->getExpressInfo($info,$shop_list[$info['shop']]);
  171. print_r($info['orderinfo']);
  172. print_r("|");
  173. usleep(10);
  174. }
  175. if(date("H") == 20){
  176. exit("执行到20点了 不能在执行了");
  177. }
  178. }
  179. echo "<br/>";
  180. exit("执行完成");
  181. }
  182. }