1
This commit is contained in:
parent
d04628622d
commit
06032da236
@ -89,17 +89,6 @@ class ShopController extends BaseAuthedController
|
||||
const WEEKLY_BUY_LIMIT = 2;
|
||||
const TOTAL_BUY_LIMIT = 3;
|
||||
|
||||
public function _handlePre()
|
||||
{
|
||||
$a = getReqVal('a', '');
|
||||
if (
|
||||
$a != 'buyGoodsDirect' &&
|
||||
$a != 'inappPurchaseDiamonds'
|
||||
) {
|
||||
parent::_handlePre();
|
||||
}
|
||||
}
|
||||
|
||||
public function getGoodsList()
|
||||
{
|
||||
$shop_id = getReqVal('shop_id', 0);
|
||||
@ -268,132 +257,6 @@ class ShopController extends BaseAuthedController
|
||||
}
|
||||
}
|
||||
|
||||
// callback from (hongliang) server
|
||||
public function buyGoodsDirect()
|
||||
{
|
||||
error_log("buyGoodsDirect --- " . json_encode($_REQUEST));
|
||||
|
||||
// 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是
|
||||
// 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, BUY_SERVER_PKEY);
|
||||
|
||||
error_log("buyGoodsDirect-------" . $signature . "---" . $sign . "---" . json_encode($data));
|
||||
|
||||
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', 'id', 'item_id', 'goods_num', 'status'), array('order_id' => $order_id));
|
||||
if (!$order) {
|
||||
$this->_rspErr(2, "order not found: {$order_id}");
|
||||
return;
|
||||
}
|
||||
|
||||
$id = $order['id'];
|
||||
$goods_num = $order['goods_num'];
|
||||
$o_status = $order['status'];
|
||||
$address = $order['address'];
|
||||
|
||||
if ($o_status != 0) {
|
||||
$this->_rspErr(1, "order status error, status: {$o_status}");
|
||||
return;
|
||||
}
|
||||
|
||||
$buyStatus = 0; // 1: 成功, 2: 失败
|
||||
switch ($status) {
|
||||
case "9":
|
||||
$buyStatus = 1;
|
||||
// 充值成功,开始首充奖励
|
||||
$this->beginFirstTupop($address);
|
||||
break;
|
||||
case "99":
|
||||
case "98":
|
||||
$buyStatus = 2;
|
||||
break;
|
||||
default:
|
||||
error_log("buyGoodsDirect--- " . $order_id . " --- " . $status);
|
||||
$this->_rspErr(1, "status error, status: {$status}");
|
||||
return;
|
||||
}
|
||||
|
||||
SqlHelper::update($conn, 't_shop_buy_order', array('order_id' => $order_id), array('status' => $buyStatus));
|
||||
|
||||
if ($buyStatus == 2) {
|
||||
$this->_rspErr(2, "buyStatus error, buyStatus: {$buyStatus}");
|
||||
return;
|
||||
}
|
||||
|
||||
// 以下是看商品表中是否配置了充值额外奖励
|
||||
$goods = mt\ShopGoods::get($id);
|
||||
error_log("buyGoodsDirect---" . json_encode($goods));
|
||||
$goods_num = $order['goods_num'];
|
||||
$bundle_size = $goods['bonus_num'] ? $goods['bonus_num'] : 0;
|
||||
$item_num = $goods_num * $bundle_size;
|
||||
$item_id = $goods['bonus'];
|
||||
$meta = mt\Item::get($item_id);
|
||||
error_log("buyGoodsDirect---" . $item_id . "---" . $item_num . "---" . $bundle_size . "---" . $meta['name']);
|
||||
if ($meta && $item_num > 0) {
|
||||
// $address = $order['address'];
|
||||
$account_id = $this->getAccountId($address);
|
||||
|
||||
if ($item_id == V_ITEM_DIAMOND) {
|
||||
$event = [
|
||||
'name' => LogService::RECHARGE_CEBG_BONUS,
|
||||
'val' => $item_num
|
||||
];
|
||||
LogService::productDiamondCallback(['account_id' => $account_id], $event);
|
||||
}
|
||||
|
||||
error_log("buyGoodsDirect---" . $address . "---" . $item_id . "---" . $item_num);
|
||||
|
||||
$this->_addGoods($address, array(
|
||||
'goods_id' => $item_id,
|
||||
'goods_num' => $item_num,
|
||||
'id' => $id,
|
||||
));
|
||||
}
|
||||
|
||||
$this->_rspOk();
|
||||
}
|
||||
|
||||
public function startInappPurchase()
|
||||
{
|
||||
$self = myself();
|
||||
@ -476,207 +339,6 @@ class ShopController extends BaseAuthedController
|
||||
$this->_rspData($order);
|
||||
}
|
||||
|
||||
public function inappPurchaseDiamonds()
|
||||
{
|
||||
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 = ''
|
||||
// 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, BUY_SERVER_PKEY);
|
||||
|
||||
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 = 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'];
|
||||
if (empty($address)) {
|
||||
$this->_rspErr(4, "address is empty");
|
||||
return;
|
||||
}
|
||||
$account_id = $this->getAccountId($address);
|
||||
if (empty($account_id)) {
|
||||
$this->_rspErr(5, "account_id is empty");
|
||||
return;
|
||||
}
|
||||
|
||||
if ($item_id == V_ITEM_DIAMOND) {
|
||||
$event = [
|
||||
'name' => LogService::RECHARGE_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,
|
||||
));
|
||||
}
|
||||
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 = 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'];
|
||||
if (empty($address)) {
|
||||
$this->_rspErr(4, "address is empty");
|
||||
return;
|
||||
}
|
||||
$account_id = $this->getAccountId($address);
|
||||
if (empty($account_id)) {
|
||||
$this->_rspErr(5, "account_id is empty");
|
||||
return;
|
||||
}
|
||||
|
||||
if ($item_id == V_ITEM_DIAMOND) {
|
||||
$event = [
|
||||
'name' => LogService::RECHARGE_DIAMOND,
|
||||
'val' => -$item_num
|
||||
];
|
||||
LogService::productDiamondCallback(['account_id' => $account_id], $event);
|
||||
}
|
||||
|
||||
$this->_decGoods($address, array(
|
||||
'goods_id' => $item_id,
|
||||
'goods_num' => $item_num,
|
||||
'id' => $id,
|
||||
));
|
||||
break;
|
||||
default:
|
||||
$status = 0;
|
||||
$this->_rspErr(1, "status is not 9 or 96");
|
||||
return;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->_rspOk();
|
||||
}
|
||||
|
||||
private function getAccountId($address)
|
||||
{
|
||||
$row = SqlHelper::ormSelectOne(
|
||||
myself()->_getMysql($address),
|
||||
't_user',
|
||||
array(
|
||||
'address' => $address
|
||||
)
|
||||
);
|
||||
if (!$row) {
|
||||
return null;
|
||||
}
|
||||
return $row['account_id'];
|
||||
}
|
||||
|
||||
private function _addGoods($address, $goods)
|
||||
{
|
||||
$itemService = new ShopAddItemService();
|
||||
|
Loading…
x
Reference in New Issue
Block a user