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'); // } }