Beispiel #1
0
     exit;
 }
 protected function prepareActivity($activity, $verifyParams = array())
 {
     if (empty($activity)) {
         return error(-1, '<h1>访问错误</h1>');
     }
     if (is_error($activity)) {
         return $activity;
     }
     if ($activity['start'] > TIMESTAMP) {
         return error(-2, '<h4>不要着急, 活动还未开始, 敬请期待</h4> <br><h5>本次活动时间为: <br>' . date('Y-m-d H:i', $activity['start']) . ' <br> ' . date('Y-m-d H:i', $activity['end']) . '</h5>');
     }
     if ($activity['end'] < TIMESTAMP) {
         return error(-2, '<h4>手慢了, 本次活动已经结束, 请关注我们期待下次活动</h4> <br><h5>本次活动时间为: <br>' . date('Y-m-d H:i', $activity['start']) . ' <br> ' . date('Y-m-d H:i', $activity['end']) . '</h5>');
     }
     if (!empty($activity['limit'])) {
         if (!empty($activity['limit']['range']) && !empty($verifyParams['user'])) {
             $valid = false;
             $pieces = explode(';', $activity['limit']['range']);
             if (is_array($pieces)) {
                 foreach ($pieces as $district) {
                     if ($valid) {
                         break;
                     }
                     $district = trim($district);
                     $districts = explode('-', $district);
                     $area = array();
                     $area['state'] = trim($districts[0]);
                     $area['city'] = trim($districts[1]);
                     if (!empty($area['state']) && !empty($area['city'])) {
                         if ($area['state'] == $verifyParams['user']['state'] && $area['city'] == $verifyParams['user']['city']) {
                             $valid = true;
                         }
                     } elseif (!empty($area['state'])) {
                         if ($area['state'] == $verifyParams['user']['state']) {
                             $valid = true;
                         }
                     }
                 }
             }
             if (!$valid) {
                 return error(-3, "<h4>你的位置是: {$verifyParams['user']['state']}-{$verifyParams['user']['city']}</h4><br><h5>不在本次活动范围. 请关注并期待我们下一次活动</h5>");
             }
         }
         if (!empty($activity['limit']['gender']) && !empty($verifyParams['user'])) {
             if ($activity['limit']['gender'] != $verifyParams['user']['gender']) {
                 return error(-3, "<h4>抱歉哦: 本次活动只在 <mark>{$activity['limit']['gender']}</mark> 性朋友范围内举行</h4>");
             }
         }
         if (!empty($activity['limit']['amount'])) {
             if ($activity['amount'] >= $activity['limit']['amount']) {
                 return error(-4, "<h4>哎呀, 手慢了. 本次活动所有红包已发完</h4> <br><h5>本次活动已经结束, 请关注我们期待下一次活动</h5>");
             }
         }
     }
     if ($activity['type'] == 'game') {
         if ($activity['tag']['pool'] <= $activity['tag']['threshold']) {
             return error(-4, "<h4>哎呀, 手慢了. 本次活动所有红包已发完</h4> <br><h5>本次活动已经结束, 请关注我们期待下一次活动</h5>");
         }
     }
     $api = new Api();
     $info = $api->getCurrent();
     if (is_error($info)) {
         return $info;
         #debug
     }
     if ($activity['type'] == 'direct') {
         $a = new Activity();
         $gots = $a->getUserRecords($verifyParams['user']['uid'], $activity['actid']);
         if (!empty($gots)) {
             if (!empty($activity['tag']['daily'])) {
                 $count = 0;
                 $today = strtotime(date('Y-m-d', TIMESTAMP));
                 foreach ($gots as $got) {
                     if ($got['created'] > $today && ($got['status'] == 'none' || $got['status'] == 'complete')) {
                         $count++;
                     }
                 }
                 if ($count >= intval($activity['tag']['daily'])) {
                     return error(-5, "<h4>这次活动每人每天只能参加 {$activity['tag']['daily']} 次. <br>您今天已经参加或 {$count} 次, 不能再玩了</h4>");
                 }
             }
             if (!empty($activity['tag']['total'])) {
                 $count = 0;
                 foreach ($gots as $got) {
                     if ($got['status'] == 'none' || $got['status'] == 'complete') {
                         $count++;
                     }
                 }
                 if ($count >= intval($activity['tag']['total'])) {
                     return error(-5, "<h4>这次活动每人只能参加 {$activity['tag']['total']} 次. <br>您已经参加或 {$count} 次, 不能再玩了</h4>");
                 }
             }
         }
     }
Beispiel #2
0
<?php

global $_W, $_GPC;
require_once MB_ROOT . '/source/Activity.class.php';
$user = $this->auth();
$id = $_GPC['actid'];
$id = intval($id);
$a = new Activity();
$activity = $a->getOne($id);
$prepare = $this->prepareActivity($activity, array('user' => $user));
if (is_error($prepare)) {
    $error = $prepare;
    exit($error['message']);
}
$api = new Api();
$current = $api->getCurrent();
$info = array();
$info['distance'] = $current['distance'];
$info['device'] = $current['device']['id'];
if ($activity['type'] == 'direct') {
    $rid = intval($_GPC['rid']);
    if (!empty($rid)) {
        $record = $a->getOneRecord($rid);
        if (empty($record) || $record['activity'] != $activity['actid'] || $record['uid'] != $user['uid']) {
            exit('非法的访问');
        }
        $ret = $record;
    } else {
        $ret = $a->grap($user, $activity, $info);
    }
    if (is_error($ret)) {