| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 | 
							- package shanghu
 
- import (
 
- 	orm "duoduo/database"
 
- 	"time"
 
- )
 
- type Merchant struct {
 
- 	ID                 int64     `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"`            
 
- 	OpenId             string    `gorm:"column:open_id;type:varchar(255)" json:"open_id"`                           
 
- 	MerchantName       string    `gorm:"column:merchant_name;type:varchar(255)" json:"merchant_name"`               
 
- 	Industry           string    `gorm:"column:industry;type:varchar(50)" json:"industry"`                          
 
- 	IndustryCategory   string    `gorm:"column:industry_category;type:varchar(50)" json:"industry_category"`        
 
- 	Contacts           string    `gorm:"column:contacts;type:varchar(50)" json:"contacts"`                          
 
- 	BusinessHours      string    `gorm:"column:business_hours;type:varchar(100)" json:"business_hours"`             
 
- 	Consumption        string    `gorm:"column:consumption;type:varchar(50)" json:"consumption"`                    
 
- 	Iphone             string    `gorm:"column:iphone;type:varchar(20)" json:"iphone"`                              
 
- 	Area               string    `gorm:"column:area;type:varchar(50)" json:"area"`                                  
 
- 	Address            string    `gorm:"column:address;type:varchar(100)" json:"address"`                           
 
- 	NumberPlate        string    `gorm:"column:number_plate;type:varchar(50)" json:"number_plate"`                  
 
- 	BusinessLicenseUrl string    `gorm:"column:business_license_url;type:varchar(255)" json:"business_license_url"` 
 
- 	DoorHeaderUrl      string    `gorm:"column:door_header_url;type:varchar(255)" json:"door_header_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"`         
 
- }
 
- func (m *Merchant) TableName() string {
 
- 	return "merchant"
 
- }
 
- func (u *Merchant) Create() (Merchant, error) {
 
- 	var doc Merchant
 
- 	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 *Merchant) GetMerchant() (Merchant, error) {
 
- 	var doc Merchant
 
- 	table := orm.ShMysql.Table(m.TableName())
 
- 	table = table.Where("open_id = ?  ", m.OpenId)
 
- 	if err := table.Select("*").First(&doc).Error; err != nil {
 
- 		return doc, err
 
- 	}
 
- 	return doc, nil
 
- }
 
- func (m *Merchant) GetOpenIdList(pageSize int, pageIndex int) ([]Merchant, int, error) {
 
- 	var doc []Merchant
 
- 	table := orm.ShMysql.Table(m.TableName())
 
- 	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 *Merchant) UpdateMerchant() error {
 
- 	if err := orm.ShMysql.Table(m.TableName()).Model(&m).Where("id = ? ", m.ID).Updates(
 
- 		map[string]interface{}{
 
- 			"merchant_name":        m.MerchantName,
 
- 			"industry":             m.Industry,
 
- 			"industry_category":    m.IndustryCategory,
 
- 			"contacts":             m.Contacts,
 
- 			"business_hours":       m.BusinessHours,
 
- 			"consumption":          m.Consumption,
 
- 			"iphone":               m.Iphone,
 
- 			"area":                 m.Area,
 
- 			"address":              m.Address,
 
- 			"number_plate":         m.NumberPlate,
 
- 			"business_license_url": m.BusinessLicenseUrl,
 
- 			"door_header_url":      m.DoorHeaderUrl}).Error; err != nil {
 
- 		return err
 
- 	}
 
- 	return nil
 
- }
 
 
  |