Vote.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. namespace app\index\controller;
  3. use app\admin\model\Onepage;
  4. use app\common\controller\Frontend;
  5. use app\admin\model\community\Articles;
  6. class Vote extends Frontend
  7. {
  8. protected $noNeedLogin = '*';
  9. protected $noNeedRight = '*';
  10. protected $layout = '';
  11. public function index()
  12. {
  13. $uid = $this->request->param('uid');
  14. $vote = $this->request->param('vote');
  15. if(empty($vote)){
  16. return "vote参数错误";
  17. }
  18. $where = [
  19. 'user_id'=>$uid,
  20. 'vote_id'=>$vote,
  21. ];
  22. $model = model("app\admin\model\community\Vote");
  23. $modelDetail = model("app\admin\model\community\VoteDetail");
  24. $total = false;
  25. $isExistVote = $model::find($vote);
  26. $isExistUserVote = $modelDetail->where($where)->find();
  27. if($isExistVote){
  28. if($isExistUserVote){
  29. // 显示统计
  30. // $voteList = json_decode($isExistVote->config);
  31. // $voteList = json_decode($isExistVote->config);
  32. $total = true;
  33. $totalData = [];
  34. $this->view->assign('vote_total',$totalData);
  35. }else{
  36. $voteList = json_decode($isExistVote->config);
  37. $this->view->assign('vote',$isExistVote);
  38. $this->view->assign('vote_list',$isExistVote);
  39. }
  40. $this->view->assign('total',$total);
  41. return $this->view->fetch();
  42. }
  43. }
  44. public function vote()
  45. {
  46. // CREATE TABLE `ucg_vote_detail` (
  47. // `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  48. // `vote_id` int(11) NOT NULL,
  49. // `user_id` int(11) NOT NULL,
  50. // `item` varchar(255) DEFAULT NULL,
  51. // `createtime` bigint(16) DEFAULT NULL,
  52. // PRIMARY KEY (`id`)
  53. // ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
  54. $uid = $this->request->param('uid');
  55. $vote = $this->request->param('vote');
  56. $item = $this->request->param('item');
  57. if(empty($uid)){
  58. return "uid参数错误";
  59. }
  60. if(empty($vote)){
  61. return "vote参数错误";
  62. }
  63. if(empty($item)){
  64. return "item参数错误";
  65. }
  66. $where = [
  67. 'user_id'=>$uid,
  68. 'vote_id'=>$vote,
  69. ];
  70. $modelDetail = model("app\admin\model\community\VoteDetail");
  71. $isExistUserVote = $modelDetail->where($where)->find();
  72. if($isExistUserVote){
  73. echo "已投票";
  74. // return $this->success("投票成功");
  75. }else{
  76. // return $this->success("已投票");
  77. $where['item'] = $item;
  78. $modelDetail::create($where);
  79. echo "投票成功";
  80. }
  81. }
  82. // public function onepage(){
  83. // $code = $this->request->request('code');
  84. // $reader = $this->request->request('reader') ?? 'json';
  85. // $where = [
  86. // 'code'=>$code,
  87. // 'status'=>1
  88. // ];
  89. // $result = Onepage::where($where)->find();
  90. // if($result){
  91. // $this->view->assign('html',$result["content"]);
  92. // return $this->view->fetch('index@tpl/text');
  93. // }else{
  94. // return $this->error();
  95. // }
  96. // }
  97. // /**
  98. // * 获取文章详情
  99. // * @ApiMethod (GET)
  100. // * @param String $id 单页代码
  101. // */
  102. // public function article()
  103. // {
  104. // $code = $this->request->param('id');
  105. // $where = [
  106. // 'id'=>$code,
  107. // ];
  108. // $result = Articles::where($where)->find();
  109. // if($result){
  110. // $this->view->assign('html',$result["content"]);
  111. // return $this->view->fetch('index@tpl/text');
  112. // }else{
  113. // return $this->error();
  114. // }
  115. // }
  116. // /**
  117. // * 投票
  118. // * @ApiMethod (GET)
  119. // * @param String $id 单页代码
  120. // */
  121. // public function vote()
  122. // {
  123. // // $code = $this->request->param('id');
  124. // // $where = [
  125. // // 'id'=>$code,
  126. // // ];
  127. // // $result = Articles::where($where)->find();
  128. // // if($result){
  129. // // $this->view->assign('html',$result["content"]);
  130. // // return $this->view->fetch('index@tpl/text');
  131. // // }else{
  132. // // return $this->error();
  133. // // }
  134. // return $this->view->fetch('index@vote/index');
  135. // }
  136. }