activity_signup.go 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114
  1. package cygx
  2. import (
  3. "fmt"
  4. "hongze/hz_crm_api/models/company"
  5. "hongze/hz_crm_api/utils"
  6. //"hongze/hongze_admin/models"
  7. "github.com/beego/beego/v2/client/orm"
  8. "github.com/rdlucklib/rdluck_tools/paging"
  9. "time"
  10. )
  11. // 活动详情
  12. type CygxSignupList struct {
  13. ActivityId int `orm:"column(activity_id);pk";description:"活动ID 等于0新增活动,大于0修改活动"`
  14. ActivityName string `description:"活动名称"`
  15. ActivityTypeName string `description:"活动类型名称"`
  16. ChartPermissionName string `description:"行业名称"`
  17. ChartPermissionNames string `description:"行业名称辅助字段,区分研选子分类"`
  18. LimitPeopleNum int `description:"限制的人数数量"`
  19. ActivityTime string `description:"活动时间"`
  20. ActivityTimeText string `description:"活动时间带文字"`
  21. SignupPeopleNum int `description:"报名人数/预约外呼人数"`
  22. SignupFailPeopleNum int `description:"报名/预约外呼失败人数"`
  23. AskNum int `description:"带问人数"`
  24. AppointmentPeopleNum int `description:"预约纪要人数"`
  25. ReminderPeopleNum int `description:"设置会议提醒人数"`
  26. IsShowAppointment bool `description:"是否展示预约纪要"`
  27. IsHideAppointment int `description:"是否隐藏预约纪要按钮 1是,0 否"`
  28. ActivityTypeId int `description:"活动类型id"`
  29. Label string `description:"标签"`
  30. ActiveState int `description:"活动进行状态 未开始:1、进行中2、已结束3"`
  31. PublishStatus int `description:"发布状态 1已发布,0未发布"`
  32. TemporaryLabel string `description:"临时标签"`
  33. YidongActivityId string `description:"易董的活动ID"`
  34. IsCanAppointmentMinutes int `description:"是否可预约纪要 1是 ,0 否 默认0 "`
  35. IsCancel int `description:"是否取消,1是,0否"`
  36. IsYidongConduct int `description:"是否属于易董办会 1:是 、0:否"`
  37. IsResearchPoints int `description:"是否为研选扣点 1是,0否"`
  38. ChartPermissionNameDeputy string `description:"副行业名称"`
  39. }
  40. type GetCygxSignupListRep struct {
  41. Paging *paging.PagingItem `description:"分页数据"`
  42. List []*CygxSignupList
  43. }
  44. // 获取数量
  45. func GetCygxSignupCount(condition string, pars []interface{}) (count int, err error) {
  46. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_activity as art WHERE 1= 1 `
  47. if condition != "" {
  48. sqlCount += condition
  49. }
  50. o := orm.NewOrmUsingDB("hz_cygx")
  51. err = o.Raw(sqlCount, pars).QueryRow(&count)
  52. return
  53. }
  54. // 列表
  55. func GetCygxSignupListAll(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxSignupList, err error) {
  56. o := orm.NewOrmUsingDB("hz_cygx")
  57. sql := `SELECT
  58. ( SELECT COUNT( 1 ) FROM cygx_activity_signup AS s WHERE s.activity_id = art.activity_id AND s.is_cancel = 0 AND s.do_fail_type = 0 AND s.company_id != 16 ) AS signup_people_num,
  59. ( SELECT COUNT( 1 ) FROM cygx_activity_signup AS s WHERE s.activity_id = art.activity_id AND s.is_cancel = 0 AND s.fail_type >= 1) AS signup_fail_people_num,
  60. ( SELECT COUNT( 1 ) FROM cygx_activity_help_ask AS k WHERE k.activity_id = art.activity_id ) AS ask_num,
  61. ( SELECT COUNT( 1 ) FROM cygx_activity_appointment AS ap WHERE ap.activity_id = art.activity_id ) AS appointment_people_num,
  62. ( SELECT COUNT( 1 ) FROM cygx_activity_meeting_reminder AS ap WHERE ap.activity_id = art.activity_id ) AS reminder_people_num,
  63. art.* FROM cygx_activity as art
  64. WHERE 1= 1 `
  65. if condition != "" {
  66. sql += condition
  67. }
  68. sql += ` LIMIT ?,?`
  69. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  70. return
  71. }
  72. type CygxAppointmentList struct {
  73. Id int `orm:"column(id);pk"`
  74. ActivityId int `description:"活动ID"`
  75. ActivityTime string `description:"活动时间"`
  76. UserId int `description:"用户ID"`
  77. CreateTime string `description:"创建时间"`
  78. Mobile string `description:"手机号"`
  79. OutboundMobile string `description:"外呼手机号"`
  80. CountryCode string `description:"手机国家区号"`
  81. CompanyName string `description:"公司名称"`
  82. CompanyId int `description:"公司ID"`
  83. RealName string `description:"姓名"`
  84. FailType int `description:"失败原因,0,未失败,1总人数已满,2单机构超限制,3,爽约次数超限"`
  85. //MeetingType int `description:"参会方式,0,无,1预约外呼,2自主拨入"`
  86. SellerName string `description:"销售姓名"`
  87. PsellerName string `description:"销售姓名"`
  88. SignupType int `description:"报名方式,1预约外呼,2自主拨入,3我要报名"`
  89. YidongExamineStatus int `description:"易董活动报名审核状态0审核中,1:审核通过、2审核不通过"`
  90. Email string `description:"邮箱"`
  91. }
  92. type CygxSignupUser struct {
  93. UserId int `description:"用户ID"`
  94. ActivityId int `description:"活动ID"`
  95. }
  96. type CygxSignupId struct {
  97. SignupId int `description:"报名ID"`
  98. CancelClass int `description:"取消类型 0取消报名,1取消外呼"`
  99. }
  100. // 预约外呼列表
  101. func GetCygxAppointmentLisssst(activityId int) (items []*CygxAppointmentList, err error) {
  102. o := orm.NewOrmUsingDB("hz_cygx")
  103. sql := `SELECT * FROM cygx_activity_signup WHERE activity_id= ? `
  104. _, err = o.Raw(sql, activityId).QueryRows(&items)
  105. return
  106. }
  107. func GetCygxAppointmentList(article_id int, sqlStr string) (item []*CygxAppointmentList, err error) {
  108. o := orm.NewOrmUsingDB("hz_cygx")
  109. sql := `SELECT s.*
  110. FROM
  111. cygx_activity_signup AS s
  112. LEFT JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  113. WHERE a.activity_id = ? AND s.do_fail_type = 0 ` + sqlStr + ` GROUP BY s.user_id ORDER BY s.create_time DESC `
  114. _, err = o.Raw(sql, article_id).QueryRows(&item)
  115. return
  116. }
  117. type GetAppointmentListRep struct {
  118. ExcelType string `description:"EXcel下载类型 AppointmentCall:预约外呼、ExpertSalon:专家沙龙报名、Teleconference:公司调研电话会、OfflineResearch:公司线下调研 、CClass: C类电话会 、YiDong:易董 "`
  119. ActivityId int `description:"活动ID"`
  120. Total int `description:"总人数"`
  121. MyTotal int `description:"本人名下客户"`
  122. IsLimitPeople int `description:"是否限制人数 1是,0否"`
  123. MemberType string `description:"管理员身份 Admin:超级管理员、权益管理员、权益研究员、专家组;GroupLeader:组长;Sale:销售"`
  124. ActivityType int `description:"1线上 ,0 线下"`
  125. IsYidongConduct int `description:"是否属于易董办会 1:是 、0:否"`
  126. IsResearchPoints int `description:"是否为研选扣点 1是,0否"`
  127. List []*CygxAppointmentList
  128. }
  129. func GetCygxAppointmentCount(articleId int, sqlStr string) (count int, err error) {
  130. o := orm.NewOrmUsingDB("hz_cygx")
  131. sql := `SELECT COUNT(*) FROM
  132. cygx_activity_signup AS s
  133. LEFT JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  134. WHERE
  135. s.activity_id = ? ` + sqlStr + `
  136. GROUP BY s.user_id)`
  137. sql = `SELECT COUNT(*) as count FROM (` + sql + ` a`
  138. err = o.Raw(sql, articleId).QueryRow(&count)
  139. return
  140. }
  141. // 新增外呼人员
  142. type GetOutboundPersonnelListRep struct {
  143. List []*GetOutboundPersonnelRep
  144. }
  145. type GetOutboundPersonnelRep struct {
  146. UserId int `description:"用户id"`
  147. RealName string `description:"姓名"`
  148. Mobile string `description:"手机号"`
  149. CompanyName string `description:"公司名称"`
  150. }
  151. // 列表
  152. func GetOutboundPersonnelList(name string) (items []*GetOutboundPersonnelRep, err error) {
  153. o := orm.NewOrm()
  154. sql := `SELECT u.user_id,u.real_name,u.mobile,p.company_name FROM wx_user as u INNER JOIN company AS p ON p.company_id = u.company_id WHERE real_name LIKE '%` + name + `%' AND u.company_id >1 GROUP BY u.user_id ORDER BY user_id ASC`
  155. _, err = o.Raw(sql).QueryRows(&items)
  156. return
  157. }
  158. type AddOutboundPersonnelItm struct {
  159. UserIds string `description:"用户id,多个用,隔开"`
  160. ActivityIds string `description:"活动ID,多个用,隔开"`
  161. }
  162. type AddOutboundPersonnelJsonItm struct {
  163. JsonStar string `description:"报名信息json字符串 :Uid 用户ID,int类型 。Type string类型,报名方式,1预约外呼,2自主拨入 "`
  164. ActivityIds string `description:"活动ID,多个用,隔开"`
  165. }
  166. type CygxActivitySignup struct {
  167. Id int `orm:"column(id);pk"`
  168. UserId int `description:"用户id,多个用,隔开"`
  169. ActivityId int `description:"活动ID"`
  170. CreateTime time.Time `description:"创建时间"`
  171. Mobile string `description:"手机号"`
  172. Email string `description:"邮箱号"`
  173. CompanyId int `description:"公司ID"`
  174. CompanyName string `description:"公司名称"`
  175. OutboundMobile string `description:"外呼手机号"`
  176. CountryCode string `description:"手机国家区号"`
  177. Source int `description:"来源,1小程序,2后台添加"`
  178. SignupType int `description:"报名方式,1预约外呼,2自主拨入,3我要报名"`
  179. RealName string `description:"用户实际名称"`
  180. SellerName string `description:"所属销售"`
  181. }
  182. // 我的日程
  183. type CygxMySchedule struct {
  184. Id int `orm:"column(id);pk"`
  185. ActivityId int `description:"活动ID"`
  186. UserId int `description:"用户ID"`
  187. CreateTime time.Time `description:"创建时间"`
  188. Mobile string `description:"手机号"`
  189. Email string `description:"邮箱"`
  190. CompanyId int `description:"公司id"`
  191. CompanyName string `description:"公司名称"`
  192. }
  193. type UserAndCompanyName struct {
  194. UserId int `orm:"column(user_id);pk"`
  195. Mobile string
  196. Email string
  197. CompanyId int
  198. CompanyName string `description:"公司名称"`
  199. CountryCode string `description:"手机国家区号"`
  200. OutboundMobile string `description:"外呼手机号"`
  201. OutboundCountryCode string `description:"外呼手机号区号"`
  202. SellerName string `description:"所属销售"`
  203. RealName string `description:"真实姓名"`
  204. }
  205. func GetUserAndCompanyNameList(uid int) (item *UserAndCompanyName, err error) {
  206. o := orm.NewOrm()
  207. sql := ` SELECT
  208. u.*,
  209. c.company_name,
  210. GROUP_CONCAT( DISTINCT p.seller_name SEPARATOR '/' ) AS seller_name
  211. FROM
  212. wx_user AS u
  213. INNER JOIN company AS c ON c.company_id = u.company_id
  214. LEFT JOIN company_product AS p ON p.company_id = u.company_id
  215. WHERE
  216. user_id = ?`
  217. err = o.Raw(sql, uid).QueryRow(&item)
  218. return
  219. }
  220. func GetUserAndCompanyNameListByUids(uids string) (items []*UserAndCompanyName, err error) {
  221. o := orm.NewOrm()
  222. sql := ` SELECT u.*,c.company_name FROM wx_user AS u
  223. INNER JOIN company AS c ON c.company_id = u.company_id
  224. WHERE user_id IN (` + uids + `)`
  225. _, err = o.Raw(sql).QueryRows(&items)
  226. return
  227. }
  228. // 新增预约人数
  229. func AddCygxActivitySignup(items []*CygxActivitySignup, itemsAppointment []*CygxActivityAppointment, mapYidongActivity map[int]int) (err error) {
  230. o := orm.NewOrmUsingDB("hz_cygx")
  231. to, err := o.Begin()
  232. if err != nil {
  233. return
  234. }
  235. defer func() {
  236. if err != nil {
  237. _ = to.Rollback()
  238. } else {
  239. _ = to.Commit()
  240. }
  241. }()
  242. //添加预约纪要部分
  243. if len(itemsAppointment) > 0 {
  244. for _, item := range itemsAppointment {
  245. var count int
  246. sql := `SELECT COUNT(1) AS count FROM cygx_activity_appointment WHERE user_id=? AND activity_id=? `
  247. err = to.Raw(sql, item.UserId, item.ActivityId).QueryRow(&count)
  248. if err != nil {
  249. return
  250. }
  251. if count == 0 {
  252. _, err = to.Insert(item)
  253. if err != nil {
  254. return
  255. }
  256. }
  257. }
  258. }
  259. //添加会议提醒
  260. for _, item := range items {
  261. var count int
  262. sql := `SELECT COUNT(1) AS count FROM cygx_my_schedule WHERE user_id=? AND activity_id=? `
  263. err = to.Raw(sql, item.UserId, item.ActivityId).QueryRow(&count)
  264. if err != nil {
  265. return
  266. }
  267. //如果是易懂的活动就不加入日程
  268. if count == 0 && mapYidongActivity[item.ActivityId] == 0 {
  269. itemMy := new(CygxMySchedule)
  270. itemMy.UserId = item.UserId
  271. itemMy.ActivityId = item.ActivityId
  272. itemMy.CreateTime = time.Now()
  273. itemMy.Mobile = item.Mobile
  274. itemMy.Email = item.Email
  275. itemMy.CompanyId = item.CompanyId
  276. itemMy.CompanyName = item.CompanyName
  277. _, err = to.Insert(itemMy)
  278. if err != nil {
  279. return
  280. }
  281. }
  282. sql = `SELECT COUNT(1) AS count FROM cygx_activity_signup WHERE user_id=? AND activity_id=? `
  283. err = to.Raw(sql, item.UserId, item.ActivityId).QueryRow(&count)
  284. if err != nil {
  285. return
  286. }
  287. if count == 0 {
  288. _, err = to.Insert(item)
  289. } else {
  290. sql := `UPDATE cygx_activity_signup SET is_cancel=0, do_fail_type = 0 ,create_time = NOW() WHERE user_id=? AND activity_id=? `
  291. _, err = to.Raw(sql, item.UserId, item.ActivityId).Exec()
  292. }
  293. }
  294. return
  295. }
  296. // 获取用户报名数量
  297. func GetActivitySignupCount(uid, activityId int) (count int, err error) {
  298. sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_signup WHERE is_cancel=0 AND do_fail_type = 0 AND user_id=? AND activity_id=? `
  299. o := orm.NewOrmUsingDB("hz_cygx")
  300. err = o.Raw(sqlCount, uid, activityId).QueryRow(&count)
  301. return
  302. }
  303. func GetActivitySignupCountByActivityId(activityId int) (count int, err error) {
  304. sqlCount := `SELECT
  305. COUNT( 1 ) AS count
  306. FROM
  307. cygx_activity_signup AS s
  308. WHERE
  309. s.do_fail_type = 0
  310. AND s.company_id != 16
  311. AND s.activity_id = ? `
  312. o := orm.NewOrmUsingDB("hz_cygx")
  313. err = o.Raw(sqlCount, activityId).QueryRow(&count)
  314. return
  315. }
  316. func GetActivitySignupCountByThisUser(activityId int, uids string) (count int, err error) {
  317. sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_signup WHERE do_fail_type = 0 AND activity_id=? AND user_id IN (` + uids + `) `
  318. o := orm.NewOrmUsingDB("hz_cygx")
  319. err = o.Raw(sqlCount, activityId).QueryRow(&count)
  320. return
  321. }
  322. //end
  323. // 报名失败
  324. type FailSignupListRep struct {
  325. Id int `orm:"column(id);pk;"description:"报名ID"`
  326. ActivityId int `description:"活动ID"`
  327. CreateTime string `description:"创建时间"`
  328. Mobile string `description:"手机号"`
  329. CompanyName string `description:"公司名称"`
  330. CompanyId int `description:"公司ID"`
  331. RealName string `description:"姓名"`
  332. UserId int `description:"用户id"`
  333. SellerName string `description:"销售姓名"`
  334. PsellerName string `description:"销售姓名"`
  335. FailType int `description:"失败原因,0,未失败,1总人数已满,2单机构超限制,3,爽约次数超限"`
  336. DoFailType int `description:"报名失败之后的操作,失败原因,0,未失败,1总人数已满,2单机构超限制,3,爽约次数超限"`
  337. SalonOperation bool `description:"操作按钮1,true,加入报名,false 限制报名"`
  338. CallOperation int `description:"操作按钮2,1预约外呼,2自主拨入,3限制报名"`
  339. IsAdminAddSignup int `description:"(多余字段不使用)"`
  340. MeetingType int `description:"(多余字段不使用)"`
  341. IsMeeting int `description:"是否到会 ,1是, 0否"`
  342. SignupType int `description:"报名方式,1预约外呼,2自主拨入,3我要报名"`
  343. }
  344. type GetFailSignupListRep struct {
  345. ExcelType string `description:"EXcel下载类型 AppointmentCall:预约外呼、ExpertSalon:专家沙龙报名、Teleconference:公司调研电话会、OfflineResearch:公司线下调研 "`
  346. MemberType string `description:"管理员身份 Admin:超级管理员、权益管理员、权益研究员、专家组;GroupLeader:组长;Sale:销售"`
  347. //ActivityId int `description:"活动ID"`
  348. Total int `description:"预约外呼总人数"`
  349. MyTotal int `description:"预约外呼本人名下客户"`
  350. IsLimitPeople int `description:"是否限制人数 1是,0否"`
  351. IsFull bool `description:"报名人数是否已满"`
  352. List []*FailSignupListRep
  353. }
  354. func GetFailSignupList(activity_id int, sqlStr string) (item []*FailSignupListRep, err error) {
  355. o := orm.NewOrmUsingDB("hz_cygx")
  356. sql := `SELECT s.* ,a.is_limit_people
  357. FROM
  358. cygx_activity_signup AS s
  359. LEFT JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  360. WHERE a.activity_id = ?` + sqlStr + ` GROUP BY s.id ORDER BY s.create_time DESC `
  361. _, err = o.Raw(sql, activity_id).QueryRows(&item)
  362. return
  363. }
  364. //end
  365. type SignupId struct {
  366. Id int `orm:"column(id);pk;"description:"报名ID"`
  367. }
  368. type SignupIdCall struct {
  369. Id int `description:"报名ID"`
  370. OperationStatus int `description:"操作方式:1预约外呼,2自主拨入,3限制报名"`
  371. }
  372. // 获取失败数量
  373. func GetCygxSignupCountFile(id int) (count int, err error) {
  374. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_activity_signup WHERE id= ?`
  375. o := orm.NewOrmUsingDB("hz_cygx")
  376. err = o.Raw(sqlCount, id).QueryRow(&count)
  377. return
  378. }
  379. func GetCygxSignupDetailById(id int) (item *FailSignupListRep, err error) {
  380. o := orm.NewOrmUsingDB("hz_cygx")
  381. sql := `SELECT * FROM cygx_activity_signup WHERE id=?`
  382. err = o.Raw(sql, id).QueryRow(&item)
  383. return
  384. }
  385. func GetCygxSignupDetailByUid(id int) (item *FailSignupListRep, err error) {
  386. o := orm.NewOrmUsingDB("hz_cygx")
  387. sql := `SELECT * FROM cygx_activity_signup WHERE user_id=? LIMIT 1`
  388. err = o.Raw(sql, id).QueryRow(&item)
  389. return
  390. }
  391. // 加入报名限制报名
  392. func SalonSignupEdit(newIsAdminAddSignup, doFailType, id int, item *CygxActivitySignup) (err error) {
  393. o := orm.NewOrmUsingDB("hz_cygx")
  394. to, err := o.Begin()
  395. if err != nil {
  396. return
  397. }
  398. defer func() {
  399. if err != nil {
  400. fmt.Println(err)
  401. _ = to.Rollback()
  402. } else {
  403. _ = to.Commit()
  404. }
  405. }()
  406. var count int
  407. sql := `SELECT COUNT(1) AS count FROM cygx_activity_meeting_reminder WHERE user_id=? AND activity_id=? `
  408. err = to.Raw(sql, item.UserId, item.ActivityId).QueryRow(&count)
  409. if err != nil {
  410. return
  411. }
  412. sql = `UPDATE cygx_activity_signup SET is_admin_add_signup=?,do_fail_type=? WHERE id=? `
  413. _, err = to.Raw(sql, newIsAdminAddSignup, doFailType, id).Exec()
  414. if doFailType == 0 && count == 0 {
  415. //加入报名后并添加到我的日程
  416. itemMy := new(CygxMySchedule)
  417. itemMy.UserId = item.UserId
  418. itemMy.ActivityId = item.ActivityId
  419. itemMy.CreateTime = time.Now()
  420. itemMy.Mobile = item.Mobile
  421. itemMy.Email = item.Email
  422. itemMy.CompanyId = item.CompanyId
  423. itemMy.CompanyName = item.CompanyName
  424. _, err = to.Insert(itemMy)
  425. if err != nil {
  426. return
  427. }
  428. } else {
  429. //删除我的日程
  430. if count == 0 {
  431. sql = `DELETE FROM cygx_my_schedule WHERE user_id=? AND activity_id=? `
  432. _, err = to.Raw(sql, item.UserId, item.ActivityId).Exec()
  433. if err != nil {
  434. return
  435. }
  436. }
  437. }
  438. return
  439. }
  440. func CallSignupEditByStatus3(doFailType, id int, item *CygxMySchedule) (err error) {
  441. o := orm.NewOrmUsingDB("hz_cygx")
  442. to, err := o.Begin()
  443. if err != nil {
  444. return
  445. }
  446. defer func() {
  447. if err != nil {
  448. fmt.Println(err)
  449. _ = to.Rollback()
  450. } else {
  451. _ = to.Commit()
  452. }
  453. }()
  454. sql := `UPDATE cygx_activity_signup SET is_admin_add_signup=0, do_fail_type = ? WHERE id=? `
  455. _, err = to.Raw(sql, id, doFailType).Exec()
  456. if err != nil {
  457. return
  458. }
  459. sql = `DELETE FROM cygx_my_schedule WHERE user_id=? AND activity_id=? `
  460. _, err = to.Raw(sql, item.UserId, item.ActivityId).Exec()
  461. if err != nil {
  462. return
  463. }
  464. return
  465. }
  466. func CallSignupEditByStatus1_2(operationStatus, id int, item *CygxMySchedule) (err error) {
  467. o := orm.NewOrmUsingDB("hz_cygx")
  468. to, err := o.Begin()
  469. if err != nil {
  470. return
  471. }
  472. defer func() {
  473. if err != nil {
  474. fmt.Println(err)
  475. _ = to.Rollback()
  476. } else {
  477. _ = to.Commit()
  478. }
  479. }()
  480. var count int
  481. sql := `UPDATE cygx_activity_signup SET is_admin_add_signup = 1,do_fail_type=0, signup_type =? WHERE id=? `
  482. _, err = to.Raw(sql, operationStatus, id).Exec()
  483. if err != nil {
  484. return
  485. }
  486. sql = `SELECT COUNT(1) AS count FROM cygx_my_schedule WHERE user_id=? AND activity_id=? `
  487. err = to.Raw(sql, item.UserId, item.ActivityId).QueryRow(&count)
  488. if err != nil {
  489. return
  490. }
  491. if count == 0 {
  492. //添加我的日程
  493. _, err = to.Insert(item)
  494. }
  495. return
  496. }
  497. //报名信息Excel下载
  498. type SignupExportRep struct {
  499. Mobile string `description:"手机号"`
  500. CompanyName string `description:"公司名称"`
  501. RealName string `description:"姓名"`
  502. CountryCode string `description:"区号"`
  503. SellerName string `description:"销售姓名"`
  504. OutboundMobile string `description:"外呼手机号"`
  505. }
  506. type CygxActivitySignupList struct {
  507. Id int `orm:"column(id);pk"`
  508. UserId int `description:"用户id"`
  509. ActivityId int `description:"活动ID"`
  510. CompanyName string `description:"公司名称"`
  511. RealName string `description:"姓名"`
  512. CreateTime string `description:"创建时间"`
  513. IsMeeting int `description:"是否到会 ,1是, 0否"`
  514. Operation bool `description:"操作按钮,true,到会,false 未到会"`
  515. Channel int `description:"报名渠道,0 空降、 1小程序报名"`
  516. SigninTime string `description:"签到时间"`
  517. SellerName string `description:"所属销售"`
  518. Mobile string `description:"手机号"`
  519. Email string `description:"邮箱"`
  520. CompanyId int `description:"公司id"`
  521. IsAirborne int `description:"是否属于空降 1.是 ,0否"`
  522. }
  523. type CygxActivitySignupListRep struct {
  524. ActivityId int `description:"活动ID"`
  525. List []*CygxActivitySignupList
  526. ListSignin []*CygxActivitySignin
  527. }
  528. // 预约外呼列表
  529. func GetCygxActivitySignup(condition string) (items []*CygxActivitySignupList, err error) {
  530. o := orm.NewOrmUsingDB("hz_cygx")
  531. sql := `SELECT s.* FROM cygx_activity_signup as s
  532. WHERE 1 =1 ` + condition
  533. _, err = o.Raw(sql).QueryRows(&items)
  534. return
  535. }
  536. // 获取用户报名数量
  537. func GetActivitySignupNomeetingCount(activityId int) (count int, err error) {
  538. o := orm.NewOrmUsingDB("hz_cygx")
  539. sqlCount := `SELECT
  540. COUNT( 1 ) count
  541. FROM
  542. cygx_activity_signup AS s
  543. INNER JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  544. WHERE
  545. 1 = 1
  546. AND a.is_limit_people > 0
  547. AND s.is_meeting = 0
  548. AND a.is_submit_meeting = 1
  549. AND a.activity_id = ?`
  550. err = o.Raw(sqlCount, activityId).QueryRow(&count)
  551. return
  552. }
  553. // 获取用户报名列表
  554. func GetActivitySignupNomeetingCountList(activityId int) (items []*CygxActivitySignupList, err error) {
  555. o := orm.NewOrmUsingDB("hz_cygx")
  556. sql := `SELECT
  557. s.*
  558. FROM
  559. cygx_activity_signup AS s
  560. INNER JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  561. WHERE
  562. 1 = 1
  563. AND s.do_fail_type = 0
  564. AND s.is_meeting = 0
  565. AND a.activity_id = ?`
  566. _, err = o.Raw(sql, activityId).QueryRows(&items)
  567. return
  568. }
  569. // 获取用户爽约次数
  570. func GetActivitySignupNomeetingCountByUid(uid int) (count int, err error) {
  571. o := orm.NewOrmUsingDB("hz_cygx")
  572. sqlCount := `SELECT
  573. COUNT( 1 ) count
  574. FROM
  575. cygx_activity_signup AS s
  576. INNER JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  577. WHERE
  578. 1 = 1
  579. AND a.is_limit_people > 0
  580. AND s.is_meeting = 0
  581. AND a.is_submit_meeting = 1
  582. AND s.do_fail_type = 0
  583. AND s.user_id = ?`
  584. err = o.Raw(sqlCount, uid).QueryRow(&count)
  585. return
  586. }
  587. func GetUserMeetingMobile(activityId int) (items []*CygxActivitySignup, err error) {
  588. o := orm.NewOrmUsingDB("hz_cygx")
  589. sql := `SELECT *
  590. FROM
  591. cygx_activity_signup AS s
  592. WHERE
  593. s.is_meeting = 1
  594. AND s.activity_id = ?`
  595. _, err = o.Raw(sql, activityId).QueryRows(&items)
  596. return
  597. }
  598. // 修改外呼电话以及区号
  599. type OutboundMobileEditResp struct {
  600. Id int `description:"报名ID"`
  601. OutboundMobile string `description:"外呼手机号"`
  602. CountryCode string `description:"手机国家区号"`
  603. }
  604. func OutboundMobileEdit(id int, outboundMobile, countryCode string) (err error) {
  605. o := orm.NewOrmUsingDB("hz_cygx")
  606. sql := `UPDATE cygx_activity_signup SET outbound_mobile = ?,country_code=? WHERE id=? `
  607. _, err = o.Raw(sql, outboundMobile, countryCode, id).Exec()
  608. return
  609. }
  610. //end
  611. func AddCygxActivitySignupUser(items []*CygxActivitySignup) (err error) {
  612. o := orm.NewOrmUsingDB("hz_cygx")
  613. to, err := o.Begin()
  614. if err != nil {
  615. return
  616. }
  617. defer func() {
  618. if err != nil {
  619. fmt.Println(err)
  620. _ = to.Rollback()
  621. } else {
  622. _ = to.Commit()
  623. }
  624. }()
  625. for _, item := range items {
  626. var count int
  627. sql := `SELECT COUNT(1) AS count FROM cygx_my_schedule WHERE user_id=? AND activity_id=? `
  628. err = to.Raw(sql, item.UserId, item.ActivityId).QueryRow(&count)
  629. if err != nil {
  630. return
  631. }
  632. if count == 0 {
  633. itemMy := new(CygxMySchedule)
  634. itemMy.UserId = item.UserId
  635. itemMy.ActivityId = item.ActivityId
  636. itemMy.CreateTime = time.Now()
  637. itemMy.Mobile = item.Mobile
  638. itemMy.Email = item.Email
  639. itemMy.CompanyId = item.CompanyId
  640. itemMy.CompanyName = item.CompanyName
  641. _, err = to.Insert(itemMy)
  642. if err != nil {
  643. return
  644. }
  645. }
  646. sql = `SELECT COUNT(1) AS count FROM cygx_activity_signup WHERE user_id=? AND activity_id=? `
  647. err = to.Raw(sql, item.UserId, item.ActivityId).QueryRow(&count)
  648. if err != nil {
  649. return
  650. }
  651. if count == 0 {
  652. _, err = to.Insert(item)
  653. } else {
  654. sql := `UPDATE cygx_activity_signup SET is_cancel=0, do_fail_type = 0 ,create_time = NOW() WHERE user_id=? AND activity_id=? `
  655. _, err = to.Raw(sql, item.UserId, item.ActivityId).Exec()
  656. }
  657. }
  658. return
  659. }
  660. // 通过ID获取报名详情
  661. func GetActivitySignupInfoById(id int) (item *CygxActivitySignup, err error) {
  662. o := orm.NewOrmUsingDB("hz_cygx")
  663. sql := `SELECT * FROM cygx_activity_signup WHERE id=?`
  664. err = o.Raw(sql, id).QueryRow(&item)
  665. return
  666. }
  667. type RequestCommonPolicyConfigrep struct {
  668. Type string `description:"报名方式 ,1 预约外呼 ,2 自主拨入"`
  669. Uid int `description:"用户ID"`
  670. }
  671. type RequestCommonPolicyConfig struct {
  672. CommonPolicyconfig []interface{} `json:"common_policy_config"`
  673. CommonPolicyconfigs []RequestCommonPolicyConfigrep `json:"common_policy_configs"`
  674. }
  675. // 取消报名
  676. func CancelActivitySignup(item *CygxActivitySignup) (lastId int64, err error) {
  677. o := orm.NewOrmUsingDB("hz_cygx")
  678. to, err := o.Begin()
  679. if err != nil {
  680. return
  681. }
  682. defer func() {
  683. if err != nil {
  684. fmt.Println(err)
  685. _ = to.Rollback()
  686. } else {
  687. _ = to.Commit()
  688. }
  689. }()
  690. //判断是否删除我的日程
  691. var count int
  692. sql := `SELECT COUNT(1) AS count FROM cygx_activity_meeting_reminder WHERE is_cancel = 0 AND user_id=? AND activity_id=? `
  693. err = to.Raw(sql, item.UserId, item.ActivityId).QueryRow(&count)
  694. if err != nil {
  695. return
  696. }
  697. if count == 0 {
  698. sql = `DELETE FROM cygx_my_schedule WHERE user_id=? AND activity_id=? `
  699. _, err = to.Raw(sql, item.UserId, item.ActivityId).Exec()
  700. if err != nil {
  701. return
  702. }
  703. }
  704. sql = `DELETE FROM cygx_activity_signup WHERE user_id=? AND activity_id=? `
  705. _, err = to.Raw(sql, item.UserId, item.ActivityId).Exec()
  706. if err != nil {
  707. return
  708. }
  709. return
  710. }
  711. func GetCompanyPermission(companyId int) (permission string, err error) {
  712. sql := ` SELECT GROUP_CONCAT(DISTINCT b.remark ORDER BY b.sort ASC SEPARATOR ',') AS permission
  713. FROM company_report_permission AS a
  714. INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
  715. INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id
  716. WHERE a.company_id=?
  717. AND c.is_suspend=0
  718. AND b.cygx_auth=1
  719. AND c.status IN('正式','试用','永续')
  720. AND a.status IN('正式','试用','永续') `
  721. o := orm.NewOrm()
  722. err = o.Raw(sql, companyId).QueryRow(&permission)
  723. return
  724. }
  725. // 获取可查看升级权限的正式权限
  726. func GetCompanyPermissionByUserZhengShiTrip(companyId int) (permission string, err error) {
  727. sql := ` SELECT GROUP_CONCAT(DISTINCT b.chart_permission_name ORDER BY b.sort ASC SEPARATOR ',') AS permission
  728. FROM company_report_permission AS a
  729. INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
  730. INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id
  731. WHERE a.company_id=?
  732. AND c.is_suspend=0
  733. AND b.cygx_auth=1
  734. AND ( a.is_upgrade = 1 AND c.STATUS = '正式' OR c.STATUS = '永续' ) `
  735. o := orm.NewOrm()
  736. err = o.Raw(sql, companyId).QueryRow(&permission)
  737. return
  738. }
  739. func GetCountCompanyDetailByIdGroup(companyId int) (count int, err error) {
  740. sql := ` SELECT COUNT(1) AS count
  741. FROM company AS a
  742. INNER JOIN company_product AS b ON a.company_id=b.company_id
  743. INNER JOIN company_report_permission AS p ON p.company_id = a.company_id
  744. INNER JOIN chart_permission AS cp ON cp.chart_permission_id = p.chart_permission_id
  745. LEFT JOIN admin AS c ON b.seller_id=c.admin_id
  746. WHERE a.company_id=? AND b.product_id = 2 OR (a.company_id = ? AND cp.permission_name = '策略' ) `
  747. o := orm.NewOrm()
  748. err = o.Raw(sql, companyId, companyId).QueryRow(&count)
  749. return
  750. }
  751. type CompanyDetail struct {
  752. CompanyId int `orm:"column(company_id);pk"`
  753. CompanyName string `description:"客户名称"`
  754. Status string `description:"客户状态"`
  755. SellerId int `description:"销售id"`
  756. SellerName string `description:"销售名称"`
  757. Mobile string `description:"销售手机号"`
  758. ProductId int `description:"1,FICC,2权益"`
  759. }
  760. func GetCompanyDetailByIdGroup(companyId int) (item *CompanyDetail, err error) {
  761. sql := ` SELECT a.company_id,a.company_name,b.status,b.seller_id,b.seller_name,c.mobile
  762. FROM company AS a
  763. INNER JOIN company_product AS b ON a.company_id=b.company_id
  764. INNER JOIN company_report_permission AS p ON p.company_id = a.company_id
  765. INNER JOIN chart_permission AS cp ON cp.chart_permission_id = p.chart_permission_id
  766. LEFT JOIN admin AS c ON b.seller_id=c.admin_id
  767. WHERE a.company_id=? AND b.product_id = 2
  768. OR (a.company_id = ? AND cp.permission_name = '策略' )
  769. ORDER BY b.product_id DESC LIMIT 0,1 `
  770. o := orm.NewOrm()
  771. err = o.Raw(sql, companyId, companyId).QueryRow(&item)
  772. return
  773. }
  774. func GetCompanyPermissionByUser(companyId int) (permission string, err error) {
  775. sql := ` SELECT GROUP_CONCAT(DISTINCT b.remark ORDER BY b.sort ASC SEPARATOR ',') AS permission
  776. FROM company_report_permission AS a
  777. INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
  778. INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id
  779. WHERE a.company_id=?
  780. AND c.is_suspend=0
  781. AND b.cygx_auth=1`
  782. o := orm.NewOrm()
  783. err = o.Raw(sql, companyId).QueryRow(&permission)
  784. return
  785. }
  786. // 获取正式权限
  787. func GetCompanyPermissionByUserZhengShi(companyId int) (permission string, err error) {
  788. sql := ` SELECT GROUP_CONCAT(DISTINCT b.remark ORDER BY b.sort ASC SEPARATOR ',') AS permission
  789. FROM company_report_permission AS a
  790. INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
  791. INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id
  792. WHERE a.company_id=?
  793. AND c.is_suspend=0
  794. AND b.cygx_auth=1
  795. AND c.status IN('正式')
  796. AND a.status IN('正式') `
  797. o := orm.NewOrm()
  798. err = o.Raw(sql, companyId).QueryRow(&permission)
  799. return
  800. }
  801. // 活动模板消息推送,权限处理start
  802. // GetCompanyDetailByIdGroupList 根据公司ID获取公司对应状态
  803. func GetCompanyDetailByIdGroupList(companyIds []int) (items []*CompanyDetail, err error) {
  804. lenCompanyId := len(companyIds)
  805. if lenCompanyId == 0 {
  806. return
  807. }
  808. sql := ` SELECT a.company_id,a.company_name,b.status
  809. FROM company AS a
  810. INNER JOIN company_product AS b ON a.company_id=b.company_id
  811. WHERE a.company_id IN (` + utils.GetOrmInReplace(lenCompanyId) + `) AND b.product_id = 2
  812. GROUP BY a.company_id `
  813. o := orm.NewOrm()
  814. _, err = o.Raw(sql, companyIds).QueryRows(&items)
  815. return
  816. }
  817. type CompanyPermission struct {
  818. CompanyId int `description:"公司ID"`
  819. PermissionName string `description:"权限名称"`
  820. }
  821. // 公司权限结构体
  822. type CompanyPermissionPower struct {
  823. CompanyId int `description:"公司ID"`
  824. UserType int `description:"用户类型 //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //3、分行业套餐客户(开通对应行业的正式客户) //4、仅开通专家套餐的正式客户 //5、开通对应行业套餐或专家套餐的试用客户"`
  825. Status string `description:"客户状态"`
  826. PermissionName string `description:"权限名称"`
  827. PermissionNameZhengShi string `description:"权限名称(正式)"`
  828. HavePower bool `description:"是否有权限"`
  829. }
  830. // GetCompanyPermissionByCompanyIds 根据公司ID获取公司对应的权限
  831. func GetCompanyPermissionByCompanyIds(companyIds []int) (items []*CompanyPermission, err error) {
  832. lenCompanyId := len(companyIds)
  833. if lenCompanyId == 0 {
  834. return
  835. }
  836. sql := ` SELECT
  837. GROUP_CONCAT( DISTINCT b.remark ORDER BY b.sort ASC SEPARATOR ',' ) AS permission_name,
  838. a.company_id
  839. FROM
  840. company_report_permission AS a
  841. INNER JOIN chart_permission AS b ON a.chart_permission_id = b.chart_permission_id
  842. INNER JOIN company_product AS c ON a.company_id = c.company_id
  843. AND a.product_id = c.product_id
  844. WHERE
  845. a.company_id IN (` + utils.GetOrmInReplace(lenCompanyId) + `)
  846. AND c.is_suspend = 0
  847. AND b.cygx_auth = 1
  848. GROUP BY
  849. a.company_id `
  850. o := orm.NewOrm()
  851. _, err = o.Raw(sql, companyIds).QueryRows(&items)
  852. return
  853. }
  854. // GetCompanyPermissionZhenShiByCompanyIds 根据公司ID获取正式公司对应的权限
  855. func GetCompanyPermissionZhenShiByCompanyIds(companyIds []int) (items []*CompanyPermission, err error) {
  856. lenCompanyId := len(companyIds)
  857. if lenCompanyId == 0 {
  858. return
  859. }
  860. sql := ` SELECT
  861. GROUP_CONCAT( DISTINCT b.remark ORDER BY b.sort ASC SEPARATOR ',' ) AS permission_name,
  862. a.company_id
  863. FROM
  864. company_report_permission AS a
  865. INNER JOIN chart_permission AS b ON a.chart_permission_id = b.chart_permission_id
  866. INNER JOIN company_product AS c ON a.company_id = c.company_id
  867. AND a.product_id = c.product_id
  868. WHERE
  869. a.company_id IN (` + utils.GetOrmInReplace(lenCompanyId) + `)
  870. AND c.is_suspend = 0
  871. AND b.cygx_auth = 1
  872. AND c.STATUS IN ( '正式' )
  873. AND a.STATUS IN ( '正式' )
  874. GROUP BY
  875. a.company_id `
  876. o := orm.NewOrm()
  877. _, err = o.Raw(sql, companyIds).QueryRows(&items)
  878. return
  879. }
  880. type YidongActivitySignup struct {
  881. YidongActivityId string `description:"易董的活动ID"`
  882. Mobile string `description:"手机号"`
  883. RealName string `description:"用户实际名称"`
  884. CompanyName string `description:"公司名称"`
  885. CountryCode string `description:"手机国家区号"`
  886. ActivityJoinType string `description:"活动入会类型01报名审核后可入会 02预约即可入会 03仅定向邀请人员可入会"`
  887. }
  888. // GetCompanyByUserSignUp 获取客户ID列表
  889. func GetCompanyByUserSignUp(condition string, pars []interface{}) (items []*company.CompanyNameAndId, err error) {
  890. o := orm.NewOrmUsingDB("hz_cygx")
  891. sql := `SELECT
  892. s.company_id
  893. FROM
  894. cygx_activity_signup AS s
  895. INNER JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  896. INNER JOIN cygx_activity_type AS t ON t.activity_type_id = a.activity_type_id
  897. WHERE
  898. 1 = 1
  899. AND s.is_meeting = 1
  900. AND t.activity_type = 1 `
  901. if condition != `` {
  902. sql += condition
  903. }
  904. sql += ` GROUP BY s.company_id `
  905. _, err = o.Raw(sql, pars).QueryRows(&items)
  906. return
  907. }
  908. type UserSignUpLossResp struct {
  909. Mobile string `description:"手机号"`
  910. RealName string `description:"姓名"`
  911. TotalMeeting int `description:"参会次数"`
  912. }
  913. type UserSignUpLossListResp struct {
  914. CompanyId int `description:"公司Id"`
  915. CompanyName string `description:"公司名称"`
  916. SellerName string `description:"销售名称"`
  917. List []*UserSignUpLossResp
  918. }
  919. // GetUserSignUpList 获取用户报名列表
  920. func GetUserSignUpList(condition string, pars []interface{}) (items []*UserSignUpLossResp, err error) {
  921. o := orm.NewOrmUsingDB("hz_cygx")
  922. sql := `SELECT
  923. s.real_name,
  924. s.mobile
  925. FROM
  926. cygx_activity_signup_detail AS s
  927. INNER JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  928. INNER JOIN cygx_activity_type AS t ON t.activity_type_id = a.activity_type_id
  929. WHERE
  930. 1 = 1
  931. AND s.is_meeting = 1
  932. AND t.activity_type = 1 `
  933. if condition != `` {
  934. sql += condition
  935. }
  936. _, err = o.Raw(sql, pars).QueryRows(&items)
  937. return
  938. }
  939. type UserSignUpMeetLossListResp struct {
  940. Mobile string `description:"手机号"`
  941. RealName string `description:"姓名"`
  942. List []*AttendanceDetail `description:"预约客户"`
  943. }
  944. type ActivitySignupTempMsgReq struct {
  945. ActivityIds string `description:"活动id,用,隔开"`
  946. SendGroup string `description:"发送对象,1全部 2永续 3大套餐 4行业套餐 5其他行业正式 6试用 7已参与互动 用,隔开"`
  947. FirstText string `description:"首段提示文字"`
  948. ActivityName string `description:"活动名称"`
  949. Content string `description:"变更内容"`
  950. }
  951. type SendGroup struct {
  952. Id int
  953. Name string
  954. }
  955. type SendGroupStr struct {
  956. Id string
  957. Name string
  958. }
  959. type PermissionList struct {
  960. CompanyId int
  961. Permission string
  962. }
  963. // 获取正式权限
  964. func GetCompanyPermissionByUsersZhengShi(companyIds string) (items []*PermissionList, err error) {
  965. sql := ` SELECT a.company_id, b.remark AS permission
  966. FROM company_report_permission AS a
  967. INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
  968. INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id
  969. WHERE a.company_id IN (` + companyIds + `)
  970. AND c.is_suspend=0
  971. AND b.cygx_auth=1
  972. AND c.status IN('正式')
  973. AND a.status IN('正式') `
  974. o := orm.NewOrm()
  975. _, err = o.Raw(sql).QueryRows(&items)
  976. return
  977. }
  978. // 获取某一活动某个机构已经报名的数量
  979. func GetActivitySignupCompanyCount(activityId, companyId int) (count int, err error) {
  980. o := orm.NewOrmUsingDB("hz_cygx")
  981. sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_signup WHERE is_cancel=0 AND do_fail_type = 0 AND activity_id=? AND company_id=? `
  982. err = o.Raw(sqlCount, activityId, companyId).QueryRow(&count)
  983. return
  984. }
  985. func GetCompanyPermissionByUserTrip(companyId int) (permission string, err error) {
  986. o := orm.NewOrm()
  987. sql := ` SELECT
  988. GROUP_CONCAT( DISTINCT b.remark ORDER BY b.sort ASC SEPARATOR ',' ) AS permission
  989. FROM
  990. company_report_permission AS a
  991. INNER JOIN chart_permission AS b ON a.chart_permission_id = b.chart_permission_id
  992. INNER JOIN company_product AS c ON a.company_id = c.company_id
  993. AND a.product_id = c.product_id
  994. WHERE
  995. a.company_id = ?
  996. AND c.is_suspend = 0
  997. AND b.cygx_auth = 1
  998. AND a.is_upgrade = 1
  999. AND c.STATUS IN ( '正式' )
  1000. OR ( a.company_id = ? AND c.is_suspend = 0 AND b.cygx_auth = 1 AND c.STATUS IN ( '永续' ) )
  1001. OR ( a.company_id = ? AND c.is_suspend = 0 AND b.cygx_auth = 1 AND b.chart_permission_name = '策略' AND c.STATUS IN ( '正式' ) )`
  1002. err = o.Raw(sql, companyId, companyId, companyId).QueryRow(&permission)
  1003. return
  1004. }
  1005. // GetCygxCygxActivitySignupList 获取报名列表信息
  1006. func GetActivitySignupList(condition string, pars []interface{}) (items []*CygxActivitySignup, err error) {
  1007. o := orm.NewOrmUsingDB("hz_cygx")
  1008. sql := `SELECT
  1009. *
  1010. FROM
  1011. cygx_activity_signup AS v
  1012. WHERE
  1013. 1 = 1 ` + condition
  1014. _, err = o.Raw(sql, pars).QueryRows(&items)
  1015. return
  1016. }
  1017. // GetCygxCygxActivitySignupList 获取报名列表信息
  1018. func GetActivitySignupInnerActivityList(condition string, pars []interface{}) (items []*CygxActivitySignup, err error) {
  1019. o := orm.NewOrmUsingDB("hz_cygx")
  1020. sql := `SELECT
  1021. *
  1022. FROM
  1023. cygx_activity_signup AS v
  1024. INNER JOIN cygx_activity as a ON v.activity_id = a.activity_id
  1025. WHERE
  1026. 1 = 1 ` + condition
  1027. _, err = o.Raw(sql, pars).QueryRows(&items)
  1028. return
  1029. }