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

use common\helpers\Cache;
use common\helpers\user\Info;
use common\models\Countries;
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, C.NAME AS COUNTRY',
            'from' => UserPerf::tableName().' AS UP',
            'join' => [
                ['INNER JOIN', modelUser::tableName() . ' AS U', 'UP.USER_ID=U.ID'],
                ['INNER JOIN', Countries::tableName() . ' AS C', 'U.COUNTRY_ID=C.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' => Yii::t('ctx', 'memberCode'), // 会员编号
                    'headerOther' => [
                        'width' => '200',
                    ],
                ],
                'REAL_NAME' => [
                    'header' => Yii::t('ctx', 'memberName'), // 会员姓名
                    'headerOther' => [
                        'width' => '200',
                    ],
                ],
                'COUNTRY' => [
                    'header' => Yii::t('ctx', 'country'),
                ],
                'PV_PCS' => [
                    'header' => Yii::t('ctx', 'personalPerformance'), // 个人业绩
                    'headerOther' => [
                        'width' => '180',
                    ],
                    'value' => function($row) {
                        return (new Price([
                            'value' => $row['PV_PCS_ZC'] + $row['PV_PCS_FX'],
                        ]))->result();
                    },
                ],
//                'SURPLUS_1L' => [
//                    'header' => Yii::t('ctx', 'remainderLeftLeg'), // 一市场剩余业绩
//                    'headerOther' => [
//                        'width' => '240',
//                    ],
//                    'value' => function($row) {
//                        return (new Price([
//                            'value' => $row['SURPLUS_1L'],
//                        ]))->result();
//                    },
//                ],
//                'SURPLUS_2L' => [
//                    'header' => Yii::t('ctx', 'remainderRightLeg'), // 二市场剩余业绩
//                    'headerOther' => [
//                        'width' => '240',
//                    ],
//                    'value' => function($row) {
//                        return (new Price([
//                            'value' => $row['SURPLUS_2L'],
//                        ]))->result();
//                    },
//                ],
                'PV_PSS_TOTAL' => [
                    'header' => Yii::t('ctx', 'cumulativeTeamPerformance'), // 累计团队业绩
                    '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'=> Yii::t('ctx', 'memberCode')], // 会员编号
            ];
        }
        return $this->filterTypes;
    }
}
