Model_express_tt.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. if($res['code'] != 0){
  43. return [
  44. 'x'=>0,
  45. 'Description'=>$res['message'],
  46. ];
  47. }
  48. if(!isset($res['data']['orders'])){
  49. return [
  50. 'x'=>0,
  51. 'Description'=>"获取TT订单信息异常",
  52. ];
  53. }
  54. if(empty($res['data']['orders'])){
  55. return [
  56. 'x'=>0,
  57. 'Description'=>"获取TT订单信息异常",
  58. ];
  59. }
  60. if(empty($res['data']['orders'][0]['packages'])){
  61. return [
  62. 'x'=>0,
  63. 'Description'=>"获取TT订单的快递信息",
  64. ];
  65. }
  66. $packages = $res['data']['orders'][0]['packages'];
  67. $label_list = [];
  68. print_r($packages);
  69. foreach($packages as $package){
  70. $rr = $this->apitt->downloadLabel($package['id'],$shop_info[0],$info);
  71. print_r($rr);
  72. }
  73. }else{
  74. return [
  75. 'x'=>0,
  76. 'Description'=>'暂不支持该快递类型',
  77. ];
  78. }
  79. }
  80. private function getOrderDetail($info,$shop_info){
  81. }
  82. //获取订单承运的快递商
  83. private function getExpressCompany($info,$shop_info){
  84. $res = $this->apitt->getExpressCompany($info,$shop_info);
  85. if($res['code'] != 0){
  86. return [
  87. 'x'=>0,
  88. 'Description'=>$res['message'],
  89. ];
  90. }
  91. $extra_info = json_decode($info['extra_info'],true);
  92. $extra_info['server_info'] = $res['data'];
  93. $info['extra_info'] = json_encode($extra_info,JSON_UNESCAPED_UNICODE);
  94. $this->db->update('fullordertt', [
  95. 'extra_info' => $info['extra_info']
  96. ], ['id' => $info['id']]) ;
  97. return [
  98. 'x'=>1,
  99. 'msg'=>'获取成功',
  100. 'data'=>$info
  101. ];
  102. }
  103. //创建发货单和运单标签
  104. private function createExpressLabel($info,$shop_info){
  105. $res = $this->apitt->createExpressLabel($info,$shop_info);
  106. if($res['code'] != 0){
  107. return [
  108. 'x'=>0,
  109. 'Description'=>$res['message'],
  110. ];
  111. }
  112. $extra_info = json_decode($info['extra_info'],true);
  113. $extra_info['label_info'] = $res['data'];
  114. $info['extra_info'] = json_encode($extra_info,JSON_UNESCAPED_UNICODE);
  115. $this->db->update('fullordertt', [
  116. 'extra_info' => $info['extra_info']
  117. ], ['id' => $info['id']]) ;
  118. return [
  119. 'x'=>1,
  120. 'msg'=>'获取成功',
  121. 'data'=>$info
  122. ];
  123. }
  124. //下载快递面单
  125. private function downloadExpressLabel($info,$shop){
  126. $extra_info = json_decode($info['extra_info'],true);
  127. $packageid = $extra_info['label_info']['packageid'];
  128. $res = $this->apitt->downloadLabel($packageid,$shop,$info);
  129. if($res['code'] != 0){
  130. return [
  131. 'x'=>0,
  132. 'Description'=>$res['message'],
  133. ];
  134. }
  135. $extra_info = json_decode($info['extra_info'],true);
  136. $extra_info['express_info'] = $res['data'];
  137. $info['extra_info'] = json_encode($extra_info,JSON_UNESCAPED_UNICODE);
  138. $this->db->update('fullordertt', [
  139. 'extra_info' => $info['extra_info']
  140. ], ['id' => $info['id']]) ;
  141. return [
  142. 'x'=>1,
  143. 'msg'=>'获取成功',
  144. 'waybill'=>$res['data']['tracking_number'],
  145. 'label'=>$res['data']['doc_url'],
  146. ];
  147. }
  148. }