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. 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. $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. }