merchant.recharge.go 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package shanghu
  2. import (
  3. orm "duoduo/database"
  4. "time"
  5. )
  6. type MerchantRecharge struct {
  7. ID int64 `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"` // Id
  8. MerchantRechargeName string `gorm:"column:merchant_recharge_name;type:varchar(255)" json:"merchant_recharge_name"` // 招商充值名称
  9. Amount string `gorm:"column:amount;type:decimal(10,2)" json:"amount"` // 充值金额
  10. MerchantOpenID string `gorm:"column:merchant_open_id;type:varchar(255)" json:"merchant_open_id"` // Open id
  11. CardProjectData string `gorm:"column:card_project_data;type:json" json:"card_project_data"` // 项目
  12. CreateBy int64 `gorm:"column:create_by;type:bigint(20)" json:"create_by"` // 创建者
  13. UpdateBy int64 `gorm:"column:update_by;type:bigint(20)" json:"update_by"` // 更新者
  14. CreatedAt time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` // 创建时间
  15. UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` // 最后更新时间
  16. DeletedAt time.Time `gorm:"column:deleted_at;type:datetime(3);default:null" json:"deleted_at"` // 删除时间
  17. }
  18. func (m *MerchantRecharge) TableName() string {
  19. return "merchant_recharge"
  20. }
  21. func (u *MerchantRecharge) Create() (MerchantRecharge, error) {
  22. var doc MerchantRecharge
  23. var err error
  24. doc = *u
  25. err = orm.ShMysql.Table(u.TableName()).Create(&doc).Error
  26. if err != nil {
  27. return doc, err
  28. }
  29. return doc, nil
  30. }
  31. func (m *MerchantRecharge) UpdateMerchantRecharge() error {
  32. if err := orm.ShMysql.Table(m.TableName()).Model(&m).Where("id = ? ", m.ID).Updates(
  33. map[string]interface{}{
  34. "merchant_recharge_name": m.MerchantRechargeName,
  35. "merchant_open_id": m.MerchantOpenID,
  36. "card_project_data": m.CardProjectData,
  37. "updated_at": time.Now()}).Error; err != nil {
  38. return err
  39. }
  40. return nil
  41. }
  42. func (m *MerchantRecharge) DelMerchantRecharge() error {
  43. if err := orm.ShMysql.Table(m.TableName()).Model(&m).Where("id = ? and merchant_open_id = ?", m.ID, m.MerchantOpenID).Updates(
  44. map[string]interface{}{
  45. "deleted_at": time.Now()}).Error; err != nil {
  46. return err
  47. }
  48. return nil
  49. }
  50. // list 接口使用
  51. func (m *MerchantRecharge) MerchantRechargeList(pageSize int, pageIndex int) ([]MerchantRecharge, int, error) {
  52. var doc []MerchantRecharge
  53. table := orm.ShMysql.Table(m.TableName())
  54. table = table.Where("merchant_open_id = ? ", m.MerchantOpenID)
  55. var count int
  56. if err := table.Select("*").Order("id desc").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
  57. return nil, 0, err
  58. }
  59. table.Count(&count)
  60. return doc, count, nil
  61. }
  62. func (m *MerchantRecharge) GetMerchantRecharge() (MerchantRecharge, error) {
  63. var doc MerchantRecharge
  64. table := orm.ShMysql.Table(m.TableName())
  65. table = table.Where("id = ? ", m.ID)
  66. if err := table.Select("*").First(&doc).Error; err != nil {
  67. return doc, err
  68. }
  69. return doc, nil
  70. }