activity_special_trip.go 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869
  1. package cygx
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/tealeg/xlsx"
  6. "hongze/hz_crm_api/controllers"
  7. "hongze/hz_crm_api/models"
  8. "hongze/hz_crm_api/models/cygx"
  9. "hongze/hz_crm_api/models/system"
  10. cygxService "hongze/hz_crm_api/services/cygx"
  11. "hongze/hz_crm_api/utils"
  12. "os"
  13. "path/filepath"
  14. "strconv"
  15. "strings"
  16. "time"
  17. )
  18. // 专项调研行程
  19. type ActivitySpecialTripCoAntroller struct {
  20. controllers.BaseAuthController
  21. }
  22. // @Title 新增报名
  23. // @Description 新增报名接口
  24. // @Param request body cygx.AddMeetingReminderReq true "type json string"
  25. // @Success 200 操作成功
  26. // @router /special/trip/addUser [post]
  27. func (this *ActivitySpecialTripCoAntroller) AddUser() {
  28. br := new(models.BaseResponse).Init()
  29. defer func() {
  30. this.Data["json"] = br
  31. this.ServeJSON()
  32. }()
  33. AdminUser := this.SysUser
  34. if AdminUser == nil {
  35. br.Msg = "请登录"
  36. br.ErrMsg = "请登录,SysUser Is Empty"
  37. return
  38. }
  39. var req cygx.AddMeetingReminderReq
  40. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  41. if err != nil {
  42. br.Msg = "参数解析异常!"
  43. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  44. return
  45. }
  46. var items []*cygx.CygxActivitySpecialTrip
  47. var itemsBill []*cygx.CygxActivitySpecialTripBill
  48. var itemsMeet []*cygx.CygxActivitySpecialMeetingDetail
  49. activityIds := req.ActivityIds
  50. uidList := req.List
  51. if activityIds == "" {
  52. br.Msg = "请选择活动"
  53. br.ErrMsg = "活动ID不能为空"
  54. return
  55. }
  56. activityIdList := strings.Split(activityIds, ",")
  57. var uids string
  58. for _, v := range uidList {
  59. uids += strconv.Itoa(v.UserId) + ","
  60. }
  61. uids = strings.TrimRight(uids, ",")
  62. for _, v := range uidList {
  63. uid := v.UserId
  64. wxUser, userErr := models.GetWxUserByUserId(uid)
  65. if userErr != nil {
  66. br.Msg = "编辑失败!查询用户信息失败"
  67. br.ErrMsg = "查询用户信息失败,Err:" + userErr.Error() + "用户UID:" + strconv.Itoa(uid) + "不存在"
  68. return
  69. }
  70. for _, vact := range activityIdList {
  71. activityId, _ := strconv.Atoi(vact)
  72. activityInfo, err := cygx.GetAddActivityInfoSpecialById(activityId)
  73. if err != nil {
  74. br.Msg = "活动不存在"
  75. br.ErrMsg = "活动ID错误,Err:activityId:" + strconv.Itoa(activityId)
  76. return
  77. }
  78. limitPeopleNum := activityInfo.LimitPeopleNum
  79. if limitPeopleNum > 0 {
  80. if AdminUser.RoleTypeCode != "admin" {
  81. havePower, err := cygxService.GetSpecialDetailUserPower(wxUser, activityInfo)
  82. if err != nil {
  83. br.Msg = "用户权限校验失败!"
  84. br.ErrMsg = "GetActivityDetailUserPower,Err:" + err.Error() + fmt.Sprint("UserId", wxUser.UserId, "ActivityId:", activityInfo.ActivityId)
  85. return
  86. }
  87. if !havePower {
  88. br.Msg = "当前活动对该客户不可见,无法报名"
  89. br.ErrMsg = "活动ID:" + strconv.Itoa(activityId) + "活动名称:" + activityInfo.ResearchTheme + "用户ID:" + strconv.Itoa(int(wxUser.UserId))
  90. return
  91. }
  92. }
  93. //获取这个活动已经报名的用户数量
  94. totalSignup, errSignup := cygx.GetActivitySpecialTripCountByActivityId(activityId)
  95. if errSignup != nil {
  96. br.Msg = "获取失败"
  97. br.ErrMsg = "获取失败,Err:" + errSignup.Error()
  98. return
  99. }
  100. //获取这个活动中输入的这些用户的报名数量
  101. totalThisUser, errThisUser := cygx.GetActivitySpecialTripCountByThisUser(activityId, uids)
  102. if errThisUser != nil {
  103. br.Msg = "获取失败"
  104. br.ErrMsg = "获取失败,Err:" + errThisUser.Error()
  105. return
  106. }
  107. //如果是限制人数的就做报名人数限制判断
  108. if limitPeopleNum < totalSignup+len(uidList)-totalThisUser {
  109. br.Msg = "新增失败,活动人数超限"
  110. br.ErrMsg = "当前活动报名人数已满,活动:" + activityInfo.ResearchTheme
  111. return
  112. }
  113. }
  114. total, errtotal := cygx.GetActivitySpecialTripCount(uid, activityId)
  115. if errtotal != nil {
  116. br.Msg = "获取失败"
  117. br.ErrMsg = "获取失败,Err:" + errtotal.Error()
  118. return
  119. }
  120. infoUser, err := cygx.GetUserAndCompanyNameList(uid)
  121. if err != nil {
  122. br.Msg = "获取失败"
  123. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  124. return
  125. }
  126. if total == 0 {
  127. //流水记录表
  128. itemBill := new(cygx.CygxActivitySpecialTripBill)
  129. itemBill.UserId = infoUser.UserId
  130. itemBill.ActivityId = activityInfo.ActivityId
  131. itemBill.CreateTime = time.Now()
  132. itemBill.Mobile = infoUser.Mobile
  133. itemBill.Email = infoUser.Email
  134. itemBill.CompanyId = infoUser.CompanyId
  135. itemBill.CompanyName = infoUser.CompanyName
  136. itemBill.RealName = infoUser.RealName
  137. itemBill.Source = 2
  138. itemBill.DoType = 1
  139. itemBill.BillDetailed = -1 // 流水减一
  140. itemBill.RegisterPlatform = 1
  141. itemBill.ChartPermissionId = activityInfo.ChartPermissionId
  142. itemBill.AdminId = AdminUser.AdminId
  143. userType, tripRemaining, mapChartName, err := cygxService.GetChartPermissionSpecialSurplusByCompany(infoUser.CompanyId)
  144. if err != nil {
  145. br.Msg = "获取专项调研剩余次数失败"
  146. br.ErrMsg = "获取专项调研剩余次数失败,err:" + err.Error()
  147. return
  148. }
  149. if userType == 2 {
  150. tripRemaining -= 1
  151. itemBill.Total = strconv.Itoa(tripRemaining) + "次"
  152. } else {
  153. for k, num := range mapChartName {
  154. if activityInfo.ChartPermissionName == k {
  155. num -= 1
  156. }
  157. itemBill.Total += k + strconv.Itoa(num) + "次+"
  158. }
  159. itemBill.Total = strings.TrimRight(itemBill.Total, "+")
  160. }
  161. item := new(cygx.CygxActivitySpecialTrip)
  162. item.UserId = infoUser.UserId
  163. item.RealName = infoUser.RealName
  164. item.SellerName = infoUser.SellerName
  165. item.ActivityId = activityId
  166. item.CreateTime = time.Now()
  167. item.Mobile = infoUser.Mobile
  168. item.Email = infoUser.Email
  169. item.Email = infoUser.Email
  170. item.CompanyId = infoUser.CompanyId
  171. item.CompanyName = infoUser.CompanyName
  172. item.AdminId = AdminUser.AdminId
  173. item.Source = 2
  174. //优先绑定用户修改过的外呼手机号
  175. if infoUser.OutboundMobile != "" {
  176. item.OutboundMobile = infoUser.OutboundMobile
  177. if infoUser.OutboundCountryCode == "" {
  178. item.CountryCode = "86"
  179. } else {
  180. item.CountryCode = infoUser.OutboundCountryCode
  181. }
  182. } else {
  183. item.OutboundMobile = infoUser.Mobile
  184. if infoUser.CountryCode == "" {
  185. item.CountryCode = "86"
  186. } else {
  187. item.CountryCode = infoUser.CountryCode
  188. }
  189. }
  190. items = append(items, item)
  191. itemsBill = append(itemsBill, itemBill)
  192. }
  193. var itemMeeting = new(cygx.CygxActivitySpecialMeetingDetail)
  194. itemMeeting.UserId = v.UserId
  195. itemMeeting.ActivityId = activityId
  196. itemMeeting.CreateTime = time.Now()
  197. itemMeeting.Mobile = infoUser.Mobile
  198. itemMeeting.Email = infoUser.Email
  199. itemMeeting.CompanyId = infoUser.CompanyId
  200. itemMeeting.CompanyName = infoUser.CompanyName
  201. itemMeeting.RealName = infoUser.RealName
  202. itemsMeet = append(itemsMeet, itemMeeting)
  203. }
  204. }
  205. err = cygx.AddCygxActivitySpecialTrip(items, itemsBill, itemsMeet)
  206. if err != nil {
  207. br.Msg = "操作失败"
  208. br.ErrMsg = "新增用户失败,Err:" + err.Error()
  209. return
  210. }
  211. br.Ret = 200
  212. br.Success = true
  213. br.Msg = "操作成功"
  214. br.IsAddLog = true
  215. }
  216. // @Title 报名列表
  217. // @Description 报名列表接口
  218. // @Param ActivityId query int true "活动ID"
  219. // @Param IsExport query bool false "是否导出excel,默认是false"
  220. // @Success 200 {object} cygx.GetAppointmentSpecialListRsep
  221. // @router /special/tripList [get]
  222. func (this *ActivitySpecialTripCoAntroller) TripList() {
  223. br := new(models.BaseResponse).Init()
  224. defer func() {
  225. this.Data["json"] = br
  226. this.ServeJSON()
  227. }()
  228. sysUser := this.SysUser
  229. if sysUser == nil {
  230. br.Msg = "请登录"
  231. br.ErrMsg = "请登录,SysUser Is Empty"
  232. return
  233. }
  234. isExport, _ := this.GetBool("IsExport", false)
  235. activityId, _ := this.GetInt("ActivityId")
  236. if activityId < 1 {
  237. br.Msg = "活动不存在"
  238. return
  239. }
  240. respList := new(cygx.GetAppointmentSpecialListRsep)
  241. activityInfo, _ := cygx.GetAddActivityInfoSpecialById(activityId)
  242. if activityInfo == nil {
  243. br.Msg = "活动不存在"
  244. br.ErrMsg = "活动ID错误,Err:activityId:" + strconv.Itoa(activityId)
  245. return
  246. }
  247. //超级管理员和权益管理员、权益研究员可以下载所有客户,销售组长能下载本组客户,销售只能下载本人名下客户
  248. resp := new(cygx.CanDownload)
  249. adminInfo, errAdmin := system.GetSysUserById(sysUser.AdminId)
  250. if errAdmin != nil {
  251. br.Msg = "获取失败"
  252. br.ErrMsg = "获取失败,Err:" + errAdmin.Error()
  253. return
  254. }
  255. if adminInfo.Role == "admin" || adminInfo.Role == "researcher" {
  256. resp.IsCanDownload = true
  257. }
  258. memberType := "Admin"
  259. sqlStr := ` AND s.is_cancel = 0`
  260. totalStr := sqlStr
  261. list, err := cygx.GetCygxActivitySpecialTripList(activityId, sqlStr)
  262. if err != nil {
  263. br.Msg = "获取失败"
  264. br.ErrMsg = "获取失败,Err:" + err.Error()
  265. return
  266. }
  267. //线上活动,销售查看自己客户,销售组长查看组员
  268. if resp.IsCanDownload == false && activityInfo.SpecialType == 1 {
  269. mapMobile, err := cygxService.GetAdminLookUserMobile(adminInfo)
  270. if err != nil {
  271. br.Msg = "获取失败"
  272. br.ErrMsg = "获取失败,销售对应权限,Err:" + err.Error()
  273. return
  274. }
  275. for _, v := range list {
  276. if _, ok := mapMobile[v.Mobile]; ok {
  277. respList.List = append(respList.List, v)
  278. }
  279. }
  280. if adminInfo.RoleTypeCode == "rai_group" {
  281. //组长查看本组所有组员
  282. memberType = "GroupLeader"
  283. } else {
  284. //组员查看自己
  285. memberType = "Sale"
  286. }
  287. } else {
  288. respList.List = list
  289. }
  290. if len(respList.List) == 0 {
  291. respList.List = make([]*cygx.CygxActivitySpecialTripResp, 0)
  292. }
  293. //导出excel
  294. if isExport {
  295. TripListExport(this, respList.List)
  296. return
  297. }
  298. total, errtotal := cygx.GetActivitySpecialTripTotal(activityId, totalStr)
  299. if errtotal != nil {
  300. br.Msg = "获取失败"
  301. br.ErrMsg = "客户总数获取失败,Err:" + errtotal.Error()
  302. return
  303. }
  304. myTotal := len(respList.List)
  305. respList.Source = 1
  306. respList.Total = total
  307. respList.MyTotal = myTotal
  308. respList.ActivityId = activityId
  309. respList.SpecialType = activityInfo.SpecialType
  310. if activityInfo.LimitPeopleNum > 0 {
  311. respList.IsLimitPeople = 1
  312. }
  313. respList.MemberType = memberType
  314. br.Ret = 200
  315. br.Success = true
  316. br.Msg = "获取成功"
  317. br.Data = respList
  318. }
  319. // TripListExport 下载报名信息
  320. func TripListExport(this *ActivitySpecialTripCoAntroller, listDate []*cygx.CygxActivitySpecialTripResp) {
  321. br := new(models.BaseResponse).Init()
  322. defer func() {
  323. this.Data["json"] = br
  324. this.ServeJSON()
  325. }()
  326. sysUser := this.SysUser
  327. if sysUser == nil {
  328. br.Msg = "请登录"
  329. br.ErrMsg = "请登录,SysUser Is Empty"
  330. return
  331. }
  332. activityId, _ := this.GetInt("ActivityId")
  333. activityInfo, _ := cygx.GetAddActivityInfoSpecialById(activityId)
  334. if activityInfo == nil {
  335. br.Msg = "活动不存在"
  336. br.ErrMsg = "活动ID错误,Err:activityId:" + strconv.Itoa(activityId)
  337. return
  338. }
  339. //超级管理员和权益管理员、权益研究员可以下载所有客户,销售组长能下载本组客户,销售只能下载本人名下客户
  340. resp := new(cygx.CanDownload)
  341. adminInfo, errAdmin := system.GetSysUserById(sysUser.AdminId)
  342. if errAdmin != nil {
  343. br.Msg = "获取失败"
  344. br.ErrMsg = "获取失败,Err:" + errAdmin.Error()
  345. return
  346. }
  347. if adminInfo.Role == "admin" || adminInfo.Role == "researcher" {
  348. resp.IsCanDownload = true
  349. }
  350. //创建excel
  351. dir, err := os.Executable()
  352. exPath := filepath.Dir(dir)
  353. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  354. xlsxFile := xlsx.NewFile()
  355. if err != nil {
  356. br.Msg = "生成文件失败"
  357. br.ErrMsg = "生成文件失败"
  358. return
  359. }
  360. style := xlsx.NewStyle()
  361. alignment := xlsx.Alignment{
  362. Horizontal: "center",
  363. Vertical: "center",
  364. WrapText: true,
  365. }
  366. style.Alignment = alignment
  367. style.ApplyAlignment = true
  368. sheetName := "报名名单"
  369. sheet, err := xlsxFile.AddSheet(sheetName)
  370. if err != nil {
  371. br.Msg = "新增Sheet失败"
  372. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  373. return
  374. }
  375. //标头
  376. if activityInfo.SpecialType == 1 || resp.IsCanDownload {
  377. rowTitle := sheet.AddRow()
  378. cellA := rowTitle.AddCell()
  379. cellA.Value = "姓名"
  380. cellB := rowTitle.AddCell()
  381. cellB.Value = "手机号"
  382. cellC := rowTitle.AddCell()
  383. cellC.Value = "公司名称"
  384. cellD := rowTitle.AddCell()
  385. cellD.Value = "所属销售"
  386. for _, item := range listDate {
  387. row := sheet.AddRow()
  388. cellA := row.AddCell()
  389. cellA.Value = item.RealName
  390. cellB := row.AddCell()
  391. cellB.Value = item.Mobile
  392. cellC := row.AddCell()
  393. cellC.Value = item.CompanyName
  394. cellD := row.AddCell()
  395. cellD.Value = item.SellerName
  396. }
  397. } else {
  398. rowTitle := sheet.AddRow()
  399. cellA := rowTitle.AddCell()
  400. cellA.Value = "姓名"
  401. cellB := rowTitle.AddCell()
  402. cellB.Value = "公司名称"
  403. cellC := rowTitle.AddCell()
  404. cellC.Value = "所属销售"
  405. for _, item := range listDate {
  406. row := sheet.AddRow()
  407. cellA := row.AddCell()
  408. cellA.Value = item.RealName
  409. cellB := row.AddCell()
  410. cellB.Value = item.CompanyName
  411. cellC := row.AddCell()
  412. cellC.Value = item.SellerName
  413. }
  414. }
  415. err = xlsxFile.Save(downLoadnFilePath)
  416. if err != nil {
  417. br.Msg = "保存文件失败"
  418. br.ErrMsg = "保存文件失败"
  419. return
  420. }
  421. downloadFileName := activityInfo.ResearchTheme + ".xlsx"
  422. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  423. defer func() {
  424. os.Remove(downLoadnFilePath)
  425. }()
  426. br.Success = true
  427. br.Ret = 200
  428. br.IsAddLog = true
  429. }
  430. // @Title 取消报名
  431. // @Description 取消报名接口
  432. // @Param request body cygx.ActivitySpecialTripCancelReq true "type json string"
  433. // @Success 200 操作成功
  434. // @router /special/trip/cancel [post]
  435. func (this *ActivitySpecialTripCoAntroller) TripCancel() {
  436. br := new(models.BaseResponse).Init()
  437. defer func() {
  438. this.Data["json"] = br
  439. this.ServeJSON()
  440. }()
  441. sysUser := this.SysUser
  442. if sysUser == nil {
  443. br.Msg = "请登录"
  444. br.ErrMsg = "请登录,SysUser Is Empty"
  445. return
  446. }
  447. var req cygx.ActivitySpecialTripCancelReq
  448. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  449. if err != nil {
  450. br.Msg = "参数解析异常!"
  451. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  452. return
  453. }
  454. userId := req.UserId
  455. activityId := req.ActivityId
  456. total, err := cygx.GetActivitySpecialTripCountByThisUser(activityId, strconv.Itoa(userId))
  457. if err != nil {
  458. br.Msg = "获取失败"
  459. br.ErrMsg = "获取失败,Err:" + err.Error()
  460. return
  461. }
  462. if total == 0 {
  463. br.Msg = "获取报名信息失败"
  464. br.ErrMsg = "获取失败,activityId:" + strconv.Itoa(activityId)
  465. return
  466. }
  467. activityInfo, errInfo := cygx.GetAddActivityInfoSpecialById(activityId)
  468. if activityInfo == nil {
  469. br.Msg = "操作失败"
  470. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  471. return
  472. }
  473. if errInfo != nil {
  474. br.Msg = "操作失败"
  475. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  476. return
  477. }
  478. infoUser, err := cygx.GetUserAndCompanyNameList(userId)
  479. if err != nil {
  480. br.Msg = "获取失败"
  481. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  482. return
  483. }
  484. //流水记录表
  485. itemBill := new(cygx.CygxActivitySpecialTripBill)
  486. itemBill.UserId = infoUser.UserId
  487. itemBill.ActivityId = activityInfo.ActivityId
  488. itemBill.CreateTime = time.Now()
  489. itemBill.Mobile = infoUser.Mobile
  490. itemBill.Email = infoUser.Email
  491. itemBill.CompanyId = infoUser.CompanyId
  492. itemBill.CompanyName = infoUser.CompanyName
  493. itemBill.RealName = infoUser.RealName
  494. itemBill.Source = 2
  495. itemBill.DoType = 2
  496. itemBill.BillDetailed = 1 // 流水加一
  497. itemBill.RegisterPlatform = 1
  498. itemBill.ChartPermissionId = activityInfo.ChartPermissionId
  499. itemBill.AdminId = sysUser.AdminId
  500. resultTime := utils.StrTimeToTime(activityInfo.ActivityTime)
  501. //48小时之内的取消也扣除一次参会记录
  502. var isValid int
  503. if time.Now().Add(+time.Hour * 48).After(resultTime) {
  504. isValid = 1
  505. itemBill.BillDetailed = 0 // 48小时之内取消的,照样扣点,流水不进行加一
  506. }
  507. err = cygx.ActivitySpecialTripCancel(isValid, activityId, userId)
  508. if err != nil {
  509. br.Msg = "修改失败"
  510. br.ErrMsg = "修改失败 Err:" + err.Error()
  511. return
  512. }
  513. userType, tripRemaining, mapChartName, err := cygxService.GetChartPermissionSpecialSurplusByCompany(infoUser.CompanyId)
  514. if err != nil {
  515. br.Msg = "获取专项调研剩余次数失败"
  516. br.ErrMsg = "获取专项调研剩余次数失败,err:" + err.Error()
  517. return
  518. }
  519. if userType == 2 {
  520. tripRemaining += itemBill.BillDetailed
  521. itemBill.Total = strconv.Itoa(tripRemaining) + "次"
  522. } else {
  523. for k, num := range mapChartName {
  524. if activityInfo.ChartPermissionName == k {
  525. num += itemBill.BillDetailed
  526. }
  527. itemBill.Total += k + strconv.Itoa(num) + "次+"
  528. }
  529. itemBill.Total = strings.TrimRight(itemBill.Total, "+")
  530. }
  531. err = cygx.AddCygxActivitySpecialTripBill(itemBill)
  532. if err != nil {
  533. br.Msg = "修改失败"
  534. br.ErrMsg = "修改失败流水记录添加失败 Err:" + err.Error()
  535. return
  536. }
  537. br.Ret = 200
  538. br.Success = true
  539. br.Msg = "操作成功"
  540. br.IsAddLog = true
  541. }
  542. // @Title 到会详情/提交到会详情
  543. // @Description 报名详情列表接口
  544. // @Param ActivityId query int true "活动ID"
  545. // @Success 200 {object} cygx.GetAppointmentSpecialListRsep
  546. // @router /special/trip/meetDetial [get]
  547. func (this *ActivitySpecialTripCoAntroller) MeetDetial() {
  548. br := new(models.BaseResponse).Init()
  549. defer func() {
  550. this.Data["json"] = br
  551. this.ServeJSON()
  552. }()
  553. AdminUser := this.SysUser
  554. if AdminUser == nil {
  555. br.Msg = "请登录"
  556. br.ErrMsg = "请登录,SysUser Is Empty"
  557. return
  558. }
  559. activityId, _ := this.GetInt("ActivityId")
  560. if activityId < 1 {
  561. br.Msg = "活动不存在"
  562. return
  563. }
  564. activityInfo, err := cygx.GetAddActivityInfoSpecialById(activityId)
  565. if err != nil {
  566. br.Msg = "活动不存在"
  567. br.ErrMsg = "活动ID错误,Err:activityId:" + strconv.Itoa(activityId)
  568. return
  569. }
  570. respList := new(cygx.SpecialMeetingDetailRespList)
  571. if activityInfo.IsSubmitMeeting == 0 {
  572. sqlStr := ` AND s.is_cancel = 0`
  573. list, err := cygx.GetCygxActivitySpecialTripList(activityId, sqlStr)
  574. if err != nil {
  575. br.Msg = "获取失败"
  576. br.ErrMsg = "获取失败,Err:" + err.Error()
  577. return
  578. }
  579. for _, v := range list {
  580. item := new(cygx.CygxActivitySpecialMeetingDetailResp)
  581. item.UserId = v.UserId
  582. item.RealName = v.RealName
  583. item.CompanyName = v.CompanyName
  584. respList.List = append(respList.List, item)
  585. }
  586. } else {
  587. respList.List, err = cygx.GetCygxActivitySpecialMeetingDetailListByActivity(activityId)
  588. if err != nil {
  589. br.Msg = "获取失败"
  590. br.ErrMsg = "获取失败,Err:" + err.Error()
  591. return
  592. }
  593. UserMap, err := cygxService.GetSpecialTripUserMap(activityId)
  594. if err != nil {
  595. br.Msg = "获取失败"
  596. br.ErrMsg = "获取失败,Err:" + err.Error()
  597. return
  598. }
  599. for k, v := range respList.List {
  600. if v.IsMeeting == 1 {
  601. if _, ok := UserMap[v.UserId]; !ok {
  602. respList.List[k].IsMeeting = 2
  603. }
  604. respList.List[k].Operation = true
  605. }
  606. }
  607. }
  608. br.Ret = 200
  609. br.Success = true
  610. br.Msg = "获取成功"
  611. br.Data = respList
  612. }
  613. // @Title 提交线下到会情况
  614. // @Description 提交线下到会情况接口
  615. // @Param request body cygx.MeetingDoRep true "type json string"
  616. // @Success 200 操作成功
  617. // @router /special/trip/meetingDo [post]
  618. func (this *ActivitySpecialTripCoAntroller) MeetingDo() {
  619. br := new(models.BaseResponse).Init()
  620. defer func() {
  621. this.Data["json"] = br
  622. this.ServeJSON()
  623. }()
  624. AdminUser := this.SysUser
  625. if AdminUser == nil {
  626. br.Msg = "请登录"
  627. br.ErrMsg = "请登录,用户信息为空"
  628. br.Ret = 408
  629. return
  630. }
  631. var req cygx.MeetingSpeciaDoRep
  632. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  633. if err != nil {
  634. br.Msg = "参数解析异常!"
  635. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  636. return
  637. }
  638. var userIdArr []int
  639. var newMeetingUserid = make(map[int]bool) //新提交的到会的额用户ID
  640. meetingUids := req.UserIds
  641. if len(meetingUids) == 0 {
  642. meetingUids = "0"
  643. } else {
  644. //过滤字段
  645. slice := strings.Split(meetingUids, ",")
  646. meetingUids = ""
  647. for _, v := range slice {
  648. if v != "" {
  649. meetingUids += v + ","
  650. userId, _ := strconv.Atoi(v)
  651. if userId > 0 {
  652. userIdArr = append(userIdArr, userId)
  653. newMeetingUserid[userId] = true
  654. }
  655. }
  656. }
  657. meetingUids = strings.TrimRight(meetingUids, ",")
  658. }
  659. activityId := req.ActivityId
  660. activityInfo, err := cygx.GetAddActivityInfoSpecialById(activityId)
  661. if err != nil {
  662. br.Msg = "活动不存在"
  663. br.ErrMsg = "活动ID错误,Err:activityId:" + strconv.Itoa(activityId)
  664. return
  665. }
  666. //校验活动后台管理员、销售是否有修改权限
  667. havePower, popupMsg, err := cygxService.CheckActivitySpecialUpdatePower(AdminUser.AdminId, activityInfo)
  668. if err != nil {
  669. br.Msg = "获取管理员身份信息失败"
  670. br.ErrMsg = "获取管理员身份信息失败,Err:" + err.Error()
  671. return
  672. }
  673. if !havePower {
  674. br.Msg = popupMsg
  675. return
  676. }
  677. noMeetingUids, err := cygx.GetSpecialTripUserIds(activityId, meetingUids) //未到会的用户ID
  678. if err != nil {
  679. br.Msg = "获取信息失败"
  680. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  681. return
  682. }
  683. var allUids string
  684. if len(noMeetingUids) > 0 {
  685. allUids = noMeetingUids + "," + meetingUids
  686. } else {
  687. allUids = meetingUids
  688. }
  689. listUser, err := cygx.GetUserAndCompanyNameListByUids(allUids)
  690. if err != nil {
  691. br.Msg = "获取失败"
  692. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  693. return
  694. }
  695. UserMap, err := cygxService.GetSpecialTripUserMap(activityId)
  696. if err != nil {
  697. br.Msg = "获取失败"
  698. br.ErrMsg = "获取失败,Err:" + err.Error()
  699. return
  700. }
  701. var condition string
  702. var pars []interface{}
  703. condition += " AND is_meeting = 1 AND activity_id = ? "
  704. pars = append(pars, activityId)
  705. listOldMeetingDetail, err := cygx.GetCygxActivitySpecialMeetingDetailList(condition, pars)
  706. if err != nil && err.Error() != utils.ErrNoRow() {
  707. br.Msg = "获取失败"
  708. br.ErrMsg = "GetCygxActivitySpecialMeetingDetailList,Err:" + err.Error()
  709. return
  710. }
  711. //获取之前已经到会的人
  712. //var oldMeetingUserid = make(map[int]bool)
  713. pars = make([]interface{}, 0)
  714. condition = " AND activity_id = ? "
  715. pars = append(pars, activityId)
  716. listTripBill, err := cygx.GetCygxActivitySpecialTripBill(condition, pars)
  717. if err != nil && err.Error() != utils.ErrNoRow() {
  718. br.Msg = "获取失败"
  719. br.ErrMsg = "GetCygxActivitySpecialTripBill,Err:" + err.Error()
  720. return
  721. }
  722. //获取用户最后一次的扣点状态
  723. mapUserLastTripBill := make(map[int]*cygx.CygxActivitySpecialTripBill)
  724. for _, v := range listTripBill {
  725. mapUserLastTripBill[v.UserId] = v
  726. }
  727. var items []*cygx.CygxActivitySpecialMeetingDetail
  728. var itemsBill []*cygx.CygxActivitySpecialTripBill
  729. if len(listOldMeetingDetail) > 0 {
  730. for _, v := range listOldMeetingDetail {
  731. if mapUserLastTripBill[v.UserId] == nil {
  732. continue
  733. }
  734. //如果上一次空降的用户,这一次提交的时候没有带入,而且还被扣点了,那么就进行返点处理
  735. if !newMeetingUserid[v.UserId] && v.IsAirborne == 1 && mapUserLastTripBill[v.UserId].BillDetailed < 0 {
  736. var itemBill = new(cygx.CygxActivitySpecialTripBill)
  737. //流水记录表
  738. itemBill.UserId = v.UserId
  739. itemBill.ActivityId = activityInfo.ActivityId
  740. itemBill.CreateTime = time.Now()
  741. itemBill.Mobile = v.Mobile
  742. itemBill.Email = v.Email
  743. itemBill.CompanyId = v.CompanyId
  744. itemBill.CompanyName = v.CompanyName
  745. itemBill.RealName = v.RealName
  746. itemBill.Source = 2
  747. itemBill.DoType = 2
  748. itemBill.BillDetailed = 1 // 流水加一
  749. itemBill.RegisterPlatform = 1
  750. itemBill.ChartPermissionId = activityInfo.ChartPermissionId
  751. itemBill.AdminId = AdminUser.AdminId
  752. itemBill.Way = 2
  753. itemsBill = append(itemsBill, itemBill)
  754. }
  755. }
  756. }
  757. for _, v := range listUser {
  758. var item = new(cygx.CygxActivitySpecialMeetingDetail)
  759. item.UserId = v.UserId
  760. item.ActivityId = activityId
  761. item.CreateTime = time.Now()
  762. item.Mobile = v.Mobile
  763. item.Email = v.Email
  764. item.CompanyId = v.CompanyId
  765. item.CompanyName = v.CompanyName
  766. item.IsMeeting = 1
  767. item.RealName = v.RealName
  768. //添加空降人员字段
  769. if _, ok := UserMap[v.UserId]; !ok {
  770. item.IsAirborne = 1
  771. }
  772. var itemBill = new(cygx.CygxActivitySpecialTripBill)
  773. //如果是空降客户,(没有扣点记录,或者上一次的流水不为负) 就进行扣点处理
  774. if item.IsAirborne == 1 && (mapUserLastTripBill[v.UserId] == nil || mapUserLastTripBill[v.UserId].BillDetailed >= 0) {
  775. //流水记录表
  776. itemBill.UserId = v.UserId
  777. itemBill.ActivityId = activityInfo.ActivityId
  778. itemBill.CreateTime = time.Now()
  779. itemBill.Mobile = v.Mobile
  780. itemBill.Email = v.Email
  781. itemBill.CompanyId = v.CompanyId
  782. itemBill.CompanyName = v.CompanyName
  783. itemBill.RealName = v.RealName
  784. itemBill.Source = 2
  785. itemBill.DoType = 1
  786. itemBill.BillDetailed = -1 // 流水减一
  787. itemBill.RegisterPlatform = 1
  788. itemBill.ChartPermissionId = activityInfo.ChartPermissionId
  789. itemBill.AdminId = AdminUser.AdminId
  790. itemBill.Way = 2
  791. itemsBill = append(itemsBill, itemBill)
  792. }
  793. items = append(items, item)
  794. }
  795. err = cygx.MeetingDopecialMeet(meetingUids, noMeetingUids, activityId, items, itemsBill)
  796. if err != nil {
  797. br.Msg = "操作失败"
  798. br.ErrMsg = "操作失败,Err:" + err.Error()
  799. return
  800. }
  801. go cygxService.ActivitySpecialUserLabelLogAdd(activityId, userIdArr)
  802. //添加操作日志记录
  803. br.Ret = 200
  804. br.Success = true
  805. br.Msg = "操作成功"
  806. br.IsAddLog = true
  807. }
  808. // @Title 修改外呼号码
  809. // @Description 修改外呼号码接口
  810. // @Param request body cygx.OutboundMobileEditResp true "type json string"
  811. // @Success 200 操作成功
  812. // @router /special/trip/outboundMobileEdit [post]
  813. func (this *ActivitySpecialTripCoAntroller) OutboundMobileEdit() {
  814. br := new(models.BaseResponse).Init()
  815. defer func() {
  816. this.Data["json"] = br
  817. this.ServeJSON()
  818. }()
  819. sysUser := this.SysUser
  820. if sysUser == nil {
  821. br.Msg = "请登录"
  822. br.ErrMsg = "请登录,SysUser Is Empty"
  823. return
  824. }
  825. var req cygx.OutboundMobileEditResp
  826. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  827. if err != nil {
  828. br.Msg = "参数解析异常!"
  829. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  830. return
  831. }
  832. id := req.Id
  833. outboundMobile := req.OutboundMobile
  834. countryCode := req.CountryCode
  835. err = cygx.SpecialTripOutboundMobileEdit(id, outboundMobile, countryCode)
  836. if err != nil {
  837. br.Msg = "修改失败"
  838. br.ErrMsg = "修改失败 Err:" + err.Error()
  839. return
  840. }
  841. br.Ret = 200
  842. br.Success = true
  843. br.Msg = "操作成功"
  844. br.IsAddLog = true
  845. }