Model_job_getyuntuwaybillid.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. class Model_job_getyuntuwaybillid extends Lin_Model {
  3. function __construct(){
  4. parent::__construct();
  5. $this->load->_model("Model_yuntu","yuntu");
  6. $this->load->_model("Model_fullorder","fullorder");
  7. $this->load->_model("Model_fullordersmt","fullordersmt");
  8. $this->load->_model("Model_fullordertt","fullordertt");
  9. $this->load->_model("Model_fullorderamz","fullorderamz");
  10. }
  11. public function do_job(){
  12. $end_time = time() - 5 * 3600 * 24;
  13. $start_time = time() - 1 * 3600 * 24;
  14. //快递为3pe 76 出库时间十天前 waybillid 不能为空
  15. $where = "express in (66,67) and librarytime >= ".$end_time ." and librarytime <= ".$start_time." ";
  16. // $where = "express in (66,67) ";
  17. $fields = "id,number,waybill,waybillid,librarytime,express";
  18. echo "<pre>";
  19. var_dump(date("Y-m-d H:i:s",time()));
  20. $this->do_dlz($where,$fields);
  21. $this->do_tt($where,$fields);
  22. $this->do_amz($where,$fields);
  23. $this->do_smt($where,$fields);
  24. var_dump(date("Y-m-d H:i:s",time()));
  25. }
  26. //执行对立站的代码
  27. private function do_dlz($where,$fields){
  28. $list = $this->fullorder->find_all($where,$fields,'id asc',0,300);
  29. $final_list = [];
  30. foreach($list as $item){
  31. if(empty($item['waybillid'])&&(!empty($item['waybill']))){
  32. $final_list[] = $item['waybill'];
  33. }else{
  34. continue;
  35. }
  36. }
  37. if(empty($final_list)){
  38. return;
  39. }
  40. $this->do_final($final_list,"fullorder");
  41. }
  42. private function do_tt($where,$fields){
  43. $list = $this->fullordertt->find_all($where,$fields,'id asc',0,300);
  44. $final_list = [];
  45. foreach($list as $item){
  46. if(empty($item['waybillid'])&&(!empty($item['waybill']))){
  47. $final_list[] = $item['waybill'];
  48. }else{
  49. continue;
  50. }
  51. }
  52. if(empty($final_list)){
  53. return;
  54. }
  55. $this->do_final($final_list,"fullordertt");
  56. }
  57. private function do_amz($where,$fields){
  58. $list = $this->fullorderamz->find_all($where,$fields,'id asc',0,300);
  59. $final_list = [];
  60. foreach($list as $item){
  61. if(empty($item['waybillid'])&&(!empty($item['waybill']))){
  62. $final_list[] = $item['waybill'];
  63. }else{
  64. continue;
  65. }
  66. }
  67. if(empty($final_list)){
  68. return;
  69. }
  70. $this->do_final($final_list,"fullorderamz");
  71. }
  72. private function do_smt($where,$fields){
  73. $list = $this->fullordersmt->find_all($where,$fields,'id asc',0,300);
  74. $final_list = [];
  75. foreach($list as $item){
  76. if(empty($item['waybillid'])&&(!empty($item['waybill']))){
  77. $final_list[] = $item['waybill'];
  78. }else{
  79. continue;
  80. }
  81. }
  82. if(empty($final_list)){
  83. return;
  84. }
  85. $this->do_final($final_list,"fullordersmt");
  86. }
  87. private function do_final($final_list,$table_name){
  88. $arr = array_chunk($final_list,15);
  89. foreach($arr as $item){
  90. sleep(1);
  91. $res = $this->yuntu->getTransferNumber($item);
  92. if(isset($res['result'])){
  93. if(isset($res['result']['carriers'])){
  94. foreach($res['result']['carriers'] as $value){
  95. $list = $this->$table_name->find_all("waybill = '". $value['waybill_number']."'",'id,number,waybill,waybillid,librarytime,express');
  96. if(!empty($list)){
  97. foreach($list as $item_info){
  98. $this->$table_name->save(['waybillid'=>$value['tracking_number']],$item_info['id']);
  99. //$this->logic_ding->sendToDing("云途转单号更新信息【".$item_info['waybill']."】"."转单号:".$value['tracking_number']." 平台:".$table_name."订单详细信息:{".json_encode($item_info)."}");
  100. }
  101. }
  102. }
  103. }
  104. }
  105. }
  106. }
  107. }