Model_express_tt.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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 get_data($info,$type = 'CBT'){
  8. if(empty($info)){
  9. return $g = [
  10. 'x'=>0,
  11. 'Description'=>'订单信息不存在',
  12. ];
  13. }
  14. if(is_numeric($info['shop'])){
  15. $shopid = $info['shop'];
  16. }else{
  17. $shopid = $info['tmp_shop_id'];
  18. }
  19. $shop_info = $this->db->from('shop')->where('id', $shopid)->get()->result_array();
  20. if(empty($shop_info)){
  21. return [
  22. 'x'=>0,
  23. 'Description'=>'该商铺不存在',
  24. ];
  25. }
  26. if($type == 'CBT'){
  27. //获取快递服务信息
  28. $res = $this->getExpressCompany($info,$shop_info[0]);
  29. if($res['x'] == 0){
  30. return $res;
  31. }
  32. $res1 = $this->createExpressLabel($res['data'],$shop_info[0]);
  33. if($res1['x'] == 0){
  34. return $res1;
  35. }
  36. $res2 = $this->downloadExpressLabel($res['data'],$shop_info[0]);
  37. if($res2['x'] == 0){
  38. return $res2;
  39. }
  40. return [
  41. 'x'=>1,
  42. 'msg'=>'获取成功',
  43. 'data'=>$info
  44. ];
  45. }else if($type == 'FBT'){
  46. $extra_text = json_decode($info['extra_text'],true);
  47. if(empty($extra_text)){
  48. return $this->getFBTOrderDetail($info,$shop_info);
  49. }
  50. if(empty($extra_text['packages'])){
  51. return $this->getFBTOrderDetail($info,$shop_info);
  52. }
  53. $info['extra_text'] = $extra_text;
  54. return $this->getFBTPackage($info,$shop_info);
  55. }else{
  56. return [
  57. 'x'=>0,
  58. 'Description'=>'暂不支持该快递类型',
  59. ];
  60. }
  61. }
  62. private function getFBTOrderDetail($info,$shop_info){
  63. var_dump("执行到getFBTOrderDetail");
  64. $res = $this->apitt->get_data([$info['orderinfo']],$shop_info[0]);
  65. if($res['code'] != 0){
  66. return [
  67. 'x'=>0,
  68. 'Description'=>$res['message'],
  69. ];
  70. }
  71. if(!isset($res['data']['orders'])){
  72. return [
  73. 'x'=>0,
  74. 'Description'=>"获取TT订单信息异常",
  75. ];
  76. }
  77. if(empty($res['data']['orders'])){
  78. return [
  79. 'x'=>0,
  80. 'Description'=>"获取TT订单信息异常",
  81. ];
  82. }
  83. if(empty($res['data']['orders'][0]['packages'])){
  84. return [
  85. 'x'=>0,
  86. 'Description'=>"获取TT订单的快递信息",
  87. ];
  88. }
  89. $packages = $res['data']['orders'][0]['packages'];
  90. $label_list = [];
  91. print_r($packages);
  92. foreach($packages as $package){
  93. $rr = $this->apitt->downloadLabel($package['id'],$shop_info[0],$info);
  94. print_r($rr);
  95. }
  96. }
  97. private function getFBTPackage($info,$shop_info){
  98. var_dump("执行到getFBTPackage");
  99. $extra_text = $info['extra_text'];
  100. $packages = $extra_text['packages'];
  101. // 确定没有多包裹的情况 就不再写循环了 直接获取第一个包裹
  102. // foreach($packages as $package){
  103. // $rr = $this->apitt->downloadLabel($package['id'],$shop_info[0],$info);
  104. // if($rr['code']!=0){
  105. // $flag_status = 1;
  106. // $err_arr[] = $rr['message'];
  107. // }else{
  108. // $label_list[] = [
  109. // 'waybill'=>$rr['data']['tracking_number'],
  110. // 'label'=>$rr['data']['doc_url'],
  111. // ];
  112. // }
  113. // }
  114. $packageid = $packages[0]['id'];
  115. $rr = $this->apitt->downloadLabel($packageid,$shop_info[0],$info);
  116. if($rr['code']!=0){
  117. return [
  118. 'x'=>0,
  119. 'Description'=>$rr['message'],
  120. ];
  121. }else{
  122. return [
  123. 'x'=>1,
  124. 'msg'=>'获取成功',
  125. 'waybill'=>$rr['data']['tracking_number'],
  126. 'label'=>$rr['data']['doc_url'],
  127. ];
  128. }
  129. }
  130. private function getOrderDetail($info,$shop_info){
  131. }
  132. //获取订单承运的快递商
  133. private function getExpressCompany($info,$shop_info){
  134. $res = $this->apitt->getExpressCompany($info,$shop_info);
  135. if($res['code'] != 0){
  136. return [
  137. 'x'=>0,
  138. 'Description'=>$res['message'],
  139. ];
  140. }
  141. $extra_text = json_decode($info['extra_text'],true);
  142. $extra_text['server_info'] = $res['data'];
  143. $info['extra_text'] = json_encode($extra_text,JSON_UNESCAPED_UNICODE);
  144. $this->db->update('fullordertt', [
  145. 'extra_text' => $info['extra_text']
  146. ], ['id' => $info['id']]) ;
  147. return [
  148. 'x'=>1,
  149. 'msg'=>'获取成功',
  150. 'data'=>$info
  151. ];
  152. }
  153. //创建发货单和运单标签
  154. private function createExpressLabel($info,$shop_info){
  155. $res = $this->apitt->createExpressLabel($info,$shop_info);
  156. if($res['code'] != 0){
  157. return [
  158. 'x'=>0,
  159. 'Description'=>$res['message'],
  160. ];
  161. }
  162. $extra_text = json_decode($info['extra_text'],true);
  163. $extra_text['label_info'] = $res['data'];
  164. $info['extra_text'] = json_encode($extra_text,JSON_UNESCAPED_UNICODE);
  165. $this->db->update('fullordertt', [
  166. 'extra_text' => $info['extra_text']
  167. ], ['id' => $info['id']]) ;
  168. return [
  169. 'x'=>1,
  170. 'msg'=>'获取成功',
  171. 'data'=>$info
  172. ];
  173. }
  174. //下载快递面单
  175. private function downloadExpressLabel($info,$shop){
  176. $extra_text = json_decode($info['extra_text'],true);
  177. $packageid = $extra_text['label_info']['packageid'];
  178. $res = $this->apitt->downloadLabel($packageid,$shop,$info);
  179. if($res['code'] != 0){
  180. return [
  181. 'x'=>0,
  182. 'Description'=>$res['message'],
  183. ];
  184. }
  185. $extra_text = json_decode($info['extra_text'],true);
  186. $extra_text['express_info'] = $res['data'];
  187. $info['extra_text'] = json_encode($extra_text,JSON_UNESCAPED_UNICODE);
  188. $this->db->update('fullordertt', [
  189. 'extra_text' => $info['extra_text']
  190. ], ['id' => $info['id']]) ;
  191. return [
  192. 'x'=>1,
  193. 'msg'=>'获取成功',
  194. 'waybill'=>$res['data']['tracking_number'],
  195. 'label'=>$res['data']['doc_url'],
  196. ];
  197. }
  198. }