<?php

namespace backendApi\modules\v1\models\lists\shop;

use common\helpers\Cache;
use common\helpers\user\Info;
use common\libs\dataList\column\Price;
use common\libs\dataList\DataListInterface;
use common\libs\dataList\column\DateTime;
use common\models\RemainPv;
use Yii;

class RemainPvList extends \common\libs\dataList\DataList implements DataListInterface {
    /**
     * 列表名称
     * @return string
     */
    public function getListName() {
        return '剩余BV';
    }

    /**
     * 列表筛选到的数据
     * @throws \yii\base\Exception
     */
    public function dataHandle() {
        $this->listData = RemainPv::lists($this->condition, $this->params, [
            'select' => 'FR.*,U.USER_NAME,U.REAL_NAME,U.IS_DEC',
            'orderBy' => 'FR.UPDATED_AT DESC,FR.ID DESC',
            'from' => RemainPv::tableName() . ' AS FR',
            'join' => [
                ['LEFT JOIN', \common\models\User::tableName() . ' AS U', 'FR.USER_ID=U.ID'],
            ],
            'page' => $this->page,
            'pageSize' => $this->pageSize,
        ]);
        foreach ($this->listData['list'] as $key => $value) {
//            $this->listData['list'][$key]['LAST_STATUS_NAME'] = \Yii::$app->params['userStatus'][$value['LAST_STATUS']]['label'] ?? '';
        }

    }

    /**
     * 要展示和导出的所有字段
     * @return array
     */
    public function getColumn() {
        if (!$this->columns) {
            $this->columns = [
                'ID' => null,
                'USER_NAME' => [
                    'header' => 'Member code',//会员编号
                    'headerOther' => [
                        'width' => '150',
                    ],
                    'valueOther' => [
                        'tag' => ['type' => 'info', 'size' => 'small', 'class' => 'no-border']
                    ],
                ],
                'REAL_NAME' => [
                    'header' => 'Member name',//会员姓名
                    'headerOther' => [
                        'width' => '120',
                    ],
                    'valueOther' => [
                        'tag' => ['type' => 'success', 'size' => 'small', 'class' => 'no-border']
                    ],
                ],
                'REMAIN_PV' => [
                    'header' => 'Remain BV',
                    'headerOther' => [
                        'width' => '150',
                        'prop' => 'REMAIN_PV',
                    ],
                ],
                'UPDATED_AT' => [
                    'header' => 'Updated Time',//创建时间
                    'value' => function ($row) {
                        return (new DateTime([
                            'value' => $row['UPDATED_AT'],
                        ]))->result();
                    },
                    'headerOther' => ['width' => '170'],
                ],
            ];
        }
        return $this->columns;
    }

    /**
     * 前台用于筛选的类型集合
     * @return mixed
     */
    public function getFilterTypes() {
        if (!$this->filterTypes) {
            $this->filterTypes = [
                'UPDATED_AT' => ['isUserTable' => false, 'name' => 'Updated Time', 'other' => 'date'], // 创建时间
                'USER_NAME' => ['isUserTable' => false, 'name' => 'Member Code'], // 会员编号
                'REAL_NAME' => ['isUserTable' => false, 'name' => 'Member Name'], // 会员姓名
            ];
        }
        return $this->filterTypes;
    }
}