activity_special_trip.go 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. package cygx
  2. import (
  3. //"hongze/hongze_admin/models"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. type CygxActivitySpecialTrip struct {
  8. Id int `orm:"column(id);pk"`
  9. UserId int `description:"用户id,多个用,隔开"`
  10. ActivityId int `description:"活动ID"`
  11. CreateTime time.Time `description:"创建时间"`
  12. Mobile string `description:"手机号"`
  13. Email string `description:"邮箱号"`
  14. CompanyId int `description:"公司ID"`
  15. CompanyName string `description:"公司名称"`
  16. RealName string `description:"用户实际名称"`
  17. SellerName string `description:"所属销售"`
  18. AdminId int `description:"销售/管理员ID"`
  19. Source int `description:"来源,1小程序,2后台添加"`
  20. IsMeeting int `description:"是否到会"`
  21. OutboundMobile string `description:"外呼手机号"`
  22. CountryCode string `description:"手机国家区号"`
  23. }
  24. type CygxActivitySpecialTripResp struct {
  25. Id int `description:"ID"`
  26. UserId int `description:"用户id"`
  27. ActivityId int `description:"活动ID"`
  28. CreateTime string `description:"创建时间"`
  29. Mobile string `description:"手机号"`
  30. Email string `description:"邮箱号"`
  31. CompanyId int `description:"公司ID"`
  32. CompanyName string `description:"公司名称"`
  33. RealName string `description:"用户实际名称"`
  34. SellerName string `description:"所属销售"`
  35. AdminId int `description:"销售/管理员ID"`
  36. Source int `description:"来源,1小程序,2后台添加"`
  37. OutboundMobile string `description:"外呼手机号"`
  38. CountryCode string `description:"手机国家区号"`
  39. SpecialType int `description:"调研形式、 1 线上 , 2 线下"`
  40. }
  41. // 修改外呼电话以及区号
  42. type ActivitySpecialTripCancelReq struct {
  43. UserId int `description:"用户id"`
  44. ActivityId int `description:"活动ID"`
  45. }
  46. func GetActivitySpecialTripCountByActivityId(activityId int) (count int, err error) {
  47. sqlCount := `SELECT
  48. COUNT( 1 ) AS count
  49. FROM
  50. cygx_activity_special_trip AS s
  51. WHERE
  52. s.is_cancel = 0
  53. AND s.activity_id = ? `
  54. o := orm.NewOrmUsingDB("hz_cygx")
  55. err = o.Raw(sqlCount, activityId).QueryRow(&count)
  56. return
  57. }
  58. func GetActivitySpecialTripCountByThisUser(activityId int, uids string) (count int, err error) {
  59. sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_special_trip WHERE is_cancel = 0 AND activity_id=? AND user_id IN (` + uids + `) `
  60. o := orm.NewOrmUsingDB("hz_cygx")
  61. err = o.Raw(sqlCount, activityId).QueryRow(&count)
  62. return
  63. }
  64. // 获取用户报名数量
  65. func GetActivitySpecialTripCount(uid, activityId int) (count int, err error) {
  66. sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_special_trip WHERE is_cancel=0 AND user_id=? AND activity_id=? `
  67. o := orm.NewOrmUsingDB("hz_cygx")
  68. err = o.Raw(sqlCount, uid, activityId).QueryRow(&count)
  69. return
  70. }
  71. // 新增预约人数
  72. func AddCygxActivitySpecialTrip(items []*CygxActivitySpecialTrip, itemsBill []*CygxActivitySpecialTripBill, itemsMeet []*CygxActivitySpecialMeetingDetail) (err error) {
  73. o := orm.NewOrmUsingDB("hz_cygx")
  74. to, err := o.Begin()
  75. if err != nil {
  76. return
  77. }
  78. defer func() {
  79. if err != nil {
  80. _ = to.Rollback()
  81. } else {
  82. _ = to.Commit()
  83. }
  84. }()
  85. var count int
  86. var sql string
  87. //添加会议提醒
  88. for _, item := range items {
  89. sql = `SELECT COUNT(1) AS count FROM cygx_activity_special_trip WHERE user_id=? AND activity_id=? `
  90. err = to.Raw(sql, item.UserId, item.ActivityId).QueryRow(&count)
  91. if err != nil {
  92. return
  93. }
  94. if count == 0 {
  95. _, err = to.Insert(item)
  96. } else {
  97. sql := `UPDATE cygx_activity_special_trip SET is_cancel=0 ,create_time = NOW() WHERE user_id=? AND activity_id=? `
  98. _, err = to.Raw(sql, item.UserId, item.ActivityId).Exec()
  99. }
  100. if err != nil {
  101. return
  102. }
  103. }
  104. //添加流水记录
  105. //倒序插入,让流水表看起来是正的
  106. for i := len(itemsBill) - 1; i >= 0; i-- {
  107. _, err = to.Insert(itemsBill[i])
  108. if err != nil {
  109. return
  110. }
  111. }
  112. //添加到会信息记录查询表
  113. for _, item := range itemsMeet {
  114. _, err = to.Insert(item)
  115. if err != nil {
  116. return
  117. }
  118. }
  119. return
  120. }
  121. type GetAppointmentSpecialListRsep struct {
  122. Source int `description:"来源 专项调研:1 "`
  123. ActivityId int `description:"活动ID"`
  124. Total int `description:"总人数"`
  125. MyTotal int `description:"本人名下客户"`
  126. IsLimitPeople int `description:"是否限制人数 1是,0否"`
  127. MemberType string `description:"管理员身份 Admin:超级管理员、权益管理员、权益研究员、专家组;GroupLeader:组长;Sale:销售"`
  128. SpecialType int `description:"调研形式、 1 线上 , 2 线下"`
  129. List []*CygxActivitySpecialTripResp
  130. }
  131. func GetCygxActivitySpecialTripList(activityId int, condition string) (item []*CygxActivitySpecialTripResp, err error) {
  132. o := orm.NewOrmUsingDB("hz_cygx")
  133. sql := `SELECT s.*,
  134. a.activity_time,
  135. a.special_type
  136. FROM
  137. cygx_activity_special_trip AS s
  138. INNER JOIN cygx_activity_special AS a ON a.activity_id = s.activity_id
  139. WHERE a.activity_id = ? ` + condition + ` GROUP BY s.user_id ORDER BY s.create_time DESC `
  140. _, err = o.Raw(sql, activityId).QueryRows(&item)
  141. return
  142. }
  143. func GetActivitySpecialTripTotal(activityId int, sqlStr string) (count int, err error) {
  144. o := orm.NewOrmUsingDB("hz_cygx")
  145. sql := `SELECT COUNT(*) FROM
  146. cygx_activity_special_trip AS s
  147. LEFT JOIN cygx_activity_special AS a ON a.activity_id = s.activity_id
  148. WHERE
  149. s.activity_id = ? ` + sqlStr + `
  150. GROUP BY s.user_id)`
  151. sql = `SELECT COUNT(*) as count FROM (` + sql + ` a`
  152. err = o.Raw(sql, activityId).QueryRow(&count)
  153. return
  154. }
  155. // ActivitySpecialTripCancel 取消报名
  156. func ActivitySpecialTripCancel(isValid, activityId, uid int) (err error) {
  157. o, err := orm.NewOrmUsingDB("hz_cygx").Begin()
  158. if err != nil {
  159. return
  160. }
  161. defer func() {
  162. if err != nil {
  163. _ = o.Rollback()
  164. } else {
  165. _ = o.Commit()
  166. }
  167. }()
  168. sql := `UPDATE cygx_activity_special_trip SET is_valid= ?, is_cancel = 1 WHERE activity_id=? AND user_id = ? `
  169. _, err = o.Raw(sql, isValid, activityId, uid).Exec()
  170. if err != nil {
  171. return
  172. }
  173. //删除到会记录表信息
  174. sql = ` DELETE FROM cygx_activity_special_meeting_detail WHERE activity_id = ? AND user_id = ? `
  175. _, err = o.Raw(sql, activityId, uid).Exec()
  176. return
  177. }
  178. // 获取报名了的用户IDs
  179. func GetSpecialTripUserIds(activityId int, uIds string) (signupUids string, err error) {
  180. sql := ` SELECT
  181. GROUP_CONCAT( DISTINCT s.user_id SEPARATOR ',' ) AS signupUids
  182. FROM cygx_activity_special_trip AS s
  183. WHERE s.activity_id = ? AND s.is_cancel = 0 AND s.user_id not IN (` + uIds + `)`
  184. o := orm.NewOrmUsingDB("hz_cygx")
  185. err = o.Raw(sql, activityId).QueryRow(&signupUids)
  186. return
  187. }
  188. // 修改外呼手机号
  189. func SpecialTripOutboundMobileEdit(id int, outboundMobile, countryCode string) (err error) {
  190. o := orm.NewOrmUsingDB("hz_cygx")
  191. sql := `UPDATE cygx_activity_special_trip SET outbound_mobile = ?,country_code=? WHERE id=? `
  192. _, err = o.Raw(sql, outboundMobile, countryCode, id).Exec()
  193. return
  194. }
  195. func GetCygxActivitySpecialTripListByActivityId(activityId int) (item []*CygxActivitySpecialTripResp, err error) {
  196. o := orm.NewOrmUsingDB("hz_cygx")
  197. sql := `SELECT *
  198. FROM
  199. cygx_activity_special_trip
  200. WHERE activity_id = ? AND is_cancel = 0 `
  201. _, err = o.Raw(sql, activityId).QueryRows(&item)
  202. return
  203. }
  204. // 获取公司报名的记录
  205. func GetCygxActivitySpecialTripListByComapnyId(companyId int) (item []*CygxActivitySpecial, err error) {
  206. o := orm.NewOrmUsingDB("hz_cygx")
  207. sql := `SELECT
  208. t.*,
  209. a.chart_permission_id,
  210. a.chart_permission_name
  211. FROM
  212. cygx_activity_special_trip AS t
  213. INNER JOIN cygx_activity_special AS a ON a.activity_id = t.activity_id
  214. WHERE
  215. t.company_id = ? AND t.is_valid = 1 `
  216. _, err = o.Raw(sql, companyId).QueryRows(&item)
  217. return
  218. }
  219. // 获取空降的公司报名的记录
  220. func GetCygxActivitySpecialTripAirborneListByComapnyId(companyId int) (item []*CygxActivitySpecial, err error) {
  221. o := orm.NewOrmUsingDB("hz_cygx")
  222. sql := `SELECT
  223. t.*,
  224. a.chart_permission_id,
  225. a.chart_permission_name
  226. FROM
  227. cygx_activity_special_meeting_detail AS t
  228. INNER JOIN cygx_activity_special AS a ON a.activity_id = t.activity_id
  229. WHERE
  230. t.company_id = ? AND t.is_airborne = 1 `
  231. _, err = o.Raw(sql, companyId).QueryRows(&item)
  232. return
  233. }
  234. type ActivitySpecialSignupTempMsgReq struct {
  235. ActivityIds string `description:"活动id,用,隔开"`
  236. SendGroup string `description:"发送对象,1已报名 用,隔开"`
  237. ResearchTheme string `description:"调研主题"`
  238. Content string `description:"推送内容"`
  239. }
  240. // 列表
  241. func GetCygxActivitySpecialTripListCondition(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxActivitySpecialTrip, err error) {
  242. o := orm.NewOrmUsingDB("hz_cygx")
  243. sql := `SELECT * FROM cygx_activity_special_trip as art WHERE 1= 1 `
  244. if condition != "" {
  245. sql += condition
  246. }
  247. if startSize+pageSize > 0 {
  248. sql += ` LIMIT ?,? `
  249. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  250. } else {
  251. _, err = o.Raw(sql, pars).QueryRows(&items)
  252. }
  253. return
  254. }
  255. // 获取某一用户的报名的数量
  256. func GetUserActivitySpecialTripCount(uid, activityId int) (count int, err error) {
  257. sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_special_trip WHERE user_id=? AND activity_id =? `
  258. o := orm.NewOrmUsingDB("hz_cygx")
  259. err = o.Raw(sqlCount, uid, activityId).QueryRow(&count)
  260. return
  261. }
  262. func UpdateSpecialTrip(isValid, isCancel, userId, activityId int) (err error) {
  263. o := orm.NewOrmUsingDB("hz_cygx")
  264. sql := `UPDATE cygx_activity_special_trip SET is_valid = ?,create_time=NOW(),is_cancel=? WHERE user_id=? AND activity_id=? `
  265. _, err = o.Raw(sql, isValid, isCancel, userId, activityId).Exec()
  266. return
  267. }