VisitorOrder.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. namespace app\api\controller\v1;
  3. use app\api\controller\Base;
  4. use app\hander\HelpHander;
  5. use think\facade\Request;
  6. class VisitorOrder extends Base
  7. {
  8. // 扫码确认
  9. public function scan(){
  10. $code = input('code');
  11. if(!$code){
  12. HelpHander::error('参数错误');
  13. }
  14. $arr = get_qrcode_arr($code);
  15. if(!$arr || $arr['ucode'] != config('app.ucode') || $arr['type'] != 'visitor'){
  16. HelpHander::error('二维码不正确');
  17. }
  18. $id = $arr['id'];
  19. if(!$id){
  20. HelpHander::error('参数错误');
  21. }
  22. $info = db('visitor_order')
  23. ->where('id',$id)
  24. ->where('org_id',$this->orgId)
  25. ->where('del',0)
  26. ->find();
  27. if(!$info){
  28. HelpHander::error('未查询到预约记录');
  29. }
  30. $curTime = time();
  31. $info['org_name'] = '';
  32. $info['title'] = '';
  33. $info['day'] = '';
  34. $info['start'] = '';
  35. $info['end'] = '';
  36. $info['org_name'] = db('org')->where('id',$info['org_id'])->value('name');
  37. $info['pass_msg'] = '';
  38. $pass = 0;
  39. if($info['status'] == 2){
  40. $info['pass_msg'] = '通行码仅且使用一次,请重新登记预约';
  41. }else if ($info['status'] == 3){
  42. $info['pass_msg'] = '预约已失效,请重新登记预约';
  43. }else if ($info['status'] == 4){
  44. $info['pass_msg'] = '预约未通过审核,请重新登记预约';
  45. }else if ($info['status'] == 0){
  46. $info['pass_msg'] = '预约正在审核中';
  47. }else{
  48. $info['pass_msg'] = '验证成功,允许通过!';
  49. $pass = 1;
  50. }
  51. if($info['service_time_id'] > 0){
  52. $time = db('service_time')->where('id',$info['service_time_id'])->find();
  53. $info['day'] = $time?$time['day']:'';
  54. $info['start'] = date('H:i',strtotime($time['day'].' '.$time['start']));
  55. $info['end'] = date('H:i',strtotime($time['day'].' '.$time['end']));
  56. $info['title'] = db('service')->where('id',$info['service_id'])->value('title');
  57. if($info['status'] == 1 && ($curTime < strtotime($info['day'].' '.$info['start']) || $curTime > strtotime($info['day'].' '.$info['end']))){
  58. $info['pass_msg'] = '您的预约不在使用时间范围内,请确认预约时间';
  59. $pass = 0;
  60. }
  61. }
  62. if($info['type'] == 3 && date('Y-m-d') != date('Y-m-d',strtotime($info['book_time']))){
  63. $info['pass_msg'] = '您的预约不在使用时间范围内,请确认预约时间';
  64. $pass = 0;
  65. }
  66. $info['pass'] = $pass;
  67. if($pass == 1){ // 已使用
  68. db('visitor_order')->where('id',$id)->update(['status'=>2,'scan_time'=>date('Y-m-d H:i:s'),'scan_user_id'=>$this->userId]);
  69. }
  70. HelpHander::success($info);
  71. }
  72. // 我审批的
  73. public function apply(){
  74. $lists = db('visitor_order')
  75. ->where('from_user_id',$this->userId)
  76. ->where('del',0)
  77. ->where('type',3)
  78. ->order(['status'=>'asc','id'=>'desc'])
  79. ->select();
  80. foreach ($lists as $k=>$v){
  81. $lists[$k]['org_name'] = db('org')->where('id',$v['org_id'])->value('name');
  82. $lists[$k]['from_user_name'] = db('user')->where('id',$v['from_user_id'])->value('real_name');
  83. }
  84. HelpHander::success($lists);
  85. }
  86. public function detail(){
  87. $id = input('id',0);
  88. $info = db('visitor_order')->where('from_user_id',$this->userId)->where('id',$id)->where('del',0)->find();
  89. if(!$info){
  90. HelpHander::error('记录不存在');
  91. }
  92. $info['org_name'] = db('org')->where('id',$info['org_id'])->value('name');
  93. $info['from_user_name'] = db('user')->where('id',$info['from_user_id'])->value('real_name');
  94. $info['qrcode'] = Request::domain().'/admin/Qrcode/qrcode?code='.get_qrcode_str('visitor',$info['id']);
  95. HelpHander::success($info);
  96. }
  97. public function deal(){
  98. $id = input('id',0);
  99. $s = input('s');
  100. if($id<=0||!in_array($s,[1,4,5])){
  101. HelpHander::error('参数错误');
  102. }
  103. $info = db('visitor_order')
  104. ->where('id',$id)
  105. ->where('from_user_id',$this->userId)
  106. ->where('del',0)
  107. ->find();
  108. if(!$info){
  109. HelpHander::error('记录不存在');
  110. }
  111. if($info['status'] != 0){
  112. HelpHander::error('记录已处理');
  113. }
  114. $res = db('visitor_order')
  115. ->where('id',$id)
  116. ->update(['status'=>$s,'update_time'=>date('Y-m-d H:i:s')]);
  117. if($res){
  118. HelpHander::success([],'操作成功');
  119. }else{
  120. HelpHander::error('操作失败');
  121. }
  122. }
  123. //获取待审批预约单
  124. public function vistCount(){
  125. $lists = db('visitor_order')
  126. ->where('from_user_id',$this->userId)
  127. ->where('del',0)
  128. ->where('type',3)
  129. ->where('status',0)
  130. ->count();
  131. HelpHander::success($lists,'操作成功');
  132. }
  133. }