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

use common\helpers\Cache;
use common\helpers\LoggerTool;
use common\helpers\Tool;
use common\helpers\user\Info;
use common\libs\dataList\DataListInterface;
use common\models\ApproachOrder;
use common\models\ApproachOrderGoods;
use common\models\Countries;
use common\models\Currency;
use common\models\DecOrder;
use common\models\Order;
use common\models\OrderGoods;
use common\models\ShopGoods;
use common\models\User;
use common\libs\dataList\column\DateTime;
use yii\data\Pagination;
use yii\db\Query;

class OrderList extends \common\libs\dataList\DataList implements DataListInterface
{
    /**
     * 列表名称
     * @return string
     */
    public function getListName(){
        return '订单列表';
    }

    /**
     * 列表筛选到的数据
     */
    public function dataHandle()
    {
        $orderQuery = Order::find()
            ->alias('O')
            ->where($this->condition, $this->params)
            ->select('O.*,U.REAL_NAME,U.DEC_ID,SG.CATEGORY_TYPE,OG.REAL_PRICE,OG.TAX_RATE,OG.BUY_NUMS,OG.SKU_CODE,OG.GOODS_TITLE,OG.REAL_PV,OG.STANDARD_PRICE,CS.NAME AS COUNTRY,CY.CODE AS CURRENCY, O.DEC_USER_ID AS ORDER_DEC_ID')
            ->join('LEFT JOIN', User::tableName() . ' AS U', 'U.ID=O.USER_ID')
            ->join('LEFT JOIN', OrderGoods::tableName() . ' AS OG', 'OG.ORDER_SN=O.SN')
            ->join('LEFT JOIN', ShopGoods::tableName() . ' AS SG', 'SG.ID=OG.GOODS_ID')
            ->join('LEFT JOIN', Countries::tableName() . ' AS CS', 'CS.ID=O.COUNTRY_ID')
            ->join('LEFT JOIN', Currency::tableName() . ' AS CY', 'CY.ID=O.CURRENCY_ID')
            ->join('LEFT JOIN', DecOrder::tableName() . ' AS DO', 'DO.ORDER_SN=O.SN')
            ->orderBy('O.CREATED_AT DESC');

        // 订单中间表只查询待支付和支付失败的订单
        $this->params[':NOT_PAID'] = \Yii::$app->params['orderStatus']['notPaid']['value'];   // 待支付
        $this->params[':FAIL_PAID'] = \Yii::$app->params['orderStatus']['failPaid']['value'];   // 支付失败
        $orderStandardQuery = ApproachOrder::find()
            ->alias('O')
            ->where($this->condition . ' AND (O.STATUS = :NOT_PAID OR O.STATUS = :FAIL_PAID)', $this->params)
            ->select('O.*,U.REAL_NAME,U.DEC_ID,SG.CATEGORY_TYPE,OG.REAL_PRICE,OG.TAX_RATE,OG.BUY_NUMS,OG.SKU_CODE,OG.GOODS_TITLE,OG.REAL_PV,OG.STANDARD_PRICE,CS.NAME AS COUNTRY,CY.CODE AS CURRENCY, O.DEC_USER_ID AS ORDER_DEC_ID')
            ->join('LEFT JOIN', User::tableName() . ' AS U', 'U.ID=O.USER_ID')
            ->join('LEFT JOIN', ApproachOrderGoods::tableName() . ' AS OG', 'OG.ORDER_SN=O.SN')
            ->join('LEFT JOIN', ShopGoods::tableName() . ' AS SG', 'SG.ID=OG.GOODS_ID')
            ->join('LEFT JOIN', Countries::tableName() . ' AS CS', 'CS.ID=O.COUNTRY_ID')
            ->join('LEFT JOIN', Currency::tableName() . ' AS CY', 'CY.ID=O.CURRENCY_ID')
            ->join('LEFT JOIN', DecOrder::tableName() . ' AS DO', 'DO.ORDER_SN=O.SN')
            ->orderBy('O.CREATED_AT DESC');

        $queryAll = $orderQuery->union($orderStandardQuery, true);
        $query = (new Query())->from(['Q' => $queryAll])->select('Q.*')->distinct()->orderBy(['CREATED_AT' => SORT_DESC]);

        $totalCount = $query->count();
        $pagination = new Pagination(['totalCount' => $totalCount, 'pageSize' => \Yii::$app->request->get('pageSize')]);
        $lists = $query->offset($pagination->offset)->limit($pagination->limit)->all();

        $this->listData = [
            'list' => $lists,
            'currentPage'=>$pagination->page,
            'totalPages'=>$pagination->pageCount,
            'startNum' => $pagination->page * $pagination->pageSize + 1,
            'totalCount' => $pagination->totalCount,
            'pageSize' => $pagination->pageSize,
        ];

        foreach ($this->listData['list'] as $key => $value) {
            if ($value['ORDER_TYPE'] == 'FX') {
                if ($value['DEC_USER_ID']) {
                    // 复消：显示传入的报单中心
                    $this->listData['list'][$key]['DEC_USER_NAME'] = $value['DEC_USER_ID'];
                } else {
                    // 会员复消：订单会员的所属报单中心
                    $this->listData['list'][$key]['DEC_USER_NAME'] = Info::getUserNameByUserId($value['DEC_ID']);
                }
            } else {
//                $this->listData['list'][$key]['DEC_USER_NAME'] = Info::getUserNameByUserId($value['ORDER_DEC_ID']);
                $this->listData['list'][$key]['DEC_USER_NAME'] = $value['ORDER_DEC_ID'];
            }

            $CREATE_USER_ID = Info::getUserIdByUserName($value['CREATE_USER']);
            $this->listData['list'][$key]['CREATE_USER_NAME'] = Info::getUserRealNameByUserId($CREATE_USER_ID);
        }
    }

