activity_special_trip.go 28 KB

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