1
This commit is contained in:
parent
cec0178662
commit
9f53849c7d
@ -157,30 +157,6 @@ CREATE TABLE `t_gun` (
|
|||||||
) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
|
) ENGINE=InnoDB AUTO_INCREMENT=10000 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_chip`
|
|
||||||
--
|
|
||||||
|
|
||||||
DROP TABLE IF EXISTS `t_chip`;
|
|
||||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
|
||||||
/*!40101 SET character_set_client = utf8 */;
|
|
||||||
CREATE TABLE `t_chip` (
|
|
||||||
`idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id',
|
|
||||||
`account_id` varchar(60) CHARACTER SET utf8 NOT NULL COMMENT 'account_id',
|
|
||||||
`chip_id` int(11) NOT NULL DEFAULT '0' COMMENT '芯片id',
|
|
||||||
`state` int(11) NOT NULL DEFAULT '0' COMMENT '0:已购买 1:体验中',
|
|
||||||
`try_count` int(11) NOT NULL DEFAULT '0' COMMENT '剩余体验次数 当state=1时才有意义',
|
|
||||||
`lock_type` int(11) NOT NULL DEFAULT '0' COMMENT '0:无锁 1:升级 2:升阶',
|
|
||||||
`unlock_time` int(11) NOT NULL DEFAULT '0' COMMENT '解锁时间',
|
|
||||||
`unlock_trade_time` int(11) NOT NULL DEFAULT '0' COMMENT '出售解锁时间',
|
|
||||||
`rand_attr` mediumblob COMMENT '随机属性',
|
|
||||||
`createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
|
|
||||||
`modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
|
|
||||||
PRIMARY KEY (`idx`),
|
|
||||||
KEY `account_id` (`account_id`)
|
|
||||||
) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
|
|
||||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Table structure for table `t_gun_skin`
|
-- Table structure for table `t_gun_skin`
|
||||||
--
|
--
|
||||||
|
@ -83,4 +83,204 @@ class GunController extends BaseAuthedController {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function gunList()
|
||||||
|
{
|
||||||
|
$gunList = array();
|
||||||
|
SqlHelper::ormSelect(
|
||||||
|
$this->_getSelfMysql(),
|
||||||
|
't_gun',
|
||||||
|
array(
|
||||||
|
'account_id' => $this->_getAccountId()
|
||||||
|
),
|
||||||
|
function ($row) use(&$gunList) {
|
||||||
|
array_push($gunList, Gun::toDto($row));
|
||||||
|
}
|
||||||
|
);
|
||||||
|
$this->_rspData(array(
|
||||||
|
'gun_list' => $gunList
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function upgradeLevel()
|
||||||
|
{
|
||||||
|
$costItemId = getReqVal('cost_item_id', 0);
|
||||||
|
$heroUniId = getReqVal('hero_uniid', 0);
|
||||||
|
$heroDb = Hero::find($heroUniId);
|
||||||
|
if (!$heroDb) {
|
||||||
|
$this->_rspErr(1, '英雄不存在');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ($heroDb['state'] != Hero::GETED_STATE) {
|
||||||
|
$this->_rspErr(3, '试用英雄不能操作');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ($heroDb['unlock_time'] > $this->_getNowTime()) {
|
||||||
|
$this->_rspErr(2, '锁定期间不能操作');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ($heroDb['unlock_trade_time'] > $this->_getNowTime()) {
|
||||||
|
$this->_rspErr(2, '锁定期间不能操作');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$currLevelMeta = mt\HeroLevel::getByQualityLevel($heroDb['quality'], $heroDb['hero_lv']);
|
||||||
|
if (!$currLevelMeta) {
|
||||||
|
$this->_rspErr(100, '服务器内部错误');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$nextLevelMeta = mt\HeroLevel::getByQualityLevel($heroDb['quality'], $heroDb['hero_lv'] + 1);
|
||||||
|
if (!$nextLevelMeta) {
|
||||||
|
$this->_rspErr(5, '已满级');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$costItems = array();
|
||||||
|
switch ($costItemId) {
|
||||||
|
case V_ITEM_GOLD:
|
||||||
|
{
|
||||||
|
$costItems = array(
|
||||||
|
array(
|
||||||
|
'item_id' => $costItemId,
|
||||||
|
'item_num' => $currLevelMeta['gold']
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Break;
|
||||||
|
case V_ITEM_DIAMOND:
|
||||||
|
{
|
||||||
|
$costItems = array(
|
||||||
|
array(
|
||||||
|
'item_id' => $costItemId,
|
||||||
|
'item_num' => $currLevelMeta['diamond']
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
$this->_rspErr(2, '支付方式不支持');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$lackItem = null;
|
||||||
|
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
||||||
|
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$attrs = emptyReplace(json_decode($heroDb['rand_attr'], true), array());
|
||||||
|
$ret = mt\HeroLevel::addRandAttr($nextLevelMeta, $attrs);
|
||||||
|
if (!$ret) {
|
||||||
|
$this->_rspErr(2, '服务器内部错误');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$this->_decItems($costItems);
|
||||||
|
Hero::update($heroUniId,
|
||||||
|
array(
|
||||||
|
'hero_lv' => $heroDb['hero_lv'] + 1,
|
||||||
|
'rand_attr' => json_encode($attrs)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$propertyChgService = new services\PropertyChgService();
|
||||||
|
$propertyChgService->addGunChg();
|
||||||
|
$this->_rspData(array(
|
||||||
|
'property_chg' => $propertyChgService->toDto(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function upgradeQuality()
|
||||||
|
{
|
||||||
|
$costItemId = getReqVal('cost_item_id', 0);
|
||||||
|
$heroUniId = getReqVal('hero_uniid', 0);
|
||||||
|
$heroDb = Hero::find($heroUniId);
|
||||||
|
if (!$heroDb) {
|
||||||
|
$this->_rspErr(1, '英雄不存在');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ($heroDb['state'] != Hero::GETED_STATE) {
|
||||||
|
$this->_rspErr(3, '试用英雄不能操作');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ($heroDb['unlock_time'] > $this->_getNowTime()) {
|
||||||
|
$this->_rspErr(2, '锁定期间不能操作');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ($heroDb['unlock_trade_time'] > $this->_getNowTime()) {
|
||||||
|
$this->_rspErr(2, '锁定期间不能操作');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$currQualityMeta = mt\HeroQuality::getByQuality($heroDb['quality']);
|
||||||
|
if (!$currQualityMeta) {
|
||||||
|
$this->_rspErr(100, '服务器内部错误');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$nextQualityMeta = mt\HeroQuality::getByQuality($heroDb['quality'] + 1);
|
||||||
|
if (!$nextQualityMeta) {
|
||||||
|
$this->_rspErr(5, '已满级1');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$nextLevelMeta = mt\HeroLevel::getByQualityLevel($heroDb['quality'] + 1, $heroDb['hero_lv']);
|
||||||
|
if (!$nextLevelMeta) {
|
||||||
|
$this->_rspErr(5, '已满级2');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$costItems = array();
|
||||||
|
switch ($costItemId) {
|
||||||
|
case V_ITEM_GOLD:
|
||||||
|
{
|
||||||
|
$costItems = array(
|
||||||
|
array(
|
||||||
|
'item_id' => $costItemId,
|
||||||
|
'item_num' => $currQualityMeta['gold']
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case V_ITEM_DIAMOND:
|
||||||
|
{
|
||||||
|
$costItems = array(
|
||||||
|
array(
|
||||||
|
'item_id' => $costItemId,
|
||||||
|
'item_num' => $currQualityMeta['diamond']
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
$this->_rspErr(2, '支付方式不支持');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$lackItem = null;
|
||||||
|
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
||||||
|
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$attrs = emptyReplace(json_decode($heroDb['rand_attr'], true), array());
|
||||||
|
{
|
||||||
|
$obtainAttrs = mt\HeroQuality::getRandAttr($nextQualityMeta);
|
||||||
|
mt\AttrHelper::mergeAttr($attrs, $obtainAttrs);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
$ret = mt\HeroLevel::addRandAttr($nextLevelMeta, $attrs);
|
||||||
|
if (!$ret) {
|
||||||
|
$this->_rspErr(2, '服务器内部错误');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->_decItems($costItems);
|
||||||
|
Hero::update($heroUniId,
|
||||||
|
array(
|
||||||
|
'hero_lv' => $heroDb['hero_lv'],
|
||||||
|
'quality' => $heroDb['quality'] + 1,
|
||||||
|
'rand_attr' => json_encode($attrs)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$propertyChgService = new services\PropertyChgService();
|
||||||
|
$propertyChgService->addGunChg();
|
||||||
|
$this->_rspData(array(
|
||||||
|
'property_chg' => $propertyChgService->toDto(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
122
webapp/models/Gun.php
Normal file
122
webapp/models/Gun.php
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace models;
|
||||||
|
|
||||||
|
require_once('mt/Item.php');
|
||||||
|
require_once('mt/GunQuality.php');
|
||||||
|
|
||||||
|
use mt;
|
||||||
|
use phpcommon\SqlHelper;
|
||||||
|
|
||||||
|
class Gun extends BaseModel {
|
||||||
|
|
||||||
|
public static function find($itemId)
|
||||||
|
{
|
||||||
|
$row = SqlHelper::ormSelectOne(
|
||||||
|
myself()->_getSelfMysql(),
|
||||||
|
't_gun',
|
||||||
|
array(
|
||||||
|
'account_id' => myself()->_getAccountId(),
|
||||||
|
'gun_id' => $itemId,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function toDto($row)
|
||||||
|
{
|
||||||
|
$attr = emptyReplace(json_decode($row['rand_attr'], true), array());
|
||||||
|
return array(
|
||||||
|
'gun_uniid' => $row['idx'],
|
||||||
|
'gun_id' => $row['gun_id'],
|
||||||
|
'state' => $row['state'],
|
||||||
|
'gun_lv' => $row['gun_lv'],
|
||||||
|
'quality' => $row['quality'],
|
||||||
|
'try_count' => $row['try_count'],
|
||||||
|
'lock_type' => $lockType,
|
||||||
|
'lock_time' => $lockTime,
|
||||||
|
'trade_locktime' => $tradeLocktime,
|
||||||
|
'attr' => $attr,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function all()
|
||||||
|
{
|
||||||
|
$itemList = array();
|
||||||
|
SqlHelper::ormSelect(
|
||||||
|
myself()->_getSelfMysql(),
|
||||||
|
't_bag',
|
||||||
|
array(
|
||||||
|
'account_id' => myself()->_getAccountId()
|
||||||
|
),
|
||||||
|
function ($row) use(&$itemList) {
|
||||||
|
if ($row['item_num'] > 0) {
|
||||||
|
array_push($itemList, Bag::toDto($row));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return $itemList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getItemCount($itemId)
|
||||||
|
{
|
||||||
|
$itemDb = self::find($itemId);
|
||||||
|
return $itemDb ? $itemDb['item_num'] : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function addItem($itemId, $itemNum)
|
||||||
|
{
|
||||||
|
if (myself()->_isVirtualItem($itemId)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ($itemNum <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$itemMeta = mt\Item::get($itemId);
|
||||||
|
if (!$itemMeta) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ($itemMeta['cannot_stack']) {
|
||||||
|
$randAttr = array();
|
||||||
|
if (mt\Item::isRandAttrItem($itemMeta)) {
|
||||||
|
$qualityMeta = mt\ChipQuality::getByQuality($itemMeta['quality']);
|
||||||
|
if ($qualityMeta) {
|
||||||
|
$randAttr = mt\ChipQuality::getRandAttr($qualityMeta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SqlHelper::insert
|
||||||
|
(myself()->_getSelfMysql(),
|
||||||
|
't_bag',
|
||||||
|
array(
|
||||||
|
'account_id' => myself()->_getAccountId(),
|
||||||
|
'item_id' => $itemId,
|
||||||
|
'item_num' => 1,
|
||||||
|
'rand_attr' => json_encode($randAttr),
|
||||||
|
'createtime' => myself()->_getNowTime(),
|
||||||
|
'modifytime' => myself()->_getNowTime()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
SqlHelper::upsert
|
||||||
|
(myself()->_getSelfMysql(),
|
||||||
|
't_bag',
|
||||||
|
array(
|
||||||
|
'account_id' => myself()->_getAccountId(),
|
||||||
|
'item_id' => $itemId
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'item_num' => function () use($itemNum) { return "item_num + {$itemNum}";},
|
||||||
|
'modifytime' => myself()->_getNowTime(),
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'account_id' => myself()->_getAccountId(),
|
||||||
|
'item_id' => $itemId,
|
||||||
|
'item_num' => $itemNum,
|
||||||
|
'createtime' => myself()->_getNowTime(),
|
||||||
|
'modifytime' => myself()->_getNowTime()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -36,6 +36,11 @@ class PropertyChgService extends BaseService {
|
|||||||
$this->internalAddChg('bag');
|
$this->internalAddChg('bag');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function addGunChg()
|
||||||
|
{
|
||||||
|
$this->internalAddChg('gun');
|
||||||
|
}
|
||||||
|
|
||||||
public function toDto()
|
public function toDto()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user