Model_express_tt.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. class Model_express_tt extends Lin_Model {
  3. function __construct(){
  4. parent::__construct();
  5. $this->load->_model("Model_apitt","apitt");
  6. }
  7. public function getData($info,$type = 'CBT'){
  8. if(empty($info)){
  9. return $g = [
  10. 'x'=>0,
  11. 'Description'=>'订单信息不存在',
  12. ];
  13. }
  14. $shop_info = $this->db->from('shop')->where('id', $info['shop'])->get()->result_array();
  15. if(empty($shop_info)){
  16. return [
  17. 'x'=>0,
  18. 'Description'=>'该商铺不存在',
  19. ];
  20. }
  21. if($type == 'CBT'){
  22. //获取快递服务信息
  23. $res = $this->getExpressCompany($info,$shop_info[0]);
  24. if($res['x'] == 0){
  25. return $res;
  26. }
  27. $res1 = $this->createExpressLabel($res['data'],$shop_info[0]);
  28. if($res1['x'] == 0){
  29. return $res1;
  30. }
  31. $res2 = $this->downloadExpressLabel($res['data'],$shop_info[0]);
  32. if($res2['x'] == 0){
  33. return $res2;
  34. }
  35. return [
  36. 'x'=>1,
  37. 'msg'=>'获取成功',
  38. 'data'=>$info
  39. ];
  40. }else if($type == 'FBT'){
  41. $res = $this->apitt->get_data([$info['orderinfo']],$shop_info[0]);
  42. echo "<pre>";
  43. print_r($res);
  44. die;
  45. }else{
  46. return [
  47. 'x'=>0,
  48. 'Description'=>'暂不支持该快递类型',
  49. ];
  50. }
  51. }
  52. private function getOrderDetail($info,$shop_info){
  53. }
  54. //获取订单承运的快递商
  55. private function getExpressCompany($info,$shop_info){
  56. $res = $this->apitt->getExpressCompany($info,$shop_info);
  57. if($res['code'] != 0){
  58. return [
  59. 'x'=>0,
  60. 'Description'=>$res['message'],
  61. ];
  62. }
  63. $extra_info = json_decode($info['extra_info'],true);
  64. $extra_info['server_info'] = $res['data'];
  65. $info['extra_info'] = json_encode($extra_info,JSON_UNESCAPED_UNICODE);
  66. $this->db->update('fullordertt', [
  67. 'extra_info' => $info['extra_info']
  68. ], ['id' => $info['id']]) ;
  69. return [
  70. 'x'=>1,
  71. 'msg'=>'获取成功',
  72. 'data'=>$info
  73. ];
  74. }
  75. //创建发货单和运单标签
  76. private function createExpressLabel($info,$shop_info){
  77. $res = $this->apitt->createExpressLabel($info,$shop_info);
  78. if($res['code'] != 0){
  79. return [
  80. 'x'=>0,
  81. 'Description'=>$res['message'],
  82. ];
  83. }
  84. $extra_info = json_decode($info['extra_info'],true);
  85. $extra_info['label_info'] = $res['data'];
  86. $info['extra_info'] = json_encode($extra_info,JSON_UNESCAPED_UNICODE);
  87. $this->db->update('fullordertt', [
  88. 'extra_info' => $info['extra_info']
  89. ], ['id' => $info['id']]) ;
  90. return [
  91. 'x'=>1,
  92. 'msg'=>'获取成功',
  93. 'data'=>$info
  94. ];
  95. }
  96. //下载快递面单
  97. private function downloadExpressLabel($info,$shop){
  98. $extra_info = json_decode($info['extra_info'],true);
  99. $packageid = $extra_info['label_info']['packageid'];
  100. $res = $this->apitt->downloadLabel($packageid,$shop,$info);
  101. if($res['code'] != 0){
  102. return [
  103. 'x'=>0,
  104. 'Description'=>$res['message'],
  105. ];
  106. }
  107. $extra_info = json_decode($info['extra_info'],true);
  108. $extra_info['express_info'] = $res['data'];
  109. $info['extra_info'] = json_encode($extra_info,JSON_UNESCAPED_UNICODE);
  110. $this->db->update('fullordertt', [
  111. 'extra_info' => $info['extra_info']
  112. ], ['id' => $info['id']]) ;
  113. return [
  114. 'x'=>1,
  115. 'msg'=>'获取成功',
  116. 'waybill'=>$res['data']['tracking_number'],
  117. 'label'=>$res['data']['doc_url'],
  118. ];
  119. }
  120. }