activity_special_trip.go 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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. for _, item := range itemsBill {
  107. _, err = to.Insert(item)
  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.NewOrm()
  133. 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,
  134. (SELECT p.seller_name from company_product as p WHERE p.company_id = u.company_id AND p.product_id = 2 ) AS seller_name,
  135. GROUP_CONCAT( DISTINCT p.seller_name SEPARATOR '/' ) AS pseller_name
  136. FROM
  137. cygx_activity_special_trip AS s
  138. INNER JOIN wx_user AS u ON u.user_id = s.user_id
  139. INNER JOIN cygx_activity_special AS a ON a.activity_id = s.activity_id
  140. LEFT JOIN company_product AS p ON p.company_id = u.company_id
  141. LEFT JOIN company AS c ON c.company_id = u.company_id
  142. WHERE a.activity_id = ? ` + condition + ` GROUP BY s.user_id ORDER BY s.create_time DESC `
  143. _, err = o.Raw(sql, activityId).QueryRows(&item)
  144. return
  145. }
  146. func GetActivitySpecialTripTotal(activityId int, sqlStr string) (count int, err error) {
  147. o := orm.NewOrm()
  148. sql := `SELECT COUNT(*) FROM
  149. cygx_activity_special_trip AS s
  150. INNER JOIN wx_user AS u ON u.user_id = s.user_id
  151. LEFT JOIN cygx_activity_special AS a ON a.activity_id = s.activity_id
  152. LEFT JOIN company_product AS p ON p.company_id = u.company_id
  153. WHERE
  154. s.activity_id = ? ` + sqlStr + `
  155. GROUP BY s.user_id)`
  156. sql = `SELECT COUNT(*) as count FROM (` + sql + ` a`
  157. err = o.Raw(sql, activityId).QueryRow(&count)
  158. return
  159. }
  160. // ActivitySpecialTripCancel 取消报名
  161. func ActivitySpecialTripCancel(isValid, activityId, uid int) (err error) {
  162. o, err := orm.NewOrm().Begin()
  163. if err != nil {
  164. return
  165. }
  166. defer func() {
  167. if err != nil {
  168. _ = o.Rollback()
  169. } else {
  170. _ = o.Commit()
  171. }
  172. }()
  173. sql := `UPDATE cygx_activity_special_trip SET is_valid= ?, is_cancel = 1 WHERE activity_id=? AND user_id = ? `
  174. _, err = o.Raw(sql, isValid, activityId, uid).Exec()
  175. if err != nil {
  176. return
  177. }
  178. //删除到会记录表信息
  179. sql = ` DELETE FROM cygx_activity_special_meeting_detail WHERE activity_id = ? AND user_id = ? `
  180. _, err = o.Raw(sql, activityId, uid).Exec()
  181. return
  182. }
  183. // 获取报名了的用户IDs
  184. func GetSpecialTripUserIds(activityId int, uIds string) (signupUids string, err error) {
  185. sql := ` SELECT
  186. GROUP_CONCAT( DISTINCT s.user_id SEPARATOR ',' ) AS signupUids
  187. FROM cygx_activity_special_trip AS s
  188. WHERE s.activity_id = ? AND s.is_cancel = 0 AND s.user_id not IN (` + uIds + `)`
  189. o := orm.NewOrm()
  190. err = o.Raw(sql, activityId).QueryRow(&signupUids)
  191. return
  192. }
  193. // 修改外呼手机号
  194. func SpecialTripOutboundMobileEdit(id int, outboundMobile, countryCode string) (err error) {
  195. o := orm.NewOrm()
  196. sql := `UPDATE cygx_activity_special_trip SET outbound_mobile = ?,country_code=? WHERE id=? `
  197. _, err = o.Raw(sql, outboundMobile, countryCode, id).Exec()
  198. return
  199. }
  200. func GetCygxActivitySpecialTripListByActivityId(activityId int) (item []*CygxActivitySpecialTripResp, err error) {
  201. o := orm.NewOrm()
  202. sql := `SELECT *
  203. FROM
  204. cygx_activity_special_trip
  205. WHERE activity_id = ? AND is_cancel = 0 `
  206. _, err = o.Raw(sql, activityId).QueryRows(&item)
  207. return
  208. }
  209. // 获取公司报名的记录
  210. func GetCygxActivitySpecialTripListByComapnyId(companyId int) (item []*CygxActivitySpecial, err error) {
  211. o := orm.NewOrm()
  212. sql := `SELECT
  213. t.*,
  214. a.chart_permission_id,
  215. a.chart_permission_name
  216. FROM
  217. cygx_activity_special_trip AS t
  218. INNER JOIN cygx_activity_special AS a ON a.activity_id = t.activity_id
  219. WHERE
  220. t.company_id = ? AND t.is_valid = 1 `
  221. _, err = o.Raw(sql, companyId).QueryRows(&item)
  222. return
  223. }
  224. // 获取空降的公司报名的记录
  225. func GetCygxActivitySpecialTripAirborneListByComapnyId(companyId int) (item []*CygxActivitySpecial, err error) {
  226. o := orm.NewOrm()
  227. sql := `SELECT
  228. t.*,
  229. a.chart_permission_id,
  230. a.chart_permission_name
  231. FROM
  232. cygx_activity_special_meeting_detail AS t
  233. INNER JOIN cygx_activity_special AS a ON a.activity_id = t.activity_id
  234. WHERE
  235. t.company_id = ? AND t.is_airborne = 1 `
  236. _, err = o.Raw(sql, companyId).QueryRows(&item)
  237. return
  238. }
  239. type ActivitySpecialSignupTempMsgReq struct {
  240. ActivityIds string `description:"活动id,用,隔开"`
  241. SendGroup string `description:"发送对象,1已报名 用,隔开"`
  242. ResearchTheme string `description:"调研主题"`
  243. Content string `description:"推送内容"`
  244. }
  245. // 列表
  246. func GetCygxActivitySpecialTripListCondition(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxActivitySpecialTrip, err error) {
  247. o := orm.NewOrm()
  248. sql := `SELECT * FROM cygx_activity_special_trip as art WHERE 1= 1 `
  249. if condition != "" {
  250. sql += condition
  251. }
  252. if startSize+pageSize > 0 {
  253. sql += ` LIMIT ?,? `
  254. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  255. } else {
  256. _, err = o.Raw(sql, pars).QueryRows(&items)
  257. }
  258. return
  259. }