    /**
     * 要展示和导出的所有字段
     * @return array
     */
    public function getColumn(){
        $regionConfig = Cache::getRegionConfig();
        if(!$this->columns){
            $this->columns = [
                'ID' => null,
                'DEC_SN' => null,
                'USER_NAME' => [
                    'header' => \Yii::t('ctx', 'shopOrderListMemberCode'), // 会员编号
                    'headerOther' => ['width' => '120'],
                ],
                'DEC_USER_NAME' => [
                    'header' => \Yii::t('ctx', 'shopOrderListStockist'), // 报单中心
                    'headerOther' => ['width' => '120'],
                ],
                'CREATE_USER' => [
                    'header' => \Yii::t('ctx', 'shopOrderListCreatorNo'), // 创建人编号
                    'headerOther' => ['width' => '120'],
                ],
                'CREATE_USER_NAME' => [
                    'header' => \Yii::t('ctx', 'shopOrderListCreatorName'), // 创建人姓名
                    'headerOther' => ['width' => '120'],
                ],
                'SN' => [
                    'header' => \Yii::t('ctx', 'shopOrderListOrderCode'), // 订单号
                    'headerOther' => ['width' => '200'],
                ],
                'INVOICE_NO' => [
                    'header' => \Yii::t('ctx', 'taxInvoice'), // 发票号
                    'headerOther' => ['width' => '200'],
                ],
//                'STATUS' => null,
                'STATUS' => [
                    'header' => \Yii::t('ctx', 'shopOrderListOrderStatus'), // 订单状态
                    'headerOther' => [
                        'width' => '110',
                    ],
                    'value' => function ($row) {
                        return $this->getOrderStatus()[$row['STATUS']]['label'] ?? '';
                    },
                ],
                'SKU_CODE' => [
                    'header' => \Yii::t('ctx', 'shopOrderListProductCode'), // 存货编码
                    'headerOther' => ['width' => '150'],
                ],
                'GOODS_TITLE' => [
                    'header' => \Yii::t('ctx', 'shopOrderListProductName'), // 存货名称
                    'headerOther' => ['width' => '200'],
                ],
                'CONSIGNEE' => [
                    'header' => \Yii::t('ctx', 'shopOrderListRecipient'), // 收货人
                    'headerOther' => [
                        'width' => '150',
                    ],
                ],
                'MOBILE' => [
                    'header' => \Yii::t('ctx', 'shopOrderListContactOne'), // 联系方式1
                    'headerOther' => [
                        'width' => '150',
                    ],
                ],
                'COUNTRY' => [
                    'header' => \Yii::t('ctx', 'country'), // 国家
                ],
                'CURRENCY' => [
                    'header' => \Yii::t('ctx', 'currency'), // 币种
                ],
                'PROVINCE' => [
                    'header' => \Yii::t('ctx', 'shopOrderListState'), // 州
                    'headerOther' => ['width' => '120'],
                    'value' => function ($row) use($regionConfig) {
                        return $regionConfig[$row['PROVINCE']]['REGION_NAME'] ?? '';
                    },
                ],
                'CITY' => [
                    'header' => \Yii::t('ctx', 'shopOrderListLocalGovernmentArea'), // 地方政府
                    'headerOther' => ['width' => '170'],
                    'value' => function ($row) use($regionConfig) {
                        return $regionConfig[$row['CITY']]['REGION_NAME'] ?? '';
                    },
                ],
                'COUNTY' => [
                    'header' => \Yii::t('ctx', 'shopOrderListCity'), // 区
                    'headerOther' => ['width' => '120'],
                    'value' => function ($row) use($regionConfig) {
                        return $regionConfig[$row['COUNTY']]['REGION_NAME'] ?? '';
                    },
                ],
                'ADDRESS' => [
                    'header' => \Yii::t('ctx', 'shopOrderListDetailedAddress'), // 详细地址
                    'headerOther' => [
                        'width' => '300',
                    ],
                ],
                'PERIOD_NUM' => [
                    'header' => \Yii::t('ctx', 'shopOrderListPeriod'), // 期数
                ],
                'ORDER_TYPE' => [
                    'header' => \Yii::t('ctx', 'shopOrderListOrderType'), // 订单类型
                    'headerOther' => ['width' => '140'],
                    'value' => function ($row) {
                        switch ($row['ORDER_TYPE']) {
                            case 'ZC':
                                return \Yii::t('ctx', 'shopOrderListOrderTypeZc');
                            case 'FX':
                                return in_array($row['PAY_TYPE'], ['cash', 'pay_stack']) ? \Yii::t('ctx', 'shopOrderListOrderTypeRepeatPurchase'): \Yii::t('ctx', 'shopOrderListOrderTypePoints'); //'重消' : '积分'
                        }
                    },
                ],
                'CREATED_AT' => [
                    'header' => \Yii::t('ctx', 'shopOrderListCreationTime'), // 创建时间
                    'value' => function ($row) {
                        return (new DateTime([
                            'value' => $row['CREATED_AT'],
                        ]))->result();
                    },
                    'headerOther' => ['width' => '190'],
                ],
                'PAY_TYPE' => [
                    'header' => \Yii::t('ctx', 'shopOrderListPayType'), // 支付方式
                    'value' => function ($row) {
                        return ShopGoods::payTypes()[$row['PAY_TYPE']]['name'] ?? ShopGoods::payTypes()['cash']['name'];
                    },
                    'headerOther' => ['width' => '190'],
                ],
                'PAY_AT' => [
                    'header' => \Yii::t('ctx', 'shopOrderListPaymentTime'), // 支付时间
                    'value' => function ($row) {
                        return (new DateTime([
                            'value' => $row['PAY_AT'],
                        ]))->result();
                    },
                    'headerOther' => ['width' => '190'],
                ],
//                'DELIVERY_AT' => [
//                    'header' => \Yii::t('ctx', 'shopOrderListDeliveryTime'), // 发货时间
//                    'value' => function ($row) {
//                        return (new DateTime([
//                            'value' => $row['DELIVERY_AT'],
//                        ]))->result();
//                    },
//                    'headerOther' => ['width' => '190'],
//                ],
                'BUY_NUMS' => [
                    'header' => \Yii::t('ctx', 'shopOrderListQty'), // 数量
                    'headerOther' => ['width' => '100'],
                ],
                'REAL_PRICE' => [
                    'header' => \Yii::t('ctx', 'shopOrderListItemPricing'), // 商品单价
                    'headerOther' => [
                        'width' => '150',
                    ],
                    'value' => function ($row) {
                        return Tool::formatPrice($row['REAL_PRICE']);
                    },
                    'valueOther' => function ($row) {
                        return [
                            'tag' => ['type' => 'danger', 'size' => 'small', 'class' => 'no-border']
                        ];
                    },
                ],
                'TOTAL_PRICE' => [
                    'header' => \Yii::t('ctx', 'shopOrderListTotalPrice'), // 订单总价
                    'headerOther' => [
                        'width' => '150',
                    ],
                    'value' => function ($row) {
                        return Tool::formatPrice($row['REAL_PRICE'] * $row['BUY_NUMS']);
                    },
                    'valueOther' => function ($row) {
                        return [
                            'tag' => ['type' => 'danger', 'size' => 'small', 'class' => 'no-border']
                        ];
                    },
                ],
                'REAL_PV' => [
                    'header' => \Yii::t('ctx', 'shopOrderListBVAmount'), // 商品金额
                    'headerOther' => [
                        'width' => '150',
                    ],
                    'value' => function ($row) {
                        return Tool::formatPrice($row['REAL_PV'] * $row['BUY_NUMS']);
                    },
                    'valueOther' => function ($row) {
                        return [
                            'tag' => ['type' => 'danger', 'size' => 'small', 'class' => 'no-border']
                        ];
                    },
                ],
                'STANDARD_PRICE' => [
                    'header' => \Yii::t('ctx', 'shopOrderListUsTotalPrice'), // 美元价格或标准价格
                    'headerOther' => [
                        'width' => '150',
                    ],
                    'value' => function ($row) {
                        return Tool::formatPrice($row['STANDARD_PRICE'] * $row['BUY_NUMS']);
                    },
                    'valueOther' => function ($row) {
                        return [
                            'tag' => ['type' => 'danger', 'size' => 'small', 'class' => 'no-border']
                        ];
                    },
                ],
                'PAY_FREIGHT' => [
                    'header' => \Yii::t('ctx', 'shopOrderListFreight'), // 运费
                    'headerOther' => [
                        'width' => '150',
                    ],
                    'value' => function ($row) {
                        return Tool::formatPrice($row['FREIGHT']);
                    },
                    'valueOther' => function ($row) {
                        return [
                            'tag' => ['type' => 'danger', 'size' => 'small', 'class' => 'no-border']
                        ];
                    },
                ],
                'TAX_RATE' => [
                    'header' => \Yii::t('ctx', 'shopOrderListTaxRate'), // 税率
                    'headerOther' => [
                        'width' => '150',
                    ],
                    'value' => function ($row) {
                        return Tool::formatPrice($row['TAX_RATE']);
                    },
                    'valueOther' => function ($row) {
                        return [
                            'tag' => ['type' => 'danger', 'size' => 'small', 'class' => 'no-border']
                        ];
                    },
                ],
                'TAX_AMOUNT' => [
                    'header' => \Yii::t('ctx', 'shopOrderListTax'), // 税额
                    'headerOther' => [
                        'width' => '150',
                    ],
                    'value' => function ($row) {
                        return Tool::formatPrice(($row['REAL_PRICE'] - $row['REAL_PRICE'] / (1 + $row['TAX_RATE'] / 100)));
                    },
                    'valueOther' => function ($row) {
                        return [
                            'tag' => ['type' => 'danger', 'size' => 'small', 'class' => 'no-border']
                        ];
                    },
                ],
                'EXPRESS_TYPE' => [
                    'header' => \Yii::t('ctx', 'shopOrderListShippingMethod'), // 发货方式
                    'headerOther' => ['width' => '150'],
                    'value' => function ($row) {
                        return $row['EXPRESS_TYPE']==0 ?  \Yii::t('ctx', 'shopOrderListShippingMethodMailing') : \Yii::t('ctx', 'shopOrderListShippingMethodAutoPick'); // '邮寄' : '自提'
                    },
                ],
                'FRONT_REMARK' => [
                    'header' => \Yii::t('ctx', 'shopOrderListMemberNotes'), // 会员备注
                    'headerOther' => [
                        'width' => '200',
                    ],
                    'value' => function ($row) {
                        return $row['FRONT_REMARK'];
                    },
                    'showValue' => function ($row) {
                        return '<div title="'.$row['FRONT_REMARK'].'" style="width:180px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;">'.$row['FRONT_REMARK'].'</div>';
                    },
                ],
                'DELIVERY_STATUS' => null,
                'DELIVERY_STATUS_NAME' => [
                    'header' => \Yii::t('ctx', 'shopOrderListShipmentStatus'), // 发货状态
                    'headerOther' => [
                        'width' => '130',
                    ],
                    'value' => function ($row) {

                        return $this->getDeliveryStatus()[$row['DELIVERY_STATUS']]['label'] ?? '';
                    },
                ],
                'AUTO_MAINTENANCE' => [
                    'header' => \Yii::t('ctx', 'shopListAutoMaintenance'),
                    'value' => function ($row) {
                        return $row['AUTO_MAINTENANCE'] == 1 ? \Yii::t('ctx', 'yes') : \Yii::t('ctx', 'no');
                    },
                ],
                'INVOICE_REMARK' => null,
                'METHOD' => null,
            ];
        }
        return $this->columns;
    }

