From ba998d8363a3beb16e4cf59c559bacd1b6e396a7 Mon Sep 17 00:00:00 2001 From: hujiabin <519660157@qq.com> Date: Tue, 23 Jul 2024 15:21:48 +0800 Subject: [PATCH] emoji --- doc/_common.py | 1 + sql/gamedb.sql | 2 + sql/gamedb2006_migrate_240722_01.sql | 20 ++++ .../controller/BaseAuthedController.class.php | 7 ++ webapp/controller/EmojiController.class.php | 54 ++++----- webapp/models/Emoji.php | 104 ++++++++++++++---- webapp/mt/Item.php | 1 + webapp/services/TimingPropService.php | 29 +++++ 8 files changed, 171 insertions(+), 47 deletions(-) create mode 100644 sql/gamedb2006_migrate_240722_01.sql create mode 100644 webapp/services/TimingPropService.php diff --git a/doc/_common.py b/doc/_common.py index 2bd4eae7..f4118659 100644 --- a/doc/_common.py +++ b/doc/_common.py @@ -1092,6 +1092,7 @@ class Emoji(object): self.fields = [ ['item_id', 0, 'item_id'], ['state', 0, '1:使用 0:未使用'], + ['left_time', 0, '剩余时间'], ] class ChipPage(object): diff --git a/sql/gamedb.sql b/sql/gamedb.sql index 21543e1f..e0cf94bd 100644 --- a/sql/gamedb.sql +++ b/sql/gamedb.sql @@ -1006,6 +1006,8 @@ CREATE TABLE `t_emoji` ( `idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id', `account_id` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id', `item_id` int(11) NOT NULL DEFAULT '0' COMMENT 'itemID', + `last_get_time` int(11) NOT NULL DEFAULT '0' COMMENT '最后获得时间', + `valid_time` int(11) NOT NULL DEFAULT '0' COMMENT '有效时间', `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', PRIMARY KEY (`idx`), diff --git a/sql/gamedb2006_migrate_240722_01.sql b/sql/gamedb2006_migrate_240722_01.sql new file mode 100644 index 00000000..14d51d08 --- /dev/null +++ b/sql/gamedb2006_migrate_240722_01.sql @@ -0,0 +1,20 @@ +begin; + +DROP TABLE IF EXISTS `t_emoji`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `t_emoji` ( + `idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id', + `account_id` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id', + `item_id` int(11) NOT NULL DEFAULT '0' COMMENT 'itemID', + `last_get_time` int(11) NOT NULL DEFAULT '0' COMMENT '最后获得时间', + `valid_time` int(11) NOT NULL DEFAULT '0' COMMENT '有效时间', + `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', + `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', + PRIMARY KEY (`idx`), + UNIQUE KEY `account_item_id` (`account_id`, `item_id`) +) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + +insert into version (version) values(2024052101); + +commit; diff --git a/webapp/controller/BaseAuthedController.class.php b/webapp/controller/BaseAuthedController.class.php index 2f38a71c..c8573480 100644 --- a/webapp/controller/BaseAuthedController.class.php +++ b/webapp/controller/BaseAuthedController.class.php @@ -1,6 +1,7 @@ handleProp($itemMeta); + } + break; default: { $this->_addLog('additems', 'invalid_item', array( diff --git a/webapp/controller/EmojiController.class.php b/webapp/controller/EmojiController.class.php index fa84e5a0..13fe97bc 100644 --- a/webapp/controller/EmojiController.class.php +++ b/webapp/controller/EmojiController.class.php @@ -4,38 +4,36 @@ require_once('models/Emoji.php'); use models\Emoji; class EmojiController extends BaseAuthedController { -// public function getEmojiList(){ -// $this->_rspData(array( -// 'data' => array( -// array( -// 'item_id'=>200001, -// 'state'=>1, -// ) -// ), -// 'use_emoji' => array(200001) -// )); -// } public function getEmojiList(){ - $list = Emoji::emojiList(); + $emojiList = array(); + Emoji::emojiList(function ($row) use (&$emojiList){ + $tDo = Emoji::toDto($row); + if ($tDo['left_time'] > 0){ + array_push($emojiList,Emoji::toDto($row)); + } + }); + $uses = Emoji::getUseEmoji(); $temp = array_map(function ($val){ return $val['item_id']; },$uses); $data = array(); - foreach ($list as $val){ - if(in_array($val, $temp)){ + foreach ($emojiList as $val){ + if(in_array($val['item_id'], $temp)){ array_push($data, array( - 'item_id'=>$val, + 'item_id'=>$val['item_id'], 'state'=>1, + 'left_time'=>$val['left_time'], ) ); }else{ array_push($data, array( - 'item_id'=>$val, + 'item_id'=>$val['item_id'], 'state'=>0, + 'left_time'=>$val['left_time'], ) ); } @@ -49,7 +47,16 @@ class EmojiController extends BaseAuthedController public function setEmoji(){ $itemId = getReqVal('item_id', ''); $slotId = getReqVal('slot_id', 0); - if(! in_array($itemId,Emoji::emojiList())){ + $emojiList = array(); + Emoji::emojiList(function ($row) use (&$emojiList){ + $tDo = Emoji::toDto($row); + if ($tDo['left_time'] > 0){ + array_push($emojiList,Emoji::toDto($row)); + } + }); + if(! in_array($itemId,array_map(function ($val){ + return $val['item_id']; + },$emojiList))){ $this->_rspErr(1, 'item_id parameter error'); return; } @@ -65,17 +72,10 @@ class EmojiController extends BaseAuthedController $this->_rspErr(1, 'The emoji has been used'); return; } - if ($uses){ - foreach ($uses as &$val){ - if ($val['slot_id'] == $slotId){ - $val['item_id'] = $itemId; - } + foreach ($uses as &$val){ + if ($val['slot_id'] == $slotId){ + $val['item_id'] = $itemId; } - }else{ - array_push($uses,array( - 'item_id' => $itemId, - "slot_id" => $slotId - )); } Emoji::updateEmoji( json_encode($uses)); diff --git a/webapp/models/Emoji.php b/webapp/models/Emoji.php index c49c1dde..78561071 100644 --- a/webapp/models/Emoji.php +++ b/webapp/models/Emoji.php @@ -10,46 +10,53 @@ class Emoji extends BaseModel private static function defaultUseEmoji(){ return array( array( - 'item_id' => 200001, + 'item_id' => 0, "slot_id" => 1 ), array( - 'item_id' => 200002, + 'item_id' => 0, "slot_id" => 2 ), array( - 'item_id' => 200003, + 'item_id' => 0, "slot_id" => 3 ), array( - 'item_id' => 200004, + 'item_id' => 0, "slot_id" => 4 ), array( - 'item_id' => 200005, + 'item_id' => 0, "slot_id" => 5 ), array( - 'item_id' => 200006, + 'item_id' => 0, "slot_id" => 6 ), ); } - private static function defaultEmoji(){ - $default = array(); - $meta = mt\Parameter::getByName('emoji_default'); - if ($meta){ - $default = explode('|',$meta['param_value']) ; - } - return $default; + + + public static function emojiList($cb){ + SqlHelper::ormSelect( + myself()->_getSelfMysql(), + 't_emoji', + array( + 'account_id'=> myself()->_getAccountId(), + ), + function ($row) use($cb) { + $cb($row); + } + ); } - public static function emojiList(){ - $data = self::DefaultEmoji(); - //查询用户新获得的表情(t_emoji 表) - - return $data; + public static function toDto($row){ + return array( + 'item_id' => $row['item_id'], +// 'valid_time' => $row['valid_time'], + 'left_time' => max(0,$row['valid_time'] - (myself()->_getNowTime()-$row['last_get_time']) ), + ); } public static function getUseEmoji(){ @@ -62,9 +69,22 @@ class Emoji extends BaseModel ); if ($row){ $useEmojiList = emptyReplace(json_decode($row['used'], true), array()); + $isUpdate = 0; + foreach ($useEmojiList as &$value){ + $emojiDb = self::findEmoji($value['item_id']); + if ($emojiDb){ + $emojiDto = self::toDto($emojiDb); + if ($emojiDto['left_time'] == 0){ + $value['item_id'] = 0; + $isUpdate = 1; + } + } + } + if ($isUpdate){ + self::updateEmoji(json_encode($useEmojiList)); + } }else{ - $useEmojiList= self::defaultUseEmoji(); - self::updateEmoji(json_encode($useEmojiList)); + $useEmojiList = self::defaultUseEmoji(); } return $useEmojiList; } @@ -89,4 +109,48 @@ class Emoji extends BaseModel ); } + public static function findEmoji($itemId){ + return SqlHelper::ormSelectOne( + myself()->_getSelfMysql(), + 't_emoji', + array( + 'account_id'=> myself()->_getAccountId(), + 'item_id'=> $itemId, + ) + ); + } + + public static function addEmoji($itemMeta,$time){ + $row = self::findEmoji($itemMeta['id']); + if ($row){ + $leftTime = max(0,$row['valid_time'] - (myself()->_getNowTime()-$row['last_get_time']) ); + SqlHelper::update + (myself()->_getSelfMysql(), + 't_emoji', + array( + 'account_id' => myself()->_getAccountId(), + 'item_id' => $itemMeta['id'], + ), + array( + 'last_get_time' => myself()->_getNowTime(), + 'valid_time' => $leftTime + $time * 86400, + 'modifytime' => myself()->_getNowTime(), + ) + ); + }else{ + SqlHelper::insert + (myself()->_getSelfMysql(), + 't_emoji', + array( + 'account_id' => myself()->_getAccountId(), + 'item_id' => $itemMeta['id'], + 'last_get_time' => myself()->_getNowTime(), + 'valid_time' => $time * 86400, + 'createtime' => myself()->_getNowTime(), + 'modifytime' => myself()->_getNowTime(), + ) + ); + } + } + } \ No newline at end of file diff --git a/webapp/mt/Item.php b/webapp/mt/Item.php index 42bf5bb2..ee920c17 100644 --- a/webapp/mt/Item.php +++ b/webapp/mt/Item.php @@ -111,6 +111,7 @@ class Item { const TREASURE_BOX = 30; const GOLD_SYN = 31; const BATTLE_REWARD_BOX = 32; + const TIMING_PROP_TYPE = 33; const FUNC_RENAME_CARD_SUBTYPE = 1; const FUNC_GUILD_CARD_SUBTYPE = 3; diff --git a/webapp/services/TimingPropService.php b/webapp/services/TimingPropService.php new file mode 100644 index 00000000..c50bc503 --- /dev/null +++ b/webapp/services/TimingPropService.php @@ -0,0 +1,29 @@ +