...
This commit is contained in:
parent
0a24b624ab
commit
933a0c9f5c
@ -44,7 +44,8 @@ use models\Transaction;
|
|||||||
use models\BcOrder;
|
use models\BcOrder;
|
||||||
|
|
||||||
if (!function_exists('array_column')) {
|
if (!function_exists('array_column')) {
|
||||||
function array_column($arr2, $column_key) {
|
function array_column($arr2, $column_key)
|
||||||
|
{
|
||||||
$data = [];
|
$data = [];
|
||||||
foreach ($arr2 as $arr) {
|
foreach ($arr2 as $arr) {
|
||||||
$data[] = $arr[$column_key];
|
$data[] = $arr[$column_key];
|
||||||
@ -139,6 +140,10 @@ class ShopController extends BaseAuthedController
|
|||||||
if (empty($goods['goods_num'])) {
|
if (empty($goods['goods_num'])) {
|
||||||
$goods['goods_num'] = 1;
|
$goods['goods_num'] = 1;
|
||||||
}
|
}
|
||||||
|
if (!empty($goods['free_type'])) {
|
||||||
|
$count = $this->countFreeBuyTimes($goods);
|
||||||
|
$goods['free_num'] = $goods['free_num'] - $count;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->_rspData(
|
$this->_rspData(
|
||||||
@ -838,7 +843,16 @@ class ShopController extends BaseAuthedController
|
|||||||
$desired_token_type = $row['token_type'];
|
$desired_token_type = $row['token_type'];
|
||||||
$check_token_type = splitStr1($desired_token_type);
|
$check_token_type = splitStr1($desired_token_type);
|
||||||
$token_pos = array_search($token_type, $check_token_type, true);
|
$token_pos = array_search($token_type, $check_token_type, true);
|
||||||
if (!in_array($token_type, $check_token_type)) {
|
$isFreeBuy = false;
|
||||||
|
if (!empty($row['free_type'])) {
|
||||||
|
$count = $this->countFreeBuyTimes($row);
|
||||||
|
if ($count < $row['free_num']) {
|
||||||
|
$isFreeBuy = true;
|
||||||
|
} else {
|
||||||
|
$this->_rspErr(1, "free_num parameter error, free_num: {$row['free_num']}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else if (!in_array($token_type, $check_token_type)) {
|
||||||
$this->_rspErr(1, "token_type parameter error, desired_token_type: {$desired_token_type}");
|
$this->_rspErr(1, "token_type parameter error, desired_token_type: {$desired_token_type}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -968,32 +982,39 @@ class ShopController extends BaseAuthedController
|
|||||||
break;
|
break;
|
||||||
case ShopController::TOKEN_TYPE_CEG:
|
case ShopController::TOKEN_TYPE_CEG:
|
||||||
case ShopController::TOKEN_TYPE_CEC:
|
case ShopController::TOKEN_TYPE_CEC:
|
||||||
|
if ($isFreeBuy) {
|
||||||
|
$propertyChgService = new services\PropertyChgService();
|
||||||
|
$this->addFreeBuyRecord($row);
|
||||||
|
$itemMeta = mt\Item::get($row['goods_id']);
|
||||||
|
$this->internalAddItem($propertyChgService, $itemMeta, $goods_count);
|
||||||
|
$this->_rspOk();
|
||||||
|
} else {
|
||||||
|
$price = $this->normalizeWeb3Price($goods_num * $need_price);
|
||||||
|
$item_id = $row['goods_id'];
|
||||||
|
$item_count = $goods_num;
|
||||||
|
|
||||||
$price = $this->normalizeWeb3Price($goods_num * $need_price);
|
$response = services\BlockChainService::gameItemMallBuy(
|
||||||
$item_id = $row['goods_id'];
|
Transaction::BUY_GOODS_ACTION_TYPE,
|
||||||
$item_count = $goods_num;
|
$price,
|
||||||
|
$item_id,
|
||||||
|
$item_count
|
||||||
|
);
|
||||||
|
|
||||||
$response = services\BlockChainService::gameItemMallBuy(
|
BcOrder::upsert($response['trans_id'], array(
|
||||||
Transaction::BUY_GOODS_ACTION_TYPE,
|
'item_id' => $item_id,
|
||||||
$price,
|
'item_num' => $item_count,
|
||||||
$item_id,
|
'order_type' => 1,
|
||||||
$item_count
|
'ext_data' => json_encode(array(
|
||||||
);
|
'mode' => SHOP_BUY_MODE_NORMAL,
|
||||||
|
)),
|
||||||
|
));
|
||||||
|
|
||||||
BcOrder::upsert( $response['trans_id'], array(
|
$response['item_id'] = $item_id;
|
||||||
'item_id' => $item_id,
|
$response['item_num'] = $item_count;
|
||||||
'item_num' => $item_count,
|
$this->_rspData(
|
||||||
'order_type' => 1,
|
$response
|
||||||
'ext_data' => json_encode(array(
|
);
|
||||||
'mode' => SHOP_BUY_MODE_NORMAL,
|
}
|
||||||
)),
|
|
||||||
));
|
|
||||||
|
|
||||||
$response['item_id'] = $item_id;
|
|
||||||
$response['item_num'] = $item_count;
|
|
||||||
$this->_rspData(
|
|
||||||
$response
|
|
||||||
);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ShopController::TOKEN_TYPE_BCEG:
|
case ShopController::TOKEN_TYPE_BCEG:
|
||||||
@ -1070,7 +1091,7 @@ class ShopController extends BaseAuthedController
|
|||||||
$item_count
|
$item_count
|
||||||
);
|
);
|
||||||
|
|
||||||
BcOrder::upsert( $response['trans_id'], array(
|
BcOrder::upsert($response['trans_id'], array(
|
||||||
'item_id' => $item_id,
|
'item_id' => $item_id,
|
||||||
'item_num' => $item_count,
|
'item_num' => $item_count,
|
||||||
'order_type' => 1,
|
'order_type' => 1,
|
||||||
@ -1093,8 +1114,8 @@ class ShopController extends BaseAuthedController
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private function buyGoodsFree() {
|
private function buyGoodsFree()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
private function decDailySelectionItem($idx, $grid, $count)
|
private function decDailySelectionItem($idx, $grid, $count)
|
||||||
@ -1534,4 +1555,51 @@ class ShopController extends BaseAuthedController
|
|||||||
|
|
||||||
return $price;
|
return $price;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function countFreeBuyTimes($goods) {
|
||||||
|
$conn = myself()->_getMysql('');
|
||||||
|
$account = myself()->_getAccountId();
|
||||||
|
|
||||||
|
switch($goods['free_type'])
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
$dayTime = myself()->_getNowDaySeconds();
|
||||||
|
$sql = 'SELECT COUNT(*) as cnt FROM t_shop_free_record WHERE account_id = ? AND `id` = ? AND goods_id = ? AND createtime >= ?';
|
||||||
|
$row = $conn->execQueryOne($sql, array($account, $goods['id'], $goods['goods_id'], $dayTime));
|
||||||
|
return $row['cnt'];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function addFreeBuyRecord($goods) {
|
||||||
|
$conn = myself()->_getMysql('');
|
||||||
|
$account = myself()->_getAccountId();
|
||||||
|
|
||||||
|
switch($goods['free_type'])
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
$dayTime = myself()->_getNowTime();
|
||||||
|
SqlHelper::insert(
|
||||||
|
$conn,
|
||||||
|
't_shop_free_record',
|
||||||
|
array(
|
||||||
|
'account_id' => $account,
|
||||||
|
'shop_id' => $goods['shop_id'],
|
||||||
|
'id' => $goods['id'],
|
||||||
|
'goods_id' => $goods['goods_id'],
|
||||||
|
'goods_num' => $goods['goods_num'],
|
||||||
|
'free_type' => $goods['free_type'],
|
||||||
|
'free_num' => $goods['free_num'],
|
||||||
|
'createtime' => $dayTime,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user