1
This commit is contained in:
parent
006e5bf05a
commit
4282ea3c4a
@ -12,188 +12,188 @@ require_once('services/LogService.php');
|
||||
use phpcommon\SqlHelper;
|
||||
use models\ShopBuyRecord;
|
||||
|
||||
class GameItemMarketBuyOk
|
||||
{
|
||||
class GameItemMarketBuyOk {
|
||||
|
||||
public function process()
|
||||
{
|
||||
SignatureService::web3ServiceCheck();
|
||||
$itemService = new ShopAddItemService();
|
||||
$address = getReqVal('address', '');
|
||||
$orderId = getReqVal('order_id', '');
|
||||
|
||||
error_log("GameItemMallBuyOk-------------------");
|
||||
$orderDb = SqlHelper::ormSelectOne(
|
||||
myself()->_getMysql($address),
|
||||
't_bc_order',
|
||||
array(
|
||||
'order_id' => $orderId
|
||||
)
|
||||
);
|
||||
//1:已发货 2:订单不存在 3:订单模式错误
|
||||
if (!$orderDb) {
|
||||
echo json_encode(array(
|
||||
'errcode' => 2,
|
||||
'errmsg' => "Order does not exist",
|
||||
));
|
||||
die;
|
||||
}
|
||||
if ($orderDb['status'] == 1) {
|
||||
echo json_encode(array(
|
||||
'errcode' => 1,
|
||||
'errmsg' => "Order shipped",
|
||||
));
|
||||
die;
|
||||
}
|
||||
// 修改订单状态
|
||||
$this->_updateOrderState($address, $orderId);
|
||||
|
||||
$ext_data = json_decode($orderDb['ext_data'], true);
|
||||
|
||||
switch ($ext_data['mode']) {
|
||||
case MARKET_BUY_MODE_NORMAL: {
|
||||
$order = $orderDb;
|
||||
$itemService->addGameLog($order['address'], "marketBuyNormal", "begin", array(
|
||||
'param1' => $order['order_id'],
|
||||
'param2' => json_encode(array(
|
||||
'item_id' => $order['item_id'],
|
||||
'item_num' => $order['item_num'],
|
||||
)),
|
||||
));
|
||||
$this->buyFromMarket($order, $ext_data['idx']);
|
||||
$itemService->addGameLog($order['address'], "marketBuyNormal", "end", array(
|
||||
'param1' => $order['order_id'],
|
||||
'param2' => json_encode(array(
|
||||
'item_id' => $order['item_id'],
|
||||
'item_num' => $order['item_num'],
|
||||
)),
|
||||
));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// 这里不应该出现其他模式,内部错误
|
||||
echo json_encode(array(
|
||||
'errcode' => 3,
|
||||
'errmsg' => "order mode error.",
|
||||
));
|
||||
die();
|
||||
break;
|
||||
}
|
||||
|
||||
echo json_encode(array(
|
||||
'errcode' => 0,
|
||||
'errmsg' => "callback success",
|
||||
));
|
||||
}
|
||||
|
||||
private function _isVirtualItem($itemId)
|
||||
{
|
||||
return in_array(
|
||||
$itemId,
|
||||
array(
|
||||
V_ITEM_EXP,
|
||||
V_ITEM_PASS,
|
||||
V_ITEM_RESET_CARD,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private function _updateOrderState($address, $transId)
|
||||
{
|
||||
SqlHelper::update(
|
||||
myself()->_getMysql($address),
|
||||
't_bc_order',
|
||||
array(
|
||||
'order_id' => $transId
|
||||
),
|
||||
array(
|
||||
'status' => 1,
|
||||
'modifytime' => myself()->_getNowTime(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private function buyFromMarket($order, $idx)
|
||||
{
|
||||
$address = $order['address'];
|
||||
$account_id = $this->getAccountId($address);
|
||||
$goods = $this->getMarketGoods($address, $idx);
|
||||
$this->markMarketGoodsSold($address, $idx);
|
||||
|
||||
$this->_addGoods($address, $goods);
|
||||
public function process()
|
||||
{
|
||||
//埋点
|
||||
$event = [
|
||||
'name' => LogService::MARKET_BUY_GOLD,
|
||||
'val' => $goods['amount']
|
||||
];
|
||||
LogService::productGoldCallback(['account_id' => $account_id], $event );
|
||||
}
|
||||
}
|
||||
SignatureService::web3ServiceCheck();
|
||||
$itemService = new ShopAddItemService();
|
||||
$address = getReqVal('address', '');
|
||||
$orderId = getReqVal('order_id', '');
|
||||
|
||||
private function getMarketGoods($address, $idx)
|
||||
{
|
||||
$row = SqlHelper::selectOne(
|
||||
myself()->_getMysql($address),
|
||||
't_market_store',
|
||||
array('order_id', 'item_id', 'amount', 's_price', 'owner_address'),
|
||||
array(
|
||||
'idx' => $idx
|
||||
)
|
||||
);
|
||||
if (!$row) {
|
||||
return null;
|
||||
}
|
||||
if (!$row['item_id']) {
|
||||
return null;
|
||||
}
|
||||
return $row;
|
||||
}
|
||||
error_log("GameItemMallBuyOk-------------------");
|
||||
$orderDb = SqlHelper::ormSelectOne(
|
||||
myself()->_getMysql($address),
|
||||
't_bc_order',
|
||||
array(
|
||||
'order_id' => $orderId
|
||||
)
|
||||
);
|
||||
//1:已发货 2:订单不存在 3:订单模式错误
|
||||
if (!$orderDb) {
|
||||
echo json_encode(array(
|
||||
'errcode' => 2,
|
||||
'errmsg' => "Order does not exist",
|
||||
));
|
||||
die;
|
||||
}
|
||||
if ($orderDb['status'] == 1) {
|
||||
echo json_encode(array(
|
||||
'errcode' => 1,
|
||||
'errmsg' => "Order shipped",
|
||||
));
|
||||
die;
|
||||
}
|
||||
// 修改订单状态
|
||||
$this->_updateOrderState($address, $orderId);
|
||||
|
||||
private function markMarketGoodsSold($address, $idx)
|
||||
{
|
||||
SqlHelper::update(
|
||||
myself()->_getMysql($address),
|
||||
't_market_store',
|
||||
array(
|
||||
'idx' => $idx
|
||||
),
|
||||
array(
|
||||
'status' => 2,
|
||||
'modifytime' => myself()->_getNowTime(),
|
||||
)
|
||||
);
|
||||
}
|
||||
$ext_data = json_decode($orderDb['ext_data'], true);
|
||||
|
||||
private function _addGoods($address, $goods)
|
||||
{
|
||||
$itemService = new ShopAddItemService();
|
||||
$item_id = $goods['item_id'];
|
||||
$goods_num = $goods['amount'];
|
||||
switch ($ext_data['mode']) {
|
||||
case MARKET_BUY_MODE_NORMAL: {
|
||||
$order = $orderDb;
|
||||
$itemService->addGameLog($order['address'], "marketBuyNormal", "begin", array(
|
||||
'param1' => $order['order_id'],
|
||||
'param2' => json_encode(array(
|
||||
'item_id' => $order['item_id'],
|
||||
'item_num' => $order['item_num'],
|
||||
)),
|
||||
));
|
||||
$this->buyFromMarket($order, $ext_data['idx']);
|
||||
$itemService->addGameLog($order['address'], "marketBuyNormal", "end", array(
|
||||
'param1' => $order['order_id'],
|
||||
'param2' => json_encode(array(
|
||||
'item_id' => $order['item_id'],
|
||||
'item_num' => $order['item_num'],
|
||||
)),
|
||||
));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// 这里不应该出现其他模式,内部错误
|
||||
echo json_encode(array(
|
||||
'errcode' => 3,
|
||||
'errmsg' => "order mode error.",
|
||||
));
|
||||
die();
|
||||
break;
|
||||
}
|
||||
|
||||
$id = null;
|
||||
if (!empty($goods['id'])) {
|
||||
$id = $goods['id'];
|
||||
echo json_encode(array(
|
||||
'errcode' => 0,
|
||||
'errmsg' => "callback success",
|
||||
));
|
||||
}
|
||||
|
||||
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 _isVirtualItem($itemId)
|
||||
{
|
||||
return in_array(
|
||||
$itemId,
|
||||
array(
|
||||
V_ITEM_EXP,
|
||||
V_ITEM_PASS,
|
||||
V_ITEM_RESET_CARD,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private function getAccountId($address){
|
||||
private function _updateOrderState($address, $transId)
|
||||
{
|
||||
SqlHelper::update(
|
||||
myself()->_getMysql($address),
|
||||
't_bc_order',
|
||||
array(
|
||||
'order_id' => $transId
|
||||
),
|
||||
array(
|
||||
'status' => 1,
|
||||
'modifytime' => myself()->_getNowTime(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$row = SqlHelper::ormSelectOne
|
||||
(myself()->_getMysql($address),
|
||||
't_user',
|
||||
array(
|
||||
'address' => $address
|
||||
)
|
||||
);
|
||||
private function buyFromMarket($order, $idx)
|
||||
{
|
||||
$address = $order['address'];
|
||||
$account_id = $this->getAccountId($address);
|
||||
$goods = $this->getMarketGoods($address, $idx);
|
||||
$this->markMarketGoodsSold($address, $idx);
|
||||
|
||||
$this->_addGoods($address, $goods);
|
||||
{
|
||||
//埋点
|
||||
$event = [
|
||||
'name' => LogService::MARKET_BUY_GOLD,
|
||||
'val' => $goods['amount']
|
||||
];
|
||||
LogService::productGoldCallback(['account_id' => $account_id], $event );
|
||||
}
|
||||
}
|
||||
|
||||
private function getMarketGoods($address, $idx)
|
||||
{
|
||||
$row = SqlHelper::selectOne(
|
||||
myself()->_getMysql($address),
|
||||
't_market_store',
|
||||
array('order_id', 'item_id', 'amount', 's_price', 'owner_address'),
|
||||
array(
|
||||
'idx' => $idx
|
||||
)
|
||||
);
|
||||
if (!$row) {
|
||||
return null;
|
||||
}
|
||||
if (!$row['item_id']) {
|
||||
return null;
|
||||
}
|
||||
return $row;
|
||||
}
|
||||
|
||||
private function markMarketGoodsSold($address, $idx)
|
||||
{
|
||||
SqlHelper::update(
|
||||
myself()->_getMysql($address),
|
||||
't_market_store',
|
||||
array(
|
||||
'idx' => $idx
|
||||
),
|
||||
array(
|
||||
'status' => 2,
|
||||
'modifytime' => myself()->_getNowTime(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private function _addGoods($address, $goods)
|
||||
{
|
||||
$itemService = new ShopAddItemService();
|
||||
$item_id = $goods['item_id'];
|
||||
$goods_num = $goods['amount'];
|
||||
|
||||
$id = null;
|
||||
if (!empty($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'];
|
||||
}
|
||||
|
||||
return $row['account_id'];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user