906 lines
27 KiB
Go
906 lines
27 KiB
Go
|
package usermanage
|
||
|
|
||
|
import (
|
||
|
"errors"
|
||
|
"fmt"
|
||
|
"github.com/gin-gonic/gin"
|
||
|
"go-admin/app/admin/models"
|
||
|
orm "go-admin/common/global"
|
||
|
"go-admin/logger"
|
||
|
"go-admin/pkg/jwtauth"
|
||
|
"go-admin/tools/app"
|
||
|
"net/http"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
func UserList(c *gin.Context) {
|
||
|
req := struct {
|
||
|
Page int `json:"pageIndex"`
|
||
|
PageSize int `json:"pageSize"`
|
||
|
Tel string `json:"tel"` // 电话
|
||
|
Uid int `json:"uid"` // 用户id
|
||
|
CooperativeBusinessId int `json:"cooperative_business_id"`
|
||
|
MemberLevel int `json:"memberLevel"`
|
||
|
StoreId int `json:"store_id"` // 门店id
|
||
|
UserType int `json:"user_type"` // 用户类型 用户类型 1-普通用户 2-店员
|
||
|
StartTime string `json:"startTime"` // 开始时间
|
||
|
EndTime string `json:"endTime"` // 结束时间
|
||
|
NameKey string `json:"nameKey"` // 昵称搜索
|
||
|
}{
|
||
|
Page: 1,
|
||
|
PageSize: 10,
|
||
|
}
|
||
|
if c.ShouldBindJSON(&req) != nil {
|
||
|
logger.Errorf("para err")
|
||
|
app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
||
|
return
|
||
|
}
|
||
|
fmt.Printf("req: %+v \n", req)
|
||
|
if req.CooperativeBusinessId == 0 {
|
||
|
data, _ := c.Get(jwtauth.JwtPayloadKey)
|
||
|
mapClaims := data.(jwtauth.MapClaims)
|
||
|
sysUid := float64(0)
|
||
|
if v, ok := mapClaims["identity"]; ok {
|
||
|
sysUid = v.(float64)
|
||
|
}
|
||
|
var sUser models.SysUser
|
||
|
sql := fmt.Sprintf("SELECT * FROM sys_user WHERE user_id=%.0f;", sysUid)
|
||
|
err := orm.Eloquent.Raw(sql).Scan(&sUser).Error
|
||
|
if err != nil {
|
||
|
logger.Error("sys user err:", err)
|
||
|
app.Error(c, http.StatusInternalServerError, err, "查询失败")
|
||
|
return
|
||
|
}
|
||
|
req.CooperativeBusinessId = int(sUser.CooperativeBusinessId)
|
||
|
}
|
||
|
|
||
|
//req.SysUid = fmt.Sprintf("%.0f", sysUid)
|
||
|
|
||
|
userList, _, count, err := models.GetUserList(req.Page, req.PageSize, req.Uid, req.MemberLevel, req.StoreId,
|
||
|
req.UserType, req.CooperativeBusinessId, req.Tel, req.StartTime, req.EndTime, req.NameKey)
|
||
|
if err != nil {
|
||
|
logger.Errorf("err:", err)
|
||
|
app.Error(c, http.StatusInternalServerError, err, "查询失败")
|
||
|
return
|
||
|
}
|
||
|
|
||
|
ret := map[string]interface{}{
|
||
|
"count": count,
|
||
|
"list": userList,
|
||
|
"pageIndex": req.Page,
|
||
|
"total_page": req.PageSize,
|
||
|
}
|
||
|
app.OK(c, ret, "")
|
||
|
}
|
||
|
|
||
|
func LoggingList(c *gin.Context) {
|
||
|
req := struct {
|
||
|
PageIndex int `json:"page_index"`
|
||
|
PageSize int `json:"page_size"`
|
||
|
StartTime string `json:"start_time"` // 开始时间
|
||
|
EndTime string `json:"end_time"` // 结束时间
|
||
|
}{}
|
||
|
if c.ShouldBindJSON(&req) != nil {
|
||
|
logger.Errorf("para err")
|
||
|
app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
||
|
return
|
||
|
}
|
||
|
page := req.PageIndex - 1
|
||
|
if page < 0 {
|
||
|
page = 0
|
||
|
}
|
||
|
if req.PageSize == 0 {
|
||
|
req.PageSize = 10
|
||
|
}
|
||
|
|
||
|
qs := orm.Eloquent.Table("logging")
|
||
|
if req.StartTime != "" {
|
||
|
parse, err := time.Parse(models.DateTimeFormat, req.StartTime)
|
||
|
if err != nil {
|
||
|
logger.Errorf("err:", err)
|
||
|
return
|
||
|
}
|
||
|
qs = qs.Where("created_at > ?", parse)
|
||
|
}
|
||
|
if req.EndTime != "" {
|
||
|
parse, err := time.Parse(models.DateTimeFormat, req.EndTime)
|
||
|
if err != nil {
|
||
|
logger.Error("err:", err)
|
||
|
return
|
||
|
}
|
||
|
qs = qs.Where("created_at < ?", parse)
|
||
|
}
|
||
|
var count int64
|
||
|
err := qs.Count(&count).Error
|
||
|
if err != nil {
|
||
|
logger.Error("count err:", err)
|
||
|
app.Error(c, http.StatusInternalServerError, err, "查询失败")
|
||
|
return
|
||
|
}
|
||
|
|
||
|
totalPage := int(count)/req.PageSize + 1
|
||
|
var loggings []models.Logging
|
||
|
err = qs.Order("id DESC").Offset(page * req.PageSize).Limit(req.PageSize).Find(&loggings).Error
|
||
|
if err != nil && err != models.RecordNotFound {
|
||
|
logger.Error("logging err:", err)
|
||
|
app.Error(c, http.StatusInternalServerError, err, "查询失败")
|
||
|
return
|
||
|
}
|
||
|
listRsp := models.LoggingListRsp{
|
||
|
Count: count,
|
||
|
List: loggings,
|
||
|
PageIndex: req.PageIndex,
|
||
|
PageSize: req.PageSize,
|
||
|
TotalPage: totalPage,
|
||
|
}
|
||
|
//ret := map[string]interface{}{
|
||
|
// "count": count,
|
||
|
// "list": loggings,
|
||
|
// "page_index": req.PageIndex,
|
||
|
// "page_size": req.PageSize,
|
||
|
// "total_page": totalPage,
|
||
|
//}
|
||
|
app.OK(c, listRsp, "")
|
||
|
return
|
||
|
}
|
||
|
|
||
|
//func CommonProblemList(c *gin.Context) {
|
||
|
// commonProblem := &models.CommonProblem{}
|
||
|
// list, err := commonProblem.List()
|
||
|
// if err != nil {
|
||
|
// logger.Errorf("err:", err)
|
||
|
// app.Error(c, http.StatusInternalServerError, err, "查询失败")
|
||
|
// return
|
||
|
// }
|
||
|
//
|
||
|
// app.OK(c, list, "")
|
||
|
//}
|
||
|
//
|
||
|
//func CommonProblemAdd(c *gin.Context) {
|
||
|
// commonProblem := &models.CommonProblem{}
|
||
|
// if c.ShouldBindJSON(commonProblem) != nil {
|
||
|
// logger.Errorf("para err")
|
||
|
// app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
||
|
// return
|
||
|
// }
|
||
|
// err := commonProblem.Add()
|
||
|
// if err != nil {
|
||
|
// logger.Errorf("err:", err)
|
||
|
// app.Error(c, http.StatusInternalServerError, err, "查询失败")
|
||
|
// return
|
||
|
// }
|
||
|
//
|
||
|
// app.OK(c, commonProblem, "")
|
||
|
//}
|
||
|
//
|
||
|
//func CommonProblemModify(c *gin.Context) {
|
||
|
// commonProblem := &models.CommonProblem{}
|
||
|
// if c.ShouldBindJSON(commonProblem) != nil {
|
||
|
// logger.Errorf("para err")
|
||
|
// app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
||
|
// return
|
||
|
// }
|
||
|
// err := commonProblem.Modify()
|
||
|
// if err != nil {
|
||
|
// logger.Errorf("err:", err)
|
||
|
// app.Error(c, http.StatusInternalServerError, err, "查询失败")
|
||
|
// return
|
||
|
// }
|
||
|
//
|
||
|
// app.OK(c, commonProblem, "")
|
||
|
//}
|
||
|
//
|
||
|
//func CommonProblemDel(c *gin.Context) {
|
||
|
// req := &struct {
|
||
|
// CommonProblemId uint32 `json:"common_problem_id"`
|
||
|
// }{}
|
||
|
// if c.ShouldBindJSON(req) != nil {
|
||
|
// logger.Errorf("para err")
|
||
|
// app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
||
|
// return
|
||
|
// }
|
||
|
// commonProblem := &models.CommonProblem{}
|
||
|
// commonProblem.ID = req.CommonProblemId
|
||
|
// err := commonProblem.Del()
|
||
|
// if err != nil {
|
||
|
// logger.Errorf("err:", err)
|
||
|
// app.Error(c, http.StatusInternalServerError, err, "查询失败")
|
||
|
// return
|
||
|
// }
|
||
|
//
|
||
|
// app.OK(c, commonProblem, "")
|
||
|
//}
|
||
|
//
|
||
|
//func UserAddAssistant(c *gin.Context) {
|
||
|
// req := &struct {
|
||
|
// Uid uint32 `json:"uid"` // 用户id
|
||
|
// ShopAssistantName string `json:"shop_assistant_name"` // 店员名称
|
||
|
// StoreId uint32 `json:"store_id"` // 门店id
|
||
|
// CooperativeBusinessId uint32 `json:"cooperative_business_id"`
|
||
|
// XcxRoleId uint32 `json:"xcx_role_id"` // 角色id
|
||
|
// //Name string `json:"name"` //
|
||
|
// }{}
|
||
|
// if c.ShouldBindJSON(req) != nil {
|
||
|
// logger.Errorf("para err")
|
||
|
// app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
||
|
// return
|
||
|
// }
|
||
|
//
|
||
|
// //models.UserInfo{}
|
||
|
// // TODO 注册会员更新时间
|
||
|
// // TODO 会员价格
|
||
|
// // TODO 支付地址
|
||
|
// userInfo, err := models.GetUserInfoByUid(req.Uid)
|
||
|
// if err != nil {
|
||
|
// logger.Error("get user info err:", err)
|
||
|
// app.Error(c, http.StatusInternalServerError, err, "绑定店员失败")
|
||
|
// return
|
||
|
// }
|
||
|
// if userInfo.Uid != req.Uid {
|
||
|
// logger.Error("user info err:", err)
|
||
|
// app.Error(c, http.StatusInternalServerError, err, "绑定店员失败")
|
||
|
// return
|
||
|
// }
|
||
|
// var cooperative models.CooperativeBusiness
|
||
|
// err = orm.Eloquent.Table("cooperative_business").Where("id=?", req.CooperativeBusinessId).Find(&cooperative).Error
|
||
|
// if err != nil {
|
||
|
// logger.Error("err:", err)
|
||
|
// app.Error(c, http.StatusInternalServerError, err, "绑定店员失败")
|
||
|
// return
|
||
|
// }
|
||
|
// store, err := models.GetStore(req.StoreId)
|
||
|
// if err != nil {
|
||
|
// logger.Error("get store err:", err)
|
||
|
// app.Error(c, http.StatusInternalServerError, err, "绑定店员失败")
|
||
|
// return
|
||
|
// }
|
||
|
// if store.CooperativeBusinessId != req.CooperativeBusinessId {
|
||
|
// logger.Error("cooperative business store err:", err)
|
||
|
// app.Error(c, http.StatusInternalServerError, err, "绑定门店错误")
|
||
|
// return
|
||
|
// }
|
||
|
//
|
||
|
// sql := fmt.Sprintf(
|
||
|
// "UPDATE `user` SET user_type = 2, store_id = %d,shop_assistant_name='%s',cooperative_business_id=%d,cooperative_name='%s',xcx_role_id=%d WHERE uid = %d;",
|
||
|
// req.StoreId, req.ShopAssistantName, req.CooperativeBusinessId, cooperative.Name, req.XcxRoleId, req.Uid)
|
||
|
// err = orm.Eloquent.Exec(sql).Error
|
||
|
// if err != nil {
|
||
|
// logger.Errorf("err:", err)
|
||
|
// app.Error(c, http.StatusInternalServerError, err, "绑定店员失败")
|
||
|
// return
|
||
|
// }
|
||
|
//
|
||
|
// app.OK(c, nil, "绑定店员成功")
|
||
|
//}
|
||
|
//
|
||
|
//func UserAssistantDel(c *gin.Context) {
|
||
|
// req := &struct {
|
||
|
// Uid uint32 `json:"uid"` // 用户id
|
||
|
// }{}
|
||
|
// if c.ShouldBindJSON(req) != nil {
|
||
|
// logger.Errorf("para err")
|
||
|
// app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
||
|
// return
|
||
|
// }
|
||
|
// //models.UserInfo{}
|
||
|
//
|
||
|
// // TODO 注册会员更新时间
|
||
|
// // TODO 会员价格
|
||
|
// // TODO 支付地址
|
||
|
// sql := fmt.Sprintf("UPDATE `user` SET user_type = 1, store_id = 0 WHERE uid = %d;", req.Uid)
|
||
|
// err := orm.Eloquent.Exec(sql).Error
|
||
|
// if err != nil {
|
||
|
// logger.Errorf("err:", err)
|
||
|
// app.Error(c, http.StatusInternalServerError, err, "绑定失败")
|
||
|
// return
|
||
|
// }
|
||
|
//
|
||
|
// app.OK(c, nil, "绑定店员成功")
|
||
|
//}
|
||
|
//
|
||
|
//func UserInviteList(c *gin.Context) {
|
||
|
// req := new(models.UserInviteListReq)
|
||
|
// if c.ShouldBindJSON(req) != nil {
|
||
|
// logger.Errorf("para err")
|
||
|
// app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
||
|
// return
|
||
|
// }
|
||
|
//
|
||
|
// // TODO 注册会员更新时间
|
||
|
// // TODO 会员价格
|
||
|
// // TODO 支付地址
|
||
|
// list, count, err := req.InviteList()
|
||
|
// if err != nil {
|
||
|
// logger.Errorf("err:", err)
|
||
|
// app.Error(c, http.StatusInternalServerError, err, "查询失败")
|
||
|
// return
|
||
|
// }
|
||
|
//
|
||
|
// ret := map[string]interface{}{
|
||
|
// "count": count,
|
||
|
// "list": list,
|
||
|
// "pageIndex": req.Page,
|
||
|
// }
|
||
|
// app.OK(c, ret, "")
|
||
|
//}
|
||
|
//
|
||
|
//func CancelMembers(c *gin.Context) {
|
||
|
// req := &struct {
|
||
|
// Uid uint32 `json:"uid"` // 用户id
|
||
|
// }{}
|
||
|
// if c.ShouldBindJSON(req) != nil {
|
||
|
// logger.Errorf("para err")
|
||
|
// app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
||
|
// return
|
||
|
// }
|
||
|
//
|
||
|
// //list, count, err := req.InviteList()
|
||
|
// //if err != nil {
|
||
|
// // logger.Errorf("err:", err)
|
||
|
// // app.Error(c, http.StatusInternalServerError, err, "查询失败")
|
||
|
// // return
|
||
|
// //}
|
||
|
// var userInfo models.UserInfo
|
||
|
// err := orm.Eloquent.Table("user").Where("uid", req.Uid).Find(&userInfo).Error
|
||
|
// if err != nil {
|
||
|
// logger.Errorf("err:", err)
|
||
|
// app.Error(c, http.StatusInternalServerError, err, "查询用户失败")
|
||
|
// return
|
||
|
// }
|
||
|
// userInfo.MemberLevel = 1
|
||
|
// //memberExpire := userInfo.MemberExpire.AddDate(-1, 0, 0)
|
||
|
// //userInfo.MemberExpire = memberExpire
|
||
|
// nowTime := time.Now()
|
||
|
// sql := fmt.Sprintf("UPDATE `user` SET member_level = 1,member_expire=?,updated_at=?,deposit=0 WHERE uid = ?;")
|
||
|
// err = orm.Eloquent.Debug().Exec(sql, nowTime, nowTime, req.Uid).Error
|
||
|
// if err != nil {
|
||
|
// logger.Errorf("err:", err)
|
||
|
// app.Error(c, http.StatusInternalServerError, err, "取消会员失败")
|
||
|
// return
|
||
|
// }
|
||
|
// var userInvite models.UserInvite
|
||
|
// orm.Eloquent.Table("user_invite").Where("to_uid=?", req.Uid).Where("spend_type=2").
|
||
|
// Order("id DESC").Limit(1).Find(&userInvite)
|
||
|
// sqlInvite := fmt.Sprintf("UPDATE user_invite SET member_status=3,action=1,spend_type=1 WHERE id= ? ;")
|
||
|
// err = orm.Eloquent.Exec(sqlInvite, userInvite.ID).Error
|
||
|
// if err != nil {
|
||
|
// logger.Errorf("err:", err)
|
||
|
// app.Error(c, http.StatusInternalServerError, err, "取消会员失败")
|
||
|
// return
|
||
|
// }
|
||
|
// app.OK(c, userInfo, "修改成功")
|
||
|
//}
|
||
|
//
|
||
|
//func ExportDataUser(c *gin.Context) {
|
||
|
// req := struct {
|
||
|
// StoreId uint32 `json:"store_id"`
|
||
|
// StartTime string `json:"startTime"` // 开始时间
|
||
|
// EndTime string `json:"endTime"` // 结束时间
|
||
|
// }{}
|
||
|
// if c.ShouldBindJSON(&req) != nil {
|
||
|
// logger.Errorf("para err")
|
||
|
// app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
||
|
// return
|
||
|
// }
|
||
|
// //goodsStock := models.ExportUserMember(req.StoreId, req.StartTime, req.EndTime)
|
||
|
// sysUser, err := models.GetSysUserByCtx(c)
|
||
|
// if err != nil {
|
||
|
// logger.Error("sys user err:", err)
|
||
|
// app.Error(c, http.StatusInternalServerError, err, "查询失败")
|
||
|
// return
|
||
|
// }
|
||
|
// //data, _ := c.Get(jwtauth.JwtPayloadKey)
|
||
|
// //sysUid, ok := data.(jwtauth.MapClaims)["identity"]
|
||
|
// //if !ok {
|
||
|
// // logger.Error("sys uid err")
|
||
|
// // app.Error(c, http.StatusInternalServerError, errors.New("sys uid err"), "查询失败")
|
||
|
// // return
|
||
|
// //}
|
||
|
// //sysUser, err := models.GetSysUser(sysUid)
|
||
|
// //if err != nil {
|
||
|
// // logger.Error("sys user err:", err)
|
||
|
// // app.Error(c, http.StatusInternalServerError, err, "查询失败")
|
||
|
// // return
|
||
|
// //}
|
||
|
//
|
||
|
// goodsStock := models.ExportUserMemberList(req.StoreId, 2, sysUser.CooperativeBusinessId, req.StartTime, req.EndTime)
|
||
|
//
|
||
|
// //StoreId uint32 `json:"store_id"` // 门店id
|
||
|
// //cardGoods := &models.GameCardGoods{}
|
||
|
// //err := cardGoods.Adds(req.Cards)
|
||
|
// //if err != nil {
|
||
|
// // logger.Errorf("err:", err)
|
||
|
// // app.Error(c, http.StatusInternalServerError, err, "入库失败")
|
||
|
// // return
|
||
|
// //}
|
||
|
// ret := &map[string]interface{}{
|
||
|
// "goods_stock_url": goodsStock,
|
||
|
// }
|
||
|
// app.OK(c, ret, "数据导出成功")
|
||
|
//}
|
||
|
//
|
||
|
//func ExportDataUserMember(c *gin.Context) {
|
||
|
// req := struct {
|
||
|
// MemberType uint32 `json:"member_type"` // 1-普通用户 2-会员 3-短期会员
|
||
|
// StoreId uint32 `json:"store_id"`
|
||
|
// StartTime string `json:"startTime"` // 开始时间
|
||
|
// EndTime string `json:"endTime"` // 结束时间
|
||
|
// }{}
|
||
|
// if c.ShouldBindJSON(&req) != nil {
|
||
|
// logger.Errorf("para err")
|
||
|
// app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
||
|
// return
|
||
|
// }
|
||
|
//
|
||
|
// // pms 导出会员数据
|
||
|
// goodsStock := models.ExportUserMemberList(req.StoreId, req.MemberType, 0, req.StartTime, req.EndTime)
|
||
|
// //StoreId uint32 `json:"store_id"` // 门店id
|
||
|
// //cardGoods := &models.GameCardGoods{}
|
||
|
// //err := cardGoods.Adds(req.Cards)
|
||
|
// //if err != nil {
|
||
|
// // logger.Errorf("err:", err)
|
||
|
// // app.Error(c, http.StatusInternalServerError, err, "入库失败")
|
||
|
// // return
|
||
|
// //}
|
||
|
// ret := &map[string]interface{}{
|
||
|
// "goods_stock_url": goodsStock,
|
||
|
// }
|
||
|
// app.OK(c, ret, "数据导出成功")
|
||
|
//}
|
||
|
//
|
||
|
//func ArticleAdd(c *gin.Context) {
|
||
|
// req := &models.Article{}
|
||
|
// if c.ShouldBindJSON(req) != nil {
|
||
|
// logger.Errorf("para err")
|
||
|
// app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
||
|
// return
|
||
|
// }
|
||
|
// err := orm.Eloquent.Create(req).Error
|
||
|
// if err != nil {
|
||
|
// logger.Errorf("err:", err)
|
||
|
// app.Error(c, http.StatusInternalServerError, err, "添加文章错误")
|
||
|
// return
|
||
|
// }
|
||
|
//
|
||
|
// app.OK(c, nil, "绑定店员成功")
|
||
|
//}
|
||
|
//
|
||
|
//func ArticleUpdate(c *gin.Context) {
|
||
|
// req := &models.Article{}
|
||
|
// if c.ShouldBindJSON(req) != nil {
|
||
|
// logger.Errorf("para err")
|
||
|
// app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
||
|
// return
|
||
|
// }
|
||
|
// err := orm.Eloquent.Save(req).Error
|
||
|
// if err != nil {
|
||
|
// logger.Errorf("err:", err)
|
||
|
// app.Error(c, http.StatusInternalServerError, err, "添加文章错误")
|
||
|
// return
|
||
|
// }
|
||
|
//
|
||
|
// app.OK(c, nil, "绑定店员成功")
|
||
|
//}
|
||
|
//
|
||
|
//func ArticleList(c *gin.Context) {
|
||
|
// req := &models.ArticleListReq{}
|
||
|
// if c.ShouldBindJSON(req) != nil {
|
||
|
// logger.Errorf("para err")
|
||
|
// app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
||
|
// return
|
||
|
// }
|
||
|
//
|
||
|
// list, total, err := req.GetArticleList()
|
||
|
// if err != nil {
|
||
|
// logger.Errorf("err:", err)
|
||
|
// app.Error(c, http.StatusInternalServerError, err, "获取列表错误")
|
||
|
// return
|
||
|
// }
|
||
|
//
|
||
|
// ret := &map[string]interface{}{
|
||
|
// "list": list,
|
||
|
// "count": total,
|
||
|
// "page_idx": req.PageIdx,
|
||
|
// }
|
||
|
// app.OK(c, ret, "绑定店员成功")
|
||
|
//}
|
||
|
//
|
||
|
//func ArticleDel(c *gin.Context) {
|
||
|
// req := &struct {
|
||
|
// Ids []int `json:"ids"`
|
||
|
// }{}
|
||
|
// if c.ShouldBindJSON(req) != nil {
|
||
|
// logger.Errorf("para err")
|
||
|
// app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
||
|
// return
|
||
|
// }
|
||
|
//
|
||
|
// err := orm.Eloquent.Table("article").Where("id in (?)", req.Ids).Delete(&models.Article{}).Error
|
||
|
// if err != nil {
|
||
|
// logger.Errorf("err:", err)
|
||
|
// app.Error(c, http.StatusInternalServerError, err, "文章删除错误")
|
||
|
// return
|
||
|
// }
|
||
|
//
|
||
|
// app.OK(c, nil, "绑定店员成功")
|
||
|
//}
|
||
|
//
|
||
|
//func UserDepositRefundRecordList(c *gin.Context) {
|
||
|
// req := &models.UserDepositRefundRecordListReq{}
|
||
|
// if c.ShouldBindJSON(req) != nil {
|
||
|
// logger.Errorf("para err")
|
||
|
// app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
||
|
// return
|
||
|
// }
|
||
|
//
|
||
|
// resp, err := req.DepositRefundRecordList()
|
||
|
// if err != nil {
|
||
|
// logger.Errorf("err:", err)
|
||
|
// app.Error(c, http.StatusInternalServerError, err, "获取列表错误")
|
||
|
// return
|
||
|
// }
|
||
|
//
|
||
|
// app.OK(c, resp, "绑定店员成功")
|
||
|
//}
|
||
|
//
|
||
|
//func NotarizeUserDepositRefund(c *gin.Context) {
|
||
|
// req := &struct {
|
||
|
// DepositRefundRecordId uint32 `json:"deposit_refund_record_id"`
|
||
|
// }{}
|
||
|
// if c.ShouldBindJSON(req) != nil {
|
||
|
// logger.Errorf("para err")
|
||
|
// app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
||
|
// return
|
||
|
// }
|
||
|
//
|
||
|
// fmt.Println("DepositRefundRecordId:", req.DepositRefundRecordId)
|
||
|
// var depositRefund models.DepositRefundRecord
|
||
|
// err := orm.Eloquent.Table("deposit_refund_record").Where("id = ?", req.DepositRefundRecordId).Find(&depositRefund).Error
|
||
|
// if err != nil {
|
||
|
// logger.Error("err:", err)
|
||
|
// app.Error(c, http.StatusInternalServerError, err, "错误")
|
||
|
// return
|
||
|
// }
|
||
|
// if depositRefund.Status != models.DepositRefundStatusUnconfirmed {
|
||
|
// logger.Error("status not DepositRefundStatusUnconfirmed")
|
||
|
// app.Error(c, http.StatusInternalServerError, err, "错误")
|
||
|
// return
|
||
|
// }
|
||
|
//
|
||
|
// unreturnedOrders, err := models.IsUserHaveUnreturnedOrders(depositRefund.Uid)
|
||
|
// if err != nil {
|
||
|
// logger.Error("err:", err)
|
||
|
// //RespJson(c, status.InternalServerError, nil)
|
||
|
// app.Error(c, http.StatusInternalServerError, err, "用户有未完成订单")
|
||
|
// return
|
||
|
// }
|
||
|
// if unreturnedOrders {
|
||
|
// logger.Error("unreturnedOrders")
|
||
|
// app.Error(c, http.StatusInternalServerError, err, "用户有未完成订单")
|
||
|
// return
|
||
|
// }
|
||
|
//
|
||
|
// userInfo, err := models.GetUserInfoByUid(depositRefund.Uid)
|
||
|
// if err != nil {
|
||
|
// logger.Error("err:", err)
|
||
|
// app.Error(c, http.StatusInternalServerError, err, "错误")
|
||
|
// return
|
||
|
// }
|
||
|
//
|
||
|
// transfer, err := pay.Transfer(userInfo.Deposit, userInfo.WxOpenID, "押金退款")
|
||
|
// if err != nil {
|
||
|
// logger.Error("err:", err)
|
||
|
// app.Error(c, http.StatusInternalServerError, err, "错误")
|
||
|
// return
|
||
|
// }
|
||
|
// fmt.Println("transfer:", transfer)
|
||
|
// updateUser := map[string]interface{}{
|
||
|
// "deposit": 0,
|
||
|
// "member_level": 1,
|
||
|
// }
|
||
|
// if userInfo.MemberExpire.After(time.Now()) {
|
||
|
// updateUser["member_expire"] = time.Now()
|
||
|
// }
|
||
|
// err = orm.Eloquent.Table("user").Where("uid = ?", userInfo.Uid).Updates(updateUser).Error
|
||
|
// if err != nil {
|
||
|
// logger.Error("update deposit err:", err)
|
||
|
// app.Error(c, http.StatusInternalServerError, err, "错误")
|
||
|
// return
|
||
|
// }
|
||
|
//
|
||
|
// err = orm.Eloquent.Table("deposit_refund_record").Where("id = ?", depositRefund.ID).Updates(map[string]interface{}{
|
||
|
// "status": models.DepositRefundStatusRefunded,
|
||
|
// "confirm_time": time.Now(),
|
||
|
// }).Error
|
||
|
// if err != nil {
|
||
|
// logger.Error("update deposit refund record err:", err)
|
||
|
// app.Error(c, http.StatusInternalServerError, err, "错误")
|
||
|
// return
|
||
|
// }
|
||
|
// fundRecord := &models.FundRecord{
|
||
|
// Uid: depositRefund.Uid,
|
||
|
// FundType: models.FundTypeDepositRefund,
|
||
|
// Amount: int64(depositRefund.Amount) * (-1),
|
||
|
// OutTradeNo: transfer.PartnerTradeNo,
|
||
|
// PaymentNo: transfer.PaymentNo,
|
||
|
// Status: 2,
|
||
|
// Remark: "退还押金",
|
||
|
//
|
||
|
// //TransactionId: ,
|
||
|
// }
|
||
|
// err = orm.Eloquent.Create(fundRecord).Error
|
||
|
// if err != nil {
|
||
|
// logger.Error("create fund record err:", err)
|
||
|
// }
|
||
|
// app.OK(c, nil, "操作成功")
|
||
|
//}
|
||
|
//
|
||
|
//func NotarizeUserDepositRefused(c *gin.Context) {
|
||
|
// req := &struct {
|
||
|
// DepositRefundRecordId uint32 `json:"deposit_refund_record_id"`
|
||
|
// }{}
|
||
|
// if c.ShouldBindJSON(req) != nil {
|
||
|
// logger.Errorf("para err")
|
||
|
// app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
||
|
// return
|
||
|
// }
|
||
|
//
|
||
|
// var depositRefund models.DepositRefundRecord
|
||
|
// err := orm.Eloquent.Table("deposit_refund_record").Where("id = ?", req.DepositRefundRecordId).Find(&depositRefund).Error
|
||
|
// if err != nil {
|
||
|
// logger.Error("err:", err)
|
||
|
// app.Error(c, http.StatusInternalServerError, err, "错误")
|
||
|
// return
|
||
|
// }
|
||
|
// if depositRefund.Status != models.DepositRefundStatusUnconfirmed {
|
||
|
// logger.Error("status not DepositRefundStatusUnconfirmed")
|
||
|
// app.Error(c, http.StatusInternalServerError, err, "错误")
|
||
|
// return
|
||
|
// }
|
||
|
//
|
||
|
// err = orm.Eloquent.Table("deposit_refund_record").Where("id = ?", req.DepositRefundRecordId).Updates(map[string]interface{}{
|
||
|
// "status": models.DepositRefundStatusRefused,
|
||
|
// "confirm_time": time.Now(),
|
||
|
// }).Error
|
||
|
// if err != nil {
|
||
|
// logger.Error("update deposit refund record err:", err)
|
||
|
// app.Error(c, http.StatusInternalServerError, err, "错误")
|
||
|
// return
|
||
|
// }
|
||
|
//
|
||
|
// app.OK(c, nil, "操作成功")
|
||
|
//}
|
||
|
//
|
||
|
//func GroupSendMessageCreateTemplateList(c *gin.Context) {
|
||
|
// req := &models.GroupSendMessageCreateTemplateListReq{}
|
||
|
// if c.ShouldBindJSON(req) != nil {
|
||
|
// logger.Errorf("para err")
|
||
|
// app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
||
|
// return
|
||
|
// }
|
||
|
// list, err := req.List()
|
||
|
// if err != nil {
|
||
|
// app.Error(c, http.StatusInternalServerError, err, "获取列表错误")
|
||
|
// return
|
||
|
// }
|
||
|
//
|
||
|
// app.OK(c, list, "操作成功")
|
||
|
//}
|
||
|
//
|
||
|
//func GroupSendMessageCreateTemplate(c *gin.Context) {
|
||
|
// req := &models.GroupSendMessageTemplate{}
|
||
|
// if c.ShouldBindJSON(req) != nil {
|
||
|
// logger.Errorf("para err")
|
||
|
// app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
||
|
// return
|
||
|
// }
|
||
|
// if req.UserType == 4 && req.Tels == "" {
|
||
|
// app.Error(c, http.StatusBadRequest, errors.New("para err"), "指定用户手机号")
|
||
|
// return
|
||
|
// }
|
||
|
//
|
||
|
// if req.Message == "" {
|
||
|
// app.Error(c, http.StatusBadRequest, errors.New("para err"), "短信内容不能为空")
|
||
|
// return
|
||
|
// }
|
||
|
// req.Status = 1
|
||
|
// err := orm.Eloquent.Create(req).Error
|
||
|
// if err != nil {
|
||
|
// logger.Errorf("Create GroupSendMessageTemplate err:", err)
|
||
|
// app.Error(c, http.StatusInternalServerError, err, "模板创建错误")
|
||
|
// return
|
||
|
// }
|
||
|
//
|
||
|
// app.OK(c, nil, "操作成功")
|
||
|
//}
|
||
|
//
|
||
|
//func GroupSendMessage(c *gin.Context) {
|
||
|
// req := &struct {
|
||
|
// GroupSendMessageTemplateId uint32 `json:"group_send_message_template_id"`
|
||
|
// }{}
|
||
|
// if c.ShouldBindJSON(req) != nil {
|
||
|
// logger.Errorf("para err")
|
||
|
// app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
||
|
// return
|
||
|
// }
|
||
|
// var groupMessageTemplate models.GroupSendMessageTemplate
|
||
|
// err := orm.Eloquent.Table("group_send_message_template").Where("id = ?", req.GroupSendMessageTemplateId).Find(&groupMessageTemplate).Error
|
||
|
// if err != nil && err != models.RecordNotFound {
|
||
|
// logger.Errorf("GroupSendMessageTemplate err:", err)
|
||
|
// app.Error(c, http.StatusInternalServerError, err, "获取模板错误")
|
||
|
// return
|
||
|
// }
|
||
|
// tels := ""
|
||
|
// qs := orm.Eloquent.Table("user")
|
||
|
// switch groupMessageTemplate.UserType {
|
||
|
// case 1:
|
||
|
//
|
||
|
// case 2:
|
||
|
// qs = qs.Where("member_level IN (2, 3)")
|
||
|
// case 3:
|
||
|
// qs = qs.Where("member_level = 1")
|
||
|
// case 4:
|
||
|
// tels = groupMessageTemplate.Tels
|
||
|
// }
|
||
|
// // 1-所有用户 2-会员 3-非会员
|
||
|
// if tels == "" {
|
||
|
// var users []models.UserInfo
|
||
|
// err := qs.Find(&users).Error
|
||
|
// if err != nil {
|
||
|
// logger.Errorf("users err:", err)
|
||
|
// app.Error(c, http.StatusInternalServerError, err, "获取用户错误")
|
||
|
// return
|
||
|
// }
|
||
|
// telList := make([]string, 0)
|
||
|
// for i, _ := range users {
|
||
|
// if users[i].Tel != "" {
|
||
|
// telList = append(telList, users[i].Tel)
|
||
|
// }
|
||
|
// }
|
||
|
// tels = strings.Join(telList, ",")
|
||
|
// }
|
||
|
// if tels == "" {
|
||
|
// app.Error(c, http.StatusBadRequest, errors.New("para err"), "没有要发送的手机号")
|
||
|
// return
|
||
|
// }
|
||
|
//
|
||
|
// fmt.Println("tels:", tels)
|
||
|
// fmt.Println("Message:", groupMessageTemplate.Message)
|
||
|
// //groupMessageTemplate.Message = "【go2switch】温馨提示:您的会员即将过期,请在过期之前将卡归还到门店,如有问题联系客服"
|
||
|
// err = models.SmsSend(tels, groupMessageTemplate.Message)
|
||
|
// if err != nil {
|
||
|
// logger.Errorf("SmsSend err:", err)
|
||
|
// app.Error(c, http.StatusInternalServerError, err, "群发消息错误")
|
||
|
// return
|
||
|
// }
|
||
|
//
|
||
|
// err = orm.Eloquent.Table("group_send_message_template").Where("id = ?", req.GroupSendMessageTemplateId).Updates(map[string]interface{}{
|
||
|
// "status": 2,
|
||
|
// "send_time": time.Now(),
|
||
|
// }).Error
|
||
|
// if err != nil {
|
||
|
// logger.Error("message template send update err:", err)
|
||
|
// }
|
||
|
//
|
||
|
// app.OK(c, nil, "操作成功")
|
||
|
//}
|
||
|
//
|
||
|
//func GroupSendMessageCreateTemplateDel(c *gin.Context) {
|
||
|
// req := &struct {
|
||
|
// GroupSendMessageTemplateId uint32 `json:"group_send_message_template_id"`
|
||
|
// }{}
|
||
|
// if c.ShouldBindJSON(req) != nil {
|
||
|
// logger.Errorf("para err")
|
||
|
// app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
||
|
// return
|
||
|
// }
|
||
|
// err := orm.Eloquent.Table("group_send_message_template").Where("id = ?", req.GroupSendMessageTemplateId).Delete(&models.GroupSendMessageTemplate{}).Error
|
||
|
// if err != nil {
|
||
|
// logger.Errorf("GroupMessageTemplate del err:", err)
|
||
|
// app.Error(c, http.StatusInternalServerError, err, "删除错误")
|
||
|
// return
|
||
|
// }
|
||
|
//
|
||
|
// app.OK(c, nil, "操作成功")
|
||
|
//}
|
||
|
//
|
||
|
//func XcxRoleList(c *gin.Context) {
|
||
|
// var xcxRoles []models.XcxRole
|
||
|
// err := orm.Eloquent.Table("xcx_role").Find(&xcxRoles).Error
|
||
|
// if err != nil {
|
||
|
// app.Error(c, http.StatusInternalServerError, err, "获取列表错误")
|
||
|
// return
|
||
|
// }
|
||
|
//
|
||
|
// app.OK(c, xcxRoles, "")
|
||
|
//}
|
||
|
//
|
||
|
//// 升级 1-黄金会员 2-白金会员 3-黑金会员
|
||
|
//
|
||
|
//func UserMemberRecordList(c *gin.Context) {
|
||
|
// req := new(models.UserMemberRecordReq)
|
||
|
// if c.ShouldBindJSON(req) != nil {
|
||
|
// logger.Errorf("para err")
|
||
|
// app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
||
|
// return
|
||
|
// }
|
||
|
//
|
||
|
// list, count, err := req.List()
|
||
|
// if err != nil {
|
||
|
// logger.Errorf("err:", err)
|
||
|
// app.Error(c, http.StatusInternalServerError, err, "查询失败")
|
||
|
// return
|
||
|
// }
|
||
|
//
|
||
|
// ret := map[string]interface{}{
|
||
|
// "count": count,
|
||
|
// "list": list,
|
||
|
// "pageIndex": req.PageIndex,
|
||
|
// }
|
||
|
// app.OK(c, ret, "")
|
||
|
//}
|
||
|
//
|
||
|
//func UserMemberRecordListExport(c *gin.Context) {
|
||
|
// req := new(models.UserMemberRecordReq)
|
||
|
// if c.ShouldBindJSON(req) != nil {
|
||
|
// logger.Errorf("para err")
|
||
|
// app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
||
|
// return
|
||
|
// }
|
||
|
//
|
||
|
// url, err := req.Export()
|
||
|
// if err != nil {
|
||
|
// logger.Errorf("err:", err)
|
||
|
// app.Error(c, http.StatusInternalServerError, err, "查询失败")
|
||
|
// return
|
||
|
// }
|
||
|
//
|
||
|
// app.OK(c, url, "")
|
||
|
//}
|
||
|
//
|
||
|
//func UserMemberStatisticList(c *gin.Context) {
|
||
|
// req := new(models.MemberStatisticDailyListReq)
|
||
|
// if c.ShouldBindJSON(req) != nil {
|
||
|
// logger.Errorf("para err")
|
||
|
// app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
||
|
// return
|
||
|
// }
|
||
|
//
|
||
|
// rsp, err := req.List()
|
||
|
// if err != nil {
|
||
|
// logger.Errorf("err:", err)
|
||
|
// app.Error(c, http.StatusInternalServerError, err, "查询失败")
|
||
|
// return
|
||
|
// }
|
||
|
//
|
||
|
// //ret := map[string]interface{}{
|
||
|
// // "count": count,
|
||
|
// // "list": list,
|
||
|
// // "pageIndex": req.PageNum,
|
||
|
// //}
|
||
|
// app.OK(c, rsp, "")
|
||
|
//}
|
||
|
//
|
||
|
//func UserInviteRecordList(c *gin.Context) {
|
||
|
// req := new(models.UserInviteRecordReq)
|
||
|
// if c.ShouldBindJSON(req) != nil {
|
||
|
// logger.Errorf("para err")
|
||
|
// app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
||
|
// return
|
||
|
// }
|
||
|
//
|
||
|
// list, count, err := req.List()
|
||
|
// if err != nil {
|
||
|
// logger.Errorf("err:", err)
|
||
|
// app.Error(c, http.StatusInternalServerError, err, "查询失败")
|
||
|
// return
|
||
|
// }
|
||
|
//
|
||
|
// ret := map[string]interface{}{
|
||
|
// "count": count,
|
||
|
// "list": list,
|
||
|
// "pageIndex": req.PageNum,
|
||
|
// }
|
||
|
// app.OK(c, ret, "")
|
||
|
//}
|