This commit is contained in:
aozhiwei 2023-08-07 16:14:54 +08:00
parent 006e5bf05a
commit 4282ea3c4a

View File

@ -12,188 +12,188 @@ require_once('services/LogService.php');
use phpcommon\SqlHelper; use phpcommon\SqlHelper;
use models\ShopBuyRecord; use models\ShopBuyRecord;
class GameItemMarketBuyOk class GameItemMarketBuyOk {
{
public function process() 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);
{ {
//埋点 SignatureService::web3ServiceCheck();
$event = [ $itemService = new ShopAddItemService();
'name' => LogService::MARKET_BUY_GOLD, $address = getReqVal('address', '');
'val' => $goods['amount'] $orderId = getReqVal('order_id', '');
];
LogService::productGoldCallback(['account_id' => $account_id], $event );
}
}
private function getMarketGoods($address, $idx) error_log("GameItemMallBuyOk-------------------");
{ $orderDb = SqlHelper::ormSelectOne(
$row = SqlHelper::selectOne( myself()->_getMysql($address),
myself()->_getMysql($address), 't_bc_order',
't_market_store', array(
array('order_id', 'item_id', 'amount', 's_price', 'owner_address'), 'order_id' => $orderId
array( )
'idx' => $idx );
) //1已发货 2订单不存在 3订单模式错误
); if (!$orderDb) {
if (!$row) { echo json_encode(array(
return null; 'errcode' => 2,
} 'errmsg' => "Order does not exist",
if (!$row['item_id']) { ));
return null; die;
} }
return $row; if ($orderDb['status'] == 1) {
} echo json_encode(array(
'errcode' => 1,
'errmsg' => "Order shipped",
));
die;
}
// 修改订单状态
$this->_updateOrderState($address, $orderId);
private function markMarketGoodsSold($address, $idx) $ext_data = json_decode($orderDb['ext_data'], true);
{
SqlHelper::update(
myself()->_getMysql($address),
't_market_store',
array(
'idx' => $idx
),
array(
'status' => 2,
'modifytime' => myself()->_getNowTime(),
)
);
}
private function _addGoods($address, $goods) switch ($ext_data['mode']) {
{ case MARKET_BUY_MODE_NORMAL: {
$itemService = new ShopAddItemService(); $order = $orderDb;
$item_id = $goods['item_id']; $itemService->addGameLog($order['address'], "marketBuyNormal", "begin", array(
$goods_num = $goods['amount']; '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; echo json_encode(array(
if (!empty($goods['id'])) { 'errcode' => 0,
$id = $goods['id']; 'errmsg' => "callback success",
));
} }
error_log(json_encode($goods)); private function _isVirtualItem($itemId)
error_log('_addGoods ' . $address . ' item_id ' . $item_id . ' goods_num ' . $goods_num . ' id ' . $id); {
$itemService->addItem($address, $item_id, $goods_num); return in_array(
if ($id) { $itemId,
ShopBuyRecord::addWithAddress($address, $id, $goods_num); 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 private function buyFromMarket($order, $idx)
(myself()->_getMysql($address), {
't_user', $address = $order['address'];
array( $account_id = $this->getAccountId($address);
'address' => $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'];
}
} }