Index.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. */
  7. namespace app\guard\controller\home;
  8. use app\common\controller\Official;
  9. use app\guard\model\Guard;
  10. use app\guard\model\GuardHistory;
  11. use app\guard\model\GuardUser;
  12. class Index extends Official{
  13. public function initialize() {
  14. parent::initialize();
  15. $this->view->engine->layout(false);
  16. }
  17. /**
  18. * 签到
  19. */
  20. public function index(){
  21. if(request()->isAjax()){
  22. $data = [
  23. 'id' => $this->request->param('id/d'),
  24. 'member_miniapp_id' => $this->member_miniapp_id,
  25. 'car_num' => $this->request->param('car_num/s'),
  26. 'name' => $this->request->param('name/s'),
  27. 'idcard' => $this->request->param('idcard/d'),
  28. 'pass_out' => $this->request->param('pass_out/s','进'),
  29. 'phone' => $this->request->param('phone/s'),
  30. 'temperature' => $this->request->param('temperature/s'),
  31. 'why' => $this->request->param('why/s'),
  32. 'is_danger' => $this->request->param('is_danger/s','off')
  33. ];
  34. $validate = $this->validate($data,'Send.sign');
  35. if(true !== $validate){
  36. return enjson(0,$validate);
  37. }
  38. $info = GuardUser::where(['uid' => $this->user->id])->find();
  39. if(empty($info)){
  40. $guard = [
  41. 'member_miniapp_id' => $data['member_miniapp_id'],
  42. 'uid' => $this->user->id,
  43. 'name' => $data['name'],
  44. 'idcard' => $data['idcard'],
  45. 'phone' => $data['phone'],
  46. 'pass_out' => $data['pass_out'] == '进' ? '进': '出',
  47. 'car_num' => $data['car_num'],
  48. 'create_time' => time(),
  49. 'update_time' => time()
  50. ];
  51. $info = GuardUser::create($guard);
  52. }else{
  53. $info->update_time = time();
  54. $info->pass_out = $data['pass_out'] == '进' ? '进': '出';
  55. $info->car_num = $data['car_num'];
  56. $info->save();
  57. }
  58. $history['member_miniapp_id'] = $data['member_miniapp_id'];
  59. $history['gid'] = $data['id'];
  60. $history['uid'] = $info->uid;
  61. $history['car_num'] = $data['car_num'];
  62. $history['is_danger'] = $data['is_danger'] == 'off' ? 0: 1;
  63. $history['temperature'] = $data['temperature'];
  64. $history['pass_out'] = $data['pass_out'] == '进' ? '进' : '出';
  65. $history['why'] = $data['why'];
  66. $history['update_time'] = time();
  67. $rel = GuardHistory::create($history);
  68. if(empty($rel)){
  69. return enjson(0,'填写失败,请重新创建一下');
  70. }
  71. return enjson(200,'成功,允许通行',$rel);
  72. }else{
  73. $view['guard'] = Guard::where(['member_miniapp_id' => $this->member_miniapp_id, 'id' => $this->request->param('id/d')])->find();
  74. $view['info'] = GuardUser::where(['member_miniapp_id' => $this->member_miniapp_id, 'uid' => $this->user->id])->find();
  75. if(!$view['guard']){
  76. $this->error('请先增加主体');
  77. }
  78. return view()->assign($view);
  79. }
  80. }
  81. /**
  82. * 签到
  83. */
  84. public function history(){
  85. $info = GuardHistory::where(['member_miniapp_id' => $this->member_miniapp_id,'uid' => $this->user->id])->limit(10)->order('id desc')->select();
  86. foreach ($info as $key => $value) {
  87. $info[$key]['account'] = $value->account;
  88. $info[$key]['update_time'] = date('Y-m-d H:i:s',$value->update_time);
  89. }
  90. return enjson(200,'成功',$info);
  91. }
  92. }