53 lines
1.5 KiB
PHP
53 lines
1.5 KiB
PHP
|
|
<?php
|
||
|
|
namespace app\model;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 相册模型
|
||
|
|
* @property integer $id 主键(ID)
|
||
|
|
* @property integer $user_id 用户ID
|
||
|
|
* @property integer $group_id 内容
|
||
|
|
* @property string $url 图片
|
||
|
|
* @property string $title 标题
|
||
|
|
* @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,
|
||
|
|
],
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
public static function onAfterInsert($row){
|
||
|
|
$changeData = $row->getChangedData();
|
||
|
|
if(isset($changeData['url'])) {
|
||
|
|
Files::where('path',$changeData['url'])->inc('use_count');
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function onAfterUpdate($row){
|
||
|
|
$OrgData = $row->getOrigin();
|
||
|
|
$changeData = $row->getChangedData();
|
||
|
|
if(isset($OrgData['url']) && $OrgData['url']) {
|
||
|
|
\support\Log::info('OrgData string');
|
||
|
|
Files::where('path',$OrgData['url'])->dec('use_count');
|
||
|
|
};
|
||
|
|
if(isset($changeData['url']) && $changeData['url']) {
|
||
|
|
\support\Log::info('changeData string');
|
||
|
|
Files::where('path',$changeData['url'])->inc('use_count');
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function onAfterDelete($row){
|
||
|
|
Files::where('path',$row->url)->dec('use_count');
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|