表情设置

This commit is contained in:
hujiabin 2023-02-13 14:22:45 +08:00
parent e05583a87d
commit 910fbcffec
8 changed files with 273 additions and 1 deletions

44
doc/Emoji.py Normal file
View File

@ -0,0 +1,44 @@
import _common
class Emoji(object):
def __init__(self):
self.apis = [
{
'name': 'getEmojiList',
'desc': '表情列表',
'group': 'Emoji',
'url': 'webapp/index.php?c=Emoji&a=getEmojiList',
'params': [
_common.ReqHead(),
],
'response': [
_common.RspHead(),
['!data', [_common.Emoji()], '表情列表']
]
},{
'name': 'setEmoji',
'desc': '设置表情',
'group': 'Emoji',
'url': 'webapp/index.php?c=Emoji&a=setEmoji',
'params': [
_common.ReqHead(),
['item_id', '0', 'item_id'],
],
'response': [
_common.RspHead(),
]
},{
'name': 'cancel',
'desc': '取消设置',
'group': 'Emoji',
'url': 'webapp/index.php?c=Emoji&a=cancel',
'params': [
_common.ReqHead(),
['item_id', '0', 'item_id'],
],
'response': [
_common.RspHead(),
]
},
]

View File

@ -78,6 +78,7 @@ class User(object):
['guild_job', 0, '跟新工会职位(可选参数,不传就不更新)'],
['guild_name', 0, '跟新工会名称(可选参数,不传就不更新)'],
['parachute', 0, '跟新降落伞(可选参数,不传就不更新)'],
['ring_id', 0, '跟新戒指(可选参数,不传就不更新)'],
],
'response': [
_common.RspHead(),

View File

@ -1017,4 +1017,12 @@ class Currency(object):
['symbol', '', '符号'],
['precision', 0, '精度'],
['type', 0, '1:ERC721 2:ERC1155 3:ERC20'],
]
class Emoji(object):
def __init__(self):
self.fields = [
['item_id', 0, 'item_id'],
['state', 0, '1:使用 0未使用'],
]

View File

@ -920,4 +920,40 @@ CREATE TABLE `t_user_currency` (
PRIMARY KEY (`idx`),
UNIQUE KEY `account_net_address` (`account_id`, `net_id`, `address`)
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `t_emoji`
--
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',
`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;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `t_user_use_emoji`
--
DROP TABLE IF EXISTS `t_user_use_emoji`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `t_user_use_emoji` (
`idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id',
`account_id` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id',
`value` varchar(255) NOT NULL DEFAULT '' COMMENT '选中表情itemID',
`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 */;

View File

@ -0,0 +1,76 @@
<?php
require_once('models/Emoji.php');
use models\Emoji;
class EmojiController extends BaseAuthedController
{
public function getEmojiList(){
$list = Emoji::emojiList();
$uses = Emoji::getUseEmoji();
$data = array();
foreach ($list as $val){
if(in_array($val,$uses)){
array_push($data,
array(
'item_id'=>$val,
'state'=>1,
)
);
}else{
array_push($data,
array(
'item_id'=>$val,
'state'=>0,
)
);
}
}
$this->_rspData(array(
'data' => $data
));
}
public function setEmoji(){
$itemId = getReqVal('item_id', '');
if(! in_array($itemId,Emoji::emojiList())){
$this->_rspErr(1, 'item_id parameter error');
return;
}
$uses = Emoji::getUseEmoji();
if(in_array($itemId,$uses)){
$this->_rspErr(1, 'The emoji has been used');
return;
}
if(count($uses) >= 6){
$this->_rspErr(1, 'To maximize');
return;
}
array_push($uses,$itemId);
Emoji::updateEmoji(array(
'value' => implode('|',$uses)
));
$this->_rspOk();
}
public function cancel(){
$itemId = getReqVal('item_id', '');
if(! in_array($itemId,Emoji::emojiList())){
$this->_rspErr(1, 'item_id parameter error');
return;
}
$uses = Emoji::getUseEmoji();
if(! in_array($itemId,$uses)){
$this->_rspErr(1, 'The emoji is not used');
return;
}
foreach ($uses as $k=>$v){
if ($itemId == $v){
unset($uses[$k]);
}
}
Emoji::updateEmoji(array(
'value' => implode('|',$uses)
));
$this->_rspOk();
}
}

52
webapp/models/Emoji.php Normal file
View File

@ -0,0 +1,52 @@
<?php
namespace models;
use mt;
use phpcommon\SqlHelper;
class Emoji extends BaseModel
{
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(){
$data = self::DefaultEmoji();
//查询用户新获得的表情t_emoji 表)
return $data;
}
public static function getUseEmoji(){
$row = SqlHelper::ormSelectOne(
myself()->_getSelfMysql(),
't_user_use_emoji',
array(
'account_id'=> myself()->_getAccountId()
)
);
$value = array();
if ($row && $row['value']){
$value = explode('|',$row['value']) ;
}
return $value;
}
public static function updateEmoji($fieldsKv){
SqlHelper::update
(myself()->_getSelfMysql(),
't_user_use_emoji',
array(
'account_id' => myself()->_getAccountId(),
),
$fieldsKv
);
}
}

View File

@ -6,5 +6,32 @@ namespace mt;
class LevelUp
{
public static function getExpByLv(&$lv,&$exp){
$meta = self::getMetaList();
if ($exp > 0){
for ($i=1;$i<=count($meta);$i++){
if ($exp > $meta[count($meta)]['total_exp']){
$exp = min($exp, $meta[count($meta)]['total_exp']);
$lv = $meta[count($meta)]['id'];
}else{
if ($exp >= $meta[$i]['total_exp'] &&
$exp < $meta[$i+1]['total_exp'])
{
$lv = $meta[$i]['id'];
}
}
}
}
}
protected static function getMetaList()
{
if (!self::$metaList) {
self::$metaList = getMetaTable('levelup@levelup.php');
}
return self::$metaList;
}
protected static $metaList;
}

View File

@ -15,6 +15,7 @@ require_once('mt/AttrHelper.php');
require_once('mt/PveGemini.php');
require_once('mt/PveGeminiMode.php');
require_once('mt/RankSeason.php');
require_once('mt/LevelUp.php');
require_once('models/Season.php');
require_once('models/Battle.php');
@ -90,7 +91,8 @@ class BattleDataService extends BaseService {
'curr_ceg' => 0,
),
'total_ceg' => 0,
'items' => array()
'items' => array(),
'lvInfo' => array()
);
private $rankActivityService = null;
private $pveGeminiMeta = null;
@ -191,6 +193,32 @@ class BattleDataService extends BaseService {
}
public function rewardExpPvp(){
$expNum = 222;
if ($expNum>0){
array_push($this->reward['items'],
array(
'item_id' => V_ITEM_EXP,
'item_num' => $expNum
));
$userInfo = myself()->_getOrmUserInfo();
$newExp = $userInfo['exp']+$expNum;
$newLv = $userInfo['level'];
mt\LevelUp::getExpByLv($newLv,$newExp);
$this->reward['lvInfo'] = array(
'oldLv' => $userInfo['level'],
'newLv' => $newLv
);
if ( $newExp != $userInfo['exp'] ) {
myself()->_updateUserInfo(array(
'level' => $newLv,
'exp' => $newExp,
));
}
}
}
private function saveBattleHistory(){
$user = myself()->_getOrmUserInfo();
$newRank = $user['rank'];