activity_appointment.go 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. package models
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. type CygxActivityAppointment struct {
  8. Id int `orm:"column(id);pk"`
  9. ActivityId int `description:"活动ID"`
  10. UserId 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. }
  19. type AppointmentResp struct {
  20. ActivityId int `description:"活动ID"`
  21. HasPermission int `description:"操作方式,1:有该行业权限,正常展示,2:无该行业权限,3:潜在客户,未提交过申请,4:潜在客户,已提交过申请"`
  22. PopupMsg string `description:"权限弹窗信息"`
  23. SellerMobile string `description:"销售电话"`
  24. SellerName string `description:"销售姓名"`
  25. GoFollow bool `description:"是否去关注"`
  26. }
  27. //添加
  28. func AddCygxActivityAppointment(item *CygxActivityAppointment) (err error) {
  29. o, err := orm.NewOrm().Begin()
  30. if err != nil {
  31. return
  32. }
  33. defer func() {
  34. fmt.Println(err)
  35. if err == nil {
  36. o.Commit()
  37. } else {
  38. o.Rollback()
  39. }
  40. }()
  41. var countMySchedule int
  42. sql := `SELECT COUNT(1) AS count FROM cygx_my_schedule WHERE user_id=? AND activity_id=? `
  43. err = o.Raw(sql, item.UserId, item.ActivityId).QueryRow(&countMySchedule)
  44. if err != nil {
  45. return
  46. }
  47. if countMySchedule == 0 {
  48. itemMy := new(CygxMySchedule)
  49. itemMy.UserId = item.UserId
  50. itemMy.ActivityId = item.ActivityId
  51. itemMy.CreateTime = time.Now()
  52. itemMy.Mobile = item.Mobile
  53. itemMy.Email = item.Email
  54. itemMy.CompanyId = item.CompanyId
  55. itemMy.CompanyName = item.CompanyName
  56. _, err = o.Insert(itemMy)
  57. if err != nil {
  58. return
  59. }
  60. }
  61. _, err = o.Insert(item)
  62. return
  63. }
  64. //获取某一用户的报名的数量
  65. func GetUserCygxActivityAppointmentCount(uid, activityId int) (count int, err error) {
  66. sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_appointment WHERE user_id=? AND activity_id =? `
  67. o := orm.NewOrm()
  68. err = o.Raw(sqlCount, uid, activityId).QueryRow(&count)
  69. return
  70. }
  71. //获取某一用户的报名的数量
  72. func GetUserCygxActivityAppointmentCountByUid(uid int) (count int, err error) {
  73. sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_appointment WHERE user_id=? `
  74. o := orm.NewOrm()
  75. err = o.Raw(sqlCount, uid).QueryRow(&count)
  76. return
  77. }
  78. //删除
  79. func DeleteCygxActivityAppointment(uid, activityId int) (err error) {
  80. o := orm.NewOrm()
  81. sql := `DELETE FROM cygx_activity_special_signup WHERE user_id=? AND activity_id=? `
  82. _, err = o.Raw(sql, uid, activityId).Exec()
  83. return
  84. }
  85. //取消纪要预约
  86. func CancelcygxActivityAppointment(item *CygxActivityAppointment) (lastId int64, err error) {
  87. o, err := orm.NewOrm().Begin()
  88. if err != nil {
  89. return
  90. }
  91. defer func() {
  92. fmt.Println(err)
  93. if err == nil {
  94. o.Commit()
  95. } else {
  96. o.Rollback()
  97. }
  98. }()
  99. //判断是否删除我的日程
  100. var countSingup int
  101. var countReminder int
  102. sql := `SELECT COUNT(1) AS count FROM cygx_activity_signup WHERE is_cancel = 0 AND user_id=? AND activity_id=? `
  103. err = o.Raw(sql, item.UserId, item.ActivityId).QueryRow(&countSingup)
  104. sql = `SELECT COUNT(1) AS count FROM cygx_activity_meeting_reminder WHERE user_id=? AND activity_id=? `
  105. err = o.Raw(sql, item.UserId, item.ActivityId).QueryRow(&countReminder)
  106. if err != nil {
  107. return
  108. }
  109. if countSingup == 0 && countReminder == 0 {
  110. sql = `DELETE FROM cygx_my_schedule WHERE user_id=? AND activity_id=? `
  111. _, err = o.Raw(sql, item.UserId, item.ActivityId).Exec()
  112. if err != nil {
  113. return
  114. }
  115. }
  116. //删除预约的纪要
  117. sql = `DELETE FROM cygx_activity_appointment WHERE user_id=? AND activity_id=? `
  118. _, err = o.Raw(sql, item.UserId, item.ActivityId).Exec()
  119. if err != nil {
  120. return
  121. }
  122. return
  123. }
  124. type CygxAppointmentAndActivity struct {
  125. Mobile string `description:"手机号"`
  126. ActivityName string `description:"所属销售"`
  127. ActivityTypeId int `description:"活动类型"`
  128. }
  129. //通过活动ID获取预约列表
  130. func GetAppointmentListByActivityId(activityIds, activityTypeIds string) (items []*CygxAppointmentAndActivity, err error) {
  131. o := orm.NewOrm()
  132. sql := `SELECT
  133. m.*,a.activity_name,
  134. a.activity_type_id
  135. FROM
  136. cygx_activity_appointment AS m
  137. INNER JOIN cygx_activity AS a ON a.activity_id = m.activity_id
  138. WHERE
  139. a.activity_id IN ( ` + activityIds + ` )
  140. AND a.activity_type_id IN (` + activityTypeIds + `)
  141. AND DATE_SUB( CURDATE(), INTERVAL 14 DAY ) <= date( a.activity_time )
  142. AND a.active_state = 3 GROUP BY m.mobile`
  143. _, err = o.Raw(sql).QueryRows(&items)
  144. return
  145. }
  146. //通过活动ID、手机号获取预约列表
  147. func GetAppointmentListByActivityIdAndMobile(activityIds, mobile string) (items []*CygxAppointmentAndActivity, err error) {
  148. o := orm.NewOrm()
  149. sql := `SELECT
  150. m.*,a.activity_name
  151. FROM
  152. cygx_activity_appointment AS m
  153. INNER JOIN cygx_activity AS a ON a.activity_id = m.activity_id
  154. WHERE
  155. a.activity_id IN ( ` + activityIds + ` )
  156. AND a.activity_type_id IN ( 1, 2, 5 )
  157. AND DATE_SUB( CURDATE(), INTERVAL 14 DAY ) <= date( a.activity_time )
  158. AND a.active_state = 3
  159. AND m.mobile= ?`
  160. _, err = o.Raw(sql, mobile).QueryRows(&items)
  161. return
  162. }
  163. //通过活动ID获取预约纪要的人数列表
  164. func GetCygxAppointmentSummaryListBySubjectId(subjectIds string) (item []*CygxAppointmentAndActivity, err error) {
  165. o := orm.NewOrm()
  166. sql := `SELECT
  167. ap.mobile,
  168. ap.activity_id,
  169. a.activity_name
  170. FROM
  171. cygx_activity_appointment AS ap
  172. INNER JOIN cygx_activity AS a ON a.activity_id = ap.activity_id
  173. INNER JOIN cygx_industrial_activity_group_subject AS sg ON sg.activity_id = a.activity_id
  174. WHERE
  175. a.active_state = 3
  176. AND a.chart_permission_id = 31
  177. AND DATE_SUB( CURDATE(), INTERVAL 14 DAY ) <= date( a.activity_time )
  178. AND a.activity_type_id = 1
  179. AND sg.industrial_subject_id IN (` + subjectIds + `)
  180. GROUP BY
  181. ap.mobile,
  182. ap.activity_id `
  183. _, err = o.Raw(sql).QueryRows(&item)
  184. return
  185. }
  186. type CygxAppointment struct {
  187. Mobile string `description:"手机号"`
  188. UserId int `description:"userId"`
  189. ActivityName string `description:"所属销售"`
  190. ActivityTypeId int `description:"活动类型"`
  191. }
  192. //通过活动ID获取预约纪要的人数列表
  193. func GetCygxAppointmentSummaryBySubjectId(subjectIds string) (item []*CygxAppointment, err error) {
  194. o := orm.NewOrm()
  195. sql := `SELECT
  196. ap.user_id,
  197. ap.mobile,
  198. ap.activity_id,
  199. a.activity_name
  200. FROM
  201. cygx_activity_appointment AS ap
  202. INNER JOIN cygx_activity AS a ON a.activity_id = ap.activity_id
  203. INNER JOIN cygx_industrial_activity_group_subject AS sg ON sg.activity_id = a.activity_id
  204. WHERE
  205. a.active_state = 3
  206. AND sg.industrial_subject_id IN (` + subjectIds + `)
  207. GROUP BY
  208. ap.mobile,
  209. ap.activity_id `
  210. _, err = o.Raw(sql).QueryRows(&item)
  211. return
  212. }
  213. //GetCygxAppointmentListByUser 获取预约纪要的人
  214. func GetCygxAppointmentListByUser(condition string, pars []interface{}) (item []*CygxActivityAppointment, err error) {
  215. o := orm.NewOrm()
  216. sql := `SELECT *
  217. FROM
  218. cygx_activity_appointment
  219. WHERE 1 = 1 ` + condition
  220. _, err = o.Raw(sql, pars).QueryRows(&item)
  221. return
  222. }