load->_model('Model_apitt','apitt'); $this->load->_model('Model_fullordertt','fullordertt'); $this->load->_model("Model_shop","shop"); } public function doAction(){ $start_time = time() - 3600 * 24 * 6; $where = "cf = 1 and waybill = '' and type = '34' and state = '216' and shop = 42 "; $where .= " and buytime > ".$start_time; $list = $this->fullordertt->find_all($where,"id,orderinfo,number,shop,cf,waybill,type,state,buytime,extra_text"); if(empty($list)){ return ; } $shop_info = $this->shop->read(42); foreach($list as $k => $v){ if(empty($v['waybill'])){ $this->getWaybill($v,$shop_info); } } } private function getWaybill($info,$shop){ if(empty($info['extra_text'])){ $res = $this->apitt->get_detail($info['orderinfo'],$shop); if($res['code'] == 0){ $data = $res['data']; $packages_id = $data['orders'][0]['packages'][0]['id']; }else{ return ; } }else{ if(is_string($info['extra_text'])){ $extra_text = json_decode($info['extra_text'],true); } $packages_id = $extra_text['packages'][0]['id']; } $waybill_info = $this->apitt->getWaybillInfo($packages_id,$shop); if($waybill_info['code'] == 0){ $waybill = $waybill_info['data']['tracking_number']; $this->fullordertt->save(['waybill' => $waybill],$info['id']); } } }