1
This commit is contained in:
parent
db9cfb4586
commit
6e2d2bc88b
@ -16,211 +16,206 @@ use models\Chip;
|
||||
class FirstTopupController extends BaseAuthedController
|
||||
{
|
||||
|
||||
public function info()
|
||||
{
|
||||
$complete = false;
|
||||
public function info()
|
||||
{
|
||||
$complete = false;
|
||||
|
||||
// $address = myself()->_getAddress();
|
||||
// if (!$address) {
|
||||
// $this->_rspErr(1, 'you have not a web3 address');
|
||||
// return;
|
||||
// }
|
||||
$conn = myself()->_getMysql('');
|
||||
|
||||
$conn = myself()->_getMysql('');
|
||||
$status = $this->getStatusFromDB($conn);
|
||||
|
||||
$status = $this->getStatusFromDB($conn);
|
||||
|
||||
// 检查所有 奖励都 领取完成
|
||||
$complete = ($status[0] == 2 && $status[1] == 2 && $status[2] == 2) ? 1 : 0;
|
||||
if ($complete == 1) {
|
||||
$this->_setV(TN_FIRST_TUPOP_STATUS, 0, 1);
|
||||
}
|
||||
|
||||
$this->_rspData(
|
||||
array(
|
||||
'complete' => $complete,
|
||||
'firstTopupList' => mt\FirstTopup::getGroups(),
|
||||
'status' => $status,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private function begin()
|
||||
{
|
||||
$conn = myself()->_getMysql('');
|
||||
|
||||
$address = myself()->_getAddress();
|
||||
if (!$address) {
|
||||
$this->_rspErr(1, 'you have not a web3 address');
|
||||
return;
|
||||
}
|
||||
|
||||
$exist = SqlHelper::selectOne(
|
||||
$conn,
|
||||
't_first_topup',
|
||||
array('address'),
|
||||
array('address' => myself()->_getAddress())
|
||||
);
|
||||
if ($exist) {
|
||||
$this->_rspErr(1, '首充奖励活动已经开启');
|
||||
return;
|
||||
}
|
||||
|
||||
// 开始首充奖励活动进程
|
||||
$chk = SqlHelper::insert(
|
||||
$conn,
|
||||
't_first_topup',
|
||||
array(
|
||||
'address' => myself()->_getAddress(),
|
||||
'createtime' => myself()->_getNowTime(),
|
||||
'status1' => 0,
|
||||
'status2' => 0,
|
||||
'status3' => 0,
|
||||
)
|
||||
);
|
||||
|
||||
if ($chk) {
|
||||
$this->_rspOk();
|
||||
} else {
|
||||
$this->_rspErr(1, '首充奖励活动开启失败');
|
||||
}
|
||||
}
|
||||
|
||||
public function get()
|
||||
{
|
||||
$group = getReqVal('group', 1);
|
||||
|
||||
$conn = myself()->_getMysql('');
|
||||
|
||||
$address = myself()->_getAddress();
|
||||
if (!$address) {
|
||||
$this->_rspErr(1, 'you have not a web3 address');
|
||||
return;
|
||||
}
|
||||
|
||||
$status = $this->getStatusFromDB($conn);
|
||||
|
||||
$test = $status[$group - 1];
|
||||
|
||||
if ($test == 1) {
|
||||
$status[$group - 1] = 2;
|
||||
$chk = SqlHelper::update(
|
||||
$conn,
|
||||
't_first_topup',
|
||||
array(
|
||||
'address' => myself()->_getAddress(),
|
||||
),
|
||||
array(
|
||||
'status' . $group => 2,
|
||||
)
|
||||
);
|
||||
// 发放奖励
|
||||
$reward = mt\FirstTopup::getByGroup($group);
|
||||
|
||||
$propertyChgService = new services\PropertyChgService();
|
||||
|
||||
for ($i = 0; $i < count($reward); $i++) {
|
||||
$item = $reward[$i];
|
||||
$itemMeta = mt\Item::get($item['goods_id']);
|
||||
for ($j = 0; $j < $item['goods_num']; $j++) {
|
||||
$this->internalAddItem($propertyChgService, $itemMeta, 1);
|
||||
// 检查所有 奖励都 领取完成
|
||||
$complete = ($status[0] == 2 && $status[1] == 2 && $status[2] == 2) ? 1 : 0;
|
||||
if ($complete == 1) {
|
||||
$this->_setV(TN_FIRST_TUPOP_STATUS, 0, 1);
|
||||
}
|
||||
}
|
||||
|
||||
$complete = ($status[0] == 2 && $status[1] == 2 && $status[2] == 2) ? 1 : 0;
|
||||
if ($complete == 1) {
|
||||
$this->_setV(TN_FIRST_TUPOP_STATUS, 0, 1);
|
||||
}
|
||||
|
||||
$this->_rspData(
|
||||
array(
|
||||
'group' => $group,
|
||||
'status' => $status,
|
||||
'reward' => $reward,
|
||||
)
|
||||
);
|
||||
} else if ($test >= 2) {
|
||||
$this->_rspErr(2, "already received the reward, group: $group");
|
||||
} else if ($test < 1) {
|
||||
$this->_rspErr(1, "not yet to receive the reward, group: $group");
|
||||
}
|
||||
}
|
||||
|
||||
private function getStatus($group, $time)
|
||||
{
|
||||
$beginDayTime = myself()->_getDaySeconds($time);
|
||||
$now = myself()->_getNowTime();
|
||||
|
||||
$diff = $now - ($beginDayTime + $group * 24 * 3600);
|
||||
if ($diff >= 0) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private function getStatusFromDB($conn)
|
||||
{
|
||||
// 从数据库中获取 status
|
||||
$row = SqlHelper::selectOne(
|
||||
$conn,
|
||||
't_first_topup',
|
||||
array('createtime', 'status1', 'status2', 'status3'),
|
||||
array('address' => myself()->_getAddress())
|
||||
);
|
||||
|
||||
$status = [0, 0, 0];
|
||||
|
||||
if ($row) {
|
||||
// 0 未领取 1 可领取 2 已领取
|
||||
$status = [(int)$row['status1'], (int)$row['status2'], (int)$row['status3']];
|
||||
$time = $row['createtime'];
|
||||
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
if ($status[$i] < 2) {
|
||||
// 检测是否到了可以领取的时间
|
||||
$status[$i] = $this->getStatus($i, $time);
|
||||
}
|
||||
}
|
||||
$this->_rspData(
|
||||
array(
|
||||
'complete' => $complete,
|
||||
'firstTopupList' => mt\FirstTopup::getGroups(),
|
||||
'status' => $status,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
private function begin()
|
||||
{
|
||||
$conn = myself()->_getMysql('');
|
||||
|
||||
private function internalAddItem($propertyChgService, $itemMeta, $count)
|
||||
{
|
||||
switch ($itemMeta['type']) {
|
||||
case mt\Item::HERO_TYPE: {
|
||||
Hero::addHero($itemMeta);
|
||||
$propertyChgService->addHeroChg();
|
||||
$propertyChgService->addUserChg();
|
||||
$address = myself()->_getAddress();
|
||||
if (!$address) {
|
||||
$this->_rspErr(1, 'you have not a web3 address');
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case mt\Item::HERO_SKIN_TYPE: {
|
||||
HeroSkin::addSkin($itemMeta);
|
||||
$propertyChgService->addHeroSkinChg();
|
||||
|
||||
$exist = SqlHelper::selectOne(
|
||||
$conn,
|
||||
't_first_topup',
|
||||
array('address'),
|
||||
array('address' => myself()->_getAddress())
|
||||
);
|
||||
if ($exist) {
|
||||
$this->_rspErr(1, '首充奖励活动已经开启');
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case mt\Item::GUN_TYPE: {
|
||||
Gun::addGun($itemMeta);
|
||||
$propertyChgService->addGunChg();
|
||||
|
||||
// 开始首充奖励活动进程
|
||||
$chk = SqlHelper::insert(
|
||||
$conn,
|
||||
't_first_topup',
|
||||
array(
|
||||
'address' => myself()->_getAddress(),
|
||||
'createtime' => myself()->_getNowTime(),
|
||||
'status1' => 0,
|
||||
'status2' => 0,
|
||||
'status3' => 0,
|
||||
)
|
||||
);
|
||||
|
||||
if ($chk) {
|
||||
$this->_rspOk();
|
||||
} else {
|
||||
$this->_rspErr(1, '首充奖励活动开启失败');
|
||||
}
|
||||
break;
|
||||
case mt\Item::GUN_SKIN_TYPE: {
|
||||
GunSkin::addSkin($itemMeta);
|
||||
$propertyChgService->addGunSkinChg();
|
||||
}
|
||||
break;
|
||||
case mt\Item::CHIP_TYPE: {
|
||||
Chip::addChip($itemMeta);
|
||||
$propertyChgService->addChip();
|
||||
}
|
||||
break;
|
||||
default: {
|
||||
Bag::addItem($itemMeta['id'], $count);
|
||||
$propertyChgService->addBagChg();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function get()
|
||||
{
|
||||
$group = getReqVal('group', 1);
|
||||
|
||||
$conn = myself()->_getMysql('');
|
||||
|
||||
$address = myself()->_getAddress();
|
||||
if (!$address) {
|
||||
$this->_rspErr(1, 'you have not a web3 address');
|
||||
return;
|
||||
}
|
||||
|
||||
$status = $this->getStatusFromDB($conn);
|
||||
|
||||
$test = $status[$group - 1];
|
||||
|
||||
if ($test == 1) {
|
||||
$status[$group - 1] = 2;
|
||||
$chk = SqlHelper::update(
|
||||
$conn,
|
||||
't_first_topup',
|
||||
array(
|
||||
'address' => myself()->_getAddress(),
|
||||
),
|
||||
array(
|
||||
'status' . $group => 2,
|
||||
)
|
||||
);
|
||||
// 发放奖励
|
||||
$reward = mt\FirstTopup::getByGroup($group);
|
||||
|
||||
$propertyChgService = new services\PropertyChgService();
|
||||
|
||||
for ($i = 0; $i < count($reward); $i++) {
|
||||
$item = $reward[$i];
|
||||
$itemMeta = mt\Item::get($item['goods_id']);
|
||||
for ($j = 0; $j < $item['goods_num']; $j++) {
|
||||
$this->internalAddItem($propertyChgService, $itemMeta, 1);
|
||||
}
|
||||
}
|
||||
|
||||
$complete = ($status[0] == 2 && $status[1] == 2 && $status[2] == 2) ? 1 : 0;
|
||||
if ($complete == 1) {
|
||||
$this->_setV(TN_FIRST_TUPOP_STATUS, 0, 1);
|
||||
}
|
||||
|
||||
$this->_rspData(
|
||||
array(
|
||||
'group' => $group,
|
||||
'status' => $status,
|
||||
'reward' => $reward,
|
||||
)
|
||||
);
|
||||
} else if ($test >= 2) {
|
||||
$this->_rspErr(2, "already received the reward, group: $group");
|
||||
} else if ($test < 1) {
|
||||
$this->_rspErr(1, "not yet to receive the reward, group: $group");
|
||||
}
|
||||
}
|
||||
|
||||
private function getStatus($group, $time)
|
||||
{
|
||||
$beginDayTime = myself()->_getDaySeconds($time);
|
||||
$now = myself()->_getNowTime();
|
||||
|
||||
$diff = $now - ($beginDayTime + $group * 24 * 3600);
|
||||
if ($diff >= 0) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private function getStatusFromDB($conn)
|
||||
{
|
||||
// 从数据库中获取 status
|
||||
$row = SqlHelper::selectOne(
|
||||
$conn,
|
||||
't_first_topup',
|
||||
array('createtime', 'status1', 'status2', 'status3'),
|
||||
array('address' => myself()->_getAddress())
|
||||
);
|
||||
|
||||
$status = [0, 0, 0];
|
||||
|
||||
if ($row) {
|
||||
// 0 未领取 1 可领取 2 已领取
|
||||
$status = [(int)$row['status1'], (int)$row['status2'], (int)$row['status3']];
|
||||
$time = $row['createtime'];
|
||||
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
if ($status[$i] < 2) {
|
||||
// 检测是否到了可以领取的时间
|
||||
$status[$i] = $this->getStatus($i, $time);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
private function internalAddItem($propertyChgService, $itemMeta, $count)
|
||||
{
|
||||
switch ($itemMeta['type']) {
|
||||
case mt\Item::HERO_TYPE: {
|
||||
Hero::addHero($itemMeta);
|
||||
$propertyChgService->addHeroChg();
|
||||
$propertyChgService->addUserChg();
|
||||
}
|
||||
break;
|
||||
case mt\Item::HERO_SKIN_TYPE: {
|
||||
HeroSkin::addSkin($itemMeta);
|
||||
$propertyChgService->addHeroSkinChg();
|
||||
}
|
||||
break;
|
||||
case mt\Item::GUN_TYPE: {
|
||||
Gun::addGun($itemMeta);
|
||||
$propertyChgService->addGunChg();
|
||||
}
|
||||
break;
|
||||
case mt\Item::GUN_SKIN_TYPE: {
|
||||
GunSkin::addSkin($itemMeta);
|
||||
$propertyChgService->addGunSkinChg();
|
||||
}
|
||||
break;
|
||||
case mt\Item::CHIP_TYPE: {
|
||||
Chip::addChip($itemMeta);
|
||||
$propertyChgService->addChip();
|
||||
}
|
||||
break;
|
||||
default: {
|
||||
Bag::addItem($itemMeta['id'], $count);
|
||||
$propertyChgService->addBagChg();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,29 +7,31 @@ use phpcommon\SqlHelper;
|
||||
|
||||
class FirstTopup extends BaseModel {
|
||||
|
||||
public static function find()
|
||||
public static function get()
|
||||
{
|
||||
$row = SqlHelper::ormSelectOne(
|
||||
myself()->_getMysql(''),
|
||||
myself()->_getSelfMysql(),
|
||||
't_first_topup',
|
||||
array(
|
||||
'order_id' => $orderId,
|
||||
'account_id' => myself()->_getAccountId(),
|
||||
)
|
||||
);
|
||||
return $row;
|
||||
}
|
||||
|
||||
public static function add($orderId, $platform, $goodsId, $price)
|
||||
public static function add($accountId)
|
||||
{
|
||||
SqlHelper::insert(
|
||||
myself()->_getMysql(''),
|
||||
SqlHelper::upsert(
|
||||
myself()->_getMysql($accountId),
|
||||
't_first_topup',
|
||||
array(
|
||||
'order_id' => $orderId,
|
||||
'account_id' => myself()->_getAccountId(),
|
||||
'platform' => $platform,
|
||||
'goods_id' => $goodsId,
|
||||
'price' => $price,
|
||||
'account_id' => $accountId,
|
||||
),
|
||||
array(
|
||||
|
||||
),
|
||||
array(
|
||||
'account_id' => $accountId,
|
||||
'createtime' => myself()->_getNowTime(),
|
||||
'modifytime' => myself()->_getNowTime(),
|
||||
)
|
||||
@ -39,10 +41,10 @@ class FirstTopup extends BaseModel {
|
||||
public static function update($orderId, $fieldsKv)
|
||||
{
|
||||
SqlHelper::update(
|
||||
myself()->_getMysql(''),
|
||||
myself()->_getSelfMysql(),
|
||||
't_first_topup',
|
||||
array(
|
||||
'order_id' => $orderId
|
||||
'account_id' => myself()->_getAccountId()
|
||||
),
|
||||
$fieldsKv
|
||||
);
|
||||
|
@ -7,6 +7,7 @@ require_once("mt/Item.php");
|
||||
|
||||
require_once("models/ShopBuyRecord.php");
|
||||
require_once("models/OutAppOrder.php");
|
||||
require_once("models/FirstTopup.php");
|
||||
|
||||
require_once("services/LogService.php");
|
||||
require_once("ShopAddItemService.php");
|
||||
@ -15,6 +16,7 @@ use phpcommon\SqlHelper;
|
||||
|
||||
use models\ShopBuyRecord;
|
||||
use models\OutAppOrder;
|
||||
use models\FirstTopup;
|
||||
|
||||
use services\LogService;
|
||||
|
||||
@ -68,7 +70,7 @@ class OutAppPurchase {
|
||||
return;
|
||||
}
|
||||
OutAppOrder::markFinished($orderDb['order_id']);
|
||||
$this->beginFirstTupop($address);
|
||||
FirstTopup::add($accountId);
|
||||
// 以下是看商品表中是否配置了充值额外奖励
|
||||
$goodsMeta = mt\ShopGoods::get($orderDb['goods_id']);
|
||||
if (!$goodsMeta) {
|
||||
@ -99,38 +101,6 @@ class OutAppPurchase {
|
||||
$this->_rspOk();
|
||||
}
|
||||
|
||||
private function beginFirstTupop($address)
|
||||
{
|
||||
$conn = myself()->_getMysql('');
|
||||
|
||||
$exist = SqlHelper::selectOne(
|
||||
$conn,
|
||||
't_first_topup',
|
||||
array('address'),
|
||||
array('address' => $address)
|
||||
);
|
||||
if ($exist) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 开始首充奖励活动进程
|
||||
$chk = SqlHelper::insert(
|
||||
$conn,
|
||||
't_first_topup',
|
||||
array(
|
||||
'address' => $address,
|
||||
'createtime' => myself()->_getNowTime(),
|
||||
'status1' => 0,
|
||||
'status2' => 0,
|
||||
'status3' => 0,
|
||||
)
|
||||
);
|
||||
if (!$chk) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function verifySign()
|
||||
{
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user