Merge branch 'star' of git.kingsome.cn:server/game2006api into star

This commit is contained in:
hujiabin 2023-07-13 16:19:04 +08:00
commit 27df407ba0
9 changed files with 571 additions and 19 deletions

View File

@ -4,6 +4,12 @@ class CallbackController extends BaseController {
private $handlers = array( private $handlers = array(
'gameItemMallBuyOk' => 'GameItemMallBuyOk', 'gameItemMallBuyOk' => 'GameItemMallBuyOk',
'eventSellOrder' => 'eventSellOrder',
'eventBuyOrder' => 'eventBuyOrder',
'eventCancelOrder' => 'eventCancelOrder',
'eventPriceUpdateOrder' => 'eventPriceUpdateOrder',
'buyGoodsDirect' => 'buyGoodsDirect',
'inappPurchaseDiamonds' => 'inappPurchaseDiamonds',
); );
public function dispatch() public function dispatch()

View File

@ -347,7 +347,7 @@ class MarketController extends BaseAuthedController
return ''; return '';
}; };
$conn = myself()->_getSelfMysql(''); $conn = myself()->_getSelfMysql();
$counts = $conn->execQuery( $counts = $conn->execQuery(
'SELECT count(idx) as count FROM t_market_store ' . 'SELECT count(idx) as count FROM t_market_store ' .
@ -518,7 +518,7 @@ class MarketController extends BaseAuthedController
$signature = getReqVal('signature', ''); $signature = getReqVal('signature', '');
$net_id = getReqVal('net_id', ''); $net_id = getReqVal('net_id', '');
$conn = myself()->_getSelfMysql(''); $conn = myself()->_getSelfMysql();
$nftDb = null; $nftDb = null;
@ -610,7 +610,7 @@ class MarketController extends BaseAuthedController
return; return;
} }
$conn = $this->_getSelfMysql(''); $conn = $this->_getSelfMysql();
$r = SqlHelper::update( $r = SqlHelper::update(
$conn, $conn,
't_market_store', 't_market_store',
@ -648,7 +648,7 @@ class MarketController extends BaseAuthedController
return; return;
} }
$conn = $this->_getSelfMysql(''); $conn = $this->_getSelfMysql();
$r = SqlHelper::update( $r = SqlHelper::update(
$conn, $conn,
't_market_store', 't_market_store',
@ -717,7 +717,7 @@ class MarketController extends BaseAuthedController
$signature = getReqVal('signature', ''); $signature = getReqVal('signature', '');
$net_id = getReqVal('net_id', ''); $net_id = getReqVal('net_id', '');
$conn = myself()->_getSelfMysql(''); $conn = myself()->_getSelfMysql();
$nftDb = Nft::findNftByOwner($account, $nft_token); $nftDb = Nft::findNftByOwner($account, $nft_token);
$nftDetail = Nft::toDto($nftDb); $nftDetail = Nft::toDto($nftDb);
@ -758,7 +758,7 @@ class MarketController extends BaseAuthedController
$signature = getReqVal('signature', ''); $signature = getReqVal('signature', '');
$net_id = getReqVal('net_id', ''); $net_id = getReqVal('net_id', '');
$conn = myself()->_getSelfMysql(''); $conn = myself()->_getSelfMysql();
$conn->execScript('DELETE FROM t_market_store WHERE ' . 'token_id=\'' . $nft_token . '\''); $conn->execScript('DELETE FROM t_market_store WHERE ' . 'token_id=\'' . $nft_token . '\'');
$this->_rspOk(); $this->_rspOk();
@ -790,7 +790,7 @@ class MarketController extends BaseAuthedController
$start = getReqVal('start', 0); $start = getReqVal('start', 0);
$page_size = getReqVal('page_size', 10); $page_size = getReqVal('page_size', 10);
$page_size = max(1, min(100, $page_size)); $page_size = max(1, min(100, $page_size));
$conn = myself()->_getSelfMysql(''); $conn = myself()->_getSelfMysql();
$type_filter_fn = function ($f) { $type_filter_fn = function ($f) {
if ($f == 0) { if ($f == 0) {
@ -877,7 +877,7 @@ class MarketController extends BaseAuthedController
) )
); );
$conn = myself()->_getSelfMysql(''); $conn = myself()->_getSelfMysql();
// 1. check order status // 1. check order status
$chk = SqlHelper::selectOne($conn, 't_market_store', array('status'), array('o_link' => $orderId)); $chk = SqlHelper::selectOne($conn, 't_market_store', array('status'), array('o_link' => $orderId));
@ -954,7 +954,7 @@ class MarketController extends BaseAuthedController
) )
); );
$conn = myself()->_getSelfMysql(''); $conn = myself()->_getSelfMysql();
// 1. check order status // 1. check order status
$chk = SqlHelper::selectOne($conn, 't_market_store', array('status', 'idx', 'c_name', 'token_type'), array('o_link' => $orderId)); $chk = SqlHelper::selectOne($conn, 't_market_store', array('status', 'idx', 'c_name', 'token_type'), array('o_link' => $orderId));
@ -1010,7 +1010,7 @@ class MarketController extends BaseAuthedController
) )
); );
$conn = myself()->_getSelfMysql(''); $conn = myself()->_getSelfMysql();
// 1. check order status // 1. check order status
$chk = SqlHelper::selectOne($conn, 't_market_store', array('status'), array('o_link' => $orderId)); $chk = SqlHelper::selectOne($conn, 't_market_store', array('status'), array('o_link' => $orderId));
@ -1057,7 +1057,7 @@ class MarketController extends BaseAuthedController
) )
); );
$conn = myself()->_getSelfMysql(''); $conn = myself()->_getSelfMysql();
// 1. check order status // 1. check order status
$chk = SqlHelper::selectOne($conn, 't_market_store', array('status'), array('o_link' => $orderId)); $chk = SqlHelper::selectOne($conn, 't_market_store', array('status'), array('o_link' => $orderId));
@ -1132,7 +1132,7 @@ class MarketController extends BaseAuthedController
private function attach_market_selling(&$row) private function attach_market_selling(&$row)
{ {
$conn = myself()->_getSelfMysql(''); $conn = myself()->_getSelfMysql();
$rows = $conn->execQuery( $rows = $conn->execQuery(
'SELECT * FROM t_market_store ' . 'SELECT * FROM t_market_store ' .
@ -1159,7 +1159,7 @@ class MarketController extends BaseAuthedController
{ {
// error_log('listMySelledNfts ' . $account . ' ' . $type); // error_log('listMySelledNfts ' . $account . ' ' . $type);
$conn = myself()->_getSelfMysql(''); $conn = myself()->_getSelfMysql();
$rows = $conn->execQuery( $rows = $conn->execQuery(
'SELECT * FROM t_market_store ' . 'SELECT * FROM t_market_store ' .
@ -1268,7 +1268,7 @@ class MarketController extends BaseAuthedController
private function updateUserInfo($address, $fieldKv) private function updateUserInfo($address, $fieldKv)
{ {
$r = SqlHelper::update( $r = SqlHelper::update(
myself()->_getSelfMysql(''), myself()->_getSelfMysql(),
't_user', 't_user',
array( array(
'address' => $address, 'address' => $address,
@ -1309,7 +1309,7 @@ class MarketController extends BaseAuthedController
// return null; // return null;
// } // }
$conn = myself()->_getSelfMysql($address); $conn = myself()->_getMysql($address);
$row = SqlHelper::selectOne( $row = SqlHelper::selectOne(
$conn, $conn,
't_user', 't_user',
@ -1328,7 +1328,7 @@ class MarketController extends BaseAuthedController
private function getAccountId($address) private function getAccountId($address)
{ {
$row = SqlHelper::selectOne( $row = SqlHelper::selectOne(
myself()->_getSelfMysql($address), myself()->_getMysql($address),
't_user', 't_user',
array('account_id'), array('account_id'),
array( array(
@ -1352,7 +1352,7 @@ class MarketController extends BaseAuthedController
private function getGoodsByIdx($idx) private function getGoodsByIdx($idx)
{ {
$row = SqlHelper::selectOne( $row = SqlHelper::selectOne(
myself()->_getSelfMysql(''), myself()->_getSelfMysql(),
't_market_store', 't_market_store',
array('item_id', 'amount', 's_price', 'owner_address'), array('item_id', 'amount', 's_price', 'owner_address'),
array( array(
@ -1372,7 +1372,7 @@ class MarketController extends BaseAuthedController
private function markOrderBuyStatus($idx) private function markOrderBuyStatus($idx)
{ {
$r = SqlHelper::update( $r = SqlHelper::update(
myself()->_getSelfMysql(''), myself()->_getSelfMysql(),
't_market_store', 't_market_store',
array( array(
'idx' => $idx, 'idx' => $idx,

View File

@ -10,7 +10,7 @@ use phpcommon\SqlHelper;
class BuyRecord extends BaseModel { class BuyRecord extends BaseModel {
public static function genOrderId($gameId, $funcId, $time, $®) public static function genOrderId($gameId, $funcId, $time, $buyerAddress)
{ {
SqlHelper::insert SqlHelper::insert
(myself()->_getMarketMysql(), (myself()->_getMarketMysql(),

View File

@ -0,0 +1,75 @@
<?php
namespace services;
class MarketBuyOrderOk
{
public function process()
{
error_log('MarketBuyOrderOk:' . json_encode($_REQUEST, JSON_PRETTY_PRINT));
$tokenId = getReqVal('tokenId', '');
$orderId = getReqVal('orderId', '');
$nftToken = getReqVal('nftToken', '');
$amount = getReqVal('amount', 0);
$seller = strtolower(getReqVal('seller', ''));
$buyer = strtolower(getReqVal('buyer', ''));
$erc20 = getReqVal('erc20', '');
$price = getReqVal('price', '');
error_log(
"eventBuyOrder:" . json_encode(
array(
'tokenId' => $tokenId,
'orderId' => $orderId,
'nftToken' => $nftToken,
'amount' => $amount,
'seller' => $seller,
'buyer' => $buyer,
'erc20' => $erc20,
'price' => $price,
),
JSON_PRETTY_PRINT
)
);
$conn = myself()->_getSelfMysql();
// 1. check order status
$chk = SqlHelper::selectOne($conn, 't_market_store', array('status', 'idx', 'c_name', 'token_type'), array('o_link' => $orderId));
if (empty($chk)) {
$this->_rspErr(1, 'not found order, orderId=' . $orderId);
return;
}
if ($chk['status'] == '0') {
$r = SqlHelper::update(
$conn,
't_market_store',
array(
'o_link' => $orderId,
),
array(
'status' => 2,
)
);
if ($r) {
// 增加交易记录
$record = array(
'createtime' => myself()->_getNowTime(),
'orderid' => $chk['idx'],
'o_link' => $orderId,
'seller' => $seller,
'buyer' => $buyer,
'tokenid' => $tokenId,
'amount' => $amount,
'name' => $chk['c_name'],
'type' => $chk['token_type'],
);
$this->addTransactionRecord($record);
$this->_rspOk();
return;
}
}
$this->_rspErr(1, 'order status error, order=' . $orderId);
}
}

View File

@ -0,0 +1,51 @@
<?php
namespace services;
class MarketCancelOrderOk
{
public function process()
{
error_log('MarketCancelOrderOk:' . json_encode($_REQUEST, JSON_PRETTY_PRINT));
$orderId = getReqVal('orderId', '');
$nftToken = getReqVal('nftToken', '');
$tokenId = getReqVal('tokenId', '');
error_log(
"eventCancelOrder:" . json_encode(
array(
'orderId' => $orderId,
'nftToken' => $nftToken,
'tokenId' => $tokenId,
),
JSON_PRETTY_PRINT
)
);
$conn = myself()->_getSelfMysql();
// 1. check order status
$chk = SqlHelper::selectOne($conn, 't_market_store', array('status'), array('o_link' => $orderId));
if (empty($chk)) {
$this->_rspErr(1, 'not found order, orderId=' . $orderId);
return;
}
if ($chk['status'] == '0') {
$r = SqlHelper::update(
$conn,
't_market_store',
array(
'o_link' => $orderId,
),
array(
'status' => 1,
)
);
if ($r) {
$this->_rspOk();
return;
}
}
$this->_rspErr(1, 'order status error, order=' . $orderId);
}
}

View File

@ -0,0 +1,57 @@
<?php
namespace services;
class MarketPriceUpdateOrderOk
{
public function process()
{
error_log('MarketPriceUpdateOrderOk:' . json_encode($_REQUEST, JSON_PRETTY_PRINT));
$orderId = getReqVal('orderId', '');;
$nftToken = getReqVal('nftToken', '');
$tokenId = getReqVal('tokenId', '');
$priceOld = getReqVal('priceOld', '');
$price = getReqVal('price', '');
error_log(
"eventPriceUpdateOrder:" . json_encode(
array(
'orderId' => $orderId,
'nftToken' => $nftToken,
'tokenId' => $tokenId,
'priceOld' => $priceOld,
'price' => $price,
),
JSON_PRETTY_PRINT
)
);
$conn = myself()->_getSelfMysql();
// 1. check order status
$chk = SqlHelper::selectOne($conn, 't_market_store', array('status'), array('o_link' => $orderId));
if (empty($chk)) {
$this->_rspErr(1, 'not found order, orderId=' . $orderId);
return;
}
if ($chk['status'] == '0') {
$r = SqlHelper::update(
$conn,
't_market_store',
array(
'o_link' => $orderId,
),
array(
's_price' => $price,
)
);
if ($r) {
$this->_rspOk();
return;
}
}
$this->_rspErr(1, 'price update failed, orderId=' . $orderId);
}
}

View File

@ -0,0 +1,83 @@
<?php
namespace services;
class MarketSellOrderOk
{
public function process()
{
error_log('MarketSellOrderOk:' . json_encode($_REQUEST, JSON_PRETTY_PRINT));
$tokenId = getReqVal('tokenId', '');
$owner = strtolower(getReqVal('owner', ''));
$nftToken = getReqVal('nftToken', '');
$amount = getReqVal('amount', 0);
$orderId = getReqVal('orderId', '');
$currency = getReqVal('currency', '');
$price = getReqVal('price', '');
error_log(
"eventSellOrder:" . json_encode(
array(
'tokenId' => $tokenId,
'owner' => $owner,
'nftToken' => $nftToken,
'amount' => $amount,
'orderId' => $orderId,
'currency' => $currency,
'price' => $price,
),
JSON_PRETTY_PRINT
)
);
$conn = myself()->_getSelfMysql();
// 1. check order status
$chk = SqlHelper::selectOne($conn, 't_market_store', array('status'), array('o_link' => $orderId));
if (!empty($chk)) {
$this->_rspErr(1, 'repeat sell order, orderId=' . $orderId);
return;
}
// 2. insert sell order to t_market_store
$nftDb = Nft::findNftByOwner($owner, $tokenId);
if (empty($nftDb)) {
$nftDb = Nft::getNft($tokenId);
}
$nftDetail = Nft::toDto($nftDb);
$detail = $this->getNftGameData($nftDb);
$r = SqlHelper::insert(
$conn,
't_market_store',
array(
'token_id' => $tokenId,
'o_link' => $orderId,
'nft_token' => $nftToken,
'status' => 0,
'owner_address' => $owner,
'token_type' => $nftDetail['type'],
'amount' => $amount,
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime(),
's_currency' => $currency,
's_price' => $price,
'c_name' => $nftDetail['info']['name'],
'c_job' => isset($nftDetail['info']['job']) ? $nftDetail['info']['job']
: (isset($detail['chip_type']) ? $detail['chip_type']
: (isset($detail['type']) ? $detail['type']
: 0)),
'c_lv' => @$detail['gun_lv'] | @$detail['hero_lv'] | @$detail['chip_grade'],
'c_quality' => isset($nftDetail['info']['quality']) ? $nftDetail['info']['quality'] : 0,
'c_durability' => isset($nftDetail['info']['durability']) ? $nftDetail['info']['durability'] : (isset($detail['hero_tili']) ? $detail['hero_tili'] : 0),
'c_type' => isset($detail['type']) ? $detail['type'] : 0,
'c_id' => $nftDetail['item_id'],
)
);
if (!$r) {
$this->_rspErr(2, 'unknown error, orderId=' . $orderId);
}
$this->_rspOk();
}
}

View File

@ -0,0 +1,105 @@
<?php
namespace services;
class ShopBuyGoodsDirect
{
public function process()
{
error_log('ShopBuyGoodsDirect:' . json_encode($_REQUEST, JSON_PRETTY_PRINT));
// let repdata = {
// account_id: string
// order_id: string
// status: string
// id: string
// txhash: string
// }
// 我返回给你这些数据和一个sign字段,
// sign使用上面 repdata 按key 顺序排后, 组成key1=val1&key2=val2后, 使用hmac_sha256 hash, key是 iG4Rpsa)6U31$H#^T85$^^3
// PENDING = 0, // 初始状态
// TRANSFERING = 1, //只有国库模式才会有该状态
// TRANSFERED = 2, //只有国库模式才会有该状态
// SUCCESS = 9, // 成功的最终状态
// TRANSFER_FAIL = 98, // 转账错误
// FAIL = 99, // 也是错误
//
$account_id = getReqVal('account_id', '');
$order_id = getReqVal('order_id', '');
$status = getReqVal('status', '');
$id = getReqVal('id', '');
$txhash = getReqVal('txhash', '');
$sign = getReqVal('sign', '');
$data = array(
'account_id' => $account_id,
'id' => $id,
'order_id' => $order_id,
'status' => $status,
'txhash' => $txhash,
);
$hash_data = http_build_query($data);
$signature = hash_hmac('sha256', $hash_data, 'iG4Rpsa)6U31$H#^T85$^^3');
if ($signature != $sign) {
$this->_rspErr(1, "signature error, signature: {$signature}, sign: {$sign}");
return;
}
error_log("buyGoodsDirect-------" . $order_id . "---" . $status);
$conn = myself()->_getMysql('');
$order = SqlHelper::selectOne($conn, 't_shop_buy_order', array('address', 'item_id', 'goods_num', 'status'), array('idx' => $order_id));
$id = $order['item_id'];
$goods_num = $order['goods_num'];
$o_status = $order['status'];
if ($o_status != 0) {
$this->_rspErr(1, "order status error, status: {$o_status}");
return;
}
$buyStatus = 0; // 1: 成功, 2: 失败
switch ($status) {
case "9":
$buyStatus = 1;
break;
case "99":
case "98":
$buyStatus = 2;
break;
}
SqlHelper::update($conn, 't_shop_buy_order', array('idx' => $order_id), array('status' => $buyStatus));
$goods = mt\ShopGoods::get($id);
// 这里命名混乱了, 购买个数,一捆个数命名冲突
$goods_num = $order['goods_num'];
$bundle_size = $goods['bonus_num'];
$item_num = $goods_num * $bundle_size;
$item_id = $goods['bonus'];
$address = $order['address'];
$account_id = $this->getAccountId($address);
if ($item_id == V_ITEM_DIAMOND) {
$event = [
'name' => LogService::RECHARGE_CEBG_BONUS,
'val' => $item_num
];
LogService::productDiamond(['account_id' => $account_id], $event);
}
$this->_addGoods($address, array(
'goods_id' => $item_id,
'goods_num' => $item_num,
'id' => $id,
));
$this->_rspOk();
}
}

View File

@ -0,0 +1,175 @@
<?php
namespace services;
class ShopInappPurchaseDiamonds
{
public function process()
{
error_log('ShopInappPurchaseDiamonds:' . json_encode($_REQUEST, JSON_PRETTY_PRINT));
error_log('----- inappPurchaseDiamonds -----');
$body = json_decode(file_get_contents('php://input'), true);
error_log('body:' . json_encode($body));
$channel = $body['channel'];
$records = $body['records'];
$sign = $body['sign'];
// {
// channel: 'google',
// sign: '123456677' // 签名字段
// records: [{
// productId: '2999', // 从google play console获取的product id
// gameOrderId: '1231321312', // 开始支付时, 从游戏相关服务那获得的订单id
// orderId: 'GPA.3355-1172-9416-16839', // 从google develope API 获取的订单id
// status: 9, // 订单状态, 上报的订单状态一般只有2种情况, 9: 支付成功, 96: 用户退款
// }]
// }
// let reportData: any = {
// channel: 'google',
// records,
// }
// const hashSort = 'iG4Rpsa)6U31$H#^T85$^^3'
// const signStr = 'channel=google&' + records.map(record =>Object.keys(record).sort().map(key => `${key}=${record[key]}`).join('&')).join('&')
// const sign = hmacsha256(signStr, hashSort)
// 定义一个空数组,用来存放每个记录的键值对字符串
$record_strings = array();
// 遍历 records 数组,对每个记录进行排序和拼接
foreach ($records as $record) {
// 对记录的键进行升序排序
ksort($record);
// 把记录的键值对用等号连接,然后用 & 连接成一个字符串
$record_string = http_build_query($record);
// 把字符串加入到 record_strings 数组中
$record_strings[] = $record_string;
}
// 把 record_strings 数组用 & 连接成一个字符串
$records_string = implode("&", $record_strings);
$hash_data = 'channel=' . $channel . '&' . $records_string;
$signature = hash_hmac('sha256', $hash_data, 'iG4Rpsa)6U31$H#^T85$^^3');
if ($signature != $sign) {
$this->_rspErr(1, "signature error, signature: {$signature}, sign: {$sign}");
return;
}
$conn = myself()->_getMysql('');
// 有三种情况:
// 1. 从商城购买钻石,有订单号
// 2. 站外充值钻石,没有订单号
// 3. appstore 退款,没有订单号
for ($i = 0; $i < count($records); $i++) {
$record = $records[$i];
$product_id = $record['productId'];
$order_id = $record['gameOrderId'];
$out_order_id = $record['orderId'];
$status = $record['status'];
switch ($status) {
case 9: {
$status = 1;
if (empty($order_id)) {
if (empty($product_id)) {
$this->_rspErr(2, "product_id is empty");
return;
}
// $goods = mt\ShopGoods::getByProductId($product_id);
return;
}
$order = SqlHelper::selectOne($conn, 't_web2_order', array('address', 'id', 'item_id', 'goods_num', 'status'), array('order_id' => $order_id, 'status' => 0));
error_log('process order ' . json_encode($order));
if (!$order) {
$this->_rspErr(3, "order not found, order_id: {$order_id}");
return;
}
SqlHelper::update($conn, 't_web2_order', array('order_id' => $order_id), array('status' => $status, 'channel' => $channel, 'out_order_id' => $out_order_id));
$id = $order['id'];
$goods = mt\ShopGoods::get($id);
// 这里命名混乱了, 购买个数,一捆个数命名冲突
$goods_num = $order['goods_num'];
$bundle_size = $goods['goods_num'];
$item_num = $goods_num * $bundle_size;
$item_id = $goods['goods_id'];
$address = $order['address'];
$account_id = $this->getAccountId($address);
if ($item_id == V_ITEM_DIAMOND) {
$event = [
'name' => LogService::RECHARGE_DIAMOND,
'val' => $item_num
];
LogService::productDiamond(['account_id' => $account_id], $event);
}
$this->_addGoods($address, array(
'goods_id' => $item_id,
'goods_num' => $item_num,
'id' => $id,
));
}
break;
case 96:
$status = 3;
if (empty($order_id)) {
if (empty($product_id)) {
$this->_rspErr(2, "product_id is empty");
return;
}
// $goods = mt\ShopGoods::getByProductId($product_id);
return;
}
// 退款
$order = SqlHelper::selectOne($conn, 't_web2_order', array('address', 'id', 'item_id', 'goods_num', 'status'), array('order_id' => $order_id, 'status' => 1));
if (!$order) {
$this->_rspErr(3, "order not found, order_id: {$order_id}");
return;
}
SqlHelper::update($conn, 't_web2_order', array('order_id' => $order_id), array('status' => $status));
$id = $order['id'];
$goods = mt\ShopGoods::get($id);
// 这里命名混乱了, 购买个数,一捆个数命名冲突
$goods_num = $order['goods_num'];
$bundle_size = $goods['goods_num'];
$item_num = $goods_num * $bundle_size;
$item_id = $goods['goods_id'];
$address = $order['address'];
$account_id = $this->getAccountId($address);
if ($item_id == V_ITEM_DIAMOND) {
$event = [
'name' => LogService::RECHARGE_DIAMOND,
'val' => -$item_num
];
LogService::productDiamond(['account_id' => $account_id], $event);
}
$this->_decGoods($address, array(
'goods_id' => $item_id,
'goods_num' => $item_num,
'id' => $id,
));
break;
default:
$status = 0;
break;
}
}
$this->_rspOk();
}
}