activity_special_trip.go 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. package cygx
  2. import (
  3. //"hongze/hz_crm_api/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. OutboundMobile string `description:"外呼手机号"`
  21. CountryCode string `description:"手机国家区号"`
  22. }
  23. type CygxActivitySpecialTripResp struct {
  24. Id int `description:"ID"`
  25. UserId int `description:"用户id"`
  26. ActivityId int `description:"活动ID"`
  27. CreateTime string `description:"创建时间"`
  28. Mobile string `description:"手机号"`
  29. Email string `description:"邮箱号"`
  30. CompanyId int `description:"公司ID"`
  31. CompanyName string `description:"公司名称"`
  32. RealName string `description:"用户实际名称"`
  33. SellerName string `description:"所属销售"`
  34. AdminId int `description:"销售/管理员ID"`
  35. Source int `description:"来源,1小程序,2后台添加"`
  36. OutboundMobile string `description:"外呼手机号"`
  37. CountryCode string `description:"手机国家区号"`
  38. SpecialType int `description:"调研形式、 1 线上 , 2 线下"`
  39. }
  40. // 修改外呼电话以及区号
  41. type ActivitySpecialTripCancelReq struct {
  42. UserId int `description:"用户id"`
  43. ActivityId int `description:"活动ID"`
  44. }
  45. func GetActivitySpecialTripCountByActivityId(activityId int) (count int, err error) {
  46. sqlCount := `SELECT
  47. COUNT( 1 ) AS count
  48. FROM
  49. cygx_activity_special_trip AS s
  50. INNER JOIN wx_user AS u ON u.user_id = s.user_id
  51. WHERE
  52. s.is_cancel = 0
  53. AND s.activity_id = ? `
  54. o := orm.NewOrm()
  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.NewOrm()
  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.NewOrm()
  68. err = o.Raw(sqlCount, uid, activityId).QueryRow(&count)
  69. return
  70. }
  71. // 新增预约人数
  72. func AddCygxActivitySpecialTrip(items []*CygxActivitySpecialTrip, itemsBill []*CygxActivitySpecialTripBill) (err error) {
  73. o := orm.NewOrm()
  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. for _, item := range itemsBill {
  106. _, err = to.Insert(item)
  107. if err != nil {
  108. return
  109. }
  110. }
  111. return
  112. }
  113. type GetAppointmentSpecialListRsep struct {
  114. Source int `description:"来源 专项调研:1 "`
  115. ActivityId int `description:"活动ID"`
  116. Total int `description:"总人数"`
  117. MyTotal int `description:"本人名下客户"`
  118. IsLimitPeople int `description:"是否限制人数 1是,0否"`
  119. MemberType string `description:"管理员身份 Admin:超级管理员、权益管理员、权益研究员、专家组;GroupLeader:组长;Sale:销售"`
  120. SpecialType int `description:"调研形式、 1 线上 , 2 线下"`
  121. List []*CygxActivitySpecialTripResp
  122. }
  123. func GetCygxActivitySpecialTripList(activityId int, condition string) (item []*CygxActivitySpecialTripResp, err error) {
  124. o := orm.NewOrm()
  125. 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,
  126. (SELECT p.seller_name from company_product as p WHERE p.company_id = u.company_id AND p.product_id = 2 ) AS seller_name,
  127. GROUP_CONCAT( DISTINCT p.seller_name SEPARATOR '/' ) AS pseller_name
  128. FROM
  129. cygx_activity_special_trip AS s
  130. INNER JOIN wx_user AS u ON u.user_id = s.user_id
  131. INNER JOIN cygx_activity_special AS a ON a.activity_id = s.activity_id
  132. LEFT JOIN company_product AS p ON p.company_id = u.company_id
  133. LEFT JOIN company AS c ON c.company_id = u.company_id
  134. WHERE a.activity_id = ? ` + condition + ` GROUP BY s.user_id ORDER BY s.create_time DESC `
  135. _, err = o.Raw(sql, activityId).QueryRows(&item)
  136. return
  137. }
  138. func GetActivitySpecialTripTotal(activityId int, sqlStr string) (count int, err error) {
  139. o := orm.NewOrm()
  140. sql := `SELECT COUNT(*) FROM
  141. cygx_activity_special_trip AS s
  142. INNER JOIN wx_user AS u ON u.user_id = s.user_id
  143. LEFT JOIN cygx_activity_special AS a ON a.activity_id = s.activity_id
  144. LEFT JOIN company_product AS p ON p.company_id = u.company_id
  145. WHERE
  146. s.activity_id = ? ` + sqlStr + `
  147. GROUP BY s.user_id)`
  148. sql = `SELECT COUNT(*) as count FROM (` + sql + ` a`
  149. err = o.Raw(sql, activityId).QueryRow(&count)
  150. return
  151. }
  152. // ActivitySpecialTripCancel 取消报名
  153. func ActivitySpecialTripCancel(isValid, activityId, uid int) (err error) {
  154. o := orm.NewOrm()
  155. sql := `UPDATE cygx_activity_special_trip SET is_valid= ?, is_cancel = 1 WHERE activity_id=? AND user_id = ? `
  156. _, err = o.Raw(sql, isValid, activityId, uid).Exec()
  157. return
  158. }
  159. // 获取报名了的用户IDs
  160. func GetSpecialTripUserIds(activityId int, uIds string) (signupUids string, err error) {
  161. sql := ` SELECT
  162. GROUP_CONCAT( DISTINCT s.user_id SEPARATOR ',' ) AS signupUids
  163. FROM cygx_activity_special_trip AS s
  164. WHERE s.activity_id = ? AND s.is_cancel = 0 AND s.user_id not IN (` + uIds + `)`
  165. o := orm.NewOrm()
  166. err = o.Raw(sql, activityId).QueryRow(&signupUids)
  167. return
  168. }
  169. // 修改外呼手机号
  170. func SpecialTripOutboundMobileEdit(id int, outboundMobile, countryCode string) (err error) {
  171. o := orm.NewOrm()
  172. sql := `UPDATE cygx_activity_special_trip SET outbound_mobile = ?,country_code=? WHERE id=? `
  173. _, err = o.Raw(sql, outboundMobile, countryCode, id).Exec()
  174. return
  175. }
  176. func GetCygxActivitySpecialTripListByActivityId(activityId int) (item []*CygxActivitySpecialTripResp, err error) {
  177. o := orm.NewOrm()
  178. sql := `SELECT *
  179. FROM
  180. cygx_activity_special_trip
  181. WHERE activity_id = ? AND is_cancel = 0 `
  182. _, err = o.Raw(sql, activityId).QueryRows(&item)
  183. return
  184. }
  185. // 获取公司报名的记录
  186. func GetCygxActivitySpecialTripListByComapnyId(companyId int) (item []*CygxActivitySpecial, err error) {
  187. o := orm.NewOrm()
  188. sql := `SELECT
  189. t.*,
  190. a.chart_permission_id,
  191. a.chart_permission_name
  192. FROM
  193. cygx_activity_special_trip AS t
  194. INNER JOIN cygx_activity_special AS a ON a.activity_id = t.activity_id
  195. WHERE
  196. t.company_id = ? AND t.is_valid = 1 `
  197. _, err = o.Raw(sql, companyId).QueryRows(&item)
  198. return
  199. }
  200. // 获取空降的公司报名的记录
  201. func GetCygxActivitySpecialTripAirborneListByComapnyId(companyId int) (item []*CygxActivitySpecial, err error) {
  202. o := orm.NewOrm()
  203. sql := `SELECT
  204. t.*,
  205. a.chart_permission_id,
  206. a.chart_permission_name
  207. FROM
  208. cygx_activity_special_meeting_detail AS t
  209. INNER JOIN cygx_activity_special AS a ON a.activity_id = t.activity_id
  210. WHERE
  211. t.company_id = ? AND t.is_airborne = 1 `
  212. _, err = o.Raw(sql, companyId).QueryRows(&item)
  213. return
  214. }