rai_serve_bill.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. package rai_serve
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hongze_cygx/utils"
  5. "time"
  6. )
  7. // 权益服务明细表
  8. type CygxRaiServeBill struct {
  9. BillId int `orm:"column(bill_id);pk" description:"服务明细主键ID"`
  10. Content string `comment:"服务内容说明"`
  11. ServeTypeId int `comment:"服务类型ID"`
  12. ServeTypeName string `comment:"服务类型"`
  13. UserId int `comment:"用户ID"`
  14. Mobile string `comment:"手机号"`
  15. Email string `comment:"邮箱"`
  16. CompanyId int `comment:"公司ID"`
  17. CompanyName string `comment:"公司名称"`
  18. RealName string `comment:"用户实际名称"`
  19. RegisterPlatform int `comment:"来源 1小程序,2:网页"`
  20. ServeCount float64 `comment:"服务量小计"`
  21. IsKp int `comment:"是否是KP,1:是、0:否"`
  22. SourceId int `comment:"来源ID"`
  23. Source string `comment:"来源 "`
  24. WeekStartDate string `comment:"周一开始日期"`
  25. WeekEndDate string `comment:"周日结束日期"`
  26. MonthStartDate string `comment:"月份开始日期"`
  27. MonthEndDate string `comment:"月份结束日期"`
  28. ChartPermissionId int `description:"行业id"`
  29. ChartPermissionName string `description:"行业名称"`
  30. CreateTime time.Time `comment:"创建时间"`
  31. ViewTime string `comment:"浏览时间"`
  32. ActivityId int `description:"活动ID"`
  33. RecordId int `description:"日志ID"`
  34. }
  35. // Redis对列消息中的结构体
  36. type RaiServeBillRedis struct {
  37. Content string `comment:"服务内容说明"`
  38. UserId int `comment:"用户ID"`
  39. ComapnyId int `comment:"公司ID"`
  40. SourceId int `comment:"来源ID"`
  41. Source string `comment:"来源"`
  42. RegisterPlatform int `comment:"来源 1小程序,2:网页"`
  43. ViewTime time.Time `comment:"浏览时间"`
  44. }
  45. // 添加
  46. func AddCygxRaiServeBill(item *CygxRaiServeBill) (err error) {
  47. o := orm.NewOrm()
  48. _, err = o.Insert(item)
  49. return
  50. }
  51. func GetCygxRaiServeBillCountByUserAndSource(userId, sourceId int, source string) (count int, err error) {
  52. o := orm.NewOrm()
  53. sql := ` SELECT COUNT(1) AS count FROM cygx_rai_serve_bill WHERE user_id = ? AND source_id = 2 AND source = ? `
  54. err = o.Raw(sql, userId, sourceId, source).QueryRow(&count)
  55. return
  56. }
  57. // 列表
  58. func GetCygxRaiServeBillListAll(condition string, pars []interface{}) (items []*CygxRaiServeBill, err error) {
  59. if condition == "" {
  60. return
  61. }
  62. o := orm.NewOrm()
  63. sql := `SELECT * FROM cygx_rai_serve_bill WHERE 1= 1 `
  64. if condition != "" {
  65. sql += condition
  66. }
  67. _, err = o.Raw(sql, pars).QueryRows(&items)
  68. return
  69. }
  70. // AddCygxRaiServeBillMulti 批量添加
  71. func AddCygxRaiServeBillMulti(items []*CygxRaiServeBill) (err error) {
  72. if len(items) == 0 {
  73. return
  74. }
  75. o, err := orm.NewOrm().Begin()
  76. if err != nil {
  77. return
  78. }
  79. defer func() {
  80. if err == nil {
  81. o.Commit()
  82. } else {
  83. o.Rollback()
  84. }
  85. }()
  86. if len(items) > 0 {
  87. //批量添加流水信息
  88. _, err = o.InsertMulti(len(items), items)
  89. }
  90. return
  91. }
  92. // 批量删除
  93. func DelCygxRaiServeCompanyMulti(delBillIds []int) (err error) {
  94. lenArr := len(delBillIds)
  95. if lenArr == 0 {
  96. return
  97. }
  98. o := orm.NewOrm()
  99. sql := ` DELETE FROM cygx_rai_serve_bill WHERE bill_id IN (` + utils.GetOrmInReplace(lenArr) + `) `
  100. _, err = o.Raw(sql, delBillIds).Exec()
  101. return
  102. }
  103. // UpdateActivitySignupDetailMulti 批量修改
  104. func UpdateCygxRaiServeBillMulti(items []*CygxRaiServeBill) (err error) {
  105. o := orm.NewOrm()
  106. p, err := o.Raw(` UPDATE cygx_rai_serve_bill SET
  107. month_start_date = ?,
  108. month_end_date = ?
  109. WHERE bill_id = ? `).Prepare()
  110. if err != nil {
  111. return
  112. }
  113. defer func() {
  114. _ = p.Close() // 别忘记关闭 statement
  115. }()
  116. for _, v := range items {
  117. _, err = p.Exec(
  118. v.MonthStartDate,
  119. v.MonthEndDate,
  120. v.BillId)
  121. if err != nil {
  122. return
  123. }
  124. }
  125. return
  126. }