| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 | 
							- package shanghu
 
- import (
 
- 	orm "duoduo/database"
 
- 	"duoduo/tools"
 
- 	"time"
 
- )
 
- type MerchantCard struct {
 
- 	ID                int64     `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"`
 
- 	MerchantCardName  string    `gorm:"column:merchant_card_name;type:varchar(255)" json:"merchant_card_name"`      // 商户卡名称
 
- 	MerchantOpenID    string    `gorm:"column:merchant_open_id;type:varchar(255);NOT NULL" json:"merchant_open_id"` // openid
 
- 	CardProjectData   string    `gorm:"column:card_project_data;type:json" json:"card_project_data"`                // 项目
 
- 	CardPrice         string    `gorm:"column:card_price;type:decimal(10,2)" json:"card_price"`                     // 单价
 
- 	ActivityEndTime   int64     `gorm:"column:activity_end_time;type:bigint(20)" json:"activity_end_time"`          // 活动结束时间
 
- 	ActivityStartTime int64     `gorm:"column:activity_start_time;type:bigint(20)" json:"activity_start_time"`      // 活动开始时间
 
- 	MerchantCardTime  int64     `gorm:"column:merchant_card_time;type:bigint(20)" json:"merchant_card_time"`        // 商户卡有效期
 
- 	Inventory         int64     `gorm:"column:inventory;type:bigint(20)" json:"inventory"`                          // 库存数量
 
- 	QuotaNum          int64     `gorm:"column:quota_num;type:int(11)" json:"quota_num"`                             // 限购数量
 
- 	UseRule           string    `gorm:"column:use_rule;type:varchar(255)" json:"use_rule"`                          // 使用规则
 
- 	Picture           string    `gorm:"column:picture;type:varchar(255)" json:"picture"`                            // 图片
 
- 	RebateRate        int64     `gorm:"column:rebate_rate;type:int(11)" json:"rebate_rate"`                         // 佣金比例
 
- 	CancelNumber      int       `gorm:"column:cancel_number;type:int(11)" json:"cancel_number"`                     //
 
- 	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"`          // 删除时间
 
- 	BackgroundImage   string    `gorm:"column:background_image;type:varchar(255)" json:"background_image"`          //背景图
 
- 	W                 string    `gorm:"column:w;type:varchar(255);default:null" json:"w"`                           // w
 
- 	H                 string    `gorm:"column:h;type:varchar(255);default:null" json:"h"`                           // h
 
- 	X                 string    `gorm:"column:x;type:varchar(255);default:null" json:"x"`                           // x
 
- 	Y                 string    `gorm:"column:y;type:varchar(255);default:null" json:"y"`                           // y
 
- 	CardTotalPrice    string    `gorm:"column:card_total_price;type:decimal(10,2)" json:"card_total_price"`         // 总价
 
- }
 
- func (m *MerchantCard) TableName() string {
 
- 	return "merchant_card"
 
- }
 
- func (u *MerchantCard) Create() (MerchantCard, error) {
 
- 	var doc MerchantCard
 
- 	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 *MerchantCard) GetMerchantCard() (MerchantCard, error) {
 
- 	var doc MerchantCard
 
- 	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
 
- }
 
- // list 接口使用
 
- func (m *MerchantCard) GetOpenIdList(pageSize int, pageIndex int, listType int) ([]MerchantCard, int, error) {
 
- 	var doc []MerchantCard
 
- 	timeNow := time.Now().Unix()
 
- 	table := orm.ShMysql.Table(m.TableName())
 
- 	if listType == 1 { //待开始
 
- 		table = table.Where("activity_start_time > ?", timeNow)
 
- 	} else if listType == 2 { //进行中
 
- 		table = table.Where("activity_start_time < ? and activity_end_time > ?", timeNow, timeNow)
 
- 	} else if listType == 3 { //已结束
 
- 		table = table.Where("activity_end_time < ?", timeNow)
 
- 	}
 
- 	//if m.ActivityStartTime != 0
 
- 	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
 
- }
 
- // list 接口使用
 
- func (m *MerchantCard) GetMerchantByOpenId() ([]MerchantCard, error) {
 
- 	var doc []MerchantCard
 
- 	table := orm.ShMysql.Table(m.TableName())
 
- 	table = table.Where("merchant_open_id = ?  ", m.MerchantOpenID)
 
- 	err := table.Select("id,merchant_card_name,merchant_card_time,rebate_rate").Find(&doc).Error
 
- 	if err != nil {
 
- 		return nil, err
 
- 	}
 
- 	return doc, nil
 
- }
 
- // list 接口使用
 
- func (m *MerchantCard) ClientGetOpenIdList(pageSize int, pageIndex int, listType int) ([]MerchantCard, int, error) {
 
- 	var doc []MerchantCard
 
- 	timeNow := time.Now().Unix()
 
- 	table := orm.ShMysql.Table(m.TableName())
 
- 	if listType == 1 { //待开始
 
- 		table = table.Where("activity_start_time > ?", timeNow)
 
- 	} else if listType == 2 { //进行中
 
- 		table = table.Where("activity_start_time < ? and activity_end_time > ?", timeNow, timeNow)
 
- 	} else if listType == 3 { //已结束
 
- 		table = table.Where("activity_end_time < ?", timeNow)
 
- 	}
 
- 	//if m.ActivityStartTime != 0
 
- 	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 *MerchantCard) UpdateMerchantCard() error {
 
- 	if err := orm.ShMysql.Table(m.TableName()).Model(&m).Where("id = ? ", m.ID).Updates(
 
- 		map[string]interface{}{
 
- 			"project_name":        m.ActivityEndTime,
 
- 			"activity_start_time": m.ActivityStartTime,
 
- 			"inventory":           m.Inventory,
 
- 			"quota_num":           m.QuotaNum,
 
- 			"use_rule":            m.UseRule,
 
- 			"picture":             m.Picture,
 
- 			"updated_at":          tools.GetCurrntTimeStr()}).Error; err != nil {
 
- 		return err
 
- 	}
 
- 	return nil
 
- }
 
- func (m *MerchantCard) UpdateMerchantWHXY() error {
 
- 	if err := orm.ShMysql.Table(m.TableName()).Model(&m).Where("id = ? ", m.ID).Updates(
 
- 		map[string]interface{}{
 
- 			"w":          m.W,
 
- 			"h":          m.H,
 
- 			"x":          m.X,
 
- 			"y":          m.Y,
 
- 			"updated_at": tools.GetCurrntTimeStr()}).Error; err != nil {
 
- 		return err
 
- 	}
 
- 	return nil
 
- }
 
 
  |