activity.go 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204
  1. package models
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "hongze/hongze_cygx/utils"
  7. "strings"
  8. "time"
  9. )
  10. // 活动详情
  11. type CygxActivity struct {
  12. ActivityId int `orm:"column(activity_id);pk";description:"活动ID 等于0新增活动,大于0修改活动"`
  13. ActivityTypeId int `description:"活动类型id"`
  14. ActivityTypeName string `description:"活动类型名称"`
  15. ChartPermissionId int `description:"行业id"`
  16. ChartPermissionName string `description:"行业名称"`
  17. ChartPermissionNames string `description:"行业名称辅助字段,区分研选子分类"`
  18. Body string `description:"内容"`
  19. CreateTime time.Time `description:"创建时间"`
  20. IsLimitPeople int `description:"是否限制人数 1是,0否"`
  21. LimitPeopleNum int `description:"限制的人数数量"`
  22. CustomerTypeIds string `description:"活动可见的客户类型,多个ID用 , 隔开"`
  23. PublishStatus int `description:"发布状态 1已发布,0未发布"`
  24. LastUpdatedTime time.Time `description:"更新时间"`
  25. ActivityTime string `description:"活动时间"`
  26. ActivityTimeText string `description:"活动时间带文字"`
  27. DistinguishedGuest string `description:"嘉宾"`
  28. Host string `description:"主持人"`
  29. MainlandTell string `description:"大陆拨入号"`
  30. HongKongTell string `description:"香港拨入号"`
  31. TaiwanTell string `description:"台湾拨入号"`
  32. AmericaTell string `description:"美国拨入号"`
  33. ParticipationCode string `description:"参会密码"`
  34. Theme string `description:"主题"`
  35. Expert string `description:"专家"`
  36. ActivityName string `description:"活动名称"`
  37. ActivityNameTask string `description:"活动名称定时任务同步的时候使用"`
  38. OnlineParticipation string `description:"网络参会"`
  39. ReportLink string `description:"报告链接"`
  40. City string `description:"城市"`
  41. Address string `description:"活动地址"`
  42. Highlights string `description:"活动亮点"`
  43. Remarks string `description:"备注"`
  44. Speaker string `description:"主讲人"`
  45. ArticleId int `description:"关联报告id"`
  46. Label string `description:"标签"`
  47. LinkParticipants string `description:"链接参会"`
  48. AppAttendance string `description:"App参会"`
  49. ConferencePassword string `description:"会议密码"`
  50. TemporaryLabel string `description:"临时标签"`
  51. IsMakerShow int `description:"是否仅决策人可见 0,否 、1,是"`
  52. VisibleRange int `description:"可见范围 1,仅本组可见 、2,全部客户可见"`
  53. Scale string `description:"管理规模,空不填,1::50亿以下,2:50~100亿,3:100亿以上。多个用, 隔开"`
  54. IsShowSubjectName int `description:"小程序内是否展示标的名称 1是 ,0 否 默认0 "`
  55. IsHideAppointment int `description:"是否隐藏预约纪要按钮 1是 ,0 否 默认0 "`
  56. AdminId int `description:"销售/管理员ID"`
  57. AdminName string `description:"销售/管理员姓名"`
  58. IsCanAppointmentMinutes int `description:"是否可预约纪要 1是 ,0 否 默认0 "`
  59. YidongActivityId string `description:"易董活动ID"`
  60. YidongActivityUrl string `description:"易董活动跳转地址"`
  61. YidongActivityEndTime string `description:"易董活动截止时间"`
  62. ActivityJoinType string `description:"活动入会类型01报名审核后可入会 02预约即可入会 03仅定向邀请人员可入会"`
  63. YidongSignUpEnd string `description:"易董活动截止时间"` // 报名结束时间,适应于报名审核后可入会,为空表示不限制报名时间
  64. YidongSignUpStart string `description:"易董活动截止时间"` // 报名开始时间,适应于报名审核后可入会,为空表示不限制报名时间
  65. IsExternalLabel int `description:"是否为外部资源 1是,0否"`
  66. YidongActivityIdByCygx string `description:"通过查研观向建会易董返回的活动ID"`
  67. }
  68. type Activity struct {
  69. ActivityTypeId int `description:"活动类型id"`
  70. ActivityTypeName string `description:"活动名称"`
  71. TemplateP string `description:"活动模板,带P标签"`
  72. Template string `description:"活动模板"`
  73. ShowType string `description:"人数限制类型,1不展示限制,2可选限制,3强制限制"`
  74. }
  75. type ActivityIdRep struct {
  76. ActivityId int `description:"活动id"`
  77. PlaySeconds int `description:"播放时长"`
  78. }
  79. type ActivitySingnupRep struct {
  80. ActivityId int `description:"活动id"`
  81. SignupType int `description:"报名方式,1预约外呼,2自主拨入,3我要报名"`
  82. }
  83. type ActivityCcustomerType struct {
  84. CustomerTypeId int `description:"活动类型id"`
  85. CustomerName string `description:"活动名称"`
  86. PermissionValue string `description:"用户权限对应的值"`
  87. }
  88. type ActivityCcustomerTypeList struct {
  89. List []*ActivityCcustomerType
  90. }
  91. // 列表
  92. func GetActivityCcustomerTypeList() (items []*ActivityCcustomerType, err error) {
  93. o := orm.NewOrm()
  94. sql := `SELECT * FROM cygx_customer_type ORDER BY sort DESC`
  95. _, err = o.Raw(sql).QueryRows(&items)
  96. return
  97. }
  98. // 活动添加、修改入参
  99. type ActivityRep struct {
  100. ActivityTypeId int `description:"活动类型id"`
  101. ChartPermissionId int `description:"行业id"`
  102. Body string `description:"内容"`
  103. LimitPeopleNum int `description:"限制的人数数量"`
  104. CustomerTypeIds string `description:"活动可见的客户类型,多个ID用 , 隔开"`
  105. ActivityId int `description:"活动ID 等于0新增活动,大于0修改活动"`
  106. DoType int `description:"操作类型 0,保存 、1,发布"`
  107. }
  108. type ActivityArticleResp struct {
  109. ReportLink string `description:"报告链接"`
  110. ArticleId int `description:"报告id(报告链接跳转使用)"`
  111. Title string `description:"报告id(报告链接跳转使用)"`
  112. }
  113. // 活动详情
  114. type ActivityDetail struct {
  115. ActivityId int `orm:"column(activity_id);pk";description:"活动ID "`
  116. ActivityTypeId int `description:"活动类型id"`
  117. ActivityTypeName string `description:"活动类型名称"`
  118. ChartPermissionId int `description:"行业id"`
  119. ChartPermissionName string `description:"行业名称"`
  120. ChartPermissionNames string `description:"行业名称辅助字段,区分研选子分类"`
  121. Body string `description:"内容"`
  122. CreateTime string `description:"创建时间"`
  123. IsLimitPeople int `description:"是否限制人数 1是,0否"`
  124. LimitPeopleNum int `description:"限制的人数数量"`
  125. LastUpdatedTime string `description:"更新时间"`
  126. ActivityTime string `description:"活动时间"`
  127. ActivityTimeText string `description:"活动时间带文字"`
  128. DistinguishedGuest string `description:"嘉宾"`
  129. Host string `description:"主持人"`
  130. Speaker string `description:"主讲人"`
  131. MainlandTell string `description:"大陆拨入号"`
  132. HongKongTell string `description:"香港拨入号"`
  133. TaiwanTell string `description:"台湾拨入号"`
  134. AmericaTell string `description:"美国拨入号"`
  135. ParticipationCode string `description:"参会密码"`
  136. Theme string `description:"主题"`
  137. Expert string `description:"专家"`
  138. ActivityName string `description:"活动名称"`
  139. OnlineParticipation string `description:"网络参会"`
  140. ReportLink string `description:"报告链接"`
  141. City string `description:"城市"`
  142. Address string `description:"活动地址"`
  143. Highlights string `description:"活动亮点"`
  144. Remarks string `description:"备注"`
  145. ShowType string `description:"人数限制类型,1不展示限制,2可选限制,3强制限制"`
  146. IsSignup int `description:"是否已报名 1是 ,0 否"`
  147. IsAppointment int `description:"是否已预约纪要 1是 ,0 否"`
  148. SignupNum int `description:"已报名人数"`
  149. SignupType int `description:"报名方式,1预约外呼,2自主拨入,3我要报名"`
  150. ActiveState string `description:"活动进行状态 未开始:1、进行中2、已结束3"`
  151. IsCancelMeetingReminder int `description:"是否取消会议提醒 1展示取消会议提醒 ,0展示会议提醒"`
  152. ArticleId int `description:"报告id(报告链接跳转使用)"`
  153. CustomerTypeIds string `description:"活动可见的客户类型,多个ID用 , 隔开"`
  154. IsShowSustainable bool `description:"是否展示限免标签"`
  155. Description string `description:"研选内容说明"`
  156. IsResearch bool `description:"是否属于研选"`
  157. LinkParticipants string `description:"链接参会"`
  158. AppAttendance string `description:"App参会"`
  159. ConferencePassword string `description:"会议密码"`
  160. Scale string `description:"管理规模,空不填,1::50亿以下,2:50~100亿,3:100亿以上。多个用, 隔开"`
  161. IsShowAppointment bool `description:"是否展示预约纪要"`
  162. IsHideAppointment int `description:"是否隐藏预约纪要按钮 1是,0 否"`
  163. IsCClassMeeting bool `description:"是否是c类电话会"`
  164. ArticleList []*ActivityArticleResp // 下面是列表添加的部分结构体
  165. IsBrackets int `description:"是否有方括号 1是 ,0 否"`
  166. Label string `description:"主题标签"`
  167. ImgUrl string `description:"图片链接"`
  168. ImgUrlText string `description:"图片链接文字"`
  169. ActivityType int `description:"活动线上线下类型 1线上,0 线下"`
  170. JmcjRoadshowTitle string `description:"进门财经手动匹配的活动名称"`
  171. Listndustrial []*IndustrialManagementRep `description:"活动关联的产业信息"`
  172. IsShowOutboundCall bool `description:"是否展示预约外呼"`
  173. IsShowMeetingReminder bool `description:"是否展示会议提醒"`
  174. IsShowHelpSsk bool `description:"是否展示帮我带问"`
  175. IsShowSignup bool `description:"是否展示我要报名"`
  176. IsShowDetails bool `description:"是否展示查看详情按钮"`
  177. TemporaryLabel string `description:"临时标签"`
  178. IsCanAppointmentMinutes int `description:"是否可预约纪要 1是 ,0 否 默认0 "`
  179. YidongActivityId string `description:"易董活动ID"`
  180. YidongActivityUrl string `description:"易董活动跳转地址"`
  181. AudioLink bool `description:"是否展示回放按钮"`
  182. VoiceList *CygxActivityVoiceReq `description:"音频数据"`
  183. AdminId int `description:"管理员、销售ID "`
  184. IsMakerShow int `description:"是否仅决策人可见 0,否 、1,是"`
  185. VisibleRange int `description:"可见范围 1,仅本组可见 、2,全部客户可见"`
  186. VideoDetail *CygxActivityVideoListResp `description:"视频数据"`
  187. FileType int `description:"类型: 1-音频; 2-视频"`
  188. SourceType int `description:"活动来源。 1:活动 、2:专项产业调研"`
  189. TripImgLink string `description:"专项产业调研行程链接"`
  190. ActivityTimeEnd string `description:"专项产业调研活动预期结束时间"`
  191. IsCollect bool `description:"是否收藏"`
  192. IsShowFollowButton bool `description:"是否展示关注取关按钮"`
  193. IsFollowButton bool `description:"是否关注"`
  194. IsYidongConduct bool `description:"是否属于易董办会 1:是 、0:否"`
  195. IsCanOutboundCall int `description:"是否提供外呼 1:是 、0:否"`
  196. TencentConferenceNumber string `description:"腾讯会议号"`
  197. YidongActivityIdByCygx string `description:"通过查研观向建会易董返回的活动ID"`
  198. IsShowSigninButton bool `description:"是否展示签到码按钮"`
  199. SigninImg string `description:"签到码图片"`
  200. }
  201. type ListArticleActivity struct {
  202. Title string `description:"文章标题"`
  203. ArtleId int `description:"产业id"`
  204. }
  205. type CygxActivityResp struct {
  206. HaqveJurisdiction bool `description:"是否有权限"`
  207. OperationMode string `description:"操作方式 Apply:立即申请、Call:拨号 为空则为有权限"`
  208. HasPermission int `description:"操作方式,1:有该行业权限,正常展示,2:无该行业权限,3:潜在客户,未提交过申请,4:潜在客户,已提交过申请,5:有IFCC、无权益"`
  209. PopupMsg string `description:"权限弹窗信息"`
  210. MsgType string `description:"Type : 类型 , Industry : 行业"`
  211. SellerMobile string `description:"销售电话"`
  212. SellerName string `description:"销售姓名"`
  213. Detail *ActivityDetail
  214. }
  215. // 通过纪要ID获取活动详情
  216. func GetAddActivityInfoById(ActivityId int) (item *ActivityDetail, err error) {
  217. o := orm.NewOrm()
  218. sql := `SELECT * FROM cygx_activity WHERE activity_id=? AND publish_status = 1 `
  219. err = o.Raw(sql, ActivityId).QueryRow(&item)
  220. return
  221. }
  222. // 通过活动名称获取活动详情
  223. func GetAddActivityInfoByTitle(title, startDate, endDate string) (item *ActivityDetail, err error) {
  224. o := orm.NewOrm()
  225. sql := `SELECT * FROM cygx_activity WHERE activity_time > '` + startDate + `' AND activity_time < '` + endDate + `' AND (activity_name_task LIKE '%` + title + `%' OR jmcj_roadshow_title LIKE '%` + title + `%') AND activity_id NOT IN (1328) LIMIT 1 `
  226. err = o.Raw(sql).QueryRow(&item)
  227. return
  228. }
  229. // 通过纪要ID获取活动详情
  230. func GetAddActivityInfoByIdShow(uid, ActivityId int) (item *ActivityDetail, err error) {
  231. o := orm.NewOrm()
  232. sql := `SELECT *,( SELECT COUNT( 1 ) FROM cygx_activity_signup AS s WHERE s.activity_id = a.activity_id AND s.user_id = ? AND s.is_cancel = 0 AND s.do_fail_type = 0) AS is_signup,
  233. ( SELECT COUNT( DISTINCT user_id ) FROM cygx_activity_signup AS s WHERE s.activity_id = a.activity_id AND s.is_cancel = 0 AND s.do_fail_type = 0) AS signup_num,
  234. ( SELECT COUNT( 1 ) FROM cygx_activity_meeting_reminder AS m WHERE m.activity_id = a.activity_id AND m.user_id = ? AND m.is_cancel = 0 ) AS is_cancel_meeting_reminder,
  235. ( SELECT COUNT( 1 ) FROM cygx_activity_appointment AS ap WHERE ap.activity_id = a.activity_id AND ap.user_id = ? ) AS is_appointment
  236. FROM cygx_activity AS a WHERE activity_id=? AND publish_status = 1 `
  237. err = o.Raw(sql, uid, uid, uid, ActivityId).QueryRow(&item)
  238. return
  239. }
  240. // 活动列表
  241. type CygxActivityList struct {
  242. ActivityId int `orm:"column(activity_id);pk";description:"活动ID 等于0新增活动,大于0修改活动"`
  243. ActivityTypeId int `description:"活动类型id"`
  244. ActivityName string `description:"活动名称"`
  245. ActivityTypeName string `description:"活动类型名称"`
  246. Speaker string `description:"主讲人"`
  247. SignupType int `description:"报名方式,1预约外呼,2我要报名"`
  248. ChartPermissionId int `description:"行业id"`
  249. ChartPermissionName string `description:"行业名称"`
  250. IsLimitPeople int `description:"是否限制人数 1是,0否"`
  251. LimitPeopleNum int `description:"限制的人数数量"`
  252. ActivityTime string `description:"活动时间"`
  253. ActivityTimeText string `description:"活动时间带文字"`
  254. City string `description:"城市"`
  255. Address string `description:"活动地址"`
  256. DistinguishedGuest string `description:"嘉宾"`
  257. Expert string `description:"专家"`
  258. IsSignup int `description:"是否已报名 1是 ,0 否"`
  259. IsAppointment int `description:"是否已预约纪要 1是 ,0 否"`
  260. IsShowAppointment bool `description:"是否展示预约纪要"`
  261. SignupNum int `description:"已报名人数"`
  262. ActiveState string `description:"活动进行状态 未开始:1、进行中2、已结束3"`
  263. IsCancelMeetingReminder int `description:"是否取消会议提醒 1展示取消会议提醒 ,0展示会议提醒"`
  264. IsBrackets int `description:"是否有方括号 1是 ,0 否"`
  265. Label string `description:"主题标签"`
  266. IsShowSustainable bool `description:"是否展示限免标签"`
  267. ImgUrl string `description:"图片链接"`
  268. ImgUrlText string `description:"图片链接文字"`
  269. ActivityType int `description:"活动线上线下类型 1线上,0 线下"`
  270. IsHideAppointment int `description:"是否隐藏预约纪要按钮 1是,0 否"`
  271. JmcjRoadshowTitle string `description:"进门财经手动匹配的活动名称"`
  272. IsCClassMeeting bool `description:"是否是c类电话会"`
  273. }
  274. type GetCygxActivityListRep struct {
  275. Paging *paging.PagingItem `description:"分页数据"`
  276. List []*ActivityDetail
  277. Label string `description:"主题"`
  278. ImgUrl string `description:"图片路径"`
  279. IsResearch bool `description:"是否属于研选"`
  280. IsJump bool `description:"是否跳转"`
  281. IndustrialManagementId int `description:"产业ID"`
  282. IndustryNewLabel bool `description:"产业是否新标签"`
  283. }
  284. // 列表
  285. func GetActivityListAll(condition string, pars []interface{}, uid, startSize, pageSize, playBack int) (items []*ActivityDetail, err error) {
  286. var sqlJiontable string
  287. if playBack == 1 {
  288. //sqlJiontable = ` INNER JOIN cygx_activity_voice AS ac ON ac.activity_id = art.activity_id `
  289. }
  290. o := orm.NewOrm()
  291. sql := `SELECT art.* ,t.activity_type,t.img_url_text,c.image_url as img_url,
  292. ( SELECT COUNT( 1 ) FROM cygx_activity_signup AS s WHERE s.activity_id = art.activity_id AND s.user_id = ? AND s.is_cancel = 0 AND s.do_fail_type = 0) AS is_signup,
  293. ( SELECT COUNT( DISTINCT user_id ) FROM cygx_activity_signup AS s WHERE s.activity_id = art.activity_id AND s.is_cancel = 0 AND s.do_fail_type = 0) AS signup_num,
  294. ( SELECT COUNT( 1 ) FROM cygx_activity_meeting_reminder AS m WHERE m.activity_id = art.activity_id AND m.user_id = ? AND m.is_cancel = 0 ) AS is_cancel_meeting_reminder,
  295. ( SELECT COUNT( 1 ) FROM cygx_activity_appointment AS ap WHERE ap.activity_id = art.activity_id AND ap.user_id = ? ) AS is_appointment
  296. FROM cygx_activity as art
  297. INNER JOIN cygx_activity_type as t ON t.activity_type_id = art.activity_type_id
  298. INNER JOIN chart_permission AS c ON c.chart_permission_id = art.chart_permission_id ` + sqlJiontable + ` WHERE 1= 1 `
  299. if condition != "" {
  300. sql += condition
  301. }
  302. sql += ` LIMIT ?,?`
  303. _, err = o.Raw(sql, pars, uid, uid, uid, startSize, pageSize).QueryRows(&items)
  304. return
  305. }
  306. // 列表
  307. func GetActivityListByDateTime(startDate, endDate, activityIds, activityIdsLongTime string) (items []*CygxActivityList, err error) {
  308. o := orm.NewOrm()
  309. sql := `SELECT * FROM cygx_activity WHERE activity_time > '` + startDate + `' AND activity_time < '` + endDate + `' `
  310. activityIds = strings.TrimRight(activityIds, ",")
  311. if activityIds != "" {
  312. sql += ` AND activity_id NOT IN (` + activityIds + `,1328 ) `
  313. }
  314. sql += ` OR activity_id IN (` + activityIdsLongTime + `)`
  315. _, err = o.Raw(sql).QueryRows(&items)
  316. return
  317. }
  318. // 获取我的日程数量
  319. func GetSpecialScheduleCount(uid int) (count int, err error) {
  320. o := orm.NewOrm()
  321. sqlCount := `
  322. SELECT COUNT( 1 ) AS count FROM
  323. cygx_activity_special AS art
  324. INNER JOIN cygx_activity_special_trip AS my ON my.activity_id = art.activity_id
  325. WHERE
  326. 1 = 1 AND my.user_id = ? AND my.is_cancel = 0`
  327. err = o.Raw(sqlCount, uid).QueryRow(&count)
  328. return
  329. }
  330. // 获取数量
  331. func GetActivityCount(condition string, playBack int, pars []interface{}, filter int) (count int, err error) {
  332. var sqlJiontable string
  333. if playBack == 1 {
  334. //sqlJiontable = ` INNER JOIN cygx_activity_voice AS ac ON ac.activity_id = art.activity_id `
  335. }
  336. if filter == 1 {
  337. sqlJiontable = ` INNER JOIN cygx_activity_video AS av ON av.activity_id = art.activity_id `
  338. } else if filter == 2 {
  339. sqlJiontable = ` INNER JOIN cygx_activity_voice AS ac ON ac.activity_id = art.activity_id `
  340. }
  341. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_activity as art ` + sqlJiontable + ` WHERE 1= 1 `
  342. if condition != "" {
  343. sqlCount += condition
  344. }
  345. o := orm.NewOrm()
  346. err = o.Raw(sqlCount, pars).QueryRow(&count)
  347. return
  348. }
  349. // 获取我的日程数量
  350. func GetScheduleCount(condition string, uid int) (count int, err error) {
  351. o := orm.NewOrm()
  352. sqlCount := `SELECT COUNT( 1 ) AS count
  353. FROM cygx_my_schedule AS m
  354. INNER JOIN cygx_activity AS art ON art.activity_id = m.activity_id
  355. WHERE
  356. user_id = ?`
  357. if condition != "" {
  358. sqlCount += condition
  359. }
  360. err = o.Raw(sqlCount, uid).QueryRow(&count)
  361. return
  362. }
  363. // 我的日程列表
  364. func GetScheduleList(condition string, pars []interface{}, uid, startSize, pageSize int) (items []*ActivityDetail, err error) {
  365. o := orm.NewOrm()
  366. sql := `SELECT art.*,t.activity_type,t.img_url_text,c.image_url as img_url,
  367. ( SELECT COUNT( 1 ) FROM cygx_activity_signup AS s WHERE s.activity_id = art.activity_id AND s.user_id = ? AND s.is_cancel = 0 AND s.do_fail_type = 0) AS is_signup,
  368. ( SELECT COUNT( DISTINCT user_id ) FROM cygx_activity_signup AS s WHERE s.activity_id = art.activity_id AND s.is_cancel = 0 AND s.do_fail_type = 0) AS signup_num ,
  369. ( SELECT COUNT( 1 ) FROM cygx_activity_appointment AS ap WHERE ap.activity_id = art.activity_id AND ap.user_id = ? ) AS is_appointment,
  370. ( SELECT COUNT( 1 ) FROM cygx_activity_meeting_reminder AS m WHERE m.activity_id = art.activity_id AND m.is_cancel = 0 AND m.user_id = ? ) AS is_cancel_meeting_reminder
  371. FROM cygx_activity AS art
  372. INNER JOIN cygx_my_schedule as my ON my.activity_id = art.activity_id
  373. INNER JOIN cygx_activity_type as t ON t.activity_type_id = art.activity_type_id
  374. INNER JOIN chart_permission AS c ON c.chart_permission_id = art.chart_permission_id
  375. WHERE 1=1 AND my.user_id = ? `
  376. if condition != "" {
  377. sql += condition
  378. }
  379. sql += ` ORDER BY art.active_state ASC,art.activity_time ASC LIMIT ?,?`
  380. _, err = o.Raw(sql, pars, uid, uid, uid, uid, startSize, pageSize).QueryRows(&items)
  381. return
  382. }
  383. // 我的日程列表 活动以及专项调研一起
  384. func GetScheduleAndSpecilList(condition string, pars []interface{}, conditionSpecil string, parsSpecil []interface{}, startSize, pageSize int) (items []*ActivityDetail, err error) {
  385. o := orm.NewOrm()
  386. sql := `SELECT
  387. art.activity_id,
  388. art.activity_time_text,
  389. art.activity_name,
  390. art.chart_permission_id,
  391. art.active_state,
  392. t.activity_type,
  393. art.chart_permission_name,
  394. art.distinguished_guest,
  395. art.expert,
  396. art.speaker,
  397. "" AS trip_img_link,
  398. "" AS activity_time_end,
  399. art.yidong_activity_id,
  400. art.is_can_appointment_minutes,
  401. art.activity_type_id,
  402. art.limit_people_num,
  403. art.is_limit_people,
  404. 1 AS source_type,
  405. art.activity_time,
  406. art.city
  407. FROM
  408. cygx_activity AS art
  409. INNER JOIN cygx_my_schedule AS my ON my.activity_id = art.activity_id
  410. INNER JOIN cygx_activity_type AS t ON t.activity_type_id = art.activity_type_id
  411. INNER JOIN chart_permission AS c ON c.chart_permission_id = art.chart_permission_id
  412. WHERE
  413. 1 = 1 `
  414. if condition != `` {
  415. sql += condition
  416. }
  417. sql += ` UNION ALL
  418. SELECT
  419. art.activity_id,
  420. art.activity_time_text_by_day AS activity_time_text,
  421. art.research_theme AS activity_name,
  422. art.chart_permission_id,
  423. "",
  424. art.special_type AS activity_type,
  425. art.chart_permission_name,
  426. "",
  427. "",
  428. "",
  429. art.trip_img_link_fix AS trip_img_link,
  430. art.activity_time_end,
  431. "",
  432. "",
  433. "",
  434. "",
  435. "",
  436. 2 AS source_type,
  437. art.activity_time,
  438. ""
  439. FROM
  440. cygx_activity_special AS art
  441. INNER JOIN cygx_activity_special_trip AS my ON my.activity_id = art.activity_id
  442. WHERE
  443. 1 = 1`
  444. if conditionSpecil != "" {
  445. sql += conditionSpecil
  446. }
  447. sql += ` ORDER BY activity_time DESC LIMIT ?,?`
  448. _, err = o.Raw(sql, pars, parsSpecil, startSize, pageSize).QueryRows(&items)
  449. return
  450. }
  451. // 获取数量
  452. func GetActivityCountById(activityId int) (count int, err error) {
  453. o := orm.NewOrm()
  454. sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity WHERE activity_id = ?`
  455. err = o.Raw(sqlCount, activityId).QueryRow(&count)
  456. return
  457. }
  458. // 删除数据
  459. func DeleteActivity(activityId int) (err error) {
  460. o := orm.NewOrm()
  461. sql := ` DELETE FROM cygx_activity WHERE activity_id = ?`
  462. _, err = o.Raw(sql, activityId).Exec()
  463. return
  464. }
  465. // 修改活动状态至进行中
  466. func UpdateActivitySattusToHaveInHand() (err error) {
  467. defer func() {
  468. if err != nil {
  469. fmt.Println(err)
  470. go utils.SendAlarmMsg("修改活动状态至进行中失败"+err.Error(), 2)
  471. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "修改活动状态至进行中失败 ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  472. }
  473. }()
  474. o := orm.NewOrm()
  475. resultTime_30 := time.Now().Add(-time.Minute * 30).Format("2006-01-02 15:04:05")
  476. resultTime_60 := time.Now().Add(-time.Minute * 60).Format("2006-01-02 15:04:05")
  477. var sqlOr string
  478. var condition string
  479. condition += ` AND activity_time < NOW()`
  480. sqlOr = condition
  481. condition += ` AND (activity_type_id IN ( 1, 2, 3, 7 ) AND activity_time > ` + "'" + resultTime_30 + "'" + ")"
  482. condition += ` OR(activity_type_id IN ( 4, 5, 6 ) AND activity_time > ` + "'" + resultTime_60 + "'" + sqlOr + ")"
  483. msql := " UPDATE cygx_activity SET active_state = 2 WHERE 1 = 1 " + condition
  484. _, err = o.Raw(msql).Exec()
  485. return
  486. }
  487. // 修改活动状态至已结束
  488. func UpdateActivitySattusToComplete() (err error) {
  489. defer func() {
  490. if err != nil {
  491. fmt.Println(err)
  492. go utils.SendAlarmMsg("修改活动状态至已结束"+err.Error(), 2)
  493. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "修改活动状态至已结束 ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  494. }
  495. }()
  496. o := orm.NewOrm()
  497. resultTime_30 := time.Now().Add(-time.Minute * 30).Format("2006-01-02 15:04:05")
  498. resultTime_60 := time.Now().Add(-time.Minute * 60).Format("2006-01-02 15:04:05")
  499. //var sqlOr string
  500. var condition string
  501. //condition += ` AND activity_time < NOW()`
  502. //sqlOr = condition
  503. condition += ` AND (activity_type_id IN ( 1, 2, 3, 7 ) AND activity_time < ` + "'" + resultTime_30 + "'" + ")"
  504. condition += ` OR(activity_type_id IN ( 4, 5, 6 ) AND activity_time < ` + "'" + resultTime_60 + "'" + ")"
  505. msql := " UPDATE cygx_activity SET active_state = 3 WHERE 1 = 1 " + condition
  506. _, err = o.Raw(msql).Exec()
  507. return
  508. }
  509. // 活动详情
  510. type WxMsgCygxActivityList struct {
  511. Id int `description:"报名ID"`
  512. UserId int `description:"用户ID"`
  513. ActivityId int `description:"活动ID 等于0新增活动,大于0修改活动"`
  514. ActivityTypeId int `description:"活动类型id"`
  515. ActivityName string `description:"活动名称"`
  516. ActivityTypeName string `description:"活动类型名称"`
  517. Speaker string `description:"主讲人"`
  518. SignupType int `description:"报名方式,1预约外呼,2我要报名"`
  519. ChartPermissionId int `description:"行业id"`
  520. ChartPermissionName string `description:"行业名称"`
  521. IsLimitPeople int `description:"是否限制人数 1是,0否"`
  522. LimitPeopleNum int `description:"限制的人数数量"`
  523. ActivityTime string `description:"活动时间"`
  524. ActivityTimeText string `description:"活动时间带文字"`
  525. City string `description:"城市"`
  526. Address string `description:"活动地址"`
  527. DistinguishedGuest string `description:"嘉宾"`
  528. Expert string `description:"专家"`
  529. IsSignup int `description:"是否已报名 1是 ,0 否"`
  530. SignupNum int `description:"已报名人数"`
  531. ActiveState string `description:"活动进行状态 未开始:1、进行中2、已结束3"`
  532. IsCancelMeetingReminder int `description:"是否取消会议提醒 1展示取消会议提醒 ,0展示会议提醒"`
  533. IsBrackets int `description:"是否有方括号 1是 ,0 否"`
  534. OpenId string `description:"OenId"`
  535. FailType int `description:"失败原因,0,未失败,1总人数已满,2单机构超限制,3,爽约次数超限"`
  536. }
  537. // 列表 3o分钟
  538. func GetActivitySendMsgListAll(endDate string) (items []*WxMsgCygxActivityList, err error) {
  539. o := orm.NewOrm()
  540. sql := `SELECT
  541. s.id,
  542. s.user_id,
  543. s.fail_type,
  544. cr.open_id,
  545. a.*
  546. FROM
  547. cygx_activity AS a
  548. INNER JOIN cygx_activity_signup AS s ON s.activity_id = a.activity_id
  549. INNER JOIN user_record AS c ON c.bind_account = s.mobile
  550. INNER JOIN cygx_user_record AS cr ON cr.union_id = c.union_id
  551. WHERE
  552. 1 = 1
  553. AND s.is_send_wx_msg = 0
  554. AND s.do_fail_type = 0
  555. AND a.publish_status = 1
  556. AND c.create_platform = 4
  557. AND a.activity_time <= ? AND a.activity_time >= NOW()
  558. AND s.is_cancel = 0
  559. AND( a.activity_type_id IN (4,5,6) OR (a.activity_type_id = 3 AND a.is_limit_people = 1 )) GROUP BY s.id`
  560. _, err = o.Raw(sql, endDate).QueryRows(&items)
  561. return
  562. }
  563. // 列表 15分钟提醒
  564. func GetActivitySendMsgListAllMeeting(endDate string) (items []*WxMsgCygxActivityList, err error) {
  565. o := orm.NewOrm()
  566. sql := `SELECT
  567. m.id,
  568. cr.open_id,
  569. a.*
  570. FROM
  571. cygx_activity AS a
  572. INNER JOIN cygx_activity_meeting_reminder AS m ON m.activity_id = a.activity_id
  573. INNER JOIN user_record AS c ON c.bind_account = m.mobile
  574. INNER JOIN cygx_user_record AS cr ON cr.union_id = c.union_id
  575. WHERE
  576. 1 = 1
  577. AND m.is_send_wx_msg = 0
  578. AND a.publish_status = 1
  579. AND a.activity_time <= ? AND a.activity_time >= NOW()
  580. AND m.is_cancel = 0
  581. AND c.create_platform = 4
  582. AND (
  583. a.activity_type_id IN ( 1, 2 )
  584. OR ( a.activity_type_id = 3 AND a.is_limit_people = 0 ))
  585. GROUP BY m.id`
  586. _, err = o.Raw(sql, endDate).QueryRows(&items)
  587. return
  588. }
  589. // 修改是否推送消息状态
  590. func UPdateSendedMsgStatus(signupIds string) (err error) {
  591. sql := ` UPDATE cygx_activity_signup SET is_send_wx_msg= 1 WHERE id IN(` + signupIds + `)`
  592. o := orm.NewOrm()
  593. _, err = o.Raw(sql).Exec()
  594. return
  595. }
  596. // 修改是否推送消息状态
  597. func UPdateSendedYiDongSignUp(activityId int) (err error) {
  598. sql := ` UPDATE cygx_activity SET is_yidong_sign_up= 1 WHERE activity_id = ? `
  599. o := orm.NewOrm()
  600. _, err = o.Raw(sql, activityId).Exec()
  601. return
  602. }
  603. // 修改是否推送消息状态
  604. func UPdateSendedMsgMeetingStatus(signupIds string) (err error) {
  605. sql := ` UPDATE cygx_activity_meeting_reminder SET is_send_wx_msg= 1 WHERE id IN(` + signupIds + `)`
  606. o := orm.NewOrm()
  607. _, err = o.Raw(sql).Exec()
  608. return
  609. }
  610. // 获取满足推送的活动ID数量
  611. func GetCountActivityIdToSendFile(endDate string) (count int, err error) {
  612. o := orm.NewOrm()
  613. sql := `SELECT
  614. COUNT(1) count
  615. FROM
  616. cygx_activity AS a
  617. INNER JOIN cygx_activity_signup AS s ON s.activity_id = a.activity_id
  618. WHERE
  619. 1 = 1
  620. AND s.signup_type = 1
  621. AND s.fail_type = 0
  622. AND a.is_send_file_toemail = 0
  623. AND a.activity_time <= ? AND a.activity_time >= NOW() GROUP BY a.activity_id `
  624. err = o.Raw(sql, endDate).QueryRow(&count)
  625. return
  626. }
  627. // 获取满足推送的活动ID
  628. func GetActivityIdToSendFile(endDate string) (items []*ActivityIdRep, err error) {
  629. o := orm.NewOrm()
  630. sql := `SELECT
  631. *
  632. FROM
  633. cygx_activity AS a
  634. INNER JOIN cygx_activity_signup AS s ON s.activity_id = a.activity_id
  635. INNER JOIN cygx_activity_type AS t ON a.activity_type_id = t.activity_type_id
  636. WHERE
  637. 1 = 1
  638. AND s.signup_type = 1
  639. AND a.yidong_activity_id = ''
  640. AND t.activity_type = 1
  641. AND s.fail_type = 0
  642. AND a.is_send_file_toemail = 0
  643. AND a.activity_time <= ? AND a.activity_time >= NOW() GROUP BY a.activity_id `
  644. _, err = o.Raw(sql, endDate).QueryRows(&items)
  645. return
  646. }
  647. type SignupExportRep struct {
  648. Mobile string `description:"手机号"`
  649. CompanyName string `description:"公司名称"`
  650. RealName string `description:"姓名"`
  651. CountryCode string `description:"区号"`
  652. OutboundMobile string `description:"外呼手机号"`
  653. SellerName string `description:"销售姓名"`
  654. }
  655. type ActivityMsgExportRep struct {
  656. UserId int `description:"用户ID"`
  657. RealName string `description:"姓名"`
  658. CompanyName string `description:"公司名称"`
  659. CompanyId int `description:"公司ID"`
  660. Content string `description:"内容"`
  661. CreateTime string `description:"提交时间"`
  662. }
  663. func GetSignupExport(activityId int) (item []*SignupExportRep, err error) {
  664. o := orm.NewOrm()
  665. sql := ` SELECT s.outbound_mobile,
  666. s.country_code,
  667. a.is_limit_people,
  668. u.real_name,
  669. ( SELECT p.seller_name FROM company_product AS p WHERE p.company_id = u.company_id AND p.product_id = 2 ) AS seller_name,
  670. ( SELECT c.company_name FROM company AS c WHERE c.company_id = u.company_id ) AS company_name
  671. FROM
  672. cygx_activity_signup AS s
  673. LEFT JOIN wx_user AS u ON u.user_id = s.user_id
  674. LEFT JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  675. LEFT JOIN company_product AS p ON p.company_id = u.company_id
  676. WHERE a.activity_id = ? AND s.do_fail_type = 0 AND s.signup_type = 1 GROUP BY s.id `
  677. _, err = o.Raw(sql, activityId).QueryRows(&item)
  678. return
  679. }
  680. // 修改文件是否推送状态
  681. func UPdateActivityIdToSendFile(activityId int) (err error) {
  682. sql := ` UPDATE cygx_activity SET is_send_file_toemail= 1 WHERE activity_id = ?`
  683. o := orm.NewOrm()
  684. _, err = o.Raw(sql, activityId).Exec()
  685. return
  686. }
  687. // 活动详情
  688. type CygxActivityLabelList struct {
  689. KeyWord string `orm:"column(label)";description:"主题"`
  690. Timesort string `description:"最大时间"`
  691. Mintimesort string `description:"最小时间"`
  692. ImgUrlBg string `description:"背景图片"`
  693. ActivityId int `description:"活动ID "`
  694. IsShowSubjectName int `description:"小程序内是否展示标的名称 1是 ,0否 默认0 "`
  695. Resource int `description:"位置 ,1:活动 ,2:专项产业调研"`
  696. TemporaryLabel string `description:"临时标签"`
  697. IsNew bool `description:"是否为新:活动存在关联的的产业所关联的报告均在3个月内/无报告则标记新"`
  698. YidongActivityId int `description:"易董活动ID"`
  699. IsExternalLabel bool `description:"是否为外部资源"`
  700. TripStatus int `description:"行程进行状态 1:预报名,2:确定行程"`
  701. City string `description:"城市"`
  702. Days int `description:"天数"`
  703. ActivityTypeId int `description:"活动类型id"`
  704. }
  705. // 主题列表
  706. func GetActivityLabelListAll(condition, sortTime string, pars []interface{}, startSize, pageSize int) (items []*CygxActivityLabelList, err error) {
  707. o := orm.NewOrm()
  708. sql := `SELECT activity_id,activity_type_id, label,temporary_label,is_show_subject_name, MAX( art.activity_time ) AS timesort, MIn( art.activity_time ) AS mintimesort , yidong_activity_id,city,is_external_label
  709. FROM cygx_activity as art WHERE 1= 1 `
  710. if condition != "" {
  711. sql += condition
  712. }
  713. sql += ` GROUP BY art.activity_id ORDER BY ` + sortTime + ` ,art.activity_id DESC LIMIT ?,? `
  714. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  715. return
  716. }
  717. // 主题列表
  718. func GetActivityLabelListCity() (items []*CygxActivity, err error) {
  719. o := orm.NewOrm()
  720. sql := `SELECT
  721. activity_id,
  722. activity_type_id,
  723. activity_time,
  724. label,
  725. temporary_label,
  726. is_show_subject_name,
  727. yidong_activity_id,
  728. city
  729. FROM
  730. cygx_activity AS art
  731. WHERE
  732. 1 = 1
  733. AND art.active_state IN ( 1, 2 )
  734. AND city != ''
  735. ORDER BY
  736. activity_time ASC `
  737. _, err = o.Raw(sql).QueryRows(&items)
  738. return
  739. }
  740. type GetCygxActivityLabelListRep struct {
  741. Label string `description:"主题"`
  742. ImgUrl string `description:"图片路径"`
  743. List []*CygxActivityLabelList
  744. }
  745. // 获取研选系列专家电话会,会前1小时,满足推送的活动ID数量
  746. func GetCountActivityResearchToSendFile(condition, endDate string) (count int, err error) {
  747. o := orm.NewOrm()
  748. sql := `SELECT
  749. COUNT(1) count
  750. FROM
  751. cygx_activity AS a
  752. INNER JOIN cygx_activity_help_ask AS k ON k.activity_id = a.activity_id
  753. WHERE
  754. 1 = 1 ` + condition + `
  755. AND a.is_send_ask_msg = 0
  756. AND a.activity_time <= ?
  757. AND a.activity_time >= NOW()`
  758. err = o.Raw(sql, endDate).QueryRow(&count)
  759. return
  760. }
  761. // 获取研选系列专家电话会,会前1小时,满足推送的活动ID
  762. func GetActivityResearchToSendFile(condition, endDate string) (items []*ActivityIdRep, err error) {
  763. o := orm.NewOrm()
  764. sql := `SELECT
  765. *
  766. FROM
  767. cygx_activity AS a
  768. INNER JOIN cygx_activity_help_ask AS k ON k.activity_id = a.activity_id
  769. WHERE
  770. 1 = 1 ` + condition + `
  771. AND a.is_send_ask_msg = 0
  772. AND a.activity_time <= ?
  773. AND a.activity_time >= NOW()
  774. GROUP BY
  775. a.activity_id `
  776. _, err = o.Raw(sql, endDate).QueryRows(&items)
  777. return
  778. }
  779. func GetActivityMsgExport(activityId int) (item []*ActivityMsgExportRep, err error) {
  780. o := orm.NewOrm()
  781. sql := `SELECT
  782. k.*,
  783. u.real_name
  784. FROM
  785. cygx_activity_help_ask AS k
  786. LEFT JOIN wx_user AS u ON u.user_id = k.user_id
  787. WHERE
  788. k.activity_id = ?
  789. GROUP BY
  790. k.ask_id`
  791. _, err = o.Raw(sql, activityId).QueryRows(&item)
  792. return
  793. }
  794. // 修改文件带问消息是否推送状态
  795. func UPdateActivityMsgToSendFile(activityId int) (err error) {
  796. sql := ` UPDATE cygx_activity SET is_send_ask_msg= 1 WHERE activity_id = ?`
  797. o := orm.NewOrm()
  798. _, err = o.Raw(sql, activityId).Exec()
  799. return
  800. }
  801. type AskEmailRep struct {
  802. Name string `description:"姓名"`
  803. Email string `description:"邮箱"`
  804. Mobile string `description:"手机号"`
  805. }
  806. func GetAskEmail() (item []*AskEmailRep, err error) {
  807. o := orm.NewOrm()
  808. sql := `SELECT * FROM cygx_activity_ask_email`
  809. _, err = o.Raw(sql).QueryRows(&item)
  810. return
  811. }
  812. // 主题列表
  813. func GetActivityLabelSpecialListAll(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxActivityLabelList, err error) {
  814. o := orm.NewOrm()
  815. sql := `SELECT label,activity_id,is_show_subject_name,days
  816. FROM cygx_activity_special as art WHERE 1= 1 `
  817. if condition != "" {
  818. sql += condition
  819. }
  820. sql += ` LIMIT ?,? `
  821. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  822. return
  823. }
  824. type GetCygxActivitySpecialDetailListResp struct {
  825. IsFollow bool `description:"是否关注新调研通知"`
  826. IsBindingMobile bool `description:"是否绑定了手机号"`
  827. Paging *paging.PagingItem `description:"分页数据"`
  828. List []*CygxActivitySpecialDetail
  829. }
  830. type CygxActivitySpecialResp struct {
  831. HaqveJurisdiction bool `description:"是否有权限"`
  832. OperationMode string `description:"操作方式 Apply:立即申请、Call:拨号 为空则为有权限"`
  833. HasPermission int `description:"操作方式,1:有该行业权限,正常展示,2:无该行业权限,3:潜在客户,未提交过申请,4:潜在客户,已提交过申请,5:有IFCC、无权益"`
  834. PopupMsg string `description:"权限弹窗信息"`
  835. MsgType string `description:"Type : 类型 , Industry : 行业"`
  836. SellerMobile string `description:"销售电话"`
  837. SellerName string `description:"销售姓名"`
  838. IsFollow bool `description:"是否关注新调研通知"`
  839. Detail *CygxActivitySpecialDetail
  840. }
  841. // 获取专项调研活动列表
  842. func GetCygxActivitySpecialDetailList(condition string, pars []interface{}, uid, startSize, pageSize int) (items []*CygxActivitySpecialDetail, err error) {
  843. o := orm.NewOrm()
  844. sql := ` SELECT
  845. art.*,
  846. c.image_url AS img_url,
  847. (
  848. SELECT
  849. COUNT( 1 )
  850. FROM
  851. cygx_activity_special_signup AS s
  852. WHERE
  853. s.activity_id = art.activity_id
  854. AND s.user_id = ?
  855. ) AS is_signup
  856. FROM
  857. cygx_activity_special AS art
  858. INNER JOIN chart_permission AS c ON c.chart_permission_id = art.chart_permission_id
  859. WHERE
  860. 1 = 1 `
  861. if condition != "" {
  862. sql += condition
  863. }
  864. sql += ` LIMIT ?,? `
  865. _, err = o.Raw(sql, uid, pars, startSize, pageSize).QueryRows(&items)
  866. return
  867. }
  868. // 通过活动ID获取活动详情
  869. func GetCygxActivitySpecialDetailById(uid, ActivityId int) (item *CygxActivitySpecialDetail, err error) {
  870. o := orm.NewOrm()
  871. sql := `SELECT *,( SELECT COUNT( 1 ) FROM cygx_activity_special_signup AS s WHERE s.activity_id = a.activity_id AND s.user_id = ? ) AS is_signup
  872. FROM
  873. cygx_activity_special AS a
  874. WHERE
  875. activity_id = ?
  876. AND publish_status = 1 AND is_offline = 0 `
  877. err = o.Raw(sql, uid, ActivityId).QueryRow(&item)
  878. return
  879. }
  880. // 通过活动ID获取活动详情
  881. func GetCygxActivitySpecialDetail(ActivityId int) (item *CygxActivitySpecialDetail, err error) {
  882. o := orm.NewOrm()
  883. sql := `SELECT * FROM cygx_activity_special WHERE activity_id=? AND publish_status = 1 `
  884. err = o.Raw(sql, ActivityId).QueryRow(&item)
  885. return
  886. }
  887. func UpdateCygxActivityName(activityId int, Name string) (err error) {
  888. o := orm.NewOrm()
  889. sql := `UPDATE cygx_activity SET activity_name_task = ? WHERE activity_id=? `
  890. _, err = o.Raw(sql, Name, activityId).Exec()
  891. return
  892. }
  893. // 获取已发布但是为开始活动的权限
  894. func GetActivityWeekPermission() (permission string, err error) {
  895. o := orm.NewOrm()
  896. sql := ` SELECT
  897. GROUP_CONCAT( DISTINCT chart_permission_name SEPARATOR ',' ) AS permission
  898. FROM
  899. cygx_activity
  900. WHERE
  901. active_state = 1`
  902. err = o.Raw(sql).QueryRow(&permission)
  903. return
  904. }
  905. // 列表
  906. func GetIndustrialActivityGroupManagementList(activityId int) (items []*IndustrialManagementRep, err error) {
  907. o := orm.NewOrm()
  908. sql := `SELECT
  909. p.permission_name,
  910. p.chart_permission_id,
  911. m.industrial_management_id,
  912. m.industry_name
  913. FROM
  914. cygx_industrial_activity_group_management AS am
  915. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = am.industrial_management_id
  916. INNER JOIN chart_permission AS p ON p.chart_permission_id = m.chart_permission_id
  917. WHERE
  918. am.activity_id = ? AND am.source = 1`
  919. _, err = o.Raw(sql, activityId).QueryRows(&items)
  920. return
  921. }
  922. // GetActivityListByYiDong 获取易董同步过来的活动列表
  923. func GetActivityListByYiDong() (items []*CygxActivity, err error) {
  924. o := orm.NewOrm()
  925. sql := ` SELECT * FROM cygx_activity WHERE yidong_activity_id != '' `
  926. _, err = o.Raw(sql).QueryRows(&items)
  927. return
  928. }
  929. // GetActivityListByYiDong 获取易董同步过来的活动列表
  930. func GetActivityListByYiDongByCygx() (items []*CygxActivity, err error) {
  931. o := orm.NewOrm()
  932. sql := ` SELECT * FROM cygx_activity WHERE yidong_activity_id_by_cygx != '' `
  933. _, err = o.Raw(sql).QueryRows(&items)
  934. return
  935. }
  936. // AddCygxActivity 添加活动
  937. func AddCygxActivity(item *CygxActivity) (lastId int64, err error) {
  938. o := orm.NewOrm()
  939. lastId, err = o.Insert(item)
  940. return
  941. }
  942. // 列表
  943. func GetActivityListByYidong(condition string) (items []*ActivityDetail, err error) {
  944. o := orm.NewOrm()
  945. sql := `SELECT * FROM cygx_activity WHERE 1 = 1
  946. AND ( yidong_activity_id != '' OR yidong_activity_id_by_cygx != '' ) `
  947. if condition != "" {
  948. sql += condition
  949. }
  950. _, err = o.Raw(sql).QueryRows(&items)
  951. return
  952. }
  953. // 列表
  954. func GetActivityListByCondition(condition string, pars []interface{}) (items []*CygxActivity, err error) {
  955. o := orm.NewOrm()
  956. sql := `SELECT * FROM cygx_activity WHERE 1 =1 `
  957. if condition != "" {
  958. sql += condition
  959. }
  960. _, err = o.Raw(sql, pars).QueryRows(&items)
  961. return
  962. }
  963. // UpdateCygxActivitySubmitMeetingByYidong ,跟易董返回的用户状态修改活动以提交到会状态
  964. func UpdateCygxActivitySubmitMeetingByYidong(yidongActivityId string) (err error) {
  965. o := orm.NewOrm()
  966. sql := `UPDATE cygx_activity SET is_submit_meeting = 1 WHERE yidong_activity_id=? OR yidong_activity_id_by_cygx = ? `
  967. _, err = o.Raw(sql, yidongActivityId, yidongActivityId).Exec()
  968. return
  969. }
  970. // UpdateActivityshowSubject 根据易董推过来的匹配信息,判断临时标签是否展示
  971. func UpdateActivityshowSubject(activityId int) (err error) {
  972. sql := ` UPDATE cygx_activity SET is_show_subject_name= 1 , temporary_label = '' WHERE activity_id = ?`
  973. o := orm.NewOrm()
  974. _, err = o.Raw(sql, activityId).Exec()
  975. return
  976. }
  977. // GetActivitySpecialSearcheList 活动与专项调研的搜索
  978. func GetActivitySpecialSearcheList(condition string, pars []interface{}, conditionSpecil string, parsSpecil []interface{}, startSize, pageSize int) (items []*ActivityDetail, total int, err error) {
  979. o := orm.NewOrm()
  980. sql := `SELECT
  981. art.activity_id,
  982. art.activity_time_text,
  983. art.activity_name,
  984. art.chart_permission_id,
  985. art.active_state,
  986. t.activity_type,
  987. t.img_url_text,
  988. art.chart_permission_name,
  989. art.distinguished_guest,
  990. art.expert,
  991. art.speaker,
  992. "" AS trip_img_link,
  993. "" AS activity_time_end,
  994. art.yidong_activity_id,
  995. art.is_can_appointment_minutes,
  996. art.activity_type_id,
  997. art.limit_people_num,
  998. art.is_limit_people,
  999. art.city,
  1000. 1 AS source_type,
  1001. art.is_yidong_conduct,
  1002. art.activity_time
  1003. FROM
  1004. cygx_activity AS art
  1005. INNER JOIN cygx_activity_type AS t ON t.activity_type_id = art.activity_type_id
  1006. WHERE
  1007. 1 = 1 `
  1008. if condition != `` {
  1009. sql += condition
  1010. }
  1011. sql += ` UNION ALL
  1012. SELECT
  1013. art.activity_id,
  1014. art.activity_time_text_by_day AS activity_time_text,
  1015. art.research_theme AS activity_name,
  1016. art.chart_permission_id,
  1017. "",
  1018. art.special_type AS activity_type,
  1019. "",
  1020. art.chart_permission_name,
  1021. "",
  1022. "",
  1023. "",
  1024. art.trip_img_link_fix AS trip_img_link,
  1025. art.activity_time_end,
  1026. "",
  1027. "",
  1028. "",
  1029. "",
  1030. "",
  1031. "",
  1032. 2 AS source_type,
  1033. "",
  1034. art.activity_time
  1035. FROM
  1036. cygx_activity_special AS art
  1037. WHERE
  1038. 1 = 1 `
  1039. if conditionSpecil != "" {
  1040. sql += conditionSpecil
  1041. }
  1042. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  1043. err = o.Raw(totalSql, pars, parsSpecil).QueryRow(&total)
  1044. if err != nil {
  1045. return
  1046. }
  1047. sql += ` ORDER BY activity_time DESC LIMIT ?,?`
  1048. _, err = o.Raw(sql, pars, parsSpecil, startSize, pageSize).QueryRows(&items)
  1049. return
  1050. }
  1051. // 列表
  1052. func GetActivityListNew(condition string, pars []interface{}, uid, startSize, pageSize, playBack, filter int, typeName string) (items []*ActivityDetail, err error) {
  1053. var sqlJiontable string
  1054. if playBack == 1 {
  1055. //sqlJiontable = ` INNER JOIN cygx_activity_voice AS ac ON ac.activity_id = art.activity_id `
  1056. }
  1057. if filter == 1 {
  1058. sqlJiontable = ` INNER JOIN cygx_activity_video AS av ON av.activity_id = art.activity_id `
  1059. } else if filter == 2 {
  1060. sqlJiontable = ` INNER JOIN cygx_activity_voice AS ac ON ac.activity_id = art.activity_id `
  1061. }
  1062. o := orm.NewOrm()
  1063. sql := `SELECT art.* ,t.activity_type,t.img_url_text,c.image_url as img_url,
  1064. ( SELECT COUNT( 1 ) FROM cygx_activity_signup AS s WHERE s.activity_id = art.activity_id AND s.user_id = ? AND s.is_cancel = 0 AND s.do_fail_type = 0) AS is_signup,
  1065. ( SELECT COUNT( DISTINCT user_id ) FROM cygx_activity_signup AS s WHERE s.activity_id = art.activity_id AND s.is_cancel = 0 AND s.do_fail_type = 0) AS signup_num,
  1066. ( SELECT COUNT( 1 ) FROM cygx_activity_meeting_reminder AS m WHERE m.activity_id = art.activity_id AND m.user_id = ? AND m.is_cancel = 0 ) AS is_cancel_meeting_reminder,
  1067. ( SELECT COUNT( 1 ) FROM cygx_activity_appointment AS ap WHERE ap.activity_id = art.activity_id AND ap.user_id = ? ) AS is_appointment
  1068. FROM cygx_activity as art
  1069. INNER JOIN cygx_activity_type as t ON t.activity_type_id = art.activity_type_id
  1070. INNER JOIN chart_permission AS c ON c.chart_permission_id = art.chart_permission_id ` + sqlJiontable + ` WHERE 1= 1 `
  1071. if condition != "" {
  1072. sql += condition
  1073. }
  1074. sql += ` LIMIT ?,?`
  1075. if typeName != "" {
  1076. typeSlice := strings.Split(typeName, ",")
  1077. tempCondition := ""
  1078. for _, s := range typeSlice {
  1079. if s == "1" {
  1080. tempCondition += "'专家电话会',"
  1081. } else if s == "2" {
  1082. tempCondition += "'分析师电话会',"
  1083. } else if s == "1,2" {
  1084. tempCondition += "'专家电话会','分析师电话会',"
  1085. }
  1086. }
  1087. tempCondition = strings.TrimRight(tempCondition, ",")
  1088. sql = `SELECT * FROM(` + sql + `) AS t WHERE t.activity_type_name IN (` + tempCondition + `)`
  1089. }
  1090. _, err = o.Raw(sql, uid, uid, uid, pars, startSize, pageSize).QueryRows(&items)
  1091. return
  1092. }
  1093. // 列表
  1094. func GetActivityListHomeNew(condition string, startSize, pageSize int) (items []*ActivityDetail, err error) {
  1095. o := orm.NewOrm()
  1096. sql := `SELECT activity_id
  1097. FROM cygx_activity as art
  1098. INNER JOIN cygx_activity_type as t ON t.activity_type_id = art.activity_type_id
  1099. INNER JOIN chart_permission AS c ON c.chart_permission_id = art.chart_permission_id WHERE 1= 1 `
  1100. if condition != "" {
  1101. sql += condition
  1102. }
  1103. sql += ` LIMIT ?,?`
  1104. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  1105. return
  1106. }
  1107. // 主题列表
  1108. func GetActivityLabelListAllNoLimit(condition, sortTime string, pars []interface{}, conditionSpecial string) (items []*CygxActivityLabelList, err error) {
  1109. o := orm.NewOrm()
  1110. sql := `SELECT activity_id, label,temporary_label,is_show_subject_name, art.activity_time, 1 AS resource, yidong_activity_id
  1111. FROM cygx_activity as art WHERE 1= 1 `
  1112. if condition != "" {
  1113. sql += condition
  1114. }
  1115. sql += ` UNION ALL `
  1116. sql += ` SELECT
  1117. art.activity_id,
  1118. art.label,
  1119. art.temporary_label,
  1120. is_show_subject_name,
  1121. art.activity_time,
  1122. 2 AS resource,
  1123. '' AS yidong_activity_id
  1124. FROM
  1125. cygx_activity_special AS art WHERE 1= 1 ` + conditionSpecial
  1126. sql += ` GROUP BY label,resource ORDER BY ` + sortTime + ` , activity_id DESC `
  1127. _, err = o.Raw(sql, pars).QueryRows(&items)
  1128. return
  1129. }