change_history.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package model
  2. import (
  3. "strconv"
  4. "time"
  5. "go-common/library/log"
  6. xtime "go-common/library/time"
  7. )
  8. // UserChangeHistory 会员变动流水.
  9. type UserChangeHistory struct {
  10. ID int32 `json:"id"` // vip开通历史
  11. Mid int64 `json:"mid"` // 用户mid
  12. ChangeType int8 `json:"change_type"` // 变更类型(1:充值开通 2:系统发放 3:活动赠送 4:重复领取扣除)
  13. ChangeTime xtime.Time `json:"change_time"` // 变更时间
  14. OrderNo string `json:"order_no"` // 关联订单号
  15. Days int32 `json:"days"` // 开通天数
  16. OperatorId string `json:"operator_id"` // 操作人id
  17. Remark string `json:"remark"` // 备注
  18. Ctime xtime.Time `json:"ctime"` // 创建时间
  19. Mtime xtime.Time `json:"mtime"` // 修改时间
  20. }
  21. func (uc *UserChangeHistory) orderType2ChangeType(orderType int8) int8 {
  22. var ct int8
  23. switch orderType {
  24. case PayOrderTypeNormal:
  25. ct = UserChangeTypeRecharge
  26. case PayOrderTypeSub:
  27. ct = UserChangeTypeSystem
  28. default:
  29. log.Error("uc.CopyFromPayOrder() err(UnknownOrderType) orderType(%d)", orderType)
  30. ct = UserChangeTypeRecharge
  31. }
  32. return ct
  33. }
  34. // CopyFromPayOrder copies fields from pay order.
  35. func (uc *UserChangeHistory) CopyFromPayOrder(po *PayOrder) {
  36. uc.Mid = po.Mid
  37. uc.OrderNo = po.OrderNo
  38. uc.Days = int32(po.BuyMonths) * 31
  39. uc.OperatorId = strconv.Itoa(int(po.Mid))
  40. uc.ChangeTime = xtime.Time(time.Now().Unix())
  41. uc.ChangeType = uc.orderType2ChangeType(po.OrderType)
  42. }