会员积分管理,会员日志管理
积分管理效果图
变更积分效果图:
会员日志管理效果图
控制器代码: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"></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"></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"></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=" 提交 "> </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>
完结
但行好事,莫问前程!
本文来自博客园,作者:yangphp,转载请注明原文链接:https://www.cnblogs.com/ypeih/p/17351157.html