From f8cafa49fd138ef7eb2e0887cb1747371fa5684b Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 31 Mar 2022 08:05:05 +0800 Subject: [PATCH] 1 --- webapp/models/Bag.php | 64 +++++++++++++++++++++++++++++-------- webapp/models/Gun.php | 67 ++++++++++++++++++++++++++++++--------- webapp/models/Hero.php | 71 ++++++++++++++++++++++++++++++++---------- 3 files changed, 159 insertions(+), 43 deletions(-) diff --git a/webapp/models/Bag.php b/webapp/models/Bag.php index 06c10dba..9b209990 100644 --- a/webapp/models/Bag.php +++ b/webapp/models/Bag.php @@ -86,6 +86,19 @@ class Bag extends BaseModel { 'token_id' => $nftDb['token_id'], ) ); + if (!$row) { + $itemMeta = mt\Item::get($nftDb['item_id']); + if ($itemMeta) { + self::addNftItem($nftDb['item_id'], $nftDb['token_id']); + $row = SqlHelper::ormSelectOne( + myself()->_getSelfMysql(), + 't_bag', + array( + 'token_id' => $nftDb['token_id'], + ) + ); + } + } if ($row) { $cb($row); } @@ -110,6 +123,24 @@ class Bag extends BaseModel { } public static function addItem($itemId, $itemNum) + { + return self::internalAddItem( + myself()->_getSelfMysql(), + $gunMeta, + myself()->_getAccountId(), + null); + } + + public static function addNftItem($itemId, $tokenId) + { + return self::internalAddItem( + myself()->_getMysql($tokenId), + $itemId, + null, + $tokenId); + } + + public static function internalAddItem($conn, $itemId, $itemNum, $accountId, $tokenId) { if (myself()->_isVirtualItem($itemId)) { return; @@ -129,24 +160,31 @@ class Bag extends BaseModel { $randAttr = mt\ChipQuality::getRandAttr($qualityMeta); } } + $fieldsKv = array( + 'item_id' => $itemId, + 'item_num' => 1, + 'rand_attr' => json_encode($randAttr), + 'createtime' => myself()->_getNowTime(), + 'modifytime' => myself()->_getNowTime() + ); + if ($accountId) { + $fieldsKv['account_id'] = $accountId; + } + if ($tokenId) { + $fieldsKv['token_id'] = $tokenId; + } + SqlHelper::insert - (myself()->_getSelfMysql(), + ($conn, 't_bag', - array( - 'account_id' => myself()->_getAccountId(), - 'item_id' => $itemId, - 'item_num' => 1, - 'rand_attr' => json_encode($randAttr), - 'createtime' => myself()->_getNowTime(), - 'modifytime' => myself()->_getNowTime() - ) + $fieldsKv ); - } else { + } else if ($accountId){ SqlHelper::upsert - (myself()->_getSelfMysql(), + ($conn, 't_bag', array( - 'account_id' => myself()->_getAccountId(), + 'account_id' => $accountId, 'item_id' => $itemId ), array( @@ -154,7 +192,7 @@ class Bag extends BaseModel { 'modifytime' => myself()->_getNowTime(), ), array( - 'account_id' => myself()->_getAccountId(), + 'account_id' => $accountId, 'item_id' => $itemId, 'item_num' => $itemNum, 'createtime' => myself()->_getNowTime(), diff --git a/webapp/models/Gun.php b/webapp/models/Gun.php index 28bfa273..2902359e 100644 --- a/webapp/models/Gun.php +++ b/webapp/models/Gun.php @@ -4,6 +4,7 @@ namespace models; require_once('mt/GunLevel.php'); require_once('mt/GunQuality.php'); +require_once('mt/Item.php'); require_once('models/GunSkin.php'); require_once('services/NftService.php'); @@ -70,6 +71,19 @@ class Gun extends BaseModel { 'token_id' => $nftDb['token_id'], ) ); + if (!$row) { + $itemMeta = mt\Item::get($nftDb['item_id']); + if ($itemMeta) { + self::addNftGun($itemMeta, $nftDb['token_id']); + $row = SqlHelper::ormSelectOne( + myself()->_getSelfMysql(), + 't_gun', + array( + 'token_id' => $nftDb['token_id'], + ) + ); + } + } if ($row) { $cb($row); } @@ -106,6 +120,24 @@ class Gun extends BaseModel { } public static function addGun($gunMeta) + { + return self::internalAddGun( + myself()->_getSelfMysql(), + $gunMeta, + myself()->_getAccountId(), + null); + } + + public static function addNftGun($gunMeta, $tokenId) + { + return self::internalAddGun( + myself()->_getMysql($tokenId), + $gunMeta, + null, + $tokenId); + } + + private static function internalAddGun($conn, $gunMeta, $accountId, $tokenId) { $randAttr = array(); { @@ -114,22 +146,29 @@ class Gun extends BaseModel { $randAttr = mt\GunQuality::getRandAttr($initQualityMeta); } } + $fieldsKv = array( + 'gun_id' => $gunMeta['id'], + 'gun_lv' => 1, + 'quality' => 1, + 'state' => self::GETED_STATE, + 'rand_attr' => json_encode($randAttr), + 'lock_type' => self::NO_LOCK, + 'unlock_time' => 0, + 'unlock_trade_time' => 0, + 'createtime' => myself()->_getNowTime(), + 'modifytime' => myself()->_getNowTime() + ); + if (!$accountId) { + $fieldsKv['account_id'] = $accountId; + } + if ($tokenId) { + $fieldsKv['token_id'] = $tokenId; + } + SqlHelper::insert( - myself()->_getSelfMysql(), + $conn, 't_gun', - array( - 'account_id' => myself()->_getAccountId(), - 'gun_id' => $gunMeta['id'], - 'gun_lv' => 1, - 'quality' => 1, - 'state' => self::GETED_STATE, - 'rand_attr' => json_encode($randAttr), - 'lock_type' => self::NO_LOCK, - 'unlock_time' => 0, - 'unlock_trade_time' => 0, - 'createtime' => myself()->_getNowTime(), - 'modifytime' => myself()->_getNowTime() - ) + $fieldsKv ); } diff --git a/webapp/models/Hero.php b/webapp/models/Hero.php index 888c550f..8a3df965 100644 --- a/webapp/models/Hero.php +++ b/webapp/models/Hero.php @@ -6,6 +6,7 @@ require_once('mt/Hero.php'); require_once('mt/HeroLevel.php'); require_once('mt/HeroQuality.php'); require_once('mt/AttrHelper.php'); +require_once('mt/Item.php'); require_once('models/HeroSkin.php'); require_once('services/NftService.php'); @@ -72,6 +73,19 @@ class Hero extends BaseModel { 'token_id' => $nftDb['token_id'], ) ); + if (!$row) { + $itemMeta = mt\Item::get($nftDb['item_id']); + if ($itemMeta) { + self::addNftHero($itemMeta, $nftDb['token_id']); + $row = SqlHelper::ormSelectOne( + myself()->_getSelfMysql(), + 't_hero', + array( + 'token_id' => $nftDb['token_id'], + ) + ); + } + } if ($row) { $cb($row); } @@ -113,6 +127,24 @@ class Hero extends BaseModel { } public static function addHero($heroMeta) + { + return self::internalAddHero( + myself()->_getSelfMysql(), + $gunMeta, + myself()->_getAccountId(), + null); + } + + public static function addNftHero($heroMeta, $tokenId) + { + return self::internalAddHero( + myself()->_getMysql($tokenId), + $gunMeta, + null, + $tokenId); + } + + public static function internalAddHero($conn, $heroMeta, $accountId, $tokenId) { $realHeroMeta = mt\Hero::get($heroMeta['id']); $randAttr = array(); @@ -122,25 +154,32 @@ class Hero extends BaseModel { $randAttr = mt\HeroQuality::getRandAttr($initQualityMeta); } } + $fieldKv = array( + 'hero_id' => $heroMeta['id'], + 'hero_lv' => 1, + 'quality' => 1, + 'hero_tili' => $realHeroMeta ? $realHeroMeta['tili'] : 0, + 'state' => self::GETED_STATE, + 'skill_lv1' => 1, + 'skill_lv2' => 1, + 'rand_attr' => json_encode($randAttr), + 'lock_type' => self::NO_LOCK, + 'unlock_time' => 0, + 'unlock_trade_time' => 0, + 'createtime' => myself()->_getNowTime(), + 'modifytime' => myself()->_getNowTime() + ); + if ($accountId) { + $fieldsKv['account_id'] = $accountId; + } + if ($tokenId) { + $fieldKv['token_id'] = $tokenId; + } + SqlHelper::insert( myself()->_getSelfMysql(), 't_hero', - array( - 'account_id' => myself()->_getAccountId(), - 'hero_id' => $heroMeta['id'], - 'hero_lv' => 1, - 'quality' => 1, - 'hero_tili' => $realHeroMeta ? $realHeroMeta['tili'] : 0, - 'state' => self::GETED_STATE, - 'skill_lv1' => 1, - 'skill_lv2' => 1, - 'rand_attr' => json_encode($randAttr), - 'lock_type' => self::NO_LOCK, - 'unlock_time' => 0, - 'unlock_trade_time' => 0, - 'createtime' => myself()->_getNowTime(), - 'modifytime' => myself()->_getNowTime() - ) + $fieldKv ); }