eta_trial.go 54 KB

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