123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- package models
- import (
- "github.com/beego/beego/v2/client/orm"
- "time"
- )
- // CompanyProductTryOutUpdateLog 客户产品试用变更日志表
- type CompanyProductTryOutUpdateLog struct {
- Id int `orm:"column(id);pk"`
- CompanyId int `description:"客户id"`
- ProductId int `description:"产品id"`
- SellerId int `description:"销售id"`
- SellerName string `description:"销售名称"`
- Source string `description:"来源"`
- StartDate time.Time `description:"开始日期"`
- EndDate time.Time `description:"结束日期"`
- RealEndDate time.Time `description:"实际结束日期"`
- IsStop int `description:"是否已经终止了,0:进行中;1:已终止"`
- CreateTime time.Time `description:"创建时间"`
- }
- // Update 更新客户产品试用变更日志
- func (item *CompanyProductTryOutUpdateLog) Update(cols []string) (err error) {
- o := orm.NewOrm()
- _, err = o.Update(item, cols...)
- return
- }
- // CompanyProductTryOutUpdatePermissionLog 客户产品变更品种详情表
- type CompanyProductTryOutUpdatePermissionLog struct {
- Id int `orm:"column(id);pk"`
- CompanyProductUpdateLogId int `description:"产品变更id"`
- ChartPermissionId int `description:"品种权限id"`
- StartDate time.Time `description:"开始日期"`
- EndDate time.Time `description:"结束日期"`
- RealEndDate time.Time `description:"实际结束日期"`
- IsStop int `description:"是否已经终止了,0:进行中;1:已终止"`
- CreateTime time.Time `description:"创建时间"`
- }
- // Update 更新客户产品变更品种详情
- func (item *CompanyProductTryOutUpdatePermissionLog) Update(cols []string) (err error) {
- o := orm.NewOrm()
- _, err = o.Update(item, cols...)
- return
- }
- // AddCompanyProductTryOutUpdateLog 新增客户试用产品变更日志
- func AddCompanyProductTryOutUpdateLog(item *CompanyProductTryOutUpdateLog, companyReportPermissionList []*CompanyReportPermission) (err error) {
- o := orm.NewOrm()
- lastId, err := o.Insert(item)
- if err != nil {
- return
- }
- item.Id = int(lastId)
- companyProductUpdatePermissionLogList := make([]*CompanyProductTryOutUpdatePermissionLog, 0)
- for _, v := range companyReportPermissionList {
- tmpCompanyProductUpdatePermissionLog := &CompanyProductTryOutUpdatePermissionLog{
- //Id: 0,
- CompanyProductUpdateLogId: item.Id,
- ChartPermissionId: v.ChartPermissionId,
- StartDate: item.StartDate,
- EndDate: item.EndDate,
- RealEndDate: item.StartDate,
- IsStop: item.IsStop,
- CreateTime: item.CreateTime,
- }
- companyProductUpdatePermissionLogList = append(companyProductUpdatePermissionLogList, tmpCompanyProductUpdatePermissionLog)
- }
- if len(companyProductUpdatePermissionLogList) > 0 {
- _, err = o.InsertMulti(len(companyProductUpdatePermissionLogList), companyProductUpdatePermissionLogList)
- }
- {
- // 获取当前正在进行中的客户变更试用的数据
- findProgress, _ := GetCompanyProductTryOutUpdateLogItem(item.CompanyId, item.ProductId)
- // 如果没有的话,那么就将试用天数+1
- if findProgress != nil {
- sql := `UPDATE company_product
- SET
- try_out_day_total = try_out_day_total+1
- WHERE company_id = ? AND product_id = ?`
- _, err = o.Raw(sql, item.CompanyId, item.ProductId).Exec()
- }
- }
- return
- }
- // GetCompanyProductTryOutUpdateLogItem 获取当前正在进行中的客户变更试用的数据
- func GetCompanyProductTryOutUpdateLogItem(companyId, productId int) (item *CompanyProductTryOutUpdateLog, err error) {
- o := orm.NewOrm()
- sql := ` select * from company_product_try_out_update_log where company_id=? and product_id=? and is_stop = 0`
- err = o.Raw(sql, companyId, productId).QueryRow(&item)
- return
- }
- // GetCompanyProductTryOutUpdateGroup 获取当前正在进行中的客户变更试用的数据
- func GetCompanyProductTryOutUpdateGroup() (items []*CompanyProductTryOutUpdateLog, err error) {
- o := orm.NewOrm()
- sql := ` select * from company_product_try_out_update_log group by company_id,product_id;`
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- // GetCompanyProductTryOutUpdateNoStopGroup 获取当前正在进行中的客户变更试用的数据(未停止的)
- func GetCompanyProductTryOutUpdateNoStopGroup() (items []*CompanyProductTryOutUpdateLog, err error) {
- o := orm.NewOrm()
- sql := ` select * from company_product_try_out_update_log where is_stop=0 group by company_id,product_id;`
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- // GetCompanyProductTryOutUpdateList 获取当前正在进行中的客户变更试用的数据
- func GetCompanyProductTryOutUpdateList(companyId, productId int) (items []*CompanyProductTryOutUpdateLog, err error) {
- o := orm.NewOrm()
- sql := ` select * from company_product_try_out_update_log Where company_id=? and product_id=? order by create_time asc;`
- _, err = o.Raw(sql, companyId, productId).QueryRows(&items)
- return
- }
- // GetCompanyProductTryOutUpdateNoStopList 获取当前正在进行中的客户变更试用的数据(未停止的)
- func GetCompanyProductTryOutUpdateNoStopList(companyId, productId int) (items []*CompanyProductTryOutUpdateLog, err error) {
- o := orm.NewOrm()
- sql := ` select * from company_product_try_out_update_log Where company_id=? and product_id=? AND is_stop=0 order by create_time asc;`
- _, err = o.Raw(sql, companyId, productId).QueryRows(&items)
- return
- }
- // GetCompanyProductTryOutUpdateNoStopListByEndDate 获取当前正在进行中的客户变更试用的数据(未停止的)
- func GetCompanyProductTryOutUpdateNoStopListByEndDate(companyId, productId int) (items []*CompanyProductTryOutUpdateLog, err error) {
- o := orm.NewOrm()
- sql := ` select * from company_product_try_out_update_log Where company_id=? and product_id=? AND is_stop=0 order by end_date desc;`
- _, err = o.Raw(sql, companyId, productId).QueryRows(&items)
- return
- }
- // AddCompanyProductUpdatePermissionLog 客户产品变更品种详情日志
- func AddCompanyProductUpdatePermissionLog(item *CompanyProductTryOutUpdatePermissionLog) (lastId int64, err error) {
- o := orm.NewOrm()
- lastId, err = o.Insert(item)
- return
- }
- // GetCompanyProductTryOutUpdateLogTotal 获取客户转试用的记录列表
- func GetCompanyProductTryOutUpdateLogTotal(companyId, productId int) (total int, err error) {
- o := orm.NewOrm()
- var pars []interface{}
- sql := `select count(1) total from company_product_try_out_update_log a join company_product b on a.company_id=b.company_id and a.product_id=b.product_id where a.company_id = ? `
- pars = append(pars, companyId)
- //如果有传入产品id,那么只查询该类型下的产品
- if productId != 0 {
- sql += ` and a.product_id = ? `
- pars = append(pars, productId)
- }
- err = o.Raw(sql, pars...).QueryRow(&total)
- return
- }
- // GetCompanyProductTryOutUpdateLogList 获取客户转试用的记录列表
- func GetCompanyProductTryOutUpdateLogList(companyId, productId, startSize, pageSize int) (items []*CompanyProductTryOutUpdateLog, err error) {
- o := orm.NewOrm()
- var pars []interface{}
- sql := `select a.* from company_product_try_out_update_log a join company_product b on a.company_id=b.company_id and a.product_id=b.product_id where a.company_id = ? `
- pars = append(pars, companyId)
- //如果有传入产品id,那么只查询该类型下的产品
- if productId != 0 {
- sql += ` and a.product_id = ? `
- pars = append(pars, productId)
- }
- sql += ` order by a.create_time desc LIMIT ?,? `
- pars = append(pars, startSize, pageSize)
- _, err = o.Raw(sql, pars...).QueryRows(&items)
- return
- }
- // GetCompanyProductTryOutPermissionUpdateNoStopListByEndDate 获取当前正在进行中的客户变更试用品种的数据(未停止的)
- func GetCompanyProductTryOutPermissionUpdateNoStopListByEndDate(companyProductUpdateLogId int) (items []*CompanyProductTryOutUpdatePermissionLog, err error) {
- o := orm.NewOrm()
- sql := ` select * from company_product_try_out_update_permission_log Where company_product_update_log_id=? AND is_stop=0 order by end_date desc;`
- _, err = o.Raw(sql, companyProductUpdateLogId).QueryRows(&items)
- return
- }
|