activity_special_trip.go 6.8 KB

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