Model_express_tt.php 5.8 KB

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