Apiexpress.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. if(strpos($re_arr[0],"[") !== false){
  85. $shipping_time_arr = explode("[",$re_arr[0] ) ;
  86. $shipping_time = $shipping_time_arr[0];
  87. if($info['expressstate'] == 6){
  88. $receive_tmp_arr = explode("[",$tmp_arr[0] ) ;
  89. $receive_time = $receive_tmp_arr[0];
  90. }
  91. }else{
  92. $shipping_time = date("Y-m-d H:i:s",$info['dlzemailtime']);
  93. if($info['expressstate'] == 6){
  94. $receive_time = -1;
  95. }
  96. }
  97. $express_trace = $re_arr;
  98. }
  99. if(empty($info['dtime'])){
  100. $preparing = [
  101. "desc"=>"",
  102. "status"=>0,
  103. "date"=>"",
  104. ];
  105. }else{
  106. $preparing = [
  107. "desc"=>"The Order Has Been Created And TheMerchant lspreparing Your Order.",
  108. "status"=>1,
  109. "date"=>date("Y-m-d H:i:s",$info['dtime']),
  110. ];
  111. }
  112. if(empty($info['printtime'])){
  113. $warehouse_processing = [
  114. "desc"=>"",
  115. "status"=>0,
  116. "date"=>"",
  117. ];
  118. }else{
  119. $warehouse_processing = [
  120. "desc"=>"Packing And Final Check",
  121. "status"=>1,
  122. "date"=>date("Y-m-d H:i:s",$info['printtime']),
  123. ];
  124. }
  125. if(empty($shipping_time)){
  126. $shipping = [
  127. "desc"=>"",
  128. "status"=>0,
  129. "date"=>"",
  130. ];
  131. }else{
  132. $shipping = [
  133. "desc"=>"Courier Company Picked Up The Package",
  134. "status"=>1,
  135. "date"=>$shipping_time,
  136. ];
  137. }
  138. if(empty($receive_time)){
  139. $received = [
  140. "desc"=>"",
  141. "status"=>0,
  142. "date"=>"",
  143. ];
  144. }else{
  145. if($receive_time < 0){
  146. $received = [
  147. "desc"=>"Order signed for successfully",
  148. "status"=>1,
  149. "date"=>0,
  150. ];
  151. }else{
  152. $received = [
  153. "desc"=>"Order signed for successfully",
  154. "status"=>1,
  155. "date"=>$receive_time,
  156. ];
  157. }
  158. }
  159. $ret_arr = [
  160. "order_no"=>$order_no,
  161. "express_name"=>$express_info['iscode'],
  162. "waybill"=>$info['waybill'],
  163. "preparing"=>$preparing,//店家处理
  164. "warehouse_processing"=>$warehouse_processing,//工厂处理
  165. "shipping"=> $shipping,//快递发货
  166. "received"=>$received,//客户收货
  167. "express_trace"=>$express_trace,//快递跟踪信息
  168. ];
  169. die($this->logic_tools->ret_json(1,"success",$ret_arr));
  170. }
  171. }