<?php

namespace App\Admin\Repositories;

use App\Models\SiteAlbumLog as Model;
use App\Models\SiteAlbum as AlbumModel;
use Dcat\Admin\Admin;
use Dcat\Admin\Repositories\EloquentRepository;

class SiteAlbumLog extends EloquentRepository
{
    /**
     * Model.
     *
     * @var string
     */
    protected $eloquentClass = Model::class;

    /*
     * 记录日志
     */
    public static function log($action,$albumId,$model,$input)
    {
        $data = AlbumModel::find($albumId)->toArray();
        $input = json_decode($input,true);
        $content = [];
        if ($action == 'add') {
            if ($data['cover'] != '[]') {$content[] = '主图';}
            if ($data['en_detail'] != '[]') {$content[] = '英文详情页';}
            if ($data['cn_detail'] != '[]') {$content[] = '中文详情页';}
            if ($data['poster'] != '[]') {$content[] = '海报';}
            if ($data['cert'] != '[]') {$content[] = '证书';}
            if ($data['pdf'] != '[]') {$content[] = 'PDF';}
            if ($data['video'] != '[]') {$content[] = '视频';}
            if ($data['text_detail'] != '') {$content[] = '文字介绍';}
        } else if ($action == 'edit') {
            if ($data['cover'] != $input['cover']) {$content[] = '主图';}
            if ($data['en_detail'] != $input['en_detail']) {$content[] = '英文详情页';}
            if ($data['cn_detail'] != $input['cn_detail']) {$content[] = '中文详情页';}
            if ($data['poster'] != $input['poster']) {$content[] = '海报';}
            if ($data['cert'] != $input['cert']) {$content[] = '证书';}
            if ($data['pdf'] != $input['pdf']) {$content[] = 'PDF';}
            if ($data['video'] != $input['video']) {$content[] = '视频';}
            if ($data['text_detail'] != $input['text_detail']) {$content[] = '文字介绍';}
        }
        if (empty($content) == false) {
            $nickName = Admin::user()->name;
            $log = new Model();
            $log->user_name = $nickName;
            $log->action = $action;
            $log->model = $model;
            $log->content = implode(' ',$content);
            $log->content_id = $albumId;
            $log->save();
        }
    }
}
