rai_serve_company.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. package rai_serve
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hongze_cygx/utils"
  5. "time"
  6. )
  7. type CygxRaiServeCompany struct {
  8. ServeCompanyId int `comment:"ServeCompanyId 主键ID"`
  9. CompanyId int `comment:"公司ID"`
  10. CompanyName string `comment:"公司名称"`
  11. CreateTime time.Time `comment:"创建时间"`
  12. Money float64 `comment:"合同金额"`
  13. ServeCoverageRate string `comment:"近四周服务覆盖率"`
  14. SellerId int `comment:"所属销售id"`
  15. SellerName string `comment:"所属销售名称"`
  16. StartDate string `comment:"开始日期"`
  17. EndDate string `comment:"结束日期"`
  18. ShareSeller string `comment:"共享销售"`
  19. ShareSellerId int `comment:"共享销售员id"`
  20. GroupId int `description:"销售分组id"`
  21. ShareGroupId int `description:"共享销售分组id"`
  22. Status string `comment:"客户状态"`
  23. PermissionName string `comment:"权限名"`
  24. IsUserMaker int `comment:"近四周之内是否包含决策人 ,1是、0否"`
  25. }
  26. func AddCygxRaiServeCompanyMulti(items, itemsUpdate []*CygxRaiServeCompany, delCompanyIds []int) (err error) {
  27. o, err := orm.NewOrm().Begin()
  28. if err != nil {
  29. return
  30. }
  31. defer func() {
  32. if err == nil {
  33. o.Commit()
  34. } else {
  35. o.Rollback()
  36. }
  37. }()
  38. if len(delCompanyIds) > 0 {
  39. //删除不属于权益共享的公司
  40. sql := ` DELETE FROM cygx_rai_serve_company WHERE company_id IN (` + utils.GetOrmInReplace(len(delCompanyIds)) + `) `
  41. _, err = o.Raw(sql, delCompanyIds).Exec()
  42. if err != nil {
  43. return
  44. }
  45. }
  46. //批量插入新的关联数据
  47. if len(items) > 0 {
  48. //批量添加流水信息
  49. _, err = o.InsertMulti(len(items), items)
  50. if err != nil {
  51. return
  52. }
  53. }
  54. if len(itemsUpdate) > 0 {
  55. p, errUpdate := o.Raw("UPDATE cygx_rai_serve_company SET company_name = ? ,seller_id =? ,seller_name = ? ,start_date = ? ,end_date = ? ,share_seller = ? ,share_seller_id = ? ,group_id = ? ,share_group_id = ?,status = ? WHERE company_id = ?").Prepare()
  56. if errUpdate != nil {
  57. err = errUpdate
  58. return
  59. }
  60. defer func() {
  61. _ = p.Close() // 别忘记关闭 statement
  62. }()
  63. for _, v := range itemsUpdate {
  64. _, err = p.Exec(v.CompanyName, v.SellerId, v.SellerName, v.StartDate, v.EndDate, v.ShareSeller, v.ShareSellerId, v.GroupId, v.ShareGroupId, v.Status, v.CompanyId)
  65. if err != nil {
  66. return
  67. }
  68. }
  69. }
  70. return
  71. }
  72. // UpdateCygxRaiServeCompanyMulti 批量修改正式客户信息
  73. func UpdateCygxRaiServeCompanyMulti(items []*CygxRaiServeCompany) (err error) {
  74. o := orm.NewOrm()
  75. p, err := o.Raw("UPDATE cygx_rai_serve_company SET money = ? ,serve_coverage_rate =? ,permission_name = ? ,is_user_maker = ? WHERE company_id = ?").Prepare()
  76. if err != nil {
  77. return
  78. }
  79. defer func() {
  80. _ = p.Close() // 别忘记关闭 statement
  81. }()
  82. for _, v := range items {
  83. _, err = p.Exec(v.Money, v.ServeCoverageRate, v.PermissionName, v.IsUserMaker, v.CompanyId)
  84. if err != nil {
  85. return
  86. }
  87. }
  88. return
  89. }
  90. // UpdateCygxRaiServeCompanyFormalNoMulti 批量修改非正式客户信息
  91. func UpdateCygxRaiServeCompanyFormalNoMulti(items []*CygxRaiServeCompany) (err error) {
  92. o := orm.NewOrm()
  93. p, err := o.Raw("UPDATE cygx_rai_serve_company SET money = ? , serve_coverage_rate =? ,permission_name = ? , start_date = ? , end_date = ? ,is_user_maker = ? WHERE company_id = ?").Prepare()
  94. if err != nil {
  95. return
  96. }
  97. defer func() {
  98. _ = p.Close() // 别忘记关闭 statement
  99. }()
  100. for _, v := range items {
  101. _, err = p.Exec(v.Money, v.ServeCoverageRate, v.PermissionName, v.StartDate, v.EndDate, v.IsUserMaker, v.CompanyId)
  102. if err != nil {
  103. return
  104. }
  105. }
  106. return
  107. }
  108. // UpdateCygxRaiServeCompanyFormalNoContractMulti 批量修改非正式,且没有签约过合同的客户信息
  109. func UpdateCygxRaiServeCompanyFormalNoContractMulti(items []*CygxRaiServeCompany) (err error) {
  110. o := orm.NewOrm()
  111. p, err := o.Raw("UPDATE cygx_rai_serve_company SET serve_coverage_rate =? ,is_user_maker = ? WHERE company_id = ?").Prepare()
  112. if err != nil {
  113. return
  114. }
  115. defer func() {
  116. _ = p.Close() // 别忘记关闭 statement
  117. }()
  118. for _, v := range items {
  119. _, err = p.Exec(v.ServeCoverageRate, v.IsUserMaker, v.CompanyId)
  120. if err != nil {
  121. return
  122. }
  123. }
  124. return
  125. }
  126. // 获取当前所属权益服务公司表所有ID
  127. func GetCygxRaiServeCompanyAllList() (items []*CygxRaiServeCompany, err error) {
  128. o := orm.NewOrm()
  129. sql := ` SELECT * FROM cygx_rai_serve_company LIMIT 1000 `
  130. _, err = o.Raw(sql).QueryRows(&items)
  131. return
  132. }