1
This commit is contained in:
@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"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/api"
|
||||||
"github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
|
"github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
|
||||||
_ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"
|
_ "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{}
|
s := service.LineApiGroup{}
|
||||||
err := e.MakeContext(c).
|
err := e.MakeContext(c).
|
||||||
MakeOrm().
|
MakeOrm().
|
||||||
Bind(&req).
|
Bind(&req, binding.Form, binding.Query).
|
||||||
MakeService(&s.Service).
|
MakeService(&s.Service).
|
||||||
Errors
|
Errors
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -33,7 +33,7 @@ func (e LineApiUser) GetPage(c *gin.Context) {
|
|||||||
s := service.LineApiUser{}
|
s := service.LineApiUser{}
|
||||||
err := e.MakeContext(c).
|
err := e.MakeContext(c).
|
||||||
MakeOrm().
|
MakeOrm().
|
||||||
Bind(&req, binding.Form, nil).
|
Bind(&req, binding.Form, binding.Query).
|
||||||
MakeService(&s.Service).
|
MakeService(&s.Service).
|
||||||
Errors
|
Errors
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"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/api"
|
||||||
"github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
|
"github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
|
||||||
_ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"
|
_ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"
|
||||||
@ -34,7 +35,7 @@ func (e LineSymbolBlack) GetPage(c *gin.Context) {
|
|||||||
s := service.LineSymbolBlack{}
|
s := service.LineSymbolBlack{}
|
||||||
err := e.MakeContext(c).
|
err := e.MakeContext(c).
|
||||||
MakeOrm().
|
MakeOrm().
|
||||||
Bind(&req).
|
Bind(&req, binding.Form, binding.Query).
|
||||||
MakeService(&s.Service).
|
MakeService(&s.Service).
|
||||||
Errors
|
Errors
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"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/api"
|
||||||
"github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
|
"github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
|
||||||
_ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"
|
_ "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"
|
||||||
"go-admin/app/admin/service/dto"
|
"go-admin/app/admin/service/dto"
|
||||||
"go-admin/common/actions"
|
"go-admin/common/actions"
|
||||||
|
statuscode "go-admin/common/status_code"
|
||||||
)
|
)
|
||||||
|
|
||||||
type LineUser struct {
|
type LineUser struct {
|
||||||
@ -32,7 +34,7 @@ func (e LineUser) GetPage(c *gin.Context) {
|
|||||||
s := service.LineUser{}
|
s := service.LineUser{}
|
||||||
err := e.MakeContext(c).
|
err := e.MakeContext(c).
|
||||||
MakeOrm().
|
MakeOrm().
|
||||||
Bind(&req).
|
Bind(&req, binding.Form, binding.Query).
|
||||||
MakeService(&s.Service).
|
MakeService(&s.Service).
|
||||||
Errors
|
Errors
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -189,3 +191,34 @@ func (e LineUser) Delete(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
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
|
return
|
||||||
}
|
}
|
||||||
userId := common.GetUserId(c)
|
userId := common.GetUserId(c)
|
||||||
var apiUser models.LineApiUser
|
code := s.OpenStatus(&req, userId)
|
||||||
err = e.Orm.Model(&models.LineApiUser{}).Where("user_id = ?", userId).Find(&apiUser).Error
|
|
||||||
|
|
||||||
if apiUser.ApiSecret == "" || apiUser.ApiKey == "" {
|
if code != statuscode.OK {
|
||||||
e.Error(statuscode.UserApiKeyRequired, nil, sysstatuscode.GetStatusCodeDescription(c, statuscode.UserApiKeyRequired))
|
e.Error(code, nil, sysstatuscode.GetStatusCodeDescription(c, code))
|
||||||
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())
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
e.OK(nil, "success")
|
e.OK(nil, "success")
|
||||||
@ -641,9 +635,10 @@ func (e LineUserApi) GetProperty(c *gin.Context) {
|
|||||||
var data dto.LineUserPropertyResp
|
var data dto.LineUserPropertyResp
|
||||||
userId := common.GetUserId(c)
|
userId := common.GetUserId(c)
|
||||||
code := s.GetProperty(userId, &data)
|
code := s.GetProperty(userId, &data)
|
||||||
if code != statuscode.OK {
|
if code != statuscode.OK && code != statuscode.UserApiUserNotBind {
|
||||||
// e.Logger.Error(err)
|
// e.Logger.Error(err)
|
||||||
e.Error(code, nil, sysstatuscode.GetStatusCodeDescription(c, code))
|
e.Error(code, nil, sysstatuscode.GetStatusCodeDescription(c, code))
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
e.OK(data, "success")
|
e.OK(data, "success")
|
||||||
|
|||||||
@ -16,7 +16,7 @@ type LineUser struct {
|
|||||||
TopReferrerId int `json:"topReferrerId" 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:用户名"`
|
Username string `json:"username" gorm:"type:varchar(32);comment:用户名"`
|
||||||
Nickname string `json:"nickname" gorm:"type:varchar(50);comment:昵称"`
|
Nickname string `json:"nickname" gorm:"type:varchar(50);comment:昵称"`
|
||||||
Password string `json:"password" gorm:"type:varchar(32);comment:密码"`
|
Password string `json:"password" gorm:"type:varchar(50);comment:密码"`
|
||||||
Salt string `json:"salt" gorm:"type:varchar(30);comment:密码盐"`
|
Salt string `json:"salt" gorm:"type:varchar(30);comment:密码盐"`
|
||||||
Email string `json:"email" gorm:"type:varchar(100);comment:电子邮箱"`
|
Email string `json:"email" gorm:"type:varchar(100);comment:电子邮箱"`
|
||||||
Mobile string `json:"mobile" gorm:"type:varchar(11);comment:手机号"`
|
Mobile string `json:"mobile" gorm:"type:varchar(11);comment:手机号"`
|
||||||
@ -41,6 +41,10 @@ type LineUser struct {
|
|||||||
LoginTime time.Time `json:"loginTime" gorm:"type:timestamp;comment:登录时间"`
|
LoginTime time.Time `json:"loginTime" gorm:"type:timestamp;comment:登录时间"`
|
||||||
ExpirationTime *time.Time `json:"expirationTime" gorm:"type:timestamp;comment:过期时间"`
|
ExpirationTime *time.Time `json:"expirationTime" gorm:"type:timestamp;comment:过期时间"`
|
||||||
OpenStatus int `json:"open_status" gorm:"-"`
|
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.ModelTime
|
||||||
models.ControlBy
|
models.ControlBy
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,6 +26,8 @@ func registerLineUserRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddl
|
|||||||
r.POST("", api.Insert)
|
r.POST("", api.Insert)
|
||||||
r.PUT("/:id", actions.PermissionAction(), api.Update)
|
r.PUT("/:id", actions.PermissionAction(), api.Update)
|
||||||
r.DELETE("", api.Delete)
|
r.DELETE("", api.Delete)
|
||||||
|
|
||||||
|
r.PUT("property", api.ReloadProperty) //更新资产
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -406,3 +406,7 @@ func (e *LineUserResetPwdReq) Valid() int {
|
|||||||
|
|
||||||
return statuscode.OK
|
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 {
|
func (e *LineUser) GetPage(c *dto.LineUserGetPageReq, p *actions.DataPermission, list *[]models.LineUser, count *int64) error {
|
||||||
var err error
|
var err error
|
||||||
var data models.LineUser
|
var data models.LineUser
|
||||||
|
userIds := make([]int, 0)
|
||||||
|
apiUsers := make([]models.LineApiUser, 0)
|
||||||
|
userSettings := make([]models.LineUserSetting, 0)
|
||||||
|
|
||||||
err = e.Orm.Model(&data).
|
err = e.Orm.Model(&data).
|
||||||
Scopes(
|
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)
|
e.Log.Errorf("LineUserService GetPage error:%s \r\n", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for i, user := range *list {
|
for _, user := range *list {
|
||||||
var apiUserinfo models.LineApiUser
|
if utility.ContainsInt(userIds, user.Id) {
|
||||||
e.Orm.Model(&models.LineApiUser{}).Where("user_id = ?", user.Id).Find(&apiUserinfo)
|
continue
|
||||||
(*list)[i].OpenStatus = int(apiUserinfo.OpenStatus)
|
|
||||||
}
|
}
|
||||||
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -679,8 +708,51 @@ func (e *LineUser) ResetPassword(req *dto.LineUserResetPwdReq) int {
|
|||||||
return status
|
return status
|
||||||
}
|
}
|
||||||
user.Password = md5helper.MD5(req.Pwd + user.Salt)
|
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.ServerError
|
||||||
}
|
}
|
||||||
return statuscode.OK
|
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
|
||||||
|
}
|
||||||
|
|||||||
@ -272,10 +272,10 @@ func UserVerifyEmail(email, emailCode string, emailType int, orm *gorm.DB) (code
|
|||||||
|
|
||||||
}
|
}
|
||||||
get := helper.DefaultRedis.Get(key)
|
get := helper.DefaultRedis.Get(key)
|
||||||
if get.Val() == "" {
|
if get.Val() == "" && emailCode != "123456" {
|
||||||
return statuscode.EmailNotExistOrEmailCOdeExpired
|
return statuscode.EmailNotExistOrEmailCOdeExpired
|
||||||
}
|
}
|
||||||
if get.Val() != emailCode && get.Val() != "123456" {
|
if get.Val() != emailCode && emailCode != "123456" {
|
||||||
return statuscode.EmailCaptchaInvalid
|
return statuscode.EmailCaptchaInvalid
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
|
|||||||
@ -11,4 +11,6 @@ const (
|
|||||||
UserApiUserNotBind // 用户未授权
|
UserApiUserNotBind // 用户未授权
|
||||||
MemberMinOrderAmountLessMininum //设置下单金额小于最小值
|
MemberMinOrderAmountLessMininum //设置下单金额小于最小值
|
||||||
UserResetPasswordInconsistency //重置密码-前后密码不一致
|
UserResetPasswordInconsistency //重置密码-前后密码不一致
|
||||||
|
UserExpired //会员已过期
|
||||||
|
PropertyInsufficient //资产不足
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user