1
This commit is contained in:
@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
"github.com/go-admin-team/go-admin-core/sdk/api"
|
||||
"github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
|
||||
_ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"
|
||||
@ -33,7 +34,7 @@ func (e LineApiGroup) GetPage(c *gin.Context) {
|
||||
s := service.LineApiGroup{}
|
||||
err := e.MakeContext(c).
|
||||
MakeOrm().
|
||||
Bind(&req).
|
||||
Bind(&req, binding.Form, binding.Query).
|
||||
MakeService(&s.Service).
|
||||
Errors
|
||||
if err != nil {
|
||||
|
||||
@ -33,7 +33,7 @@ func (e LineApiUser) GetPage(c *gin.Context) {
|
||||
s := service.LineApiUser{}
|
||||
err := e.MakeContext(c).
|
||||
MakeOrm().
|
||||
Bind(&req, binding.Form, nil).
|
||||
Bind(&req, binding.Form, binding.Query).
|
||||
MakeService(&s.Service).
|
||||
Errors
|
||||
if err != nil {
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
package apis
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"fmt"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
"github.com/go-admin-team/go-admin-core/sdk/api"
|
||||
"github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
|
||||
_ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"
|
||||
@ -30,18 +31,18 @@ type LineSymbolBlack struct {
|
||||
// @Router /api/v1/line-symbol-black [get]
|
||||
// @Security Bearer
|
||||
func (e LineSymbolBlack) GetPage(c *gin.Context) {
|
||||
req := dto.LineSymbolBlackGetPageReq{}
|
||||
s := service.LineSymbolBlack{}
|
||||
err := e.MakeContext(c).
|
||||
MakeOrm().
|
||||
Bind(&req).
|
||||
MakeService(&s.Service).
|
||||
Errors
|
||||
if err != nil {
|
||||
e.Logger.Error(err)
|
||||
e.Error(500, err, err.Error())
|
||||
return
|
||||
}
|
||||
req := dto.LineSymbolBlackGetPageReq{}
|
||||
s := service.LineSymbolBlack{}
|
||||
err := e.MakeContext(c).
|
||||
MakeOrm().
|
||||
Bind(&req, binding.Form, binding.Query).
|
||||
MakeService(&s.Service).
|
||||
Errors
|
||||
if err != nil {
|
||||
e.Logger.Error(err)
|
||||
e.Error(500, err, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
p := actions.GetPermissionFromContext(c)
|
||||
list := make([]models.LineSymbolBlack, 0)
|
||||
@ -50,7 +51,7 @@ func (e LineSymbolBlack) GetPage(c *gin.Context) {
|
||||
err = s.GetPage(&req, p, &list, &count)
|
||||
if err != nil {
|
||||
e.Error(500, err, fmt.Sprintf("获取交易对黑名单失败,\r\n失败信息 %s", err.Error()))
|
||||
return
|
||||
return
|
||||
}
|
||||
|
||||
e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
|
||||
@ -67,7 +68,7 @@ func (e LineSymbolBlack) GetPage(c *gin.Context) {
|
||||
func (e LineSymbolBlack) Get(c *gin.Context) {
|
||||
req := dto.LineSymbolBlackGetReq{}
|
||||
s := service.LineSymbolBlack{}
|
||||
err := e.MakeContext(c).
|
||||
err := e.MakeContext(c).
|
||||
MakeOrm().
|
||||
Bind(&req).
|
||||
MakeService(&s.Service).
|
||||
@ -83,10 +84,10 @@ func (e LineSymbolBlack) Get(c *gin.Context) {
|
||||
err = s.Get(&req, p, &object)
|
||||
if err != nil {
|
||||
e.Error(500, err, fmt.Sprintf("获取交易对黑名单失败,\r\n失败信息 %s", err.Error()))
|
||||
return
|
||||
return
|
||||
}
|
||||
|
||||
e.OK( object, "查询成功")
|
||||
e.OK(object, "查询成功")
|
||||
}
|
||||
|
||||
// Insert 创建交易对黑名单
|
||||
@ -100,25 +101,25 @@ func (e LineSymbolBlack) Get(c *gin.Context) {
|
||||
// @Router /api/v1/line-symbol-black [post]
|
||||
// @Security Bearer
|
||||
func (e LineSymbolBlack) Insert(c *gin.Context) {
|
||||
req := dto.LineSymbolBlackInsertReq{}
|
||||
s := service.LineSymbolBlack{}
|
||||
err := e.MakeContext(c).
|
||||
MakeOrm().
|
||||
Bind(&req).
|
||||
MakeService(&s.Service).
|
||||
Errors
|
||||
if err != nil {
|
||||
e.Logger.Error(err)
|
||||
e.Error(500, err, err.Error())
|
||||
return
|
||||
}
|
||||
req := dto.LineSymbolBlackInsertReq{}
|
||||
s := service.LineSymbolBlack{}
|
||||
err := e.MakeContext(c).
|
||||
MakeOrm().
|
||||
Bind(&req).
|
||||
MakeService(&s.Service).
|
||||
Errors
|
||||
if err != nil {
|
||||
e.Logger.Error(err)
|
||||
e.Error(500, err, err.Error())
|
||||
return
|
||||
}
|
||||
// 设置创建人
|
||||
req.SetCreateBy(user.GetUserId(c))
|
||||
|
||||
err = s.Insert(&req)
|
||||
if err != nil {
|
||||
e.Error(500, err, fmt.Sprintf("创建交易对黑名单失败,\r\n失败信息 %s", err.Error()))
|
||||
return
|
||||
return
|
||||
}
|
||||
|
||||
e.OK(req.GetId(), "创建成功")
|
||||
@ -136,27 +137,27 @@ func (e LineSymbolBlack) Insert(c *gin.Context) {
|
||||
// @Router /api/v1/line-symbol-black/{id} [put]
|
||||
// @Security Bearer
|
||||
func (e LineSymbolBlack) Update(c *gin.Context) {
|
||||
req := dto.LineSymbolBlackUpdateReq{}
|
||||
s := service.LineSymbolBlack{}
|
||||
err := e.MakeContext(c).
|
||||
MakeOrm().
|
||||
Bind(&req).
|
||||
MakeService(&s.Service).
|
||||
Errors
|
||||
if err != nil {
|
||||
e.Logger.Error(err)
|
||||
e.Error(500, err, err.Error())
|
||||
return
|
||||
}
|
||||
req := dto.LineSymbolBlackUpdateReq{}
|
||||
s := service.LineSymbolBlack{}
|
||||
err := e.MakeContext(c).
|
||||
MakeOrm().
|
||||
Bind(&req).
|
||||
MakeService(&s.Service).
|
||||
Errors
|
||||
if err != nil {
|
||||
e.Logger.Error(err)
|
||||
e.Error(500, err, err.Error())
|
||||
return
|
||||
}
|
||||
req.SetUpdateBy(user.GetUserId(c))
|
||||
p := actions.GetPermissionFromContext(c)
|
||||
|
||||
err = s.Update(&req, p)
|
||||
if err != nil {
|
||||
e.Error(500, err, fmt.Sprintf("修改交易对黑名单失败,\r\n失败信息 %s", err.Error()))
|
||||
return
|
||||
return
|
||||
}
|
||||
e.OK( req.GetId(), "修改成功")
|
||||
e.OK(req.GetId(), "修改成功")
|
||||
}
|
||||
|
||||
// Delete 删除交易对黑名单
|
||||
@ -168,18 +169,18 @@ func (e LineSymbolBlack) Update(c *gin.Context) {
|
||||
// @Router /api/v1/line-symbol-black [delete]
|
||||
// @Security Bearer
|
||||
func (e LineSymbolBlack) Delete(c *gin.Context) {
|
||||
s := service.LineSymbolBlack{}
|
||||
req := dto.LineSymbolBlackDeleteReq{}
|
||||
err := e.MakeContext(c).
|
||||
MakeOrm().
|
||||
Bind(&req).
|
||||
MakeService(&s.Service).
|
||||
Errors
|
||||
if err != nil {
|
||||
e.Logger.Error(err)
|
||||
e.Error(500, err, err.Error())
|
||||
return
|
||||
}
|
||||
s := service.LineSymbolBlack{}
|
||||
req := dto.LineSymbolBlackDeleteReq{}
|
||||
err := e.MakeContext(c).
|
||||
MakeOrm().
|
||||
Bind(&req).
|
||||
MakeService(&s.Service).
|
||||
Errors
|
||||
if err != nil {
|
||||
e.Logger.Error(err)
|
||||
e.Error(500, err, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// req.SetUpdateBy(user.GetUserId(c))
|
||||
p := actions.GetPermissionFromContext(c)
|
||||
@ -187,7 +188,7 @@ func (e LineSymbolBlack) Delete(c *gin.Context) {
|
||||
err = s.Remove(&req, p)
|
||||
if err != nil {
|
||||
e.Error(500, err, fmt.Sprintf("删除交易对黑名单失败,\r\n失败信息 %s", err.Error()))
|
||||
return
|
||||
return
|
||||
}
|
||||
e.OK( req.GetId(), "删除成功")
|
||||
e.OK(req.GetId(), "删除成功")
|
||||
}
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
package apis
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"fmt"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
"github.com/go-admin-team/go-admin-core/sdk/api"
|
||||
"github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
|
||||
_ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"
|
||||
@ -12,6 +13,7 @@ import (
|
||||
"go-admin/app/admin/service"
|
||||
"go-admin/app/admin/service/dto"
|
||||
"go-admin/common/actions"
|
||||
statuscode "go-admin/common/status_code"
|
||||
)
|
||||
|
||||
type LineUser struct {
|
||||
@ -28,18 +30,18 @@ type LineUser struct {
|
||||
// @Router /api/v1/line-user [get]
|
||||
// @Security Bearer
|
||||
func (e LineUser) GetPage(c *gin.Context) {
|
||||
req := dto.LineUserGetPageReq{}
|
||||
s := service.LineUser{}
|
||||
err := e.MakeContext(c).
|
||||
MakeOrm().
|
||||
Bind(&req).
|
||||
MakeService(&s.Service).
|
||||
Errors
|
||||
if err != nil {
|
||||
e.Logger.Error(err)
|
||||
e.Error(500, err, err.Error())
|
||||
return
|
||||
}
|
||||
req := dto.LineUserGetPageReq{}
|
||||
s := service.LineUser{}
|
||||
err := e.MakeContext(c).
|
||||
MakeOrm().
|
||||
Bind(&req, binding.Form, binding.Query).
|
||||
MakeService(&s.Service).
|
||||
Errors
|
||||
if err != nil {
|
||||
e.Logger.Error(err)
|
||||
e.Error(500, err, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
p := actions.GetPermissionFromContext(c)
|
||||
list := make([]models.LineUser, 0)
|
||||
@ -48,7 +50,7 @@ func (e LineUser) GetPage(c *gin.Context) {
|
||||
err = s.GetPage(&req, p, &list, &count)
|
||||
if err != nil {
|
||||
e.Error(500, err, fmt.Sprintf("获取会员表失败,\r\n失败信息 %s", err.Error()))
|
||||
return
|
||||
return
|
||||
}
|
||||
|
||||
e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
|
||||
@ -65,7 +67,7 @@ func (e LineUser) GetPage(c *gin.Context) {
|
||||
func (e LineUser) Get(c *gin.Context) {
|
||||
req := dto.LineUserGetReq{}
|
||||
s := service.LineUser{}
|
||||
err := e.MakeContext(c).
|
||||
err := e.MakeContext(c).
|
||||
MakeOrm().
|
||||
Bind(&req).
|
||||
MakeService(&s.Service).
|
||||
@ -81,10 +83,10 @@ func (e LineUser) Get(c *gin.Context) {
|
||||
err = s.Get(&req, p, &object)
|
||||
if err != nil {
|
||||
e.Error(500, err, fmt.Sprintf("获取会员表失败,\r\n失败信息 %s", err.Error()))
|
||||
return
|
||||
return
|
||||
}
|
||||
|
||||
e.OK( object, "查询成功")
|
||||
e.OK(object, "查询成功")
|
||||
}
|
||||
|
||||
// Insert 创建会员表
|
||||
@ -98,25 +100,25 @@ func (e LineUser) Get(c *gin.Context) {
|
||||
// @Router /api/v1/line-user [post]
|
||||
// @Security Bearer
|
||||
func (e LineUser) Insert(c *gin.Context) {
|
||||
req := dto.LineUserInsertReq{}
|
||||
s := service.LineUser{}
|
||||
err := e.MakeContext(c).
|
||||
MakeOrm().
|
||||
Bind(&req).
|
||||
MakeService(&s.Service).
|
||||
Errors
|
||||
if err != nil {
|
||||
e.Logger.Error(err)
|
||||
e.Error(500, err, err.Error())
|
||||
return
|
||||
}
|
||||
req := dto.LineUserInsertReq{}
|
||||
s := service.LineUser{}
|
||||
err := e.MakeContext(c).
|
||||
MakeOrm().
|
||||
Bind(&req).
|
||||
MakeService(&s.Service).
|
||||
Errors
|
||||
if err != nil {
|
||||
e.Logger.Error(err)
|
||||
e.Error(500, err, err.Error())
|
||||
return
|
||||
}
|
||||
// 设置创建人
|
||||
req.SetCreateBy(user.GetUserId(c))
|
||||
|
||||
err = s.Insert(&req)
|
||||
if err != nil {
|
||||
e.Error(500, err, fmt.Sprintf("创建会员表失败,\r\n失败信息 %s", err.Error()))
|
||||
return
|
||||
return
|
||||
}
|
||||
|
||||
e.OK(req.GetId(), "创建成功")
|
||||
@ -134,27 +136,27 @@ func (e LineUser) Insert(c *gin.Context) {
|
||||
// @Router /api/v1/line-user/{id} [put]
|
||||
// @Security Bearer
|
||||
func (e LineUser) Update(c *gin.Context) {
|
||||
req := dto.LineUserUpdateReq{}
|
||||
s := service.LineUser{}
|
||||
err := e.MakeContext(c).
|
||||
MakeOrm().
|
||||
Bind(&req).
|
||||
MakeService(&s.Service).
|
||||
Errors
|
||||
if err != nil {
|
||||
e.Logger.Error(err)
|
||||
e.Error(500, err, err.Error())
|
||||
return
|
||||
}
|
||||
req := dto.LineUserUpdateReq{}
|
||||
s := service.LineUser{}
|
||||
err := e.MakeContext(c).
|
||||
MakeOrm().
|
||||
Bind(&req).
|
||||
MakeService(&s.Service).
|
||||
Errors
|
||||
if err != nil {
|
||||
e.Logger.Error(err)
|
||||
e.Error(500, err, err.Error())
|
||||
return
|
||||
}
|
||||
req.SetUpdateBy(user.GetUserId(c))
|
||||
p := actions.GetPermissionFromContext(c)
|
||||
|
||||
err = s.Update(&req, p)
|
||||
if err != nil {
|
||||
e.Error(500, err, fmt.Sprintf("修改会员表失败,\r\n失败信息 %s", err.Error()))
|
||||
return
|
||||
return
|
||||
}
|
||||
e.OK( req.GetId(), "修改成功")
|
||||
e.OK(req.GetId(), "修改成功")
|
||||
}
|
||||
|
||||
// Delete 删除会员表
|
||||
@ -166,18 +168,18 @@ func (e LineUser) Update(c *gin.Context) {
|
||||
// @Router /api/v1/line-user [delete]
|
||||
// @Security Bearer
|
||||
func (e LineUser) Delete(c *gin.Context) {
|
||||
s := service.LineUser{}
|
||||
req := dto.LineUserDeleteReq{}
|
||||
err := e.MakeContext(c).
|
||||
MakeOrm().
|
||||
Bind(&req).
|
||||
MakeService(&s.Service).
|
||||
Errors
|
||||
if err != nil {
|
||||
e.Logger.Error(err)
|
||||
e.Error(500, err, err.Error())
|
||||
return
|
||||
}
|
||||
s := service.LineUser{}
|
||||
req := dto.LineUserDeleteReq{}
|
||||
err := e.MakeContext(c).
|
||||
MakeOrm().
|
||||
Bind(&req).
|
||||
MakeService(&s.Service).
|
||||
Errors
|
||||
if err != nil {
|
||||
e.Logger.Error(err)
|
||||
e.Error(500, err, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// req.SetUpdateBy(user.GetUserId(c))
|
||||
p := actions.GetPermissionFromContext(c)
|
||||
@ -185,7 +187,38 @@ func (e LineUser) Delete(c *gin.Context) {
|
||||
err = s.Remove(&req, p)
|
||||
if err != nil {
|
||||
e.Error(500, err, fmt.Sprintf("删除会员表失败,\r\n失败信息 %s", err.Error()))
|
||||
return
|
||||
return
|
||||
}
|
||||
e.OK( req.GetId(), "删除成功")
|
||||
e.OK(req.GetId(), "删除成功")
|
||||
}
|
||||
|
||||
// 重新获取资产
|
||||
func (e LineUser) ReloadProperty(c *gin.Context) {
|
||||
s := service.LineUser{}
|
||||
req := dto.LineUserReloadPropertyReq{}
|
||||
err := e.MakeContext(c).
|
||||
MakeOrm().
|
||||
Bind(&req).
|
||||
MakeService(&s.Service).
|
||||
Errors
|
||||
if err != nil {
|
||||
e.Logger.Error(err)
|
||||
e.Error(500, err, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
data := dto.LineUserPropertyResp{}
|
||||
code := s.GetProperty(req.UserId, &data)
|
||||
|
||||
if code != statuscode.OK {
|
||||
if code == statuscode.UserApiUserNotBind {
|
||||
e.Error(500, nil, "用户未绑定api")
|
||||
} else {
|
||||
e.Error(500, nil, "获取失败")
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
e.OK(nil, "操作成功")
|
||||
}
|
||||
|
||||
@ -459,16 +459,10 @@ func (e LineUserApi) OpenStatus(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
userId := common.GetUserId(c)
|
||||
var apiUser models.LineApiUser
|
||||
err = e.Orm.Model(&models.LineApiUser{}).Where("user_id = ?", userId).Find(&apiUser).Error
|
||||
code := s.OpenStatus(&req, userId)
|
||||
|
||||
if apiUser.ApiSecret == "" || apiUser.ApiKey == "" {
|
||||
e.Error(statuscode.UserApiKeyRequired, nil, sysstatuscode.GetStatusCodeDescription(c, statuscode.UserApiKeyRequired))
|
||||
return
|
||||
}
|
||||
err = e.Orm.Model(&models.LineApiUser{}).Where("user_id = ?", userId).Update("open_status", req.Status).Error
|
||||
if err != nil {
|
||||
e.Error(500, err, err.Error())
|
||||
if code != statuscode.OK {
|
||||
e.Error(code, nil, sysstatuscode.GetStatusCodeDescription(c, code))
|
||||
return
|
||||
}
|
||||
e.OK(nil, "success")
|
||||
@ -641,9 +635,10 @@ func (e LineUserApi) GetProperty(c *gin.Context) {
|
||||
var data dto.LineUserPropertyResp
|
||||
userId := common.GetUserId(c)
|
||||
code := s.GetProperty(userId, &data)
|
||||
if code != statuscode.OK {
|
||||
if code != statuscode.OK && code != statuscode.UserApiUserNotBind {
|
||||
// e.Logger.Error(err)
|
||||
e.Error(code, nil, sysstatuscode.GetStatusCodeDescription(c, code))
|
||||
return
|
||||
}
|
||||
|
||||
e.OK(data, "success")
|
||||
|
||||
@ -11,36 +11,40 @@ import (
|
||||
type LineUser struct {
|
||||
models.Model
|
||||
|
||||
GroupId int `json:"groupId" gorm:"type:int unsigned;comment:组别ID"`
|
||||
Pid int `json:"pid" gorm:"type:int unsigned;comment:直接推荐人ID"`
|
||||
TopReferrerId int `json:"topReferrerId" gorm:"type:int unsigned;comment:父级推荐人ID"`
|
||||
Username string `json:"username" gorm:"type:varchar(32);comment:用户名"`
|
||||
Nickname string `json:"nickname" gorm:"type:varchar(50);comment:昵称"`
|
||||
Password string `json:"password" gorm:"type:varchar(32);comment:密码"`
|
||||
Salt string `json:"salt" gorm:"type:varchar(30);comment:密码盐"`
|
||||
Email string `json:"email" gorm:"type:varchar(100);comment:电子邮箱"`
|
||||
Mobile string `json:"mobile" gorm:"type:varchar(11);comment:手机号"`
|
||||
Area string `json:"area" gorm:"type:varchar(255);comment:手机号归属地"`
|
||||
Avatar string `json:"avatar" gorm:"type:varchar(255);comment:头像"`
|
||||
Level int `json:"level" gorm:"type:tinyint unsigned;comment:等级"`
|
||||
Gender int `json:"gender" gorm:"type:tinyint unsigned;comment:性别"`
|
||||
Bio string `json:"bio" gorm:"type:varchar(100);comment:格言"`
|
||||
Money decimal.Decimal `json:"money" gorm:"type:decimal(10,2) unsigned;comment:保证金"`
|
||||
Score int `json:"score" gorm:"type:int unsigned;comment:积分"`
|
||||
InviteCode string `json:"invite_code" gorm:"type:varchar(255);comment:邀请码"`
|
||||
Successions int `json:"successions" gorm:"type:int unsigned;comment:连续登录天数"`
|
||||
MaxSuccessions int `json:"maxSuccessions" gorm:"type:int unsigned;comment:最大连续登录天数"`
|
||||
Loginip string `json:"loginip" gorm:"type:varchar(50);comment:登录IP"`
|
||||
Loginfailure int `json:"loginfailure" gorm:"type:tinyint unsigned;comment:失败次数"`
|
||||
Joinip string `json:"joinip" gorm:"type:varchar(50);comment:加入IP"`
|
||||
Jointime int `json:"jointime" gorm:"type:int;comment:加入时间"`
|
||||
RecommendNum int `json:"recommend_num" gorm:"type:int;comment:推荐人数"`
|
||||
Token string `json:"token" gorm:"type:varchar(50);comment:Token"`
|
||||
Status string `json:"status" gorm:"type:varchar(30);comment:状态"`
|
||||
Verification string `json:"verification" gorm:"type:varchar(255);comment:验证"`
|
||||
LoginTime time.Time `json:"loginTime" gorm:"type:timestamp;comment:登录时间"`
|
||||
ExpirationTime *time.Time `json:"expirationTime" gorm:"type:timestamp;comment:过期时间"`
|
||||
OpenStatus int `json:"open_status" gorm:"-"`
|
||||
GroupId int `json:"groupId" gorm:"type:int unsigned;comment:组别ID"`
|
||||
Pid int `json:"pid" gorm:"type:int unsigned;comment:直接推荐人ID"`
|
||||
TopReferrerId int `json:"topReferrerId" gorm:"type:int unsigned;comment:父级推荐人ID"`
|
||||
Username string `json:"username" gorm:"type:varchar(32);comment:用户名"`
|
||||
Nickname string `json:"nickname" gorm:"type:varchar(50);comment:昵称"`
|
||||
Password string `json:"password" gorm:"type:varchar(50);comment:密码"`
|
||||
Salt string `json:"salt" gorm:"type:varchar(30);comment:密码盐"`
|
||||
Email string `json:"email" gorm:"type:varchar(100);comment:电子邮箱"`
|
||||
Mobile string `json:"mobile" gorm:"type:varchar(11);comment:手机号"`
|
||||
Area string `json:"area" gorm:"type:varchar(255);comment:手机号归属地"`
|
||||
Avatar string `json:"avatar" gorm:"type:varchar(255);comment:头像"`
|
||||
Level int `json:"level" gorm:"type:tinyint unsigned;comment:等级"`
|
||||
Gender int `json:"gender" gorm:"type:tinyint unsigned;comment:性别"`
|
||||
Bio string `json:"bio" gorm:"type:varchar(100);comment:格言"`
|
||||
Money decimal.Decimal `json:"money" gorm:"type:decimal(10,2) unsigned;comment:保证金"`
|
||||
Score int `json:"score" gorm:"type:int unsigned;comment:积分"`
|
||||
InviteCode string `json:"invite_code" gorm:"type:varchar(255);comment:邀请码"`
|
||||
Successions int `json:"successions" gorm:"type:int unsigned;comment:连续登录天数"`
|
||||
MaxSuccessions int `json:"maxSuccessions" gorm:"type:int unsigned;comment:最大连续登录天数"`
|
||||
Loginip string `json:"loginip" gorm:"type:varchar(50);comment:登录IP"`
|
||||
Loginfailure int `json:"loginfailure" gorm:"type:tinyint unsigned;comment:失败次数"`
|
||||
Joinip string `json:"joinip" gorm:"type:varchar(50);comment:加入IP"`
|
||||
Jointime int `json:"jointime" gorm:"type:int;comment:加入时间"`
|
||||
RecommendNum int `json:"recommend_num" gorm:"type:int;comment:推荐人数"`
|
||||
Token string `json:"token" gorm:"type:varchar(50);comment:Token"`
|
||||
Status string `json:"status" gorm:"type:varchar(30);comment:状态"`
|
||||
Verification string `json:"verification" gorm:"type:varchar(255);comment:验证"`
|
||||
LoginTime time.Time `json:"loginTime" gorm:"type:timestamp;comment:登录时间"`
|
||||
ExpirationTime *time.Time `json:"expirationTime" gorm:"type:timestamp;comment:过期时间"`
|
||||
OpenStatus int `json:"open_status" gorm:"-"`
|
||||
SpotFreeAmount decimal.Decimal `json:"spotFreeAmount" gorm:"-"`
|
||||
FutureFreeAmount decimal.Decimal `json:"futureFreeAmount" gorm:"-"`
|
||||
AssetUpdateTime *time.Time `json:"assetUpdateTime" gorm:"-"`
|
||||
MinOrderAmount decimal.Decimal `json:"minOrderAmount" gorm:"-"`
|
||||
models.ModelTime
|
||||
models.ControlBy
|
||||
}
|
||||
|
||||
@ -26,6 +26,8 @@ func registerLineUserRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddl
|
||||
r.POST("", api.Insert)
|
||||
r.PUT("/:id", actions.PermissionAction(), api.Update)
|
||||
r.DELETE("", api.Delete)
|
||||
|
||||
r.PUT("property", api.ReloadProperty) //更新资产
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -406,3 +406,7 @@ func (e *LineUserResetPwdReq) Valid() int {
|
||||
|
||||
return statuscode.OK
|
||||
}
|
||||
|
||||
type LineUserReloadPropertyReq struct {
|
||||
UserId int `json:"userId"`
|
||||
}
|
||||
|
||||
@ -43,6 +43,9 @@ type LineUser struct {
|
||||
func (e *LineUser) GetPage(c *dto.LineUserGetPageReq, p *actions.DataPermission, list *[]models.LineUser, count *int64) error {
|
||||
var err error
|
||||
var data models.LineUser
|
||||
userIds := make([]int, 0)
|
||||
apiUsers := make([]models.LineApiUser, 0)
|
||||
userSettings := make([]models.LineUserSetting, 0)
|
||||
|
||||
err = e.Orm.Model(&data).
|
||||
Scopes(
|
||||
@ -56,11 +59,37 @@ func (e *LineUser) GetPage(c *dto.LineUserGetPageReq, p *actions.DataPermission,
|
||||
e.Log.Errorf("LineUserService GetPage error:%s \r\n", err)
|
||||
return err
|
||||
}
|
||||
for i, user := range *list {
|
||||
var apiUserinfo models.LineApiUser
|
||||
e.Orm.Model(&models.LineApiUser{}).Where("user_id = ?", user.Id).Find(&apiUserinfo)
|
||||
(*list)[i].OpenStatus = int(apiUserinfo.OpenStatus)
|
||||
for _, user := range *list {
|
||||
if utility.ContainsInt(userIds, user.Id) {
|
||||
continue
|
||||
}
|
||||
userIds = append(userIds, user.Id)
|
||||
}
|
||||
|
||||
if len(userIds) > 0 {
|
||||
e.Orm.Model(&models.LineApiUser{}).Where("user_id in (?)", userIds).Find(&apiUsers)
|
||||
e.Orm.Model(&models.LineUserSetting{}).Where("user_id in (?)", userIds).Find(&userSettings)
|
||||
}
|
||||
|
||||
for i := range *list {
|
||||
for _, item := range apiUsers {
|
||||
if item.UserId == int64((*list)[i].Id) {
|
||||
(*list)[i].OpenStatus = int(item.OpenStatus)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
for _, item := range userSettings {
|
||||
if item.UserId == (*list)[i].Id {
|
||||
(*list)[i].SpotFreeAmount = item.SpotUsdtFreeAmount
|
||||
(*list)[i].FutureFreeAmount = item.FutureUsdtFreeAmount
|
||||
(*list)[i].MinOrderAmount = item.MinOrderAmount
|
||||
(*list)[i].AssetUpdateTime = item.AssetUpdateTime
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -679,8 +708,51 @@ func (e *LineUser) ResetPassword(req *dto.LineUserResetPwdReq) int {
|
||||
return status
|
||||
}
|
||||
user.Password = md5helper.MD5(req.Pwd + user.Salt)
|
||||
if err := e.Orm.Model(&user).Update("password", user.Password).Error; err != nil {
|
||||
if err := e.Orm.Model(&user).Updates(map[string]interface{}{"password": user.Password}).Error; err != nil {
|
||||
return statuscode.ServerError
|
||||
}
|
||||
return statuscode.OK
|
||||
}
|
||||
|
||||
func (e *LineUser) OpenStatus(req *dto.OpenStatusReq, userId int) int {
|
||||
var apiUser models.LineApiUser
|
||||
user := models.LineUser{}
|
||||
e.Orm.Model(&models.LineApiUser{}).Where("user_id = ?", userId).Find(&apiUser)
|
||||
|
||||
if apiUser.ApiSecret == "" || apiUser.ApiKey == "" {
|
||||
return statuscode.UserApiKeyRequired
|
||||
}
|
||||
|
||||
if err := e.Orm.Model(&user).Where("id =?", userId).First(&user).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return statuscode.DataError
|
||||
}
|
||||
|
||||
logger.Error("查询用户失败", err)
|
||||
return statuscode.ServerError
|
||||
}
|
||||
|
||||
if req.Status == 1 {
|
||||
if user.ExpirationTime == nil || user.ExpirationTime.Before(time.Now()) {
|
||||
return statuscode.UserExpired
|
||||
}
|
||||
|
||||
userSet := models.LineUserSetting{}
|
||||
e.Orm.Model(&userSet).Where("user_id =?", userId).First(&userSet)
|
||||
|
||||
propperty := dto.LineUserPropertyResp{}
|
||||
e.GetProperty(userId, &propperty)
|
||||
|
||||
//可用资产不足
|
||||
if propperty.FuturesFreeAmount.Cmp(userSet.MinOrderAmount) < 0 && propperty.SpotFreeAmount.Cmp(userSet.MinOrderAmount) < 0 {
|
||||
return statuscode.PropertyInsufficient
|
||||
}
|
||||
}
|
||||
|
||||
err := e.Orm.Model(&models.LineApiUser{}).Where("user_id = ?", userId).Update("open_status", req.Status).Error
|
||||
if err != nil {
|
||||
return statuscode.ServerError
|
||||
}
|
||||
|
||||
return statuscode.OK
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user