<?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;
use common\models\LogSystem;
use common\models\LogUserHandle;
use common\models\LogUserLogin;

class UserHandleList extends \common\libs\dataList\DataList implements DataListInterface
{
    /**
     * 列表名称
     * @return string
     */
    public function getListName(){
        return \Yii::t('ctx', 'userOperatingLog');
    }

    /**
     * 列表筛选到的数据
     * @throws \yii\base\Exception
     */
    public function dataHandle()
    {
        $filter = MongodbSearchFilter::filterCondition([
            'opt_type' => 'opt_type',
            'opt_obj_name' => 'opt_obj_name',
            'remark' => 'remark',
            'user_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  = LogUserHandle::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' => '130',
                    ],
                ],
                'remark' => [
                    'header' => \Yii::t('ctx', 'remarks'), // 备注
                    'headerOther' => [
                        'width' => '120',
                        'show-overflow-tooltip'=>true,
                        'min-width'=>'200',
                    ],
                ],
                'user_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' => \Yii::t('ctx', 'numberOfPhases'), // 期数
                'ip' => [
                    'header' => \Yii::t('ctx', 'IPAddress'), // IP地址
                    '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', 'enableDisableAutomaticWithdrawal')], // 开启关闭自动提现
                ['id'=>'开启关闭复销短信提醒','name'=>\Yii::t('ctx', 'enableDisableReSalesSMSReminder')], // 开启关闭复销短信提醒
                ['id'=>'会员转账','name'=>\Yii::t('ctx', 'memberTransfer')], // 会员转账
                ['id'=>'会员提现申请','name'=>\Yii::t('ctx', 'memberWithdrawalApplication')], // 会员提现申请
                ['id'=>'会员修改资料','name'=>\Yii::t('ctx', 'memberModificationInformation')], // 会员修改资料
                ['id'=>'修改主点位','name'=>\Yii::t('ctx', 'modifyMasterPoint')], // 修改主点位
            ];
            $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')], // 备注
                'user_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')], // IP地址
                '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;
    }
}
