<?php
namespace backendApi\modules\v1\models\lists\log;

use common\helpers\MongodbSearchFilter;
use common\libs\dataList\DataListInterface;
use common\libs\dataList\column\DateTime;
use common\models\LogAdminHandle;

class AdminHandleList extends \common\libs\dataList\DataList implements DataListInterface
{
    /**
     * 列表名称
     * @return string
     */
    public function getListName(){
        return '管理员操作日志';
    }

    /**
     * 列表筛选到的数据
     * @throws \yii\base\Exception
     */
    public function dataHandle()
    {
        $filter = MongodbSearchFilter::filterCondition([
            'opt_type' => 'opt_type',
            'opt_obj_name' => 'opt_obj_name',
            'remark' => 'remark',
            'admin_name' => 'admin_name',
            'created_at' => 'created_at',
            'period_num' => 'period_num',
            'ip' => 'ip',
            'device' => 'device',
            'user_agent' => 'user_agent',
            'request_route' => 'request_route',
        ]);
        $this->listData  = LogAdminHandle::lists($filter['condition'], []);
    }

    /**
     * 要展示和导出的所有字段
     * @return array
     */
    public function getColumn(){
        if(!$this->columns){
            $this->columns = [
                'save_before_content' => null,
                'save_after_content' => null,
                'opt_type' => [
                    'header' => '操作类型',
                    'headerOther' => [
                        'width' => '200',
                    ],
                    'valueOther' => function($row) {
                        return [
                            'tag'=>['type'=>'success', 'size' => 'small']
                        ];
                    },
                ],
                'opt_obj_name' => [
                    'header' => '操作对象编号',
                    'headerOther' => [
                        'width' => '130',
                    ],
                ],
                'remark' => [
                    'header' => '备注',
                    'headerOther' => [
                        'width' => '120',
                        'show-overflow-tooltip'=>true,
                        'min-width'=>'200',
                    ],
                ],
                'admin_name' => [
                    'header' => '操作人',
                    'headerOther' => [
                        'width' => '130',
                    ],
                ],
                'created_at' => [
                    'header' => '操作时间',
                    'value' => function($row) {
                        return (new DateTime([
                            'value' => $row['created_at'],
                        ]))->result();
                    },
                    'headerOther' => ['width' => '180'],
                ],
                'period_num' => '期数',
                'ip' => [
                    'header' => 'IP地址',
                    'headerOther' => [
                        'width' => '150',
                    ],
                ],
                'device' => [
                    'header' => '客户端',
                    'headerOther' => [
                        'width' => '150',
                    ],
                ],
                'user_agent' => [
                    'header' => '操作系统',
                    'headerOther' => [
                        'width' => '950',
                    ],
                ],
                'request_route' => [
                    'header' => '请求路径',
                    'headerOther' => [
                        'width' => '250',
                    ],
                ],
            ];
        }
        return $this->columns;
    }

    /**
     * 前台用于筛选的类型集合
     * @return mixed
     */
    public function getFilterTypes()
    {
        if(!$this->filterTypes){
            $selectData = [
                ['id'=>'更新期数配置','name'=>'更新期数配置'],
                ['id'=>'更新级别奖金配置','name'=>'更新级别奖金配置'],
                ['id'=>'更新奖金配置','name'=>'更新奖金配置'],
                ['id'=>'更新聘级奖金配置','name'=>'更新聘级奖金配置'],
                ['id'=>'更新转账配置','name'=>'更新转账配置'],
                ['id'=>'申请变动会员余额','name'=>'申请变动会员余额'],
                ['id'=>'审核会员余额','name'=>'审核会员余额'],
                ['id'=>'批量申请变动会员余额','name'=>'批量申请变动会员余额'],
                ['id'=>'空单录入','name'=>'空单录入'],
                ['id'=>'删除空单会员','name'=>'删除空单会员'],
                ['id'=>'修改会员级别','name'=>'修改会员级别'],
                ['id'=>'申请调整会员业绩','name'=>'申请调整会员业绩'],
                ['id'=>'申请修改会员状态','name'=>'申请修改会员状态'],
                ['id'=>'设置团队领导人','name'=>'设置团队领导人'],
                ['id'=>'申请修改会员状态','name'=>'申请修改会员状态'],
                ['id'=>'审核会员状态','name'=>'审核会员状态'],
                ['id'=>'显示图谱','name'=>'显示图谱'],
                ['id'=>'隐藏图谱','name'=>'隐藏图谱'],
                ['id'=>'设置报单中心','name'=>'设置报单中心'],
                ['id'=>'取消报单中心','name'=>'取消报单中心'],
                ['id'=>'会员激活','name'=>'会员激活'],
                ['id'=>'会员锁定','name'=>'会员锁定'],
                ['id'=>'修改会员资料','name'=>'修改会员资料'],
                ['id'=>'编辑管理员','name'=>'编辑管理员'],
                ['id'=>'申请移网','name'=>'申请移网'],
                ['id'=>'审核通过移网','name'=>'审核通过移网'],
                ['id'=>'重置密码','name'=>'重置密码'],
                ['id'=>'撤销体系','name'=>'撤销体系'],
                ['id'=>'添加体系','name'=>'添加体系'],
                ['id'=>'编辑体系','name'=>'编辑体系'],
                ['id'=>'恢复体系','name'=>'恢复体系'],
            ];
            $this->filterTypes = [
                'opt_type' => ['isUserTable'=>false, 'name'=>'操作类型', 'other'=> 'select', 'selectData'=> $selectData],
                'opt_obj_name' => ['isUserTable'=>false, 'name'=>'操作对象编号'],
                'remark' => ['isUserTable'=>false, 'name'=>'备注'],
                'admin_name' => ['isUserTable'=>false, 'name'=>'操作人'],
                'created_at' => ['isUserTable'=>false, 'name'=>'操作时间', 'other'=> 'date'],
                'period_num' => ['isUserTable'=>false, 'name'=>'期数'],
                'ip' => ['isUserTable'=>false, 'name'=>'IP地址'],
                'device' => ['isUserTable'=>false, 'name'=>'客户端'],
                'user_agent' => ['isUserTable'=>false, 'name'=>'操作系统'],
                'request_route' => ['isUserTable'=>false, 'name'=>'请求路径'],
            ];
        }
        return $this->filterTypes;
    }
}