This commit is contained in:
songliang 2023-07-10 17:38:36 +08:00
parent 8f06131b7a
commit cf33b30174
4 changed files with 96 additions and 9 deletions

View File

@ -28,7 +28,7 @@ require_once('services/BlockChainService.php');
require_once('phpcommon/bignumber.php');
require_once('services/LogService.php');
require_once('ShopAddItemService.php');
require_once('services/callback/ShopAddItemService.php');
// use phpcommon;
use phpcommon\HttpClient;
@ -193,9 +193,16 @@ class ShopController extends BaseAuthedController
{
$id = getReqVal('id', 0);
$token_type = getReqVal('token_type', '');
$goods_num = getReqVal('goods_num', 0);
$goods_num = getReqVal('goods_num', 1);
if ($goods_num <= 0) {
$this->_rspErr(1, 'goods_num is invalid');
}
$goods = mt\ShopGoods::get($id);
if ($goods['shop_id'] == 9 && $goods_num > 1) {
$this->_rspErr(1, 'goods_num is invalid');
}
$conn = myself()->_getMysql('');
@ -363,6 +370,25 @@ class ShopController extends BaseAuthedController
public function inappPurchaseDiamonds()
{
// {
// 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)
// 有三种情况:
// 1. 从商城购买钻石,有订单号
// 2. 站外充值钻石,没有订单号
@ -372,6 +398,22 @@ class ShopController extends BaseAuthedController
error_log('----- inappPurchaseDiamonds -----');
$data = [
'channel' => 'google',
'sign' => '123456677',
'records' => [[
'productId' => '2999', // 从google play console获取的product id
'gameOrderId' => '299', // 开始支付时, 从游戏相关服务那获得的订单id
'orderId' => 'GPA.3355-1172-9416-16839', // 从google develope API 获取的订单id
'status' => 9, // 订单状态, 上报的订单状态一般只有2种情况, 9: 支付成功, 96: 用户退款
]]
];
$order_id = $data['records'][0]['gameOrderId'];
$data_str = json_encode($data);
$data_json = json_decode($data_str, true);
error_log('----- inappPurchaseDiamonds -----' . json_encode($data));
$conn = myself()->_getMysql('');
$order = SqlHelper::selectOne($conn, 't_shop_buy_order', array('address', 'id', 'item_id', 'goods_num', 'status'), array('idx' => $order_id));
@ -388,13 +430,14 @@ class ShopController extends BaseAuthedController
$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($event);
LogService::productDiamond(['account_id' => $account_id], $event);
}
$this->_addGoods($address, array(
@ -406,6 +449,18 @@ class ShopController extends BaseAuthedController
$this->_rspOk();
}
private function getAccountId($address)
{
$row = SqlHelper::ormSelectOne(
myself()->_getMysql($address),
't_user',
array(
'address' => $address
)
);
return $row['account_id'];
}
private function _addGoods($address, $goods)
{
$itemService = new ShopAddItemService();

View File

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

View File

@ -82,10 +82,10 @@ class LogService extends BaseService
TGLog::writeToLog(self::PRONAME,self::GAMEID,$logInfo);
}
public static function productDiamond($event,$param = [])
public static function productDiamond($base, $event,$param = [])
{
$logInfo = self::goldRecord();
$data = self::userInfo();
$logInfo = self::diamondRecord($base['account_id']);
$data = self::userInfoByAccountId($base['account_id']);
$data['type'] = self::PRODUCT_TYPE;
$data['event_name'] = $event['name'];
$data['event_type'] = self::DIAMOND_TYPE;
@ -117,6 +117,24 @@ class LogService extends BaseService
return $info;
}
private static function userInfoByAccountId($account_id) {
$user = User::find($account_id);
$info = array(
'account_id' => $user['account_id'], //账号id
'channel' => $user['channel'], //账号channel
'openid' => 'unknown',
'adress' => $user['address'], //账号openid
'name' => $user['name'], //用户名字
'rank' => $user['rank'], //段位
'gold' => $user['gold'], //金币
'diamond' => $user['diamond'], //钻石
'account_register_time' => $user['createtime'], //账号注册时间
'ip' => $_SERVER['REMOTE_ADDR'], //用户ip
'_os' => getReqVal('_os', ''),
'_net' => getReqVal('_net', ''),
);
return $info;
}
private static function goldRecord()
{
// $logInfo['log_class'] = $logInfo['log_class'];
@ -132,4 +150,16 @@ class LogService extends BaseService
return $data;
}
private static function diamondRecord($account_id)
{
$data = [
"#account_id" => $account_id,
"#event_name"=> "diamond_record",
"#ip"=> $_SERVER['REMOTE_ADDR'],
"#time"=> myself()->_getNowTime(),
"#type"=> "track",
"properties"=>''
];
return $data;
}
}

View File

@ -76,6 +76,7 @@ class BuyShopGoodsCbService
$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;
@ -89,7 +90,7 @@ class BuyShopGoodsCbService
'name' => LogService::CEBG_TO_DIAMOND,
'val' => $item_num
];
LogService::productDiamond($event);
LogService::productDiamond(['account_id' => $account_id], $event);
}
$this->_addGoods($address, array(
@ -110,6 +111,7 @@ class BuyShopGoodsCbService
$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'];