QueueCbt.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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_in("express",[83,85])
  62. ->where_not_in('state',[214,217])
  63. ->get()->result_array();
  64. if(empty($list)){
  65. exit("没有符合条件的订单");
  66. }
  67. foreach($list as $k=>$v){
  68. $info = $this->fullordertt->read($v['id']);
  69. if(empty($info['extra_text'])){
  70. continue;
  71. }
  72. $extra_text = json_decode($info['extra_text'],true);
  73. if(isset($extra_text['label_info'])){
  74. continue;
  75. }
  76. if(isset($shop_list[$info['shop']])){
  77. $r = $this->express_tt->doCreateCBTLabel($info,$shop_list[$info['shop']]);
  78. print_r($info['orderinfo']);
  79. print_r("|");
  80. usleep(500);
  81. }
  82. }
  83. var_dump(date("<br/>执行完成<br/>"));
  84. sleep(3);
  85. $this->_cbtCreateLabelAgain();
  86. }
  87. private function _cbtCreateLabelAgain(){
  88. $where_arr = [
  89. //"shop"=>35,//当前店铺为tt-wk
  90. // "express"=>83,//快递为tt-cbt
  91. "print"=>2,//未打印
  92. 'printtype'=>1,//打运单
  93. "printnumber"=>0,//打印次数
  94. 'library'=>1,//未出库
  95. //'libraryconfirm'=>2,//允许出库
  96. "review >"=>4,//审核通过或自动审核
  97. ];
  98. //$shop_info = $this->shop->read(35);
  99. $shop_list = $this->shop->find_all('1 = 1');
  100. $shop_list = array_column($shop_list,null,'id');
  101. // if(empty($shop_info)){
  102. // exit("当前店铺不存在");
  103. // }
  104. $list = $this->db->from("fullordertt")
  105. ->select("id,orderinfo,shop,express,print,printnumber,library,review,state")
  106. ->where($where_arr)
  107. ->where_in("express",[83,85])
  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_decode($info['extra_text'],true);
  119. if(isset($extra_text['label_info'])){
  120. continue;
  121. }
  122. if(isset($shop_list[$info['shop']])){
  123. $r = $this->express_tt->doCreateCBTLabel($info,$shop_list[$info['shop']]);
  124. print_r($info['orderinfo']);
  125. print_r("|");
  126. usleep(500);
  127. }
  128. }
  129. echo "<br/>";
  130. exit("执行完成again");
  131. }
  132. public function _preGetService(){
  133. $where_arr = [
  134. //"shop"=>35,//当前店铺为tt-wk
  135. //"express"=>83,//快递为tt-cbt
  136. "print"=>2,//未打印
  137. 'printtype'=>1,//打运单
  138. "printnumber"=>0,//打印次数
  139. 'library'=>1,//未出库
  140. //'libraryconfirm'=>2,//允许出库
  141. "review >"=>4,//审核通过或自动审核
  142. "ttsp_status"=>0,//未同步 快递承运商
  143. ];
  144. //$shop_info = $this->shop->read(35);
  145. $shop_list = $this->shop->find_all('1 = 1');
  146. $shop_list = array_column($shop_list,null,'id');
  147. // if(empty($shop_info)){
  148. // exit("当前店铺不存在");
  149. // }
  150. $list = $this->db->from("fullordertt")
  151. ->select("id,orderinfo,shop,express,print,printnumber,library,review,state")
  152. ->where($where_arr)
  153. ->where_in("express",[83,85])
  154. ->where_not_in('state',[214,217])
  155. ->get()->result_array();
  156. if(empty($list)){
  157. exit("没有符合条件的订单");
  158. }
  159. foreach($list as $k=>$v){
  160. $info = $this->fullordertt->read($v['id']);
  161. if(empty($info['extra_text'])){
  162. continue;
  163. }
  164. $extra_text = json_decode($info['extra_text'],true);
  165. if(isset($extra_text['server_info'])){
  166. continue;
  167. }
  168. if(isset($shop_list[$info['shop']])){
  169. $r = $this->express_tt->getExpressInfo($info,$shop_list[$info['shop']]);
  170. print_r($info['orderinfo']);
  171. print_r("|");
  172. usleep(10);
  173. }
  174. }
  175. }
  176. public function _getService(){
  177. if(date("H") != 18){
  178. exit("当前不是18点执行".date("H"));
  179. }
  180. //允许长时间运行
  181. set_time_limit(0);
  182. $where_arr = [
  183. //"shop"=>35,//当前店铺为tt-wk
  184. //"express"=>83,//快递为tt-cbt
  185. "print"=>2,//未打印
  186. 'printtype'=>1,//打运单
  187. "printnumber"=>0,//打印次数
  188. 'library'=>1,//未出库
  189. //'libraryconfirm'=>2,//允许出库
  190. "review >"=>4,//审核通过或自动审核
  191. ];
  192. //$shop_info = $this->shop->read(35);
  193. $shop_list = $this->shop->find_all('1 = 1');
  194. $shop_list = array_column($shop_list,null,'id');
  195. // if(empty($shop_info)){
  196. // exit("当前店铺不存在");
  197. // }
  198. $list = $this->db->from("fullordertt")
  199. ->select("id,orderinfo,shop,express,print,printnumber,library,review,state")
  200. ->where($where_arr)
  201. ->where_in("express",[83,85])
  202. ->where_not_in('state',[214,217])
  203. ->get()->result_array();
  204. if(empty($list)){
  205. exit("没有符合条件的订单");
  206. }
  207. foreach($list as $k=>$v){
  208. $info = $this->fullordertt->read($v['id']);
  209. if(empty($info['extra_text'])){
  210. continue;
  211. }
  212. $extra_text = json_decode($info['extra_text'],true);
  213. if(isset($extra_text['server_info'])){
  214. continue;
  215. }
  216. if(isset($shop_list[$info['shop']])){
  217. $r = $this->express_tt->getExpressInfo($info,$shop_list[$info['shop']]);
  218. print_r($info['orderinfo']);
  219. print_r("|");
  220. usleep(10);
  221. }
  222. if(date("H") == 20){
  223. exit("执行到20点了 不能在执行了");
  224. }
  225. }
  226. echo "<br>执行完成<br/>";
  227. $this->_getServiceAgain();
  228. }
  229. public function _getServiceAgain(){
  230. //允许长时间运行
  231. set_time_limit(0);
  232. $where_arr = [
  233. //"shop"=>35,//当前店铺为tt-wk
  234. //"express"=>83,//快递为tt-cbt
  235. "print"=>2,//未打印
  236. 'printtype'=>1,//打运单
  237. "printnumber"=>0,//打印次数
  238. 'library'=>1,//未出库
  239. //'libraryconfirm'=>2,//允许出库
  240. "review >"=>4,//审核通过或自动审核
  241. ];
  242. //$shop_info = $this->shop->read(35);
  243. $shop_list = $this->shop->find_all('1 = 1');
  244. $shop_list = array_column($shop_list,null,'id');
  245. // if(empty($shop_info)){
  246. // exit("当前店铺不存在");
  247. // }
  248. $list = $this->db->from("fullordertt")
  249. ->select("id,orderinfo,shop,express,print,printnumber,library,review,state")
  250. ->where($where_arr)
  251. ->where_in("express",[83,85])
  252. ->where_not_in('state',[214,217])
  253. ->get()->result_array();
  254. if(empty($list)){
  255. exit("没有符合条件的订单");
  256. }
  257. foreach($list as $k=>$v){
  258. $info = $this->fullordertt->read($v['id']);
  259. if(empty($info['extra_text'])){
  260. continue;
  261. }
  262. $extra_text = json_decode($info['extra_text'],true);
  263. if(isset($extra_text['server_info'])){
  264. continue;
  265. }
  266. if(isset($shop_list[$info['shop']])){
  267. $r = $this->express_tt->getExpressInfo($info,$shop_list[$info['shop']]);
  268. print_r($info['orderinfo']);
  269. print_r("|");
  270. usleep(10);
  271. }
  272. if(date("H") == 20){
  273. exit("执行到20点了 不能在执行了");
  274. }
  275. }
  276. echo "<br/>";
  277. exit("执行完成again");
  278. }
  279. }