eta_trial.go 54 KB

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