    /**
     * 前台用于筛选的类型集合
     * @return mixed
     */
    public function getFilterTypes()
    {
        if(!$this->filterTypes){
            $this->filterTypes = [
                'SN'=> ['name'=> \Yii::t('ctx', 'shopOrderListOrderNo')],//订单编号
                'USER_NAME'=> ['name'=> \Yii::t('ctx', 'shopOrderListMemberCode')],//会员编号
                'MOBILE'=> ['name'=> \Yii::t('ctx', 'shopOrderListContactOne')],//联系方式1
                'ORDER_TYPE'=> [
                    'name'=> \Yii::t('ctx', 'shopOrderListOrderType'),
                    'other'=> 'select',
                    'selectData'=> [
                        ['id' => 'ZC', 'name' => \Yii::t('ctx', 'shopOrderListOrderTypeZc')],
                        ['id' => 'FX', 'name' => \Yii::t('ctx', 'shopOrderListOrderTypeRepeatPurchase')],
                    ]
                ],
                'COUNTRY'=> [
                    'name'=> \Yii::t('ctx', 'country'),
                    'other'=> 'select',
                    'selectData'=> self::getCountry()
                ],
                'PERIOD_NUM'=> ['name'=> \Yii::t('ctx', 'numberOfPeriods')],//期数
                'CREATED_AT'=> ['name'=> \Yii::t('ctx', 'shopOrderListCreationTime'), 'other'=>'date'],//创建时间
                'STATUS'=> [
                    'name'=> \Yii::t('ctx', 'shopOrderListOrderStatus'),
                    'other'=> 'select',
                    'selectData'=> [
                        ['id' => $this->getOrderStatus()['paid']['value'], 'name' => $this->getOrderStatus()['paid']['label']],
                        ['id' => $this->getOrderStatus()['notPaid']['value'], 'name' => $this->getOrderStatus()['notPaid']['label']],
                        ['id' => $this->getOrderStatus()['failPaid']['value'], 'name' => $this->getOrderStatus()['failPaid']['label']]
                    ]
                ],
                'AUTO_MAINTENANCE' => [
                    'name'=>\Yii::t('ctx', 'shopListAutoMaintenance'),
                    'other'=> 'select',
                    'selectData'=> [
                        ['id'=>1, 'name'=>\Yii::t('ctx', 'yes')],
                        ['id'=>0, 'name'=>\Yii::t('ctx', 'no')],
                    ]
                ],
                'PAY_TYPE' => [
                    'name' => \Yii::t('ctx', 'shopOrderListPayType'), // 支付方式
                    'other'=> 'select',
                    'selectData'=>self::getpayTypes()
                ],
                'CREATE_USER_NAME' => [
                    'name' => \Yii::t('ctx', 'shopOrderListCreatorName'), // 创建人姓名
                ],
                'SKU_CODE' => [
                    'name' => \Yii::t('ctx', 'shopOrderListProductCode'), // 存货编码
                ],
                'DELIVERY_STATUS_NAME' => [
                    'name' => \Yii::t('ctx', 'shopOrderListShipmentStatus'), // 发货状态
                    'other'=> 'select',
                    'selectData'=>[
                        ['id'=>0, 'name'=>\Yii::t('ctx', 'shopOrderListUndelivered')],
                        ['id'=>1, 'name'=>\Yii::t('ctx', 'shopOrderListDelivered')],
                        ['id'=>2, 'name'=>\Yii::t('ctx', 'shopOrderListConfirmReceipt')],
                    ]
                ],
                'PAY_AT' => [
                    'name' => \Yii::t('ctx', 'shopOrderListPaymentTime'), // 支付时间
                    'other' => 'date'
                ],
                'CONSIGNEE' => [
                    'name' => \Yii::t('ctx', 'shopOrderListRecipient'), // 收货人
                ],
                'GOODS_TITLE' => [
                    'name' => \Yii::t('ctx', 'shopOrderListProductName'), // 存货名称
                ],
                'CREATE_USER' => [
                    'name' => \Yii::t('ctx', 'shopOrderListCreatorNo'), // 创建人编号
                ],
                'DEC_USER_NAME' => [
                    'name' => \Yii::t('ctx', 'shopOrderListStockist'), // 报单中心
                ],
                'INVOICE_NO' => [
                    'name' => \Yii::t('ctx', 'taxInvoice'), // 发票号
                ],
            ];
        }
        return $this->filterTypes;
    }

