| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- package shanghu
- import (
- orm "duoduo/database"
- "time"
- )
- type MerchantRecharge struct {
- ID int64 `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"`
- MerchantRechargeName string `gorm:"column:merchant_recharge_name;type:varchar(255)" json:"merchant_recharge_name"`
- Amount string `gorm:"column:amount;type:decimal(10,2)" json:"amount"`
- MerchantOpenID string `gorm:"column:merchant_open_id;type:varchar(255)" json:"merchant_open_id"`
- CardProjectData string `gorm:"column:card_project_data;type:json" json:"card_project_data"`
- CreateBy int64 `gorm:"column:create_by;type:bigint(20)" json:"create_by"`
- UpdateBy int64 `gorm:"column:update_by;type:bigint(20)" json:"update_by"`
- CreatedAt time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"`
- UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"`
- DeletedAt time.Time `gorm:"column:deleted_at;type:datetime(3);default:null" json:"deleted_at"`
- }
- func (m *MerchantRecharge) TableName() string {
- return "merchant_recharge"
- }
- func (u *MerchantRecharge) Create() (MerchantRecharge, error) {
- var doc MerchantRecharge
- var err error
- doc = *u
- err = orm.ShMysql.Table(u.TableName()).Create(&doc).Error
- if err != nil {
- return doc, err
- }
- return doc, nil
- }
- func (m *MerchantRecharge) UpdateMerchantRecharge() error {
- if err := orm.ShMysql.Table(m.TableName()).Model(&m).Where("id = ? ", m.ID).Updates(
- map[string]interface{}{
- "merchant_recharge_name": m.MerchantRechargeName,
- "merchant_open_id": m.MerchantOpenID,
- "card_project_data": m.CardProjectData,
- "updated_at": time.Now()}).Error; err != nil {
- return err
- }
- return nil
- }
- func (m *MerchantRecharge) DelMerchantRecharge() error {
- if err := orm.ShMysql.Table(m.TableName()).Model(&m).Where("id = ? and merchant_open_id = ?", m.ID, m.MerchantOpenID).Updates(
- map[string]interface{}{
- "deleted_at": time.Now()}).Error; err != nil {
- return err
- }
- return nil
- }
- func (m *MerchantRecharge) MerchantRechargeList(pageSize int, pageIndex int) ([]MerchantRecharge, int, error) {
- var doc []MerchantRecharge
- table := orm.ShMysql.Table(m.TableName())
- table = table.Where("merchant_open_id = ? ", m.MerchantOpenID)
- var count int
- if err := table.Select("*").Order("id desc").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
- return nil, 0, err
- }
- table.Count(&count)
- return doc, count, nil
- }
- func (m *MerchantRecharge) GetMerchantRecharge() (MerchantRecharge, error) {
- var doc MerchantRecharge
- table := orm.ShMysql.Table(m.TableName())
- table = table.Where("id = ? ", m.ID)
- if err := table.Select("*").First(&doc).Error; err != nil {
- return doc, err
- }
- return doc, nil
- }
|