Model_job_gethualeiwaybillid.php 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. class Model_job_gethualeiwaybillid extends Lin_Model {
  3. function __construct(){
  4. parent::__construct();
  5. $this->load->_model("Model_hualei","hualei");
  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. $this->load->_model("Model_logic_ding","logic_ding");
  11. }
  12. public function do_job(){
  13. $end_time = time() - 10* 3600 * 24;
  14. $start_time = time() - 3600 * 24;
  15. // 目前只处理惠城的usps 73
  16. // 出库时间十天前 waybillid 不能为空
  17. $where = "express = 73 and librarytime >= ".$end_time ." and librarytime <= ".$start_time." ";
  18. //$where = "express = 76 and librarytime <= ".$start_time." ";
  19. $fields = "id,number,waybill,waybillid,librarytime,express";
  20. echo "<pre>";
  21. var_dump(date("Y-m-d H:i:s",time()));
  22. $this->do_dlz($where,$fields);
  23. $this->do_tt($where,$fields);
  24. $this->do_amz($where,$fields);
  25. $this->do_smt($where,$fields);
  26. var_dump(date("Y-m-d H:i:s",time()));
  27. }
  28. //执行对立站的代码
  29. private function do_dlz($where,$fields){
  30. $list = $this->fullorder->find_all($where,$fields);
  31. foreach($list as $item){
  32. if(empty($item['waybillid'])){
  33. $this->do_final($item,"fullorder");
  34. }else{
  35. continue;
  36. }
  37. }
  38. }
  39. private function do_tt($where,$fields){
  40. $list = $this->fullordertt->find_all($where,$fields);
  41. foreach($list as $item){
  42. if(empty($item['waybillid'])){
  43. $this->do_final($item,"fullordertt");
  44. }else{
  45. continue;
  46. }
  47. }
  48. }
  49. private function do_amz($where,$fields){
  50. $list = $this->fullorderamz->find_all($where,$fields);
  51. foreach($list as $item){
  52. if(empty($item['waybillid'])){
  53. $this->do_final($item,"fullorderamz");
  54. }else{
  55. continue;
  56. }
  57. }
  58. }
  59. private function do_smt($where,$fields){
  60. $list = $this->fullordersmt->find_all($where,$fields);
  61. foreach($list as $item){
  62. if(empty($item['waybillid'])){
  63. $this->do_final($item,"fullordersmt");
  64. }else{
  65. continue;
  66. }
  67. }
  68. }
  69. private function do_final($info,$table_name){
  70. sleep(1);
  71. $res = $this->hualei->getDetail($info['number']);
  72. // var_dump($table_name);
  73. // var_dump($res);
  74. $res = json_decode($res,true);
  75. if(isset($res['msg_code']) && $res['msg_code'] == 200){
  76. if(isset($res['data'])){
  77. if(isset($res['data']['order_serveinvoicecode'])){
  78. if(strpos($res['data']['order_serveinvoicecode'],"HC") === false){
  79. if(!empty($res['data']['order_serveinvoicecode']) && $res['data']['order_serveinvoicecode'] != $info['waybill']){
  80. $this->$table_name->save(['waybillid' => $res['data']['order_serveinvoicecode']],$info['id']);
  81. //$this->logic_ding->sendToDing("惠城转单号更新信息【".$info['waybill']."】"."转单号:".$res['data']['order_serveinvoicecode']." 平台:".$table_name."订单详细信息:{".json_encode($info)."}");
  82. }
  83. }
  84. }
  85. }
  86. }
  87. }
  88. }