zhangqian
2023-08-05 1d8f07d32634854a07379479a760ba387a53314c
model/saleChance.go
@@ -1,7 +1,6 @@
package model
import (
   "aps_crm/constvar"
   "aps_crm/pkg/mysqlx"
   "gorm.io/gorm"
   "time"
@@ -9,44 +8,51 @@
type (
   SaleChance 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:销售线索编号"`
      ContactId          int                   `json:"contact_id" gorm:"column:contact_id;type:int(11);comment:联系人ID"`
      ClientId           int                   `json:"client_id" gorm:"column:client_id;type:int(11);comment:客户ID"`
      SalesSourcesId     int                   `json:"sales_sources_id" gorm:"column:sales_sources_id;type:int(11);comment:商机来源ID"`
      SaleTypeId         int                   `json:"sale_type_id" gorm:"column:sale_type_id;type:int(11);comment:商机类型ID"`
      SaleStageId        int                   `json:"sale_stage_id" gorm:"column:sale_stage_id;type:int(11);comment:商机阶段ID"`
      MemberId           int                   `json:"member_id" gorm:"column:member_id;type:int(11);comment:销售负责人ID"`
      RegularCustomersId int                   `json:"regular_customers_id" gorm:"column:regular_customers_id;type:int(11);comment:常客ID"`
      Competitors        string                `json:"competitors" gorm:"column:competitors;type:varchar(255);comment:竞争对手"`
      Possibilities      int                   `json:"possibilities" gorm:"column:possibilities;type:int(11);comment:可能性"`
      Budget             float64               `json:"budget" gorm:"column:budget;type:decimal(10,2);comment:预算"`
      ProjectedAmount    float64               `json:"projected_amount" gorm:"column:projected_amount;type:decimal(10,2);comment:预计金额"`
      Currency           constvar.CurrencyType `json:"currency" gorm:"column:currency;type:int(11);comment:货币类型"`
      ExpectedTime       time.Time             `json:"expected_time" gorm:"column:expected_time;type:datetime;comment:预计成交时间"`
      StatusId           int                   `json:"status_id" gorm:"column:status_id;type:int(11);comment:状态ID"`
      PainPoints         string                `json:"pain_points" gorm:"column:pain_points;type:text;comment:痛点"`
      WhetherEstablished string                `json:"whether_established" gorm:"column:whether_established;type:text;comment:是否成立"`
      CapitalBudget      string                `json:"capital_budget" gorm:"column:capital_budget;type:text;comment:资金预算"`
      KeyMaker           string                `json:"key_maker" gorm:"column:key_maker;type:text;comment:关键人"`
      KeyFactors         string                `json:"key_factors" gorm:"column:key_factors;type:text;comment:关键因素"`
      Process            string                `json:"process" gorm:"column:process;type:text;comment:决策流程"`
      Solutions          string                `json:"solutions" gorm:"column:solutions;type:text;comment:竞争对手解决方案"`
      Advantages         string                `json:"advantages" gorm:"column:advantages;type:text;comment:竞争优势"`
      Disadvantages      string                `json:"disadvantages" gorm:"column:disadvantages;type:text;comment:竞争劣势"`
      Opportunities      string                `json:"opportunities" gorm:"column:opportunities;type:text;comment:竞争机会"`
      Threats            string                `json:"threats" gorm:"column:threats;type:text;comment:竞争威胁"`
      Contact            Contact               `json:"contact" gorm:"foreignKey:ContactId;references:Id"`
      Client             Client                `json:"client" gorm:"foreignKey:ClientId;references:Id"`
      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:销售线索编号"`
      ContactId          int       `json:"contact_id" gorm:"column:contact_id;type:int(11);comment:联系人ID"`
      ClientId           int       `json:"client_id" gorm:"column:client_id;type:int(11);comment:客户ID"`
      SalesSourcesId     int       `json:"sales_sources_id" gorm:"column:sales_sources_id;type:int(11);comment:商机来源ID"`
      SaleTypeId         int       `json:"sale_type_id" gorm:"column:sale_type_id;type:int(11);comment:商机类型ID"`
      SaleStageId        int       `json:"sale_stage_id" gorm:"column:sale_stage_id;type:int(11);comment:商机阶段ID"`
      MemberId           int       `json:"member_id" gorm:"column:member_id;type:int(11);comment:销售负责人ID"`
      RegularCustomersId int       `json:"regular_customers_id" gorm:"column:regular_customers_id;type:int(11);comment:常客ID"`
      Competitors        string    `json:"competitors" gorm:"column:competitors;type:varchar(255);comment:竞争对手"`
      PossibilitiesId    int       `json:"possibilities_id" gorm:"column:possibilities_id;type:int(11);comment:可能性ID"`
      Budget             float64   `json:"budget" gorm:"column:budget;type:decimal(10,2);comment:预算"`
      ProjectedAmount    float64   `json:"projected_amount" gorm:"column:projected_amount;type:decimal(10,2);comment:预计金额"`
      Currency           int       `json:"currency" gorm:"column:currency;type:int(11);comment:币种"`
      ExpectedTime       time.Time `json:"expected_time" gorm:"column:expected_time;type:datetime;comment:预计成交时间"`
      StatusId           int       `json:"status_id" gorm:"column:status_id;type:int(11);comment:状态ID"`
      PainPoints         string    `json:"pain_points" gorm:"column:pain_points;type:text;comment:痛点"`
      WhetherEstablished string    `json:"whether_established" gorm:"column:whether_established;type:text;comment:是否成立"`
      CapitalBudget      string    `json:"capital_budget" gorm:"column:capital_budget;type:text;comment:资金预算"`
      KeyMaker           string    `json:"key_maker" gorm:"column:key_maker;type:text;comment:关键人"`
      KeyFactors         string    `json:"key_factors" gorm:"column:key_factors;type:text;comment:关键因素"`
      Process            string    `json:"process" gorm:"column:process;type:text;comment:决策流程"`
      Solutions          string    `json:"solutions" gorm:"column:solutions;type:text;comment:竞争对手解决方案"`
      Advantages         string    `json:"advantages" gorm:"column:advantages;type:text;comment:竞争优势"`
      Disadvantages      string    `json:"disadvantages" gorm:"column:disadvantages;type:text;comment:竞争劣势"`
      Opportunities      string    `json:"opportunities" gorm:"column:opportunities;type:text;comment:竞争机会"`
      Threats            string    `json:"threats" gorm:"column:threats;type:text;comment:竞争威胁"`
      DetailAddress      string    `json:"detail_address" gorm:"column:detail_address;type:text;comment:详细地址"`
      Remark             string    `json:"remark" gorm:"column:remark;type:text;comment:备注"`
      Contact            Contact   `json:"contact" gorm:"foreignKey:ContactId;references:Id"`
      Client             Client    `json:"client" gorm:"foreignKey:ClientId;references:Id"`
      SalesSources       SalesSources
      Address
      gorm.Model `json:"-"`
   }
   SaleChangeSearch struct {
   SaleChanceSearch struct {
      SaleChance
      Orm *gorm.DB
      Orm      *gorm.DB
      Keyword  string
      OrderBy  string
      PageNum  int
      PageSize int
   }
)
@@ -54,12 +60,15 @@
   return "sale_chance"
}
func NewSaleChangeSearch() *SaleChangeSearch {
   return &SaleChangeSearch{Orm: mysqlx.GetDB()}
func NewSaleChanceSearch() *SaleChanceSearch {
   return &SaleChanceSearch{Orm: mysqlx.GetDB()}
}
func (slf *SaleChangeSearch) build() *gorm.DB {
func (slf *SaleChanceSearch) build() *gorm.DB {
   var db = slf.Orm.Model(&SaleChance{})
   if slf.Keyword != "" {
      db = db.Where("name LIKE ?", "%"+slf.Keyword+"%")
   }
   if slf.Id > 0 {
      db = db.Where("id = ?", slf.Id)
   }
@@ -70,42 +79,66 @@
   return db
}
func (slf *SaleChangeSearch) Create(record *SaleChance) (err error) {
func (slf *SaleChanceSearch) Create(record *SaleChance) (err error) {
   var db = slf.build()
   err = db.Create(record).Error
   return
}
func (slf *SaleChangeSearch) Update(record *SaleChance) (err error) {
func (slf *SaleChanceSearch) Update(record *SaleChance) (err error) {
   var db = slf.build()
   err = db.Updates(record).Error
   return
}
func (slf *SaleChangeSearch) Delete() (err error) {
func (slf *SaleChanceSearch) Delete() (err error) {
   var db = slf.build()
   err = db.Delete(&SaleChance{}).Error
   return
}
func (slf *SaleChangeSearch) Find() (record SaleChance, err error) {
func (slf *SaleChanceSearch) Find() (record SaleChance, err error) {
   var db = slf.build()
   err = db.First(&record).Error
   return
}
func (slf *SaleChangeSearch) FindAll() (record []*SaleChance, err error) {
func (slf *SaleChanceSearch) FindAll() ([]*SaleChance, int64, error) {
   var db = slf.build()
   err = db.Preload("Client").Preload("Contact").Find(&record).Error
   return
   var records = make([]*SaleChance, 0)
   var total int64
   if err := db.Count(&total).Error; err != nil {
      return records, total, err
   }
   if slf.PageNum > 0 && slf.PageSize > 0 {
      db = db.Limit(slf.PageSize).Offset((slf.PageNum - 1) * slf.PageSize)
   }
   err := db.Preload("Client").Preload("Contact").Find(&records).Error
   return records, total, err
}
func (slf *SaleChangeSearch) SetId(id int) *SaleChangeSearch {
func (slf *SaleChanceSearch) SetId(id int) *SaleChanceSearch {
   slf.Id = id
   return slf
}
func (slf *SaleChangeSearch) SetName(name string) *SaleChangeSearch {
func (slf *SaleChanceSearch) SetName(name string) *SaleChanceSearch {
   slf.Name = name
   return slf
}
func (slf *SaleChanceSearch) SetKeyword(keyword string) *SaleChanceSearch {
   slf.Keyword = keyword
   return slf
}
func (slf *SaleChanceSearch) SetPage(page, size int) *SaleChanceSearch {
   slf.PageNum, slf.PageSize = page, size
   return slf
}
func (slf *SaleChanceSearch) SetOrder(order string) *SaleChanceSearch {
   slf.OrderBy = order
   return slf
}