activity_signup.go 42 KB

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