161 lines
4.7 KiB
PHP
161 lines
4.7 KiB
PHP
<?php
|
|
|
|
|
|
namespace models;
|
|
|
|
use mt;
|
|
use phpcommon\SqlHelper;
|
|
class Emoji extends BaseModel
|
|
{
|
|
private static function defaultUseEmoji(){
|
|
return array(
|
|
array(
|
|
'item_id' => 0,
|
|
"slot_id" => 1
|
|
),
|
|
array(
|
|
'item_id' => 0,
|
|
"slot_id" => 2
|
|
),
|
|
array(
|
|
'item_id' => 0,
|
|
"slot_id" => 3
|
|
),
|
|
array(
|
|
'item_id' => 0,
|
|
"slot_id" => 4
|
|
),
|
|
array(
|
|
'item_id' => 0,
|
|
"slot_id" => 5
|
|
),
|
|
array(
|
|
'item_id' => 0,
|
|
"slot_id" => 6
|
|
),
|
|
);
|
|
}
|
|
|
|
|
|
|
|
public static function emojiList($cb){
|
|
SqlHelper::ormSelect(
|
|
myself()->_getSelfMysql(),
|
|
't_emoji',
|
|
array(
|
|
'account_id'=> myself()->_getAccountId(),
|
|
),
|
|
function ($row) use($cb) {
|
|
$cb($row);
|
|
}
|
|
);
|
|
}
|
|
|
|
public static function toDto($row){
|
|
return array(
|
|
'item_id' => $row['item_id'],
|
|
// 'valid_time' => $row['valid_time'],
|
|
'left_time' => max(0,$row['valid_time'] - (myself()->_getNowTime()-$row['last_get_time']) ),
|
|
);
|
|
}
|
|
|
|
public static function getUseEmoji(){
|
|
$row = SqlHelper::ormSelectOne(
|
|
myself()->_getSelfMysql(),
|
|
't_user_use_emoji',
|
|
array(
|
|
'account_id'=> myself()->_getAccountId()
|
|
)
|
|
);
|
|
if ($row){
|
|
$useEmojiList = emptyReplace(json_decode($row['used'], true), array());
|
|
$isUpdate = 0;
|
|
foreach ($useEmojiList as &$value){
|
|
$emojiDb = self::findEmoji($value['item_id']);
|
|
if ($emojiDb){
|
|
$emojiDto = self::toDto($emojiDb);
|
|
if ($emojiDto['left_time'] == 0){
|
|
$value['item_id'] = 0;
|
|
$isUpdate = 1;
|
|
}
|
|
}
|
|
}
|
|
if ($isUpdate){
|
|
self::updateEmoji(json_encode($useEmojiList));
|
|
}
|
|
}else{
|
|
$useEmojiList = self::defaultUseEmoji();
|
|
}
|
|
return $useEmojiList;
|
|
}
|
|
|
|
public static function updateEmoji($fields){
|
|
SqlHelper::upsert
|
|
(myself()->_getSelfMysql(),
|
|
't_user_use_emoji',
|
|
array(
|
|
'account_id' => myself()->_getAccountId(),
|
|
),
|
|
array(
|
|
'used' => $fields,
|
|
'modifytime' => myself()->_getNowTime(),
|
|
),
|
|
array(
|
|
'account_id' => myself()->_getAccountId(),
|
|
'used' => $fields,
|
|
'createtime' => myself()->_getNowTime(),
|
|
'modifytime' => myself()->_getNowTime(),
|
|
)
|
|
);
|
|
}
|
|
|
|
public static function findEmoji($itemId){
|
|
return SqlHelper::ormSelectOne(
|
|
myself()->_getSelfMysql(),
|
|
't_emoji',
|
|
array(
|
|
'account_id'=> myself()->_getAccountId(),
|
|
'item_id'=> $itemId,
|
|
)
|
|
);
|
|
}
|
|
|
|
public static function addEmoji($itemMeta,$time){
|
|
$row = self::findEmoji($itemMeta['id']);
|
|
if ($row){
|
|
$leftTime = max(0,$row['valid_time'] - (myself()->_getNowTime()-$row['last_get_time']) );
|
|
SqlHelper::update
|
|
(myself()->_getSelfMysql(),
|
|
't_emoji',
|
|
array(
|
|
'account_id' => myself()->_getAccountId(),
|
|
'item_id' => $itemMeta['id'],
|
|
),
|
|
array(
|
|
'last_get_time' => myself()->_getNowTime(),
|
|
'valid_time' => $leftTime + $time * 86400,
|
|
'modifytime' => myself()->_getNowTime(),
|
|
)
|
|
);
|
|
}else{
|
|
SqlHelper::insert
|
|
(myself()->_getSelfMysql(),
|
|
't_emoji',
|
|
array(
|
|
'account_id' => myself()->_getAccountId(),
|
|
'item_id' => $itemMeta['id'],
|
|
'last_get_time' => myself()->_getNowTime(),
|
|
'valid_time' => $time * 86400,
|
|
'createtime' => myself()->_getNowTime(),
|
|
'modifytime' => myself()->_getNowTime(),
|
|
)
|
|
);
|
|
}
|
|
myself()->_addTgLog("addEmojiItem",array(
|
|
'item_id'=>$itemMeta['id'],
|
|
'item_num'=>1,
|
|
'use_time'=>$time,
|
|
));
|
|
}
|
|
|
|
} |