game2005api/webapp/controller/BagController.class.php
aozhiwei 01df0f6b56 1
2021-12-07 11:01:45 +08:00

128 lines
3.5 KiB
PHP

<?php
require_once('mt/Parameter.php');
require_once('mt/Item.php');
require_once('models/Bag.php');
require_once('services/AwardService.php');
require_once('services/PropertyChgService.php');
require_once('services/NameService.php');
use phpcommon\SqlHelper;
use models\Bag;
class BagController extends BaseAuthedController {
private $propertyChgService = null;
private $awardService = null;
public function _handlePre()
{
parent::_handlePre();
$this->propertyChgService = new services\PropertyChgService();
$this->awardService = new services\AwardService();
}
public function itemList()
{
$itemList = array();
SqlHelper::ormSelect(
$this->_getSelfMysql(),
't_bag',
array(
'account_id' => $this->_getAccountId()
),
function ($row) use(&$itemList) {
array_push($itemList, Bag::toDto($row));
}
);
$this->_rspData(array(
'item_list' => $itemList,
));
}
public function useItem()
{
$itemId = getReqVal('item_id', 0);
$itemNum = getReqVal('item_num', 0);
$param1 = getReqVal('param1', '');
$param2 = getReqVal('param2', '');
$param3 = getReqVal('param3', '');
if ($itemNum < 0) {
$this->_rspErr(1, 'item_num必须大于0');
return;
}
$itemDb = Bag::find($itemId);
if (isset($itemDb) || $itemDb['item_num'] <= 0) {
$this->_rspErr(1, '道具不足');
return;
}
$itemMeta = mt\Item::get($itemId);
if (!$itemMeta) {
$this->_rspErr(2, '配置表错误');
return;
}
if ($itemMeta['type'] != mt\Item::FUNC_TYPE) {
$this->_rspErr(3, '该道具为不可使用道具');
return;
}
switch ($itemMeta['sub_type']) {
case mt\Item::FUNC_RENAME_CARD_SUBTYPE:
{
$this->renameCard($itemDb, $itemMeta, $itemNum, $param1, $param2, $param3);
}
break;
default:
{
$this->_rspErr(4, '该道具功能暂未实现');
return;
}
break;
}
}
private function renameCard($itemDb, $itemMeta, $itemNum, $param1, $param2, $param3)
{
if (mb_strlen($param1) < 3) {
$this->_rspErr(5, '参数错误名字长度不得小于3');
return;
}
if (mb_strlen($param1) > 7) {
$this->_rspErr(5, '参数错误名字长度不得大于7');
return;
}
$nameService = new services\NameService();
if (!$nameService->verifyNameSign($param1, $param2)){
$this->_rspErr(5, '参数错误名,签名校验失败');
return;
}
if (!$nameService->nameUsed($param1)){
$this->_rspErr(6, '名字已被占用');
return;
}
$ret = $nameService->useName($param1);
if (!$ret) {
$this->_rspErr(10, '服务器内部错误');
return;
}
$this->_updateUserInfo(array(
'name' => $name
));
$this->_decItems(array(
array(
'item_id' => $itemMeta['id'],
'item_num' => 1
)
));
$this->propertyChgService->addUserChg();
$this->propertyChgService->addBagChg();
$this->_rspData(array(
'property_chg' => $this->propertyChgService->toDto(),
));
}
}