activity_points_bill.go 6.4 KB

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