1
This commit is contained in:
parent
8e1094416d
commit
a355e19fe0
@ -18,160 +18,160 @@ use services\LogService;
|
||||
|
||||
class BuyShopGoodsCbService
|
||||
{
|
||||
public function process($order)
|
||||
{
|
||||
$itemService = new ShopAddItemService();
|
||||
switch ($order['order_type']) {
|
||||
case V_ORDER_TYPE_BUY_SHOP_GOODS: {
|
||||
$ext_data = json_decode($order['ext_data'], true);
|
||||
switch ($ext_data['mode']) {
|
||||
public function process($order)
|
||||
{
|
||||
$itemService = new ShopAddItemService();
|
||||
switch ($order['order_type']) {
|
||||
case V_ORDER_TYPE_BUY_SHOP_GOODS: {
|
||||
$ext_data = json_decode($order['ext_data'], true);
|
||||
switch ($ext_data['mode']) {
|
||||
case SHOP_BUY_MODE_NORMAL:
|
||||
$itemService->addGameLog($order['address'], "shopBuyNormal", "begin", array(
|
||||
'param1' => $order['order_id'],
|
||||
'param2' => json_encode(array(
|
||||
'item_id' => $order['item_id'],
|
||||
'item_num' => $order['item_num'],
|
||||
)),
|
||||
));
|
||||
$this->_buyNormal($order, $ext_data);
|
||||
$itemService->addGameLog($order['address'], "shopBuyNormal", "end", array(
|
||||
'param1' => $order['order_id'],
|
||||
'param2' => json_encode(array(
|
||||
'item_id' => $order['item_id'],
|
||||
'item_num' => $order['item_num'],
|
||||
)),
|
||||
));
|
||||
break;
|
||||
$itemService->addGameLog($order['address'], "shopBuyNormal", "begin", array(
|
||||
'param1' => $order['order_id'],
|
||||
'param2' => json_encode(array(
|
||||
'item_id' => $order['item_id'],
|
||||
'item_num' => $order['item_num'],
|
||||
)),
|
||||
));
|
||||
$this->_buyNormal($order, $ext_data);
|
||||
$itemService->addGameLog($order['address'], "shopBuyNormal", "end", array(
|
||||
'param1' => $order['order_id'],
|
||||
'param2' => json_encode(array(
|
||||
'item_id' => $order['item_id'],
|
||||
'item_num' => $order['item_num'],
|
||||
)),
|
||||
));
|
||||
break;
|
||||
case SHOP_BUY_MODE_DAILY_SELECTION:
|
||||
$itemService->addGameLog($order['address'], "shopBuyDailySelection", "begin", array(
|
||||
'param1' => $order['order_id'],
|
||||
'param2' => json_encode(array(
|
||||
'item_id' => $order['item_id'],
|
||||
'item_num' => $order['item_num'],
|
||||
)),
|
||||
));
|
||||
$this->_buyDailySelection($order, $ext_data);
|
||||
$itemService->addGameLog($order['address'], "shopBuyDailySelection", "end", array(
|
||||
'param1' => $order['order_id'],
|
||||
'param2' => json_encode(array(
|
||||
'item_id' => $order['item_id'],
|
||||
'item_num' => $order['item_num'],
|
||||
)),
|
||||
));
|
||||
break;
|
||||
}
|
||||
$itemService->addGameLog($order['address'], "shopBuyDailySelection", "begin", array(
|
||||
'param1' => $order['order_id'],
|
||||
'param2' => json_encode(array(
|
||||
'item_id' => $order['item_id'],
|
||||
'item_num' => $order['item_num'],
|
||||
)),
|
||||
));
|
||||
$this->_buyDailySelection($order, $ext_data);
|
||||
$itemService->addGameLog($order['address'], "shopBuyDailySelection", "end", array(
|
||||
'param1' => $order['order_id'],
|
||||
'param2' => json_encode(array(
|
||||
'item_id' => $order['item_id'],
|
||||
'item_num' => $order['item_num'],
|
||||
)),
|
||||
));
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default: {
|
||||
}
|
||||
break;
|
||||
default: {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function _buyNormal($order, $ext_data)
|
||||
{
|
||||
$self = myself();
|
||||
if (!$self) {
|
||||
return;
|
||||
private function _buyNormal($order, $ext_data)
|
||||
{
|
||||
$self = myself();
|
||||
if (!$self) {
|
||||
return;
|
||||
}
|
||||
|
||||
$order_id = $order['order_id'];
|
||||
$address = $order['address'];
|
||||
$account_id = $this->getAccountId($address);
|
||||
$item_id = $order['item_id'];
|
||||
$item_num = $order['item_num'];
|
||||
$id = null;
|
||||
if (isset($ext_data['id'])) {
|
||||
$id = $ext_data['id'];
|
||||
}
|
||||
|
||||
error_log("callback buynormal address: $address, order_id: $order_id, goods_id: $item_id, goods_num: $item_num");
|
||||
if ($item_id == V_ITEM_DIAMOND) {
|
||||
$event = [
|
||||
'name' => LogService::CEBG_TO_DIAMOND,
|
||||
'val' => $item_num
|
||||
];
|
||||
LogService::productDiamondCallback(['account_id' => $account_id], $event);
|
||||
}
|
||||
|
||||
$this->_addGoods($address, array(
|
||||
'goods_id' => $item_id,
|
||||
'goods_num' => $item_num,
|
||||
'id' => $id,
|
||||
));
|
||||
}
|
||||
|
||||
$order_id = $order['order_id'];
|
||||
$address = $order['address'];
|
||||
$account_id = $this->getAccountId($address);
|
||||
$item_id = $order['item_id'];
|
||||
$item_num = $order['item_num'];
|
||||
$id = null;
|
||||
if (isset($ext_data['id'])) {
|
||||
$id = $ext_data['id'];
|
||||
private function _buyDailySelection($order, $ext_data)
|
||||
{
|
||||
$self = myself();
|
||||
if (!$self) {
|
||||
return;
|
||||
}
|
||||
|
||||
$order_id = $order['order_id'];
|
||||
$item_id = $order['item_id'];
|
||||
$item_num = $order['item_num'];
|
||||
$address = $order['address'];
|
||||
$account_id = $this->getAccountId($address);
|
||||
$idx = $ext_data['idx'];
|
||||
$grid = $ext_data['grid'];
|
||||
$count = $ext_data['count'];
|
||||
|
||||
error_log("callback buyDailySelection address: $address, order_id: $order_id, item_id: $item_id, item_num: $item_num, idx: $idx, grid: $grid, count: $count");
|
||||
|
||||
$conn = $self->_getMysql($address);
|
||||
$sql = "SELECT count_$grid FROM t_shop_dailyselection WHERE idx = $idx";
|
||||
$chk = $conn->execQuery($sql);
|
||||
if (!$chk) {
|
||||
return;
|
||||
}
|
||||
if ($chk[0]['count_' . $grid] < $count) {
|
||||
error_log("BuyShopGoodsCbService::_buyDailySelection() count not enough, address: $address, order_id: $order_id, item_id: $item_id, item_num: $item_num, idx: $idx, grid: $grid, count: $count");
|
||||
return;
|
||||
}
|
||||
|
||||
$sql = "UPDATE t_shop_dailyselection SET count_$grid = count_$grid - $count WHERE idx = $idx";
|
||||
$chk = $conn->execScript($sql);
|
||||
|
||||
if ($chk) {
|
||||
$this->_addGoods($address, array(
|
||||
'goods_id' => $item_id,
|
||||
'goods_num' => $item_num,
|
||||
));
|
||||
} else {
|
||||
error_log("BuyShopGoodsCbService::_buyDailySelection() decDailySelectionItem failed, address: $address, order_id: $order_id, item_id: $item_id, item_num: $item_num, idx: $idx, grid: $grid, count: $count");
|
||||
}
|
||||
}
|
||||
|
||||
error_log("callback buynormal address: $address, order_id: $order_id, goods_id: $item_id, goods_num: $item_num");
|
||||
if ($item_id == V_ITEM_DIAMOND) {
|
||||
$event = [
|
||||
'name' => LogService::CEBG_TO_DIAMOND,
|
||||
'val' => $item_num
|
||||
];
|
||||
LogService::productDiamondCallback(['account_id' => $account_id], $event);
|
||||
private function _addGoods($address, $goods)
|
||||
{
|
||||
$itemService = new ShopAddItemService();
|
||||
$item_id = $goods['goods_id'];
|
||||
$goods_num = $goods['goods_num'];
|
||||
|
||||
$id = null;
|
||||
if ($goods['id']) {
|
||||
$id = $goods['id'];
|
||||
}
|
||||
|
||||
error_log(json_encode($goods));
|
||||
error_log('_addGoods ' . $address . ' item_id ' . $item_id . ' goods_num ' . $goods_num . ' id ' . $id);
|
||||
$itemService->addItem($address, $item_id, $goods_num);
|
||||
if ($id) {
|
||||
ShopBuyRecord::addWithAddress($address, $id, $goods_num);
|
||||
}
|
||||
}
|
||||
|
||||
$this->_addGoods($address, array(
|
||||
'goods_id' => $item_id,
|
||||
'goods_num' => $item_num,
|
||||
'id' => $id,
|
||||
));
|
||||
}
|
||||
private function getAccountId($address)
|
||||
{
|
||||
|
||||
private function _buyDailySelection($order, $ext_data)
|
||||
{
|
||||
$self = myself();
|
||||
if (!$self) {
|
||||
return;
|
||||
$row = SqlHelper::ormSelectOne(
|
||||
myself()->_getMysql($address),
|
||||
't_user',
|
||||
array(
|
||||
'address' => $address
|
||||
)
|
||||
);
|
||||
|
||||
return $row['account_id'];
|
||||
}
|
||||
|
||||
$order_id = $order['order_id'];
|
||||
$item_id = $order['item_id'];
|
||||
$item_num = $order['item_num'];
|
||||
$address = $order['address'];
|
||||
$account_id = $this->getAccountId($address);
|
||||
$idx = $ext_data['idx'];
|
||||
$grid = $ext_data['grid'];
|
||||
$count = $ext_data['count'];
|
||||
|
||||
error_log("callback buyDailySelection address: $address, order_id: $order_id, item_id: $item_id, item_num: $item_num, idx: $idx, grid: $grid, count: $count");
|
||||
|
||||
$conn = $self->_getMysql($address);
|
||||
$sql = "SELECT count_$grid FROM t_shop_dailyselection WHERE idx = $idx";
|
||||
$chk = $conn->execQuery($sql);
|
||||
if (!$chk) {
|
||||
return;
|
||||
}
|
||||
if ($chk[0]['count_' . $grid] < $count) {
|
||||
error_log("BuyShopGoodsCbService::_buyDailySelection() count not enough, address: $address, order_id: $order_id, item_id: $item_id, item_num: $item_num, idx: $idx, grid: $grid, count: $count");
|
||||
return;
|
||||
}
|
||||
|
||||
$sql = "UPDATE t_shop_dailyselection SET count_$grid = count_$grid - $count WHERE idx = $idx";
|
||||
$chk = $conn->execScript($sql);
|
||||
|
||||
if ($chk) {
|
||||
$this->_addGoods($address, array(
|
||||
'goods_id' => $item_id,
|
||||
'goods_num' => $item_num,
|
||||
));
|
||||
} else {
|
||||
error_log("BuyShopGoodsCbService::_buyDailySelection() decDailySelectionItem failed, address: $address, order_id: $order_id, item_id: $item_id, item_num: $item_num, idx: $idx, grid: $grid, count: $count");
|
||||
}
|
||||
}
|
||||
|
||||
private function _addGoods($address, $goods)
|
||||
{
|
||||
$itemService = new ShopAddItemService();
|
||||
$item_id = $goods['goods_id'];
|
||||
$goods_num = $goods['goods_num'];
|
||||
|
||||
$id = null;
|
||||
if ($goods['id']) {
|
||||
$id = $goods['id'];
|
||||
}
|
||||
|
||||
error_log(json_encode($goods));
|
||||
error_log('_addGoods ' . $address . ' item_id ' . $item_id . ' goods_num ' . $goods_num . ' id ' . $id);
|
||||
$itemService->addItem($address, $item_id, $goods_num);
|
||||
if ($id) {
|
||||
ShopBuyRecord::addWithAddress($address, $id, $goods_num);
|
||||
}
|
||||
}
|
||||
|
||||
private function getAccountId($address)
|
||||
{
|
||||
|
||||
$row = SqlHelper::ormSelectOne(
|
||||
myself()->_getMysql($address),
|
||||
't_user',
|
||||
array(
|
||||
'address' => $address
|
||||
)
|
||||
);
|
||||
|
||||
return $row['account_id'];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user