activity_signup.go 42 KB

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