835 lines
28 KiB
PHP
835 lines
28 KiB
PHP
<?php
|
|
|
|
namespace classes;
|
|
|
|
use phpcommon;
|
|
|
|
class AddReward
|
|
{
|
|
protected function getMysql($account_id)
|
|
{
|
|
$mysql_conf = getMysqlConfig(crc32($account_id));
|
|
$conn = new phpcommon\Mysql(array(
|
|
'host' => $mysql_conf['host'],
|
|
'port' => $mysql_conf['port'],
|
|
'user' => $mysql_conf['user'],
|
|
'passwd' => $mysql_conf['passwd'],
|
|
'dbname' => DBNAME_PREFIX . $mysql_conf['instance_id']
|
|
));
|
|
return $conn;
|
|
}
|
|
|
|
protected function getItem($item_id)
|
|
{
|
|
$g_conf_item_cluster = require('../res/item@item.php');
|
|
$item_conf = getItemConfig($g_conf_item_cluster, $item_id);
|
|
$it = array(
|
|
'id' => $item_conf['id'],
|
|
'diamond' => $item_conf['diamond'],
|
|
'type' => $item_conf['fuction'],
|
|
'diamond_hour' => $item_conf['diamond_hour'],
|
|
'piece' => $item_conf['piece'],
|
|
);
|
|
return $it;
|
|
}
|
|
|
|
protected function getBag($bag_id)
|
|
{
|
|
$g_conf_bag_cluster = require('../res/bag@bag.php');
|
|
$bag_conf = getBagConfig($g_conf_bag_cluster, $bag_id);
|
|
$b = array(
|
|
'id' => $bag_conf['id'],
|
|
'name' => $bag_conf['name'],
|
|
'fuction' => $bag_conf['fuction'],
|
|
);
|
|
return $b;
|
|
}
|
|
|
|
protected function getExplode($string)
|
|
{
|
|
$delim = "|";
|
|
$drop_multiply = explode($delim, $string);
|
|
$delim1 = ":";
|
|
$arr = array();
|
|
for ($i = 0; $i < count($drop_multiply); $i++) {
|
|
$mul = explode($delim1, $drop_multiply[$i]);
|
|
array_push($arr, $mul);
|
|
}
|
|
return $arr;
|
|
}
|
|
|
|
protected function getEquip($equip_id)
|
|
{
|
|
$g_conf_equip_cluster = require('../res/equip@equip.php');
|
|
$equip_conf = getEquipConfig($g_conf_equip_cluster, $equip_id);
|
|
if (!$equip_conf) {
|
|
return null;
|
|
}
|
|
$e = array(
|
|
'id' => $equip_conf['id'],
|
|
'equip_material' => $equip_conf['equip_material'],
|
|
'real_index_id' => $equip_conf['real_index_id'],
|
|
);
|
|
return $e;
|
|
}
|
|
|
|
public function addReward($item_id, $item_num, $account_id, $time, $t)
|
|
{
|
|
$conn = $this->getMysql($account_id);
|
|
if (!$conn) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
die();
|
|
}
|
|
$it = $this->getItem($item_id);
|
|
if (!$it) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个道具');
|
|
die();
|
|
}
|
|
$item_list = array();
|
|
array_push($item_list, array(
|
|
'item_id' => $item_id,
|
|
'item_num' => $item_num,
|
|
'time' => $time
|
|
));
|
|
|
|
foreach ($item_list as $item) {
|
|
$i = $this->getItem($item['item_id']);
|
|
if ($i['type'] == 1) {
|
|
$this->addCoin($item['item_id'], $item['item_num'], $account_id);
|
|
} else if ($i['type'] == 2) {
|
|
$this->addDiamond($item['item_id'], $item['item_num'], $account_id);
|
|
} else if ($i['type'] == 8) {
|
|
$this->addticket($item['item_id'], $item['item_num'], $account_id);
|
|
} else if ($i['type'] == 9) {
|
|
$this->addtenticket($item['item_id'], $item['item_num'], $account_id);
|
|
} else if ($i['type'] == 10 || $i['type'] == 11) {
|
|
$this->addweizhuang($item['item_id'], $item['item_num'], $account_id);
|
|
} else if ($i['type'] == 12) {
|
|
$item_list = $this->addEquip($item['item_id'], $account_id, $i['piece']);
|
|
} else if ($i['type'] == 16 || $i['type'] == 19 ) {
|
|
$this->addSpoilsItem($item['item_id'], $item['item_num'], $account_id);
|
|
} else if ($i['type'] == 17) {
|
|
$this->addAdfree($item['item_id'], $item['item_num'], $account_id);
|
|
} else if ($i['type'] == 18) {
|
|
$this->addMedal($item['item_id'], $item['item_num'], $account_id);
|
|
} else if ($i['type'] == 20) {
|
|
|
|
} else {
|
|
$priceid = 10003;
|
|
$price = $i['diamond'];
|
|
if ($time != 0) {
|
|
$price = $i['diamond_hour'] * $time;
|
|
}
|
|
|
|
if ($price == 0) {
|
|
$strs = explode(":",$i['piece']);
|
|
if (count($strs) > 1) {
|
|
$priceid = intval($strs[0]);
|
|
$price = intval($strs[1]);
|
|
}
|
|
}
|
|
|
|
if ($t) {
|
|
$item_list = $this->addItem($item['item_id'], $item['time'], $account_id, $priceid, $price, $t);
|
|
} else {
|
|
$item_list = $this->addItem($item['item_id'], $item['time'], $account_id, $priceid, $price, 0);
|
|
}
|
|
}
|
|
}
|
|
return $item_list;
|
|
}
|
|
|
|
public function addSpoilsItem($id, $num, $accountid)
|
|
{
|
|
$conn = $this->getMysql($accountid);
|
|
if (!$conn) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
die();
|
|
}
|
|
$row = $conn->execQueryOne(
|
|
'SELECT num FROM bag WHERE accountid=:accountid AND id=:id;',
|
|
array(
|
|
':accountid' => $accountid,
|
|
':id' => $id
|
|
)
|
|
);
|
|
if (!$row && $id != 0) {
|
|
$ret = $conn->execScript(
|
|
'INSERT INTO bag(accountid, id, color_id, status, num, active_time, create_time, modify_time) ' .
|
|
' VALUES(:account_id, :id, 0, 1, :num, 0, :create_time, :modify_time) ' .
|
|
' ON DUPLICATE KEY UPDATE accountid=:account_id, id=:id, color_id=0, status=1, num=:num, active_time=0, modify_time=:modify_time;',
|
|
array(
|
|
':account_id' => $accountid,
|
|
':id' => $id,
|
|
':num' => $num,
|
|
':create_time' => time(),
|
|
':modify_time' => time()
|
|
)
|
|
);
|
|
if (!$ret) {
|
|
die();
|
|
}
|
|
} else {
|
|
$ret = $conn->execScript(
|
|
'UPDATE bag SET num=:num, modify_time=:modify_time ' .
|
|
' WHERE accountid=:account_id AND id=:id;',
|
|
array(
|
|
':account_id' => $accountid,
|
|
':id' => $id,
|
|
':num' => $row['num'] + $num,
|
|
':modify_time' => time()
|
|
)
|
|
);
|
|
if (!$ret) {
|
|
die();
|
|
}
|
|
}
|
|
}
|
|
|
|
public function getCoinNum($accountid)
|
|
{
|
|
$conn = $this->getMysql($accountid);
|
|
if (!$conn) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
die();
|
|
}
|
|
$row = $conn->execQueryOne(
|
|
'SELECT coin_num FROM user WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $accountid
|
|
)
|
|
);
|
|
return $row['coin_num'];
|
|
}
|
|
|
|
public function getDiamondNum($accountid)
|
|
{
|
|
$conn = $this->getMysql($accountid);
|
|
if (!$conn) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
die();
|
|
}
|
|
$row = $conn->execQueryOne(
|
|
'SELECT diamond_num FROM user WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $accountid
|
|
)
|
|
);
|
|
return $row['diamond_num'];
|
|
}
|
|
|
|
public function getAdfree($accountid)
|
|
{
|
|
$conn = $this->getMysql($accountid);
|
|
if (!$conn) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
die();
|
|
}
|
|
$row = $conn->execQueryOne(
|
|
'SELECT adfree FROM recharge WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $accountid
|
|
)
|
|
);
|
|
return $row ? $row['adfree'] : 0;
|
|
}
|
|
|
|
public function getMedals($accountid) {
|
|
$conn = $this->getMysql($accountid);
|
|
if (!$conn) {
|
|
return 0;
|
|
}
|
|
$row = $conn->execQueryOne(
|
|
'SELECT medals FROM solo WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $accountid
|
|
)
|
|
);
|
|
|
|
return $row ? $row['medals'] : 0;
|
|
}
|
|
|
|
//添加钻石
|
|
protected function addDiamond($item_id, $item_num, $accountid)
|
|
{
|
|
$conn = $this->getMysql($accountid);
|
|
if (!$conn) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
die();
|
|
}
|
|
$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' => time()
|
|
)
|
|
);
|
|
if (!$ret) {
|
|
die();
|
|
}
|
|
}
|
|
//添加金币
|
|
protected function addCoin($item_id, $item_num, $accountid)
|
|
{
|
|
$conn = $this->getMysql($accountid);
|
|
if (!$conn) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
die();
|
|
}
|
|
$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' => time()
|
|
)
|
|
);
|
|
if (!$ret) {
|
|
die();
|
|
}
|
|
}
|
|
|
|
protected function addweizhuang($item_id, $item_num, $accountid)
|
|
{
|
|
$conn = $this->getMysql($accountid);
|
|
if (!$conn) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
die();
|
|
}
|
|
$it = $this->getItem($item_id);
|
|
$status = 1;
|
|
$sum = 0;
|
|
if ($it['type'] == 10) {
|
|
$rows = $conn->execQuery(
|
|
'SELECT id, status FROM bag WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $accountid,
|
|
)
|
|
);
|
|
foreach ($rows as $r) {
|
|
$it = $this->getItem($r['id']);
|
|
if ($r['status'] == 0 && $it['type'] == 10) {
|
|
$sum++;
|
|
}
|
|
}
|
|
if ($sum < 4) {
|
|
$status = 0;
|
|
}
|
|
}
|
|
$row = $conn->execQueryOne(
|
|
'SELECT status, num FROM bag WHERE accountid=:accountid AND id=:id;',
|
|
array(
|
|
':accountid' => $accountid,
|
|
'id' => $item_id
|
|
)
|
|
);
|
|
if (!$row && $item_id != 0) {
|
|
$ret = $conn->execScript(
|
|
'INSERT INTO bag(accountid, id, color_id, status, num, active_time, create_time, modify_time) ' .
|
|
' VALUES(:account_id, :id, 0, :status, :num, :active_time, :create_time, :modify_time) ' .
|
|
' ON DUPLICATE KEY UPDATE accountid=:account_id, id=:id, color_id=0, status=:status, num=:num, active_time=:active_time, modify_time=:modify_time;',
|
|
array(
|
|
':account_id' => $accountid,
|
|
':id' => $item_id,
|
|
':active_time' => 0,
|
|
':status' => $status,
|
|
':num' => $item_num,
|
|
':create_time' => time(),
|
|
':modify_time' => time()
|
|
)
|
|
);
|
|
if (!$ret) {
|
|
die();
|
|
}
|
|
} else {
|
|
if ($it['type'] == 10) {
|
|
$status = $row['status'];
|
|
if ($row['status'] == 2) {
|
|
if ($sum >= 4) {
|
|
$status = 1;
|
|
} else {
|
|
$status = 0;
|
|
}
|
|
}
|
|
}
|
|
$ret = $conn->execScript(
|
|
'UPDATE bag SET num=:num, status=:status, modify_time=:modify_time ' .
|
|
' WHERE accountid=:account_id AND id=:id;',
|
|
array(
|
|
':account_id' => $accountid,
|
|
':id' => $item_id,
|
|
':num' => $row['num'] + $item_num,
|
|
':status' => $status,
|
|
':modify_time' => time()
|
|
)
|
|
);
|
|
if (!$ret) {
|
|
die();
|
|
}
|
|
}
|
|
}
|
|
|
|
protected function addticket($item_id, $item_num, $accountid)
|
|
{
|
|
$conn = $this->getMysql($accountid);
|
|
if (!$conn) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
die();
|
|
}
|
|
$row = $conn->execQueryOne(
|
|
'SELECT free_lot_ticket FROM user WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $accountid
|
|
)
|
|
);
|
|
$ret = $conn->execScript(
|
|
'UPDATE user SET free_lot_ticket=:free_lot_ticket, modify_time=:modify_time ' .
|
|
' WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $accountid,
|
|
':free_lot_ticket' => $item_num + $row['free_lot_ticket'],
|
|
':modify_time' => time()
|
|
)
|
|
);
|
|
if (!$ret) {
|
|
die();
|
|
}
|
|
}
|
|
|
|
protected function addtenticket($item_id, $item_num, $accountid)
|
|
{
|
|
$conn = $this->getMysql($accountid);
|
|
if (!$conn) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
die();
|
|
}
|
|
$row = $conn->execQueryOne(
|
|
'SELECT free_dou_lot_ticket FROM user WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $accountid
|
|
)
|
|
);
|
|
$ret = $conn->execScript(
|
|
'UPDATE user SET free_dou_lot_ticket=:free_dou_lot_ticket, modify_time=:modify_time ' .
|
|
' WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $accountid,
|
|
':free_dou_lot_ticket' => $item_num + $row['free_dou_lot_ticket'],
|
|
':modify_time' => time()
|
|
)
|
|
);
|
|
if (!$ret) {
|
|
die();
|
|
}
|
|
}
|
|
|
|
protected function addAdfree($item_id, $item_num, $accountid)
|
|
{
|
|
$conn = $this->getMysql($accountid);
|
|
if (!$conn) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
die();
|
|
}
|
|
$row = $conn->execQueryOne(
|
|
'SELECT adfree FROM recharge WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $accountid
|
|
)
|
|
);
|
|
$ret = false;
|
|
$nowtime = time();
|
|
if (!$row) {
|
|
$ret = $conn->execScript(
|
|
'INSERT INTO recharge(accountid, adree, first_data, daily_purchase, vip_info, activity, first_purchase, create_time, modify_time) ' .
|
|
' VALUES(:account_id, :adfree_add, :first_data, :daily_purchase, :vip_info, :activity, :first_purchase, :create_time, :modify_time) ' .
|
|
' ON DUPLICATE KEY UPDATE accountid=:account_id, adfree=adfree+:adfree_add, modify_time=:modify_time;',
|
|
array(
|
|
':account_id' => $accountid,
|
|
':adfree_add' => $item_num,
|
|
':first_data' => '',
|
|
':daily_purchase' => '',
|
|
':vip_info' => '',
|
|
':activity' => '',
|
|
':first_purchase' => '',
|
|
':create_time' => $nowtime,
|
|
':modify_time' => $nowtime,
|
|
)
|
|
);
|
|
} else {
|
|
$ret = $conn->execScript(
|
|
'UPDATE recharge SET adfree=adfree+:adfree_add, modify_time=:modify_time ' .
|
|
' WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $accountid,
|
|
':adfree_add' => $item_num,
|
|
':modify_time' => $nowtime,
|
|
)
|
|
);
|
|
}
|
|
if (!$ret) {
|
|
die();
|
|
}
|
|
}
|
|
|
|
protected function addMedal($item_id, $item_num, $accountid)
|
|
{
|
|
$conn = $this->getMysql($accountid);
|
|
if (!$conn) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
die();
|
|
}
|
|
$row = $conn->execQueryOne(
|
|
'SELECT medals, lastredeem FROM solo WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $accountid
|
|
)
|
|
);
|
|
$ret = false;
|
|
$nowtime = time();
|
|
if (!$row) {
|
|
$ret = $conn->execScript(
|
|
'INSERT INTO rolo(accountid, medals, create_time, modify_time) ' .
|
|
' VALUES(:account_id, :medals_add, :create_time, :modify_time) ' .
|
|
' ON DUPLICATE KEY UPDATE accountid=:account_id, medals=medals+:medals_add, modify_time=:modify_time;',
|
|
array(
|
|
':account_id' => $accountid,
|
|
':medals_add' => $item_num,
|
|
':create_time' => $nowtime,
|
|
':modify_time' => $nowtime,
|
|
)
|
|
);
|
|
} else {
|
|
$ret = $conn->execScript(
|
|
'UPDATE solo SET medals=medals+:medals_add, modify_time=:modify_time ' .
|
|
' WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $accountid,
|
|
':medals_add' => $item_num,
|
|
':modify_time' => $nowtime,
|
|
)
|
|
);
|
|
}
|
|
if (!$ret) {
|
|
die();
|
|
}
|
|
}
|
|
|
|
//添加道具
|
|
protected function addItem($itemid, $hourtime, $accountid, $priceid, $price, $t)
|
|
{
|
|
$item_list = array();
|
|
$item_num = 1;
|
|
$item_id = intval($itemid);
|
|
$time = intval($hourtime);
|
|
$conn = $this->getMysql($accountid);
|
|
if (!$conn) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
die();
|
|
}
|
|
$status = 1;
|
|
$active_time = $time * 3600 + time();
|
|
$row = $conn->execQueryOne(
|
|
'SELECT * FROM bag WHERE accountid=:accountid AND id=:id;',
|
|
array(
|
|
':accountid' => $accountid,
|
|
'id' => $item_id
|
|
)
|
|
);
|
|
if (!$row && $item_id != 0) {
|
|
if ($time == 0) {
|
|
$status = 1;
|
|
$active_time = 0;
|
|
}
|
|
if ($t == 0) {
|
|
$status = $this->getStatus($item_id, $status, $accountid);
|
|
} else if ($t == 1) {
|
|
$status = 0;
|
|
$this->updateStatus($item_id, $accountid);
|
|
}
|
|
$ret = $conn->execScript(
|
|
'INSERT INTO bag(accountid, id, color_id, status, num, active_time, create_time, modify_time) ' .
|
|
' VALUES(:account_id, :id, 0, :status, 0, :active_time, :create_time, :modify_time) ' .
|
|
' ON DUPLICATE KEY UPDATE accountid=:account_id, id=:id, color_id=0, status=:status, num=0, active_time=:active_time, modify_time=:modify_time;',
|
|
array(
|
|
':account_id' => $accountid,
|
|
':id' => $item_id,
|
|
':active_time' => $active_time,
|
|
':status' => $status,
|
|
':create_time' => time(),
|
|
':modify_time' => time()
|
|
)
|
|
);
|
|
if (!$ret) {
|
|
die();
|
|
}
|
|
} else {
|
|
if ($row['status'] != 2 && $row['active_time'] == 0) {
|
|
$item_id = $priceid;
|
|
$item_num = $price;
|
|
$time = 0;
|
|
if ($price > 0) {
|
|
if ($priceid == 10003) {
|
|
$this->addDiamond($item_id, $item_num, $accountid);
|
|
} else {
|
|
$this->addweizhuang($item_id, $item_num, $accountid);
|
|
}
|
|
}
|
|
} else {
|
|
$nowTime = $row['active_time'];
|
|
$status = $row['status'];
|
|
if ($time == 0) {
|
|
$nowTime = 0;
|
|
if ($row['status'] == 2) {
|
|
$status = 1;
|
|
}
|
|
} else {
|
|
if ($row['active_time'] < time() + $time * 3600) {
|
|
$nowTime = time() + $time * 3600;
|
|
}
|
|
if ($status == 2) {
|
|
$status = 1;
|
|
}
|
|
}
|
|
if ($t == 0) {
|
|
$status = $this->getStatus($item_id, $status, $accountid);
|
|
} else if ($t == 1) {
|
|
$status = 0;
|
|
$this->updateStatus($item_id, $accountid);
|
|
}
|
|
$ret = $conn->execScript(
|
|
'UPDATE bag SET active_time=:active_time, status=:status, modify_time=:modify_time ' .
|
|
' WHERE accountid=:account_id AND id=:id;',
|
|
array(
|
|
':account_id' => $accountid,
|
|
':id' => $item_id,
|
|
':active_time' => $nowTime,
|
|
':status' => $status,
|
|
':modify_time' => time()
|
|
)
|
|
);
|
|
if (!$ret) {
|
|
die();
|
|
}
|
|
}
|
|
}
|
|
array_push($item_list, array(
|
|
'item_id' => $item_id,
|
|
'item_num' => $item_num,
|
|
'time' => $time,
|
|
));
|
|
return $item_list;
|
|
}
|
|
|
|
public function getStatus($item_id, $status, $accountid)
|
|
{
|
|
$s = $status;
|
|
$b = $this->getBag($item_id);
|
|
$bag_meta_table = require('../res/bag@bag.php');
|
|
//正在装备的道具
|
|
$flag = 0;
|
|
$conn = $this->getMysql($accountid);
|
|
if (!$conn) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
die();
|
|
}
|
|
if ($b['fuction'] != 5) {
|
|
foreach ($bag_meta_table as $bag_info) {
|
|
$id = $bag_info['id'];
|
|
$bag = $this->getBag($id);
|
|
if ($bag['fuction'] != $b['fuction']) {
|
|
continue;
|
|
}
|
|
$row = $conn->execQueryOne(
|
|
'SELECT status FROM bag WHERE accountid=:accountid AND id=:id;',
|
|
array(
|
|
':accountid' => $accountid,
|
|
':id' => $id,
|
|
)
|
|
);
|
|
if (!$row || $row['status'] != 0) {
|
|
continue;
|
|
}
|
|
$flag = 1;
|
|
break;
|
|
}
|
|
if ($flag == 1) {
|
|
$s = $status;
|
|
} else {
|
|
$s = 0;
|
|
}
|
|
} else {
|
|
$emoji_num = 0;
|
|
foreach ($bag_meta_table as $bag_info) {
|
|
$id = $bag_info['id'];
|
|
$bag = $this->getBag($id);
|
|
if ($bag['fuction'] != $b['fuction']) {
|
|
continue;
|
|
}
|
|
$row_emoji = $conn->execQueryOne(
|
|
'SELECT status FROM bag WHERE accountid=:accountid AND id=:id;',
|
|
array(
|
|
':accountid' => $accountid,
|
|
':id' => $id,
|
|
)
|
|
);
|
|
if ($row_emoji['status'] == 0) {
|
|
$emoji_num++;
|
|
}
|
|
}
|
|
if ($emoji_num >= 6) {
|
|
$s = 1;
|
|
} else {
|
|
$s = 0;
|
|
}
|
|
}
|
|
return $s;
|
|
}
|
|
|
|
public function updateStatus($item_id, $accountid)
|
|
{
|
|
$conn = $this->getMysql($accountid);
|
|
if (!$conn) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
return;
|
|
}
|
|
$b = $this->getBag($item_id);
|
|
$bag_meta_table = require('../res/bag@bag.php');
|
|
//正在装备的道具
|
|
if ($b['fuction'] != 5) {
|
|
foreach ($bag_meta_table as $bag_info) {
|
|
$id = $bag_info['id'];
|
|
$bag = $this->getBag($id);
|
|
if ($bag['fuction'] != $b['fuction']) {
|
|
continue;
|
|
}
|
|
$row = $conn->execQueryOne(
|
|
'SELECT status, active_time FROM bag WHERE accountid=:accountid AND id=:id;',
|
|
array(
|
|
':accountid' => $accountid,
|
|
':id' => $id,
|
|
)
|
|
);
|
|
if (!$row || $row['status'] != 0) {
|
|
continue;
|
|
}
|
|
$status = 2;
|
|
if ($row['active_time'] == 0) {
|
|
$status = 1;
|
|
}
|
|
$using_ret = $conn->execScript(
|
|
'UPDATE bag SET status=:status, color_id=0, modify_time=:modify_time ' .
|
|
' WHERE accountid = :account_id AND id = :id;',
|
|
array(
|
|
':account_id' => $accountid,
|
|
':id' => $id,
|
|
':status' => $status,
|
|
':modify_time' => time()
|
|
)
|
|
);
|
|
if (!$using_ret) {
|
|
die();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
protected function addEquip($item_id, $accountid, $piecestr)
|
|
{
|
|
$conn = $this->getMysql($accountid);
|
|
if (!$conn) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
die();
|
|
return;
|
|
}
|
|
$row = $conn->execQueryOne(
|
|
'SELECT id FROM equip WHERE accountid=:accountid AND id=:id;',
|
|
array(
|
|
':accountid' => $accountid,
|
|
':id' => $item_id,
|
|
)
|
|
);
|
|
//没有装备解锁装备
|
|
$item_list = array();
|
|
if (!$row) {
|
|
$rows = $conn->execQuery(
|
|
'SELECT using_id FROM equip WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $accountid,
|
|
)
|
|
);
|
|
$using_id = $item_id;
|
|
if ($rows) {
|
|
foreach ($rows as $r) {
|
|
$using_id = $r['using_id'];
|
|
}
|
|
}
|
|
$ret = $conn->execScript(
|
|
'INSERT INTO equip(accountid, id, lv, active_time, sub_time, create_time, modify_time, using_id, exp) ' .
|
|
' VALUES(:account_id, :id, 0, :active_time, :sub_time, :create_time, :modify_time, :using_id, :exp) ' .
|
|
' ON DUPLICATE KEY UPDATE accountid=:account_id, id=:id, lv=0, active_time=:active_time, sub_time=:sub_time, modify_time=:modify_time, using_id=:using_id, exp=:exp;',
|
|
array(
|
|
':account_id' => $accountid,
|
|
':id' => $item_id,
|
|
':active_time' => 0,
|
|
':create_time' => time(),
|
|
':modify_time' => time(),
|
|
':sub_time' => 0,
|
|
':using_id' => $using_id,
|
|
':exp' => 0,
|
|
)
|
|
);
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
array_push($item_list, array(
|
|
'item_id' => $item_id,
|
|
'item_num' => 1,
|
|
'time' => 0,
|
|
));
|
|
} else {
|
|
//转化碎片
|
|
$e = $this->getEquip($item_id);
|
|
if (!$e) {
|
|
phpcommon\sendError(ERR_USER_BASE + 2, '没有这个装备');
|
|
die();
|
|
return;
|
|
}
|
|
$piecestrs = explode(':', $piecestr);
|
|
$this->addweizhuang($piecestrs[0], $piecestrs[1], $accountid);
|
|
array_push($item_list, array(
|
|
'item_id' => $piecestrs[0],
|
|
'item_num' => $piecestrs[1],
|
|
'time' => 0,
|
|
));
|
|
}
|
|
return $item_list;
|
|
}
|
|
|
|
|
|
public function getRealIndexid($id, $accountid)
|
|
{
|
|
$e = $this->getEquip($id);
|
|
if (!$e || $e['real_index_id'] == '' || !$e['real_index_id']) {
|
|
return intval($id);
|
|
}
|
|
return intval($e['real_index_id']);
|
|
}
|
|
}
|