AdminUsersController.php 2.2 KB
<?php
/**
 * 会员相关
 * Author : xiaojie
 * DateTime: 2018/11/30 10:06
 */
namespace app\portal\controller;

use app\portal\model\UsersModel;
use cmf\controller\AdminBaseController;

/**
 * Class AdminUsersController
 * @package app\portal\controller
 * @adminMenuRoot(
 *     'name'   =>'会员相关',
 *     'action' =>'default',
 *     'parent' =>'',
 *     'display'=> true,
 *     'order'  => 30,
 *     'icon'   =>'th',
 *     'remark' =>'会员相关'
 * )
 */

class AdminUsersController extends AdminBaseController
{
    /**
     * 会员管理
     * @adminMenu(
     *     'name'   => '会员管理',
     *     'parent' => 'portal/AdminUsers/default',
     *     'display'=> true,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '会员管理',
     *     'param'  => ''
     * )
     */
    public function index()
    {
        $param = $this->request->param();
        $map = $this->search($param,'create_time','mobile');
        $userModel = new UsersModel();
        $list = $userModel
            ->where($map)
            ->order('id DESC')
            ->paginate(30);

        $this->assign('list',$list);
        $this->assign('page',$list->render());
        return $this->fetch();
    }


    /**
     * 删除
     * @adminMenu(
     *     'name'   => '删除',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '删除',
     *     'param'  => ''
     * )
     */
    public function delete()
    {
        $userModel = new UsersModel();
        $res = $this->del($userModel);
        if($res){
            $this->success('删除成功');
        }
        $this->error('请稍后重试');
    }


    /**
     * 会员导出
     */
    public function export()
    {
        $userModel = new UsersModel();
        $data = $userModel
            ->field('id,mobile,create_time')
            ->select()->each(function ($item){
               $item['create_time'] = date('Y-m-d',$item['create_time']);
            })->toArray();
        $this->exportExcel(array('序号','手机号','注册时间'), $data, '会员资料', './', true);
    }

}