QueueCbt.php 12 KB

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