103 lines
3.3 KiB
PHP
103 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace models;
|
|
|
|
require_once('services/AwardService.php');
|
|
require_once('services/PropertyChgService.php');
|
|
require_once('services/MailApiService.php');
|
|
|
|
class GoldBullion extends BaseModel {
|
|
|
|
const OPEN_STATUS_SENT = 1;
|
|
const OPEN_STATUS_PENDING = 2;
|
|
const OPEN_STATUS_SEND_BEGIN = 3;
|
|
const OPEN_STATUS_SEND_END = 4;
|
|
|
|
public static function onLogin()
|
|
{
|
|
$address = myself()->_getAddress();
|
|
if (empty($address)) {
|
|
return;
|
|
}
|
|
$rows = SqlHelper::ormSelect(
|
|
myself()->_getSelfMysql(),
|
|
't_gold_bullion',
|
|
array(
|
|
'open_address' => myself()->_getAddress(),
|
|
'open_status' => self::OPEN_STATUS_PENDING,
|
|
'returned' => 0,
|
|
)
|
|
);
|
|
if (count($rows) > 0) {
|
|
$confirmedRows = array();
|
|
foreach ($rows as $row) {
|
|
$uniqId = self::genUniqId();
|
|
SqlHelper::update(
|
|
myself()->_getSelfMysql(),
|
|
't_gold_bullion',
|
|
array(
|
|
'idx' => $row['idx'],
|
|
'open_status' => self::OPEN_STATUS_PENDING
|
|
),
|
|
array(
|
|
'open_status' => self::OPEN_STATUS_SEND_BEGIN,
|
|
'open_uniqid' => $uniqId
|
|
)
|
|
);
|
|
$newRow = SqlHelper::ormSelectOne(
|
|
myself()->_getSelfMysql(),
|
|
't_gold_bullion',
|
|
array(
|
|
'idx' => $row['idx'],
|
|
)
|
|
);
|
|
if (!empty($newRow) && $newRow['open_uniqid'] == $uniqId) {
|
|
array_push($confirmedRows, $row);
|
|
}
|
|
self::doSendAward($confirmedRows);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static function doSendAward($confirmedRows)
|
|
{
|
|
$propertyChgService = new services\PropertyChgService();
|
|
$awardService = new services\AwardService();
|
|
if (empty($confirmedRows)) {
|
|
return;
|
|
}
|
|
foreach ($confirmedRows as $row) {
|
|
$items = array(
|
|
array(
|
|
'item_id' => V_ITEM_GOLD,
|
|
'item_num' => $row['gold']
|
|
)
|
|
);
|
|
myself()->_addItems($items, $awardService, $propertyChgService);
|
|
SqlHelper::update(
|
|
myself()->_getSelfMysql(),
|
|
't_gold_bullion',
|
|
array(
|
|
'idx' => $row['idx'],
|
|
),
|
|
array(
|
|
'account_id' => myself()->_getAccountId(),
|
|
'open_status' => self::OPEN_STATUS_SEND_END,
|
|
)
|
|
);
|
|
$content = "[Item Name] has been used successfully, you have received 100,000 gold";
|
|
services\MailApiService::sendOpenGold($row['net_id'],
|
|
$row['token_id'],
|
|
'',
|
|
$content);
|
|
}
|
|
}
|
|
|
|
private static function genUniqId()
|
|
{
|
|
$uniqId = uniqid(md5(rand() . rand() . rand() . myself()->_getSessionId()), true);
|
|
return $uniqId;
|
|
}
|
|
|
|
}
|