activity_appointment.go 7.4 KB

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