Model_job_getcbtwaybillid.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. echo "<pre>";
  18. print_r($list);
  19. die;
  20. if(empty($list)){
  21. return ;
  22. }
  23. $shop_info = $this->shop->read(42);
  24. foreach($list as $k => $v){
  25. if(empty($v['waybill'])){
  26. $this->getWaybill($v,$shop_info);
  27. }
  28. }
  29. }
  30. private function getWaybill($info,$shop){
  31. if(empty($info['extra_text'])){
  32. $res = $this->apitt->get_detail($info['orderinfo'],$shop);
  33. if($res['code'] == 0){
  34. $data = $res['data'];
  35. $packages_id = $data['orders'][0]['packages'][0]['id'];
  36. }else{
  37. return ;
  38. }
  39. }else{
  40. if(is_string($info['extra_text'])){
  41. $extra_text = json_decode($info['extra_text'],true);
  42. }
  43. $packages_id = $extra_text['packages'][0]['id'];
  44. }
  45. echo "<pre>";
  46. print_r($packages_id);
  47. die;
  48. $waybill_info = $this->apitt->getWaybillInfo($packages_id,$shop);
  49. if($waybill_info['code'] == 0){
  50. $waybill = $waybill_info['data']['tracking_number'];
  51. $this->fullordertt->save(['waybill' => $waybill],$info['id']);
  52. }
  53. }
  54. }