Model_express_tt.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. // 确定没有多包裹的情况 就不再写循环了 直接获取第一个包裹
  97. // foreach($packages as $package){
  98. // $rr = $this->apitt->downloadLabel($package['id'],$shop_info[0],$info);
  99. // if($rr['code']!=0){
  100. // $flag_status = 1;
  101. // $err_arr[] = $rr['message'];
  102. // }else{
  103. // $label_list[] = [
  104. // 'waybill'=>$rr['data']['tracking_number'],
  105. // 'label'=>$rr['data']['doc_url'],
  106. // ];
  107. // }
  108. // }
  109. $packageid = $packages[0]['id'];
  110. $rr = $this->apitt->downloadLabel($packageid,$shop_info[0],$info);
  111. if($rr['code']!=0){
  112. return [
  113. 'x'=>0,
  114. 'Description'=>$rr['message'],
  115. ];
  116. }else{
  117. return [
  118. 'x'=>1,
  119. 'msg'=>'获取成功',
  120. 'waybill'=>$rr['data']['tracking_number'],
  121. 'label'=>$rr['data']['doc_url'],
  122. ];
  123. }
  124. }
  125. private function getOrderDetail($info,$shop_info){
  126. }
  127. //获取订单承运的快递商
  128. private function getExpressCompany($info,$shop_info){
  129. $res = $this->apitt->getExpressCompany($info,$shop_info);
  130. if($res['code'] != 0){
  131. return [
  132. 'x'=>0,
  133. 'Description'=>$res['message'],
  134. ];
  135. }
  136. $extra_text = json_decode($info['extra_text'],true);
  137. $extra_text['server_info'] = $res['data'];
  138. $info['extra_text'] = json_encode($extra_text,JSON_UNESCAPED_UNICODE);
  139. $this->db->update('fullordertt', [
  140. 'extra_text' => $info['extra_text']
  141. ], ['id' => $info['id']]) ;
  142. return [
  143. 'x'=>1,
  144. 'msg'=>'获取成功',
  145. 'data'=>$info
  146. ];
  147. }
  148. //创建发货单和运单标签
  149. private function createExpressLabel($info,$shop_info){
  150. $res = $this->apitt->createExpressLabel($info,$shop_info);
  151. if($res['code'] != 0){
  152. return [
  153. 'x'=>0,
  154. 'Description'=>$res['message'],
  155. ];
  156. }
  157. $extra_text = json_decode($info['extra_text'],true);
  158. $extra_text['label_info'] = $res['data'];
  159. $info['extra_text'] = json_encode($extra_text,JSON_UNESCAPED_UNICODE);
  160. $this->db->update('fullordertt', [
  161. 'extra_text' => $info['extra_text']
  162. ], ['id' => $info['id']]) ;
  163. return [
  164. 'x'=>1,
  165. 'msg'=>'获取成功',
  166. 'data'=>$info
  167. ];
  168. }
  169. //下载快递面单
  170. private function downloadExpressLabel($info,$shop){
  171. $extra_text = json_decode($info['extra_text'],true);
  172. $packageid = $extra_text['label_info']['packageid'];
  173. $res = $this->apitt->downloadLabel($packageid,$shop,$info);
  174. if($res['code'] != 0){
  175. return [
  176. 'x'=>0,
  177. 'Description'=>$res['message'],
  178. ];
  179. }
  180. $extra_text = json_decode($info['extra_text'],true);
  181. $extra_text['express_info'] = $res['data'];
  182. $info['extra_text'] = json_encode($extra_text,JSON_UNESCAPED_UNICODE);
  183. $this->db->update('fullordertt', [
  184. 'extra_text' => $info['extra_text']
  185. ], ['id' => $info['id']]) ;
  186. return [
  187. 'x'=>1,
  188. 'msg'=>'获取成功',
  189. 'waybill'=>$res['data']['tracking_number'],
  190. 'label'=>$res['data']['doc_url'],
  191. ];
  192. }
  193. }