<?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\FlowRemainPv;
use Yii;

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

    /**
     * 列表筛选到的数据
     * @throws \yii\base\Exception
     */
    public function dataHandle() {
        $this->listData = FlowRemainPv::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' => FlowRemainPv::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,
                'PERIOD_NUM' => [
                    'header' => '期数', // 期数
                    'headerOther' => [
                        'width' => '150',
                    ],
                ],
                'USER_NAME' => [
                    'header' => '会员编号',//会员编号
                    'headerOther' => [
                        'width' => '150',
                    ],
                    'valueOther' => [
                        'tag' => ['type' => 'info', 'size' => 'small', 'class' => 'no-border']
                    ],
                ],
                'REAL_NAME' => [
                    'header' => '会员姓名',//会员姓名
                    'headerOther' => [
                        'width' => '120',
                    ],
                    'valueOther' => [
                        'tag' => ['type' => 'success', 'size' => 'small', 'class' => 'no-border']
                    ],
                ],
                'REMAIN_PV_FLOW' => [
                    'header' => '剩余PV流水',
                    'headerOther' => [
                        'width' => '150',
                        'prop' => 'REMAIN_PV_FLOW',
                    ],
                ],
                'REMAIN_PV_TOTAL' => [
                    'header' => '总剩余PV',
                    'headerOther' => [
                        'width' => '150',
                        'prop' => 'REMAIN_PV_TOTAL',
                    ],
                ],
                'UPDATED_AT' => [
                    'header' => '更新时间',//创建时间
                    'value' => function ($row) {
                        return (new DateTime([
                            'value' => $row['UPDATED_AT'],
                        ]))->result();
                    },
                    'headerOther' => ['width' => '170'],
                ],
                'ORDER_SN' => [
                    'header' => '订单编号',
                    'headerOther' => ['width' => '190'],
                ]
            ];
        }
        return $this->columns;
    }

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