activity_special_trip.go 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. package models
  2. import (
  3. "fmt"
  4. //"hongze/hongze_admin/models"
  5. "github.com/beego/beego/v2/client/orm"
  6. "time"
  7. )
  8. type CygxActivitySpecialTrip struct {
  9. Id int `orm:"column(id);pk"`
  10. UserId int `description:"用户id,多个用,隔开"`
  11. ActivityId int `description:"活动ID"`
  12. CreateTime time.Time `description:"创建时间"`
  13. Mobile string `description:"手机号"`
  14. Email string `description:"邮箱号"`
  15. CompanyId int `description:"公司ID"`
  16. CompanyName string `description:"公司名称"`
  17. RealName string `description:"用户实际名称"`
  18. SellerName string `description:"所属销售"`
  19. AdminId int `description:"销售/管理员ID"`
  20. Source int `description:"来源,1小程序,2后台添加"`
  21. OutboundMobile string `description:"外呼手机号"`
  22. CountryCode string `description:"手机国家区号"`
  23. IsCancel string `description:"是否取消,1是,0否"`
  24. IsValid int `description:"参会报名是否有效 1:是,0"`
  25. }
  26. type CygxActivitySpecialTripResp struct {
  27. Id int `description:"ID"`
  28. UserId int `description:"用户id"`
  29. ActivityId int `description:"活动ID"`
  30. CreateTime string `description:"创建时间"`
  31. Mobile string `description:"手机号"`
  32. Email string `description:"邮箱号"`
  33. CompanyId int `description:"公司ID"`
  34. CompanyName string `description:"公司名称"`
  35. RealName string `description:"用户实际名称"`
  36. SellerName string `description:"所属销售"`
  37. OutboundMobile string `description:"外呼手机号"`
  38. CountryCode string `description:"手机国家区号"`
  39. }
  40. func GetCygxActivitySpecialTripList(condition string, pars []interface{}) (item []*CygxActivitySpecialTripResp, err error) {
  41. o := orm.NewOrm()
  42. sql := `SELECT *
  43. FROM
  44. cygx_activity_special_trip
  45. WHERE 1 = 1 ` + condition
  46. _, err = o.Raw(sql, pars).QueryRows(&item)
  47. return
  48. }
  49. // 获取某一用户的报名的数量
  50. func GetUserActivitySpecialTripCount(uid, activityId int) (count int, err error) {
  51. sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_special_trip WHERE user_id=? AND activity_id =? `
  52. o := orm.NewOrm()
  53. err = o.Raw(sqlCount, uid, activityId).QueryRow(&count)
  54. return
  55. }
  56. // 获取某一活动的报名的数量
  57. func GetActivitySpecialTripCountByActivityId(condition string, pars []interface{}) (count int, err error) {
  58. sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_special_trip as t INNER JOIN wx_user as u on u.user_id = t.user_id WHERE 1 = 1 ` + condition
  59. o := orm.NewOrm()
  60. err = o.Raw(sqlCount, pars).QueryRow(&count)
  61. return
  62. }
  63. // 获取某一活动的报名的数量 (同时关联活动类型进行获取)
  64. func GetActivitySpecialTripCountByActivitySpecial(condition string, pars []interface{}) (count int, err error) {
  65. sqlCount := ` SELECT COUNT(1) AS count
  66. FROM
  67. cygx_activity_special_trip AS t
  68. INNER JOIN cygx_activity_special AS a ON a.activity_id = t.activity_id
  69. WHERE
  70. 1= 1 ` + condition
  71. o := orm.NewOrm()
  72. err = o.Raw(sqlCount, pars).QueryRow(&count)
  73. return
  74. }
  75. // 获取空降的公司报名的记录
  76. func GetActivitySpecialTripAirborneCountByActivitySpecial(condition string, pars []interface{}) (count int, err error) {
  77. sqlCount := ` SELECT COUNT(1) AS count
  78. FROM
  79. cygx_activity_special_meeting_detail AS t
  80. INNER JOIN cygx_activity_special AS a ON a.activity_id = t.activity_id
  81. WHERE
  82. 1= 1 AND YEAR ( t.create_time )= YEAR (NOW()) ` + condition
  83. o := orm.NewOrm()
  84. err = o.Raw(sqlCount, pars).QueryRow(&count)
  85. return
  86. }
  87. // 添加
  88. func AddCygxActivitySpecialTrip(item *CygxActivitySpecialTrip) (err error) {
  89. o, err := orm.NewOrm().Begin()
  90. if err != nil {
  91. return
  92. }
  93. defer func() {
  94. fmt.Println(err)
  95. if err == nil {
  96. o.Commit()
  97. } else {
  98. o.Rollback()
  99. }
  100. }()
  101. _, err = o.Insert(item)
  102. if err != nil {
  103. return
  104. }
  105. //itemBill := new(CygxActivitySpecialTripBill)
  106. //itemBill.UserId = item.UserId
  107. //itemBill.ActivityId = item.ActivityId
  108. //itemBill.CreateTime = time.Now()
  109. //itemBill.Mobile = item.Mobile
  110. //itemBill.Email = item.Email
  111. //itemBill.CompanyId = item.CompanyId
  112. //itemBill.CompanyName = item.CompanyName
  113. //itemBill.RealName = item.RealName
  114. //itemBill.Source = 1
  115. //itemBill.BillDetailed = -1 // 流水减一
  116. //itemBill.DoType = 1
  117. //itemBill.RegisterPlatform = 1
  118. //itemBill.ChartPermissionId = itemActivity.ChartPermissionId
  119. //
  120. //_, err = o.Insert(itemBill)
  121. //if err != nil {
  122. // return
  123. //}
  124. return
  125. }
  126. // 取消
  127. func CancelActivitySpecialTrip(uid int, item *CygxActivitySpecialDetail) (err error) {
  128. o := orm.NewOrm()
  129. sql := `DELETE FROM cygx_activity_special_trip WHERE user_id=? AND activity_id=? `
  130. _, err = o.Raw(sql, uid, item.ActivityId).Exec()
  131. return
  132. }
  133. // CancelActivitySpecialTripIsValid 处理活动报名是否有效
  134. func CancelActivitySpecialTripIsValid(isValid, activityId, userId int) (err error) {
  135. sql := ` UPDATE cygx_activity_special_trip SET is_valid= ?,is_cancel = 1 WHERE activity_id = ? AND user_id = ? `
  136. o := orm.NewOrm()
  137. _, err = o.Raw(sql, isValid, activityId, userId).Exec()
  138. return
  139. }
  140. type CygxActivitySpecialTripInit struct {
  141. Id int `orm:"column(id);pk"`
  142. UserId int `description:"用户id,多个用,隔开"`
  143. ActivityId int `description:"活动ID"`
  144. CreateTime time.Time `description:"创建时间"`
  145. Mobile string `description:"手机号"`
  146. Email string `description:"邮箱号"`
  147. CompanyId int `description:"公司ID"`
  148. CompanyName string `description:"公司名称"`
  149. RealName string `description:"用户实际名称"`
  150. SellerName string `description:"所属销售"`
  151. AdminId int `description:"销售/管理员ID"`
  152. Source int `description:"来源,1小程序,2后台添加"`
  153. OutboundMobile string `description:"外呼手机号"`
  154. CountryCode string `description:"手机国家区号"`
  155. IsCancel string `description:"是否取消,1是,0否"`
  156. IsValid int `description:"参会报名是否有效 1:是,0"`
  157. ChartPermissionId int `description:"行业Id"`
  158. }
  159. func GetCygxActivitySpecialTripListinit(condition string, pars []interface{}) (item []*CygxActivitySpecialTripInit, err error) {
  160. o := orm.NewOrm()
  161. sql := `SELECT
  162. t.*,
  163. a.chart_permission_id
  164. FROM
  165. cygx_activity_special_trip AS t
  166. INNER JOIN cygx_activity_special AS a ON a.activity_id = t.activity_id
  167. WHERE
  168. 1 = 1
  169. AND is_valid = 1 ` + condition
  170. _, err = o.Raw(sql, pars).QueryRows(&item)
  171. return
  172. }