    // 为了多语言,params.php中无法解析,const无法解析.做成函数返回
    public function getDeliveryStatus() {
        return [
            '0' => [
                'value' => 0,
                'label' => \Yii::t('ctx', 'shopOrderListUndelivered')//未发货
            ],
            'notDelivery' => [
                'value' => 0,
                'label' => \Yii::t('ctx', 'shopOrderListUndelivered')//未发货
            ],
            '1' => [
                'value' => 1,
                'label' => \Yii::t('ctx', 'shopOrderListDelivered')//已发货
            ],
            'delivered' => [
                'value' => 1,
                'label' => \Yii::t('ctx', 'shopOrderListDelivered')//已发货
            ],
            '2' => [
                'value' => 2,
                'label' => \Yii::t('ctx', 'shopOrderListConfirmReceipt')//确认收货
            ],
            'confirm' => [
                'value' => 2,
                'label' => \Yii::t('ctx', 'shopOrderListConfirmReceipt')//确认收货
            ],
        ];
    }

    // 同上原因,获取订单状态
    public function getOrderStatus(){
        return [
            '0' => [
                'value' => 0,
                'label' => \Yii::t('ctx', 'shopOrderListGetOrderStatusUnpaid')//待支付
            ],
            'notPaid' => [
                'value' => 0,
                'label' => \Yii::t('ctx', 'shopOrderListGetOrderStatusUnpaid')//待支付
            ],
            '1' => [
                'value' => 1,
                'label' => \Yii::t('ctx', 'shopOrderListGetOrderStatusPaid')//已支付
            ],
            'paid' => [
                'value' => 1,
                'label' => \Yii::t('ctx', 'shopOrderListGetOrderStatusPaid')//已支付
            ],
            // 此时进入发货流程参考发货状态
            '3' => [
                'value' => 3,
                'label' => \Yii::t('ctx', 'shopOrderListGetOrderStatusLogisticsStatus')//物流状态
            ],
            'delivery' => [
                'value' => 3,
                'label' => \Yii::t('ctx', 'shopOrderListGetOrderStatusLogisticsStatus')//物流状态
            ],
            '4' => [
                'value' => 4,
                'label' => \Yii::t('ctx', 'shopOrderListGetOrderStatusOrderCompletion')//订单完成
            ],
            'complete' => [
                'value' => 4,
                'label' => \Yii::t('ctx', 'shopOrderListGetOrderStatusOrderCompletion')//订单完成
            ],
            '5' => [
                'value' => 5,
                'label' => \Yii::t('ctx', 'shopOrderListGetOrderStatusOrderCancellation'),//订单取消
            ],
            'cancel' => [
                'value' => 5,
                'label' => \Yii::t('ctx', 'shopOrderListGetOrderStatusOrderCancellation'),//订单取消
            ],
            '6' => [
                'value' => 6,
                'label' => \Yii::t('ctx', 'shopOrderListGetOrderStatusOrderDeletion'),//订单删除
            ],
            'del' => [
                'value' => 6,
                'label' => \Yii::t('ctx', 'shopOrderListGetOrderStatusOrderDeletion'),//订单删除
            ],
            '7' => [
                'value' => 7,
                'label' => \Yii::t('ctx', 'shopOrderListGetOrderStatusOrderDeletionOrderRefund'),//订单退款
            ],
            'refund' => [
                'value' => 7,
                'label' => \Yii::t('ctx', 'shopOrderListGetOrderStatusOrderDeletionOrderRefund'),//订单退款
            ],
            '-1' => [
                'value' => -1,
                'label' => \Yii::t('ctx', 'shopOrderListGetOrderStatusPaymentFailed'),//支付失败
            ],
            'failPaid' => [
                'value' => -1,
                'label' => \Yii::t('ctx', 'shopOrderListGetOrderStatusPaymentFailed'),//支付失败
            ],
        ];
    }

    public function getCountry()
    {
        $countries = Countries::getFromCache();

        $data = [];
        foreach ($countries as $country) {
            $data[] = [
                'id' => $country['ID'],
                'name' => $country['NAME'],
            ];
        }

        return $data;
    }
    public function getpayTypes()
    {
        $payTypes = ShopGoods::payTypes();

        $data = [];
        foreach ($payTypes as $key=>$payType) {
            $data[] = [
                'id' => $key,
                'name' => $payType['name'],
            ];
        }

        return $data;
    }
}