| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- /**
- * 封装一些常规的订单操作
- */
- class Model_job_getcbtwaybillid extends Lin_Model {
- function __construct(){
- parent::__construct();
- $this->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']);
- }else{
- $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 ;
- }
- $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']);
- }
- }
- }
- }
|