game2006api/webapp/models/Transaction.php
aozhiwei 3025f0d659 1
2022-11-02 12:10:55 +08:00

140 lines
3.3 KiB
PHP

<?php
namespace models;
use mt;
use phpcommon\SqlHelper;
class Transaction extends BaseModel {
const MINT_721_ACTION_TYPE = 1;
const MINT_1155_ACTION_TYPE = 2;
const EVOLVE_721_ACTION_TYPE = 3;
const EVOLVE_CHIP_ACTION_TYPE = 4;
const MINT_SHARD_BATCH_ACTION_TYPE = 5;
const SHARD_MIX_BY_USER_ACTION_TYPE = 6;
const CREATED_STATUS = 1;
const REPORTED_STATUS = 2;
const COMPLETED_STATUS = 3;
public static function all()
{
$rows = SqlHelper::ormSelect(
myself()->_getSelfMysql(),
't_transaction',
array(
'account_id' => myself()->_getAccountId()
)
);
return $rows;
}
public static function find($transId)
{
$row = SqlHelper::ormSelectOne(
myself()->_getSelfMysql(),
't_transaction',
array(
'account_id' => myself()->_getAccountId(),
'trans_id' => $transId,
)
);
return $row;
}
public static function add($transId, $action, $tokenId, $tokenType, $itemUniId, $itemId)
{
SqlHelper::insert(
myself()->_getSelfMysql(),
't_transaction',
array(
'account_id' => myself()->_getAccountId(),
'trans_id' => $transId,
'action' => $action,
'token_id' => $tokenId,
'token_type' => $tokenType,
'item_uniid' => $itemUniId,
'item_id' => $itemId,
'status' => self::CREATED_STATUS,
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime(),
)
);
}
public static function getActionDesc($transDb)
{
switch ($transDb['action']) {
case self::MINT_721_ACTION_TYPE:
case self::MINT_1155_ACTION_TYPE:
{
return 'Mint';
}
break;
case self::EVOLVE_721_ACTION_TYPE:
{
return 'Advance';
}
break;
case self::EVOLVE_CHIP_ACTION_TYPE:
{
return 'Upgrade';
}
break;
case self::MINT_SHARD_BATCH_ACTION_TYPE:
{
return 'Mint';
}
break;
case self::SHARD_MIX_BY_USER_ACTION_TYPE:
{
return 'Synthesis';
}
break;
default:
{
return 'None';
}
}
}
public static function getStatusDesc($transDb)
{
switch ($transDb['status']) {
case self::CREATED_STATUS:
case self::REPORTED_STATUS:
{
return 'Pending';
}
break;
case self::COMPLETED_STATUS:
{
return 'Complete';
}
break;
default:
{
return 'None';
}
}
}
public static function reportResult($transId, $result)
{
SqlHelper::update(
myself()->_getSelfMysql(),
't_transaction',
array(
'account_id' => myself()->_getAccountId(),
'trans_id' => $transId
),
array(
'client_result' => $result,
'modifytime' => myself()->_getNowTime()
)
);
}
}