123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- <?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'){
- $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);
- }
-
- }else{
- return [
- 'x'=>0,
- 'Description'=>'暂不支持该快递类型',
- ];
- }
-
- }
- 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_info = json_decode($info['extra_info'],true);
- $extra_info['server_info'] = $res['data'];
- $info['extra_info'] = json_encode($extra_info,JSON_UNESCAPED_UNICODE);
- $this->db->update('fullordertt', [
- 'extra_info' => $info['extra_info']
- ], ['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_info = json_decode($info['extra_info'],true);
- $extra_info['label_info'] = $res['data'];
- $info['extra_info'] = json_encode($extra_info,JSON_UNESCAPED_UNICODE);
- $this->db->update('fullordertt', [
- 'extra_info' => $info['extra_info']
- ], ['id' => $info['id']]) ;
- return [
- 'x'=>1,
- 'msg'=>'获取成功',
- 'data'=>$info
- ];
-
- }
- //下载快递面单
- private function downloadExpressLabel($info,$shop){
- $extra_info = json_decode($info['extra_info'],true);
- $packageid = $extra_info['label_info']['packageid'];
- $res = $this->apitt->downloadLabel($packageid,$shop,$info);
- if($res['code'] != 0){
- return [
- 'x'=>0,
- 'Description'=>$res['message'],
- ];
- }
- $extra_info = json_decode($info['extra_info'],true);
- $extra_info['express_info'] = $res['data'];
- $info['extra_info'] = json_encode($extra_info,JSON_UNESCAPED_UNICODE);
- $this->db->update('fullordertt', [
- 'extra_info' => $info['extra_info']
- ], ['id' => $info['id']]) ;
- return [
- 'x'=>1,
- 'msg'=>'获取成功',
- 'waybill'=>$res['data']['tracking_number'],
- 'label'=>$res['data']['doc_url'],
- ];
-
- }
- }
|