VoteController.php 3.3 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);

   }

   $options=config('wechat_config');
   $app = new Application($options);

   $js = $app->js;
   $jssdk=$js->config(array('onMenuShareAppMessage', 'onMenuShareTimeline','onMenuShareQQ'), false,false,true);
   $this->assign('jssdk',$jssdk);
   $url = "http://wangba.w.bronet.cn";
   $this -> assign('url',$url);

   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(){

    $mid = cmf_get_current_user_id();
    $id = input('post.id');
    $tid = input('post.tid');
    $tian['mid'] = $mid;
    $tian['vid'] = $tid;
    Db::name('mevo') -> insert($tian);
    $data = Db::name('vote') -> where('id',$id) -> setInc('votes');


    //投票优惠券
    $uid = Db::name('members_user') -> where('uid',$mid) -> find();
    $tpyh = Db::name('coupons') -> where('type',4) -> find();
    $coupyh['uid'] = $uid['id'];
    $coupyh['cid'] = $tpyh['id'];
    $coupyh['state'] = 0;
    $coupyh['code'] = date('md').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
    Db::name('coupons_user') -> insert($coupyh);


    if($data){
      return false;
    }else{
      return true;
    }

  }

  //多选增加票数
  public function vshuang(){

    $mid = cmf_get_current_user_id();

    //投票优惠券
    $uid = Db::name('members_user') -> where('uid',$mid) -> find();
    $tpyh = Db::name('coupons') -> where('type',4) -> find();
    $coupyh['uid'] = $uid['id'];
    $coupyh['cid'] = $tpyh['id'];
    $coupyh['state'] = 0;
    $coupyh['code'] = date('md').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
    Db::name('coupons_user') -> insert($coupyh);

    $ids = explode(',', input('post.ids'));
    foreach ($ids as $key => $value) {
       Db::name('vote') -> where('id',$value) -> setInc('votes');
    }
    $tid = input('post.tid');
    $data['mid'] = $mid;
    $data['vid'] = $tid;
    $pan = Db::name('mevo') -> insert($data);



    if($pan){
      return true;
    }else{
      return false;
    }


  }





}




 ?>