101 lines
3.2 KiB
PHP
101 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace models;
|
|
|
|
use mt;
|
|
use phpcommon\SqlHelper;
|
|
|
|
class ShopBuyRecord extends BaseModel {
|
|
|
|
public static function find($itemId)
|
|
{
|
|
$row = SqlHelper::ormSelectOne(
|
|
myself()->_getSelfMysql(),
|
|
't_shop_buy_record',
|
|
array(
|
|
'account_id' => myself()->_getAccountId(),
|
|
'item_id' => $itemId,
|
|
)
|
|
);
|
|
return $row;
|
|
}
|
|
|
|
public static function all()
|
|
{
|
|
$rows = SqlHelper::ormSelect(
|
|
myself()->_getSelfMysql(),
|
|
't_shop_buy_record',
|
|
array(
|
|
'account_id' => myself()->_getAccountId(),
|
|
)
|
|
);
|
|
return array_map(function($row) {
|
|
$nowDaySeconds = myself()->_getNowDaySeconds();
|
|
if (!($row['last_buy_time'] >= $nowDaySeconds && $row['last_buy_time'] <= $nowDaySeconds)) {
|
|
$row['this_day_buy_times'] = 0;
|
|
}
|
|
$mondaySeconds = myself()->_getMondaySeconds();
|
|
if (!($row['last_buy_time'] >= $mondaySeconds && $row['last_buy_time'] <= $mondaySeconds)) {
|
|
$row['this_week_buy_times'] = 0;
|
|
}
|
|
return $row;
|
|
}, $rows);
|
|
}
|
|
|
|
public static function allToHash()
|
|
{
|
|
$rows = self::all();
|
|
$buyRecordHash = array();
|
|
array_walk($rows, function ($row) use(&$buyRecordHash) {
|
|
$buyRecordHash[$row['item_id']] = $row;
|
|
});
|
|
return $buyRecordHash;
|
|
}
|
|
|
|
public static function toDto($row)
|
|
{
|
|
return array(
|
|
);
|
|
}
|
|
|
|
public static function add($itemId, $itemNum)
|
|
{
|
|
SqlHelper::upsert(
|
|
myself()->_getSelfMysql(),
|
|
't_shop_buy_record',
|
|
array(
|
|
'account_id' => myself()->_getAccountId(),
|
|
'item_id' => $itemId,
|
|
),
|
|
array(
|
|
'this_day_buy_times' => function () {
|
|
$nowDaySeconds = myself()->_getNowDaySeconds();
|
|
$cond = " last_buy_time>=${nowDaySeconds} AND last_buy_time<=${nowDaySeconds} + 3600 * 24 ";
|
|
return "CASE WHEN (${cond}) THEN this_day_buy_times + 1 ELSE 0 END";
|
|
},
|
|
'this_week_buy_times' => function () {
|
|
$mondaySeconds = myself()->_getMondaySeconds();
|
|
$cond = " last_buy_time>=${mondaySeconds} AND last_buy_time<=${mondaySeconds} + 3600 * 24 * 7 ";
|
|
return "CASE WHEN (${cond}) THEN this_week_buy_times + 1 ELSE 0 END";
|
|
},
|
|
'total_buy_times' => function () {
|
|
return 'total_buy_times + 1';
|
|
},
|
|
'last_buy_time' => myself()->_getNowTime(),
|
|
'modifytime' => myself()->_getNowTime(),
|
|
),
|
|
array(
|
|
'account_id' => myself()->_getAccountId(),
|
|
'item_id' => $itemId,
|
|
'this_day_buy_times' => 1,
|
|
'this_week_buy_times' => 1,
|
|
'total_buy_times' => 1,
|
|
'last_buy_time' => myself()->_getNowTime(),
|
|
'createtime' => myself()->_getNowTime(),
|
|
'modifytime' => myself()->_getNowTime(),
|
|
)
|
|
);
|
|
}
|
|
|
|
}
|