Files

71 lines
2.0 KiB
PHP
Raw Permalink Normal View History

2026-02-15 19:41:56 +08:00
<?php
namespace app\model;
/**
* 相册模型
* @property integer $id 主键(ID)
* @property integer $user_id 用户ID
2026-04-04 08:52:59 +08:00
* @property integer $group_id 群组ID
* @property integer $userID 用户ID
* @property integer $groupID 群组ID
2026-02-15 19:41:56 +08:00
* @property string $title 标题
2026-04-04 08:52:59 +08:00
* @property int $image 封面图片ID
* @property int $weigh 排序权重,越小越靠前
2026-02-15 19:41:56 +08:00
* @property integer $created_at 创建时间
* @property integer $updated_at 更新时间
* @property integer $status 状态(0:隐藏 1:正常)
*/
class Album extends Base
{
protected $name = 'album';
protected function getOptions(): array
{
return array_merge(parent::getOptions(), [
'insert' => [
'status' => 1,
],
2026-04-04 08:52:59 +08:00
'append'=>[
'userID',
'groupID'
]
2026-02-15 19:41:56 +08:00
]);
}
public static function onAfterInsert($row){
$changeData = $row->getChangedData();
2026-04-04 08:52:59 +08:00
if(isset($changeData['image'])) {
Files::where('path',$changeData['image'])->inc('use_count');
2026-02-15 19:41:56 +08:00
};
}
public static function onAfterUpdate($row){
$OrgData = $row->getOrigin();
$changeData = $row->getChangedData();
2026-04-04 08:52:59 +08:00
if(isset($OrgData['image']) && $OrgData['image']) {
2026-02-15 19:41:56 +08:00
\support\Log::info('OrgData string');
2026-04-04 08:52:59 +08:00
Files::where('path',$OrgData['image'])->dec('use_count');
2026-02-15 19:41:56 +08:00
};
2026-04-04 08:52:59 +08:00
if(isset($changeData['image']) && $changeData['image']) {
2026-02-15 19:41:56 +08:00
\support\Log::info('changeData string');
2026-04-04 08:52:59 +08:00
Files::where('path',$changeData['image'])->inc('use_count');
2026-02-15 19:41:56 +08:00
};
}
2026-04-04 08:52:59 +08:00
public static function onBeforeDelete($row){
if($row->total>0){
return false;
}
}
2026-02-15 19:41:56 +08:00
public static function onAfterDelete($row){
2026-04-04 08:52:59 +08:00
Files::where('path',$row->image)->dec('use_count');
}
function getGroupIDAttr($v,$row){
return $v?:$row['group_id'];
}
function getUserIDAttr($v,$row){
return $v?:$row['user_id'];
2026-02-15 19:41:56 +08:00
}
}