| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 | 
							- package shanghu
 
- import (
 
- 	orm "duoduo/database"
 
- 	"time"
 
- )
 
- // 用户买卡信息,用于判断用户买卡的上级分销人员,如果没有分销人员默认平台
 
- type MerchantClientCard struct {
 
- 	ID               int64     `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"`        // 主键
 
- 	MerchantCardID   int64     `gorm:"column:merchant_card_id;type:bigint(20)" json:"merchant_card_id"`       // 商户卡id
 
- 	TotalNumber      int       `gorm:"column:total_number;type:int(11)" json:"total_number"`                  // 总次数
 
- 	MerchantCardName string    `gorm:"column:merchant_card_name;type:varchar(255)" json:"merchant_card_name"` // 商户卡名称
 
- 	NumberUse        int       `gorm:"column:number_use;type:int(11)" json:"number_use"`                      // 使用次数
 
- 	ClientInviteCode string    `gorm:"column:client_Invite_code;type:varchar(10)" json:"client_Invite_code"`  // 买卡人邀请码,没邀请码默认使用官方的
 
- 	MerchantCardTime int64     `gorm:"column:merchant_card_time;type:bigint(20)" json:"merchant_card_time"`   // 商户卡有效期
 
- 	OpenID           string    `gorm:"column:open_id;type:varchar(255);NOT NULL" json:"open_id"`              // openid
 
- 	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 *MerchantClientCard) TableName() string {
 
- 	return "merchant_client_card"
 
- }
 
- // list 接口使用
 
- func (m *MerchantClientCard) GetOpenIdList(pageSize int, pageIndex int, listType int) ([]MerchantClientCard, int, error) {
 
- 	var doc []MerchantClientCard
 
- 	timeNow := time.Now().Unix()
 
- 	table := orm.ShMysql.Table(m.TableName())
 
- 	if listType == 1 { //待使用
 
- 		table = table.Where("merchant_card_time > ? and total_number < number_use", timeNow)
 
- 	} else if listType == 2 { //已完成
 
- 		table = table.Where("merchant_card_time > ? or total_number >= number_use", timeNow, timeNow)
 
- 	} else if listType == 3 { //已过期
 
- 		table = table.Where("merchant_card_time < ? and total_number < number_use", timeNow)
 
- 	}
 
- 	//if m.ActivityStartTime != 0
 
- 	table = table.Where("open_id = ? ", m.OpenID)
 
- 	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 *MerchantClientCard) GetMerchantCard() (MerchantClientCard, error) {
 
- 	var doc MerchantClientCard
 
- 	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
 
- }
 
 
  |