activity_special_trip.go 7.8 KB

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