首页 > 其他分享 >会员积分管理,会员日志管理

会员积分管理,会员日志管理

时间:2023-04-24 22:23:00浏览次数:32  
标签:username users 管理 会员 gin date NewDb 日志 uid

积分管理效果图

 变更积分效果图:

 会员日志管理效果图

 

控制器代码:admins/controllers/users.go 

//积分列表
func SocreList(c *gin.Context)  {
    list := modes.ScoreList(c)

    c.HTML(http.StatusOK,"users/users_score_list.html",gin.H{
        "list":list,
        "count":len(list),
        "start_date":c.Query("start_date"),
        "end_date":c.Query("end_date"),
        "uid":c.Query("uid"),
        "username":c.Query("username"),
        "mobile":c.Query("mobile"),
    })
}

//变更积分
func SocreChange(c *gin.Context)  {

    users := modes.UsersL{}
    id,exist := c.GetQuery("uid")
    if exist {
        idd,_ := strconv.Atoi(id)
        users = modes.UsersItem(idd)
    }

    c.HTML(http.StatusOK,"users/users_score_change.html",gin.H{
        "users":users,
    })
}
//获取用户积分
func  GetUserScore(c *gin.Context){

    username,exist := c.GetQuery("username")
    if exist {
        stat,users := modes.UsersItemByName(username)
        if stat != true {
            c.JSON(http.StatusOK,gin.H{
                "code":400,
            })
            return
        }else{
            c.JSON(http.StatusOK,gin.H{
                "code":0,
                "uid":users.Uid,
                "score":users.Uscore,
            })
            return
        }
    }
    c.JSON(http.StatusOK,gin.H{"code":400,})
    return
}
//保存积分
func SocreSave(c *gin.Context)  {

    res,msg := modes.ScoreChange(c)
    if res!=true {
        c.JSON(http.StatusOK,gin.H{"code":400,"msg":msg})
    }else{
        c.JSON(http.StatusOK,gin.H{"code":0,"msg":msg})
    }

}

//会员日志列表
func  UsersLogList(c *gin.Context)  {
    list :=modes.UsersLogList(c)

    c.HTML(http.StatusOK,"users/users_log_list.html",gin.H{
        "list":list,
        "count":len(list),
        "start_date":c.Query("start_date"),
        "end_date":c.Query("end_date"),
        "uid":c.Query("uid"),
        "username":c.Query("username"),
    })
}
//删除日志
func UsersLogDel(c *gin.Context){
    res,msg := modes.UsersLogDel(c)
    if res!=true {
        c.JSON(http.StatusOK,gin.H{"code":400,"msg":msg})
    }else{
        c.JSON(http.StatusOK,gin.H{"code":0,"msg":msg})
    }
}

模型代码:modes/ScoreModel.go

type UsersSocre struct {
    Id int `form:"id"`
    Uid int `form:"uid"`
    BeginScore float64 `form:"begin_score"`
    ChangeScore float64 `form:"change_score"`
    EndScore float64 `form:"end_score"`
    ChangeInfo string `form:"change_info"`
    AddDatetime string `form:"add_datetime"`
}
type UsersScoreL struct {
    UsersSocre
    Username string `form:"username"`
    Mobile string `form:"mobile"`
    Utype int `form:"utype"`
}

//积分列表
func ScoreList(c *gin.Context) []UsersScoreL {
    users := []UsersScoreL{}

    NewDb := DB
    if username,isExist := c.GetQuery("username");isExist == true{
        if strings.TrimSpace(username) != ""{
            NewDb = NewDb.Where("users.username = ?",username)
        }
    }
    if uid,isExist := c.GetQuery("uid");isExist == true{
        if strings.TrimSpace(uid) != ""{
            NewDb = NewDb.Where("users_socre.uid = ?",uid)
        }
    }

    if mobile,isExist := c.GetQuery("mobile");isExist == true{
        if strings.TrimSpace(mobile) != ""{
            NewDb = NewDb.Where("users.mobile = ?",mobile)
        }
    }


    if start_date,isExist := c.GetQuery("start_date");isExist == true{
        if strings.TrimSpace(start_date) != "" {
            start_date = start_date + " 00:00:00"
            NewDb = NewDb.Where("add_datetime > ?", start_date)
        }
    }
    if end_date,isExist := c.GetQuery("end_date");isExist == true{
        if strings.TrimSpace(end_date) != "" {
            end_date = end_date+" 23:59:59"
            NewDb = NewDb.Where("add_datetime <= ?",end_date)
        }
    }
    //连表查询
    res := NewDb.Model(UsersSocre{}).Select("users_socre.*,users.username,users.mobile").
        Order("users_socre.id DESC").
        Joins("join users on users_socre.uid = users.uid").Find(&users)

    if res.Error != nil {
        return users
    }
    return users
}

