public function respond() { global $_W; $message = $this->message; $from = $this->message['from']; $rid = $this->rule; $reply = pdo_fetch("SELECT * FROM " . tablename("kim_sign_reply") . " WHERE rid=:rid", array(":rid" => $rid)); if (intval($reply['type']) == 1) { $news = array("title" => $reply['title'], "picurl" => $_W['attachurl'] . trim($reply['image_url'], '/'), "url" => $this->buildSiteUrl($this->createMobileUrl("sign")), "description" => $reply['description']); return $this->respNews($news); } $settings = getModulesSettings($this->modulename); $uid = getUserIdByOpenId($from); $login_url = $this->buildSiteUrl(url('mc')); if ($uid <= 0) { return $this->respText("请先登录后再签到! <a href='{$login_url}'>登录</a>"); } list($bool, $code) = doSign($from, $settings); $board_url = $this->buildSiteUrl($this->createMobileUrl('LeaderBoard')); $my_url = $this->buildSiteUrl($this->createMobileUrl('MyPrize')); if (!$bool) { $hour = round(intval(24 / $settings['times'])); $message = sprintf("每天可以签到%s次,每隔%s小时可签到一次", $settings['times'], $hour); if ($code == 'over_number') { return $this->respText($message . "\n\n/::d签到排行: <a href='{$board_url}'>查看</a>\n/:showlove我的奖品 <a href='{$my_url}'>查看</a>"); } if ($code == 'over_time') { return $this->respText($reply['overtime']); } } else { $result = $code; //抽奖 $prize_cls = new Prize(); list($code, $message, $prize) = $prize_cls->lottery($uid, $settings['prize_group']); if ($code && !empty($prize)) { //中奖 $result .= "\n\n /:gift有意外惊喜 %s"; $prize_url = $this->buildSiteUrl($this->createMobileUrl('Prize', array('record_id' => $prize['record_id']))); $result = sprintf($result, "<a href='{$prize_url}'>查看</a>"); } else { //未中奖 $result .= "\n\n /:break很遗憾与奖品擦肩而过!"; } return $this->respText("/:circle签到成功!\n" . $result . "\n\n/::d签到排行 <a href='{$board_url}'>查看</a>\n/:showlove我的奖品 <a href='{$my_url}'>查看</a>"); } }
/** * 签到 */ function doSign($from, $settings) { global $_W; unset($uid, $today_sign, $insert); $uid = getUserIdByOpenId($from); if ($uid <= 0) { return array(false, 'no_login'); } $today_sign = getUserTodaySign($uid, $settings['times']); //今天签到数据 if (!empty($today_sign)) { return array(false, 'over_number'); } //超过签到次数 //list($times, $start_time, $end_time, $credit_type, $credit) $now = time(); if ($now < strtotime($settings['start_time']) || $now > strtotime($settings['end_time'])) { return array(false, 'over_time'); } //不在签到时间 $rank = intval(getTodaySignTotal()) + 1; $times = intval(getUserSignTotal($uid) + 1); $insert = array('uniacid' => $_W['uniacid'], 'uid' => $uid, 'time' => $now, 'sum_times' => $times, 'rank' => $rank); pdo_insert('kim_sign_record', $insert); if (pdo_insertid() > 0) { load()->model('mc'); $log = array(0, '签到获得'); mc_credit_update($uid, $settings['credit_type'], doubleval($settings['credit']), $log); $credit = mc_credit_fetch($uid, array($settings['credit_type'])); } $credits = uni_setting($_W['uniacid'], 'creditnames'); $credit_type = $credits['creditnames'][$settings['credit_type']]; $result = "您今天第 %s 个签到用户\n本次获得 %s 个%s\n您累计拥有 %s 个%s"; $result = sprintf($result, $rank, doubleval($settings['credit']), $credit_type['title'], $credit[$settings['credit_type']], $credit_type['title']); return array(true, $result); }