package admin import ( "app/commons/constant" "app/commons/model/entity" "fmt" "github.com/gin-gonic/gin" "github.com/shopspring/decimal" "time" ) func (s *Server) StakeByAdmin(ctx *gin.Context) { c := s.FromContext(ctx) type request struct { UserId int64 `json:"userId"` Quantity decimal.Decimal `json:"quantity"` // 消耗币种的数量 } req := new(request) if err := c.ShouldBindBodyWithJSON(req); err != nil { c.Fail(constant.ErrorParams) return } // 所有 post 接口 必须做 频繁控制 if !c.RepeatFilter(fmt.Sprintf("Buy:%d", c.UserId()), time.Second*3) { c.Fail(constant.ErrorFrequent) return } // tips: 必须做非零限制 if req.Quantity.LessThanOrEqual(decimal.Zero) { c.Fail(constant.ErrorResponseExceedAmountLimit) return } // 检查币种是否支持闪兑 user, err := s.GetUserByUserId(req.UserId) if err != nil { c.Fail(constant.ErrorInfo) return } if !user.Enable { c.Fail(constant.ErrorAccount) return } currentProduct, err := s.FirstStakeProduct(s.DB().Where("pledge_mode", entity.StakeProductTypeCurrent)) if err != nil { c.Fail(constant.ErrorNotOpen) return } if !currentProduct.Enable { c.Fail(constant.ErrorNotOpen) return } // todo: 开始质押 err = s.CurrentStake(user, currentProduct, req.Quantity, c.AdminId()) if err != nil { c.Fail(err.Error()) return } //go s.PledgeStockHandler() // 触发股票业绩处理 与 直推加速释放 c.Resp(nil) }