From 0db52ef66a98d7710b4e906ae5e04b7673804f00 Mon Sep 17 00:00:00 2001 From: hujiabin <519660157@qq.com> Date: Tue, 30 May 2023 11:45:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=83=E6=97=A5=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/Ranking.py | 3 +- doc/Sign.py | 71 ++++------- doc/_common.py | 12 ++ sql/gamedb.sql | 17 +++ webapp/controller/SignController.class.php | 136 +++++++++++++++++++++ webapp/models/SignLog.php | 48 +++++++- webapp/mt/Sign.php | 44 +++++++ 7 files changed, 284 insertions(+), 47 deletions(-) diff --git a/doc/Ranking.py b/doc/Ranking.py index d52e19de..2e1fd0c1 100644 --- a/doc/Ranking.py +++ b/doc/Ranking.py @@ -31,7 +31,8 @@ class Ranking(object): 'response': [ _common.RspHead(), ['status', 0, '0:常规状态 1:引导初始排位 2:赛季初,需结算上个赛季'], - ['is_rank', 0, '1:赛季开始了 0:赛季未开始'] + ['is_rank', 0, '1:赛季开始了 0:赛季未开始'], + ['countdown', 0, '下赛季倒计时(秒) 0 表示这赛季还未结束'], ] }, { diff --git a/doc/Sign.py b/doc/Sign.py index 613fefc1..41ace7da 100644 --- a/doc/Sign.py +++ b/doc/Sign.py @@ -6,48 +6,31 @@ class Sign(object): def __init__(self): self.apis_ = [ - { - 'desc': 'signInfo', - 'group': 'Sign', - 'url': 'webapp/index.php?c=Sign&a=signInfo', - 'params': [ - _common.ReqHead(), - ], - 'response': [ - _common.RspHead(), - ] - }, - { - 'desc': 'signReward', - 'group': 'Sign', - 'url': 'webapp/index.php?c=Sign&a=signReward', - 'params': [ - _common.ReqHead(), - ], - 'response': [ - _common.RspHead(), - ] - }, - { - 'desc': 'signDoubleReward', - 'group': 'Sign', - '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(), - ] - }, + { + 'name': 'getSignList', + 'desc': '7日签到', + 'group': 'Sign', + 'url': 'webapp/index.php?c=Sign&a=getSignList', + 'params': [ + _common.ReqHead(), + ], + 'response': [ + _common.RspHead(), + ['data', _common.Sign(), '签到信息'], + ] + }, + { + 'name': 'receive', + 'desc': '领取签到奖励', + 'group': 'Sign', + 'url': 'webapp/index.php?c=Sign&a=receive', + 'params': [ + _common.ReqHead(), + ['sign_id', '', '签到id'], + ], + 'response': [ + _common.RspHead(), + ['property_chg', _common.PropertyChg(), '属性变更'], + ] + }, ] diff --git a/doc/_common.py b/doc/_common.py index b52b4cab..6d2c7485 100644 --- a/doc/_common.py +++ b/doc/_common.py @@ -1153,4 +1153,16 @@ class BattleReward(object): self.fields = [ ['hero', BattleCegReward(), '英雄奖励'], ['!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()], '奖励信息'], ] \ No newline at end of file diff --git a/sql/gamedb.sql b/sql/gamedb.sql index d62337f4..44511b5a 100644 --- a/sql/gamedb.sql +++ b/sql/gamedb.sql @@ -1069,3 +1069,20 @@ CREATE TABLE `t_rank_battle` ( KEY `value` (`value`) ) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; /*!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 */; \ No newline at end of file diff --git a/webapp/controller/SignController.class.php b/webapp/controller/SignController.class.php index e69de29b..15852505 100644 --- a/webapp/controller/SignController.class.php +++ b/webapp/controller/SignController.class.php @@ -0,0 +1,136 @@ + $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(), + + )); + } + + + + + + + + + +} diff --git a/webapp/models/SignLog.php b/webapp/models/SignLog.php index b17d2cc9..ab74f051 100644 --- a/webapp/models/SignLog.php +++ b/webapp/models/SignLog.php @@ -3,8 +3,52 @@ namespace models; - -class SignLog +use mt; +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 + ); + } + } \ No newline at end of file diff --git a/webapp/mt/Sign.php b/webapp/mt/Sign.php index 88c8987a..ee1779bb 100644 --- a/webapp/mt/Sign.php +++ b/webapp/mt/Sign.php @@ -6,5 +6,49 @@ namespace mt; 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; } \ No newline at end of file