activity_special_permission_points.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package cygx
  2. import (
  3. //"github.com/beego/beego/v2/client/orm"
  4. "github.com/beego/beego/v2/client/orm"
  5. "hongze/hz_crm_api/utils"
  6. "time"
  7. )
  8. type CygxActivitySpecialPermissionPoints struct {
  9. Id int `orm:"column(id);pk"`
  10. CompanyId int `description:"公司ID"`
  11. Points int `description:"剩余点数"`
  12. CompanyName string `description:"公司名称"`
  13. ChartPermissionId int `description:"行业id"`
  14. ChartPermissionName string `description:"行业名称"`
  15. CreateTime time.Time `description:"创建时间"`
  16. ModifyTime time.Time `description:"更新时间"`
  17. }
  18. // 添加
  19. func AddCygxActivitySpecialPermissionPoints(item *CygxActivitySpecialPermissionPoints) (err error) {
  20. o := orm.NewOrmUsingDB("hz_cygx")
  21. _, err = o.Insert(item)
  22. return
  23. }
  24. // MultiAddCygxActivitySpecialPermissionPoints 批量添加
  25. func MultiAddCygxActivitySpecialPermissionPoints(items []*CygxActivitySpecialPermissionPoints) (err error) {
  26. if len(items) == 0 {
  27. return
  28. }
  29. var chartPermissionIds []int
  30. var companyId int
  31. for _, v := range items {
  32. companyId = v.CompanyId
  33. if v.ChartPermissionId > 0 {
  34. chartPermissionIds = append(chartPermissionIds, v.ChartPermissionId)
  35. }
  36. }
  37. lenchartPermissionIds := len(chartPermissionIds)
  38. o, err := orm.NewOrmUsingDB("hz_cygx").Begin()
  39. if err != nil {
  40. return
  41. }
  42. defer func() {
  43. if err == nil {
  44. o.Commit()
  45. } else {
  46. o.Rollback()
  47. }
  48. }()
  49. var condition string
  50. var pars []interface{}
  51. pars = make([]interface{}, 0)
  52. condition = " AND company_id = ? "
  53. pars = append(pars, companyId)
  54. if lenchartPermissionIds > 0 {
  55. condition += " AND chart_permission_id IN (" + utils.GetOrmInReplace(lenchartPermissionIds) + ") "
  56. pars = append(pars, chartPermissionIds)
  57. }
  58. //删除历史记录
  59. sql := ""
  60. if condition != "" {
  61. sql = " DELETE FROM cygx_activity_special_permission_points WHERE 1= 1 " + condition
  62. _, err = o.Raw(sql, pars).Exec()
  63. if err != nil {
  64. return
  65. }
  66. }
  67. //批量插入
  68. _, err = o.InsertMulti(len(items), items)
  69. if err != nil {
  70. return
  71. }
  72. return
  73. }
  74. // 获取公司每个行业剩余研选点数列表
  75. func GetCygxActivitySpecialPermissionPointsList(condition string, pars []interface{}) (items []*CygxActivitySpecialPermissionPoints, err error) {
  76. o := orm.NewOrmUsingDB("hz_cygx")
  77. sql := `SELECT * FROM cygx_activity_special_permission_points WHERE 1 = 1 `
  78. if condition != "" {
  79. sql += condition
  80. }
  81. _, err = o.Raw(sql, pars).QueryRows(&items)
  82. return
  83. }
  84. // 更新公司每个行业剩余研选点数
  85. func UpdateCygxActivitySpecialPermissionPoints(points, companyId, chartPermissionId int) (err error) {
  86. o := orm.NewOrmUsingDB("hz_cygx")
  87. sql := `UPDATE cygx_activity_special_permission_points SET points = ? WHERE company_id=? AND chart_permission_id=? `
  88. _, err = o.Raw(sql, points, companyId, chartPermissionId).Exec()
  89. return
  90. }
  91. // 获取客户是否有研选扣点点数
  92. func GetCygxActivitySpecialPermissionPointsCount(companyId int) (count int, err error) {
  93. o := orm.NewOrmUsingDB("hz_cygx")
  94. sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_special_permission_points WHERE company_id=? `
  95. err = o.Raw(sqlCount, companyId).QueryRow(&count)
  96. return
  97. }