123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- <?php
- class Model_express_tt extends Lin_Model {
- function __construct(){
- parent::__construct();
- $this->load->_model("Model_apitt","apitt");
- }
-
- public function getData($info,$type = 'CBT'){
- if(empty($info)){
- return $g = [
- 'x'=>0,
- 'Description'=>'订单信息不存在',
- ];
- }
- $shop_info = $this->db->from('shop')->where('id', $info['shop'])->get()->result_array();
-
- if(empty($shop_info)){
- return [
- 'x'=>0,
- 'Description'=>'该商铺不存在',
- ];
- }
- if($type == 'CBT'){
-
- //获取快递服务信息
- $res = $this->getExpressCompany($info,$shop_info[0]);
- if($res['x'] == 0){
- return $res;
- }
- $res1 = $this->createExpressLabel($res['data'],$shop_info[0]);
- if($res1['x'] == 0){
- return $res1;
- }
- $res2 = $this->downloadExpressLabel($res['data'],$shop_info[0]);
- if($res2['x'] == 0){
- return $res2;
- }
- return [
- 'x'=>1,
- 'msg'=>'获取成功',
- 'data'=>$info
- ];
- }else if($type == 'FBT'){
- $extra_text = json_decode($info['extra_text'],true);
- if(empty($extra_text)){
- return $this->getFBTOrderDetail($info,$shop_info);
- }
- if(empty($extra_text['packages'])){
- return $this->getFBTOrderDetail($info,$shop_info);
- }
- $info['extra_text'] = $extra_text;
- return $this->getFBTPackage($info,$shop_info);
-
- }else{
- return [
- 'x'=>0,
- 'Description'=>'暂不支持该快递类型',
- ];
- }
-
- }
- private function getFBTOrderDetail($info,$shop_info){
- var_dump("执行到getFBTOrderDetail");
- $res = $this->apitt->get_data([$info['orderinfo']],$shop_info[0]);
- if($res['code'] != 0){
- return [
- 'x'=>0,
- 'Description'=>$res['message'],
- ];
- }
- if(!isset($res['data']['orders'])){
- return [
- 'x'=>0,
- 'Description'=>"获取TT订单信息异常",
- ];
- }
- if(empty($res['data']['orders'])){
- return [
- 'x'=>0,
- 'Description'=>"获取TT订单信息异常",
- ];
- }
- if(empty($res['data']['orders'][0]['packages'])){
- return [
- 'x'=>0,
- 'Description'=>"获取TT订单的快递信息",
- ];
- }
- $packages = $res['data']['orders'][0]['packages'];
- $label_list = [];
- print_r($packages);
- foreach($packages as $package){
- $rr = $this->apitt->downloadLabel($package['id'],$shop_info[0],$info);
- print_r($rr);
- }
- }
- private function getFBTPackage($info,$shop_info){
- var_dump("执行到getFBTPackage");
- $extra_text = $info['extra_text'];
- $packages = $extra_text['packages'];
- // 确定没有多包裹的情况 就不再写循环了 直接获取第一个包裹
- // foreach($packages as $package){
- // $rr = $this->apitt->downloadLabel($package['id'],$shop_info[0],$info);
- // if($rr['code']!=0){
- // $flag_status = 1;
- // $err_arr[] = $rr['message'];
- // }else{
- // $label_list[] = [
- // 'waybill'=>$rr['data']['tracking_number'],
- // 'label'=>$rr['data']['doc_url'],
- // ];
- // }
- // }
- $packageid = $packages[0]['id'];
- $rr = $this->apitt->downloadLabel($packageid,$shop_info[0],$info);
- if($rr['code']!=0){
- return [
- 'x'=>0,
- 'Description'=>$rr['message'],
- ];
- }else{
- return [
- 'x'=>1,
- 'msg'=>'获取成功',
- 'waybill'=>$rr['data']['tracking_number'],
- 'label'=>$rr['data']['doc_url'],
- ];
- }
- }
- private function getOrderDetail($info,$shop_info){
- }
-
- //获取订单承运的快递商
- private function getExpressCompany($info,$shop_info){
- $res = $this->apitt->getExpressCompany($info,$shop_info);
- if($res['code'] != 0){
- return [
- 'x'=>0,
- 'Description'=>$res['message'],
- ];
- }
- $extra_text = json_decode($info['extra_text'],true);
- $extra_text['server_info'] = $res['data'];
- $info['extra_text'] = json_encode($extra_text,JSON_UNESCAPED_UNICODE);
- $this->db->update('fullordertt', [
- 'extra_text' => $info['extra_text']
- ], ['id' => $info['id']]) ;
- return [
- 'x'=>1,
- 'msg'=>'获取成功',
- 'data'=>$info
- ];
- }
- //创建发货单和运单标签
- private function createExpressLabel($info,$shop_info){
- $res = $this->apitt->createExpressLabel($info,$shop_info);
- if($res['code'] != 0){
- return [
- 'x'=>0,
- 'Description'=>$res['message'],
- ];
- }
- $extra_text = json_decode($info['extra_text'],true);
- $extra_text['label_info'] = $res['data'];
- $info['extra_text'] = json_encode($extra_text,JSON_UNESCAPED_UNICODE);
- $this->db->update('fullordertt', [
- 'extra_text' => $info['extra_text']
- ], ['id' => $info['id']]) ;
- return [
- 'x'=>1,
- 'msg'=>'获取成功',
- 'data'=>$info
- ];
-
- }
- //下载快递面单
- private function downloadExpressLabel($info,$shop){
- $extra_text = json_decode($info['extra_text'],true);
- $packageid = $extra_text['label_info']['packageid'];
- $res = $this->apitt->downloadLabel($packageid,$shop,$info);
- if($res['code'] != 0){
- return [
- 'x'=>0,
- 'Description'=>$res['message'],
- ];
- }
- $extra_text = json_decode($info['extra_text'],true);
- $extra_text['express_info'] = $res['data'];
- $info['extra_text'] = json_encode($extra_text,JSON_UNESCAPED_UNICODE);
- $this->db->update('fullordertt', [
- 'extra_text' => $info['extra_text']
- ], ['id' => $info['id']]) ;
- return [
- 'x'=>1,
- 'msg'=>'获取成功',
- 'waybill'=>$res['data']['tracking_number'],
- 'label'=>$res['data']['doc_url'],
- ];
-
- }
- }
|