186 lines
6.7 KiB
PHP
186 lines
6.7 KiB
PHP
<?php
|
|
|
|
require_once('mt/Parameter.php');
|
|
require_once('mt/Item.php');
|
|
|
|
class AdditemController extends BaseAuthedController {
|
|
|
|
public function additem()
|
|
{
|
|
if (SERVER_ENV == _ONLINE) {
|
|
$this->rspOk();
|
|
return;
|
|
}
|
|
$item_id = $_REQUEST['item_id'];
|
|
$item_num = $_REQUEST['item_num'];
|
|
$time = $_REQUEST['time'];
|
|
if ($_REQUEST['passwd'] != 'kingsome') {
|
|
return;
|
|
}
|
|
$it = mt\Item::getOldItem($item_id);
|
|
if (!$it) {
|
|
$this->rspErr(ERR_USER_BASE + 1, '没有这个道具');
|
|
return;
|
|
}
|
|
if ($it['type'] == 12) {
|
|
$usingId = emptyReplace($this->getUsingEquipId(), $item_id);
|
|
phpcommon\SqlHelper::upsert
|
|
($this->getSelfMysql(),
|
|
'equip',
|
|
array(
|
|
'accountid' => $this->getAccountId(),
|
|
'id' => $item_id,
|
|
),
|
|
array(
|
|
),
|
|
array(
|
|
'account_id' => $this->getAccountId(),
|
|
'id' => $item_id,
|
|
'active_time' => 0,
|
|
'create_time' => phpcommon\getNowTime(),
|
|
'modify_time' => phpcommon\getNowTime(),
|
|
'sub_time' => 0,
|
|
'using_id' => $usingId,
|
|
'lv' => 0,
|
|
'exp' => 0,
|
|
)
|
|
);
|
|
} else {
|
|
phpcommon\SqlHelper::upsert
|
|
($this->getSelfMysql(),
|
|
'bag',
|
|
array(
|
|
'accountid' => $this->getAccountId(),
|
|
'id' => $item_id,
|
|
),
|
|
array(
|
|
'active_time' => 0,
|
|
'status' => 1,
|
|
'num' => function () use($it, $item_num) {
|
|
if (in_array($it['type'], array(
|
|
10,
|
|
11,
|
|
23,
|
|
24
|
|
))) {
|
|
return "num + ${item_num}";
|
|
} else {
|
|
return 'num';
|
|
}
|
|
},
|
|
),
|
|
array(
|
|
'accountid' => $this->getAccountId(),
|
|
'id' => $item_id,
|
|
'status' => 1,
|
|
'active_time' => 0,
|
|
'num' => 1,
|
|
'create_time' => phpcommon\getNowTime(),
|
|
'modify_time' => phpcommon\getNowTime(),
|
|
)
|
|
);
|
|
}
|
|
$this->rspOk();
|
|
}
|
|
|
|
public function addDiamond()
|
|
{
|
|
if (SERVER_ENV == _ONLINE) {
|
|
$this->rspOk();
|
|
return;
|
|
}
|
|
$item_id = $_REQUEST['item_id'];
|
|
$item_num = $_REQUEST['item_num'];
|
|
$accountid = $_REQUEST['account_id'];
|
|
$time = $_REQUEST['time'];
|
|
if ($_REQUEST['passwd'] != 'kingsome') {
|
|
return;
|
|
}
|
|
$conn = $this->getMysql($accountid);
|
|
$row = $conn->execQueryOne('SELECT diamond_num FROM user WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $accountid
|
|
));
|
|
$ret = $conn->execScript('UPDATE user SET diamond_num=:diamond_num, modify_time=:modify_time ' .
|
|
' WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $accountid,
|
|
':diamond_num' => $item_num + $row['diamond_num'],
|
|
':modify_time' => phpcommon\getNowTime()
|
|
));
|
|
$this->rspOk();
|
|
}
|
|
|
|
//添加金币
|
|
public function addCoin()
|
|
{
|
|
$item_id = $_REQUEST['item_id'];
|
|
$item_num = $_REQUEST['item_num'];
|
|
$accountid = $_REQUEST['account_id'];
|
|
$time = $_REQUEST['time'];
|
|
// if (phpcommon\getIPv4() != '124.78.1.111') {
|
|
// return;
|
|
// }
|
|
if ($_REQUEST['passwd'] != 'kingsome') {
|
|
return;
|
|
}
|
|
$conn = $this->getMysql($accountid);
|
|
$row = $conn->execQueryOne('SELECT coin_num FROM user WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $accountid
|
|
));
|
|
$ret = $conn->execScript('UPDATE user SET coin_num=:coin_num, modify_time=:modify_time ' .
|
|
' WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $accountid,
|
|
':coin_num' => $item_num + $row['coin_num'],
|
|
':modify_time' => phpcommon\getNowTime()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
}
|
|
}
|
|
|
|
public function getCoin()
|
|
{
|
|
$accountid = $_REQUEST['account_id'];
|
|
$num = $_REQUEST['num'];
|
|
$conn = $this->getMysql($accountid);
|
|
$row = $conn->execQueryOne('SELECT rmb_num, coin_num FROM user WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $accountid
|
|
));
|
|
if (!$row) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
return;
|
|
}
|
|
|
|
if ($row['rmb_num'] < $num) {
|
|
phpcommon\sendError(ERR_USER_BASE + 2, '点券不足');
|
|
return;
|
|
}
|
|
|
|
$p = mt\Parameter::getOldParam(DIAMONDTOCOIN_NUM);
|
|
$estr = explode('|', $p['param_value']);
|
|
$addnum = floor($estr[1] / $estr[0] * $num);
|
|
$ret = $conn->execScript('UPDATE user SET coin_num=:coin_num, rmb_num=:rmb_num, modify_time=:modify_time ' .
|
|
' WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $accountid,
|
|
':coin_num' => $addnum + $row['coin_num'],
|
|
':rmb_num' => $row['rmb_num'] - $num,
|
|
':modify_time' => phpcommon\getNowTime()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
'coin_nums' => $addnum + $row['coin_num'],
|
|
'rmb_nums' => $row['rmb_num'] - $num
|
|
));
|
|
}
|
|
}
|