<?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 \Yii::t('ctx', 'adminLoginLog');
    }

    /**
     * 列表筛选到的数据
     * @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' => \Yii::t('ctx', 'operatingType'),
                    'headerOther' => [
                        'width' => '200',
                    ],
                    'valueOther' => function($row) {
                        return [
                            'tag'=>['type'=>'success', 'size' => 'small']
                        ];
                    },
                ],
                'opt_obj_name' => [
                    'header' => \Yii::t('ctx', 'operationObjectNumber'),
                    'headerOther' => [
                        'width' => '150',
                    ],
                ],
                'remark' => [
                    'header' => \Yii::t('ctx', 'remarks'),
                    'headerOther' => [
                        'width' => '120',
                        'show-overflow-tooltip'=>true,
                        'min-width'=>'200',
                    ],
                ],
                'admin_name' => [
                    'header' => \Yii::t('ctx', 'operator'),
                    'headerOther' => [
                        'width' => '130',
                    ],
                ],
                'created_at' => [
                    'header' => \Yii::t('ctx', 'operatingTime'),
                    'value' => function($row) {
                        return (new DateTime([
                            'value' => $row['created_at'],
                        ]))->result();
                    },
                    'headerOther' => ['width' => '180'],
                ],
                'period_num' => [
                    'header' => \Yii::t('ctx', 'numberOfPhases'),
                    'headerOther' => [
                        'width' => '150',
                    ],
                ],
                'ip' => [
                    'header' => \Yii::t('ctx', 'IPAddress'),
                    'headerOther' => [
                        'width' => '150',
                    ],
                ],
                'device' => [
                    'header' => \Yii::t('ctx', 'client'),
                    'headerOther' => [
                        'width' => '150',
                    ],
                ],
                'user_agent' => [
                    'header' => \Yii::t('ctx', 'operatingSystem'),
                    'headerOther' => [
                        'width' => '950',
                    ],
                ],
                'request_route' => [
                    'header' => \Yii::t('ctx', 'requestPath'),
                    'headerOther' => [
                        'width' => '250',
                    ],
                ],
            ];
        }
        return $this->columns;
    }

    /**
     * 前台用于筛选的类型集合
     * @return mixed
     */
    public function getFilterTypes()
    {
        if(!$this->filterTypes){
            $selectData = [
                ['id'=>'更新期数配置','name'=>\Yii::t('ctx', 'updateNumberOfPhasesConfig')],
                ['id'=>'更新级别奖金配置','name'=>\Yii::t('ctx', 'updateLevelBonusConfig')],
                ['id'=>'更新奖金配置','name'=>\Yii::t('ctx', 'updateBonusConfig')],
                ['id'=>'更新聘级奖金配置','name'=>\Yii::t('ctx', 'updateRankBonusConfig')],
                ['id'=>'更新转账配置','name'=>\Yii::t('ctx', 'updateTransferConfig')],
                ['id'=>'申请变动会员余额','name'=>\Yii::t('ctx', 'requestChangeUserBalance')],
                ['id'=>'审核会员余额','name'=>\Yii::t('ctx', 'checkUserBalance')],
                ['id'=>'批量申请变动会员余额','name'=>\Yii::t('ctx', 'batchRequestChangeUserBalance')],
                ['id'=>'空单录入','name'=>\Yii::t('ctx', 'blankEntry')],
                ['id'=>'删除空单会员','name'=>\Yii::t('ctx', 'delBlankUser')],
                ['id'=>'修改会员级别','name'=>\Yii::t('ctx', 'changeUserLevel')],
                ['id'=>'申请调整会员业绩','name'=>\Yii::t('ctx', 'applyAdjustmentUserPerformance')],
                ['id'=>'申请修改会员状态','name'=>\Yii::t('ctx', 'applyModifyUserStatus')],
                ['id'=>'设置团队领导人','name'=>\Yii::t('ctx', 'setTeamLeaders')],
                //['id'=>'申请修改会员状态','name'=>'申请修改会员状态'],
                ['id'=>'审核会员状态','name'=>\Yii::t('ctx', 'checkUserStatus')],
                ['id'=>'显示图谱','name'=>\Yii::t('ctx', 'displayMap')],
                ['id'=>'隐藏图谱','name'=>\Yii::t('ctx', 'hiddenMap')],
                ['id'=>'设置报单中心','name'=>\Yii::t('ctx', 'setDeclarationCenter')],
                ['id'=>'取消报单中心','name'=>\Yii::t('ctx', 'cancelDeclarationCenter')],
                ['id'=>'会员激活','name'=>\Yii::t('ctx', 'userActivation')],
                ['id'=>'会员锁定','name'=>\Yii::t('ctx', 'userLocking')],
                ['id'=>'修改会员资料','name'=>\Yii::t('ctx', 'modifyUserInfo')],
                ['id'=>'编辑管理员','name'=>\Yii::t('ctx', 'editAdmin')],
                ['id'=>'申请移网','name'=>\Yii::t('ctx', 'applyRemoveNetwork')],
                ['id'=>'审核通过移网','name'=>\Yii::t('ctx', 'approveRemoveNetwork')],
                ['id'=>'重置密码','name'=>\Yii::t('ctx', 'resetPasswords')],
                ['id'=>'撤销体系','name'=>\Yii::t('ctx', 'cancellationSystem')],
                ['id'=>'添加体系','name'=>\Yii::t('ctx', 'addSystem')],
                ['id'=>'编辑体系','name'=>\Yii::t('ctx', 'editSystem')],
                ['id'=>'恢复体系','name'=>\Yii::t('ctx', 'recoverySystem')],
                ['id'=>'perf adjustment','name'=>'perf adjustment'],
                ['id'=>'调整订单期数','name'=>\Yii::t('ctx', 'shopOrderPeriodAdjust')],
                ['id'=>'调整会员最高聘级','name'=>\Yii::t('ctx', 'memberHighestEmpLvAdjust')],
                ['id'=>'调整会员最高聘级','name'=> \Yii::t('ctx', 'adjustMemberHighestDirector')],
            ];
            $this->filterTypes = [
                'opt_type' => ['isUserTable'=>false, 'name'=>\Yii::t('ctx', 'operatingType'), 'other'=> 'select', 'selectData'=> $selectData],
                'opt_obj_name' => ['isUserTable'=>false, 'name'=>\Yii::t('ctx', 'operationObjectNumber')],
                'remark' => ['isUserTable'=>false, 'name'=>\Yii::t('ctx', 'remarks')],
                'admin_name' => ['isUserTable'=>false, 'name'=>\Yii::t('ctx', 'operator')],
                'created_at' => ['isUserTable'=>false, 'name'=>\Yii::t('ctx', 'operatingTime'), 'other'=> 'date'],
                'period_num' => ['isUserTable'=>false, 'name'=>\Yii::t('ctx', 'numberOfPhases')],
                'ip' => ['isUserTable'=>false, 'name'=>\Yii::t('ctx', 'IPAddress')],
                'device' => ['isUserTable'=>false, 'name'=>\Yii::t('ctx', 'client')],
                'user_agent' => ['isUserTable'=>false, 'name'=>\Yii::t('ctx', 'operatingSystem')],
                'request_route' => ['isUserTable'=>false, 'name'=>\Yii::t('ctx', 'requestPath')],
            ];
        }
        return $this->filterTypes;
    }
}
