ExpressController.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. /**
  3. * 物流信息
  4. */
  5. namespace app\appapi\controller;
  6. use cmf\controller\HomeBaseController;
  7. use think\facade\Db;
  8. class ExpressController extends HomebaseController{
  9. function index(){
  10. $data = $this->request->param();
  11. $uid=isset($data['uid']) ? $data['uid']: '';
  12. $token=isset($data['token']) ? $data['token']: '';
  13. $orderid=isset($data['orderid']) ? $data['orderid']: '';
  14. $user_type=isset($data['user_type']) ? $data['user_type']: ''; //用户身份 buyer 买家 seller 卖家 platform 平台
  15. $uid=(int)checkNull($uid);
  16. $token=checkNull($token);
  17. $orderid=checkNull($orderid);
  18. if($user_type!='platform'){
  19. if( !$uid || !$token || checkToken($uid,$token)==700 ){
  20. $reason=lang('您的登陆状态失效,请重新登陆!');
  21. $this->assign('reason', $reason);
  22. return $this->fetch(':error');
  23. }
  24. }
  25. if(!$orderid || !$user_type ||!in_array($user_type, ['buyer','seller','platform'])){
  26. $reason=lang('参数错误');
  27. $this->assign('reason', $reason);
  28. return $this->fetch(':error');
  29. }
  30. $where=[];
  31. if($user_type=='buyer'){
  32. $where=array(
  33. 'id'=>$orderid,
  34. 'uid'=>$uid,
  35. );
  36. }else if($user_type=='sellers'){
  37. $where=array(
  38. 'id'=>$orderid,
  39. 'shop_uid'=>$uid,
  40. );
  41. }else{
  42. $where=array(
  43. 'id'=>$orderid
  44. );
  45. }
  46. $orderinfo=getShopOrderInfo($where,"express_name,express_phone,express_thumb,express_code,express_number,status,province,city,area,address,phone");
  47. if(!$orderinfo){
  48. $reason=lang('订单不存在');
  49. $this->assign('reason', $reason);
  50. return $this->fetch(':error');
  51. }
  52. if($orderinfo['status']<0){
  53. $reason=lang('订单未发货');
  54. $this->assign('reason', $reason);
  55. return $this->fetch(':error');
  56. }
  57. if(!$orderinfo['express_code'] || !$orderinfo['express_number']){
  58. $reason=lang('物流参数错误');
  59. $this->assign('reason', $reason);
  60. return $this->fetch(':error');
  61. }
  62. if($orderinfo['express_thumb']){
  63. $orderinfo['express_thumb']=get_upload_path($orderinfo['express_thumb']);
  64. }
  65. $result=getExpressInfoByKDN($orderinfo['express_code'],$orderinfo['express_number'],$orderinfo['phone']);
  66. $result['Success']=is_true($result['Success']);
  67. if(!$result['Success']){
  68. $express_status=0;
  69. $desc=lang('物流查询失败');
  70. }else{
  71. $express_status=1;
  72. $desc=lang('物流查询成功');
  73. }
  74. $traces=isset($result['Traces'])?$result['Traces']:[];
  75. $express_list=[];
  76. foreach ($traces as $k => $v) {
  77. $info=[];
  78. $info['express_time']=$v['AcceptTime'];
  79. $info['express_msg']=$v['AcceptStation'];
  80. $express_list[]=$info;
  81. }
  82. $express_list=array_reverse($express_list); //数组倒序
  83. $this->assign("express_status",$express_status); //查询状态
  84. $this->assign("desc",$desc);
  85. $this->assign("express_list",$express_list);
  86. $this->assign("express_state",isset($result['State'])?$result['State']:'0'); //物流运输状态 2-在途中,3-签收,4-问题件
  87. $this->assign("orderinfo",$orderinfo); //物流运输状态 2-在途中,3-签收,4-问题件
  88. $this->assign("express_list_num",count($express_list)); //物流运输状态 2-在途中,3-签收,4-问题件
  89. return $this->fetch();
  90. }
  91. }