activity_special_trip.go 7.6 KB

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