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.5 kB

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