eta_trial.go 51 KB

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