fix
wangpengfei
2023-08-11 251c3ff0282168c8cc44c48d27916b02e3498a7f
fix

fix the time format
12个文件已修改
516 ■■■■ 已修改文件
api/v1/followRecord.go 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/business.go 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/client.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/contact.go 26 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/followRecord.go 36 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/masterOrder.go 21 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/plan.go 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/quotation.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/saleChance.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/salesRefund.go 25 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/salesReturn.go 20 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/serviceFeeManage.go 352 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/followRecord.go
@@ -172,27 +172,25 @@
// checkTimeFormat
// 检查时间格式
func checkTimeFormat(t string) (time.Time, error) {
    if t == "" {
        t = "1900-01-01T00:00:00+08:00"
    }
func checkTimeFormat(t string) (*time.Time, error) {
    location, err := time.LoadLocation("Asia/Shanghai")
    if err != nil {
        return time.Time{}, err
        return nil, err
    }
    tt, err := time.Parse("2006-01-02T15:04:05.000Z", t)
    if err == nil {
        return tt.In(location), nil
        ret := tt.In(location)
        return &ret, nil
    }
    tt, err = time.Parse("2006-01-02T15:04:05-07:00", t)
    if err == nil {
        return tt.In(location), nil
        ret := tt.In(location)
        return &ret, nil
    }
    return time.Time{}, err
    return nil, err
}
// List
model/business.go
@@ -4,9 +4,9 @@
type (
    Business struct {
        Representative      string    `json:"representative" gorm:"column:representative;type:varchar(255);comment:法人代表"`
        RegistrationTime    time.Time `json:"registration_time" gorm:"column:registration_time;type:datetime;default:1970-01-01 08:00:00;comment:注册时间"`
        RegisteredCapitalId int       `json:"registered_capital_id" gorm:"column:registered_capital_id;type:int(11);comment:注册资金"`
        Representative      string     `json:"representative" gorm:"column:representative;type:varchar(255);comment:法人代表"`
        RegistrationTime    *time.Time `json:"registration_time" gorm:"column:registration_time;type:datetime;default:1970-01-01 08:00:00;comment:注册时间"`
        RegisteredCapitalId int        `json:"registered_capital_id" gorm:"column:registered_capital_id;type:int(11);comment:注册资金"`
        RegisteredCapital   RegisteredCapital
        IndustryId          int `json:"industry_id" gorm:"column:industry_id;type:int(11);comment:所属行业"`
        Industry            Industry
model/client.go
@@ -26,8 +26,8 @@
        ServiceMemberId   int            `json:"service_member_id" gorm:"column:service_member_id;type:int(11);comment:服务负责人ID"`
        DetailAddress     string         `json:"detail_address" gorm:"column:detail_address;type:varchar(255);comment:详细地址"`
        Remark            string         `json:"remark" gorm:"column:remark;type:varchar(255);comment:备注"`
        NextVisitTime     time.Time      `json:"next_visit_time" gorm:"column:next_visit_time;type:datetime;comment:下次回访时间"`
        LatestServiceTime time.Time      `json:"latest_service_time" gorm:"column:latest_service_time;type:datetime;comment:最晚服务时间"`
        NextVisitTime     *time.Time     `json:"next_visit_time" gorm:"column:next_visit_time;type:datetime;comment:下次回访时间"`
        LatestServiceTime *time.Time     `json:"latest_service_time" gorm:"column:latest_service_time;type:datetime;comment:最晚服务时间"`
        FollowRecord      []FollowRecord `json:"follow_record" gorm:"foreignKey:ClientId"`
        Address
        Business
model/contact.go
@@ -8,19 +8,19 @@
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"`
        Client   Client    `json:"-" gorm:"foreignKey:ClientId"`
        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:备注"`
        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"`
        Client   Client     `json:"-" gorm:"foreignKey:ClientId"`
        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:"-"`
    }
model/followRecord.go
@@ -8,24 +8,24 @@
type (
    FollowRecord struct {
        Id                   int       `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
        ClientId             int       `json:"client_id" gorm:"column:client_id;type:int(11);comment:客户id"`
        ClientStatusId       int       `json:"client_status_id" gorm:"column:client_status_id;type:int(11);comment:客户状态id"`
        MemberId             int       `json:"member_id" gorm:"column:member_id;type:int(11);comment:跟进人id"`
        Member               User      `json:"member" gorm:"foreignKey:MemberId"`
        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"`
        Topic                string    `json:"topic" gorm:"column:topic;type:varchar(255);comment:跟进主题"`
        Record               string    `json:"record" gorm:"column:record;type:MEDIUMTEXT;comment:跟进记录"`
        SaleChanceId         int       `json:"sale_chance_id" gorm:"column:sale_chance_id;type:int(11);comment:销售机会id"`
        SalesLeadsId         int       `json:"sales_leads_id" gorm:"column:sales_leads_id;type:int(11);comment:销售线索id"`
        ContactInformationId int       `json:"contact_information_id" gorm:"column:contact_information_id;type:int(11);comment:联系方式id"`
        FollowTime           time.Time `json:"follow_time" gorm:"column:follow_time;type:datetime;comment:跟进时间"`
        NextFollowTime       time.Time `json:"next_follow_time" gorm:"column:next_follow_time;type:datetime;comment:下次跟进时间"`
        Purpose              string    `json:"purpose" gorm:"column:purpose;type:varchar(255);comment:跟进目的"`
        Content              string    `json:"content" gorm:"column:content;type:MEDIUMTEXT;comment:跟进内容"`
        Client               Client    `json:"client" gorm:"foreignKey:ClientId"`
        Contact              Contact   `json:"contact" gorm:"foreignKey:ContactId"`
        Id                   int        `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
        ClientId             int        `json:"client_id" gorm:"column:client_id;type:int(11);comment:客户id"`
        ClientStatusId       int        `json:"client_status_id" gorm:"column:client_status_id;type:int(11);comment:客户状态id"`
        MemberId             int        `json:"member_id" gorm:"column:member_id;type:int(11);comment:跟进人id"`
        Member               User       `json:"member" gorm:"foreignKey:MemberId"`
        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"`
        Topic                string     `json:"topic" gorm:"column:topic;type:varchar(255);comment:跟进主题"`
        Record               string     `json:"record" gorm:"column:record;type:MEDIUMTEXT;comment:跟进记录"`
        SaleChanceId         int        `json:"sale_chance_id" gorm:"column:sale_chance_id;type:int(11);comment:销售机会id"`
        SalesLeadsId         int        `json:"sales_leads_id" gorm:"column:sales_leads_id;type:int(11);comment:销售线索id"`
        ContactInformationId int        `json:"contact_information_id" gorm:"column:contact_information_id;type:int(11);comment:联系方式id"`
        FollowTime           *time.Time `json:"follow_time" gorm:"column:follow_time;type:datetime;comment:跟进时间"`
        NextFollowTime       *time.Time `json:"next_follow_time" gorm:"column:next_follow_time;type:datetime;comment:下次跟进时间"`
        Purpose              string     `json:"purpose" gorm:"column:purpose;type:varchar(255);comment:跟进目的"`
        Content              string     `json:"content" gorm:"column:content;type:MEDIUMTEXT;comment:跟进内容"`
        Client               Client     `json:"client" gorm:"foreignKey:ClientId"`
        Contact              Contact    `json:"contact" gorm:"foreignKey:ContactId"`
        gorm.Model           `json:"-"`
    }
model/masterOrder.go
@@ -9,14 +9,14 @@
type (
    // MasterOrder 销售总单
    MasterOrder struct {
        Id         int       `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
        Number     string    `json:"number" gorm:"column:number;type:varchar(255);comment:销售总单号"`
        ClientId   int       `json:"client_id" gorm:"column:client_id;type:int;comment:客户id"`
        Client     Client    `json:"client" gorm:"foreignKey:ClientId"`
        MemberId   int       `json:"member_id" gorm:"column:member_id;type:int;comment:负责人id"`
        StartTime  time.Time `json:"start_time" gorm:"column:start_time;type:datetime;comment:开始时间"`
        EndTime    time.Time `json:"end_time" gorm:"column:end_time;type:datetime;comment:结束时间"`
        Money      float64   `json:"money" gorm:"column:money;type:decimal(10,2);comment:总金额"`
        Id         int        `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
        Number     string     `json:"number" gorm:"column:number;type:varchar(255);comment:销售总单号"`
        ClientId   int        `json:"client_id" gorm:"column:client_id;type:int;comment:客户id"`
        Client     Client     `json:"client" gorm:"foreignKey:ClientId"`
        MemberId   int        `json:"member_id" gorm:"column:member_id;type:int;comment:负责人id"`
        StartTime  *time.Time `json:"start_time" gorm:"column:start_time;type:datetime;comment:开始时间"`
        EndTime    *time.Time `json:"end_time" gorm:"column:end_time;type:datetime;comment:结束时间"`
        Money      float64    `json:"money" gorm:"column:money;type:decimal(10,2);comment:总金额"`
        gorm.Model `json:"-"`
    }
@@ -24,12 +24,11 @@
    MasterOrderSearch struct {
        MasterOrder
                Orm      *gorm.DB
        Orm      *gorm.DB
        Keyword  string
        OrderBy  string
        PageNum  int
        PageSize int
    }
)
@@ -114,4 +113,4 @@
func (slf *MasterOrderSearch) SetOrder(order string) *MasterOrderSearch {
    slf.OrderBy = order
    return slf
}
}
model/plan.go
@@ -16,8 +16,8 @@
        SubOrder       SubOrder     `json:"subOrder" gorm:"foreignKey:SubOrderId"`
        SalesDetailsId int          `json:"salesDetailsId" gorm:"column:sales_details_id;type:int;comment:销售明细id"`
        SalesDetails   SalesDetails `json:"salesDetails" gorm:"foreignKey:SalesDetailsId"`
        StartTime      time.Time    `json:"startTime" gorm:"column:start_time;type:datetime;comment:开始时间"`
        EndTime        time.Time    `json:"endTime" gorm:"column:end_time;type:datetime;comment:结束时间"`
        StartTime      *time.Time   `json:"startTime" gorm:"column:start_time;type:datetime;comment:开始时间"`
        EndTime        *time.Time   `json:"endTime" gorm:"column:end_time;type:datetime;comment:结束时间"`
        Content        string       `json:"content" gorm:"column:content;type:varchar(255);comment:计划内容"`
        File           string       `json:"file" gorm:"column:file;type:varchar(255);comment:附件"`
        gorm.Model     `json:"-"`
@@ -111,4 +111,4 @@
func (slf *PlanSearch) SetOrder(order string) *PlanSearch {
    slf.OrderBy = order
    return slf
}
}
model/quotation.go
@@ -13,7 +13,7 @@
        ClientId          int        `json:"client_id" gorm:"column:client_id;type:int;comment:客户id"`
        Number            string     `json:"number" gorm:"column:number;type:varchar(255);comment:报价单号"`
        QuotationStatusId int        `json:"quotation_status_id" gorm:"column:quotation_status_id;type:int;comment:报价单状态id"`
        ValidityDate      time.Time  `json:"validity_date" gorm:"column:validity_date;type:datetime;comment:有效期"`
        ValidityDate      *time.Time `json:"validity_date" gorm:"column:validity_date;type:datetime;comment:有效期"`
        ContactId         int        `json:"contact_id" gorm:"column:contact_id;type:int;comment:联系人id"`
        MemberId          int        `json:"member_id" gorm:"column:member_id;type:int;comment:负责人id"`
        SaleChanceId      int        `json:"sale_chance_id" gorm:"column:sale_chance_id;type:int;comment:销售机会id"`
