package shanghu import ( orm "duoduo/database" "errors" "github.com/shopspring/decimal" "time" ) type MerchantActiveGroupBuy struct { ID int64 `gorm:"column:id;type:bigint(20);primary_key" json:"id"` ActiveConfigID int64 `gorm:"column:active_config_id;type:bigint(20)" json:"active_config_id"` // 关联活动 GroupBuyName string `gorm:"column:group_buy_name;type:varchar(255)" json:"group_buy_name"` // 拼团名 GroupBuyMode int `gorm:"column:group_buy_mode;type:int(11)" json:"group_buy_mode"` // 拼团模式 1-真实拼团 2-虚拟拼团 MerchantOpenID string `gorm:"column:merchant_open_id;type:varchar(255)" json:"merchant_open_id"` OriginalPrice decimal.Decimal `gorm:"column:original_price;type:decimal(10,2)" json:"original_price"` // 原价 GroupBuyOneNum int `gorm:"column:group_buy_one_num;type:int(11)" json:"group_buy_one_num"` // 人数 GroupBuyOnePrice decimal.Decimal `gorm:"column:group_buy_one_price;type:decimal(10,2)" json:"group_buy_one_price"` // 价格 GroupBuyTwoNum int `gorm:"column:group_buy_two_num;type:int(11)" json:"group_buy_two_num"` // 人数 GroupBuyTwoPrice decimal.Decimal `gorm:"column:group_buy_two_price;type:decimal(10,2)" json:"group_buy_two_price"` // 价格 GroupBuyThreeNum int `gorm:"column:group_buy_three_num;type:int(11)" json:"group_buy_three_num"` GroupBuyThreePrice decimal.Decimal `gorm:"column:group_buy_three_price;type:decimal(10,2)" json:"group_buy_three_price"` GroupBuyFourNum int `gorm:"column:group_buy_four_num;type:int(11)" json:"group_buy_four_num"` GroupBuyFourPrice decimal.Decimal `gorm:"column:group_buy_four_price;type:decimal(10,2)" json:"group_buy_four_price"` GroupBuyUrl string `gorm:"column:group_buy_url;type:varchar(255)" json:"group_buy_url"` // 图片 GroupBuyBigUrl string `gorm:"column:group_buy_big_url;type:varchar(255)" json:"group_buy_big_url"` // 大图 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"` // 删除时间 RebateRate int `gorm:"column:rebate_rate;type:int(11)" json:"rebate_rate"` // 佣金比例 } func (m *MerchantActiveGroupBuy) TableName() string { return "merchant_active_group_buy" } func (u *MerchantActiveGroupBuy) Create() (MerchantActiveGroupBuy, error) { var doc MerchantActiveGroupBuy var err error doc = *u err = orm.ShMysql.Table(u.TableName()).Create(&doc).Error if err != nil { return doc, err } return doc, nil } func (u *MerchantActiveGroupBuy) UpdateConfigId(groupBuyId int64) error { res := orm.ShMysql.Table(u.TableName()).Where("id = ? and active_config_id = 0", groupBuyId).Updates( map[string]interface{}{ "active_config_id": u.ActiveConfigID, "updated_at": time.Now(), }) if res.Error != nil { return res.Error } if res.RowsAffected <= 0 { return errors.New("未更新数据") } return nil } // 中奖商品列表 func (m *MerchantActiveGroupBuy) GetGroupBuyList() ([]MerchantActiveGroupBuy, int, error) { var doc []MerchantActiveGroupBuy table := orm.ShMysql.Table(m.TableName()) table = table.Where("active_config_id = ? ", m.ActiveConfigID) var count int if err := table.Select("*").Order("id desc").Find(&doc).Error; err != nil { return nil, 0, err } table.Count(&count) return doc, count, nil } func (m *MerchantActiveGroupBuy) GetGroupBuyListByOpenId(pageSize int, pageIndex int) ([]MerchantActiveGroupBuy, int, error) { var doc []MerchantActiveGroupBuy table := orm.ShMysql.Table(m.TableName()) table = table.Where("merchant_open_id = ? and active_config_id = 0", 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 }