//积分变更
func ScoreChange(c *gin.Context) (bool,string)  {
    var score = UsersSocre{}
    var user  = Users{}
    //获取变量
    c.ShouldBind(&score)

    fmt.Println(score)

    uid := score.Uid
    change_score := score.ChangeScore
    //开启事务
    tx := DB.Begin()
    tx.Model(Users{}).Where("uid=?",uid).First(&user)

    score.BeginScore = user.Uscore
    score.EndScore = user.Uscore+change_score
    score.AddDatetime = time.Now().Format(common.TimeTem)

    fmt.Println(score)
    //更新用户表
    user_row :=tx.Model(Users{}).Where("uid=?",uid).Updates(Users{
        Uscore: score.EndScore,
    }).RowsAffected
    score_row := tx.Model(UsersSocre{}).Create(&score).RowsAffected

    if user_row > 0 && score_row > 0 {
        tx.Commit()
        //添加日志
        AddUsersLog(uid,2,"管理员变更积分:"+score.ChangeInfo,c)

        return true,"变更成功"
    }else{
        tx.Rollback()
        return false,"更新失败"
    }
}

//添加日志
// log_type 1登录退出,2积分变更 3其他提示
func AddUsersLog(uid int,log_type int,log_info string,c *gin.Context) (bool,string) {
    var logs = UsersLog{
        Uid:uid,
        LogType: log_type,
        LogInfo: log_info,
        LogIp: c.RemoteIP(),
        AddDatetime: time.Now().Format(common.TimeTem),
    }

    DB.Model(UsersLog{}).Create(&logs)
    return true,"添加日志成功"
}

//日志列表
func UsersLogList(c *gin.Context) []UsersLogL {

    logl := []UsersLogL{}
    NewDb := DB
    if username,isExist := c.GetQuery("username");isExist == true{
        if strings.TrimSpace(username) != ""{
            NewDb = NewDb.Where("users.username like ?","%"+username+"%")
        }
    }
    if uid,isExist := c.GetQuery("uid");isExist == true{
        if strings.TrimSpace(uid) != ""{
            NewDb = NewDb.Where("users_log.uid = ?",uid)
        }
    }

    if start_date,isExist := c.GetQuery("start_date");isExist == true{
        if strings.TrimSpace(start_date) != "" {
            start_date = start_date + " 00:00:00"
            NewDb = NewDb.Where("add_datetime > ?", start_date)
        }
    }
    if end_date,isExist := c.GetQuery("end_date");isExist == true{
        if strings.TrimSpace(end_date) != "" {
            end_date = end_date+" 23:59:59"
            NewDb = NewDb.Where("add_datetime <= ?",end_date)
        }
    }
    //连表查询
    res := NewDb.Model(UsersLog{}).Select("users_log.*,users.username").
        Order("users_log.id DESC").
        Joins("join users on users.uid = users_log.uid").Find(&logl)

    if res.Error != nil {
        return logl
    }
    return logl
}

//删除日志
func  UsersLogDel(c *gin.Context) (bool,string) {

    id,exist := c.GetQuery("id")

    if exist {
        idd,_ := strconv.Atoi(id)

        res := DB.Where("id=?",idd).Delete(UsersLog{})
        if res.Error!=nil {
            return false,res.Error.Error()
        }
        return true,"删除成功"
    }
    return false,"删除失败"
}

会员积分管理视图文件:views/admins/users/users_score_list.html

