Пример #1
0
 public static function trans_time($params)
 {
     $time = $params['time'];
     if (!$time) {
         return '-';
     }
     $is_real = isset($params['is_real']) ? $params['is_real'] : false;
     $just_date = isset($params['just_date']) ? $params['just_date'] : false;
     $result = date('Y-m-d H:i:s', $time);
     if ($just_date) {
         $result = date('n月j日', $time);
     } elseif (!$is_real) {
         $differ = time() - $time;
         if ($differ < 1 * 60) {
             //1分钟前,则显示“刚刚”
             $result = '刚刚';
         } elseif ($differ < 3600) {
             //1个小时前,则显示“xx分钟前”
             $result = round($differ / 60) . '分钟前';
         } else {
             if ($time < shorttotime('jn')) {
                 //今年以前的,显示具体年月“yyyy-mm-dd hh:mm”
                 $result = date('Y-m-d H:i', $time);
             } elseif ($time < shorttotime('qt')) {
                 // 今年内的,显示“x月y日 hh:mm”
                 $result = date('n月j日 H:i', $time);
             } elseif ($time < shorttotime('zt')) {
                 // 前天内的,显示“前日 hh:mm”
                 $result = date('前天 H:i', $time);
             } elseif ($time < shorttotime('jt')) {
                 // 昨天内的,显示“昨日 hh:mm”
                 $result = date('昨天 H:i', $time);
             } else {
                 //今天内的,显示“今日 hh:mm”
                 $result = date('今天 H:i', $time);
             }
         }
     }
     return $result;
 }
Пример #2
0
 /**
  *
  * @param string $act, 'vote','flower','kiss'
  * @param integer $player_id
  * @param integer $uid
  * @param integer $inc
  * @param boolean $nocheck,是否不检查
  * @param boolean $norecord,是否不记录
  * @param array $extra,额外参数记录
  * @return number
  *   -11: vote超过了最大次数(5)
  *   -12: vote时间间隔没超过120分钟
  *   -13: 投票太频繁
  *   -14: 投票已截止
  *  -100: 操作失败
  */
 static function action($act, $player_id, $uid, $inc = 1, $nocheck = FALSE, $norecord = FALSE, $extra = array())
 {
     $now = simphp_time();
     $votedcnt = 0;
     $maxvotenum = 5;
     //一个用户一天可以对每个女神投5次票,可连续投
     $voteinterval = 60 * 60 * 2;
     //投票间隔限制(单位:秒)
     $spaminterval = 2;
     //作弊检测时间(单位:秒)
     $maybespam = 0;
     //可能作弊标志
     $limitvotetime = strtotime('2015-12-20 23:55:00');
     $stopvotetime = strtotime('2015-12-21 00:00:00');
     if ('vote' == $act && !$nocheck) {
         if ($now > $stopvotetime) {
             return -14;
         }
         $today_start = shorttotime('jt');
         $today_end = shorttotime('mt');
         //查找当天已经投的次数
         $votedcnt = D()->from("action")->where("`player_id`=%d AND `action`='%s' AND `uid`=%d AND `timeline`>=%d AND `timeline`<%d", $player_id, $act, $uid, $today_start, $today_end)->select("COUNT(`aid`) AS cnt")->result();
         if ($votedcnt >= $maxvotenum) {
             return -11;
         }
         //查找前一次投票时间
         $now = simphp_time();
         $latest = D()->from("action")->where("`action`='%s' AND `player_id`=%d AND `uid`=%d", $act, $player_id, $uid)->select("MAX(`timeline`) AS maxacttime")->result();
         $diff = $now - $latest;
         if ($diff < $spaminterval) {
             $maybespam = $spaminterval - $diff;
             //return -13;
         }
         if (isset($extra['maybe_spam']) && $extra['maybe_spam']) {
             $maybespam = 100;
         }
         /*
         if ($diff < $voteinterval) {
           return -12;
         }
         */
     }
     if (in_array($act, ['vote', 'flower', 'kiss'])) {
         $aid = 0;
         if (!$norecord) {
             $aid = D()->insert("action", ['action' => $act, 'player_id' => $player_id, 'inc' => $inc, 'uid' => $uid, 'timeline' => $now, 'spam' => $maybespam]);
         }
         if ($norecord || $aid) {
             //更新player投票数
             if ($now < $stopvotetime) {
                 D()->query("UPDATE {player} SET {$act}cnt={$act}cnt+%d WHERE player_id=%d", $inc, $player_id);
             }
             //更新node总投票数
             $match_id = D()->from("player")->where("player_id=%d", $player_id)->select("match_id")->result();
             D()->query("UPDATE {node} SET {$act}cnt={$act}cnt+%d WHERE nid=%d", $inc, $match_id);
             if ($act == 'vote') {
                 $player_stage = D()->from("player")->where("player_id=%d", $player_id)->select("`stage`")->result();
                 if ($now < $stopvotetime && in_array($player_stage, ['1', '2'])) {
                     //同步更新晋级赛程的统计票数字段
                     if ($now < $limitvotetime || isset($extra['from']) && in_array($extra['from'], ['sendflower', 'admin'])) {
                         D()->query("UPDATE {player} SET votecnt{$player_stage}=votecnt{$player_stage}+%d WHERE player_id=%d", $inc, $player_id);
                     } else {
                         if (0 == $votedcnt) {
                             //最后十分钟仅保留1人1票
                             D()->query("UPDATE {player} SET votecnt{$player_stage}=votecnt{$player_stage}+%d WHERE player_id=%d", $inc, $player_id);
                         }
                     }
                 }
                 if (!$nocheck) {
                     return $maxvotenum - $votedcnt - $inc;
                     //需检查限制的,返回当前剩余可投票数;否则留最后默认返回$aid
                 }
             } elseif ($act == 'flower') {
                 //规则:
                 // 1、一枝花抵两票
                 // 2、数量不限、时间不限
                 // 送票(x2)
                 self::action('vote', $player_id, $uid, $inc * 2, TRUE, TRUE, ['from' => 'sendflower']);
             } elseif ($act == 'kiss') {
             }
             return $aid;
             //默认返回动作id
         }
     }
     return -100;
 }