This commit is contained in:
songliang 2023-07-11 13:54:22 +08:00
parent 2c1f15ceca
commit 877df6d608
2 changed files with 100 additions and 7 deletions

View File

@ -443,16 +443,12 @@ class ShopController extends BaseAuthedController
public function inappPurchaseDiamonds() public function inappPurchaseDiamonds()
{ {
error_log('----- inappPurchaseDiamonds -----'); error_log('----- inappPurchaseDiamonds -----');
error_log('request:' . json_encode($_REQUEST));
error_log('post:' . json_encode($_POST));
$body = json_decode(file_get_contents('php://input'), true); $body = json_decode(file_get_contents('php://input'), true);
error_log('body:' . json_encode($body)); error_log('body:' . json_encode($body));
$channel = $body['channel']; $channel = $body['channel'];
$records = $body['records']; $records = $body['records'];
$sign = $body['sign']; $sign = $body['sign'];
error_log('records:' . json_encode($records));
// { // {
// channel: 'google', // channel: 'google',
// sign: '123456677' // 签名字段 // sign: '123456677' // 签名字段
@ -519,6 +515,7 @@ class ShopController extends BaseAuthedController
$this->_rspErr(2, "product_id is empty"); $this->_rspErr(2, "product_id is empty");
return; return;
} }
// $goods = mt\ShopGoods::getByProductId($product_id); // $goods = mt\ShopGoods::getByProductId($product_id);
return; return;
@ -559,8 +556,47 @@ class ShopController extends BaseAuthedController
} }
break; break;
case 96: 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;
}
// 退款 // 退款
$status = 2; $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; break;
default: default:
$status = 0; $status = 0;
@ -594,7 +630,6 @@ class ShopController extends BaseAuthedController
$id = $goods['id']; $id = $goods['id'];
} }
error_log(json_encode($goods));
error_log('_addGoods ' . $address . ' item_id ' . $item_id . ' goods_num ' . $goods_num . ' id ' . $id); error_log('_addGoods ' . $address . ' item_id ' . $item_id . ' goods_num ' . $goods_num . ' id ' . $id);
$itemService->addItem($address, $item_id, $goods_num); $itemService->addItem($address, $item_id, $goods_num);
if ($id) { if ($id) {
@ -602,6 +637,16 @@ class ShopController extends BaseAuthedController
} }
} }
private function _decGoods($address, $goods)
{
$itemService = new ShopAddItemService();
$item_id = $goods['goods_id'];
$goods_num = $goods['goods_num'];
error_log('_decGoods ' . $address . ' item_id ' . $item_id . ' goods_num ' . $goods_num);
$itemService->decItem($address, $item_id, $goods_num);
}
public function getPayMethods() public function getPayMethods()
{ {
$token_type = getReqVal('token_type', 99); $token_type = getReqVal('token_type', 99);

View File

@ -72,6 +72,25 @@ class ShopAddItemService
} }
public function decItem($address, $itemId, $itemNum)
{
if ($itemNum < 1) {
return;
}
$itemMeta = \mt\Item::get($itemId);
if (!$itemMeta) {
return;
}
$accountId = $this->getAccountId($address);
$conn = myself()->_getMysql($address);
if ($this->_isVirtualItem($itemId)) {
$this->_decVirtualItem($conn, $accountId, $itemId, $itemNum);
} else {
error_log("decItem itemId:$itemId not support");
return;
}
}
private function getAccountId($address){ private function getAccountId($address){
$row = SqlHelper::ormSelectOne $row = SqlHelper::ormSelectOne
@ -254,6 +273,35 @@ class ShopAddItemService
} }
} }
private function _decVirtualItem($conn, $accountId, $itemId, $itemNum) {
if ($itemNum <= 0) {
return;
}
switch ($itemId) {
case V_ITEM_GOLD:
{
$this->_updateUserInfo($conn,$accountId,array(
'gold' => function () use($itemNum) {
return "gold - ${itemNum}";
}
));
}
break;
case V_ITEM_DIAMOND:
{
$this->_updateUserInfo($conn,$accountId,array(
'diamond' => function () use($itemNum) {
return "diamond - ${itemNum}";
}
));
}
default:
{
}
break;
}
}
private function _updateUserInfo($conn,$accountId,$fieldsKv) private function _updateUserInfo($conn,$accountId,$fieldsKv)
{ {
SqlHelper::update SqlHelper::update