activity_points_bill.go 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. // CygxActivityPointsBill 活动扣点流水表
  7. type CygxActivityPointsBill struct {
  8. Id int `gorm:"column:id;primary_key;AUTO_INCREMENT" json:""`
  9. UserId int `gorm:"column:user_id;NOT NULL" json:""` // 用户ID
  10. ActivityId int `gorm:"column:activity_id;default:0;NOT NULL" json:""` // 活动ID
  11. CreateTime time.Time `gorm:"column:create_time" json:""` // 创建时间
  12. Mobile string `gorm:"column:mobile" json:""` // 手机号
  13. Email string `gorm:"column:email" json:""` // 邮箱
  14. CompanyId int `gorm:"column:company_id;default:0" json:""` // 公司ID
  15. CompanyName string `gorm:"column:company_name" json:""` // 公司名称
  16. RealName string `gorm:"column:real_name" json:""` // 用户实际名称
  17. AdminId int `gorm:"column:admin_id;NOT NULL" json:""` // 管理员、销售ID
  18. Source int `gorm:"column:source;default:1;NOT NULL" json:""` // 来源,1客户端,2后台添加, 3开发人员手动添加、4定时任务
  19. BillDetailed float64 `gorm:"column:bill_detailed;default:0;NOT NULL" json:""` // 流水明细,判断是进账还是出账
  20. RegisterPlatform int `gorm:"column:register_platform;default:0;NOT NULL" json:""` // 来源 1小程序,2:网页
  21. ChartPermissionId int `gorm:"column:chart_permission_id;default:0" json:""` // 表chart_permission中id
  22. DoType int `gorm:"column:do_type;default:1;NOT NULL" json:""` // 操作方式,1减少,2增加
  23. Content string `gorm:"column:content" json:""` // 内容说明
  24. Points float64 `gorm:"column:points;default:0;NOT NULL" json:""` // 公司剩余点数
  25. }
  26. // 获取列表
  27. func GetCygxActivityPointsBillList(condition string, pars []interface{}) (list []*CygxActivityPointsBill, err error) {
  28. sql := `SELECT * FROM cygx_activity_points_bill WHERE 1= 1 `
  29. if condition != "" {
  30. sql += condition
  31. }
  32. _, err = orm.NewOrm().Raw(sql, pars).QueryRows(&list)
  33. return
  34. }
  35. // CompanyTryOutDayListResp 客户累计试用天数
  36. type CygxActivityPointsBillListResp struct {
  37. List []*CygxActivityPointsBillResp
  38. }
  39. type CygxActivityPointsBillResp struct {
  40. Id int `gorm:"column:id;primary_key;AUTO_INCREMENT"`
  41. Content string `gorm:"column:content" ` // 内容说明
  42. Points float64 `gorm:"column:points;default:0;NOT NULL" ` // 公司剩余点数
  43. CreateTime string `gorm:"column:create_time" ` // 创建时间
  44. CompanyId int `gorm:"column:company_id;default:0" ` // 公司ID
  45. CompanyName string `gorm:"column:company_name" ` // 公司名称
  46. RealName string `gorm:"column:real_name"` // 用户实际名称
  47. BillDetailed float64 `gorm:"column:bill_detailed;default:0;NOT NULL" json:""` // 流水明细,判断是进账还是出账
  48. }
  49. // 获取数量
  50. func GetCygxActivityPointsBillCount(condition string, pars []interface{}) (count int, err error) {
  51. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_activity_points_bill as art WHERE 1= 1 `
  52. if condition != "" {
  53. sqlCount += condition
  54. }
  55. o := orm.NewOrm()
  56. err = o.Raw(sqlCount, pars).QueryRow(&count)
  57. return
  58. }
  59. // 通过查询条件获取详情
  60. func GetCygxActivityPointsBillDetailByCondition(condition string, pars []interface{}) (item *CygxActivityPointsBill, err error) {
  61. if condition == "" {
  62. return
  63. }
  64. o := orm.NewOrm()
  65. sql := `SELECT * FROM cygx_activity_points_bill WHERE 1 = 1 ` + condition
  66. err = o.Raw(sql, pars).QueryRow(&item)
  67. return
  68. }
  69. // AddCygxActivityPointsBillMulti 批量添加
  70. func AddCygxActivityPointsBillMulti(items []*CygxActivityPointsBill, itemsUpdate []*CygxActivityPointsCompany) (err error) {
  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. //批量修改公司剩余点数
  87. p, err := o.Raw("UPDATE cygx_activity_points_company SET points = ?, modify_time = ? WHERE company_id = ?").Prepare()
  88. if err != nil {
  89. return
  90. }
  91. defer func() {
  92. _ = p.Close() // 别忘记关闭 statement
  93. }()
  94. for _, v := range itemsUpdate {
  95. _, err = p.Exec(v.Points, v.ModifyTime, v.CompanyId)
  96. if err != nil {
  97. return
  98. }
  99. }
  100. return
  101. }
  102. // AddCygxActivityPointsBillAndCompanyMulti 批量添加
  103. func AddCygxActivityPointsBillAndCompanyMulti(items []*CygxActivityPointsBill, itemsCompany []*CygxActivityPointsCompany) (err error) {
  104. o, err := orm.NewOrm().Begin()
  105. if err != nil {
  106. return
  107. }
  108. defer func() {
  109. if err == nil {
  110. o.Commit()
  111. } else {
  112. o.Rollback()
  113. }
  114. }()
  115. if len(items) > 0 {
  116. //批量添加流水信息
  117. _, err = o.InsertMulti(len(items), items)
  118. }
  119. if len(itemsCompany) > 0 {
  120. //批量添加流水信息
  121. _, err = o.InsertMulti(len(itemsCompany), itemsCompany)
  122. }
  123. return
  124. }
  125. // UpdateCygxActivityPointsBillMulti 批量修改
  126. func UpdateCygxActivityPointsBillMulti(items []*CygxActivityPointsBill, itemsUpdate []*CygxActivityPointsCompany) (err error) {
  127. o, err := orm.NewOrm().Begin()
  128. if err != nil {
  129. return
  130. }
  131. defer func() {
  132. if err == nil {
  133. o.Commit()
  134. } else {
  135. o.Rollback()
  136. }
  137. }()
  138. //批量修改公司剩余点数
  139. p, err := o.Raw("UPDATE cygx_activity_points_bill SET points = ?, bill_detailed = ? WHERE id = ?").Prepare()
  140. if err != nil {
  141. return
  142. }
  143. defer func() {
  144. _ = p.Close() // 别忘记关闭 statement
  145. }()
  146. for _, v := range items {
  147. _, err = p.Exec(v.Points, v.BillDetailed, v.Id)
  148. if err != nil {
  149. return
  150. }
  151. }
  152. //批量修改公司剩余点数
  153. p, err = o.Raw("UPDATE cygx_activity_points_company SET points = ?, modify_time = ? WHERE company_id = ?").Prepare()
  154. if err != nil {
  155. return
  156. }
  157. defer func() {
  158. _ = p.Close() // 别忘记关闭 statement
  159. }()
  160. for _, v := range itemsUpdate {
  161. _, err = p.Exec(v.Points, v.ModifyTime, v.CompanyId)
  162. if err != nil {
  163. return
  164. }
  165. }
  166. return
  167. }