merchant.recharge.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. MerchantOpenID string `gorm:"column:merchant_open_id;type:varchar(255)" json:"merchant_open_id"` // Open id
  10. CardProjectData string `gorm:"column:card_project_data;type:json" json:"card_project_data"` // 项目
  11. CreateBy int64 `gorm:"column:create_by;type:bigint(20)" json:"create_by"` // 创建者
  12. UpdateBy int64 `gorm:"column:update_by;type:bigint(20)" json:"update_by"` // 更新者
  13. CreatedAt time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` // 创建时间
  14. UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` // 最后更新时间
  15. DeletedAt time.Time `gorm:"column:deleted_at;type:datetime(3);default:null" json:"deleted_at"` // 删除时间
  16. }
  17. func (m *MerchantRecharge) TableName() string {
  18. return "merchant_recharge"
  19. }
  20. func (u *MerchantRecharge) Create() (MerchantRecharge, error) {
  21. var doc MerchantRecharge
  22. var err error
  23. doc = *u
  24. err = orm.ShMysql.Table(u.TableName()).Create(&doc).Error
  25. if err != nil {
  26. return doc, err
  27. }
  28. return doc, nil
  29. }
  30. func (m *MerchantRecharge) UpdateMerchantRecharge() error {
  31. if err := orm.ShMysql.Table(m.TableName()).Model(&m).Where("id = ? ", m.ID).Updates(
  32. map[string]interface{}{
  33. "merchant_recharge_name": m.MerchantRechargeName,
  34. "merchant_open_id": m.MerchantOpenID,
  35. "card_project_data": m.CardProjectData,
  36. "updated_at": time.Now()}).Error; err != nil {
  37. return err
  38. }
  39. return nil
  40. }
  41. func (m *MerchantRecharge) DelMerchantRecharge() error {
  42. if err := orm.ShMysql.Table(m.TableName()).Model(&m).Where("id = ? ", m.ID).Updates(
  43. map[string]interface{}{
  44. "deleted_at": time.Now()}).Error; err != nil {
  45. return err
  46. }
  47. return nil
  48. }
  49. // list 接口使用
  50. func (m *MerchantRecharge) MerchantRechargeList(pageSize int, pageIndex int) ([]MerchantRecharge, int, error) {
  51. var doc []MerchantRecharge
  52. table := orm.ShMysql.Table(m.TableName())
  53. table = table.Where("merchant_open_id = ? ", m.MerchantOpenID)
  54. var count int
  55. if err := table.Select("*").Order("id desc").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
  56. return nil, 0, err
  57. }
  58. table.Count(&count)
  59. return doc, count, nil
  60. }