878 lines
35 KiB
PHP
878 lines
35 KiB
PHP
<?php
|
|
|
|
require 'classes/AddReward.php';
|
|
require_once 'metatable/shop.php';
|
|
require_once 'metatable/shopGoods.php';
|
|
require_once 'metatable/parameter.php';
|
|
|
|
require_once('mt/Parameter.php');
|
|
require_once('mt/Drop.php');
|
|
require_once('mt/Item.php');
|
|
|
|
class ShopController extends BaseAuthedController {
|
|
|
|
protected function getItemEx(&$g_conf_item_cluster, $item_id)
|
|
{
|
|
$item_conf = getItemConfig($g_conf_item_cluster, $item_id);
|
|
$it = array(
|
|
'id' => $item_conf['id'],
|
|
'price' => $item_conf['gold'],
|
|
'dprice' => $item_conf['diamond_price'],
|
|
'discount' => $item_conf['discount'],
|
|
'shop_type' => $item_conf['shop_type'],
|
|
'type' => $item_conf['fuction'],
|
|
'bug_groupnum' => $item_conf['bug_groupnum'],
|
|
'shop_list' => $item_conf['shop_list'],
|
|
'bug_groupnum' => $item_conf['bug_groupnum'],
|
|
'Isbug_again' => $item_conf['Isbug_again'],
|
|
);
|
|
return $it;
|
|
}
|
|
|
|
protected function readRecActDB($account_id) {
|
|
$conn = $this->getMysql($account_id);
|
|
$row = $conn->execQueryOne('SELECT blobdata FROM recharge_activity WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id
|
|
));
|
|
if (!empty($row)) {
|
|
$rec_db_str = $row['blobdata'];
|
|
$rec_db = json_decode($rec_db_str, true);
|
|
return $rec_db;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
protected function saveRecActDB($account_id, $rec_db) {
|
|
$conn = $this->getMysql($account_id);
|
|
$row = $conn->execQueryOne('SELECT accountid FROM recharge_activity WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id
|
|
));
|
|
$rec_db_str = "";
|
|
if (!empty($rec_db)) {
|
|
$rec_db_str = json_encode($rec_db);
|
|
}
|
|
if (!empty($row)) {
|
|
//update
|
|
$row = $conn->execScript('UPDATE recharge_activity SET blobdata=:blobdata, modify_time=:modify_time WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':blobdata' => $rec_db_str,
|
|
':modify_time' => phpcommon\getNowTime()
|
|
));
|
|
} else {
|
|
//insert
|
|
$row = $conn->execScript('INSERT INTO recharge_activity(accountid, blobdata, create_time, modify_time) ' .
|
|
' VALUES(:account_id, :blobdata, :create_time, :modify_time) ' .
|
|
' ON DUPLICATE KEY UPDATE accountid=:account_id, blobdata=:blobdata, modify_time=:modify_time;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':blobdata' => $rec_db_str,
|
|
':create_time' => phpcommon\getNowTime(),
|
|
':modify_time' => phpcommon\getNowTime(),
|
|
));
|
|
}
|
|
}
|
|
|
|
protected function readShopDB($account_id) {
|
|
$conn = $this->getMysql($account_id);
|
|
$row = $conn->execQueryOne('SELECT blobdata FROM shop_data WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id
|
|
));
|
|
if (!empty($row)) {
|
|
$shop_db_str = $row['blobdata'];
|
|
$shop_db = json_decode($shop_db_str, true);
|
|
return $shop_db;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
protected function saveShopDB($account_id, $shop_db) {
|
|
$conn = $this->getMysql($account_id);
|
|
$beginTick = phpcommon\getTickCount();
|
|
$row = $conn->execQueryOne('SELECT accountid FROM shop_data WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id
|
|
));
|
|
$shop_db_str = "";
|
|
if (!empty($shop_db)) {
|
|
$shop_db_str = json_encode($shop_db);
|
|
}
|
|
if (!empty($row)) {
|
|
//update
|
|
$row = $conn->execScript('UPDATE shop_data SET blobdata=:blobdata, modify_time=:modify_time WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':blobdata' => $shop_db_str,
|
|
':modify_time' => phpcommon\getNowTime()
|
|
));
|
|
} else {
|
|
//insert
|
|
$row = $conn->execScript('INSERT INTO shop_data(accountid, blobdata, create_time, modify_time) ' .
|
|
' VALUES(:account_id, :blobdata, :create_time, :modify_time) ' .
|
|
' ON DUPLICATE KEY UPDATE accountid=:account_id, blobdata=:blobdata, modify_time=:modify_time;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':blobdata' => $shop_db_str,
|
|
':create_time' => phpcommon\getNowTime(),
|
|
':modify_time' => phpcommon\getNowTime(),
|
|
));
|
|
}
|
|
}
|
|
|
|
//新版商店
|
|
public function newShopInfo()
|
|
{
|
|
$account_id = $_REQUEST['account_id'];
|
|
|
|
$conn = $this->getMysql($account_id);
|
|
$new_shop_uuid = 'game2005api_shop_uuid_new:' . $_REQUEST['account_id'];
|
|
//商店信息
|
|
$this->getNewShopInfo($new_shop_uuid, $account_id);
|
|
$user_db = $this->readShopDB($account_id);
|
|
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg'=> '',
|
|
'shop_uuid' => $new_shop_uuid,
|
|
'active_time' => $user_db['active_time'],
|
|
'act_list' => $user_db['act_list'],
|
|
'free_list' => $user_db['free_list'],
|
|
'sel_list' => $user_db['sel_list'],
|
|
'equ_list' => $user_db['equ_list'],
|
|
'clo_list' => $user_db['clo_list'],
|
|
'item_list' => $user_db['item_list'],
|
|
'guild_list' => $user_db['guild_list'],
|
|
'recharge_list' => $user_db['recharge_list'],
|
|
'tequan1_list' => $user_db['tequan1_list'],
|
|
'tequan2_list' => $user_db['tequan2_list'],
|
|
'tequan3_list' => $user_db['tequan3_list'],
|
|
'zhandui1_list' => $user_db['zhandui1_list'],
|
|
'zhandui2_list' => $user_db['zhandui2_list'],
|
|
'zhandui3_list' => $user_db['zhandui3_list'],
|
|
'zhandui4_list' => $user_db['zhandui4_list'],
|
|
'zhandui5_list' => $user_db['zhandui5_list'],
|
|
));
|
|
}
|
|
|
|
protected function getNewShopInfo($shop_uuid, $account_id)
|
|
{
|
|
$act_list = array();
|
|
$free_list = array();
|
|
$sel_list = array();
|
|
$equ_list = array();
|
|
$clo_list = array();
|
|
$item_list = array();
|
|
$guild_list = array();
|
|
$recharge_list = array();
|
|
$tequan1_list = array();
|
|
$tequan2_list = array();
|
|
$tequan3_list = array();
|
|
$zhandui1_list = array();
|
|
$zhandui2_list = array();
|
|
$zhandui3_list = array();
|
|
$zhandui4_list = array();
|
|
$zhandui5_list = array();
|
|
$user_db = $this->readShopDB($account_id);
|
|
$shop_conf = metatable\getShopConf();
|
|
if (!$shop_conf) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1,'session失效');
|
|
return;
|
|
}
|
|
$active_time = 0;
|
|
if (empty($user_db)) {
|
|
$act_list = $this->getShopListInfo(1);
|
|
$free_list = $this->getShopListInfo(2);
|
|
$sel_list = $this->getShopListInfo(3);
|
|
$equ_list = $this->getShopListInfo(4);
|
|
$clo_list = $this->getShopListInfo(5);
|
|
$item_list = $this->getShopListInfo(6);
|
|
$guild_list = $this->getShopListInfo(7);
|
|
$recharge_list = $this->getShopListInfo(8);
|
|
$tequan1_list = $this->getShopListInfo(9);
|
|
$tequan2_list = $this->getShopListInfo(10);
|
|
$tequan3_list = $this->getShopListInfo(11);
|
|
$zhandui1_list = $this->getShopListInfo(21);
|
|
$zhandui2_list = $this->getShopListInfo(22);
|
|
$zhandui3_list = $this->getShopListInfo(23);
|
|
$zhandui4_list = $this->getShopListInfo(24);
|
|
$zhandui5_list = $this->getShopListInfo(25);
|
|
$active_time = phpcommon\getNowTime();
|
|
} else {
|
|
$act_list = $user_db['act_list'];
|
|
$free_list = $user_db['free_list'];
|
|
$sel_list = $user_db['sel_list'];
|
|
$equ_list = $user_db['equ_list'];
|
|
$clo_list = $user_db['clo_list'];
|
|
$item_list = $user_db['item_list'];
|
|
$guild_list = $user_db['guild_list'];
|
|
$recharge_list = $user_db['recharge_list'];
|
|
$tequan1_list = $user_db['tequan1_list'];
|
|
$tequan2_list = $user_db['tequan2_list'];
|
|
$tequan3_list = $user_db['tequan3_list'];
|
|
$active_time = $user_db['active_time'];
|
|
$zhandui1_list =$user_db['zhandui1_list'];
|
|
$zhandui2_list = $user_db['zhandui2_list'];
|
|
$zhandui3_list = $user_db['zhandui3_list'];
|
|
$zhandui4_list = $user_db['zhandui4_list'];
|
|
$zhandui5_list = $user_db['zhandui5_list'];
|
|
$nowTime = phpcommon\getdayseconds(phpcommon\getNowTime());
|
|
$passed_days = floor(($nowTime - phpcommon\getdayseconds($user_db['active_time'])) / (3600 * 24));
|
|
//$passed_days = 2;
|
|
if ($passed_days >= 1) {
|
|
for ($i = 1; $i <= 25; $i++) {
|
|
if (!isset($shop_conf[$i]) || $shop_conf[$i]['isrefresh'] == 0) {
|
|
continue;
|
|
}
|
|
if ($shop_conf[$i]['shop_id'] == 1) {
|
|
$act_list = $this->getShopListInfo(1);
|
|
} else if($shop_conf[$i]['shop_id'] == 2) {
|
|
$free_list = $this->getShopListInfo(2);
|
|
} else if($shop_conf[$i]['shop_id'] == 3) {
|
|
$sel_list = $this->getShopListInfo(3);
|
|
} else if($shop_conf[$i]['shop_id'] == 4) {
|
|
$equ_list = $this->getShopListInfo(4);
|
|
} else if($shop_conf[$i]['shop_id'] == 5) {
|
|
$clo_list = $this->getShopListInfo(5);
|
|
} else if($shop_conf[$i]['shop_id'] == 6) {
|
|
$item_list = $this->getShopListInfo(6);
|
|
} else if ($shop_conf[$i]['shop_id'] == 7) {
|
|
$guild_list = $this->getShopListInfo(7);
|
|
} else if ($shop_conf[$i]['shop_id'] == 8) {
|
|
$recharge_list = $this->getShopListInfo(8);
|
|
} else if ($shop_conf[$i]['shop_id'] == 9) {
|
|
$tequan1_list = $this->getShopListInfo(9);
|
|
} else if ($shop_conf[$i]['shop_id'] == 10) {
|
|
$tequan2_list = $this->getShopListInfo(10);
|
|
} else if ($shop_conf[$i]['shop_id'] == 11) {
|
|
$tequan3_list = $this->getShopListInfo(11);
|
|
} else if ($shop_conf[$i]['shop_id'] == 21) {
|
|
$zhandui1_list = $this->getShopListInfo(21);
|
|
} else if ($shop_conf[$i]['shop_id'] == 22) {
|
|
$zhandui2_list = $this->getShopListInfo(22);
|
|
} else if ($shop_conf[$i]['shop_id'] == 23) {
|
|
$zhandui3_list = $this->getShopListInfo(23);
|
|
} else if ($shop_conf[$i]['shop_id'] == 24) {
|
|
$zhandui4_list = $this->getShopListInfo(24);
|
|
} else if ($shop_conf[$i]['shop_id'] == 25) {
|
|
$zhandui5_list = $this->getShopListInfo(25);
|
|
}
|
|
}
|
|
$active_time = $nowTime;
|
|
}
|
|
}
|
|
$shop_db = array(
|
|
'shop_uuid' => $shop_uuid,
|
|
'active_time' => $active_time,
|
|
'act_list' => $act_list,
|
|
'free_list' => $free_list,
|
|
'sel_list' => $sel_list,
|
|
'equ_list' => $equ_list,
|
|
'clo_list' => $clo_list,
|
|
'item_list' => $item_list,
|
|
'guild_list' => $guild_list,
|
|
'recharge_list' => $recharge_list,
|
|
'tequan1_list' => $tequan1_list,
|
|
'tequan2_list' => $tequan2_list,
|
|
'tequan3_list' => $tequan3_list,
|
|
'zhandui1_list' => $zhandui1_list,
|
|
'zhandui2_list' => $zhandui2_list,
|
|
'zhandui3_list' => $zhandui3_list,
|
|
'zhandui4_list' => $zhandui4_list,
|
|
'zhandui5_list' => $zhandui5_list,
|
|
);
|
|
$this->saveShopDB($account_id, $shop_db);
|
|
}
|
|
|
|
protected function getShopListInfo($id)
|
|
{
|
|
$shop_conf = metatable\getShopById($id);
|
|
if (!$shop_conf) {
|
|
return array();
|
|
}
|
|
$act_shop_list = $this->randomNewShop($id);
|
|
$act_list = array(
|
|
'id' => $shop_conf['shop_id'],
|
|
'isdorefresh' => $shop_conf['isdorefresh'],
|
|
'hasrefreshnum' => 0,
|
|
'refreshnum' => $shop_conf['refreshnum'],
|
|
'shop_list' => $act_shop_list,
|
|
);
|
|
return $act_list;
|
|
}
|
|
|
|
protected function randomNewShop($id)
|
|
{
|
|
$shop_list = array();
|
|
$shop_conf = metatable\getShopById($id);
|
|
if (!$shop_conf) {
|
|
return array();
|
|
}
|
|
if ($id == 8) {
|
|
return metatable\shopGoodsList($shop_conf, $shop_list);
|
|
} else {
|
|
return metatable\randGoods($shop_conf, $shop_list);
|
|
}
|
|
}
|
|
|
|
public function flushShopItem()
|
|
{
|
|
$account_id = $_REQUEST['account_id'];
|
|
$id = $_REQUEST['id'];
|
|
$type = $_REQUEST['type'];
|
|
$shop_type = $_REQUEST['shop_type'];
|
|
if ($shop_type == 0) {
|
|
$this->flushNormalShop($account_id, $id, $type);
|
|
}
|
|
if ($shop_type == 1) {
|
|
$this->flushRecShop($account_id, $id);
|
|
}
|
|
$addreward = new classes\AddReward();
|
|
$rmb_num = $addreward->getRmbNum($account_id);
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg'=> '',
|
|
'rmb_nums' => $rmb_num,
|
|
));
|
|
}
|
|
|
|
protected function flushNormalShop($account_id, $id, $type)
|
|
{
|
|
$conn = $this->getMysql($account_id);
|
|
$user_db = $this->readShopDB($account_id);
|
|
if (empty($user_db) || !$user_db) {
|
|
phpcommon\sendError(ERR_USER_BASE + 2,'没有这个商品');
|
|
return;
|
|
}
|
|
if ($user_db[$type]['refreshnum'] != '') {
|
|
if ($user_db[$type]['refreshnum'] <= $user_db[$type]['hasrefreshnum']) {
|
|
phpcommon\sendError(ERR_USER_BASE + 3,'刷新次数已达上限');
|
|
return;
|
|
}
|
|
}
|
|
$cost = metatable\getParameterByName('shop_refresh') + metatable\getParameterByName('shop_refresh_add') * $user_db[$type]['hasrefreshnum'];
|
|
$row = $conn->execQueryOne('SELECT rmb_num FROM user WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id
|
|
));
|
|
if ($row['rmb_num'] < $cost) {
|
|
phpcommon\sendError(ERR_USER_BASE + 4,'点券不足');
|
|
return;
|
|
}
|
|
|
|
$ret = $conn->execScript('UPDATE user SET rmb_num=:rmb_num, modify_time=:modify_time ' .
|
|
' WHERE accountid=:account_id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':rmb_num' => $row['rmb_num'] - $cost,
|
|
':modify_time' => phpcommon\getNowTime()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
$shop_list = $this->randomNewShop($id);
|
|
$user_db[$type]['shop_list'] = $shop_list;
|
|
$user_db[$type]['hasrefreshnum']++;
|
|
$this->saveShopDB($account_id, $user_db);
|
|
}
|
|
|
|
protected function flushRecShop($account_id, $id)
|
|
{
|
|
$conn = $this->getMysql($account_id);
|
|
$user_db = $this->readRecActDB($account_id);
|
|
if (!$user_db || empty($user_db)) {
|
|
phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家');
|
|
return;
|
|
}
|
|
foreach ($user_db['shop_list'] as &$us) {
|
|
if (!isset($us['id']) || $us['id'] != $id) {
|
|
continue;
|
|
}
|
|
if ($us['reward']['refreshnum'] != '') {
|
|
if ($us['reward']['refreshnum'] <= $us['reward']['hasrefreshnum']) {
|
|
phpcommon\sendError(ERR_USER_BASE + 3,'刷新次数已达上限');
|
|
return;
|
|
}
|
|
}
|
|
$cost = metatable\getParameterByName('shop_refresh') + metatable\getParameterByName('shop_refresh_add') * $us['reward']['hasrefreshnum'];
|
|
$row = $conn->execQueryOne('SELECT rmb_num FROM user WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id
|
|
));
|
|
if ($row['rmb_num'] < $cost) {
|
|
phpcommon\sendError(ERR_USER_BASE + 4,'点券不足');
|
|
return;
|
|
}
|
|
$ret = $conn->execScript('UPDATE user SET rmb_num=:rmb_num, modify_time=:modify_time ' .
|
|
' WHERE accountid=:account_id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':rmb_num' => $row['rmb_num'] - $cost,
|
|
':modify_time' => phpcommon\getNowTime()
|
|
));
|
|
$shop_list = $this->randomNewShop($us['reward']['id']);
|
|
$us['reward']['shop_list'] = $shop_list;
|
|
$us['reward']['hasrefreshnum']++;
|
|
break;
|
|
|
|
}
|
|
$this->saveRecActDB($account_id, $user_db);
|
|
}
|
|
|
|
public function newBuyShopItem()
|
|
{
|
|
$account_id = $_REQUEST['account_id'];
|
|
$id = $_REQUEST['id'];
|
|
$type = $_REQUEST['type'];
|
|
$num = $_REQUEST['num'];
|
|
$user_db = $this->readShopDB($account_id);
|
|
$redis_goods = $this->getGoodsDiscount($id, $type, $user_db);
|
|
$shop_conf = metatable\getShopById($type);
|
|
if (!$shop_conf || !$redis_goods) {
|
|
phpcommon\sendError(ERR_USER_BASE + 2,'没有这个商品');
|
|
return;
|
|
}
|
|
if ($redis_goods['status'] == 1) {
|
|
phpcommon\sendError(ERR_USER_BASE + 4,'商品已购买');
|
|
return;
|
|
}
|
|
$price = $redis_goods['price'] * $num;
|
|
if ($redis_goods['isdiscount']) {
|
|
$price = ceil($price * $redis_goods['dis_num'] / 100);
|
|
}
|
|
$item_conf = mt\Item::getOldItem($id);
|
|
$item_fuctionindex = $item_conf['fuctionindex'];
|
|
$drop_conf = mt\Drop::getOldDrop($item_fuctionindex);
|
|
if (!$item_conf) {
|
|
phpcommon\sendError(ERR_USER_BASE + 5,'没有这个道具');
|
|
return;
|
|
}
|
|
//扣除货币
|
|
$addreward = new classes\AddReward();
|
|
if ($redis_goods['buy'] != 3 && $shop_conf['isvipprice'] == 1) {
|
|
$val = $addreward->getVipVal($account_id, 2);
|
|
$price = floor($price - $price * $val / 100);
|
|
}
|
|
if ($redis_goods['buy'] != 0) {
|
|
$this->subCoin($price, $account_id, $redis_goods['buy'], $shop_conf['istodayad']);
|
|
}
|
|
//增加奖励
|
|
$addreward = new classes\AddReward();
|
|
$item_list = array();
|
|
$all_item_list = array();
|
|
if ($item_conf['type'] == 13) {
|
|
$item_list = $this->getRandomShopReward($item_fuctionindex);
|
|
foreach ($item_list as $it) {
|
|
$item_id = $it['item_id'];
|
|
$num = $it['item_num'];
|
|
$time = 0;
|
|
|
|
$items = $addreward->addReward($item_id, $num, $account_id, $time,0);
|
|
|
|
foreach($items as $j) {
|
|
array_push($all_item_list, array(
|
|
'item_id' => $j['item_id'],
|
|
'item_num' => $j['item_num'],
|
|
'time' => $j['time'],
|
|
));
|
|
}
|
|
}
|
|
} else {
|
|
array_push($item_list,array(
|
|
'item_id' => $redis_goods['id'],
|
|
'item_num' => $num,
|
|
'time' => 0,
|
|
));
|
|
$items = $addreward->addReward($redis_goods['id'], $num, $account_id, 0, 0);
|
|
foreach($items as $j) {
|
|
array_push($all_item_list, array(
|
|
'item_id' => $j['item_id'],
|
|
'item_num' => $j['item_num'],
|
|
'time' => $j['time'],
|
|
));
|
|
}
|
|
}
|
|
//修改购买状态
|
|
if ($shop_conf['isrepeat'] == 0) {
|
|
$this->updateShopRedis($account_id, $id, $type, $user_db);
|
|
}
|
|
$coin_num = $addreward->getCoinNum($account_id);
|
|
$rmb_num = $addreward->getRmbNum($account_id);
|
|
$guildcoin_num = $addreward->getGuildcoinNum($account_id);
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg'=> '',
|
|
'coin_nums' => $coin_num,
|
|
'item_list' => $item_list,
|
|
'all_item_list' => $all_item_list,
|
|
'id' => $id,
|
|
'rmb_nums' => $rmb_num,
|
|
'guildcoin_num' => $guildcoin_num,
|
|
));
|
|
}
|
|
|
|
protected function getRandomShopReward($drop_id)
|
|
{
|
|
$airReward_list = array();
|
|
//随机奖励
|
|
$d = mt\Drop::getOldDrop($drop_id);
|
|
if (!$d) {
|
|
phpcommon\sendError(ERR_USER_BASE + 3, '没有这个奖励');
|
|
die();
|
|
}
|
|
$item_id_array = $this->getExplode($d['item_id']);
|
|
$item_num_array = $this->getExplode($d['num']);
|
|
$weight_array = $this->getExplode($d['weight']);
|
|
if ($d['type'] == 2) {
|
|
$weight_sum = 0;
|
|
$keys = 0;
|
|
for ($i = 0; $i < count($weight_array); $i++) {
|
|
$weight_sum += $weight_array[$i][0];
|
|
}
|
|
$random = Rand(0, $weight_sum);
|
|
$weight = 0;
|
|
for ($i = 0; $i < count($weight_array); $i++) {
|
|
$weight += $weight_array[$i][0];
|
|
if ($weight > $random) {
|
|
$keys = $i;
|
|
break;
|
|
}
|
|
}
|
|
$item_id = $item_id_array[$keys][0];
|
|
$item_num = $item_num_array[$keys][0];
|
|
array_push($airReward_list, array(
|
|
'item_id' => $item_id,
|
|
'item_num' => $item_num,
|
|
'time' => 0,
|
|
));
|
|
}
|
|
if ($d['type'] == 1) {
|
|
for ($i = 0; $i < count($weight_array); $i++) {
|
|
$random = Rand(0, 10000);
|
|
if ($weight_array[$i][0] < $random) {
|
|
continue;
|
|
}
|
|
array_push($airReward_list, array(
|
|
'item_id' => $item_id_array[$i][0],
|
|
'item_num' => $item_num_array[$i][0],
|
|
'time' => 0,
|
|
));
|
|
}
|
|
}
|
|
return $airReward_list;
|
|
}
|
|
|
|
protected function updateShopRedis($account_id, $id, $type, $user_db)
|
|
{
|
|
if ($type == 1) {
|
|
foreach ($user_db['act_list']['shop_list'] as &$re) {
|
|
if ($re['id'] == $id) {
|
|
$re['status'] = 1;
|
|
break;
|
|
}
|
|
}
|
|
} else if ($type == 2) {
|
|
foreach ($user_db['free_list']['shop_list'] as &$re) {
|
|
if ($re['id'] == $id) {
|
|
$re['status'] = 1;
|
|
break;
|
|
}
|
|
}
|
|
} else if ($type == 3) {
|
|
foreach ($user_db['sel_list']['shop_list'] as &$re) {
|
|
if ($re['id'] == $id) {
|
|
$re['status'] = 1;
|
|
break;
|
|
}
|
|
}
|
|
} else if ($type == 4) {
|
|
foreach ($user_db['equ_list']['shop_list'] as &$re) {
|
|
if ($re['id'] == $id) {
|
|
$re['status'] = 1;
|
|
break;
|
|
}
|
|
}
|
|
} else if ($type == 5) {
|
|
foreach ($user_db['clo_list']['shop_list'] as &$re) {
|
|
if ($re['id'] == $id) {
|
|
$re['status'] = 1;
|
|
break;
|
|
}
|
|
}
|
|
} else if ($type == 6) {
|
|
foreach ($user_db['item_list']['shop_list'] as &$re) {
|
|
if ($re['id'] == $id) {
|
|
$re['status'] = 1;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
$this->saveShopDB($account_id, $user_db);
|
|
}
|
|
|
|
protected function getGoodsDiscount($id, $type, $user_db)
|
|
{
|
|
if ($type == 1) {
|
|
foreach ($user_db['act_list']['shop_list'] as $re) {
|
|
if ($re['id'] == $id) {
|
|
return $re;
|
|
}
|
|
}
|
|
} else if ($type == 2) {
|
|
foreach ($user_db['free_list']['shop_list'] as $re) {
|
|
if ($re['id'] == $id) {
|
|
return $re;
|
|
}
|
|
}
|
|
} else if ($type == 3) {
|
|
foreach ($user_db['sel_list']['shop_list'] as $re) {
|
|
if ($re['id'] == $id) {
|
|
return $re;
|
|
}
|
|
}
|
|
} else if ($type == 4) {
|
|
foreach ($user_db['equ_list']['shop_list'] as $re) {
|
|
if ($re['id'] == $id) {
|
|
return $re;
|
|
}
|
|
}
|
|
} else if ($type == 5) {
|
|
foreach ($user_db['clo_list']['shop_list'] as $re) {
|
|
if ($re['id'] == $id) {
|
|
return $re;
|
|
}
|
|
}
|
|
} else if ($type == 6) {
|
|
foreach ($user_db['item_list']['shop_list'] as $re) {
|
|
if ($re['id'] == $id) {
|
|
return $re;
|
|
}
|
|
}
|
|
} else if ($type == 7) {
|
|
foreach ($user_db['guild_list']['shop_list'] as $re) {
|
|
if ($re['id'] == $id) {
|
|
return $re;
|
|
}
|
|
}
|
|
} else if ($type == 8) {
|
|
foreach ($user_db['recharge_list']['shop_list'] as $re) {
|
|
if ($re['id'] == $id) {
|
|
return $re;
|
|
}
|
|
}
|
|
} else if ($type == 9) {
|
|
foreach ($user_db['tequan1_list']['shop_list'] as $re) {
|
|
if ($re['id'] == $id) {
|
|
return $re;
|
|
}
|
|
}
|
|
} else if ($type == 10) {
|
|
foreach ($user_db['tequan2_list']['shop_list'] as $re) {
|
|
if ($re['id'] == $id) {
|
|
return $re;
|
|
}
|
|
}
|
|
} else if ($type == 11) {
|
|
foreach ($user_db['tequan3_list']['shop_list'] as $re) {
|
|
if ($re['id'] == $id) {
|
|
return $re;
|
|
}
|
|
}
|
|
} else if ($type == 21) {
|
|
foreach ($user_db['zhandui1_list']['shop_list'] as $re) {
|
|
if ($re['id'] == $id) {
|
|
return $re;
|
|
}
|
|
}
|
|
} else if ($type == 22) {
|
|
foreach ($user_db['zhandui2_list']['shop_list'] as $re) {
|
|
if ($re['id'] == $id) {
|
|
return $re;
|
|
}
|
|
}
|
|
} else if ($type == 23) {
|
|
foreach ($user_db['zhandui3_list']['shop_list'] as $re) {
|
|
if ($re['id'] == $id) {
|
|
return $re;
|
|
}
|
|
}
|
|
} else if ($type == 24) {
|
|
foreach ($user_db['zhandui4_list']['shop_list'] as $re) {
|
|
if ($re['id'] == $id) {
|
|
return $re;
|
|
}
|
|
}
|
|
} else if ($type == 25) {
|
|
foreach ($user_db['zhandui5_list']['shop_list'] as $re) {
|
|
if ($re['id'] == $id) {
|
|
return $re;
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public function shopBuyMore()
|
|
{
|
|
$account_id = $_REQUEST['account_id'];
|
|
$id = $_REQUEST['id'];
|
|
$type = $_REQUEST['type'];
|
|
$num = $_REQUEST['num'];
|
|
$conn = $this->getMysql($account_id);
|
|
$i = mt\Item::getOldItem($id);
|
|
$price = 0;
|
|
if ($i['shop_type'] == 1) {
|
|
$row_c = $conn->execQueryOne('SELECT * FROM shop WHERE accountid=:accountid AND coin_id=:id;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':id' => $id
|
|
));
|
|
$price = $i['price'] * $num;
|
|
if ($row_c) {
|
|
$price = round($i['price'] * $num * $row_c['coin_discount'] / 10);
|
|
}
|
|
$this->SubCoin($price, $account_id, 1, 0);
|
|
} else if ($i['shop_type'] == 2) {
|
|
$price = $i['dprice'] * $num;
|
|
$row_d = $conn->execQueryOne('SELECT * FROM shop WHERE accountid=:accountid AND diamond_id=:id;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':id' => $id
|
|
));
|
|
if ($row_d) {
|
|
$price = round($i['dprice'] * $num * $row_d['diamond_discount'] / 10);
|
|
}
|
|
$this->SubCoin($price, $account_id, 2, 0);
|
|
} else if ($i['shop_type'] == 3) {
|
|
if ($type == 0) {
|
|
$row_c = $conn->execQueryOne('SELECT * FROM shop WHERE accountid=:accountid AND coin_id=:id;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':id' => $id
|
|
));
|
|
$price = $i['price'] * $num;
|
|
if ($row_c) {
|
|
$price = round($i['price'] * $num * $row_c['coin_discount'] / 10);
|
|
}
|
|
$this->SubCoin($price, $account_id, 1, 0);
|
|
} else if ($type == 1) {
|
|
$price = $i['dprice'] * $num;
|
|
$row_d = $conn->execQueryOne('SELECT * FROM shop WHERE accountid=:accountid AND diamond_id=:id;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':id' => $id
|
|
));
|
|
if ($row_d) {
|
|
$price = round($i['dprice'] * $num * $row_d['diamond_discount'] / 10);
|
|
}
|
|
$this->SubCoin($price, $account_id, 2, 0);
|
|
}
|
|
}
|
|
//增加奖励
|
|
$addreward = new classes\AddReward();
|
|
$all_item_list = $addreward->addReward($id, $num, $account_id, 0, 0);
|
|
$coin_num = $addreward->getCoinNum($account_id);
|
|
$rmb_num = $addreward->getRmbNum($account_id);
|
|
$item_list = array();
|
|
array_push($item_list,array(
|
|
'item_id' => $id,
|
|
'item_num' => $num,
|
|
'time' => 0,
|
|
));
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg'=> '',
|
|
'coin_nums' => $coin_num,
|
|
'rmb_nums' => $rmb_num,
|
|
'item_list' => $item_list,
|
|
'all_item_list' => $all_item_list
|
|
));
|
|
}
|
|
|
|
protected function subCoin($coin_num, $account_id, $tips, $isview)
|
|
{
|
|
$conn = $this->getMysql($account_id);
|
|
$rowCoin = $conn->execQueryOne('SELECT coin_num, guildcoin_num, shop_view_times, first_day_ad, rmb_num FROM user WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id
|
|
));
|
|
if ($tips == 1) {
|
|
//扣除货币
|
|
if ($rowCoin['coin_num'] < $coin_num) {
|
|
phpcommon\sendError(ERR_USER_BASE + 3, '金币不足');
|
|
die();
|
|
return;
|
|
}
|
|
$ret = $conn->execScript('UPDATE user SET coin_num=:coin_num, modify_time=:modify_time ' .
|
|
' WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':coin_num' => $rowCoin['coin_num'] - $coin_num,
|
|
':modify_time' => phpcommon\getNowTime()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
}
|
|
}
|
|
if ($tips == 2 || $tips == 5) {
|
|
//扣除货币
|
|
if ($rowCoin['rmb_num'] < $coin_num) {
|
|
phpcommon\sendError(ERR_USER_BASE + 9, '点券不足');
|
|
die();
|
|
return;
|
|
}
|
|
$ret = $conn->execScript('UPDATE user SET rmb_num=:rmb_num, modify_time=:modify_time ' .
|
|
' WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':rmb_num' => $rowCoin['rmb_num'] - $coin_num,
|
|
':modify_time' => phpcommon\getNowTime()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
}
|
|
}
|
|
|
|
if ($tips == 3) {
|
|
if ($isview == 1) {
|
|
if ($rowCoin['first_day_ad'] < $coin_num) {
|
|
phpcommon\sendError(ERR_USER_BASE + 7, '每日视频次数不足');
|
|
die();
|
|
return;
|
|
}
|
|
} else {
|
|
if ($rowCoin['shop_view_times'] < $coin_num) {
|
|
phpcommon\sendError(ERR_USER_BASE + 6, '视频次数不足');
|
|
die();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($tips == 4) {
|
|
if ($rowCoin['guildcoin_num'] < $coin_num) {
|
|
phpcommon\sendError(ERR_USER_BASE + 8, '战队货币不足');
|
|
die();
|
|
return;
|
|
}
|
|
$ret = $conn->execScript('UPDATE user SET guildcoin_num=:guildcoin_num, modify_time=:modify_time ' .
|
|
' WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':guildcoin_num' => $rowCoin['guildcoin_num'] - $coin_num,
|
|
':modify_time' => phpcommon\getNowTime()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
?>
|