package models import ( "github.com/beego/beego/v2/client/orm" "time" ) // CompanyProductUpdateLog 客户产品变更日志表 type CompanyProductUpdateLog struct { Id int `orm:"column(id);pk"` CompanyId int `description:"客户id"` ProductId int `description:"产品id"` Status string `description:"变更后的状态"` SellerId int `description:"销售id"` SellerName string `description:"销售名称"` IsFormal int `description:"是否已经转正式,0是没有转正式,1是已经转过正式"` Source string `description:"来源"` StartDate time.Time `description:"开始日期"` EndDate time.Time `description:"结束日期"` RealEndDate time.Time `description:"实际结束日期"` CreateTime time.Time `description:"创建时间"` } // AddCompanyProductUpdateLog 新增客户产品变更日志 func AddCompanyProductUpdateLog(item *CompanyProductUpdateLog) (lastId int64, err error) { o := orm.NewOrm() lastId, err = o.Insert(item) return } // GetCompanyProductUpdateLogList 获取客户产品变更日志列表 func GetCompanyProductUpdateLogList(createTime string) (total int64, list []*CompanyProductUpdateLog, err error) { o := orm.NewOrm() //那就三种情况了:新增试用、冻结转试用、流失转试用 //新增:add //领取:receive //试用转正式:turn_positive //冻结转试用:thaw //试用延期:delay //原销售申请领取流失客户:apply_receive //正式客户申请续约:service_update //正式客户新增补充协议:add_agreement sql := `SELECT * FROM company_product_update_log where create_time >= ? AND source in ("add","receive","thaw","apply_receive") ` total, err = o.Raw(sql, createTime).QueryRows(&list) return } // IncrementCompanyProductUpdateLog 增量客户产品变更日志表 type IncrementCompanyProductUpdateLog struct { Id int `orm:"column(id);pk"` CompanyId int `description:"客户id"` ProductId int `description:"产品id"` Status string `description:"变更后的状态"` Source string `description:"来源"` CreateTime time.Time `description:"创建时间"` CompanyName string `description:"客户名称"` CreditCode string `description:"社会信用码"` SellerName string `description:"销售名称"` CurrStatus string `description:"当前产品状态"` } // GetIncrementCompanyProductUpdateLogList 获取客户产品变更日志列表 func GetIncrementCompanyProductUpdateLogList(startCreateTime, endCreateTime string) (total int64, list []*IncrementCompanyProductUpdateLog, err error) { o := orm.NewOrm() //那就三种情况了:新增试用、冻结转试用、流失转试用 //新增:add //领取:receive //试用转正式:turn_positive //冻结转试用:thaw //试用延期:delay //原销售申请领取流失客户:apply_receive //正式客户申请续约:service_update //正式客户新增补充协议:add_agreement sql := `SELECT a.*,b.company_name,b.credit_code,c.status curr_status,c.seller_name FROM company_product_update_log a join company b on a.company_id=b.company_id join company_product c on a.company_id=c.company_id and c.product_id=a.product_id where a.create_time >= ? AND a.create_time < ? AND a.source in ("add","receive","thaw","apply_receive") ` total, err = o.Raw(sql, startCreateTime, endCreateTime).QueryRows(&list) return }