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

use common\helpers\Cache;
use common\helpers\user\Info;
use common\models\PerfMonth;
use common\models\User as modelUser;
use common\libs\dataList\column\Price;
use common\libs\dataList\DataListInterface;
use common\libs\dataList\column\DateTime;
use common\models\UserInfo;
use common\models\UserPerf;
use Yii;

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

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

    /**
     * 要展示和导出的所有字段
     * @return array
     */
    public function getColumn(){
        if(!$this->columns){
            $this->columns = [
                'USER_NAME' => [
                    'header' => 'Member code',//会员编号
                    'headerOther' => [
                        'width' => '200',
                    ],
                ],
                'REAL_NAME' => [
                    'header' => 'Member name',//会员姓名
                    'headerOther' => [
                        'width' => '200',
                    ],
                ],
                'PV_PCS' => [
                    'header' => 'Personal performance',//个人业绩
                    'headerOther' => [
                        'width' => '180',
                    ],
                    'value' => function($row) {
                        return (new Price([
                            'value' => $row['PV_PCS_ZC'] + $row['PV_PCS_FX'],
                        ]))->result();
                    },
                ],
                'SURPLUS_1L' => [
                    'header' => 'Left market residual performance',//一市场剩余业绩
                    'headerOther' => [
                        'width' => '240',
                    ],
                    'value' => function($row) {
                        return (new Price([
                            'value' => $row['SURPLUS_1L'],
                        ]))->result();
                    },
                ],
                'SURPLUS_2L' => [
                    'header' => 'Right market residual performance',//二市场剩余业绩
                    'headerOther' => [
                        'width' => '240',
                    ],
                    'value' => function($row) {
                        return (new Price([
                            'value' => $row['SURPLUS_2L'],
                        ]))->result();
                    },
                ],
//                'SURPLUS_3L' => [
//                    'header' => '三市场剩余业绩',
//                    'headerOther' => [
//                        'width' => '150',
//                    ],
//                    'value' => function($row) {
//                        return (new Price([
//                            'value' => $row['SURPLUS_3L'],
//                        ]))->result();
//                    },
//                ],
//                'SURPLUS_1L_ZC' => [
//                    'header' => 'I. remaining performance of market declaration',//一市场报单剩余业绩
//                    'headerOther' => [
//                        'width' => '150',
//                    ],
//                    'value' => function($row) {
//                        return (new Price([
//                            'value' => $row['SURPLUS_1L_ZC'],
//                        ]))->result();
//                    },
//                ],
//                'SURPLUS_2L_ZC' => [
//                    'header' => 'II. remaining performance of market declaration',//二市场报单剩余业绩
//                    'headerOther' => [
//                        'width' => '150',
//                    ],
//                    'value' => function($row) {
//                        return (new Price([
//                            'value' => $row['SURPLUS_2L_ZC'],
//                        ]))->result();
//                    },
//                ],
//                'SURPLUS_3L_ZC' => [
//                    'header' => '三市场报单剩余业绩',
//                    'headerOther' => [
//                        'width' => '150',
//                    ],
//                    'value' => function($row) {
//                        return (new Price([
//                            'value' => $row['SURPLUS_3L_ZC'],
//                        ]))->result();
//                    },
//                ],
//                'VIP_SURPLUS_1L_ZC' => [
//                    'header' => 'I. remaining performance of VIP declaration in the market',//一市场VIP报单剩余业绩
//                    'headerOther' => [
//                        'width' => '150',
//                    ],
//                    'value' => function($row) {
//                        return (new Price([
//                            'value' => $row['VIP_SURPLUS_1L_ZC'],
//                        ]))->result();
//                    },
//                ],
//                'VIP_SURPLUS_2L_ZC' => [
//                    'header' => 'II. remaining performance of VIP declaration in the market',//二市场VIP报单剩余业绩
//                    'headerOther' => [
//                        'width' => '150',
//                    ],
//                    'value' => function($row) {
//                        return (new Price([
//                            'value' => $row['VIP_SURPLUS_2L_ZC'],
//                        ]))->result();
//                    },
//                ],
//                'VIP_SURPLUS_3L_ZC' => [
//                    'header' => '三市场VIP报单剩余业绩',
//                    'headerOther' => [
//                        'width' => '150',
//                    ],
//                    'value' => function($row) {
//                        return (new Price([
//                            'value' => $row['VIP_SURPLUS_3L_ZC'],
//                        ]))->result();
//                    },
//                ],
                'PV_PSS_TOTAL' => [
                    'header' => 'Cumulative team performance',//累计团队业绩
                    'headerOther' => [
                        'width' => '250',
                    ],
                    'value' => function($row) {
                        return (new Price([
                            'value' => $row['PV_PSS_TOTAL'],
                        ]))->result();
                    },
                ],
            ];
        }
        return $this->columns;
    }

    /**
     * 前台用于筛选的类型集合
     * @return mixed
     */
    public function getFilterTypes()
    {
        if(!$this->filterTypes){
            $this->filterTypes = [
                'USER_NAME'=> ['isUserTable'=> false, 'name'=> 'Member code'],//会员编号
            ];
        }
        return $this->filterTypes;
    }
}