activity_special_trip_bill.go 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CygxActivitySpecialTripBill struct {
  7. Id int `orm:"column(id);pk"`
  8. UserId int `description:"用户id,多个用,隔开"`
  9. ActivityId int `description:"活动ID"`
  10. CreateTime time.Time `description:"创建时间"`
  11. Mobile string `description:"手机号"`
  12. Email string `description:"邮箱号"`
  13. CompanyId int `description:"公司ID"`
  14. CompanyName string `description:"公司名称"`
  15. RealName string `description:"用户实际名称"`
  16. AdminId int `description:"销售/管理员ID"`
  17. Source int `description:"来源,1小程序,2后台添加, 3开发人员手动添加"`
  18. BillDetailed float64 `description:"流水明细,判断是进账还是出账"`
  19. DoType int `description:"操作方式,1报名,2取消报名"`
  20. RegisterPlatform int `description:"来源 1小程序,2:网页"`
  21. ChartPermissionId int `description:"行业id"`
  22. ChartPermissionName string `description:"行业名称"`
  23. Way int `description:"1报名,取消报名。2到会取消到会 3转正或清零 4取消活动"`
  24. Content string `description:"内容"`
  25. Total string `description:"总和"`
  26. TableSource string `description:"活动类型来源 活动 :activity 、专项调研活动:activityspecial、路演:roadshow"`
  27. ResearcherId int `description:"研究员id"`
  28. ResearcherName string `description:"研究员名称"`
  29. }
  30. // 添加
  31. func AddCygxActivitySpecialTripBill(item *CygxActivitySpecialTripBill) (err error) {
  32. o := orm.NewOrm()
  33. _, err = o.Insert(item)
  34. if err != nil {
  35. return
  36. }
  37. return
  38. }
  39. func GetCygxActivitySpecialTripBill(condition string, pars []interface{}) (item []*CygxActivitySpecialTripBill, err error) {
  40. o := orm.NewOrm()
  41. sql := `SELECT *
  42. FROM
  43. cygx_activity_special_trip_bill
  44. WHERE 1 = 1 ` + condition
  45. _, err = o.Raw(sql, pars).QueryRows(&item)
  46. return
  47. }
  48. type CygxActivitySpecialTripBillList struct {
  49. Id int `orm:"column(id);pk"`
  50. UserId int `description:"用户id,多个用,隔开"`
  51. ActivityId int `description:"活动ID"`
  52. CreateTime time.Time `description:"创建时间"`
  53. Mobile string `description:"手机号"`
  54. Email string `description:"邮箱号"`
  55. CompanyId int `description:"公司ID"`
  56. CompanyName string `description:"公司名称"`
  57. RealName string `description:"用户实际名称"`
  58. AdminId int `description:"销售/管理员ID"`
  59. Source int `description:"来源,1小程序,2后台添加, 3开发人员手动添加"`
  60. BillDetailed int `description:"流水明细,判断是进账还是出账"`
  61. DoType int `description:"操作方式,1报名,2取消报名"`
  62. RegisterPlatform int `description:"来源 1小程序,2:网页"`
  63. ChartPermissionId int `description:"行业id"`
  64. ChartPermissionName string `description:"行业名称"`
  65. Way int `description:"1报名,取消报名。2到会取消到会 3转正或清零 4取消活动"`
  66. Content string `description:"内容"`
  67. }
  68. func GetCygxActivitySpecialTripBillList(condition string, pars []interface{}) (item []*CygxActivitySpecialTripBillList, err error) {
  69. o := orm.NewOrm()
  70. sql := `SELECT
  71. b.*
  72. FROM
  73. cygx_activity_special_trip_bill AS b
  74. WHERE
  75. 1 = 1` + condition
  76. _, err = o.Raw(sql, pars).QueryRows(&item)
  77. return
  78. }
  79. // 通过查询条件获取详情
  80. func GetCygxActivitySpecialTripBillByCondition(condition string, pars []interface{}) (item *CygxActivitySpecialTripBill, err error) {
  81. if condition == "" {
  82. return
  83. }
  84. o := orm.NewOrm()
  85. sql := `SELECT * FROM cygx_activity_special_trip_bill WHERE 1 = 1 ` + condition
  86. err = o.Raw(sql, pars).QueryRow(&item)
  87. return
  88. }
  89. // GetCygxActivitySpecialTripBillLastDetialByActivityId 根据活动ID获取最后一条扣点明细
  90. func GetCygxActivitySpecialTripBillLastDetialByActivityId(activityId, userId int) (item *CygxActivitySpecialTripBill, err error) {
  91. o := orm.NewOrm()
  92. sql := `SELECT *
  93. FROM
  94. cygx_activity_special_trip_bill
  95. WHERE 1 = 1 AND activity_id =? AND user_id = ? ORDER BY id DESC LIMIT 1 `
  96. err = o.Raw(sql, activityId, userId).QueryRow(&item)
  97. return
  98. }
  99. // AddCygxActivitySpecialTripBillMulti 批量添加
  100. func AddCygxActivitySpecialTripBillMulti(items []*CygxActivitySpecialTripBill, itemsUpdate []*CygxActivitySpecialPermissionPoints) (err error) {
  101. o, err := orm.NewOrm().Begin()
  102. if err != nil {
  103. return
  104. }
  105. defer func() {
  106. if err == nil {
  107. o.Commit()
  108. } else {
  109. o.Rollback()
  110. }
  111. }()
  112. if len(items) > 0 {
  113. //批量添加流水信息
  114. _, err = o.InsertMulti(len(items), items)
  115. }
  116. //批量修改公司剩余点数
  117. p, err := o.Raw("UPDATE cygx_activity_special_permission_points SET points = ?, modify_time = ? WHERE company_id = ?").Prepare()
  118. if err != nil {
  119. return
  120. }
  121. defer func() {
  122. _ = p.Close() // 别忘记关闭 statement
  123. }()
  124. for _, v := range itemsUpdate {
  125. _, err = p.Exec(v.Points, v.ModifyTime, v.CompanyId)
  126. if err != nil {
  127. return
  128. }
  129. }
  130. return
  131. }
  132. // 删除
  133. func DelCygxActivitySpecialTripBillById(id int) (err error) {
  134. o := orm.NewOrm()
  135. sql := ` DELETE FROM cygx_activity_special_trip_bill WHERE id = ? `
  136. _, err = o.Raw(sql, id).Exec()
  137. return
  138. }