98 lines
2.8 KiB
PHP
98 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace models;
|
|
|
|
use mt;
|
|
use phpcommon\SqlHelper;
|
|
|
|
class InAppRecord extends BaseModel {
|
|
|
|
public static function get()
|
|
{
|
|
$row = SqlHelper::ormSelectOne(
|
|
myself()->_getSelfMysql(),
|
|
't_inapp_record',
|
|
array(
|
|
'account_id' => myself()->_getAccountId(),
|
|
'daytime' => myself()->_getNowDaySeconds()
|
|
)
|
|
);
|
|
return $row;
|
|
}
|
|
|
|
public static function getTotalAmount()
|
|
{
|
|
$row = myself()->_getSelfMysql()->execQueryOne(
|
|
'SELECT SUM(amount_ok) AS total_amount FROM t_inapp_record WHERE account_id=:account_id',
|
|
array(
|
|
'account_id' => myself()->_getAccountId()
|
|
)
|
|
);
|
|
if ($row) {
|
|
if ($row['total_amount']) {
|
|
return $row['total_amount'];
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public static function addAmount($amount)
|
|
{
|
|
SqlHelper::upsert(
|
|
myself()->_getSelfMysql(),
|
|
't_inapp_record',
|
|
array(
|
|
'account_id' => myself()->_getAccountId(),
|
|
'daytime' => myself()->_getNowDaySeconds()
|
|
),
|
|
array(
|
|
'amount' => function () use($amount) {
|
|
return 'amount + ' . $amount;
|
|
},
|
|
'buy_times' => function () {
|
|
return 'buy_times + 1';
|
|
},
|
|
'modifytime' => myself()->_getNowTime(),
|
|
),
|
|
array(
|
|
'account_id' => myself()->_getAccountId(),
|
|
'amount' => $amount,
|
|
'buy_times' => 1,
|
|
'daytime' => myself()->_getNowDaySeconds(),
|
|
'createtime' => myself()->_getNowTime(),
|
|
'modifytime' => myself()->_getNowTime(),
|
|
)
|
|
);
|
|
}
|
|
|
|
public static function addAmountOk($accountId, $amount)
|
|
{
|
|
SqlHelper::upsert(
|
|
myself()->_getMysql($accountId),
|
|
't_inapp_record',
|
|
array(
|
|
'account_id' => $accountId,
|
|
'daytime' => myself()->_getNowDaySeconds()
|
|
),
|
|
array(
|
|
'amount_ok' => function () use($amount) {
|
|
return 'amount_ok + ' . $amount;
|
|
},
|
|
'buy_ok_times' => function () use($amount) {
|
|
return 'buy_ok_times + 1';
|
|
},
|
|
'modifytime' => myself()->_getNowTime(),
|
|
),
|
|
array(
|
|
'account_id' => $accountId,
|
|
'amount_ok' => $amount,
|
|
'buy_ok_times' => 1,
|
|
'daytime' => myself()->_getNowDaySeconds(),
|
|
'createtime' => myself()->_getNowTime(),
|
|
'modifytime' => myself()->_getNowTime(),
|
|
)
|
|
);
|
|
}
|
|
|
|
}
|