| | |
| | | |
| | | type ( |
| | | Contact struct { |
| | | Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` |
| | | Name string `json:"name" gorm:"column:name;type:varchar(255);comment:联系人姓名"` |
| | | Number string `json:"number" gorm:"column:number;type:varchar(255);comment:联系人编号"` |
| | | ClientId int `json:"client_id" gorm:"column:client_id;type:int(11);comment:客户ID"` |
| | | Position string `json:"position" gorm:"column:position;type:varchar(255);comment:职位"` |
| | | Phone string `json:"phone" gorm:"column:phone;type:varchar(255);comment:电话"` |
| | | MemberId int `json:"member_id" gorm:"column:member_id;type:int(11);comment:负责人ID"` |
| | | IsFirst bool `json:"is_first" gorm:"column:is_first;type:tinyint(1);comment:是否首要联系人"` |
| | | Wechat string `json:"wechat" gorm:"column:wechat;type:varchar(255);comment:微信"` |
| | | Birthday time.Time `json:"birthday" gorm:"column:birthday;type:datetime;comment:生日"` |
| | | Email string `json:"email" gorm:"column:email;type:varchar(255);comment:邮箱"` |
| | | Desc string `json:"desc" gorm:"column:desc;type:varchar(255);comment:备注"` |
| | | Client Client |
| | | FollowRecord []FollowRecord `gorm:"foreignKey:ContactId"` |
| | | Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` |
| | | Name string `json:"name" gorm:"column:name;type:varchar(255);comment:联系人姓名"` |
| | | Number string `json:"number" gorm:"column:number;type:varchar(255);comment:联系人编号"` |
| | | ClientId int `json:"client_id" gorm:"column:client_id;type:int(11);comment:客户ID"` |
| | | Position string `json:"position" gorm:"column:position;type:varchar(255);comment:职位"` |
| | | Phone string `json:"phone" gorm:"column:phone;type:varchar(255);comment:电话"` |
| | | MemberId int `json:"member_id" gorm:"column:member_id;type:int(11);comment:负责人ID"` |
| | | IsFirst bool `json:"is_first" gorm:"column:is_first;type:tinyint(1);comment:是否首要联系人"` |
| | | Wechat string `json:"wechat" gorm:"column:wechat;type:varchar(255);comment:微信"` |
| | | Birthday time.Time `json:"birthday" gorm:"column:birthday;type:datetime;comment:生日"` |
| | | Email string `json:"email" gorm:"column:email;type:varchar(255);comment:邮箱"` |
| | | Desc string `json:"desc" gorm:"column:desc;type:varchar(255);comment:备注"` |
| | | Address |
| | | gorm.Model `json:"-"` |
| | | } |
| | |
| | | Contact |
| | | Orm *gorm.DB |
| | | } |
| | | |
| | | ContactDetail struct { |
| | | Contact |
| | | Client Client |
| | | FollowRecord []FollowRecord `gorm:"foreignKey:ContactId"` |
| | | } |
| | | ) |
| | | |
| | | func (Contact) TableName() string { |
| | | return "contacts" |
| | | } |
| | | |
| | | func NewContactSearch() *ContactSearch { |
| | | func NewContactSearch(db *gorm.DB) *ContactSearch { |
| | | if db == nil { |
| | | db = mysqlx.GetDB() |
| | | } |
| | | return &ContactSearch{ |
| | | Orm: mysqlx.GetDB(), |
| | | Orm: db, |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | func (slf *ContactSearch) Update(record *Contact) error { |
| | | var db = slf.build() |
| | | return db.Updates(record).Error |
| | | m := map[string]interface{}{ |
| | | "name": record.Name, |
| | | "number": record.Number, |
| | | "client_id": record.ClientId, |
| | | "position": record.Position, |
| | | "phone": record.Phone, |
| | | "member_id": record.MemberId, |
| | | "is_first": record.IsFirst, |
| | | "wechat": record.Wechat, |
| | | "birthday": record.Birthday, |
| | | "email": record.Email, |
| | | "desc": record.Desc, |
| | | "country_id": record.CountryId, |
| | | "province_id": record.ProvinceId, |
| | | "city_id": record.CityId, |
| | | "region_id": record.RegionId, |
| | | } |
| | | return db.Updates(m).Error |
| | | } |
| | | |
| | | func (slf *ContactSearch) Delete() error { |
| | |
| | | return record, err |
| | | } |
| | | |
| | | func (slf *ContactSearch) FindAll() ([]*Contact, error) { |
| | | func (slf *ContactSearch) FindAll() ([]*ContactDetail, error) { |
| | | var db = slf.build() |
| | | var records = make([]*Contact, 0) |
| | | var records = make([]*ContactDetail, 0) |
| | | err := db.Preload("FollowRecord").Preload("Client").Preload("Country").Preload("Province").Preload("City").Preload("Region").Find(&records).Error |
| | | return records, err |
| | | } |