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

use common\helpers\Cache;
use common\models\PerfMonth;
use common\models\PerfPeriod;
use common\models\User as modelUser;
use common\libs\dataList\column\Price;
use common\libs\dataList\DataListInterface;
use common\libs\dataList\column\DateTime;
use Yii;

class PerfPeriodList extends \common\libs\dataList\DataList implements DataListInterface
{
    /**
     * 列表名称
     * @return string
     */
    public function getListName(){
        return '期业绩列表';
    }

    /**
     * 列表筛选到的数据
     * @throws \yii\base\Exception
     */
    public function dataHandle()
    {
        $data = PerfPeriod::lists($this->condition, $this->params, [
            'select'=>'PP.*, U.USER_NAME, U.REAL_NAME',
            'from' => PerfPeriod::tableName().' AS PP',
            'join' => [
                ['LEFT JOIN', modelUser::tableName() . ' AS U', 'U.ID=PP.USER_ID'],
            ],
            'orderBy' => 'PP.ID DESC',
            'page' => $this->page,
            'pageSize' => $this->pageSize,
        ]);
        $this->listData = $data;
    }

    /**
     * 要展示和导出的所有字段
     * @return array
     */
    public function getColumn(){
        if(!$this->columns){
            $this->columns = [
                'PERIOD_NUM' => [
                    'header' =>  Yii::t('ctx', 'numberOfPhases'), // 期数
                    'headerOther' => [
                        'width' => '140',
                    ],
                ],
                'USER_NAME' => [
                    'header' => Yii::t('ctx', 'memberCode'), // 会员编号
                    'headerOther' => [
                        'width' => '120',
                    ],
                ],
                'REAL_NAME' => [
                    'header' => Yii::t('ctx', 'memberName'), // 会员姓名
                    'headerOther' => [
                        'width' => '150',
                    ],
                ],
                'PV_PCS' => [
                    'header' => Yii::t('ctx', 'personalPerformance'), // 个人业绩
                    'headerOther' => [
                        'width' => '160',
                    ],
                    'value' => function($row) {
                        return (new Price([
                            'value' => $row['PV_PCS'],
                        ]))->result();
                    },
                ],
                'IS_ACTIVE' => [
                    'header' => Yii::t('ctx', 'whetherActive'), // 是否活跃
                    'headerOther' => [
                        'width' => '120',
                    ],
                    'value' => function($row) {
                        return $row['IS_ACTIVE'] == 1 ? Yii::t('ctx', 'yes') : Yii::t('ctx', 'no');
                    },
                ],
                'PV_PCS_ZC' => [
                    'header' => Yii::t('ctx', 'declarationPerformance'), // 报单业绩
                    'headerOther' => [
                        'width' => '180',
                    ],
                    'value' => function($row) {
                        return (new Price([
                            'value' => $row['PV_PCS_ZC'],
                        ]))->result();
                    },
                ],
                'PV_PCS_FX' => [
                    'header' => Yii::t('ctx', 'cancellationPerformance'), // 复消业绩
                    'headerOther' => [
                        'width' => '190',
                    ],
                    'value' => function($row) {
                        return (new Price([
                            'value' => $row['PV_PCS_FX'],
                        ]))->result();
                    },
                ],
//                'PV_1L' => [
//                    'header' =>  Yii::t('ctx', 'LNewMarketPerformance'), // 一市场新增业绩
//                    'headerOther' => [
//                        'width' => '200',
//                    ],
//                    'value' => function($row) {
//                        return (new Price([
//                            'value' => $row['PV_1L'],
//                        ]))->result();
//                    },
//                ],
//                'PV_1L_ZC' => [
//                    'header' => Yii::t('ctx', 'LNewPerformanceOfMarketEntry'), // 一市场报单新增业绩
//                    'headerOther' => [
//                        'width' => '250',
//                    ],
//                    'value' => function($row) {
//                        return (new Price([
//                            'value' => $row['PV_1L_ZC'],
//                        ]))->result();
//                    },
//                ],
//                'PV_1L_FX' => [
//                    'header' => Yii::t('ctx', 'LNewPerformanceOfMarketReCancellation'), // 一市场复消新增业绩
//                    'headerOther' => [
//                        'width' => '320',
//                    ],
//                    'value' => function($row) {
//                        return (new Price([
//                            'value' => $row['PV_1L_FX'],
//                        ]))->result();
//                    },
//                ],
//                'PV_2L' => [
//                    'header' => Yii::t('ctx', 'RNewMarketPerformance'), // 二市场新增业绩
//                    'headerOther' => [
//                        'width' => '200',
//                    ],
//                    'value' => function($row) {
//                        return (new Price([
//                            'value' => $row['PV_2L'],
//                        ]))->result();
//                    },
//                ],
//                'PV_2L_ZC' => [
//                    'header' => Yii::t('ctx', 'RNewPerformanceOfMarketEntry'), // 二市场报单新增业绩
//                    'headerOther' => [
//                        'width' => '260',
//                    ],
//                    'value' => function($row) {
//                        return (new Price([
//                            'value' => $row['PV_2L_ZC'],
//                        ]))->result();
//                    },
//                ],
//                'PV_2L_FX' => [
//                    'header' => Yii::t('ctx', 'RNewPerformanceOfMarketReCancellation'), // 二市场复消新增业绩
//                    'headerOther' => [
//                        'width' => '320',
//                    ],
//                    'value' => function($row) {
//                        return (new Price([
//                            'value' => $row['PV_2L_FX'],
//                        ]))->result();
//                    },
//                ],
//                'SURPLUS_1L' => [
//                    'header' => Yii::t('ctx', 'LMarketBalancePerformance'), // 一市场结余业绩
//                    'value' => function($row) {
//                        return (new Price([
//                            'value' => $row['SURPLUS_1L'],
//                        ]))->result();
//                    },
//                    'headerOther' => [
//                        'width' => '220',
//                        'prop'=>'SURPLUS_1L',
//                    ],
//                ],
//                'SURPLUS_2L' => [
//                    'header' => Yii::t('ctx', 'RMarketBalancePerformance'), // 二市场结余业绩
//                    'value' => function($row) {
//                        return (new Price([
//                            'value' => $row['SURPLUS_2L'],
//                        ]))->result();
//                    },
//                    'headerOther' => [
//                        'width' => '220',
//                        'prop'=>'SURPLUS_2L',
//                    ],
//                ],
//                'SURPLUS_1L_ZC' => [
//                    'header' =>  Yii::t('ctx', 'LMarketEntryBalancePerformance'), // 一市场报单结余业绩
//                    'value' => function($row) {
//                        return (new Price([
//                            'value' => $row['SURPLUS_1L_ZC'],
//                        ]))->result();
//                    },
//                    'headerOther' => [
//                        'width' => '260',
//                        'prop'=>'SURPLUS_1L_ZC',
//                    ],
//                ],
//                'SURPLUS_2L_ZC' => [
//                    'header' => Yii::t('ctx', 'RMarketEntryBalancePerformance'), // 二市场报单结余业绩
//                    'value' => function($row) {
//                        return (new Price([
//                            'value' => $row['SURPLUS_2L_ZC'],
//                        ]))->result();
//                    },
//                    'headerOther' => [
//                        'width' => '260',
//                        'prop'=>'SURPLUS_2L_ZC',
//                    ],
//                ],
//                'SURPLUS_1L_FX' => [
//                    'header' => Yii::t('ctx', 'LMarketReconditioningBalancePerformance'), // 一市场复消结余业绩
//                    'value' => function($row) {
//                        return (new Price([
//                            'value' => $row['SURPLUS_1L_FX'],
//                        ]))->result();
//                    },
//                    'headerOther' => [
//                        'width' => '320',
//                        'prop'=>'SURPLUS_1L_FX',
//                    ],
//                ],
//                'SURPLUS_2L_FX' => [
//                    'header' =>Yii::t('ctx', 'RMarketReCancellationBalancePerformance'), // 二市场复消结余业绩
//                    'value' => function($row) {
//                        return (new Price([
//                            'value' => $row['SURPLUS_2L_FX'],
//                        ]))->result();
//                    },
//                    'headerOther' => [
//                        'width' => '330',
//                        'prop'=>'SURPLUS_2L_FX',
//                    ],
//                ],
                'PV_PSS' => [
                    'header' => Yii::t('ctx', 'teamPerformance'), // 团队业绩
                    'headerOther' => [
                        'width' => '150',
                    ],
                    'value' => function($row) {
                        return (new Price([
                            'value' => $row['PV_PSS'],
                        ]))->result();
                    },
                ],
                'CREATED_AT' => [
                    'header' => Yii::t('ctx', 'createAt'), // 创建时间
                    'value' => function($row) {
                        return (new DateTime([
                            'value' => $row['CREATED_AT'],
                        ]))->result();
                    },
                    'headerOther' => ['width' => '170'],
                ],
            ];
        }
        return $this->columns;
    }

    /**
     * 前台用于筛选的类型集合
     * @return mixed
     */
    public function getFilterTypes()
    {
        if(!$this->filterTypes){
            $this->filterTypes = [
                'PERIOD_NUM'=> ['isUserTable'=> false, 'name'=> Yii::t('ctx', 'numberOfPhases')], // 期数
                'USER_NAME'=> ['isUserTable'=> false, 'name'=> Yii::t('ctx', 'memberCode')], // 会员编号
                'CREATED_AT'=> ['isUserTable'=> false, 'name'=> Yii::t('ctx', 'createAt'), 'other'=> 'date'], // 创建时间
            ];
        }
        return $this->filterTypes;
    }
}
