diamond.go 948 B

123456789101112131415161718192021222324252627282930313233343536
  1. package api
  2. import (
  3. "cockData/server/pkg"
  4. "cockData/server/sql"
  5. "github.com/gin-gonic/gin"
  6. )
  7. type DiamondParams struct {
  8. Diamond int64 `binding:"required"`
  9. Reason string `binding:"required"`
  10. }
  11. type DiamondResults struct {
  12. CurDiamond int64 `json:"cur_diamond"`
  13. CreateTime string `json:"create_time"`
  14. }
  15. func changeDiamond(context *gin.Context) {
  16. var params DiamondParams
  17. userID, err := CheckParamsAndOpenId(context, &params)
  18. if err != nil {
  19. return
  20. }
  21. curDiamond, err := sql.ChangeDiamond(userID, params.Diamond, params.Reason)
  22. ResponseApiWithError(context, CreateSuccessResponse(DiamondResults{CurDiamond: curDiamond}), err)
  23. }
  24. func getDiamond(context *gin.Context) {
  25. userID, err := GetOpenId(context)
  26. if err != nil {
  27. return
  28. }
  29. createAt, curDiamond, err := sql.GetUserInfo(userID)
  30. ResponseApiWithError(context, CreateSuccessResponse(DiamondResults{CreateTime: pkg.GetFormatTime(createAt), CurDiamond: curDiamond}), err)
  31. }