eta_trial.go 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta/eta_forum_admin/models"
  5. "eta/eta_forum_admin/models/company"
  6. "eta/eta_forum_admin/models/eta_trial"
  7. "eta/eta_forum_admin/models/system"
  8. "eta/eta_forum_admin/services"
  9. "eta/eta_forum_admin/services/eta_forum_hub"
  10. "eta/eta_forum_admin/utils"
  11. "fmt"
  12. "github.com/mozillazg/go-pinyin"
  13. "github.com/rdlucklib/rdluck_tools/paging"
  14. "sort"
  15. "strconv"
  16. "strings"
  17. "time"
  18. )
  19. type ETATrialController struct {
  20. BaseAuthController
  21. }
  22. // @Title 获取所有ETA试用客户列表
  23. // @Description 获取所有ETA试用客户列表 接口
  24. // @Param PageSize query int true "每页数据条数"
  25. // @Param CurrentIndex query int true "当前页页码,从1开始"
  26. // @Param KeyWord query string true "搜索关键词"
  27. // @Param IsOnlyMe query bool false "是否只看我的"
  28. // @Param SortParam query string false "排序字段参数,用来排序的字段, 枚举值:'Expiration':账号到期时长 、 'ModifyTime':账号更新时间 、 'LastLoginTime':最近一次登陆时间 、`ActiveTime:累计活跃时长` 、`IndexNum:累计添加指标` 、`ChartNum:累计添加图表`、`LoginNum:累计登录次数`"
  29. // @Param SortType query string true "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒叙`"
  30. // @Success 200 {object} models.ETATrialListRespList
  31. // @router /list [get]
  32. func (this *ETATrialController) List() {
  33. br := new(models.BaseResponse).Init()
  34. defer func() {
  35. this.Data["json"] = br
  36. this.ServeJSON()
  37. }()
  38. sysUser := this.SysUser
  39. if sysUser == nil {
  40. br.Msg = "请登录"
  41. br.ErrMsg = "请登录,SysUser Is Empty"
  42. br.Ret = 408
  43. return
  44. }
  45. isOnlyMe, _ := this.GetBool("IsOnlyMe")
  46. pageSize, _ := this.GetInt("PageSize")
  47. currentIndex, _ := this.GetInt("CurrentIndex")
  48. keyWord := this.GetString("KeyWord")
  49. keyWord = strings.Trim(keyWord, " ")
  50. keyWord = strings.Replace(keyWord, "'", "", -1)
  51. //排序参数
  52. sortParam := this.GetString("SortParam")
  53. sortType := this.GetString("SortType")
  54. var total int
  55. page := paging.GetPaging(currentIndex, pageSize, total)
  56. var startSize int
  57. if pageSize <= 0 {
  58. pageSize = utils.PageSize20
  59. }
  60. if currentIndex <= 0 {
  61. currentIndex = 1
  62. }
  63. startSize = paging.StartIndex(currentIndex, pageSize)
  64. var condition string
  65. var pars []interface{}
  66. if sysUser.RoleTypeCode != "admin" && sysUser.RoleTypeCode != "ficc_admin" {
  67. condition += ` AND seller_id = ? `
  68. pars = append(pars, sysUser.AdminId)
  69. } else if isOnlyMe {
  70. condition += ` AND seller_id = ? `
  71. pars = append(pars, sysUser.AdminId)
  72. }
  73. if keyWord != "" {
  74. condition += ` AND (user_name LIKE '%` + keyWord + `%' OR company_name LIKE '%` + keyWord + `%' ) `
  75. }
  76. total, err := eta_trial.GetETATrialListCount(condition, pars)
  77. if err != nil {
  78. br.Msg = "获取失败"
  79. br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  80. return
  81. }
  82. sortStr := ``
  83. if sortParam != "" && sortType != "" {
  84. if sortParam == "Expiration" {
  85. if sortType == "asc" {
  86. sortStr = "ORDER BY modify_time ASC "
  87. } else {
  88. sortStr = "ORDER BY modify_time DESC "
  89. }
  90. } else if sortParam == "ModifyTime" {
  91. if sortType == "asc" {
  92. sortStr = "ORDER BY modify_time ASC "
  93. } else {
  94. sortStr = "ORDER BY modify_time DESC "
  95. }
  96. } else if sortParam == "LastLoginTime" {
  97. if sortType == "asc" {
  98. sortStr = "ORDER BY last_login_time ASC "
  99. } else {
  100. sortStr = "ORDER BY last_login_time DESC "
  101. }
  102. } else if sortParam == "ActiveTime" {
  103. if sortType == "asc" {
  104. sortStr = "ORDER BY active_time ASC"
  105. } else {
  106. sortStr = "ORDER BY active_time DESC"
  107. }
  108. } else if sortParam == "IndexNum" {
  109. if sortType == "asc" {
  110. sortStr = "ORDER BY index_num ASC"
  111. } else {
  112. sortStr = "ORDER BY index_num DESC"
  113. }
  114. } else if sortParam == "ChartNum" {
  115. if sortType == "asc" {
  116. sortStr = "ORDER BY chart_num ASC"
  117. } else {
  118. sortStr = "ORDER BY chart_num DESC"
  119. }
  120. } else if sortParam == "LoginNum" {
  121. if sortType == "asc" {
  122. sortStr = "ORDER BY login_num ASC"
  123. } else {
  124. sortStr = "ORDER BY login_num DESC"
  125. }
  126. } else if sortParam == "LastLoginDuration" {
  127. if sortType == "asc" {
  128. sortStr = "ORDER BY last_login_duration ASC"
  129. } else {
  130. sortStr = "ORDER BY last_login_duration DESC"
  131. }
  132. }
  133. } else {
  134. sortStr = "ORDER BY create_time DESC "
  135. }
  136. list, err := eta_trial.GetETATrialList(condition, sortStr, pars, startSize, pageSize)
  137. if err != nil {
  138. br.Msg = "获取权限列表失败"
  139. br.ErrMsg = "获取权限列表失败,Err:" + err.Error()
  140. return
  141. }
  142. mobileSlice := make([]string, 0)
  143. for _, item := range list {
  144. activeTime, _ := strconv.Atoi(item.ActiveTime)
  145. item.ActiveTime = utils.GetDurationFormatBySecond(activeTime)
  146. // 最近一次登录时长
  147. loginDuration, _ := strconv.Atoi(item.LastLoginDuration)
  148. item.LastLoginDuration = utils.GetDurationFormatBySecond(loginDuration)
  149. //到期时间
  150. modifyTime, err := time.Parse(utils.FormatDateTime, item.ModifyTime)
  151. if err != nil {
  152. br.Msg = "时间转化失败"
  153. br.ErrMsg = "时间转化失败,Err:" + err.Error()
  154. return
  155. }
  156. var expired int
  157. expiredTime := modifyTime.AddDate(0, 0, 14).Format(utils.FormatDate)
  158. expired, err = utils.GetDaysBetween2Date(utils.FormatDate, expiredTime, time.Now().Format(utils.FormatDate))
  159. if err != nil {
  160. br.Msg = "时间计算失败"
  161. br.ErrMsg = "时间计算失败,CalculationDate Err:" + err.Error()
  162. return
  163. }
  164. item.Expiration = expired
  165. mobileSlice = append(mobileSlice, "'"+item.Mobile+"'")
  166. }
  167. if len(mobileSlice) > 0 {
  168. mobiles := strings.Join(mobileSlice, ",")
  169. recordList, err := eta_trial.GetEtaTrialRecordParts(mobiles)
  170. if err != nil {
  171. br.Msg = "获取记录失败"
  172. br.ErrMsg = "获取记录失败,GetEtaTrialRecordParts Err:" + err.Error()
  173. return
  174. }
  175. recordMap := make(map[string]string)
  176. for _, v := range recordList {
  177. if _, ok := recordMap[v.Mobile]; !ok {
  178. recordMap[v.Mobile] = v.Part
  179. }
  180. }
  181. for _, item := range list {
  182. item.InterestModule = recordMap[item.Mobile]
  183. }
  184. }
  185. //待审批数量
  186. condition = ` AND approval_status = '待审批' `
  187. pars = []interface{}{}
  188. totalApproval, err := eta_trial.GetETATrialApprovalListCount(condition, pars)
  189. if err != nil {
  190. br.Msg = "获取失败"
  191. br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  192. return
  193. }
  194. page = paging.GetPaging(currentIndex, pageSize, total)
  195. resp := new(eta_trial.ETATrialListRespList)
  196. resp.List = list
  197. resp.Paging = page
  198. resp.ApprovalNum = totalApproval
  199. br.Ret = 200
  200. br.Success = true
  201. br.Msg = "获取成功"
  202. br.Data = resp
  203. return
  204. }
  205. // @Title 新增用户
  206. // @Description 新增用户 接口
  207. // @Success 200 {object} models.ETATrialAddReq
  208. // @router /add [post]
  209. func (this *ETATrialController) Add() {
  210. br := new(models.BaseResponse).Init()
  211. defer func() {
  212. this.Data["json"] = br
  213. this.ServeJSON()
  214. }()
  215. sysUser := this.SysUser
  216. if sysUser == nil {
  217. br.Msg = "请登录"
  218. br.ErrMsg = "请登录,SysUser Is Empty"
  219. br.Ret = 408
  220. return
  221. }
  222. var req eta_trial.ETATrialAddReq
  223. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  224. if err != nil {
  225. br.Msg = "参数解析异常!"
  226. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  227. return
  228. }
  229. resp := new(eta_trial.ETATrialListResp)
  230. //提交审批
  231. approvalIds := make([]int, 0)
  232. for _, v := range req.List {
  233. if v.CompanyName == "" {
  234. br.Msg = "请填写公司名称"
  235. return
  236. }
  237. if v.UserName == "" {
  238. br.Msg = "请填写客户名称"
  239. return
  240. }
  241. if v.Position == "" {
  242. br.Msg = "职务不可为空"
  243. return
  244. }
  245. if v.Mobile == "" {
  246. br.Msg = "手机号不可为空"
  247. return
  248. }
  249. //检查是否为禁用客户
  250. item, e := eta_trial.GetETATrialByMobile(v.Mobile)
  251. if e != nil && e.Error() != utils.ErrNoRow() {
  252. err = e
  253. }
  254. if item != nil {
  255. if item.Enabled == 0 {
  256. //放入被禁用客户列表中
  257. respItem := eta_trial.ETATrialAddRespItem{
  258. UserName: v.UserName,
  259. CompanyName: v.CompanyName,
  260. Position: v.Position,
  261. Mobile: v.Mobile,
  262. Seller: item.Seller,
  263. }
  264. resp.BannedList = append(resp.BannedList, &respItem)
  265. continue
  266. } else {
  267. //客户已在正常使用中
  268. //放入已提交申请列表中
  269. respItem := eta_trial.ETATrialAddRespItem{
  270. UserName: v.UserName,
  271. CompanyName: v.CompanyName,
  272. Position: v.Position,
  273. Mobile: v.Mobile,
  274. Seller: item.Seller,
  275. }
  276. resp.RepeatList = append(resp.RepeatList, &respItem)
  277. continue
  278. }
  279. }
  280. seller, e := system.GetSysAdminById(sysUser.AdminId)
  281. if e != nil {
  282. err = e
  283. return
  284. }
  285. //检查是否历史已提交
  286. approval, e := eta_trial.GetETATrialApprovalByMobile(v.Mobile)
  287. if e != nil && e.Error() != utils.ErrNoRow() {
  288. err = e
  289. }
  290. if approval != nil && approval.ApprovalStatus == "待审批" {
  291. //处于待审批状态
  292. //放入已提交申请列表中
  293. respItem := eta_trial.ETATrialAddRespItem{
  294. UserName: v.UserName,
  295. CompanyName: v.CompanyName,
  296. Position: v.Position,
  297. Mobile: v.Mobile,
  298. Seller: approval.Seller,
  299. }
  300. resp.RepeatList = append(resp.RepeatList, &respItem)
  301. continue
  302. }
  303. //检查是否公司内部人员
  304. mobileCount, e := eta_forum_hub.GetEtaTrialMobileCount(v.Mobile)
  305. if e != nil {
  306. br.Msg = "判断手机号是否存在失败"
  307. br.ErrMsg = "判断手机号是否存在失败,Err:" + e.Error()
  308. return
  309. }
  310. if mobileCount > 0 {
  311. //放入内部人员列表中
  312. respItem := eta_trial.ETATrialAddRespItem{
  313. UserName: v.UserName,
  314. CompanyName: v.CompanyName,
  315. Position: v.Position,
  316. Mobile: v.Mobile,
  317. Seller: "",
  318. }
  319. resp.InternalList = append(resp.InternalList, &respItem)
  320. continue
  321. }
  322. var approvalId int64
  323. if approval != nil && (approval.ApprovalStatus == "驳回" || approval.ApprovalStatus == "已撤回") && v.Mobile == approval.Mobile {
  324. //若是被驳回后重新申请且手机号相同的,更新审批记录
  325. e = eta_trial.ResubmitTrialNoReasons(v.UserName, v.CompanyName, v.Position, approval.ApprovalId)
  326. if e != nil {
  327. err = e
  328. return
  329. }
  330. approvalId = int64(approval.ApprovalId)
  331. } else {
  332. //加入审批列表
  333. approvalItem := eta_trial.EtaTrialApproval{
  334. UserName: v.UserName,
  335. CompanyName: v.CompanyName,
  336. Position: v.Position,
  337. Mobile: v.Mobile,
  338. SellerId: seller.AdminId,
  339. Seller: seller.RealName,
  340. CreateTime: time.Now(),
  341. ModifyTime: time.Now(),
  342. ApprovalContent: "申请账号",
  343. ApplyMethod: 1,
  344. ApprovalStatus: "待审批",
  345. }
  346. approvalId, e = eta_trial.AddETATrialApproval(&approvalItem)
  347. if e != nil {
  348. err = e
  349. return
  350. }
  351. }
  352. //放入成功列表中
  353. respItem := eta_trial.ETATrialAddRespItem{
  354. UserName: v.UserName,
  355. CompanyName: v.CompanyName,
  356. Position: v.Position,
  357. Mobile: v.Mobile,
  358. Seller: seller.RealName,
  359. }
  360. resp.SuccessList = append(resp.SuccessList, &respItem)
  361. //新增待办消息
  362. msgItem := new(company.CompanyApprovalMessage)
  363. msgItem.CreateUserId = sysUser.AdminId
  364. msgItem.ReceiveUserId = -1
  365. msgItem.MessageStatus = 1 // 已读, 不再亮红点, 但是消息要有
  366. msgItem.Remark = seller.RealName + "申请试用账号"
  367. msgItem.Content = seller.RealName + "申请试用账号"
  368. msgItem.CompanyName = v.CompanyName
  369. msgItem.CreateTime = time.Now()
  370. msgItem.ModifyTime = time.Now()
  371. msgItem.CompanyApprovalId = int(approvalId)
  372. msgItem.OperationStatus = 1
  373. msgItem.MessageType = 1 //1:申请消息,2:审批结果,3:文字消息
  374. msgItem.SourceType = 9 //消息来源
  375. msgItem.ApprovalStatus = 1 //审批状态,1:待审批,2:已审批,3:已驳回
  376. err = company.AddCompanyApprovalMessage(msgItem)
  377. approvalIds = append(approvalIds, int(approvalId))
  378. }
  379. // 2023-08-01默认审批通过, 不再进行人工审批, 也不发送待办消息
  380. if len(approvalIds) > 0 {
  381. go func() {
  382. for _, v := range approvalIds {
  383. _ = services.ApprovalApply(v)
  384. }
  385. }()
  386. }
  387. br.Ret = 200
  388. br.Success = true
  389. br.Msg = "提交成功"
  390. br.Data = resp
  391. return
  392. }
  393. // @Title 申请启用
  394. // @Description 申请启用 接口
  395. // @Success 200 {object} models.ETATrialAddReq
  396. // @router /apply/enable [post]
  397. func (this *ETATrialController) ApplyEnable() {
  398. br := new(models.BaseResponse).Init()
  399. defer func() {
  400. this.Data["json"] = br
  401. this.ServeJSON()
  402. }()
  403. sysUser := this.SysUser
  404. if sysUser == nil {
  405. br.Msg = "请登录"
  406. br.ErrMsg = "请登录,SysUser Is Empty"
  407. br.Ret = 408
  408. return
  409. }
  410. var req eta_trial.ETAAddApplyReq
  411. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  412. if err != nil {
  413. br.Msg = "参数解析异常!"
  414. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  415. return
  416. }
  417. seller, e := system.GetSysAdminById(sysUser.AdminId)
  418. if e != nil {
  419. err = e
  420. return
  421. }
  422. var condition string
  423. var pars []interface{}
  424. if req.IsCheckAll {
  425. if len(req.MobileList) > 0 {
  426. condition += " and mobile not in (" + utils.GetOrmInReplace(len(req.MobileList)) + ")"
  427. for _, mobile := range req.MobileList {
  428. pars = append(pars, mobile)
  429. }
  430. }
  431. } else {
  432. if len(req.MobileList) > 0 {
  433. condition += " and mobile in (" + utils.GetOrmInReplace(len(req.MobileList)) + ")"
  434. for _, mobile := range req.MobileList {
  435. pars = append(pars, mobile)
  436. }
  437. }
  438. }
  439. trialApprovalList, err := eta_trial.GetETATrialByCondition(condition, pars)
  440. if err != nil {
  441. return
  442. }
  443. for _, trialApproval := range trialApprovalList {
  444. approval, err := eta_trial.GetETATrialApprovalByMobile(trialApproval.Mobile)
  445. if err != nil && err.Error() != utils.ErrNoRow() {
  446. br.Msg = "获取失败!"
  447. br.ErrMsg = "获取失败,Err:" + err.Error()
  448. return
  449. }
  450. var approvalId int64
  451. if approval != nil && (approval.ApprovalStatus == "驳回" || approval.ApprovalStatus == "已撤回") && trialApproval.Mobile == approval.Mobile {
  452. //若是被驳回或撤回后申请且手机号相同的,更新审批记录
  453. err = eta_trial.ResubmitTrial(approval.ApprovalId, req.ApplyReasons)
  454. if err != nil {
  455. br.Msg = "更新失败!"
  456. br.ErrMsg = "更新失败,Err:" + err.Error()
  457. return
  458. }
  459. approvalId = int64(approval.ApprovalId)
  460. } else if approval != nil && approval.ApprovalStatus == "待审批" && approval.ApprovalContent == "申请启用" {
  461. br.Msg = "该客户已在审批中!"
  462. br.ErrMsg = "该客户已在审批中!"
  463. return
  464. } else {
  465. //加入审批列表
  466. approvalItem := eta_trial.EtaTrialApproval{
  467. UserName: trialApproval.UserName,
  468. CompanyName: trialApproval.CompanyName,
  469. Position: trialApproval.Position,
  470. Mobile: trialApproval.Mobile,
  471. SellerId: seller.AdminId,
  472. Seller: seller.RealName,
  473. CreateTime: time.Now(),
  474. ModifyTime: time.Now(),
  475. ApprovalContent: "申请启用",
  476. ApplyMethod: 2,
  477. ApprovalStatus: "待审批",
  478. ApplyReasons: req.ApplyReasons,
  479. }
  480. approvalId, e = eta_trial.AddETATrialApproval(&approvalItem)
  481. if e != nil {
  482. err = e
  483. return
  484. }
  485. }
  486. //新增待办消息
  487. msgItem := new(company.CompanyApprovalMessage)
  488. msgItem.CreateUserId = sysUser.AdminId
  489. msgItem.ReceiveUserId = -1
  490. msgItem.MessageStatus = 1 // 已读, 不再亮红点, 但是消息要有
  491. msgItem.Remark = seller.RealName + "申请账号启用"
  492. msgItem.Content = seller.RealName + "申请账号启用"
  493. msgItem.CompanyName = trialApproval.CompanyName
  494. msgItem.CreateTime = time.Now()
  495. msgItem.ModifyTime = time.Now()
  496. msgItem.CompanyApprovalId = int(approvalId)
  497. msgItem.OperationStatus = 1
  498. msgItem.MessageType = 1 //1:申请消息,2:审批结果,3:文字消息
  499. msgItem.SourceType = 9 //消息来源
  500. msgItem.ApprovalStatus = 1 //审批状态,1:待审批,2:已审批,3:已驳回
  501. err = company.AddCompanyApprovalMessage(msgItem)
  502. // 2023-08-01默认审批通过, 不再进行人工审批
  503. go func() {
  504. _ = services.ApprovalApply(int(approvalId))
  505. }()
  506. }
  507. br.Ret = 200
  508. br.Success = true
  509. br.Msg = "提交成功"
  510. }
  511. // @Title 撤回
  512. // @Description 撤回申请 接口
  513. // @Success 200 {object} models.ETATrialAddReq
  514. // @router /apply/revoke [post]
  515. func (this *ETATrialController) ApplyRevoke() {
  516. br := new(models.BaseResponse).Init()
  517. defer func() {
  518. this.Data["json"] = br
  519. this.ServeJSON()
  520. }()
  521. sysUser := this.SysUser
  522. if sysUser == nil {
  523. br.Msg = "请登录"
  524. br.ErrMsg = "请登录,SysUser Is Empty"
  525. br.Ret = 408
  526. return
  527. }
  528. var req eta_trial.RevokeReq
  529. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  530. if err != nil {
  531. br.Msg = "参数解析异常!"
  532. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  533. return
  534. }
  535. mobile := req.Mobile
  536. mobile = strings.Trim(mobile, " ")
  537. mobile = strings.Replace(mobile, "'", "", -1)
  538. approval, err := eta_trial.GetETATrialApprovalByMobile(mobile)
  539. if err != nil {
  540. if err.Error() == utils.ErrNoRow() {
  541. br.Msg = "待审批信息不存在"
  542. br.ErrMsg = "待审批信息不存在,手机号:" + mobile
  543. return
  544. }
  545. br.Msg = "获取信息失败"
  546. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  547. return
  548. }
  549. if approval == nil {
  550. br.Msg = "待审批信息不存在"
  551. br.ErrMsg = "待审批信息不存在,手机号:" + mobile
  552. return
  553. }
  554. if approval.ApprovalStatus != "待审批" {
  555. br.Msg = "客户状态为:" + approval.ApprovalStatus + ";不可进行撤回操作"
  556. br.ErrMsg = "客户状态为:" + approval.ApprovalStatus + ";不可进行撤回操作"
  557. return
  558. }
  559. //撤回审批单
  560. err = eta_trial.RevokeApproval(mobile)
  561. if err != nil {
  562. br.Msg = "撤回失败"
  563. br.ErrMsg = "撤回失败,Err:" + err.Error()
  564. return
  565. }
  566. // 更新审批消息状态为已读
  567. go func() {
  568. cond := ` AND company_approval_id = ? AND source_type = ? AND message_status = ?`
  569. pars := make([]interface{}, 0)
  570. pars = append(pars, approval.ApprovalId, 9, 0)
  571. if e := company.ModifyCompanyApprovalMessageStatusByCond(cond, pars); e != nil {
  572. br.Msg = "操作失败"
  573. br.ErrMsg = "更新销售ETA试用消息已读状态失败, Err: " + e.Error()
  574. return
  575. }
  576. }()
  577. br.Ret = 200
  578. br.Success = true
  579. br.Msg = "撤回成功"
  580. }
  581. // @Title 删除申请
  582. // @Description 删除申请 接口
  583. // @Success 200 {object} models.ETATrialAddReq
  584. // @router /apply/del [post]
  585. func (this *ETATrialController) ApplyDel() {
  586. br := new(models.BaseResponse).Init()
  587. defer func() {
  588. this.Data["json"] = br
  589. this.ServeJSON()
  590. }()
  591. sysUser := this.SysUser
  592. if sysUser == nil {
  593. br.Msg = "请登录"
  594. br.ErrMsg = "请登录,SysUser Is Empty"
  595. br.Ret = 408
  596. return
  597. }
  598. var req eta_trial.DelReq
  599. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  600. if err != nil {
  601. br.Msg = "参数解析异常!"
  602. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  603. return
  604. }
  605. if req.ApprovalId <= 0 {
  606. br.Msg = "参数有误"
  607. return
  608. }
  609. _, e := eta_trial.GetETATrialApprovalById(req.ApprovalId)
  610. if e != nil {
  611. if e.Error() == utils.ErrNoRow() {
  612. br.Msg = "申请已被删除, 请刷新页面"
  613. return
  614. }
  615. br.Msg = "操作失败"
  616. br.ErrMsg = "获取ETA审批失败, Err: " + e.Error()
  617. return
  618. }
  619. err = eta_trial.DelApproval(req.ApprovalId)
  620. if err != nil {
  621. br.Msg = "删除失败"
  622. br.ErrMsg = "删除失败,Err:" + err.Error()
  623. return
  624. }
  625. // 更新审批消息状态为已读
  626. go func() {
  627. cond := ` AND company_approval_id = ? AND source_type = ? AND message_status = ?`
  628. pars := make([]interface{}, 0)
  629. pars = append(pars, req.ApprovalId, 9, 0)
  630. if e := company.ModifyCompanyApprovalMessageStatusByCond(cond, pars); e != nil {
  631. br.Msg = "操作失败"
  632. br.ErrMsg = "更新销售ETA试用消息已读状态失败, Err: " + e.Error()
  633. return
  634. }
  635. }()
  636. br.Ret = 200
  637. br.Success = true
  638. br.Msg = "删除成功"
  639. }
  640. // @Title 驳回申请
  641. // @Description 驳回申请 接口
  642. // @Param ApprovalId query string true "审批id"
  643. // @Param RejectReason query string true "驳回理由"
  644. // @Success 200 {object} models.ETATrialAddReq
  645. // @router /apply/reject [post]
  646. func (this *ETATrialController) ApplyReject() {
  647. br := new(models.BaseResponse).Init()
  648. defer func() {
  649. this.Data["json"] = br
  650. this.ServeJSON()
  651. }()
  652. sysUser := this.SysUser
  653. if sysUser == nil {
  654. br.Msg = "请登录"
  655. br.ErrMsg = "请登录,SysUser Is Empty"
  656. br.Ret = 408
  657. return
  658. }
  659. var req eta_trial.RejectReq
  660. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  661. if err != nil {
  662. br.Msg = "参数解析异常!"
  663. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  664. return
  665. }
  666. approvalId := req.ApprovalId
  667. reason := req.RejectReason
  668. err = eta_trial.RejectApproval(approvalId, reason)
  669. if err != nil {
  670. br.Msg = "删除失败"
  671. br.ErrMsg = "删除失败,Err:" + err.Error()
  672. return
  673. }
  674. approval, err := eta_trial.GetETATrialApprovalById(approvalId)
  675. if err != nil {
  676. br.Msg = "获取失败"
  677. br.ErrMsg = "获取失败,Err:" + err.Error()
  678. return
  679. }
  680. msgItem := new(company.CompanyApprovalMessage)
  681. msgItem.CreateUserId = sysUser.AdminId
  682. msgItem.ReceiveUserId = approval.SellerId
  683. msgItem.MessageStatus = 0
  684. msgItem.Remark = approval.UserName + approval.ApprovalContent + "驳回"
  685. msgItem.Content = approval.UserName + approval.ApprovalContent + "驳回"
  686. msgItem.CompanyName = approval.CompanyName
  687. msgItem.CreateTime = time.Now()
  688. msgItem.ModifyTime = time.Now()
  689. msgItem.CompanyApprovalId = approvalId
  690. msgItem.OperationStatus = 1
  691. msgItem.MessageType = 2 //1:申请消息,2:审批结果,3:文字消息
  692. msgItem.SourceType = 9 //消息来源
  693. msgItem.ApprovalStatus = 3 //审批状态,1:待审批,2:已审批,3:已驳回
  694. err = company.AddCompanyApprovalMessage(msgItem)
  695. // 更新审批消息(发给所有管理员的)为已读
  696. go func() {
  697. cond := ` AND company_approval_id = ? AND source_type = ? AND message_status = ? AND receive_user_id = -1 `
  698. pars := make([]interface{}, 0)
  699. pars = append(pars, req.ApprovalId, 9, 0)
  700. if e := company.ModifyCompanyApprovalMessageStatusByCond(cond, pars); e != nil {
  701. br.Msg = "操作失败"
  702. br.ErrMsg = "更新销售ETA试用消息已读状态失败, Err: " + e.Error()
  703. return
  704. }
  705. }()
  706. br.Ret = 200
  707. br.Success = true
  708. br.Msg = "驳回成功"
  709. }
  710. // @Title 同意申请
  711. // @Description 同意申请 接口
  712. // @Param ApprovalId query string true "审批id"
  713. // @Success 200 {object} models.ETATrialAddReq
  714. // @router /apply/approval [post]
  715. func (this *ETATrialController) Approval() {
  716. br := new(models.BaseResponse).Init()
  717. defer func() {
  718. this.Data["json"] = br
  719. this.ServeJSON()
  720. }()
  721. sysUser := this.SysUser
  722. if sysUser == nil {
  723. br.Msg = "请登录"
  724. br.ErrMsg = "请登录,SysUser Is Empty"
  725. br.Ret = 408
  726. return
  727. }
  728. var req eta_trial.DelReq
  729. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  730. if err != nil {
  731. br.Msg = "参数解析异常!"
  732. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  733. return
  734. }
  735. approvalId := req.ApprovalId
  736. err = eta_trial.ApprovalTrial(approvalId)
  737. if err != nil {
  738. br.Msg = "删除失败"
  739. br.ErrMsg = "删除失败,Err:" + err.Error()
  740. return
  741. }
  742. approval, err := eta_trial.GetETATrialApprovalById(approvalId)
  743. if err != nil {
  744. br.Msg = "查询失败"
  745. br.ErrMsg = "查询失败,Err:" + err.Error()
  746. return
  747. }
  748. //如果是新客户申请就新增,旧客户更改账号状态即可
  749. if approval.ApplyMethod == 2 {
  750. err := eta_trial.UpdateETATrialEnable(approval.Mobile)
  751. if err != nil {
  752. br.Msg = "启用失败"
  753. br.ErrMsg = "启用失败,Err:" + err.Error()
  754. return
  755. }
  756. err = eta_forum_hub.EnabledEtaTrialAdmin(approval.Mobile)
  757. if err != nil {
  758. br.Msg = "启用失败"
  759. br.ErrMsg = "启用失败,Err:" + err.Error()
  760. return
  761. }
  762. } else {
  763. //新增客户
  764. newItem := eta_trial.EtaTrial{
  765. UserName: approval.UserName,
  766. CompanyName: approval.CompanyName,
  767. Position: approval.Position,
  768. Mobile: approval.Mobile,
  769. Enabled: 1,
  770. SellerId: approval.SellerId,
  771. Seller: approval.Seller,
  772. CreateTime: time.Now(),
  773. ModifyTime: time.Now(),
  774. }
  775. strResult := ""
  776. a := pinyin.NewArgs()
  777. rows := pinyin.Pinyin(newItem.UserName, a)
  778. for i := 0; i < len(rows); i++ {
  779. strResult += rows[i][0]
  780. }
  781. //若非中文
  782. if strResult == "" {
  783. strResult = newItem.UserName
  784. }
  785. list, err := eta_trial.GetETATrialByAccount(strResult)
  786. if err != nil && err.Error() != utils.ErrNoRow() {
  787. br.Msg = "查询失败"
  788. br.ErrMsg = "查询失败,GetETATrialByAccount Err:" + err.Error()
  789. return
  790. }
  791. if list != nil && len(list) > 0 {
  792. newItem.Account = strResult + strconv.Itoa(len(list))
  793. } else {
  794. newItem.Account = strResult
  795. }
  796. //newItem.Password = utils.GetRandStringNoSpecialChar(8)
  797. // 初始密码固定
  798. newItem.Password = "123456a"
  799. _, err = eta_trial.AddETATrial(&newItem)
  800. if err != nil {
  801. br.Msg = "新增失败"
  802. br.ErrMsg = "新增失败,AddETATrial Err:" + err.Error()
  803. return
  804. }
  805. err = eta_forum_hub.AddEtaTrialAdmin(&newItem)
  806. if err != nil {
  807. err = fmt.Errorf("新增试用用户失败")
  808. return
  809. }
  810. }
  811. msgItem := new(company.CompanyApprovalMessage)
  812. msgItem.CreateUserId = sysUser.AdminId
  813. msgItem.ReceiveUserId = approval.SellerId
  814. msgItem.MessageStatus = 0
  815. msgItem.Remark = approval.UserName + approval.ApprovalContent + "通过"
  816. msgItem.Content = approval.UserName + approval.ApprovalContent + "通过"
  817. msgItem.CompanyName = approval.CompanyName
  818. msgItem.CreateTime = time.Now()
  819. msgItem.ModifyTime = time.Now()
  820. msgItem.CompanyApprovalId = approvalId
  821. msgItem.OperationStatus = 1
  822. msgItem.MessageType = 2 //1:申请消息,2:审批结果,3:文字消息
  823. msgItem.SourceType = 9 //消息来源
  824. msgItem.ApprovalStatus = 2 //审批状态,1:待审批,2:已审批,3:已驳回
  825. err = company.AddCompanyApprovalMessage(msgItem)
  826. // 更新审批消息(发给所有管理员的)为已读
  827. go func() {
  828. cond := ` AND company_approval_id = ? AND source_type = ? AND message_status = ? AND receive_user_id = -1 `
  829. pars := make([]interface{}, 0)
  830. pars = append(pars, req.ApprovalId, 9, 0)
  831. if e := company.ModifyCompanyApprovalMessageStatusByCond(cond, pars); e != nil {
  832. br.Msg = "操作失败"
  833. br.ErrMsg = "更新销售ETA试用消息已读状态失败, Err: " + e.Error()
  834. return
  835. }
  836. }()
  837. br.Ret = 200
  838. br.Success = true
  839. br.Msg = "审批成功"
  840. }
  841. // @Title 我的审批
  842. // @Description 我的审批 接口
  843. // @Param PageSize query int true "每页数据条数"
  844. // @Param CurrentIndex query int true "当前页页码,从1开始"
  845. // @Param KeyWord query string true "搜索关键词"
  846. // @Param SortType query string true "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒叙`"
  847. // @router /apply/myList [get]
  848. func (this *ETATrialController) MyList() {
  849. br := new(models.BaseResponse).Init()
  850. defer func() {
  851. this.Data["json"] = br
  852. this.ServeJSON()
  853. }()
  854. sysUser := this.SysUser
  855. if sysUser == nil {
  856. br.Msg = "请登录"
  857. br.ErrMsg = "请登录,SysUser Is Empty"
  858. br.Ret = 408
  859. return
  860. }
  861. pageSize, _ := this.GetInt("PageSize")
  862. currentIndex, _ := this.GetInt("CurrentIndex")
  863. keyWord := this.GetString("KeyWord")
  864. keyWord = strings.Trim(keyWord, " ")
  865. keyWord = strings.Replace(keyWord, "'", "", -1)
  866. //排序参数
  867. sortType := this.GetString("SortType")
  868. var total int
  869. page := paging.GetPaging(currentIndex, pageSize, total)
  870. var startSize int
  871. if pageSize <= 0 {
  872. pageSize = utils.PageSize20
  873. }
  874. if currentIndex <= 0 {
  875. currentIndex = 1
  876. }
  877. startSize = paging.StartIndex(currentIndex, pageSize)
  878. var condition string
  879. var pars []interface{}
  880. if keyWord != "" {
  881. condition += ` AND (a.user_name LIKE '%` + keyWord + `%' OR a.company_name LIKE '%` + keyWord + `%' OR a.mobile LIKE '%` + keyWord + `%') `
  882. }
  883. sortStr := ""
  884. if sortType == "asc" {
  885. sortStr = "ORDER BY a.modify_time ASC "
  886. } else {
  887. sortStr = "ORDER BY a.modify_time DESC "
  888. }
  889. pars = append(pars, sysUser.AdminId)
  890. total, err := eta_trial.GetETATrialApprovalCountBySellerId(condition, sortStr, pars)
  891. if err != nil {
  892. br.Msg = "获取失败"
  893. br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  894. return
  895. }
  896. list, err := eta_trial.GetETATrialApprovalBySellerId(condition, sortStr, pars, startSize, pageSize)
  897. if err != nil {
  898. br.Msg = "查询失败"
  899. br.ErrMsg = "查询失败,Err:" + err.Error()
  900. return
  901. }
  902. page = paging.GetPaging(currentIndex, pageSize, total)
  903. resp := new(eta_trial.ETATrialApprovalListRespList)
  904. resp.List = list
  905. resp.Paging = page
  906. br.Ret = 200
  907. br.Success = true
  908. br.Msg = "获取成功"
  909. br.Data = resp
  910. return
  911. }
  912. // @Title 审批列表
  913. // @Description 审批列表 接口
  914. // @Param SortParam query int false "排序字段参数,用来排序的字段 "
  915. // @Param ListParam query int false "筛选字段参数,用来筛选的字段, 枚举值:1:全部 、 2:待审批 、 3:已审批 "
  916. // @Param PageSize query int true "每页数据条数"
  917. // @Param CurrentIndex query int true "当前页页码,从1开始"
  918. // @Param KeyWord query string true "搜索关键词"
  919. // @Param SortType query string true "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒叙`"
  920. // @Success 200 {object} models.ETATrialAddReq
  921. // @router /apply/list [get]
  922. func (this *ETATrialController) ApplyList() {
  923. br := new(models.BaseResponse).Init()
  924. defer func() {
  925. this.Data["json"] = br
  926. this.ServeJSON()
  927. }()
  928. sysUser := this.SysUser
  929. if sysUser == nil {
  930. br.Msg = "请登录"
  931. br.ErrMsg = "请登录,SysUser Is Empty"
  932. br.Ret = 408
  933. return
  934. }
  935. pageSize, _ := this.GetInt("PageSize")
  936. currentIndex, _ := this.GetInt("CurrentIndex")
  937. keyWord := this.GetString("KeyWord")
  938. keyWord = strings.Trim(keyWord, " ")
  939. keyWord = strings.Replace(keyWord, "'", "", -1)
  940. //排序参数
  941. sortParam := this.GetString("SortParam")
  942. listParam, _ := this.GetInt("ListParam")
  943. sortType := this.GetString("SortType")
  944. var total int
  945. page := paging.GetPaging(currentIndex, pageSize, total)
  946. var startSize int
  947. if pageSize <= 0 {
  948. pageSize = utils.PageSize20
  949. }
  950. if currentIndex <= 0 {
  951. currentIndex = 1
  952. }
  953. startSize = paging.StartIndex(currentIndex, pageSize)
  954. var condition string
  955. var pars []interface{}
  956. if keyWord != "" {
  957. condition += ` AND (user_name LIKE '%` + keyWord + `%' OR company_name LIKE '%` + keyWord + `%' OR mobile LIKE '%` + keyWord + `%') `
  958. }
  959. sortStr := ""
  960. if listParam == 0 {
  961. condition += ` AND approval_status = '待审批' `
  962. } else if listParam == 2 {
  963. condition += ` AND approval_status = '待审批' `
  964. } else if listParam == 3 {
  965. condition += ` AND approval_status = '已审批' OR approval_status = '驳回' `
  966. }
  967. if sortType == "asc" {
  968. sortStr = "ORDER BY modify_time ASC "
  969. } else {
  970. sortStr = "ORDER BY modify_time DESC "
  971. }
  972. if sortParam == "Expiration" {
  973. if sortType == "asc" {
  974. sortStr = "ORDER BY modify_time ASC "
  975. } else {
  976. sortStr = "ORDER BY modify_time DESC "
  977. }
  978. } else if sortParam == "ModifyTime" {
  979. if sortType == "asc" {
  980. sortStr = "ORDER BY modify_time ASC "
  981. } else {
  982. sortStr = "ORDER BY modify_time DESC "
  983. }
  984. }
  985. total, err := eta_trial.GetETATrialApprovalListCount(condition, pars)
  986. if err != nil {
  987. br.Msg = "获取失败"
  988. br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  989. return
  990. }
  991. list, err := eta_trial.GetETATrialApprovalList(condition, sortStr, pars, startSize, pageSize)
  992. if err != nil {
  993. br.Msg = "查询失败"
  994. br.ErrMsg = "查询失败,Err:" + err.Error()
  995. return
  996. }
  997. page = paging.GetPaging(currentIndex, pageSize, total)
  998. resp := new(eta_trial.ETATrialApprovalListRespList)
  999. resp.List = list
  1000. resp.Paging = page
  1001. br.Ret = 200
  1002. br.Success = true
  1003. br.Msg = "获取成功"
  1004. br.Data = resp
  1005. return
  1006. }
  1007. // @Title 账号列表
  1008. // @Description 账号列表 接口
  1009. // @Param SortParam query string false "排序字段参数,用来排序的字段, 枚举值:'Expiration':账号到期时长 、 'ModifyTime':账号更新时间 "
  1010. // @Param PageSize query int true "每页数据条数"
  1011. // @Param CurrentIndex query int true "当前页页码,从1开始"
  1012. // @Param KeyWord query string true "搜索关键词"
  1013. // @Param SortType query string true "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒叙`"
  1014. // @Success 200 {object} models.ETATrialAddReq
  1015. // @router /apply/accountlist [get]
  1016. func (this *ETATrialController) AccountList() {
  1017. br := new(models.BaseResponse).Init()
  1018. defer func() {
  1019. this.Data["json"] = br
  1020. this.ServeJSON()
  1021. }()
  1022. sysUser := this.SysUser
  1023. if sysUser == nil {
  1024. br.Msg = "请登录"
  1025. br.ErrMsg = "请登录,SysUser Is Empty"
  1026. br.Ret = 408
  1027. return
  1028. }
  1029. pageSize, _ := this.GetInt("PageSize")
  1030. currentIndex, _ := this.GetInt("CurrentIndex")
  1031. keyWord := this.GetString("KeyWord")
  1032. keyWord = strings.Trim(keyWord, " ")
  1033. keyWord = strings.Replace(keyWord, "'", "", -1)
  1034. //排序参数
  1035. sortType := this.GetString("SortType")
  1036. var total int
  1037. page := paging.GetPaging(currentIndex, pageSize, total)
  1038. var startSize int
  1039. if pageSize <= 0 {
  1040. pageSize = utils.PageSize20
  1041. }
  1042. if currentIndex <= 0 {
  1043. currentIndex = 1
  1044. }
  1045. startSize = paging.StartIndex(currentIndex, pageSize)
  1046. var condition string
  1047. var pars []interface{}
  1048. if keyWord != "" {
  1049. condition += ` AND (user_name LIKE '%` + keyWord + `%' OR company_name LIKE '%` + keyWord + `%' OR mobile LIKE '%` + keyWord + `%') `
  1050. }
  1051. if sysUser.RoleTypeCode != "admin" && sysUser.RoleTypeCode != "ficc_admin" {
  1052. condition += ` AND seller_id = ? `
  1053. pars = append(pars, sysUser.AdminId)
  1054. }
  1055. total, err := eta_trial.GetETATrialListCount(condition, pars)
  1056. if err != nil {
  1057. br.Msg = "获取失败"
  1058. br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  1059. return
  1060. }
  1061. sortStr := ""
  1062. if sortType == "asc" {
  1063. sortStr = "ORDER BY modify_time ASC "
  1064. } else {
  1065. sortStr = "ORDER BY modify_time DESC "
  1066. }
  1067. list, err := eta_trial.GetETATrialList(condition, sortStr, pars, startSize, pageSize)
  1068. if err != nil {
  1069. br.Msg = "获取权限列表失败"
  1070. br.ErrMsg = "获取权限列表失败,Err:" + err.Error()
  1071. return
  1072. }
  1073. for _, item := range list {
  1074. activeTime, _ := strconv.Atoi(item.ActiveTime)
  1075. item.ActiveTime = utils.GetDurationFormatBySecond(activeTime)
  1076. //到期时间
  1077. modifyTime, err := time.Parse(utils.FormatDateTime, item.ModifyTime)
  1078. if err != nil {
  1079. br.Msg = "时间转化失败"
  1080. br.ErrMsg = "时间转化失败,Err:" + err.Error()
  1081. return
  1082. }
  1083. var expired int
  1084. expiredTime := modifyTime.AddDate(0, 0, 14).Format(utils.FormatDate)
  1085. expired, err = utils.GetDaysBetween2Date(utils.FormatDate, expiredTime, time.Now().Format(utils.FormatDate))
  1086. if err != nil {
  1087. br.Msg = "时间计算失败"
  1088. br.ErrMsg = "时间计算失败,CalculationDate Err:" + err.Error()
  1089. return
  1090. }
  1091. item.Expiration = expired
  1092. }
  1093. page = paging.GetPaging(currentIndex, pageSize, total)
  1094. resp := new(eta_trial.ETATrialListRespList)
  1095. resp.List = list
  1096. resp.Paging = page
  1097. br.Ret = 200
  1098. br.Success = true
  1099. br.Msg = "获取成功"
  1100. br.Data = resp
  1101. return
  1102. }
  1103. // @Title 问卷配置
  1104. // @Description 问卷配置 接口
  1105. // @Success 200 string "获取成功"
  1106. // @router /questionnaire/list [get]
  1107. func (this *ETATrialController) QuestionnaireList() {
  1108. br := new(models.BaseResponse).Init()
  1109. defer func() {
  1110. this.Data["json"] = br
  1111. this.ServeJSON()
  1112. }()
  1113. sysUser := this.SysUser
  1114. if sysUser == nil {
  1115. br.Msg = "请登录"
  1116. br.ErrMsg = "请登录,SysUser Is Empty"
  1117. br.Ret = 408
  1118. return
  1119. }
  1120. cond := ""
  1121. lists, err := eta_trial.GetETATrialQuestionnaireList(cond)
  1122. if err != nil {
  1123. br.Msg = "获取问卷失败"
  1124. br.ErrMsg = "获取问卷失败,Err:" + err.Error()
  1125. return
  1126. }
  1127. var resp eta_trial.EtaTrialQuestionnaireResp
  1128. for _, v := range lists {
  1129. item := eta_trial.EtaTrialQuestionnaireRespItem{
  1130. QuestionnaireId: v.QuestionnaireId,
  1131. Question: v.Question,
  1132. Type: v.Type,
  1133. Sort: v.Sort,
  1134. Options: strings.Split(v.Options, "~#"),
  1135. IsMust: v.IsMust,
  1136. CreateTime: v.CreateTime.Format(utils.FormatDateTime),
  1137. }
  1138. resp.List = append(resp.List, item)
  1139. }
  1140. sort.Sort(resp)
  1141. br.Ret = 200
  1142. br.Success = true
  1143. br.Msg = "获取成功"
  1144. br.Data = resp
  1145. return
  1146. }
  1147. // @Title 问卷保存
  1148. // @Description 问卷保存 接口
  1149. // @Param request body eta_trial.EtaTrialQuestionnaireSaveReq true "type json string"
  1150. // @Success 200 {object} models.ETATrialAddReq
  1151. // @router /questionnaire/save [post]
  1152. func (this *ETATrialController) QuestionnairesSave() {
  1153. br := new(models.BaseResponse).Init()
  1154. defer func() {
  1155. this.Data["json"] = br
  1156. this.ServeJSON()
  1157. }()
  1158. sysUser := this.SysUser
  1159. if sysUser == nil {
  1160. br.Msg = "请登录"
  1161. br.ErrMsg = "请登录,SysUser Is Empty"
  1162. br.Ret = 408
  1163. return
  1164. }
  1165. var req eta_trial.EtaTrialQuestionnaireSaveReq
  1166. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1167. if err != nil {
  1168. br.Msg = "参数解析异常!"
  1169. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1170. return
  1171. }
  1172. questionnaireList := make([]*eta_trial.EtaTrialQuestionnaire, 0)
  1173. for _, v := range req.List {
  1174. if v.QuestionnaireId == 0 {
  1175. //新增
  1176. questionItem := &eta_trial.EtaTrialQuestionnaire{
  1177. Question: v.Question,
  1178. IsMust: v.IsMust,
  1179. Type: v.Type,
  1180. Sort: v.Sort,
  1181. Options: strings.Join(v.Options, "~#"),
  1182. CreateTime: time.Now(),
  1183. }
  1184. questionnaireList = append(questionnaireList, questionItem)
  1185. } else {
  1186. //更新
  1187. questionItem := &eta_trial.EtaTrialQuestionnaire{
  1188. QuestionnaireId: v.QuestionnaireId,
  1189. Question: v.Question,
  1190. Options: strings.Join(v.Options, "~#"),
  1191. Sort: v.Sort,
  1192. IsMust: v.IsMust,
  1193. CreateTime: time.Time{},
  1194. }
  1195. cols := make([]string, 0)
  1196. cols = append(cols, "question", "options", "Sort", "IsMust")
  1197. err = questionItem.Update(cols)
  1198. if err != nil {
  1199. br.Msg = "更新问题失败!"
  1200. br.ErrMsg = "更新问题失败,Err:" + err.Error()
  1201. return
  1202. }
  1203. }
  1204. }
  1205. //批量新增问题和选项
  1206. if len(questionnaireList) > 0 {
  1207. err = eta_trial.AddETATrialQuestionnaire(questionnaireList)
  1208. if err != nil {
  1209. br.Msg = "保存问题失败!"
  1210. br.ErrMsg = "保存问题失败,Err:" + err.Error()
  1211. return
  1212. }
  1213. }
  1214. br.Ret = 200
  1215. br.Success = true
  1216. br.Msg = "保存成功"
  1217. return
  1218. }
  1219. // @Title 问题删除
  1220. // @Description 问题删除 接口
  1221. // @Param request body eta_trial.EtaTrialQuestionnaireSaveReq true "type json string"
  1222. // @Success 200 {object} models.ETATrialAddReq
  1223. // @router /questionnaire/del [post]
  1224. func (this *ETATrialController) QuestionnairesDel() {
  1225. br := new(models.BaseResponse).Init()
  1226. defer func() {
  1227. this.Data["json"] = br
  1228. this.ServeJSON()
  1229. }()
  1230. sysUser := this.SysUser
  1231. if sysUser == nil {
  1232. br.Msg = "请登录"
  1233. br.ErrMsg = "请登录,SysUser Is Empty"
  1234. br.Ret = 408
  1235. return
  1236. }
  1237. var req eta_trial.EtaTrialQuestionnaireDelReq
  1238. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1239. if err != nil {
  1240. br.Msg = "参数解析异常!"
  1241. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1242. return
  1243. }
  1244. if req.QuestionnaireId <= 0 {
  1245. br.Msg = "问题id异常!"
  1246. br.ErrMsg = "问题id异常,Err:" + err.Error()
  1247. return
  1248. }
  1249. count, err := eta_trial.GetETATrialQuestionnaireById(req.QuestionnaireId)
  1250. if err != nil && count > 0 {
  1251. br.Msg = "查询问题异常!"
  1252. br.ErrMsg = "查询问题异常,Err:" + err.Error()
  1253. return
  1254. }
  1255. err = eta_trial.DelETATrialQuestionnaireById(req.QuestionnaireId)
  1256. if err != nil && count > 0 {
  1257. br.Msg = "删除问题异常!"
  1258. br.ErrMsg = "删除问题异常,Err:" + err.Error()
  1259. return
  1260. }
  1261. br.Ret = 200
  1262. br.Success = true
  1263. br.Msg = "删除成功"
  1264. return
  1265. }
  1266. // @Title 问卷统计结果
  1267. // @Description 问卷统计结果 接口
  1268. // @Param ListParam query int false "筛选字段参数,用来筛选的字段, 枚举值:1:全部 、 2:选择题 、 3:简答题 "
  1269. // @Success 200 {object} models.ETATrialAddReq
  1270. // @router /questionnaire/statistical [get]
  1271. func (this *ETATrialController) QuestionnairesStatistical() {
  1272. br := new(models.BaseResponse).Init()
  1273. defer func() {
  1274. this.Data["json"] = br
  1275. this.ServeJSON()
  1276. }()
  1277. sysUser := this.SysUser
  1278. if sysUser == nil {
  1279. br.Msg = "请登录"
  1280. br.ErrMsg = "请登录,SysUser Is Empty"
  1281. br.Ret = 408
  1282. return
  1283. }
  1284. listParam, _ := this.GetInt("ListParam")
  1285. cond := ""
  1286. if listParam == 2 {
  1287. cond = "AND a.type = 1 OR a.type = 2 "
  1288. } else if listParam == 3 {
  1289. cond = "AND a.type = 3 "
  1290. }
  1291. list, err := eta_trial.GetETATrialQuestionnaireStatistic(cond)
  1292. if err != nil {
  1293. br.Msg = "获取问题统计失败!"
  1294. br.ErrMsg = "获取问题统计失败,Err:" + err.Error()
  1295. return
  1296. }
  1297. //获取单选和简答的回答数量,多选计算方式不同在计算后面统计时再计算
  1298. questionCountList, err := eta_trial.GetETATrialQuestionnaireStatisticCount()
  1299. if err != nil {
  1300. br.Msg = "获取问卷记录数量失败"
  1301. br.ErrMsg = "获取问卷记录数量失败,Err:" + err.Error()
  1302. return
  1303. }
  1304. questioncountMap := make(map[int]int, 0)
  1305. for _, v := range questionCountList {
  1306. questioncountMap[v.QuestionnaireId] = v.Count
  1307. }
  1308. chooseMap := make(map[string]int, 0)
  1309. answerCountMap := make(map[int]int, 0)
  1310. answerMap := make(map[int][]string, 0)
  1311. answerNameMap := make(map[int]string, 0)
  1312. for _, v := range list {
  1313. //问卷ID拼选项作为key,防止不同问题选项重复
  1314. if v.Type == 1 {
  1315. key := strconv.Itoa(v.QuestionnaireId) + v.Options
  1316. if _, ok := chooseMap[key]; !ok {
  1317. chooseMap[key] = v.Count
  1318. }
  1319. } else if v.Type == 2 {
  1320. options := strings.Split(v.Options, "~#")
  1321. for _, op := range options {
  1322. key := strconv.Itoa(v.QuestionnaireId) + op
  1323. if _, ok := chooseMap[key]; ok {
  1324. //多选题可能出现多人同样的选择
  1325. chooseMap[key] += v.Count
  1326. } else {
  1327. chooseMap[key] = v.Count
  1328. }
  1329. questioncountMap[v.QuestionnaireId] += v.Count
  1330. }
  1331. } else {
  1332. //简答题,最多十条
  1333. if count, ok := answerCountMap[v.QuestionnaireId]; ok && count < 11 {
  1334. answerMap[v.QuestionnaireId] = append(answerMap[v.QuestionnaireId], v.Options)
  1335. answerNameMap[v.QuestionnaireId] = v.UserName
  1336. answerCountMap[v.QuestionnaireId] += 1
  1337. } else if !ok {
  1338. answerMap[v.QuestionnaireId] = append(answerMap[v.QuestionnaireId], v.Options)
  1339. answerNameMap[v.QuestionnaireId] = v.UserName
  1340. answerCountMap[v.QuestionnaireId] = 1
  1341. }
  1342. }
  1343. }
  1344. lists, err := eta_trial.GetETATrialQuestionnaireList(cond)
  1345. if err != nil {
  1346. br.Msg = "获取问卷失败"
  1347. br.ErrMsg = "获取问卷失败,Err:" + err.Error()
  1348. return
  1349. }
  1350. var questionList eta_trial.EtaTrialQuestionnaireResp
  1351. for _, v := range lists {
  1352. item := eta_trial.EtaTrialQuestionnaireRespItem{
  1353. QuestionnaireId: v.QuestionnaireId,
  1354. Question: v.Question,
  1355. Options: strings.Split(v.Options, "~#"),
  1356. Type: v.Type,
  1357. Sort: v.Sort,
  1358. IsMust: v.IsMust,
  1359. CreateTime: v.CreateTime.Format(utils.FormatDateTime),
  1360. }
  1361. questionList.List = append(questionList.List, item)
  1362. }
  1363. sort.Sort(questionList)
  1364. var resp []eta_trial.EtaTrialQuestionnaireRecordStatisticResp
  1365. for _, v := range questionList.List {
  1366. if v.Type != 3 {
  1367. options := make([]*eta_trial.EtaTrialQuestionnaireRecordStatisticOption, 0)
  1368. for _, op := range v.Options {
  1369. key := strconv.Itoa(v.QuestionnaireId) + op
  1370. opItem := eta_trial.EtaTrialQuestionnaireRecordStatisticOption{
  1371. Option: op,
  1372. Count: chooseMap[key],
  1373. }
  1374. options = append(options, &opItem)
  1375. }
  1376. item := eta_trial.EtaTrialQuestionnaireRecordStatisticResp{
  1377. QuestionnaireId: v.QuestionnaireId,
  1378. Question: v.Question,
  1379. Options: options,
  1380. Type: v.Type,
  1381. IsMust: v.IsMust,
  1382. }
  1383. resp = append(resp, item)
  1384. } else {
  1385. item := eta_trial.EtaTrialQuestionnaireRecordStatisticResp{
  1386. QuestionnaireId: v.QuestionnaireId,
  1387. Question: v.Question,
  1388. Type: v.Type,
  1389. IsMust: v.IsMust,
  1390. }
  1391. ansList := make([]eta_trial.EtaTrialQuestionnaireRecordStatisticAnswer, 0)
  1392. for _, val := range answerMap[v.QuestionnaireId] {
  1393. ansItem := eta_trial.EtaTrialQuestionnaireRecordStatisticAnswer{
  1394. Answer: val,
  1395. UserName: answerNameMap[v.QuestionnaireId],
  1396. }
  1397. ansList = append(ansList, ansItem)
  1398. }
  1399. item.Answers = ansList
  1400. resp = append(resp, item)
  1401. }
  1402. }
  1403. for _, v := range resp {
  1404. if v.Type != 3 && v.Type != 4 {
  1405. for i, op := range v.Options {
  1406. key := strconv.Itoa(v.QuestionnaireId) + op.Option
  1407. opCount := float64(chooseMap[key])
  1408. count := float64(questioncountMap[v.QuestionnaireId])
  1409. if count != 0 {
  1410. per, _ := strconv.ParseFloat(fmt.Sprintf("%.4f", opCount/count), 64)
  1411. op.Percentage = per
  1412. }
  1413. op.Index = i
  1414. }
  1415. }
  1416. }
  1417. br.Ret = 200
  1418. br.Success = true
  1419. br.Msg = "保存成功"
  1420. br.Data = resp
  1421. return
  1422. }
  1423. // @Title 简答题列表
  1424. // @Description 简答题列表 接口
  1425. // @Success 200 string "获取成功"
  1426. // @Param PageSize query int true "每页数据条数"
  1427. // @Param CurrentIndex query int true "当前页页码,从1开始"
  1428. // @Param QuestionnaireId query int true "问题id"
  1429. // @router /questionnaire/answerList [get]
  1430. func (this *ETATrialController) QuestionnaireAnswerList() {
  1431. br := new(models.BaseResponse).Init()
  1432. defer func() {
  1433. this.Data["json"] = br
  1434. this.ServeJSON()
  1435. }()
  1436. sysUser := this.SysUser
  1437. if sysUser == nil {
  1438. br.Msg = "请登录"
  1439. br.ErrMsg = "请登录,SysUser Is Empty"
  1440. br.Ret = 408
  1441. return
  1442. }
  1443. var startSize int
  1444. pageSize, _ := this.GetInt("PageSize")
  1445. currentIndex, _ := this.GetInt("CurrentIndex")
  1446. if pageSize <= 0 {
  1447. pageSize = utils.PageSize20
  1448. }
  1449. if currentIndex <= 0 {
  1450. currentIndex = 1
  1451. }
  1452. startSize = paging.StartIndex(currentIndex, pageSize)
  1453. questionnaireId, _ := this.GetInt("QuestionnaireId")
  1454. lists, err := eta_trial.GetETATrialQuestionnaireAnswerListById(questionnaireId, startSize, pageSize)
  1455. if err != nil {
  1456. br.Msg = "获取问卷失败"
  1457. br.ErrMsg = "获取问卷失败,Err:" + err.Error()
  1458. return
  1459. }
  1460. total, err := eta_trial.GetETATrialQuestionnaireAnswerListByIdCount(questionnaireId)
  1461. if err != nil {
  1462. br.Msg = "获取问卷失败"
  1463. br.ErrMsg = "获取问卷失败,Err:" + err.Error()
  1464. return
  1465. }
  1466. cond := ""
  1467. qLists, err := eta_trial.GetETATrialQuestionnaireList(cond)
  1468. if err != nil {
  1469. br.Msg = "获取问卷失败"
  1470. br.ErrMsg = "获取问卷失败,Err:" + err.Error()
  1471. return
  1472. }
  1473. mustMap := make(map[int]int, 0)
  1474. for _, v := range qLists {
  1475. mustMap[v.QuestionnaireId] = v.IsMust
  1476. }
  1477. resp := new(eta_trial.QuestionnaireDetailListResp)
  1478. for _, v := range lists {
  1479. item := eta_trial.EtaTrialQuestionnaireRecordRespItem{
  1480. RecordId: v.RecordId,
  1481. UserName: v.UserName,
  1482. CompanyName: v.CompanyName,
  1483. Position: v.Position,
  1484. Options: v.Options,
  1485. Mobile: v.Mobile,
  1486. Type: v.Type,
  1487. QuestionnaireId: v.QuestionnaireId,
  1488. IsMust: mustMap[v.QuestionnaireId],
  1489. CreateTime: v.CreateTime.Format(utils.FormatDateTime),
  1490. }
  1491. resp.List = append(resp.List, &item)
  1492. }
  1493. page := paging.GetPaging(currentIndex, pageSize, total)
  1494. resp.Paging = page
  1495. br.Ret = 200
  1496. br.Success = true
  1497. br.Msg = "获取成功"
  1498. br.Data = resp
  1499. return
  1500. }
  1501. // @Title 详细数据列表
  1502. // @Description 详细数据列表 接口
  1503. // @Success 200 string "获取成功"
  1504. // @Param PageSize query int true "每页数据条数"
  1505. // @Param CurrentIndex query int true "当前页页码,从1开始"
  1506. // @router /questionnaire/detailList [get]
  1507. func (this *ETATrialController) QuestionnaireDetailList() {
  1508. br := new(models.BaseResponse).Init()
  1509. defer func() {
  1510. this.Data["json"] = br
  1511. this.ServeJSON()
  1512. }()
  1513. sysUser := this.SysUser
  1514. if sysUser == nil {
  1515. br.Msg = "请登录"
  1516. br.ErrMsg = "请登录,SysUser Is Empty"
  1517. br.Ret = 408
  1518. return
  1519. }
  1520. var startSize int
  1521. pageSize, _ := this.GetInt("PageSize")
  1522. currentIndex, _ := this.GetInt("CurrentIndex")
  1523. if pageSize <= 0 {
  1524. pageSize = utils.PageSize20
  1525. }
  1526. if currentIndex <= 0 {
  1527. currentIndex = 1
  1528. }
  1529. startSize = paging.StartIndex(currentIndex, pageSize)
  1530. total, err := eta_trial.GetETATrialQuestionnaireDetailListCount()
  1531. if err != nil {
  1532. br.Msg = "获取问卷数量失败"
  1533. br.ErrMsg = "获取问卷数量失败,Err:" + err.Error()
  1534. return
  1535. }
  1536. if total == 0 {
  1537. br.Msg = "无问卷调查记录"
  1538. br.Ret = 200
  1539. br.Success = true
  1540. return
  1541. }
  1542. lists, err := eta_trial.GetETATrialQuestionnaireDetailList(startSize, pageSize)
  1543. if err != nil {
  1544. br.Msg = "获取问卷失败"
  1545. br.ErrMsg = "获取问卷失败,Err:" + err.Error()
  1546. return
  1547. }
  1548. cond := ""
  1549. qLists, err := eta_trial.GetETATrialQuestionnaireList(cond)
  1550. if err != nil {
  1551. br.Msg = "获取问卷失败"
  1552. br.ErrMsg = "获取问卷失败,Err:" + err.Error()
  1553. return
  1554. }
  1555. mustMap := make(map[int]int, 0)
  1556. for _, v := range qLists {
  1557. mustMap[v.QuestionnaireId] = v.IsMust
  1558. }
  1559. resp := new(eta_trial.QuestionnaireDetailListResp)
  1560. for _, v := range lists {
  1561. item := eta_trial.EtaTrialQuestionnaireRecordRespItem{
  1562. RecordId: v.RecordId,
  1563. UserName: v.UserName,
  1564. CompanyName: v.CompanyName,
  1565. Position: v.Position,
  1566. Options: v.Options,
  1567. Mobile: v.Mobile,
  1568. Type: v.Type,
  1569. QuestionnaireId: v.QuestionnaireId,
  1570. IsMust: mustMap[v.QuestionnaireId],
  1571. CreateTime: v.CreateTime.Format(utils.FormatDateTime),
  1572. }
  1573. resp.List = append(resp.List, &item)
  1574. }
  1575. page := paging.GetPaging(currentIndex, pageSize, total)
  1576. resp.Paging = page
  1577. br.Ret = 200
  1578. br.Success = true
  1579. br.Msg = "获取成功"
  1580. br.Data = resp
  1581. return
  1582. }
  1583. // @Title 详细数据查看
  1584. // @Description 详细数据查看 接口
  1585. // @Success 200 string "获取成功"
  1586. // @Param Mobile query string true "手机号"
  1587. // @Param CreateTime query string true "手机号"
  1588. // @router /questionnaire/detail [get]
  1589. func (this *ETATrialController) QuestionnaireDetail() {
  1590. br := new(models.BaseResponse).Init()
  1591. defer func() {
  1592. this.Data["json"] = br
  1593. this.ServeJSON()
  1594. }()
  1595. sysUser := this.SysUser
  1596. if sysUser == nil {
  1597. br.Msg = "请登录"
  1598. br.ErrMsg = "请登录,SysUser Is Empty"
  1599. br.Ret = 408
  1600. return
  1601. }
  1602. cond := ""
  1603. lists, err := eta_trial.GetETATrialQuestionnaireList(cond)
  1604. if err != nil {
  1605. br.Msg = "获取问卷失败"
  1606. br.ErrMsg = "获取问卷失败,Err:" + err.Error()
  1607. return
  1608. }
  1609. var resp eta_trial.EtaTrialQuestionnaireResp
  1610. for _, v := range lists {
  1611. item := eta_trial.EtaTrialQuestionnaireRespItem{
  1612. QuestionnaireId: v.QuestionnaireId,
  1613. Question: v.Question,
  1614. Options: strings.Split(v.Options, "~#"),
  1615. Type: v.Type,
  1616. Sort: v.Sort,
  1617. IsMust: v.IsMust,
  1618. CreateTime: v.CreateTime.Format(utils.FormatDateTime),
  1619. }
  1620. resp.List = append(resp.List, item)
  1621. }
  1622. sort.Sort(resp)
  1623. mobile := this.GetString("Mobile")
  1624. createTime := this.GetString("CreateTime")
  1625. timeDate, _ := time.Parse(utils.FormatDateTime, createTime)
  1626. startDate := timeDate.AddDate(0, 0, -1).Format(utils.FormatDateTime)
  1627. endDate := timeDate.AddDate(0, 0, 1).Format(utils.FormatDateTime)
  1628. answerList, err := eta_trial.GetETATrialQuestionnaireDetailListByMobile(mobile, startDate, endDate)
  1629. if err != nil {
  1630. br.Msg = "获取问卷失败"
  1631. br.ErrMsg = "获取问卷失败,Err:" + err.Error()
  1632. return
  1633. }
  1634. answerMap := make(map[int]string)
  1635. for _, v := range answerList {
  1636. answerMap[v.QuestionnaireId] = v.Options
  1637. }
  1638. nResp := make([]eta_trial.EtaTrialQuestionnaireDetailItem, 0)
  1639. for _, v := range lists {
  1640. item := eta_trial.EtaTrialQuestionnaireDetailItem{
  1641. QuestionnaireId: v.QuestionnaireId,
  1642. Question: v.Question,
  1643. Type: v.Type,
  1644. Sort: v.Sort,
  1645. IsMust: v.IsMust,
  1646. Options: strings.Split(v.Options, "~#"),
  1647. UserOptions: answerMap[v.QuestionnaireId],
  1648. CreateTime: v.CreateTime.Format(utils.FormatDateTime),
  1649. }
  1650. nResp = append(nResp, item)
  1651. }
  1652. br.Ret = 200
  1653. br.Success = true
  1654. br.Msg = "获取成功"
  1655. br.Data = nResp
  1656. return
  1657. }
  1658. // EnableAccountList
  1659. // @Title 已启用账号列表
  1660. // @Description 已启用账号列表
  1661. // @Success 200
  1662. // @router /enable/account/list [get]
  1663. func (this *ETATrialController) EnableAccountList() {
  1664. br := new(models.BaseResponse).Init()
  1665. defer func() {
  1666. this.Data["json"] = br
  1667. this.ServeJSON()
  1668. }()
  1669. sysUser := this.SysUser
  1670. if sysUser == nil {
  1671. br.Msg = "请登录"
  1672. br.ErrMsg = "请登录,SysUser Is Empty"
  1673. br.Ret = 408
  1674. return
  1675. }
  1676. var condition string
  1677. var pars []interface{}
  1678. condition += ` AND enabled = ? `
  1679. pars = append(pars, 1)
  1680. adminItems, err := system.GetSysUserItems(condition, pars)
  1681. if err != nil {
  1682. return
  1683. }
  1684. br.Ret = 200
  1685. br.Success = true
  1686. br.Msg = "获取成功"
  1687. br.Data = adminItems
  1688. return
  1689. }
  1690. // AccountTransfer
  1691. // @Title 账号转移
  1692. // @Description 账号转移
  1693. // @Success 200
  1694. // @router /account/transfer [post]
  1695. func (this *ETATrialController) AccountTransfer() {
  1696. br := new(models.BaseResponse).Init()
  1697. defer func() {
  1698. this.Data["json"] = br
  1699. this.ServeJSON()
  1700. }()
  1701. sysUser := this.SysUser
  1702. if sysUser == nil {
  1703. br.Msg = "请登录"
  1704. br.ErrMsg = "请登录,SysUser Is Empty"
  1705. br.Ret = 408
  1706. return
  1707. }
  1708. var req eta_trial.TrialAccountTransferReq
  1709. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1710. if err != nil {
  1711. br.Msg = "参数解析异常!"
  1712. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1713. return
  1714. }
  1715. if len(req.EtaTrialIdList) <= 0 {
  1716. br.Msg = "参数有误"
  1717. br.ErrMsg = "参数有误, 至少选中一个试用用户"
  1718. return
  1719. }
  1720. err = eta_trial.TransferETATrial(&req)
  1721. if err != nil {
  1722. br.Msg = "转移失败!"
  1723. br.ErrMsg = "转移失败,Err:" + err.Error()
  1724. return
  1725. }
  1726. br.Ret = 200
  1727. br.Success = true
  1728. br.Msg = "获取成功"
  1729. return
  1730. }