Apiexpress.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3. class Apiexpress extends Start_Controller {
  4. public function __construct(){
  5. parent::__construct();
  6. $this->load->_model('Model_logic_order','logic_order');
  7. $this->load->_model('Model_logic_tools','logic_tools');
  8. $this->load->_model('Model_awlgx','awlgx');
  9. $this->load->_model("Model_express","express");
  10. }
  11. private $key = "6amg!pnfrlbpnjgirv"; //加密所需要到的key
  12. private $iv = "6ook4k!2w94m6jtm";//加密所需要到的iv
  13. //定义方法的调用规则 获取URI第二段值
  14. public function _remap($arg,$arg_array)
  15. {
  16. if($arg == 'search')
  17. {
  18. $this->search();
  19. }else{
  20. $this->_a();
  21. }
  22. }
  23. public function _a(){
  24. die();
  25. }
  26. /**
  27. * 搜索订单状态和快递信息接口
  28. * @param $arg_array[0] string 请求店铺
  29. * @param $arg_array[1] string 请求单号
  30. */
  31. public function search(){
  32. $data = file_get_contents('PHP://input');
  33. $data = json_decode($data, true);
  34. $shop = isset($data['shop'])?$data['shop']:"";
  35. $order_no = isset($data['order_no'])?$data['order_no']:"";
  36. $apply_time = isset($data['time'])?$data['time']:0;
  37. $jiami_str = isset($data['key'])?$data['key']:"";
  38. $now_time = time();
  39. if(strlen( $apply_time."") != 10){
  40. die($this->logic_tools->ret_json(-1,"参数异常"));
  41. }
  42. if(empty($shop)){
  43. die($this->logic_tools->ret_json(-1,"请求店铺异常"));
  44. }
  45. $shop_key = $this->logic_tools->getshopname($shop);
  46. if(empty($jiami_str)){
  47. die($this->logic_tools->ret_json(-1,"秘钥信息不存在"));
  48. }
  49. $jiemi_str = $this->logic_tools->toolsjiemi($jiami_str,$this->key,$this->iv);
  50. if(empty($shop_key)){
  51. die($this->logic_tools->ret_json(-1,"该店铺的秘钥不存在"));
  52. }
  53. $jiemi_arr = explode("+",$jiemi_str);
  54. $jiemi_key = isset($jiemi_arr[0])?$jiemi_arr[0]:"";
  55. $jiemi_time = isset($jiemi_arr[1])?$jiemi_arr[1]:"";
  56. if((int)$jiemi_time != (int)$apply_time){
  57. die($this->logic_tools->ret_json(-1,"请求超时"));
  58. }
  59. if( $now_time - $apply_time > 100){
  60. die($this->logic_tools->ret_json(-1,"请求已超时"));
  61. }
  62. if($jiemi_key != $shop_key){
  63. die($this->logic_tools->ret_json(-1,"该店铺的秘钥不正确"));
  64. }
  65. if(empty($order_no)){
  66. die($this->logic_tools->ret_json(-1,"请求单号异常"));
  67. }
  68. $table_name = $this->logic_tools->getOrderTable($shop);
  69. if(empty($table_name)){
  70. die($this->logic_tools->ret_json(-1,"店铺未开通此功能!!!"));
  71. }
  72. $info = $this->logic_order->getInfoByTableName($table_name,"orderinfo = ".$shop.$order_no. " and shop = ".$shop,"id,express,excontent,expressstate,waybill,dtime,printtime");
  73. if(empty($info)){
  74. die($this->logic_tools->ret_json(-1,"未查询到相关快递信息"));
  75. }
  76. $receive_time = "";//客户签到时间
  77. $shipping_time = "";//快递接受发货时间
  78. $express_trace = [];
  79. $express_info = $this->express->read($info['express']);
  80. if(!empty($info['excontent'])){
  81. $tmp_arr = explode("<br />",$info['excontent']);
  82. array_pop($tmp_arr);
  83. $re_arr = array_reverse($tmp_arr);
  84. $shipping_time_arr = explode("[",$re_arr[0] ) ;
  85. $shipping_time = $shipping_time_arr[0];
  86. if($info['expressstate'] == 6){
  87. $receive_tmp_arr = explode("[",$tmp_arr[0] ) ;
  88. $receive_time = $receive_tmp_arr[0];
  89. }
  90. $express_trace = $re_arr;
  91. }
  92. if(empty($info['dtime'])){
  93. $preparing = [
  94. "desc"=>"",
  95. "status"=>0,
  96. "date"=>"",
  97. ];
  98. }else{
  99. $preparing = [
  100. "desc"=>"The Order Has Been Created And TheMerchant lspreparing Your Order.",
  101. "status"=>1,
  102. "date"=>date("Y-m-d H:i:s",$info['dtime']),
  103. ];
  104. }
  105. if(empty($info['printtime'])){
  106. $warehouse_processing = [
  107. "desc"=>"",
  108. "status"=>0,
  109. "date"=>"",
  110. ];
  111. }else{
  112. $warehouse_processing = [
  113. "desc"=>"Packing And Final Check",
  114. "status"=>1,
  115. "date"=>date("Y-m-d H:i:s",$info['printtime']),
  116. ];
  117. }
  118. if(empty($shipping_time)){
  119. $shipping = [
  120. "desc"=>"",
  121. "status"=>0,
  122. "date"=>"",
  123. ];
  124. }else{
  125. $shipping = [
  126. "desc"=>"Courier Company Picked Up The Package",
  127. "status"=>1,
  128. "date"=>$shipping_time,
  129. ];
  130. }
  131. if(empty($receive_time)){
  132. $received = [
  133. "desc"=>"",
  134. "status"=>0,
  135. "date"=>"",
  136. ];
  137. }else{
  138. $received = [
  139. "desc"=>"Order signed for successfully",
  140. "status"=>1,
  141. "date"=>$receive_time,
  142. ];
  143. }
  144. $ret_arr = [
  145. "order_no"=>$order_no,
  146. "express_name"=>$express_info['iscode'],
  147. "waybill"=>$info['waybill'],
  148. "preparing"=>$preparing,//店家处理
  149. "warehouse_processing"=>$warehouse_processing,//工厂处理
  150. "shipping"=> $shipping,//快递发货
  151. "received"=>$received,//客户收货
  152. "express_trace"=>$express_trace,//快递跟踪信息
  153. ];
  154. die($this->logic_tools->ret_json(1,"success",$ret_arr));
  155. }
  156. }