<div class="Hui-article">
        <article class="cl pd-20">
            <div class="text-c">
                <form name="postform" method="get" action="/admin/users_socre">

                    日期范围:
                    <input type="text" onfocus="WdatePicker({maxDate:'#F{$dp.$D(\'datemax\')||\'%y-%M-%d\'}'})" id="datemin" class="input-text Wdate" name="start_date" value="{{.start_date}}" style="width:120px;">
                    -
                    <input type="text" onfocus="WdatePicker({minDate:'#F{$dp.$D(\'datemin\')}',maxDate:'%y-%M-%d'})" id="datemax" class="input-text Wdate" name="end_date" value="{{.end_date}}" style="width:120px;">

                    <input type="text" class="input-text" style="width:100px" placeholder="UID"  name="uid" value="{{.uid}}">
                    <input type="text" class="input-text" style="width:150px" placeholder="账号"  name="username" value="{{.username}}">

                    <button type="submit" class="btn btn-success radius" id="" name=""><i class="Hui-iconfont">&#xe665;</i> 搜用户</button>
                </form>
            </div>

            <div class="cl pd-5 bg-1 bk-gray"> <span class="l">
                {{ $admin_uid := GetAdminId}}

                <a class="btn btn-primary radius" href="javascript:;" {{if has_powa $admin_uid "/admin/users_socre_change"}} style="display:none" {{end}} onclick="admin_role_add('变更积分','/admin/users_socre_change','800')"><i class="Hui-iconfont">&#xe600;</i> 变更积分</a> </span> <span class="r">共有数据:<strong>{{.count}}</strong> 条</span> </div>
            <div class="mt-10">
                <table class="table table-border table-bordered table-hover  table-bg  table-sort">
                    <thead>
                    <tr>
                        <th scope="col" colspan="10">用户积分管理</th>
                    </tr>
                    <tr class="text-c">
                        <th width="25"><input type="checkbox" value="" name=""></th>
                        <th width="40">ID</th>
                        <th width="100">账号</th>
                        <th width="100">UID</th>
                        <th width="100">开始积分</th>
                        <th width="100">变动积分</th>
                        <th width="100">结束积分</th>
                        <th >变更说明</th>
                        <th width="130">添加时间</th>
                        <th width="100">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {{ range $k,$v := .list }}
                    <tr class="text-c">
                        <td><input type="checkbox" value="" name=""></td>
                        <td>{{$v.Id}}</td>
                        <td>{{$v.Username}}</td>
                        <td>{{$v.Uid}}</td>
                        <td>{{$v.BeginScore}}</td>
                        <td>{{$v.ChangeScore}}</td>
                        <td>{{$v.EndScore}}</td>
                        <td>{{$v.ChangeInfo}}</td>
                        <td>{{$v.AddDatetime}}</td>
                        <td class="f-14">
                            <a title="变更积分" href="javascript:;" {{if has_powa $admin_uid "/admin/users_socre_change"}} style="display:none" {{end}} onclick="admin_role_edit('变更积分','/admin/users_socre_change',{{$v.Uid}})" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a>
                    </tr>
                    {{end}}

                    </tbody>
                </table>
            </div>
        </article>
</div>

<script type="text/javascript">
    $('.table-sort').dataTable({
        "aaSorting": [[ 1, "desc" ]],//默认第几个排序
        "bStateSave": true,//状态保存
        "aoColumnDefs": [
            //{"bVisible": true, "aTargets": [ 3,4,5 ]} ,//控制列的隐藏显示
            {"orderable":false,"aTargets":[0,8,9]}// 不参与排序的列
        ]
    });
    /*管理员-角色-添加*/
    function admin_role_add(title,url,w,h){
        layer_show(title,url,w,h);
    }
    /*管理员-角色-编辑*/
    function admin_role_edit(title,url,id,w,h){
        layer_show(title,url+"?uid="+id,w,h);
    }

</script>

变更积分视图:views/admins/users/users_score_change.html

<article class="cl pd-20">
    <form action="/admin/users_socre_save" method="post" class="form form-horizontal" id="form-member-add">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>账号:</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="{{.users.Username}}" placeholder="" id="user_name" name="user_name">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">当前积分:</label>
            <div class="formControls col-xs-8 col-sm-9" id="now_score">
                {{.users.Uscore}}
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>变更积分</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="" placeholder="增加积分,值为正数。减少积分,值为负数" id="change_score" name="change_score">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">变更说明</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="" placeholder="" id="change_info" name="change_info">
            </div>
        </div>

        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input type="hidden" name="uid" id="uid" value="{{.users.Uid}}" />
                <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            </div>
        </div>
    </form>
</article>

