QueueCbt.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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. $this->_preGetService();
  28. }
  29. else
  30. {
  31. exit('No direct script access allowed');
  32. }
  33. }
  34. //tiktok的cbt发货模式 按照定时任务先创建标签
  35. //订单状态要求 已审核 未打印 未出库 允许出库 允许打印 快递必须要是cbt
  36. // 当前店铺为tt-wk
  37. private function _cbtCreateLabel(){
  38. if(date("H") != 20){
  39. exit("当前不是20点执行".date("H"));
  40. }
  41. //允许长时间运行
  42. set_time_limit(0);
  43. $where_arr = [
  44. //"shop"=>35,//当前店铺为tt-wk
  45. //"express"=>83,//快递为tt-cbt
  46. "print"=>2,//未打印
  47. "printnumber"=>0,//打印次数
  48. 'library'=>1,//未出库
  49. 'printtype'=>1,//打运单
  50. //'libraryconfirm'=>2,//允许出库
  51. "review >"=>4,//审核通过或自动审核
  52. ];
  53. //$shop_info = $this->shop->read(35);
  54. $shop_list = $this->shop->find_all('1 = 1');
  55. $shop_list = array_column($shop_list,null,'id');
  56. // if(empty($shop_info)){
  57. // exit("当前店铺不存在");
  58. // }
  59. $list = $this->db->from("fullordertt")
  60. ->select("id,orderinfo,shop,express,print,printnumber,library,review,state")
  61. ->where($where_arr)
  62. ->where_in("express",[83,85])
  63. ->where_not_in('state',[214,217])
  64. ->get()->result_array();
  65. if(empty($list)){
  66. exit("没有符合条件的订单");
  67. }
  68. foreach($list as $k=>$v){
  69. $info = $this->fullordertt->read($v['id']);
  70. if(empty($info['extra_text'])){
  71. continue;
  72. }
  73. $extra_text = json_decode($info['extra_text'],true);
  74. if(isset($extra_text['label_info'])){
  75. continue;
  76. }
  77. if(isset($shop_list[$info['shop']])){
  78. $r = $this->express_tt->doCreateCBTLabel($info,$shop_list[$info['shop']]);
  79. print_r($info['orderinfo']);
  80. print_r("|");
  81. usleep(500);
  82. }
  83. }
  84. var_dump(date("<br/>执行完成<br/>"));
  85. sleep(3);
  86. $this->_cbtCreateLabelAgain();
  87. }
  88. private function _cbtCreateLabelAgain(){
  89. $where_arr = [
  90. //"shop"=>35,//当前店铺为tt-wk
  91. // "express"=>83,//快递为tt-cbt
  92. "print"=>2,//未打印
  93. 'printtype'=>1,//打运单
  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_in("express",[83,85])
  109. ->where_not_in('state',[214,217])
  110. ->get()->result_array();
  111. if(empty($list)){
  112. exit("没有符合条件的订单");
  113. }
  114. foreach($list as $k=>$v){
  115. $info = $this->fullordertt->read($v['id']);
  116. if(empty($info['extra_text'])){
  117. continue;
  118. }
  119. $extra_text = json_decode($info['extra_text'],true);
  120. if(isset($extra_text['label_info'])){
  121. continue;
  122. }
  123. if(isset($shop_list[$info['shop']])){
  124. $r = $this->express_tt->doCreateCBTLabel($info,$shop_list[$info['shop']]);
  125. print_r($info['orderinfo']);
  126. print_r("|");
  127. usleep(500);
  128. }
  129. }
  130. var_dump(date("<br/>执行完成again<br/>"));
  131. sleep(3);
  132. $this->_cbtCreateLabelThree();
  133. }
  134. private function _cbtCreateLabelThree(){
  135. $where_arr = [
  136. //"shop"=>35,//当前店铺为tt-wk
  137. // "express"=>83,//快递为tt-cbt
  138. "print"=>2,//未打印
  139. 'printtype'=>1,//打运单
  140. "printnumber"=>0,//打印次数
  141. 'library'=>1,//未出库
  142. //'libraryconfirm'=>2,//允许出库
  143. "review >"=>4,//审核通过或自动审核
  144. ];
  145. //$shop_info = $this->shop->read(35);
  146. $shop_list = $this->shop->find_all('1 = 1');
  147. $shop_list = array_column($shop_list,null,'id');
  148. // if(empty($shop_info)){
  149. // exit("当前店铺不存在");
  150. // }
  151. $list = $this->db->from("fullordertt")
  152. ->select("id,orderinfo,shop,express,print,printnumber,library,review,state")
  153. ->where($where_arr)
  154. ->where_in("express",[83,85])
  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['label_info'])){
  167. continue;
  168. }
  169. if(isset($shop_list[$info['shop']])){
  170. $r = $this->express_tt->doCreateCBTLabel($info,$shop_list[$info['shop']]);
  171. print_r($info['orderinfo']);
  172. print_r("|");
  173. usleep(500);
  174. }
  175. }
  176. echo "<br/>";
  177. exit("执行完成three");
  178. }
  179. public function _preGetService(){
  180. $where_arr = [
  181. //"shop"=>35,//当前店铺为tt-wk
  182. //"express"=>83,//快递为tt-cbt
  183. // "print"=>2,//未打印
  184. // 'printtype'=>1,//打运单
  185. "printnumber"=>0,//打印次数
  186. 'library'=>1,//未出库
  187. //'libraryconfirm'=>2,//允许出库
  188. // "review >"=>4,//审核通过或自动审核
  189. "ttsp_status"=>0,//未同步 快递承运商
  190. ];
  191. //$shop_info = $this->shop->read(35);
  192. $shop_list = $this->shop->find_all('1 = 1');
  193. $shop_list = array_column($shop_list,null,'id');
  194. // if(empty($shop_info)){
  195. // exit("当前店铺不存在");
  196. // }
  197. $list = $this->db->from("fullordertt")
  198. ->select("id,orderinfo,shop,express,print,printnumber,library,review,state")
  199. ->where($where_arr)
  200. ->where_in("express",[83,85])
  201. ->where_not_in('state',[214,217])
  202. ->get()->result_array();
  203. if(empty($list)){
  204. exit("没有符合条件的订单");
  205. }
  206. foreach($list as $k=>$v){
  207. $info = $this->fullordertt->read($v['id']);
  208. if(empty($info['extra_text'])){
  209. continue;
  210. }
  211. $extra_text = json_decode($info['extra_text'],true);
  212. if(isset($extra_text['server_info'])){
  213. continue;
  214. }
  215. if(isset($shop_list[$info['shop']])){
  216. $r = $this->express_tt->getExpressInfo($info,$shop_list[$info['shop']]);
  217. print_r($info['orderinfo']);
  218. print_r("|");
  219. usleep(10);
  220. }
  221. }
  222. }
  223. public function _getService(){
  224. if(date("H") != 18){
  225. exit("当前不是18点执行".date("H"));
  226. }
  227. //允许长时间运行
  228. set_time_limit(0);
  229. $where_arr = [
  230. //"shop"=>35,//当前店铺为tt-wk
  231. //"express"=>83,//快递为tt-cbt
  232. "print"=>2,//未打印
  233. 'printtype'=>1,//打运单
  234. "printnumber"=>0,//打印次数
  235. 'library'=>1,//未出库
  236. //'libraryconfirm'=>2,//允许出库
  237. "review >"=>4,//审核通过或自动审核
  238. ];
  239. //$shop_info = $this->shop->read(35);
  240. $shop_list = $this->shop->find_all('1 = 1');
  241. $shop_list = array_column($shop_list,null,'id');
  242. // if(empty($shop_info)){
  243. // exit("当前店铺不存在");
  244. // }
  245. $list = $this->db->from("fullordertt")
  246. ->select("id,orderinfo,shop,express,print,printnumber,library,review,state")
  247. ->where($where_arr)
  248. ->where_in("express",[83,85])
  249. ->where_not_in('state',[214,217])
  250. ->get()->result_array();
  251. if(empty($list)){
  252. exit("没有符合条件的订单");
  253. }
  254. foreach($list as $k=>$v){
  255. $info = $this->fullordertt->read($v['id']);
  256. if(empty($info['extra_text'])){
  257. continue;
  258. }
  259. $extra_text = json_decode($info['extra_text'],true);
  260. if(isset($extra_text['server_info'])){
  261. continue;
  262. }
  263. if(isset($shop_list[$info['shop']])){
  264. $r = $this->express_tt->getExpressInfo($info,$shop_list[$info['shop']]);
  265. print_r($info['orderinfo']);
  266. print_r("|");
  267. usleep(10);
  268. }
  269. if(date("H") == 20){
  270. exit("执行到20点了 不能在执行了");
  271. }
  272. }
  273. echo "<br>执行完成<br/>";
  274. $this->_getServiceAgain();
  275. }
  276. public function _getServiceAgain(){
  277. //允许长时间运行
  278. set_time_limit(0);
  279. $where_arr = [
  280. //"shop"=>35,//当前店铺为tt-wk
  281. //"express"=>83,//快递为tt-cbt
  282. "print"=>2,//未打印
  283. 'printtype'=>1,//打运单
  284. "printnumber"=>0,//打印次数
  285. 'library'=>1,//未出库
  286. //'libraryconfirm'=>2,//允许出库
  287. "review >"=>4,//审核通过或自动审核
  288. ];
  289. //$shop_info = $this->shop->read(35);
  290. $shop_list = $this->shop->find_all('1 = 1');
  291. $shop_list = array_column($shop_list,null,'id');
  292. // if(empty($shop_info)){
  293. // exit("当前店铺不存在");
  294. // }
  295. $list = $this->db->from("fullordertt")
  296. ->select("id,orderinfo,shop,express,print,printnumber,library,review,state")
  297. ->where($where_arr)
  298. ->where_in("express",[83,85])
  299. ->where_not_in('state',[214,217])
  300. ->get()->result_array();
  301. if(empty($list)){
  302. exit("没有符合条件的订单");
  303. }
  304. foreach($list as $k=>$v){
  305. $info = $this->fullordertt->read($v['id']);
  306. if(empty($info['extra_text'])){
  307. continue;
  308. }
  309. $extra_text = json_decode($info['extra_text'],true);
  310. if(isset($extra_text['server_info'])){
  311. continue;
  312. }
  313. if(isset($shop_list[$info['shop']])){
  314. $r = $this->express_tt->getExpressInfo($info,$shop_list[$info['shop']]);
  315. print_r($info['orderinfo']);
  316. print_r("|");
  317. usleep(10);
  318. }
  319. if(date("H") == 20){
  320. exit("执行到20点了 不能在执行了");
  321. }
  322. }
  323. echo "<br/>";
  324. exit("执行完成again");
  325. }
  326. }