Vote.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\AdminBaseController;
  4. use app\common\model\VoteApplyModel;
  5. use app\common\model\VoteModel;
  6. use app\common\service\QrcodeService;
  7. use app\common\validate\VoteValidate;
  8. use think\exception\ValidateException;
  9. class Vote extends AdminBaseController
  10. {
  11. /**
  12. * 列表
  13. */
  14. public function index()
  15. {
  16. return view();
  17. }
  18. public function listVote()
  19. {
  20. $list = VoteModel::limit(input('limit'))->page(input('page'))->select();
  21. $count = VoteModel::count();
  22. if ($count == 0) {
  23. ajax_return(1, '未查询到数据');
  24. }
  25. list_return($list, $count);
  26. }
  27. /**
  28. * 编辑
  29. */
  30. public function voteForm()
  31. {
  32. $id = input('id/d, 0');
  33. $info = VoteModel::find($id);
  34. return view('', [
  35. 'info' => $info,
  36. ]);
  37. }
  38. public function editVote()
  39. {
  40. $data = input('post.');
  41. try {
  42. validate(VoteValidate::class)->check($data);
  43. } catch (ValidateException $e) {
  44. ajax_return(1, $e->getError());
  45. }
  46. if (empty($data['id'])) {
  47. VoteModel::create($data);
  48. } else {
  49. VoteModel::update($data, ['id' => $data['id']]);
  50. }
  51. ajax_return();
  52. }
  53. public function delVote()
  54. {
  55. $id = input('id/d');
  56. $check = VoteApplyModel::where('vote_id', $id)->find();
  57. if (!empty($check)) {
  58. ajax_return(1, '已有投票的活动无法删除!');
  59. }
  60. VoteModel::destroy($id);
  61. ajax_return();
  62. }
  63. /**
  64. * 二维码
  65. */
  66. public function qrcodeVote()
  67. {
  68. $id = input('id/d', 0);
  69. $file_name = "/vote_{$id}.png";
  70. $link = url('/mobile/vote/detail') . '?id=' . $id;
  71. $file_url = QrcodeService::getQrcode($file_name, $link);
  72. ajax_return(0, '', $file_url);
  73. }
  74. }