| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- <?php
- namespace app\index\controller;
- use app\admin\model\Onepage;
- use app\common\controller\Frontend;
- use app\admin\model\community\Articles;
- class Vote extends Frontend
- {
- protected $noNeedLogin = '*';
- protected $noNeedRight = '*';
- protected $layout = '';
- public function index()
- {
- $uid = $this->request->param('uid');
- $vote = $this->request->param('vote');
- if(empty($vote)){
- return "vote参数错误";
- }
- $where = [
- 'user_id'=>$uid,
- 'vote_id'=>$vote,
- ];
-
- $model = model("app\admin\model\community\Vote");
- $modelDetail = model("app\admin\model\community\VoteDetail");
- $total = false;
- $isExistVote = $model::find($vote);
- $isExistUserVote = $modelDetail->where($where)->find();
- if($isExistVote){
-
- if($isExistUserVote){
- // 显示统计
- // $voteList = json_decode($isExistVote->config);
- // $voteList = json_decode($isExistVote->config);
- $total = true;
- $totalData = [];
- $this->view->assign('vote_total',$totalData);
- }else{
- $voteList = json_decode($isExistVote->config);
- $this->view->assign('vote',$isExistVote);
- $this->view->assign('vote_list',$isExistVote);
- }
- $this->view->assign('total',$total);
- return $this->view->fetch();
- }
- }
- public function vote()
- {
- // CREATE TABLE `ucg_vote_detail` (
- // `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
- // `vote_id` int(11) NOT NULL,
- // `user_id` int(11) NOT NULL,
- // `item` varchar(255) DEFAULT NULL,
- // `createtime` bigint(16) DEFAULT NULL,
- // PRIMARY KEY (`id`)
- // ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
- $uid = $this->request->param('uid');
- $vote = $this->request->param('vote');
- $item = $this->request->param('item');
- if(empty($uid)){
- return "uid参数错误";
- }
- if(empty($vote)){
- return "vote参数错误";
- }
- if(empty($item)){
- return "item参数错误";
- }
- $where = [
- 'user_id'=>$uid,
- 'vote_id'=>$vote,
- ];
- $modelDetail = model("app\admin\model\community\VoteDetail");
- $isExistUserVote = $modelDetail->where($where)->find();
- if($isExistUserVote){
- echo "已投票";
- // return $this->success("投票成功");
- }else{
- // return $this->success("已投票");
- $where['item'] = $item;
- $modelDetail::create($where);
- echo "投票成功";
- }
-
- }
- // public function onepage(){
- // $code = $this->request->request('code');
- // $reader = $this->request->request('reader') ?? 'json';
- // $where = [
- // 'code'=>$code,
- // 'status'=>1
- // ];
- // $result = Onepage::where($where)->find();
- // if($result){
- // $this->view->assign('html',$result["content"]);
- // return $this->view->fetch('index@tpl/text');
- // }else{
- // return $this->error();
- // }
-
- // }
- // /**
- // * 获取文章详情
- // * @ApiMethod (GET)
- // * @param String $id 单页代码
- // */
- // public function article()
- // {
- // $code = $this->request->param('id');
- // $where = [
- // 'id'=>$code,
- // ];
- // $result = Articles::where($where)->find();
- // if($result){
- // $this->view->assign('html',$result["content"]);
- // return $this->view->fetch('index@tpl/text');
- // }else{
- // return $this->error();
- // }
- // }
- // /**
- // * 投票
- // * @ApiMethod (GET)
- // * @param String $id 单页代码
- // */
- // public function vote()
- // {
- // // $code = $this->request->param('id');
- // // $where = [
- // // 'id'=>$code,
- // // ];
- // // $result = Articles::where($where)->find();
- // // if($result){
- // // $this->view->assign('html',$result["content"]);
- // // return $this->view->fetch('index@tpl/text');
- // // }else{
- // // return $this->error();
- // // }
- // return $this->view->fetch('index@vote/index');
- // }
- }
|