activity_signup.go 41 KB

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