497 lines
20 KiB
PHP
497 lines
20 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' => 'gamedb2004_' . $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']
|
|
);
|
|
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;
|
|
}
|
|
|
|
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 {
|
|
$price = $i['diamond'];
|
|
if ($time != 0) {
|
|
$price = $i['diamond_hour'] * $time;
|
|
}
|
|
if ($t) {
|
|
$item_list = $this->addItem($item['item_id'], $item['time'], $account_id, $price, $t);
|
|
} else {
|
|
$item_list = $this->addItem($item['item_id'], $item['time'], $account_id, $price, 0);
|
|
}
|
|
}
|
|
}
|
|
return $item_list;
|
|
}
|
|
|
|
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'];
|
|
}
|
|
|
|
//添加钻石
|
|
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 addItem($item_id, $time, $accountid, $price, $t)
|
|
{
|
|
$item_list = array();
|
|
$item_num = 1;
|
|
$item_id = $item_id;
|
|
$time = $time;
|
|
$conn = $this->getMysql($accountid);
|
|
if (!$conn) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
die();
|
|
}
|
|
$status = 2;
|
|
$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 = 10003;
|
|
$item_num = $price;
|
|
$time = 0;
|
|
$this->addDiamond($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 ($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['status'] != 0 || !$row) {
|
|
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['status'] != 0 || !$row) {
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
?>
|