From b90a31431164b4b0756e4ef76f08b08953b8b04d Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期五, 13 十月 2023 14:56:23 +0800 Subject: [PATCH] 服务合同简单数据权限 --- model/serviceFollowup.go | 87 ++++++++++++++++++++++++++++++------------- 1 files changed, 61 insertions(+), 26 deletions(-) diff --git a/model/serviceFollowup.go b/model/serviceFollowup.go index 757b182..fc3b09d 100644 --- a/model/serviceFollowup.go +++ b/model/serviceFollowup.go @@ -3,29 +3,37 @@ import ( "aps_crm/constvar" "aps_crm/pkg/mysqlx" + "fmt" "gorm.io/gorm" + "gorm.io/gorm/clause" ) type ( ServiceFollowup struct { - Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` - ClientId int `json:"clientId" gorm:"column:client_id;type:int;comment:瀹㈡埛id"` - Number string `json:"number" gorm:"column:number;type:varchar(255);comment:鍚堝悓缂栧彿"` - ContactId int `json:"contactId" gorm:"column:contact_id;type:int;comment:鑱旂郴浜篿d"` - ServiceId int `json:"serviceId" gorm:"column:service_id;type:int;comment:瀹㈡埛鏈嶅姟鍗昳d"` - ServiceOrder ServiceOrder `gorm:"foreignKey:ServiceId"` - CustomerServiceSheet CustomerServiceSheet `json:"customerServiceSheet" gorm:"foreignKey:ServiceId"` - MemberId int `json:"memberId" gorm:"column:member_id;type:int;comment:鏈嶅姟浜哄憳id"` - PlanId int `json:"planId" gorm:"column:plan_id;type:int;comment:鏈嶅姟璁″垝id"` - SatisfactionId int `json:"satisfactionId" gorm:"column:satisfaction_id;type:int;comment:婊℃剰搴d"` - TimelyRateId int `json:"timelyRateId" gorm:"column:timely_rate_id;type:int;comment:鍙婃椂鐜噄d"` - SolveRateId int `json:"solveRateId" gorm:"column:solve_rate_id;type:int;comment:瑙e喅鐜噄d"` - IsVisitId int `json:"isVisitId" gorm:"column:is_visit_id;type:int;comment:鏈嶅姟浜哄憳鏄惁鏉ヨ繃id"` - OldMemberId int `json:"oldMemberId" gorm:"column:old_member_id;type:int;comment:鍘熸湇鍔′汉鍛�"` - Remark string `json:"remark" gorm:"column:remark;type:text;comment:澶囨敞"` - File string `json:"file" gorm:"column:file;type:varchar(255);comment:闄勪欢"` - - gorm.Model `json:"-"` + Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` + ClientId int `json:"clientId" gorm:"column:client_id;type:int;comment:瀹㈡埛id"` + Client Client `json:"client" gorm:"foreignKey:ClientId"` + Number string `json:"number" gorm:"column:number;type:varchar(255);comment:鍚堝悓缂栧彿"` + ContactId int `json:"contactId" gorm:"column:contact_id;type:int;comment:鑱旂郴浜篿d"` + Contact Contact `json:"contact" gorm:"foreignKey:ContactId"` + ServiceOrderId int `json:"serviceOrderId" gorm:"column:service_order_id;type:int;comment:瀹㈡埛鏈嶅姟鍗昳d"` + ServiceOrder ServiceOrder `gorm:"foreignKey:ServiceOrderId"` + MemberId int `json:"memberId" gorm:"column:member_id;type:int;comment:鏈嶅姟浜哄憳id"` + Member User `json:"Member" gorm:"foreignKey:MemberId"` + PlanId int `json:"planId" gorm:"column:plan_id;type:int;comment:鏈嶅姟璁″垝id"` + SatisfactionId int `json:"satisfactionId" gorm:"column:satisfaction_id;type:int;comment:婊℃剰搴d"` + Satisfaction Satisfaction `json:"satisfaction" gorm:"foreignKey:SatisfactionId"` + TimelyRateId int `json:"timelyRateId" gorm:"column:timely_rate_id;type:int;comment:鍙婃椂鐜噄d"` + TimelyRate TimelyRate `json:"timelyRate" gorm:"foreignKey:TimelyRateId"` + SolveRateId int `json:"solveRateId" gorm:"column:solve_rate_id;type:int;comment:瑙e喅鐜噄d"` + SolveRate SolveRate `json:"solveRate" gorm:"foreignKey:SolveRateId"` + IsVisitId int `json:"isVisitId" gorm:"column:is_visit_id;type:int;comment:鏈嶅姟浜哄憳鏄惁鏉ヨ繃id"` + IsVisit IsVisit `json:"isVisit" gorm:"foreignKey:IsVisitId"` + OldMemberId int `json:"oldMemberId" gorm:"column:old_member_id;type:int;comment:鍘熸湇鍔′汉鍛�"` + OldMember User `json:"oldMember" gorm:"foreignKey:OldMemberId"` + Remark string `json:"remark" gorm:"column:remark;type:text;comment:澶囨敞"` + File string `json:"file" gorm:"column:file;type:varchar(255);comment:闄勪欢"` + CrmModel } ServiceFollowupSearch struct { @@ -36,10 +44,11 @@ OrderBy string PageNum int PageSize int + Preload bool } ) -func (ServiceFollowup) TableName() string { +func (*ServiceFollowup) TableName() string { return "service_followup" } @@ -57,18 +66,30 @@ switch slf.KeywordType { case constvar.ServiceFollowupKeywordFollowupNo: - db = db.Where("number = ?", slf.Keyword) + db = db.Where("number like ?", fmt.Sprintf("%%%s%%", slf.Keyword)) case constvar.ServiceFollowupKeywordCustomerName: - db = db.Where("client_id = ?", slf.Keyword) + db = db.Joins("Client", clause.LeftJoin).Where("Client.name like ?", fmt.Sprintf("%%%s%%", slf.Keyword)) case constvar.ServiceFollowupKeywordContactName: - db = db.Where("contact_id = ?", slf.Keyword) + db = db.Joins("Contact").Where("Contact.name like ?", fmt.Sprintf("%%%s%%", slf.Keyword)) case constvar.ServiceFollowupKeywordCustomerServiceNo: - db = db.Where("service_id = ?", slf.Keyword) + db = db.Joins("ServiceOrder").Where("ServiceOrder.service_number like ?", fmt.Sprintf("%%%s%%", slf.Keyword)) case constvar.ServiceFollowupKeywordVisitor: - db = db.Where("member_id = ?", slf.Keyword) + db = db.Joins("left join user on user.id = service_followup.member_id").Where("user.username like ?", fmt.Sprintf("%%%s%%", slf.Keyword)) case constvar.ServiceFollowupKeywordSatisfactionDegree: - db = db.Where("satisfaction_id = ?", slf.Keyword) + db = db.Joins("Satisfaction").Where("Satisfaction.name like ?", fmt.Sprintf("%%%s%%", slf.Keyword)) + } + + if slf.Preload { + db = db.Preload("Client"). + Preload("Contact"). + Preload("ServiceOrder"). + Preload("Member"). + Preload("Satisfaction"). + Preload("TimelyRate"). + Preload("SolveRate"). + Preload("IsVisit"). + Preload("OldMember") } return db @@ -111,12 +132,22 @@ db = db.Limit(slf.PageSize).Offset((slf.PageNum - 1) * slf.PageSize) } - err := db.Preload("CustomerServiceSheet").Preload("ServiceOrder").Find(&records).Error + err := db.Order("id desc").Find(&records).Error return records, total, err } func (slf *ServiceFollowupSearch) SetId(id int) *ServiceFollowupSearch { slf.Id = id + return slf +} + +func (slf *ServiceFollowupSearch) SetServiceOrderId(id int) *ServiceFollowupSearch { + slf.ServiceOrderId = id + return slf +} + +func (slf *ServiceFollowupSearch) SetPreload(preload bool) *ServiceFollowupSearch { + slf.Preload = preload return slf } @@ -139,3 +170,7 @@ slf.OrderBy = order return slf } +func (slf *ServiceFollowupSearch) SetIds(ids []int) *ServiceFollowupSearch { + slf.Orm = slf.Orm.Where("id in (?)", ids) + return slf +} -- Gitblit v1.8.0