Model_express_tt.php 5.0 KB

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