UserExporter.php 2.1 KB
<?php
/**
+-----------------------------------------------------------------------------------------------------------------------
 * 导出类
+-----------------------------------------------------------------------------------------------------------------------
 *
 * PHP version 7
 *
 * @category  App\Admin\Extensions\Exporter
 * @package   App\Admin\Extensions\Exporter
 * @author    Richer <yangzi1028@163.com>
 * @date      2021年8月30日10:58:22
 * @copyright 2021-2022 Richer (http://www.Richer.com/)
 * @license   http://www.Richer.com/ License
 * @link      http://www.Richer.com/
 */
namespace App\Admin\Extensions\Exporter;

use App\Admin\Extensions\CustomExporter;
use Maatwebsite\Excel\Concerns\WithMapping;

/**
 * Class UserExporter
 *
 * @category  App\Admin\Extensions\Exporter
 * @package   App\Admin\Extensions\Exporter
 * @author    Richer <yangzi1028@163.com>
 * @date      2021年8月30日10:58:22
 * @copyright 2021-2022 Richer (http://www.Richer.com/)
 * @license   http://www.Richer.com/ License
 * @link      http://www.Richer.com/
 */
class UserExporter extends CustomExporter implements WithMapping
{
    protected $columns = [
        'id'        => '序号',
        'nickname'  => '昵称',
//        'avatar'    => '头像',
        'mobile'    => '手机号码',
//        'gender'    => '性别',
        'points'    => '积分',
        'balance'           => '余额',
        'role'              => '角色',
        'login_times'       => '登录次数',
        'last_login_time'   => '上次登录时间',
        'created_at'        => '注册时间',
    ];

    /**
     * 字段映射
     *
     * @param $model
     * @return array
     */
    public function map($model) : array
    {
        ini_set("memory_limit", "-1");

        $this->index ++ ;
        // 返回的映射数组
        return [
            $this->index,
            $model->nickname,
//            $model->avatar,
            "\t".$model->mobile,
            $model->points,
            $model->balance,
            $model->role_show,
            $model->login_times,
            $model->last_login_time,
            $model->created_at,
        ];
    }
}