七日登录
This commit is contained in:
parent
5540d4f690
commit
0db52ef66a
@ -31,7 +31,8 @@ class Ranking(object):
|
|||||||
'response': [
|
'response': [
|
||||||
_common.RspHead(),
|
_common.RspHead(),
|
||||||
['status', 0, '0:常规状态 1:引导初始排位 2:赛季初,需结算上个赛季'],
|
['status', 0, '0:常规状态 1:引导初始排位 2:赛季初,需结算上个赛季'],
|
||||||
['is_rank', 0, '1:赛季开始了 0:赛季未开始']
|
['is_rank', 0, '1:赛季开始了 0:赛季未开始'],
|
||||||
|
['countdown', 0, '下赛季倒计时(秒) 0 表示这赛季还未结束'],
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
71
doc/Sign.py
71
doc/Sign.py
@ -6,48 +6,31 @@ class Sign(object):
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.apis_ = [
|
self.apis_ = [
|
||||||
{
|
{
|
||||||
'desc': 'signInfo',
|
'name': 'getSignList',
|
||||||
'group': 'Sign',
|
'desc': '7日签到',
|
||||||
'url': 'webapp/index.php?c=Sign&a=signInfo',
|
'group': 'Sign',
|
||||||
'params': [
|
'url': 'webapp/index.php?c=Sign&a=getSignList',
|
||||||
_common.ReqHead(),
|
'params': [
|
||||||
],
|
_common.ReqHead(),
|
||||||
'response': [
|
],
|
||||||
_common.RspHead(),
|
'response': [
|
||||||
]
|
_common.RspHead(),
|
||||||
},
|
['data', _common.Sign(), '签到信息'],
|
||||||
{
|
]
|
||||||
'desc': 'signReward',
|
},
|
||||||
'group': 'Sign',
|
{
|
||||||
'url': 'webapp/index.php?c=Sign&a=signReward',
|
'name': 'receive',
|
||||||
'params': [
|
'desc': '领取签到奖励',
|
||||||
_common.ReqHead(),
|
'group': 'Sign',
|
||||||
],
|
'url': 'webapp/index.php?c=Sign&a=receive',
|
||||||
'response': [
|
'params': [
|
||||||
_common.RspHead(),
|
_common.ReqHead(),
|
||||||
]
|
['sign_id', '', '签到id'],
|
||||||
},
|
],
|
||||||
{
|
'response': [
|
||||||
'desc': 'signDoubleReward',
|
_common.RspHead(),
|
||||||
'group': 'Sign',
|
['property_chg', _common.PropertyChg(), '属性变更'],
|
||||||
'url': 'webapp/index.php?c=Sign&a=signDoubleReward',
|
]
|
||||||
'params': [
|
},
|
||||||
_common.ReqHead(),
|
|
||||||
],
|
|
||||||
'response': [
|
|
||||||
_common.RspHead(),
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'desc': 'getSignOrder',
|
|
||||||
'group': 'Sign',
|
|
||||||
'url': 'webapp/index.php?c=Sign&a=getSignOrder',
|
|
||||||
'params': [
|
|
||||||
_common.ReqHead(),
|
|
||||||
],
|
|
||||||
'response': [
|
|
||||||
_common.RspHead(),
|
|
||||||
]
|
|
||||||
},
|
|
||||||
]
|
]
|
||||||
|
@ -1153,4 +1153,16 @@ class BattleReward(object):
|
|||||||
self.fields = [
|
self.fields = [
|
||||||
['hero', BattleCegReward(), '英雄奖励'],
|
['hero', BattleCegReward(), '英雄奖励'],
|
||||||
['!items', [BattleItemReward()], '碎片奖励'],
|
['!items', [BattleItemReward()], '碎片奖励'],
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class Sign(object):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.fields = [
|
||||||
|
['sign_id', 0, '签到id'],
|
||||||
|
['days', 0, '累计天数'],
|
||||||
|
['condition', 0, '签到条件(天数)'],
|
||||||
|
['is_receive', 0, '领取状态 0:可领取 1:已领取 -1:未达到'],
|
||||||
|
['!award', [AwardItem()], '奖励信息'],
|
||||||
]
|
]
|
@ -1069,3 +1069,20 @@ CREATE TABLE `t_rank_battle` (
|
|||||||
KEY `value` (`value`)
|
KEY `value` (`value`)
|
||||||
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
|
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
|
||||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||||
|
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Table structure for table `t_user_sign_log`
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE TABLE `t_user_sign_log` (
|
||||||
|
`idx` int(10) NOT NULL AUTO_INCREMENT COMMENT '自增id',
|
||||||
|
`account_id` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id',
|
||||||
|
`days` int(10) DEFAULT '0' COMMENT '累计签到天数',
|
||||||
|
`sign_time` int(10) DEFAULT NULL COMMENT '签到时间',
|
||||||
|
`is_receive` tinyint(4) DEFAULT '0' COMMENT '是否领取奖励',
|
||||||
|
`createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
|
||||||
|
`modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
|
||||||
|
PRIMARY KEY (`idx`)
|
||||||
|
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
|
||||||
|
/*!40101 SET character_set_client = @saved_cs_client */;
|
@ -0,0 +1,136 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once('mt/Sign.php');
|
||||||
|
require_once('mt/Parameter.php');
|
||||||
|
|
||||||
|
require_once('models/SignLog.php');
|
||||||
|
|
||||||
|
require_once('services/AwardService.php');
|
||||||
|
require_once('services/PropertyChgService.php');
|
||||||
|
|
||||||
|
use phpcommon\SqlHelper;
|
||||||
|
use models\User;
|
||||||
|
use models\SignLog;
|
||||||
|
|
||||||
|
class SignController extends BaseAuthedController
|
||||||
|
{
|
||||||
|
|
||||||
|
public function getSignList(){
|
||||||
|
$metaList = \mt\Sign::getListByDay();
|
||||||
|
$data = array();
|
||||||
|
$row = SignLog::find();
|
||||||
|
$day = $row ? $row['days'] : 0;
|
||||||
|
foreach ($metaList as $meta){
|
||||||
|
if ($day > $meta['condition']){
|
||||||
|
$state = 1;
|
||||||
|
}elseif ($day == $meta['condition']){
|
||||||
|
$state = $row['is_receive'];
|
||||||
|
}else{
|
||||||
|
$state = -1;
|
||||||
|
}
|
||||||
|
$award = \mt\Sign::getAward($meta);
|
||||||
|
array_push($data,array(
|
||||||
|
'sign_id' => $meta['sign_id'],
|
||||||
|
'days' => $day,
|
||||||
|
'condition' => $meta['condition'],
|
||||||
|
'is_receive' => $state,
|
||||||
|
// 'item_id' => $meta['item_id'],
|
||||||
|
// 'item_num' => $meta['num'],
|
||||||
|
'award' => $award
|
||||||
|
));
|
||||||
|
}
|
||||||
|
$paramMeta = \mt\Parameter::getByName('sign_daily_duration');
|
||||||
|
$start_time = myself()->_getDaySeconds($row['createtime']);
|
||||||
|
$end_time = myself()->_getDaySeconds($row['createtime'])+$paramMeta['param_value']*24*60*60;
|
||||||
|
$this->_rspData(array(
|
||||||
|
'data' => $data,
|
||||||
|
'time' => array(
|
||||||
|
'start_time' =>$start_time,
|
||||||
|
'end_time' =>$end_time
|
||||||
|
)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
//首次登录 签到活动开始
|
||||||
|
|
||||||
|
public function sign(){
|
||||||
|
// ...用户登录-login
|
||||||
|
|
||||||
|
//用户是否有签到记录
|
||||||
|
if (SignLog::isSignRecord()){
|
||||||
|
//有签到记录
|
||||||
|
$row = SignLog::find();
|
||||||
|
$paramMeta = \mt\Parameter::getByName('sign_daily_duration');
|
||||||
|
$end_time = myself()->_getDaySeconds($row['createtime']) + $paramMeta['param_value']*24*60*60;
|
||||||
|
//判断当前时间是否结束 并且 上次签到是否领取 并且 签到时间是否满足第二天签到
|
||||||
|
if (myself()->_getNowTime() < $end_time
|
||||||
|
&& $row['is_receive']
|
||||||
|
&& $row['sign_time'] < myself()->_getNowDaySeconds() + 6*60*60){
|
||||||
|
if($row['sign_time'] > myself()->_getNowDaySeconds()){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$fieldKv = array(
|
||||||
|
'days' => function(){
|
||||||
|
return "days + 1";
|
||||||
|
},
|
||||||
|
'is_receive' => 0,
|
||||||
|
'sign_time' => myself()->_getNowTime(),
|
||||||
|
'modifytime' => myself()->_getNowTime()
|
||||||
|
);
|
||||||
|
SignLog::update($fieldKv);
|
||||||
|
}
|
||||||
|
|
||||||
|
}else{
|
||||||
|
//未有签到记录
|
||||||
|
SignLog::create();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function receive(){
|
||||||
|
$sign_id = getReqVal('sign_id', '');
|
||||||
|
$meta = \mt\Sign::get($sign_id);
|
||||||
|
if (!$meta){
|
||||||
|
$this->_rspErr(1, 'sign_id param error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$row = SignLog::find();
|
||||||
|
if (!$row || $row['days'] != $meta['condition']){
|
||||||
|
$this->_rspErr(1, 'Condition not met');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ($row['is_receive']){
|
||||||
|
$this->_rspErr(1, 'Have received');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$paramMeta = \mt\Parameter::getByName('sign_daily_duration');
|
||||||
|
$end_time = myself()->_getDaySeconds($row['createtime'])+$paramMeta['param_value']*24*60*60;
|
||||||
|
if (myself()->_getNowTime() > $end_time){
|
||||||
|
$this->_rspErr(1, 'End of activity time');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$addItems = \mt\Sign::getAward($meta);
|
||||||
|
$awardService = new services\AwardService();
|
||||||
|
$propertyChgService = new services\PropertyChgService();
|
||||||
|
$this->_addItems($addItems, $awardService, $propertyChgService);
|
||||||
|
$fieldKv = array(
|
||||||
|
'is_receive' => 1,
|
||||||
|
'modifytime' => myself()->_getNowTime()
|
||||||
|
);
|
||||||
|
SignLog::update($fieldKv);
|
||||||
|
$this->_rspData(array(
|
||||||
|
'award' => $awardService->toDto(),
|
||||||
|
'property_chg' => $propertyChgService->toDto(),
|
||||||
|
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -3,8 +3,52 @@
|
|||||||
|
|
||||||
namespace models;
|
namespace models;
|
||||||
|
|
||||||
|
use mt;
|
||||||
class SignLog
|
use phpcommon\SqlHelper;
|
||||||
|
class SignLog extends BaseModel
|
||||||
{
|
{
|
||||||
|
public static function isSignRecord(){
|
||||||
|
if (self::find()){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function find(){
|
||||||
|
return SqlHelper::ormSelectOne(
|
||||||
|
myself()->_getSelfMysql(),
|
||||||
|
't_user_sign_log',
|
||||||
|
array(
|
||||||
|
'account_id' => myself()->_getAccountId()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function create(){
|
||||||
|
SqlHelper::insert
|
||||||
|
(myself()->_getSelfMysql(),
|
||||||
|
't_user_sign_log',
|
||||||
|
array(
|
||||||
|
'account_id' => myself()->_getAccountId(),
|
||||||
|
'days' => 1,
|
||||||
|
'sign_time' => myself()->_getNowTime(),
|
||||||
|
'is_receive' => 0,
|
||||||
|
'createtime' => myself()->_getNowTime(),
|
||||||
|
'modifytime' => myself()->_getNowTime(),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function update($fieldKv){
|
||||||
|
SqlHelper::update
|
||||||
|
(myself()->_getSelfMysql(),
|
||||||
|
't_user_sign_log',
|
||||||
|
array(
|
||||||
|
'account_id' => myself()->_getAccountId(),
|
||||||
|
),
|
||||||
|
$fieldKv
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -6,5 +6,49 @@ namespace mt;
|
|||||||
|
|
||||||
class Sign
|
class Sign
|
||||||
{
|
{
|
||||||
|
const DEFAULT_DAYS = 7;
|
||||||
|
|
||||||
|
public static function get($signId)
|
||||||
|
{
|
||||||
|
return getXVal(self::getMetaList(), $signId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getListByDay()
|
||||||
|
{
|
||||||
|
$list = array();
|
||||||
|
foreach (self::getMetaList() as $meta){
|
||||||
|
if ($meta['condition'] <= self::DEFAULT_DAYS){
|
||||||
|
array_push($list,$meta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getAward($meta){
|
||||||
|
if ($meta){
|
||||||
|
$itemIds = splitStr1($meta['item_id']);
|
||||||
|
$itemNums = splitStr1($meta['num']);
|
||||||
|
$result = array();
|
||||||
|
if (count($itemIds) == count($itemNums)) {
|
||||||
|
for ($i = 0; $i < count($itemIds); ++$i) {
|
||||||
|
array_push($result, array(
|
||||||
|
'item_id' => $itemIds[$i],
|
||||||
|
'item_num' => $itemNums[$i],
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static function getMetaList()
|
||||||
|
{
|
||||||
|
if (!self::$metaList) {
|
||||||
|
self::$metaList = getMetaTable('signDaily@signDaily.php');
|
||||||
|
}
|
||||||
|
return self::$metaList;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static $metaList;
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user