Model_job_getcbtwaybillid.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * 封装一些常规的订单操作
  4. */
  5. class Model_job_getcbtwaybillid extends Lin_Model {
  6. function __construct(){
  7. parent::__construct();
  8. $this->load->_model('Model_apitt','apitt');
  9. $this->load->_model('Model_fullordertt','fullordertt');
  10. $this->load->_model("Model_shop","shop");
  11. }
  12. public function doAction(){
  13. $start_time = time() - 3600 * 24 * 6;
  14. $where = "cf = 1 and waybill = '' and type = '34' and state = '216' and shop = 42 ";
  15. $where .= " and buytime > ".$start_time;
  16. $list = $this->fullordertt->find_all($where,"id,orderinfo,number,shop,cf,waybill,type,state,buytime,extra_text");
  17. if(empty($list)){
  18. return ;
  19. }
  20. $shop_info = $this->shop->read(42);
  21. foreach($list as $k => $v){
  22. if(empty($v['waybill'])){
  23. $this->getWaybill($v,$shop_info);
  24. }
  25. }
  26. }
  27. private function getWaybill($info,$shop){
  28. if(empty($info['extra_text'])){
  29. $res = $this->apitt->get_detail($info['orderinfo'],$shop);
  30. if($res['code'] == 0){
  31. $data = $res['data'];
  32. $packages_id = $data['orders'][0]['packages'][0]['id'];
  33. }else{
  34. return ;
  35. }
  36. }else{
  37. if(is_string($info['extra_text'])){
  38. $extra_text = json_decode($info['extra_text'],true);
  39. }
  40. $packages_id = $extra_text['packages'][0]['id'];
  41. }
  42. $waybill_info = $this->apitt->getWaybillInfo($packages_id,$shop);
  43. if($waybill_info['code'] == 0){
  44. $waybill = $waybill_info['data']['tracking_number'];
  45. $this->fullordertt->save(['waybill' => $waybill],$info['id']);
  46. }else{
  47. $res = $this->apitt->get_detail($info['orderinfo'],$shop);
  48. if($res['code'] == 0){
  49. $data = $res['data'];
  50. $packages_id = $data['orders'][0]['packages'][0]['id'];
  51. }else{
  52. return ;
  53. }
  54. $waybill_info = $this->apitt->getWaybillInfo($packages_id,$shop);
  55. if($waybill_info['code'] == 0){
  56. $waybill = $waybill_info['data']['tracking_number'];
  57. $this->fullordertt->save(['waybill' => $waybill],$info['id']);
  58. }
  59. }
  60. }
  61. }