company_product_try_out_update_log.go 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. // CompanyProductTryOutUpdateLog 客户产品试用变更日志表
  7. type CompanyProductTryOutUpdateLog struct {
  8. Id int `orm:"column(id);pk"`
  9. CompanyId int `description:"客户id"`
  10. ProductId int `description:"产品id"`
  11. SellerId int `description:"销售id"`
  12. SellerName string `description:"销售名称"`
  13. Source string `description:"来源"`
  14. StartDate time.Time `description:"开始日期"`
  15. EndDate time.Time `description:"结束日期"`
  16. RealEndDate time.Time `description:"实际结束日期"`
  17. IsStop int `description:"是否已经终止了,0:进行中;1:已终止"`
  18. CreateTime time.Time `description:"创建时间"`
  19. }
  20. // Update 更新客户产品试用变更日志
  21. func (item *CompanyProductTryOutUpdateLog) Update(cols []string) (err error) {
  22. o := orm.NewOrm()
  23. _, err = o.Update(item, cols...)
  24. return
  25. }
  26. // CompanyProductTryOutUpdatePermissionLog 客户产品变更品种详情表
  27. type CompanyProductTryOutUpdatePermissionLog struct {
  28. Id int `orm:"column(id);pk"`
  29. CompanyProductUpdateLogId int `description:"产品变更id"`
  30. ChartPermissionId int `description:"品种权限id"`
  31. StartDate time.Time `description:"开始日期"`
  32. EndDate time.Time `description:"结束日期"`
  33. RealEndDate time.Time `description:"实际结束日期"`
  34. IsStop int `description:"是否已经终止了,0:进行中;1:已终止"`
  35. CreateTime time.Time `description:"创建时间"`
  36. }
  37. // Update 更新客户产品变更品种详情
  38. func (item *CompanyProductTryOutUpdatePermissionLog) Update(cols []string) (err error) {
  39. o := orm.NewOrm()
  40. _, err = o.Update(item, cols...)
  41. return
  42. }
  43. // AddCompanyProductTryOutUpdateLog 新增客户试用产品变更日志
  44. func AddCompanyProductTryOutUpdateLog(item *CompanyProductTryOutUpdateLog, companyReportPermissionList []*CompanyReportPermission) (err error) {
  45. o := orm.NewOrm()
  46. lastId, err := o.Insert(item)
  47. if err != nil {
  48. return
  49. }
  50. item.Id = int(lastId)
  51. companyProductUpdatePermissionLogList := make([]*CompanyProductTryOutUpdatePermissionLog, 0)
  52. for _, v := range companyReportPermissionList {
  53. tmpCompanyProductUpdatePermissionLog := &CompanyProductTryOutUpdatePermissionLog{
  54. //Id: 0,
  55. CompanyProductUpdateLogId: item.Id,
  56. ChartPermissionId: v.ChartPermissionId,
  57. StartDate: item.StartDate,
  58. EndDate: item.EndDate,
  59. RealEndDate: item.StartDate,
  60. IsStop: item.IsStop,
  61. CreateTime: item.CreateTime,
  62. }
  63. companyProductUpdatePermissionLogList = append(companyProductUpdatePermissionLogList, tmpCompanyProductUpdatePermissionLog)
  64. }
  65. if len(companyProductUpdatePermissionLogList) > 0 {
  66. _, err = o.InsertMulti(len(companyProductUpdatePermissionLogList), companyProductUpdatePermissionLogList)
  67. }
  68. {
  69. // 获取当前正在进行中的客户变更试用的数据
  70. findProgress, _ := GetCompanyProductTryOutUpdateLogItem(item.CompanyId, item.ProductId)
  71. // 如果没有的话,那么就将试用天数+1
  72. if findProgress != nil {
  73. sql := `UPDATE company_product
  74. SET
  75. try_out_day_total = try_out_day_total+1
  76. WHERE company_id = ? AND product_id = ?`
  77. _, err = o.Raw(sql, item.CompanyId, item.ProductId).Exec()
  78. }
  79. }
  80. return
  81. }
  82. // GetCompanyProductTryOutUpdateLogItem 获取当前正在进行中的客户变更试用的数据
  83. func GetCompanyProductTryOutUpdateLogItem(companyId, productId int) (item *CompanyProductTryOutUpdateLog, err error) {
  84. o := orm.NewOrm()
  85. sql := ` select * from company_product_try_out_update_log where company_id=? and product_id=? and is_stop = 0`
  86. err = o.Raw(sql, companyId, productId).QueryRow(&item)
  87. return
  88. }
  89. // GetCompanyProductTryOutUpdateGroup 获取当前正在进行中的客户变更试用的数据
  90. func GetCompanyProductTryOutUpdateGroup() (items []*CompanyProductTryOutUpdateLog, err error) {
  91. o := orm.NewOrm()
  92. sql := ` select * from company_product_try_out_update_log group by company_id,product_id;`
  93. _, err = o.Raw(sql).QueryRows(&items)
  94. return
  95. }
  96. // GetCompanyProductTryOutUpdateNoStopGroup 获取当前正在进行中的客户变更试用的数据(未停止的)
  97. func GetCompanyProductTryOutUpdateNoStopGroup() (items []*CompanyProductTryOutUpdateLog, err error) {
  98. o := orm.NewOrm()
  99. sql := ` select * from company_product_try_out_update_log where is_stop=0 group by company_id,product_id;`
  100. _, err = o.Raw(sql).QueryRows(&items)
  101. return
  102. }
  103. // GetCompanyProductTryOutUpdateList 获取当前正在进行中的客户变更试用的数据
  104. func GetCompanyProductTryOutUpdateList(companyId, productId int) (items []*CompanyProductTryOutUpdateLog, err error) {
  105. o := orm.NewOrm()
  106. sql := ` select * from company_product_try_out_update_log Where company_id=? and product_id=? order by create_time asc;`
  107. _, err = o.Raw(sql, companyId, productId).QueryRows(&items)
  108. return
  109. }
  110. // GetCompanyProductTryOutUpdateNoStopList 获取当前正在进行中的客户变更试用的数据(未停止的)
  111. func GetCompanyProductTryOutUpdateNoStopList(companyId, productId int) (items []*CompanyProductTryOutUpdateLog, err error) {
  112. o := orm.NewOrm()
  113. sql := ` select * from company_product_try_out_update_log Where company_id=? and product_id=? AND is_stop=0 order by create_time asc;`
  114. _, err = o.Raw(sql, companyId, productId).QueryRows(&items)
  115. return
  116. }
  117. // GetCompanyProductTryOutUpdateNoStopListByEndDate 获取当前正在进行中的客户变更试用的数据(未停止的)
  118. func GetCompanyProductTryOutUpdateNoStopListByEndDate(companyId, productId int) (items []*CompanyProductTryOutUpdateLog, err error) {
  119. o := orm.NewOrm()
  120. sql := ` select * from company_product_try_out_update_log Where company_id=? and product_id=? AND is_stop=0 order by end_date desc;`
  121. _, err = o.Raw(sql, companyId, productId).QueryRows(&items)
  122. return
  123. }
  124. // AddCompanyProductUpdatePermissionLog 客户产品变更品种详情日志
  125. func AddCompanyProductUpdatePermissionLog(item *CompanyProductTryOutUpdatePermissionLog) (lastId int64, err error) {
  126. o := orm.NewOrm()
  127. lastId, err = o.Insert(item)
  128. return
  129. }
  130. // GetCompanyProductTryOutUpdateLogTotal 获取客户转试用的记录列表
  131. func GetCompanyProductTryOutUpdateLogTotal(companyId, productId int) (total int, err error) {
  132. o := orm.NewOrm()
  133. var pars []interface{}
  134. 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 = ? `
  135. pars = append(pars, companyId)
  136. //如果有传入产品id,那么只查询该类型下的产品
  137. if productId != 0 {
  138. sql += ` and a.product_id = ? `
  139. pars = append(pars, productId)
  140. }
  141. err = o.Raw(sql, pars...).QueryRow(&total)
  142. return
  143. }
  144. // GetCompanyProductTryOutUpdateLogList 获取客户转试用的记录列表
  145. func GetCompanyProductTryOutUpdateLogList(companyId, productId, startSize, pageSize int) (items []*CompanyProductTryOutUpdateLog, err error) {
  146. o := orm.NewOrm()
  147. var pars []interface{}
  148. 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 = ? `
  149. pars = append(pars, companyId)
  150. //如果有传入产品id,那么只查询该类型下的产品
  151. if productId != 0 {
  152. sql += ` and a.product_id = ? `
  153. pars = append(pars, productId)
  154. }
  155. sql += ` order by a.create_time desc LIMIT ?,? `
  156. pars = append(pars, startSize, pageSize)
  157. _, err = o.Raw(sql, pars...).QueryRows(&items)
  158. return
  159. }
  160. // GetCompanyProductTryOutPermissionUpdateNoStopListByEndDate 获取当前正在进行中的客户变更试用品种的数据(未停止的)
  161. func GetCompanyProductTryOutPermissionUpdateNoStopListByEndDate(companyProductUpdateLogId int) (items []*CompanyProductTryOutUpdatePermissionLog, err error) {
  162. o := orm.NewOrm()
  163. 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;`
  164. _, err = o.Raw(sql, companyProductUpdateLogId).QueryRows(&items)
  165. return
  166. }