activity_special_trip.go 25 KB

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