rai_serve_bill.go 3.4 KB

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