Model_job_getcbtwaybillid.php 1.8 KB

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