Model_express_tt.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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){
  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. //获取快递服务信息
  22. $res = $this->getExpressCompany($info,$shop_info[0]);
  23. if($res['x'] == 0){
  24. return $res;
  25. }
  26. $res1 = $this->createExpressLabel($res['data'],$shop_info[0]);
  27. if($res1['x'] == 0){
  28. return $res1;
  29. }
  30. $res2 = $this->downloadExpressLabel($res['data'],$shop_info[0]);
  31. if($res2['x'] == 0){
  32. return $res2;
  33. }
  34. return [
  35. 'x'=>1,
  36. 'msg'=>'获取成功',
  37. 'data'=>$info
  38. ];
  39. }
  40. //获取订单承运的快递商
  41. private function getExpressCompany($info,$shop_info){
  42. $res = $this->apitt->getExpressCompany($info,$shop_info);
  43. if($res['code'] != 0){
  44. return [
  45. 'x'=>0,
  46. 'Description'=>$res['message'],
  47. ];
  48. }
  49. $extra_info = json_decode($info['extra_info'],true);
  50. $extra_info['server_info'] = $res['data'];
  51. $info['extra_info'] = json_encode($extra_info,JSON_UNESCAPED_UNICODE);
  52. $this->db->update('fullordertt', [
  53. 'extra_info' => $info['extra_info']
  54. ], ['id' => $info['id']]) ;
  55. return [
  56. 'x'=>1,
  57. 'msg'=>'获取成功',
  58. 'data'=>$info
  59. ];
  60. }
  61. //创建发货单和运单标签
  62. private function createExpressLabel($info,$shop_info){
  63. $res = $this->apitt->createExpressLabel($info,$shop_info);
  64. if($res['code'] != 0){
  65. return [
  66. 'x'=>0,
  67. 'Description'=>$res['message'],
  68. ];
  69. }
  70. $extra_info = json_decode($info['extra_info'],true);
  71. $extra_info['label_info'] = $res['data'];
  72. $info['extra_info'] = json_encode($extra_info,JSON_UNESCAPED_UNICODE);
  73. $this->db->update('fullordertt', [
  74. 'extra_info' => $info['extra_info']
  75. ], ['id' => $info['id']]) ;
  76. return [
  77. 'x'=>1,
  78. 'msg'=>'获取成功',
  79. 'data'=>$info
  80. ];
  81. }
  82. //下载快递面单
  83. private function downloadExpressLabel($info,$shop){
  84. $extra_info = json_decode($info['extra_info'],true);
  85. $packageid = $extra_info['label_info']['packageid'];
  86. $res = $this->apitt->downloadLabel($packageid,$shop,$info);
  87. if($res['code'] != 0){
  88. return [
  89. 'x'=>0,
  90. 'Description'=>$res['message'],
  91. ];
  92. }
  93. $extra_info = json_decode($info['extra_info'],true);
  94. $extra_info['express_info'] = $res['data'];
  95. $info['extra_info'] = json_encode($extra_info,JSON_UNESCAPED_UNICODE);
  96. $this->db->update('fullordertt', [
  97. 'extra_info' => $info['extra_info']
  98. ], ['id' => $info['id']]) ;
  99. return [
  100. 'x'=>1,
  101. 'msg'=>'获取成功',
  102. 'waybill'=>$res['data']['tracking_number'],
  103. 'label'=>$res['data']['doc_url'],
  104. ];
  105. }
  106. }