...
This commit is contained in:
parent
69424b43fa
commit
00081073a2
@ -28,6 +28,7 @@ use models\Gun;
|
||||
use models\GunSkin;
|
||||
use models\ShopBuyRecord;
|
||||
use models\Chip;
|
||||
use mt\Shop;
|
||||
|
||||
class ShopController extends BaseAuthedController
|
||||
{
|
||||
@ -43,7 +44,24 @@ class ShopController extends BaseAuthedController
|
||||
const TOKEN_TYPE_MATIC = '101';
|
||||
const TOKEN_TYPE_BNB = '102';
|
||||
|
||||
const TOKEN_TYPE_DSD = '99';
|
||||
//99 = 美元
|
||||
const TOKEN_TYPE_USD = '99';
|
||||
|
||||
//21 = 印尼
|
||||
const TOKEN_TYPE_IDR = '21';
|
||||
//22 = 菲律宾
|
||||
const TOKEN_TYPE_PHP = '22';
|
||||
//23 = 越南
|
||||
const TOKEN_TYPE_VND = '23';
|
||||
//24 = 泰国
|
||||
const TOKEN_TYPE_THB = '24';
|
||||
//25 = 马来西亚
|
||||
const TOKEN_TYPE_MYR = '25';
|
||||
//26 = 日本
|
||||
const TOKEN_TYPE_JPY = '26';
|
||||
//27 = 韩国
|
||||
const TOKEN_TYPE_KRW = '27';
|
||||
|
||||
|
||||
// 限购类型
|
||||
const DAILY_BUY_LIMIT = 1;
|
||||
@ -278,12 +296,11 @@ class ShopController extends BaseAuthedController
|
||||
// 我返回给你这些数据和一个sign字段,
|
||||
// sign使用上面 repdata 按key 顺序排后, 组成key1=val1&key2=val2后, 使用hmac_sha256 hash, key是 iG4Rpsa)6U31$H#^T85$^^3
|
||||
|
||||
|
||||
$token_type = getReqVal('token_type', '');
|
||||
$goods_num = getReqVal('goods_num', 0);
|
||||
|
||||
$order_id = 28;
|
||||
error_log("buyGoodsDirect");
|
||||
error_log("buyGoodsDirect-------");
|
||||
|
||||
$conn = myself()->_getMysql('');
|
||||
|
||||
@ -293,6 +310,14 @@ class ShopController extends BaseAuthedController
|
||||
$goods_num = $order['goods_num'];
|
||||
$status = $order['status'];
|
||||
|
||||
if ($status != 0) {
|
||||
$this->_rspErr(1, "order status error, status: {$status}");
|
||||
return;
|
||||
}
|
||||
|
||||
$buyStatus = 1; // 1: 成功, 2: 失败
|
||||
SqlHelper::update($conn, 't_shop_buy_order', array('idx' => $order_id), array('status' => $buyStatus) );
|
||||
|
||||
$row = mt\ShopGoods::get($id);
|
||||
|
||||
$desired_token_type = $row['token_type'];
|
||||
@ -311,162 +336,16 @@ class ShopController extends BaseAuthedController
|
||||
// 这里命名混乱了, 购买个数,一捆个数命名冲突
|
||||
$goods_count = $row['goods_num'];
|
||||
|
||||
$buyRecordHash = ShopBuyRecord::allToHash();
|
||||
$boughtTimes = 1;
|
||||
switch ($row['limit_type']) {
|
||||
case ShopController::DAILY_BUY_LIMIT: {
|
||||
$buyRecord = getXVal($buyRecordHash, $id);
|
||||
$boughtTimes = $buyRecord ? $buyRecord['this_day_buy_times'] + 1 : 1;
|
||||
if ($buyRecord && getXVal($buyRecord, 'this_day_buy_times', 0) >= $row['limit_num']) {
|
||||
$this->_rspErr(2, 'Has reached the maximum number of purchase restrictions today');
|
||||
return;
|
||||
}
|
||||
if ($row['limit_num'] <= 0) {
|
||||
$this->_rspErr(2, 'The maximum number of purchase restrictions has been reached');
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ShopController::WEEKLY_BUY_LIMIT: {
|
||||
$buyRecord = getXVal($buyRecordHash, $id);
|
||||
$boughtTimes = $buyRecord ? $buyRecord['this_week_buy_times'] + 1 : 1;
|
||||
if ($buyRecord && getXVal($buyRecord, 'this_week_buy_times', 0) >= $row['limit_num']) {
|
||||
$this->_rspErr(2, 'The maximum number of purchase restrictions this week has been reached');
|
||||
return;
|
||||
}
|
||||
if ($row['limit_num'] <= 0) {
|
||||
$this->_rspErr(2, 'The maximum number of purchase restrictions has been reached');
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ShopController::TOTAL_BUY_LIMIT: {
|
||||
$buyRecord = getXVal($buyRecordHash, $id);
|
||||
$boughtTimes = $buyRecord ? $buyRecord['total_buy_times'] + 1 : 1;
|
||||
if ($buyRecord && getXVal($buyRecord, 'total_buy_times', 0) >= $row['limit_num']) {
|
||||
$this->_rspErr(2, 'The maximum number of purchase restrictions has been reached');
|
||||
return;
|
||||
}
|
||||
if ($row['limit_num'] <= 0) {
|
||||
$this->_rspErr(2, 'he maximum number of purchase restrictions has been reached');
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default: {
|
||||
}
|
||||
break;
|
||||
$itemMeta = mt\Item::get($row['goods_id']);
|
||||
$propertyChgService = new services\PropertyChgService();
|
||||
for ($i = 0; $i < $goods_num; $i++) {
|
||||
$this->internalAddItem($propertyChgService, $itemMeta, $goods_count);
|
||||
}
|
||||
$awardService = new services\AwardService();
|
||||
$awardService->addItem($row['goods_id'], $goods_num);
|
||||
ShopBuyRecord::add($id, $goods_num);
|
||||
|
||||
$price_array = splitStr1($row['price']);
|
||||
$discount_array = splitStr1($row['discount']);
|
||||
|
||||
$need_price = $price_array[$token_pos];
|
||||
$discount = $discount_array[$token_pos];
|
||||
|
||||
$discount_begin = strtotime($row['discount_begin'] . ' UTC');
|
||||
$discount_end = strtotime($row['discount_end'] . ' UTC');
|
||||
$nowTime = $this->_getNowTime();
|
||||
|
||||
if ($nowTime >= $discount_begin && $nowTime < $discount_end) {
|
||||
|
||||
$need_price = ceil($need_price * ($discount / 100.0));
|
||||
}
|
||||
|
||||
$costItemId = $this->getCostItemIdByTokenType($token_type);
|
||||
|
||||
switch ($token_type) {
|
||||
case ShopController::TOKEN_TYPE_CEG:
|
||||
case ShopController::TOKEN_TYPE_CEC:
|
||||
$costItems = $this->makeCostItems($costItemId, $goods_num * $need_price);
|
||||
$lackItem = null;
|
||||
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
||||
$this->_rspErr(2, $this->_getLackItemErrMsg($lackItem));
|
||||
return;
|
||||
}
|
||||
|
||||
$itemMeta = mt\Item::get($row['goods_id']);
|
||||
$propertyChgService = new services\PropertyChgService();
|
||||
for ($i = 0; $i < $goods_num; $i++) {
|
||||
$this->internalAddItem($propertyChgService, $itemMeta, $goods_count);
|
||||
}
|
||||
$awardService = new services\AwardService();
|
||||
$awardService->addItem($row['goods_id'], $goods_num);
|
||||
ShopBuyRecord::add($id, $goods_num);
|
||||
$this->_decItems($costItems);
|
||||
$goodsDto = array(
|
||||
'goods_id' => $id,
|
||||
'item_id' => $row['goods_id'],
|
||||
'price_info' => array(
|
||||
'item_id' => $row['goods_id'],
|
||||
'cost_list' => array(),
|
||||
'discount_begin_time' => phpcommon\datetimeToTimestamp($row['discount_begin']),
|
||||
'discount_end_time' => phpcommon\datetimeToTimestamp($row['discount_end'])
|
||||
),
|
||||
'flag_icon' => $row['tag'],
|
||||
'limit_type' => $row['limit_type'],
|
||||
'bought_times' => $boughtTimes,
|
||||
'total_buy_times' => $row['limit_num'],
|
||||
); {
|
||||
$priceInfo = mt\Item::getPriceInfo($itemMeta);
|
||||
if (!empty($priceInfo)) {
|
||||
$goodsDto['price_info'] = $priceInfo['price_info'];
|
||||
}
|
||||
}
|
||||
$propertyChgService->addUserChg();
|
||||
$this->_rspData(
|
||||
array(
|
||||
'award' => $awardService->toDto(),
|
||||
'property_chg' => $propertyChgService->toDto(),
|
||||
'goods_chg' => $goodsDto
|
||||
)
|
||||
);
|
||||
break;
|
||||
|
||||
case ShopController::TOKEN_TYPE_BCEG:
|
||||
break;
|
||||
|
||||
case ShopController::TOKEN_TYPE_USDT:
|
||||
case ShopController::TOKEN_TYPE_USDC:
|
||||
|
||||
$itemMeta = mt\Item::get($row['goods_id']);
|
||||
$propertyChgService = new services\PropertyChgService();
|
||||
for ($i = 0; $i < $goods_num; $i++) {
|
||||
$this->internalAddItem($propertyChgService, $itemMeta, $goods_count);
|
||||
}
|
||||
$awardService = new services\AwardService();
|
||||
$awardService->addItem($row['goods_id'], $goods_num);
|
||||
ShopBuyRecord::add($id, $goods_num);
|
||||
|
||||
// $goodsDto = array(
|
||||
// 'goods_id' => $id,
|
||||
// 'item_id' => $row['goods_id'],
|
||||
// 'price_info' => array(
|
||||
// 'item_id' => $row['goods_id'],
|
||||
// 'cost_list' => array(),
|
||||
// 'discount_begin_time' => phpcommon\datetimeToTimestamp($row['discount_begin']),
|
||||
// 'discount_end_time' => phpcommon\datetimeToTimestamp($row['discount_end'])
|
||||
// ),
|
||||
// 'flag_icon' => $row['tag'],
|
||||
// 'limit_type' => $row['limit_type'],
|
||||
// 'bought_times' => $boughtTimes,
|
||||
// 'total_buy_times' => $row['limit_num'],
|
||||
// ); {
|
||||
// $priceInfo = mt\Item::getPriceInfo($itemMeta);
|
||||
// if (!empty($priceInfo)) {
|
||||
// $goodsDto['price_info'] = $priceInfo['price_info'];
|
||||
// }
|
||||
// }
|
||||
// $propertyChgService->addUserChg();
|
||||
|
||||
$this->_rspOk();
|
||||
break;
|
||||
case ShopController::TOKEN_TYPE_BUSD:
|
||||
case ShopController::TOKEN_TYPE_MATIC:
|
||||
case ShopController::TOKEN_TYPE_BNB:
|
||||
default:
|
||||
$this->_rspErr(1, "token_type is unsupport, {$token_type}");
|
||||
}
|
||||
$this->_rspOk();
|
||||
}
|
||||
|
||||
public function startGoodsDirect() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user