腾讯云优惠券
呆错后台管理框架基础模块(会员/用户)开发实例
人气:486 更新:2022-03-04

初始字段

$fields = [
    "user_id ",
    "user_email",
    "user_name",
    "user_nice_name",
    "user_mobile",
    "user_pass",
    "user_status",
    "user_create_time",
    "user_update_time",
    "user_create_ip",
    "user_update_ip",
    "user_slug",
    "user_views",
    "user_hits",
    "user_token",
    "user_module",
    "user_controll",
    "user_action",
    "user_capabilities",//初始扩展字段(用户组/角色)
    "user_expire",//初始扩展字段(token过期时间)
    "user_caps",//初始扩展字段(独立权限节点)
];

卸载插件时按应用名批量删除用户

\daicuo\User::delete_module('user');

安装插件时批量新增用户

//新增数据前需要定义使用的扩展字段,否则不会写入这些字段的数据(这里共用了5个,三个初始扩展字段,后面两个为后期在后台自定义的字段)
config('custom_fields.user_meta', ['user_capabilities', 'user_caps', 'user_expire', 'user_pid', 'user_score']);

\daicuo\User::save_all([
    [
        'user_name'         => 'user1',
        'user_nice_name'    => 'user1',
        'user_pass'         => 'user1',
        'user_email'        => 'user1@daicuo.org',
        'user_mobile'       => '13800138001',
        'user_status'       => 'normal',
        'user_module'       => 'user',
        'user_capabilities' => ['subscriber'],
        'user_slug'         => 'userone',
        'user_score'        => 0,
        'user_pid'          => 0,
    ],
    [
        'user_name'         => 'user2',
        'user_nice_name'    => 'user2',
        'user_pass'         => 'user2',
        'user_email'        => 'user2@daicuo.org',
        'user_mobile'       => '13800138002',
        'user_status'       => 'normal',
        'user_module'       => 'user',
        'user_capabilities' => ['subscriber'],
        'user_slug'         => 'usertwo',
        'user_score'        => 0,
        'user_pid'          => 0,
    ],
]);

新增与修改一个用户资料的实例,当传入主键user_id时则为修改操作,否则为新增操作。

model('common/User','loglic')->write([
    'user_name'         => 'user1',
    'user_nice_name'    => 'user1',
    'user_pass'         => 'user1',
    'user_email'        => 'user1@daicuo.org',
    'user_mobile'       => '13800138001',
    'user_status'       => 'normal',
    'user_module'       => 'user',
    'user_capabilities' => ['subscriber'],
    'user_slug'         => 'userone',
    'user_score'        => 0,
    'user_pid'          => 0,
]);