merchant.recharge.client.account.log.go 4.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package shanghu
  2. import (
  3. orm "duoduo/database"
  4. "github.com/shopspring/decimal"
  5. "time"
  6. )
  7. type MerchantRechargeClientAccountLog struct {
  8. ID int64 `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"` // 主键
  9. AmountPre decimal.Decimal `gorm:"column:amount_pre;type:decimal(10,2)" json:"amount_pre"` // 交易前
  10. AmountAfter decimal.Decimal `gorm:"column:amount_after;type:decimal(10,2)" json:"amount_after"` // 交易后
  11. TransType int `gorm:"column:trans_type;type:int(11)" json:"trans_type"` // 交易类型 1-充值 2-消费
  12. MerchantOpenID string `gorm:"column:merchant_open_id;type:varchar(255)" json:"merchant_open_id"` // 操作人员
  13. ClientOpenID string `gorm:"column:client_open_id;type:varchar(255)" json:"client_open_id"` // 商户openid
  14. CreateBy int64 `gorm:"column:create_by;type:bigint(20)" json:"create_by"` // 创建者
  15. UpdateBy int64 `gorm:"column:update_by;type:bigint(20)" json:"update_by"` // 更新者
  16. CreatedAt time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` // 创建时间
  17. UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` // 最后更新时间
  18. DeletedAt time.Time `gorm:"column:deleted_at;type:datetime(3);default:null" json:"deleted_at"` // 删除时间
  19. Amount decimal.Decimal `gorm:"column:amount;type:decimal(10,2)" json:"amount"` // 交易金额
  20. PayTransID int64 `gorm:"column:pay_trans_id;type:bigint(20)" json:"pay_trans_id"` // 充值id
  21. Operator string `gorm:"column:operator;type:varchar(255)" json:"operator"` // operator 操作人
  22. }
  23. func (m *MerchantRechargeClientAccountLog) TableName() string {
  24. return "merchant_recharge_client_account_log"
  25. }
  26. func (u *MerchantRechargeClientAccountLog) Create() (MerchantRechargeClientAccountLog, error) {
  27. var doc MerchantRechargeClientAccountLog
  28. var err error
  29. doc = *u
  30. err = orm.ShMysql.Table(u.TableName()).Create(&doc).Error
  31. if err != nil {
  32. return doc, err
  33. }
  34. return doc, nil
  35. }
  36. // list 接口使用
  37. func (m *MerchantRechargeClientAccountLog) MerchantRechargeClientAccountLogList(pageSize int, pageIndex int) ([]MerchantRechargeClientAccountLog, int, error) {
  38. var doc []MerchantRechargeClientAccountLog
  39. table := orm.ShMysql.Table(m.TableName())
  40. table = table.Where("merchant_open_id = ? and trans_type = 1", m.MerchantOpenID)
  41. var count int
  42. if err := table.Select("*").Order("id desc").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
  43. return nil, 0, err
  44. }
  45. table.Count(&count)
  46. return doc, count, nil
  47. }
  48. func (m *MerchantRechargeClientAccountLog) GetMerchantRechargeClientAccountLog() ([]MerchantRechargeClientAccountLog, error) {
  49. var doc []MerchantRechargeClientAccountLog
  50. table := orm.ShMysql.Table(m.TableName())
  51. table = table.Where("merchant_open_id = ? and client_open_id = ? and type = 1 ", m.MerchantOpenID, m.ClientOpenID)
  52. if err := table.Select("merchant_open_id,client_open_id,type,trans_type").Group("merchant_open_id,client_open_id,type,trans_type").Order("id desc").Find(&doc).Error; err != nil {
  53. return nil, err
  54. }
  55. return doc, nil
  56. }
  57. // list 接口使用
  58. func (m *MerchantRechargeClientAccountLog) MerchantRechargeClientAccountLogListByClient(pageSize int, pageIndex int) ([]MerchantRechargeClientAccountLog, int, error) {
  59. var doc []MerchantRechargeClientAccountLog
  60. table := orm.ShMysql.Table(m.TableName())
  61. table = table.Where("client_open_id = ? ", m.ClientOpenID)
  62. var count int
  63. if err := table.Select("*").Order("id desc").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
  64. return nil, 0, err
  65. }
  66. table.Count(&count)
  67. return doc, count, nil
  68. }
  69. // 核销log 接口使用
  70. func (m *MerchantRechargeClientAccountLog) MerchantRechargeAccountLogList(pageSize int, pageIndex int) ([]MerchantRechargeClientAccountLog, int, error) {
  71. var doc []MerchantRechargeClientAccountLog
  72. table := orm.ShMysql.Table(m.TableName())
  73. table = table.Where("merchant_open_id = ? and type = 2 ", m.MerchantOpenID)
  74. var count int
  75. if err := table.Select("*").Order("id desc").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
  76. return nil, 0, err
  77. }
  78. table.Count(&count)
  79. return doc, count, nil
  80. }