<script type="text/javascript">
    $(function(){
        $('.skin-minimal input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        });

        $("#form-member-add").validate({
            rules:{
                type_name:{
                    required:true,
                    minlength:2,
                    maxlength:20
                },
            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                $(form).ajaxSubmit(function (data){
                    if(data.code == 0){
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.window.location.reload();
                        parent.layer.close(index);
                    }else{
                        layer.alert(data.msg)
                    }
                });
            }
        });

        $("#user_name").blur(function (){
            username  = $("#user_name").val()
            $.get("/admin/get_user_score",{username:username},function (data){
                if (data.code == 0)
                {
                    $("#now_score").text(data.score)
                    $("#uid").val(data.uid)
                }else{
                    $("#now_score").innerText = 0
                    $("#uid").val("")
                    layer.alert("账号输入错误,请确认")
                }
            },'json')
        })
    });
</script>

完结

 

标签:username,users,管理,会员,gin,date,NewDb,日志,uid
From: https://www.cnblogs.com/ypeih/p/17351157.html

相关文章

  • 万达电商管理层又全换了一遍 这是什么节奏呢
    腾讯科技雷建平7月17日报道持续经历动荡的万达电商正经历新一轮调整。腾讯科技今日获悉,万达电商日前已任命新管理层,其中,原奢侈品电商佳品网COO董策将确定出任CEO,原美国新蛋网大洛杉矶地区CIO曹大军出任CTO。这意味着新一轮万达电商管理层任命调整完成。今年7月,腾讯科技曾报道过......
  • Docker容器日志中文乱码问题
    背景:在使用docker部署springboot项目的时候,查看项目日志的过程中,发现中文打印出来的都是乱码:??????楼主是通过dockerfile创建的镜像,解决方案:DcokerFile中增加环境变量ENVTZ'Asia/Shanghai'ENVLANGen_US.UTF-8ENVLANGUAGEen_US:enENVLC_ALLen_US.UTF-8其......
  • shell 脚本中定义log日志
    #!/bin/bashworkspace=$(cd`dirname$0`/.;pwd)cd$workspacefunction_log_error(){echo-e"\033[31m[ERROR]\033[0m$@"}function_log_info(){echo-e"\033[32m[INFO]\033[0m$@"}function_log_warn(){echo-e"\0......
  • 连网技术与网络管理2023-04-22
    vlan是datalinklayer中比较重要的一个协议?VLAN(VirtualLocalAreaNetwork)isalogicalgroupingofdevicesonanetworkbasedontheirfunctions,projectteams,orapplications.ItenablesnetworkadministratorstopartitionaphysicalLANintomultiple......
  • 61 openEuler 22.03-LTS 搭建MySQL数据库服务器-管理数据库用户
    61openEuler22.03-LTS搭建MySQL数据库服务器-管理数据库用户61.1创建用户可以使用CREATEUSER语句来创建一个或多个用户,并设置相应的口令。CREATEUSER'username'@'hostname'IDENTIFIEDBY'password';其中:username:用户名。hostname:主机名,即用户连接数据库时所在的主......
  • 全渠道会员经营升级之路
    随着全国消费品行业数字化进程的加快,会员营销服务厂商们也粉粉推出了全新的会员营销解决方案——全渠道会员运营解决方案。博阳认为,全渠道会员营销的宗旨在于实现消费者完整价值,以此为目标,来提升整个会员运营效率,打造完整的全域运营能力。以“实现消费者完整价值”为目的的全渠道会......
  • 第四章 存储器管理 4.3 连续分配存储管理方式
    一、单一连续分配  内存分为两个区域:系统区,用户区。  应用程序装入到用户区,可使用用户区全部空间。内存中仅驻留一道用户程序,整个用户区为一个用户独占。二、固定分区分配  1.将内存用户空间划分为若干个固定大小的区域,每个区域称为一个分区,在每个分区中只装入......
  • React、Ant Design 5.0 构建通用后台管理系统 - 接口服务环境搭建
    目录项目初始化项目结构package.jsontsconfig.jsonnodemon.jsonindex.tssrc/server.ts运行项目初始化mkdirgeneral-admin-system-servercdgeneral-admin-system-servernpminit-ynpminstalltypescriptts-node@types/nodenodemon@swc/core@swc/helpersregenerator-......
  • React、Ant Design 5.0 构建通用后台管理系统 - 登录页面
    目录安装依赖main.tsxsrc/styles/global.cssApp.tsxsrc/pages/user/Login/index.tsxsrc/pages/user/Login/style.module.css安装依赖npminstallantd@ant-design/icons@ant-design/pro-componentsAntDesign组件库@ant-design/pro-components封装一些好用的常用组件库mai......
  • oracle 建立触发器实现登录失败的时候记录日志信息
    问题:用户反映oracle用户最近总是会被锁定,解锁后过一天继续被锁定。解决思路:v$session并不会记录ip信息,建立触发器实现登录失败的时候记录日志信息   CREATEORREPLACETRIGGERlogon_denied_to_alertAFTERservererrorONDATABASEDECLAREmessageVARCHAR2(168)......