rai_serve_bill.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. ChartPermissionId int `description:"行业id"`
  27. ChartPermissionName string `description:"行业名称"`
  28. CreateTime time.Time `comment:"创建时间"`
  29. ViewTime string `comment:"浏览时间"`
  30. }
  31. // Redis对列消息中的结构体
  32. type RaiServeBillRedis struct {
  33. Content string `comment:"服务内容说明"`
  34. UserId int `comment:"用户ID"`
  35. ComapnyId int `comment:"公司ID"`
  36. SourceId int `comment:"来源ID"`
  37. Source string `comment:"来源"`
  38. RegisterPlatform int `comment:"来源 1小程序,2:网页"`
  39. ViewTime time.Time `comment:"浏览时间"`
  40. }
  41. // 添加
  42. func AddCygxRaiServeBill(item *CygxRaiServeBill) (err error) {
  43. o := orm.NewOrm()
  44. _, err = o.Insert(item)
  45. return
  46. }
  47. func GetCygxRaiServeBillCountByUserAndSource(userId, sourceId int, source string) (count int, err error) {
  48. o := orm.NewOrm()
  49. sql := ` SELECT COUNT(1) AS count FROM cygx_rai_serve_bill WHERE user_id = ? AND source_id = 2 AND source = ? `
  50. err = o.Raw(sql, userId, sourceId, source).QueryRow(&count)
  51. return
  52. }
  53. // 列表
  54. func GetCygxRaiServeBillListAll(condition string, pars []interface{}) (items []*CygxRaiServeBill, err error) {
  55. if condition == "" {
  56. return
  57. }
  58. o := orm.NewOrm()
  59. sql := `SELECT * FROM cygx_rai_serve_bill WHERE 1= 1 `
  60. if condition != "" {
  61. sql += condition
  62. }
  63. _, err = o.Raw(sql, pars).QueryRows(&items)
  64. return
  65. }
  66. // AddCygxRaiServeBillMulti 批量添加
  67. func AddCygxRaiServeBillMulti(items []*CygxRaiServeBill) (err error) {
  68. if len(items) == 0 {
  69. return
  70. }
  71. o, err := orm.NewOrm().Begin()
  72. if err != nil {
  73. return
  74. }
  75. defer func() {
  76. if err == nil {
  77. o.Commit()
  78. } else {
  79. o.Rollback()
  80. }
  81. }()
  82. if len(items) > 0 {
  83. //批量添加流水信息
  84. _, err = o.InsertMulti(len(items), items)
  85. }
  86. return
  87. }
  88. // 批量删除
  89. func DelCygxRaiServeCompanyMulti(delBillIds []int) (err error) {
  90. lenArr := len(delBillIds)
  91. if lenArr == 0 {
  92. return
  93. }
  94. o := orm.NewOrm()
  95. sql := ` DELETE FROM cygx_rai_serve_bill WHERE bill_id IN (` + utils.GetOrmInReplace(lenArr) + `) `
  96. _, err = o.Raw(sql, delBillIds).Exec()
  97. return
  98. }