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"` // 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"` // 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
- }
- // list 接口使用
- 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
- }
|