Model_express_tt.php 5.8 KB

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