activity_special_trip.go 30 KB

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