VoteController.php 1.6 KB
<?php
namespace app\portal\controller;

use cmf\controller\WeChatBaseController;
use EasyWeChat\Foundation\Application;
use EasyWeChat\Payment\Order;
use think\Db;

class VoteController extends WeChatBaseController{


  //显示投票页
  public function index(){

    $mid = cmf_get_current_user_id();
    $data = Db::name('mevo') -> alias('a') -> join('vote b','a.vid=b.id','LEFT') -> where('a.mid',$mid) -> select() ;
    $coun = count($data);
   if($coun == 0){

    $shuju = Db::name('vote') -> where('pid',0) -> select();

    $this -> assign('shuju',$shuju);

    $this -> assign('canyu','');

    $this -> assign('weican','');

   }else{

    $this -> assign('canyu',$data);

    $this -> assign('shuju','');

    foreach ($data as $key => $value) {

      $arr[] = $value['id'];

    }

    $shuju = Db::name('vote') -> where('pid',0) -> select();

    foreach ($shuju as $key => $value) {
        if(in_array($value['id'],$arr )){
            unset($shuju[$key]);
        }
    }

    $this -> assign('weican',$shuju);

   }
   return $this -> fetch();

  }


  //投票内容显示页
  public function showVote(){

    $id= $this -> request -> param();
    $title = Db::name('vote') -> where('id',$id['id']) -> find();
    $xuan = Db::name('vote') -> where('pid',$id['id']) -> select();
    $this -> assign('title',$title);
    $this -> assign('xuan',$xuan);
    return $this  -> fetch();

  }

  //单选添加票数
  public function vdan(){

    $id = input('post.id');
    $data = Db::name('vote') -> where('id',$id) -> setInc('votes');
    if($data){
      return false;
    }else{
      return true;
    }

  }





}




 ?>