Vote.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace app\mobile\controller;
  3. use app\common\model\VoteApplyModel;
  4. use app\common\model\VoteModel;
  5. use app\mobile\MobileBaseController;
  6. class Vote extends MobileBaseController
  7. {
  8. public function listVote()
  9. {
  10. $list = VoteModel::limit(input('limit', 10))
  11. ->page(input('page', 1))
  12. ->select();
  13. ajax_success($list);
  14. }
  15. public function detail()
  16. {
  17. $id = input('id/d', 0);
  18. empty($id) && jump('该活动不存在');
  19. $info = VoteModel::find($id);
  20. empty($info) && jump('该活动不存在');
  21. $user_id = get_user_id();
  22. $apply = VoteApplyModel::where('vote_id', $id)->where('user_id', $user_id)->find();
  23. $is_apply = 'false';
  24. $option_name = '';
  25. if (!empty($apply)) {
  26. $is_apply = 'true';
  27. $option_name = $apply['option_name'];
  28. }
  29. return view('', [
  30. 'info' => $info,
  31. 'is_apply' => $is_apply,
  32. 'option_name' => $option_name,
  33. ]);
  34. }
  35. public function apply()
  36. {
  37. $id = input('id/d', 0);
  38. empty($id) && ajax_return(1, '该活动不存在');
  39. $vote = VoteModel::find($id);
  40. empty($vote) && ajax_return(1, '该活动不存在');
  41. $option_name = input('option_name', '');
  42. if (!in_array($option_name, $vote['option'])) {
  43. ajax_return(1, '该选项不存在,请重新选择');
  44. }
  45. if (request()->ip() != '59.57.98.130') {
  46. ajax_return(1, '请连接RCG的WIFI进行投票');
  47. }
  48. $user_id = get_user_id();
  49. $check = VoteApplyModel::where('vote_id', $id)->where('user_id', $user_id)->find();
  50. if (!empty($check)) {
  51. ajax_return(1, '请勿重复提交!');
  52. }
  53. VoteApplyModel::create([
  54. 'vote_id' => $id,
  55. 'user_id' => $user_id,
  56. 'option_name' => $option_name,
  57. ]);
  58. ajax_return();
  59. }
  60. }