model/saleChance.go
@@ -23,7 +23,7 @@
        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:预计成交时间"`
        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:是否成立"`
model/salesRefund.go
@@ -8,28 +8,27 @@
type (
    SalesRefund 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:退款单号"`
        MemberId     int       `json:"memberId" gorm:"column:member_id;type:int;comment:负责人id"`
        RefundDate   time.Time `json:"refundDate" gorm:"column:refund_date;type:datetime;comment:退款日期"`
        RefundMethod string    `json:"refundMethod" gorm:"column:refund_method;type:varchar(255);comment:退款方式"`
        AccountId    int       `json:"accountId" gorm:"column:account_id;type:int;comment:账户"`
        IsInvoice    int       `json:"isInvoice" gorm:"column:is_invoice;type:int;comment:是否开票"`
        Reason       string    `json:"reason" gorm:"column:reason;type:varchar(255);comment:退款原因"`
        Products     []Product `json:"products" gorm:"many2many:salesRefund_product;"`
        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:退款单号"`
        MemberId     int        `json:"memberId" gorm:"column:member_id;type:int;comment:负责人id"`
        RefundDate   *time.Time `json:"refundDate" gorm:"column:refund_date;type:datetime;comment:退款日期"`
        RefundMethod string     `json:"refundMethod" gorm:"column:refund_method;type:varchar(255);comment:退款方式"`
        AccountId    int        `json:"accountId" gorm:"column:account_id;type:int;comment:账户"`
        IsInvoice    int        `json:"isInvoice" gorm:"column:is_invoice;type:int;comment:是否开票"`
        Reason       string     `json:"reason" gorm:"column:reason;type:varchar(255);comment:退款原因"`
        Products     []Product  `json:"products" gorm:"many2many:salesRefund_product;"`
        gorm.Model   `json:"-"`
    }
    SalesRefundSearch struct {
        SalesRefund
                Orm      *gorm.DB
        Orm      *gorm.DB
        Keyword  string
        OrderBy  string
        PageNum  int
        PageSize int
    }
)
@@ -114,4 +113,4 @@
func (slf *SalesRefundSearch) SetOrder(order string) *SalesRefundSearch {
    slf.OrderBy = order
    return slf
}
}
model/salesReturn.go
@@ -8,15 +8,15 @@
type (
    SalesReturn 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:退货单号"`
        Repository        string    `json:"repository" gorm:"column:repository;type:varchar(255);comment:仓库"`
        MemberId          int       `json:"memberId" gorm:"column:member_id;type:int;comment:负责人id"`
        ReturnDate        time.Time `json:"returnDate" gorm:"column:return_date;type:datetime;comment:退货日期"`
        SalesReturnStatus int       `json:"salesReturnStatus" gorm:"column:sales_return_status;type:int;comment:退货状态"`
        Reason            string    `json:"reason" gorm:"column:reason;type:varchar(255);comment:退货原因"`
        Products          []Product `json:"products" gorm:"many2many:salesReturn_product;"`
        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:退货单号"`
        Repository        string     `json:"repository" gorm:"column:repository;type:varchar(255);comment:仓库"`
        MemberId          int        `json:"memberId" gorm:"column:member_id;type:int;comment:负责人id"`
        ReturnDate        *time.Time `json:"returnDate" gorm:"column:return_date;type:datetime;comment:退货日期"`
        SalesReturnStatus int        `json:"salesReturnStatus" gorm:"column:sales_return_status;type:int;comment:退货状态"`
        Reason            string     `json:"reason" gorm:"column:reason;type:varchar(255);comment:退货原因"`
        Products          []Product  `json:"products" gorm:"many2many:salesReturn_product;"`
    }
    SalesReturnSearch struct {
@@ -107,4 +107,4 @@
func (slf *SalesReturnSearch) SetOrder(order string) *SalesReturnSearch {
    slf.OrderBy = order
    return slf
}
}
model/serviceFeeManage.go
@@ -1,176 +1,176 @@
package model
import (
    "aps_crm/constvar"
    "aps_crm/pkg/mysqlx"
    "gorm.io/gorm"
    "time"
)
type (
    ServiceFeeManage struct {
        Id         int       `json:"id" gorm:"column:id;primaryKey;autoIncrement;not null"`
        ClientId   int       `json:"client_id" gorm:"column:client_id;type:int(11);comment:客户ID"`
        Client     *Client   `json:"client" gorm:"foreignKey:ClientId"`
        MemberId   int       `json:"member_id" gorm:"column:member_id;type:int(11);comment:员工ID"`
        LatestDate time.Time `json:"latest_date" gorm:"column:latest_date;type:datetime;comment:最晚服务时间"`
        Remark     string    `json:"remark" gorm:"column:remark;type:varchar(255);comment:备注"`
        File       string    `json:"file" gorm:"column:file;type:varchar(255);comment:文件"`
        gorm.Model `json:"-"`
    }
    ServiceFeeManageSearch struct {
        ServiceFeeManage
        Orm         *gorm.DB
        QueryClass  constvar.ServiceFeeQueryClass
        KeywordType constvar.ServiceFeeKeywordType
        Keyword     string
        OrderBy     string
        PageNum     int
        PageSize    int
    }
)
func (ServiceFeeManage) TableName() string {
    return "service_fee_manage"
}
func NewServiceFeeManageSearch(db *gorm.DB) *ServiceFeeManageSearch {
    if db == nil {
        db = mysqlx.GetDB()
    }
    return &ServiceFeeManageSearch{
        Orm: db,
    }
}
func (slf *ServiceFeeManageSearch) build() *gorm.DB {
    var db = slf.Orm.Model(&ServiceFeeManage{})
    if slf.Id != 0 {
        db.Where("id = ?", slf.Id)
    }
    if slf.ClientId != 0 {
        db.Where("client_id = ?", slf.ClientId)
    }
    switch slf.QueryClass {
    case constvar.ServiceFeeQueryClassExpireLessThen60Days:
        db = db.Where("latest_date > ? and latest_date < ?", time.Now(), time.Now().AddDate(0, 0, 60))
    case constvar.ServiceFeeQueryClassExpireLessThen30Days:
        db = db.Where("latest_date > ? and latest_date < ?", time.Now(), time.Now().AddDate(0, 0, 30))
    case constvar.ServiceFeeQueryClassExpireAboutTo60Day:
        db = db.Where("latest_date = ?", time.Now().AddDate(0, 0, -60))
    case constvar.ServiceFeeQueryClassExpireAboutTo30Day:
        db = db.Where("latest_date = ?", time.Now().AddDate(0, 0, -30))
    case constvar.ServiceFeeQueryClassExpired:
        db = db.Where("latest_date < ?", time.Now())
    case constvar.ServiceFeeQueryClassNoService:
        db = db.Where("latest_date < ?", time.Now().AddDate(0, 0, -60))
    }
    switch slf.KeywordType {
    case constvar.ServiceFeeKeywordCustomerName:
        db.Joins("left join clients on clients.id = service_fee_manage.client_id")
        db = db.Where("clients.name = ?", slf.Keyword)
    case constvar.ServiceFeeKeywordCustomerType:
        db.Joins("left join clients on clients.id = service_fee_manage.client_id")
        db = db.Where("clients.client_type_id = ?", slf.Keyword)
    case constvar.ServiceFeeKeywordSalesPrincipal:
        db.Joins("left join clients on clients.id = service_fee_manage.client_id")
        db = db.Where("clients.member_id = ?", slf.Keyword)
    case constvar.ServiceFeeKeywordCustomerScale:
        db.Joins("left join clients on clients.id = service_fee_manage.client_id")
        db = db.Where("clients.enterprise_scale_id = ?", slf.Keyword)
    case constvar.ServiceFeeKeywordClientLevel:
        db.Joins("left join clients on clients.id = service_fee_manage.client_id")
        db = db.Where("clients.client_level_id = ?", slf.Keyword)
    case constvar.ServiceFeeKeywordCustomerNo:
        db.Joins("left join clients on clients.id = service_fee_manage.client_id")
        db = db.Where("clients.number = ?", slf.Keyword)
    case constvar.ServiceFeeKeywordCustomerStatus:
        db.Joins("left join clients on clients.id = service_fee_manage.client_id")
        db = db.Where("clients.client_status_id = ?", slf.Keyword)
    case constvar.ServiceFeeKeywordServiceEndDate:
        db = db.Where("latest_date = ?", slf.Keyword)
    case constvar.ServiceFeeKeywordProductName:
        //todo
    }
    return db
}
func (slf *ServiceFeeManageSearch) Create(record *ServiceFeeManage) error {
    var db = slf.build()
    return db.Create(record).Error
}
func (slf *ServiceFeeManageSearch) Update(record *ServiceFeeManage) error {
    var db = slf.build()
    return db.Updates(record).Error
}
func (slf *ServiceFeeManageSearch) Delete() error {
    var db = slf.build()
    return db.Delete(&ServiceFeeManage{}).Error
}
func (slf *ServiceFeeManageSearch) SetId(id int) *ServiceFeeManageSearch {
    slf.Id = id
    return slf
}
func (slf *ServiceFeeManageSearch) SetKeywordType(keyword constvar.ServiceFeeKeywordType) *ServiceFeeManageSearch {
    slf.KeywordType = keyword
    return slf
}
func (slf *ServiceFeeManageSearch) SetQueryClass(queryClass constvar.ServiceFeeQueryClass) *ServiceFeeManageSearch {
    slf.QueryClass = queryClass
    return slf
}
func (slf *ServiceFeeManageSearch) SetKeyword(keyword string) *ServiceFeeManageSearch {
    slf.Keyword = keyword
    return slf
}
func (slf *ServiceFeeManageSearch) Find() (*ServiceFeeManage, error) {
    var db = slf.build()
    var record = new(ServiceFeeManage)
    err := db.First(record).Error
    return record, err
}
func (slf *ServiceFeeManageSearch) FindAll() ([]*ServiceFeeManage, int64, error) {
    var db = slf.build()
    var records = make([]*ServiceFeeManage, 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)
    }
    if slf.PageNum > 0 && slf.PageSize > 0 {
        db = db.Limit(slf.PageSize).Offset((slf.PageNum - 1) * slf.PageSize)
    }
    err := db.Preload("Client").Find(&records).Error
    return records, total, err
}
func (slf *ServiceFeeManageSearch) SetPage(page, size int) *ServiceFeeManageSearch {
    slf.PageNum, slf.PageSize = page, size
    return slf
}
func (slf *ServiceFeeManageSearch) SetOrder(order string) *ServiceFeeManageSearch {
    slf.OrderBy = order
    return slf
}
func (slf *ServiceFeeManageSearch) SetIds(ids []int) *ServiceFeeManageSearch {
    slf.Orm = slf.Orm.Where("id in (?)", ids)
    return slf
}
package model
import (
    "aps_crm/constvar"
    "aps_crm/pkg/mysqlx"
    "gorm.io/gorm"
    "time"
)
type (
    ServiceFeeManage struct {
        Id         int        `json:"id" gorm:"column:id;primaryKey;autoIncrement;not null"`
        ClientId   int        `json:"client_id" gorm:"column:client_id;type:int(11);comment:客户ID"`
        Client     *Client    `json:"client" gorm:"foreignKey:ClientId"`
        MemberId   int        `json:"member_id" gorm:"column:member_id;type:int(11);comment:员工ID"`
        LatestDate *time.Time `json:"latest_date" gorm:"column:latest_date;type:datetime;comment:最晚服务时间"`
        Remark     string     `json:"remark" gorm:"column:remark;type:varchar(255);comment:备注"`
        File       string     `json:"file" gorm:"column:file;type:varchar(255);comment:文件"`
        gorm.Model `json:"-"`
    }
    ServiceFeeManageSearch struct {
        ServiceFeeManage
        Orm         *gorm.DB
        QueryClass  constvar.ServiceFeeQueryClass
        KeywordType constvar.ServiceFeeKeywordType
        Keyword     string
        OrderBy     string
        PageNum     int
        PageSize    int
    }
)
func (ServiceFeeManage) TableName() string {
    return "service_fee_manage"
}
func NewServiceFeeManageSearch(db *gorm.DB) *ServiceFeeManageSearch {
    if db == nil {
        db = mysqlx.GetDB()
    }
    return &ServiceFeeManageSearch{
        Orm: db,
    }
}
func (slf *ServiceFeeManageSearch) build() *gorm.DB {
    var db = slf.Orm.Model(&ServiceFeeManage{})
    if slf.Id != 0 {
        db.Where("id = ?", slf.Id)
    }
    if slf.ClientId != 0 {
        db.Where("client_id = ?", slf.ClientId)
    }
    switch slf.QueryClass {
    case constvar.ServiceFeeQueryClassExpireLessThen60Days:
        db = db.Where("latest_date > ? and latest_date < ?", time.Now(), time.Now().AddDate(0, 0, 60))
    case constvar.ServiceFeeQueryClassExpireLessThen30Days:
        db = db.Where("latest_date > ? and latest_date < ?", time.Now(), time.Now().AddDate(0, 0, 30))
    case constvar.ServiceFeeQueryClassExpireAboutTo60Day:
        db = db.Where("latest_date = ?", time.Now().AddDate(0, 0, -60))
    case constvar.ServiceFeeQueryClassExpireAboutTo30Day:
        db = db.Where("latest_date = ?", time.Now().AddDate(0, 0, -30))
    case constvar.ServiceFeeQueryClassExpired:
        db = db.Where("latest_date < ?", time.Now())
    case constvar.ServiceFeeQueryClassNoService:
        db = db.Where("latest_date < ?", time.Now().AddDate(0, 0, -60))
    }
    switch slf.KeywordType {
    case constvar.ServiceFeeKeywordCustomerName:
        db.Joins("left join clients on clients.id = service_fee_manage.client_id")
        db = db.Where("clients.name = ?", slf.Keyword)
    case constvar.ServiceFeeKeywordCustomerType:
        db.Joins("left join clients on clients.id = service_fee_manage.client_id")
        db = db.Where("clients.client_type_id = ?", slf.Keyword)
    case constvar.ServiceFeeKeywordSalesPrincipal:
        db.Joins("left join clients on clients.id = service_fee_manage.client_id")
        db = db.Where("clients.member_id = ?", slf.Keyword)
    case constvar.ServiceFeeKeywordCustomerScale:
        db.Joins("left join clients on clients.id = service_fee_manage.client_id")
        db = db.Where("clients.enterprise_scale_id = ?", slf.Keyword)
    case constvar.ServiceFeeKeywordClientLevel:
        db.Joins("left join clients on clients.id = service_fee_manage.client_id")
        db = db.Where("clients.client_level_id = ?", slf.Keyword)
    case constvar.ServiceFeeKeywordCustomerNo:
        db.Joins("left join clients on clients.id = service_fee_manage.client_id")
        db = db.Where("clients.number = ?", slf.Keyword)
    case constvar.ServiceFeeKeywordCustomerStatus:
        db.Joins("left join clients on clients.id = service_fee_manage.client_id")
        db = db.Where("clients.client_status_id = ?", slf.Keyword)
    case constvar.ServiceFeeKeywordServiceEndDate:
        db = db.Where("latest_date = ?", slf.Keyword)
    case constvar.ServiceFeeKeywordProductName:
        //todo
    }
    return db
}
func (slf *ServiceFeeManageSearch) Create(record *ServiceFeeManage) error {
    var db = slf.build()
    return db.Create(record).Error
}
func (slf *ServiceFeeManageSearch) Update(record *ServiceFeeManage) error {
    var db = slf.build()
    return db.Updates(record).Error
}
func (slf *ServiceFeeManageSearch) Delete() error {
    var db = slf.build()
    return db.Delete(&ServiceFeeManage{}).Error
}
func (slf *ServiceFeeManageSearch) SetId(id int) *ServiceFeeManageSearch {
    slf.Id = id
    return slf
}
func (slf *ServiceFeeManageSearch) SetKeywordType(keyword constvar.ServiceFeeKeywordType) *ServiceFeeManageSearch {
    slf.KeywordType = keyword
    return slf
}
func (slf *ServiceFeeManageSearch) SetQueryClass(queryClass constvar.ServiceFeeQueryClass) *ServiceFeeManageSearch {
    slf.QueryClass = queryClass
    return slf
}
func (slf *ServiceFeeManageSearch) SetKeyword(keyword string) *ServiceFeeManageSearch {
    slf.Keyword = keyword
    return slf
}
func (slf *ServiceFeeManageSearch) Find() (*ServiceFeeManage, error) {
    var db = slf.build()
    var record = new(ServiceFeeManage)
    err := db.First(record).Error
    return record, err
}
func (slf *ServiceFeeManageSearch) FindAll() ([]*ServiceFeeManage, int64, error) {
    var db = slf.build()
    var records = make([]*ServiceFeeManage, 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)
    }
    if slf.PageNum > 0 && slf.PageSize > 0 {
        db = db.Limit(slf.PageSize).Offset((slf.PageNum - 1) * slf.PageSize)
    }
    err := db.Preload("Client").Find(&records).Error
    return records, total, err
}
func (slf *ServiceFeeManageSearch) SetPage(page, size int) *ServiceFeeManageSearch {
    slf.PageNum, slf.PageSize = page, size
    return slf
}
func (slf *ServiceFeeManageSearch) SetOrder(order string) *ServiceFeeManageSearch {
    slf.OrderBy = order
    return slf
}
func (slf *ServiceFeeManageSearch) SetIds(ids []int) *ServiceFeeManageSearch {
    slf.Orm = slf.Orm.Where("id in (?)", ids)
    return slf
}