Model_job_getcbtwaybillid.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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['orderinfo'],$shop_info);
  24. die;
  25. }
  26. }
  27. }
  28. private function getWaybill($info,$shop){
  29. if(empty($info['extra_text'])){
  30. $res = $this->apitt->get_detail($info['orderinfo'],$shop);
  31. if($res['code'] == 0){
  32. $data = $res['data'];
  33. $packages_id = $data['orders'][0]['packages'][0]['id'];
  34. }else{
  35. return ;
  36. }
  37. }else{
  38. if(is_string($info['extra_text'])){
  39. $extra_text = json_decode($info['extra_text'],true);
  40. }
  41. $packages_id = $extra_text['packages'][0]['id'];
  42. }
  43. $waybill_info = $this->apitt->getWaybillInfo($packages_id,$shop);
  44. if($waybill_info['code'] == 0){
  45. $waybill = $waybill_info['data']['tracking_number'];
  46. $this->fullordertt->save(['waybill' => $waybill],$info['id']);
  47. }
  48. }
  49. }