activity_special_trip.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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. INNER JOIN wx_user AS u ON u.user_id = s.user_id
  52. WHERE
  53. s.is_cancel = 0
  54. AND s.activity_id = ? `
  55. o := orm.NewOrm()
  56. err = o.Raw(sqlCount, activityId).QueryRow(&count)
  57. return
  58. }
  59. func GetActivitySpecialTripCountByThisUser(activityId int, uids string) (count int, err error) {
  60. sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_special_trip WHERE is_cancel = 0 AND activity_id=? AND user_id IN (` + uids + `) `
  61. o := orm.NewOrm()
  62. err = o.Raw(sqlCount, activityId).QueryRow(&count)
  63. return
  64. }
  65. // 获取用户报名数量
  66. func GetActivitySpecialTripCount(uid, activityId int) (count int, err error) {
  67. sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_special_trip WHERE is_cancel=0 AND user_id=? AND activity_id=? `
  68. o := orm.NewOrm()
  69. err = o.Raw(sqlCount, uid, activityId).QueryRow(&count)
  70. return
  71. }
  72. // 新增预约人数
  73. func AddCygxActivitySpecialTrip(items []*CygxActivitySpecialTrip, itemsBill []*CygxActivitySpecialTripBill, itemsMeet []*CygxActivitySpecialMeetingDetail) (err error) {
  74. o := orm.NewOrm()
  75. to, err := o.Begin()
  76. if err != nil {
  77. return
  78. }
  79. defer func() {
  80. if err != nil {
  81. _ = to.Rollback()
  82. } else {
  83. _ = to.Commit()
  84. }
  85. }()
  86. var count int
  87. var sql string
  88. //添加会议提醒
  89. for _, item := range items {
  90. sql = `SELECT COUNT(1) AS count FROM cygx_activity_special_trip WHERE user_id=? AND activity_id=? `
  91. err = to.Raw(sql, item.UserId, item.ActivityId).QueryRow(&count)
  92. if err != nil {
  93. return
  94. }
  95. if count == 0 {
  96. _, err = to.Insert(item)
  97. } else {
  98. sql := `UPDATE cygx_activity_special_trip SET is_cancel=0 ,create_time = NOW() WHERE user_id=? AND activity_id=? `
  99. _, err = to.Raw(sql, item.UserId, item.ActivityId).Exec()
  100. }
  101. if err != nil {
  102. return
  103. }
  104. }
  105. //添加流水记录
  106. //倒序插入,让流水表看起来是正的
  107. for i := len(itemsBill) - 1; i >= 0; i-- {
  108. _, err = to.Insert(itemsBill[i])
  109. if err != nil {
  110. return
  111. }
  112. }
  113. //添加到会信息记录查询表
  114. for _, item := range itemsMeet {
  115. _, err = to.Insert(item)
  116. if err != nil {
  117. return
  118. }
  119. }
  120. return
  121. }
  122. type GetAppointmentSpecialListRsep struct {
  123. Source int `description:"来源 专项调研:1 "`
  124. ActivityId int `description:"活动ID"`
  125. Total int `description:"总人数"`
  126. MyTotal int `description:"本人名下客户"`
  127. IsLimitPeople int `description:"是否限制人数 1是,0否"`
  128. MemberType string `description:"管理员身份 Admin:超级管理员、权益管理员、权益研究员、专家组;GroupLeader:组长;Sale:销售"`
  129. SpecialType int `description:"调研形式、 1 线上 , 2 线下"`
  130. List []*CygxActivitySpecialTripResp
  131. }
  132. func GetCygxActivitySpecialTripList(activityId int, condition string) (item []*CygxActivitySpecialTripResp, err error) {
  133. o := orm.NewOrm()
  134. sql := `SELECT s.id,s.activity_id,s.user_id,s.create_time,s.mobile,s.company_id,u.real_name,c.company_name,a.activity_time,s.outbound_mobile,s.country_code,a.special_type,
  135. (SELECT p.seller_name from company_product as p WHERE p.company_id = u.company_id AND p.product_id = 2 ) AS seller_name,
  136. GROUP_CONCAT( DISTINCT p.seller_name SEPARATOR '/' ) AS pseller_name
  137. FROM
  138. cygx_activity_special_trip AS s
  139. INNER JOIN wx_user AS u ON u.user_id = s.user_id
  140. INNER JOIN cygx_activity_special AS a ON a.activity_id = s.activity_id
  141. LEFT JOIN company_product AS p ON p.company_id = u.company_id
  142. LEFT JOIN company AS c ON c.company_id = u.company_id
  143. WHERE a.activity_id = ? ` + condition + ` GROUP BY s.user_id ORDER BY s.create_time DESC `
  144. _, err = o.Raw(sql, activityId).QueryRows(&item)
  145. return
  146. }
  147. func GetActivitySpecialTripTotal(activityId int, sqlStr string) (count int, err error) {
  148. o := orm.NewOrm()
  149. sql := `SELECT COUNT(*) FROM
  150. cygx_activity_special_trip AS s
  151. INNER JOIN wx_user AS u ON u.user_id = s.user_id
  152. LEFT JOIN cygx_activity_special AS a ON a.activity_id = s.activity_id
  153. LEFT JOIN company_product AS p ON p.company_id = u.company_id
  154. WHERE
  155. s.activity_id = ? ` + sqlStr + `
  156. GROUP BY s.user_id)`
  157. sql = `SELECT COUNT(*) as count FROM (` + sql + ` a`
  158. err = o.Raw(sql, activityId).QueryRow(&count)
  159. return
  160. }
  161. // ActivitySpecialTripCancel 取消报名
  162. func ActivitySpecialTripCancel(isValid, activityId, uid int) (err error) {
  163. o, err := orm.NewOrm().Begin()
  164. if err != nil {
  165. return
  166. }
  167. defer func() {
  168. if err != nil {
  169. _ = o.Rollback()
  170. } else {
  171. _ = o.Commit()
  172. }
  173. }()
  174. sql := `UPDATE cygx_activity_special_trip SET is_valid= ?, is_cancel = 1 WHERE activity_id=? AND user_id = ? `
  175. _, err = o.Raw(sql, isValid, activityId, uid).Exec()
  176. if err != nil {
  177. return
  178. }
  179. //删除到会记录表信息
  180. sql = ` DELETE FROM cygx_activity_special_meeting_detail WHERE activity_id = ? AND user_id = ? `
  181. _, err = o.Raw(sql, activityId, uid).Exec()
  182. return
  183. }
  184. // 获取报名了的用户IDs
  185. func GetSpecialTripUserIds(activityId int, uIds string) (signupUids string, err error) {
  186. sql := ` SELECT
  187. GROUP_CONCAT( DISTINCT s.user_id SEPARATOR ',' ) AS signupUids
  188. FROM cygx_activity_special_trip AS s
  189. WHERE s.activity_id = ? AND s.is_cancel = 0 AND s.user_id not IN (` + uIds + `)`
  190. o := orm.NewOrm()
  191. err = o.Raw(sql, activityId).QueryRow(&signupUids)
  192. return
  193. }
  194. // 修改外呼手机号
  195. func SpecialTripOutboundMobileEdit(id int, outboundMobile, countryCode string) (err error) {
  196. o := orm.NewOrm()
  197. sql := `UPDATE cygx_activity_special_trip SET outbound_mobile = ?,country_code=? WHERE id=? `
  198. _, err = o.Raw(sql, outboundMobile, countryCode, id).Exec()
  199. return
  200. }
  201. func GetCygxActivitySpecialTripListByActivityId(activityId int) (item []*CygxActivitySpecialTripResp, err error) {
  202. o := orm.NewOrm()
  203. sql := `SELECT *
  204. FROM
  205. cygx_activity_special_trip
  206. WHERE activity_id = ? AND is_cancel = 0 `
  207. _, err = o.Raw(sql, activityId).QueryRows(&item)
  208. return
  209. }
  210. // 获取公司报名的记录
  211. func GetCygxActivitySpecialTripListByComapnyId(companyId int) (item []*CygxActivitySpecial, err error) {
  212. o := orm.NewOrm()
  213. sql := `SELECT
  214. t.*,
  215. a.chart_permission_id,
  216. a.chart_permission_name
  217. FROM
  218. cygx_activity_special_trip AS t
  219. INNER JOIN cygx_activity_special AS a ON a.activity_id = t.activity_id
  220. WHERE
  221. t.company_id = ? AND t.is_valid = 1 `
  222. _, err = o.Raw(sql, companyId).QueryRows(&item)
  223. return
  224. }
  225. // 获取空降的公司报名的记录
  226. func GetCygxActivitySpecialTripAirborneListByComapnyId(companyId int) (item []*CygxActivitySpecial, err error) {
  227. o := orm.NewOrm()
  228. sql := `SELECT
  229. t.*,
  230. a.chart_permission_id,
  231. a.chart_permission_name
  232. FROM
  233. cygx_activity_special_meeting_detail AS t
  234. INNER JOIN cygx_activity_special AS a ON a.activity_id = t.activity_id
  235. WHERE
  236. t.company_id = ? AND t.is_airborne = 1 `
  237. _, err = o.Raw(sql, companyId).QueryRows(&item)
  238. return
  239. }
  240. type ActivitySpecialSignupTempMsgReq struct {
  241. ActivityIds string `description:"活动id,用,隔开"`
  242. SendGroup string `description:"发送对象,1已报名 用,隔开"`
  243. ResearchTheme string `description:"调研主题"`
  244. Content string `description:"推送内容"`
  245. }
  246. // 列表
  247. func GetCygxActivitySpecialTripListCondition(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxActivitySpecialTrip, err error) {
  248. o := orm.NewOrm()
  249. sql := `SELECT * FROM cygx_activity_special_trip as art WHERE 1= 1 `
  250. if condition != "" {
  251. sql += condition
  252. }
  253. if startSize+pageSize > 0 {
  254. sql += ` LIMIT ?,? `
  255. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  256. } else {
  257. _, err = o.Raw(sql, pars).QueryRows(&items)
  258. }
  259. return
  260. }
  261. //获取某一用户的报名的数量
  262. func GetUserActivitySpecialTripCount(uid, activityId int) (count int, err error) {
  263. sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_special_trip WHERE user_id=? AND activity_id =? `
  264. o := orm.NewOrm()
  265. err = o.Raw(sqlCount, uid, activityId).QueryRow(&count)
  266. return
  267. }
  268. func UpdateSpecialTrip(isValid, isCancel, userId, activityId int) (err error) {
  269. o := orm.NewOrm()
  270. sql := `UPDATE cygx_activity_special_trip SET is_valid = ?,create_time=NOW(),is_cancel=? WHERE user_id=? AND activity_id=? `
  271. _, err = o.Raw(sql, isValid, isCancel, userId, activityId).Exec()
  272. return
  273. }