还原充值接口
This commit is contained in:
parent
a221a65776
commit
92ce24b773
@ -196,6 +196,105 @@ class ShopController extends BaseAuthedController {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function inappPurchase()
|
||||
{
|
||||
$goodsId = getReqVal('goods_id', 0);
|
||||
$goodsNum = getReqVal('goods_num', 0);
|
||||
$platform = getReqVal('platform', 0);
|
||||
$balance = $this->getInAppBalance();
|
||||
|
||||
if ($balance <= 0) {
|
||||
$this->_rspErr(2, "insufficient available balance");
|
||||
return;
|
||||
}
|
||||
$goodsMeta = mt\ShopGoods::getByGoodsUuid($goodsId);
|
||||
if (!$goodsMeta) {
|
||||
$this->_rspErr(2, "inapp purchase failed");
|
||||
return;
|
||||
}
|
||||
if (!in_array($goodsMeta['shop_id'],
|
||||
array(
|
||||
mt\Shop::INAPP_SHOP_DIAMOND
|
||||
)
|
||||
)) {
|
||||
$this->_rspErr(3, "inapp purchase failed");
|
||||
return;
|
||||
}
|
||||
if ($goodsNum != 1) {
|
||||
$this->_rspErr(3, "goods_num error");
|
||||
return;
|
||||
}
|
||||
if ($goodsMeta['token_type'] != mt\Shop::TOKEN_TYPE_USD) {
|
||||
$this->_rspErr(3, "token_type config error");
|
||||
return;
|
||||
}
|
||||
if (!InAppOrder::isValidPlatform($platform)) {
|
||||
$this->_rspErr(1, "error paramater platform");
|
||||
return;
|
||||
}
|
||||
$price = $goodsMeta['price'];
|
||||
if (empty($price) || $price < 0.001) {
|
||||
$this->_rspErr(1, "config error");
|
||||
return;
|
||||
}
|
||||
|
||||
$orderId = OrderId::genInappOrderId();
|
||||
InAppOrder::add(
|
||||
$orderId,
|
||||
$platform,
|
||||
$goodsId,
|
||||
$price
|
||||
);
|
||||
InAppRecord::addAmount($price);
|
||||
$this->_rspData(array(
|
||||
'order_id' => $orderId,
|
||||
));
|
||||
}
|
||||
|
||||
public function queryInAppPurchase()
|
||||
{
|
||||
$orderId = getReqVal('order_id', '');
|
||||
$orderDb = InAppOrder::find($orderId);
|
||||
if (!$orderDb) {
|
||||
myself()->_rspErr(1, 'order not found');
|
||||
return;
|
||||
}
|
||||
$goodsMeta = mt\ShopGoods::get($orderDb['goods_id']);
|
||||
error_log(json_encode($orderDb));
|
||||
error_log(json_encode($goodsMeta));
|
||||
$this->_rspData(array(
|
||||
'order_id' => $orderDb['order_id'],
|
||||
'item_id' => $goodsMeta['item_id'],
|
||||
'item_num' => $goodsMeta['item_num'],
|
||||
'status' => $orderDb['status'],
|
||||
));
|
||||
}
|
||||
|
||||
public function queryInAppBalance()
|
||||
{
|
||||
myself()->_rspData(
|
||||
array(
|
||||
'balance' => $this->getInAppBalance()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private function getInAppBalance()
|
||||
{
|
||||
$totalAmount = InAppRecord::getTotalAmount();
|
||||
$recordDb = InAppRecord::get();
|
||||
$upLimit = mt\Parameter::getVal('inapp_daily_up_limit', 0);
|
||||
$totalUpLimit = mt\Parameter::getVal('inapp_total_up_limit', 0);
|
||||
$todayAmount = 0;
|
||||
if ($recordDb) {
|
||||
$todayAmount = max($recordDb['amount'], $recordDb['amount_ok']);
|
||||
}
|
||||
$dailyBalance = max(0, $upLimit - $todayAmount);
|
||||
$totalBalance = max(0, $totalUpLimit - $totalAmount);
|
||||
return min($dailyBalance, $totalBalance);
|
||||
}
|
||||
|
||||
private function internalAddItem($awardService,
|
||||
$propertyChgService,
|
||||
$itemMeta,
|
||||
@ -213,4 +312,5 @@ class ShopController extends BaseAuthedController {
|
||||
$propertyChgService);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user