此次学习通过条件来限制投票次数,当投票后,参与投票的微信用户的openid存入数据库中。
投票规则 通过时间戳来计算,以此来生成where条件
//投票规则
private function buildwhere($type,$openid,$groupid){
//查询条件
$where = array();
$y = date("Y");
$m = date("m");
$d = date("d");
//将今天开始的年月日时分秒,转换成unix时间戳(开始示例:2018-4-28 00:00:00)
$todayStart = mktime(0,0,0,$m,$d,$y);
$todayEnd = mktime(23,59,59,$m,$d,$y);
switch ($type){
case 1:
//每个小组仅能投一次
$where['openid'] = $openid;
$where['groupid'] = $groupid;
break;
case 2:
//仅能投一次
$where['openid'] = $openid;
break;
case 3:
//给每个组一天仅能投一次
$where['openid'] = $openid;
$where['groupid'] = $groupid;
$where['vote_time'] = array('