You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

reward_operate_record.go 2.3 kB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package models
  2. import (
  3. "code.gitea.io/gitea/modules/timeutil"
  4. "fmt"
  5. )
  6. type RewardSourceType string
  7. const (
  8. SourceTypeAccomplishTask RewardSourceType = "ACCOMPLISH_TASK"
  9. SourceTypeAdminOperate RewardSourceType = "ADMIN_OPERATE"
  10. SourceTypeRunCloudbrainTask RewardSourceType = "RUN_CLOUBRAIN_TASK"
  11. )
  12. func (r *RewardSourceType) String() string {
  13. return fmt.Sprint(r)
  14. }
  15. type RewardType string
  16. const (
  17. RewardTypePoint RewardType = "POINT"
  18. )
  19. func (r *RewardType) String() string {
  20. return fmt.Sprint(r)
  21. }
  22. const (
  23. OperateTypeIncrease = "INCREASE_POINT"
  24. OperateTypeDecrease = "DECREASE_POINT"
  25. )
  26. const (
  27. OperateStatusOperating = "OPERATING"
  28. OperateStatusSucceeded = "SUCCEEDED"
  29. OperateStatusFailed = "FAILED"
  30. )
  31. type RewardOperateRecord struct {
  32. ID int64 `xorm:"pk autoincr"`
  33. UserId int64 `xorm:"INDEX NOT NULL"`
  34. Amount int64 `xorm:"NOT NULL"`
  35. RewardType string `xorm:"NOT NULL"`
  36. SourceType string `xorm:"NOT NULL"`
  37. SourceId string `xorm:"INDEX NOT NULL"`
  38. RequestId string `xorm:"INDEX NOT NULL"`
  39. OperateType string `xorm:"NOT NULL"`
  40. CycleIntervalSeconds int64 `xorm:"NOT NULL default 0"`
  41. Status string `xorm:"NOT NULL"`
  42. Remark string
  43. CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
  44. UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
  45. }
  46. func getPointOperateRecord(tl *RewardOperateRecord) (*RewardOperateRecord, error) {
  47. has, err := x.Get(tl)
  48. if err != nil {
  49. return nil, err
  50. } else if !has {
  51. return nil, ErrRecordNotExist{}
  52. }
  53. return tl, nil
  54. }
  55. func GetPointOperateRecordBySourceTypeAndRequestId(sourceType, requestId string) (*RewardOperateRecord, error) {
  56. t := &RewardOperateRecord{
  57. SourceType: sourceType,
  58. RequestId: requestId,
  59. }
  60. return getPointOperateRecord(t)
  61. }
  62. func InsertAwardOperateRecord(tl *RewardOperateRecord) (int64, error) {
  63. return x.Insert(tl)
  64. }
  65. func UpdateAwardOperateRecordStatus(sourceType, requestId, oldStatus, newStatus string) (int64, error) {
  66. r := &RewardOperateRecord{
  67. Status: newStatus,
  68. }
  69. return x.Cols("status").Where("source_type=? and requestId=? and status=?", sourceType, requestId, oldStatus).Update(r)
  70. }