user.go 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355
  1. package eta_business
  2. import (
  3. "encoding/json"
  4. "eta/eta_forum_admin/controllers"
  5. "eta/eta_forum_admin/models"
  6. "eta/eta_forum_admin/models/eta_business"
  7. "eta/eta_forum_admin/models/system"
  8. eta_business2 "eta/eta_forum_admin/services/eta_business"
  9. "eta/eta_forum_admin/utils"
  10. "fmt"
  11. "github.com/rdlucklib/rdluck_tools/paging"
  12. "github.com/tealeg/xlsx"
  13. "os"
  14. "strings"
  15. "time"
  16. )
  17. // 客户联系人管理
  18. type EtaBusinessUserController struct {
  19. controllers.BaseAuthController
  20. }
  21. // List
  22. // @Title 联系人列表
  23. // @Description 联系人列表接口
  24. // @Param PageSize query int true "每页数据条数"
  25. // @Param CurrentIndex query int true "当前页页码,从1开始"
  26. // @Param CompanyId query int true "公司id,必填"
  27. // @Param KeyWord query string true "搜索关键词"
  28. // @Param ProductType query int true "产品类型"
  29. // @Param ProductId query int true "产品id"
  30. // @Param IsSubscribe query int true "是否关注了公众号: -1-默认全部; 0-未关注; 1-已关注"
  31. // @Param IsSubscribeHzyj query int true "是否关注了弘则研究公众号: -1-默认全部; 0-未关注; 1-已关注"
  32. // @Param IsSubscribeCygx query int true "是否关注了查研观向小助手公众号: -1-默认全部; 0-未关注; 1-已关注"
  33. // @Success 200 {object} company.CompanyUserListResp
  34. // @router /user/list [get]
  35. func (this *EtaBusinessUserController) List() {
  36. br := new(models.BaseResponse).Init()
  37. defer func() {
  38. this.Data["json"] = br
  39. this.ServeJSON()
  40. }()
  41. sysUser := this.SysUser
  42. if sysUser == nil {
  43. br.Msg = "请登录"
  44. br.ErrMsg = "请登录,SysUser Is Empty"
  45. br.Ret = 408
  46. return
  47. }
  48. pageSize, _ := this.GetInt("PageSize")
  49. currentIndex, _ := this.GetInt("CurrentIndex")
  50. positionStatus, _ := this.GetInt("PositionStatus", -1)
  51. enabled, _ := this.GetInt("Enabled", -1)
  52. businessCode := this.GetString("BusinessCode")
  53. etaBusinessId, _ := this.GetInt("EtaBusinessId")
  54. keyword := utils.TrimStr(this.GetString("Keyword"))
  55. sortType := this.GetString("SortType")
  56. sortParam := this.GetString("SortParam")
  57. /*if businessCode <= 0 {
  58. br.Msg = "请选择客户"
  59. br.ErrMsg = "客户参数错误"
  60. return
  61. }*/
  62. var startSize int
  63. if pageSize <= 0 {
  64. pageSize = utils.PageSize20
  65. }
  66. if currentIndex <= 0 {
  67. currentIndex = 1
  68. }
  69. startSize = paging.StartIndex(currentIndex, pageSize)
  70. var condition string
  71. var pars []interface{}
  72. if keyword != "" {
  73. condition += ` AND (real_name LIKE '%` + keyword + `%' OR mobile LIKE '%` + keyword + `%' OR email LIKE '%` + keyword + `%') `
  74. }
  75. if businessCode != "" {
  76. condition += ` AND business_code = ? `
  77. pars = append(pars, businessCode)
  78. }
  79. if etaBusinessId != 0 {
  80. condition += ` AND eta_business_id = ? `
  81. pars = append(pars, etaBusinessId)
  82. }
  83. if positionStatus > 0 {
  84. condition += ` AND position_status = ? `
  85. pars = append(pars, positionStatus)
  86. }
  87. if enabled > 0 { // 0-禁用 1-启用
  88. condition += ` AND enabled = ? `
  89. pars = append(pars, enabled)
  90. }
  91. order := ""
  92. if sortParam == "LastLoginTime" {
  93. if sortType == "desc" || sortType == "asc" {
  94. order = " last_login_time " + sortType
  95. }
  96. }
  97. total, err := models.GetUserCountByCondition(condition, pars)
  98. if err != nil {
  99. br.Msg = "获取失败"
  100. br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  101. return
  102. }
  103. list, err := models.GetUserPageListByCondition(condition, pars, order, startSize, pageSize)
  104. if err != nil {
  105. br.Msg = "获取失败"
  106. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  107. return
  108. }
  109. page := paging.GetPaging(currentIndex, pageSize, total)
  110. resp := new(models.UserListResp)
  111. userList := make([]*models.BusinessUser, 0)
  112. if len(list) == 0 {
  113. resp.List = userList
  114. resp.Paging = page
  115. br.Ret = 200
  116. br.Success = true
  117. br.Msg = "获取成功"
  118. br.Data = resp
  119. return
  120. }
  121. // 查找商户信息
  122. businessCodeStr := make([]string, 0)
  123. businessCodeMap := make(map[string]string)
  124. for _, v := range list {
  125. if _, ok := businessCodeMap[v.BusinessCode]; ok {
  126. continue
  127. }
  128. businessCodeStr = append(businessCodeStr, v.BusinessCode)
  129. }
  130. obj := new(eta_business.EtaBusiness)
  131. condition1 := " AND business_code IN (" + utils.GetOrmInReplace(len(businessCodeStr)) + ") "
  132. var pars1 []interface{}
  133. pars1 = append(pars1, businessCodeStr)
  134. businessList, err := obj.GetItemsByCondition(condition1, pars1, []string{"business_code", "business_name"}, "")
  135. if err != nil {
  136. br.Msg = "获取失败"
  137. br.ErrMsg = "获取商户信息失败,Err:" + err.Error()
  138. return
  139. }
  140. for _, v := range businessList {
  141. businessCodeMap[v.BusinessCode] = v.BusinessName
  142. }
  143. for _, v := range list {
  144. tmp := new(models.BusinessUser)
  145. if businessName, ok := businessCodeMap[v.BusinessCode]; ok {
  146. tmp.BusinessName = businessName
  147. }
  148. tmp.BusinessCode = v.BusinessCode
  149. tmp.EtaBusinessId = v.EtaBusinessId
  150. tmp.UserId = v.UserId
  151. tmp.RealName = v.RealName
  152. tmp.Mobile = v.Mobile
  153. tmp.CountryCode = v.CountryCode
  154. tmp.Email = v.Email
  155. tmp.Enabled = v.Enabled
  156. tmp.PositionStatus = v.PositionStatus
  157. tmp.Position = v.Position
  158. tmp.DepartmentName = v.DepartmentName
  159. // 判断time类型是否为零值
  160. if !v.LastLoginTime.IsZero() {
  161. tmp.LastLoginTime = v.LastLoginTime.Format(utils.FormatDateTime)
  162. }
  163. tmp.CreatedTime = v.CreatedTime.Format(utils.FormatDateTime)
  164. tmp.LastUpdatedTime = v.LastUpdatedTime.Format(utils.FormatDateTime)
  165. userList = append(userList, tmp)
  166. }
  167. resp.List = userList
  168. resp.Paging = page
  169. br.Ret = 200
  170. br.Success = true
  171. br.Msg = "获取成功"
  172. br.Data = resp
  173. }
  174. // @Title 新增客户联系人
  175. // @Description 新增客户联系人接口
  176. // @Param request body company.AddUserReq true "type json string"
  177. // @router /user/add [post]
  178. func (this *EtaBusinessUserController) AddUser() {
  179. br := new(models.BaseResponse).Init()
  180. defer func() {
  181. this.Data["json"] = br
  182. this.ServeJSON()
  183. }()
  184. sysUser := this.SysUser
  185. if sysUser == nil {
  186. br.Msg = "请登录"
  187. br.ErrMsg = "请登录,SysUser Is Empty"
  188. br.Ret = 408
  189. return
  190. }
  191. var req models.AddUserReq
  192. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  193. if err != nil {
  194. br.Msg = "参数解析异常!"
  195. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  196. return
  197. }
  198. if req.RealName == "" {
  199. br.Msg = "请填写姓名"
  200. br.IsSendEmail = false
  201. return
  202. }
  203. if req.Mobile == "" {
  204. br.Msg = "请输入手机号"
  205. br.IsSendEmail = false
  206. return
  207. }
  208. if req.EtaBusinessId == 0 {
  209. br.Msg = "请选择客户"
  210. br.IsSendEmail = false
  211. return
  212. }
  213. if req.CountryCode == "" {
  214. req.CountryCode = "86"
  215. }
  216. //空格移除
  217. req.Mobile = utils.TrimStr(req.Mobile)
  218. req.RealName = utils.TrimStr(req.RealName)
  219. //判断该手机号、邮箱是否已经添加,如果已经添加,那么就不再添加
  220. var key string
  221. if req.Mobile != "" {
  222. key = fmt.Sprintf("user:mobile:%s_%s", req.CountryCode, req.Mobile)
  223. }
  224. isHas := utils.Rc.IsExist(key)
  225. if isHas == true {
  226. br.Msg = "重复添加"
  227. return
  228. } else {
  229. //设置3分钟缓存,不允许重复添加
  230. utils.Rc.SetNX(key, 1, time.Second*300)
  231. //添加完成删除对应的缓存
  232. defer utils.Rc.Delete(key)
  233. }
  234. businessObj := new(eta_business.EtaBusiness)
  235. businessInfo, err := businessObj.GetItemById(req.EtaBusinessId)
  236. if err != nil {
  237. if err.Error() == utils.ErrNoRow() {
  238. br.Msg = "商户不存在"
  239. return
  240. }
  241. br.Msg = "客户信息有误"
  242. br.ErrMsg = "获取客户信息失败, Err: " + err.Error()
  243. return
  244. }
  245. //操作权限校验
  246. ok := eta_business2.CheckBusinessUserButton(sysUser.RoleTypeCode, businessInfo.SellerId, sysUser.AdminId)
  247. if !ok {
  248. br.Msg = "没有操作权限"
  249. br.ErrMsg = "没有操作权限"
  250. return
  251. }
  252. //systemUser models.Company.CompanyUser
  253. //var sysemUser company.CompanyUser
  254. //校验主手机号
  255. mobileItem, err := models.GetUserByMobileCountryCode(req.Mobile, req.CountryCode)
  256. if err != nil && err.Error() != utils.ErrNoRow() {
  257. br.Msg = "校验手机号有误"
  258. br.ErrMsg = "校验手机号有误, Err: " + err.Error()
  259. return
  260. }
  261. if err == nil && mobileItem.UserId > 0 {
  262. br.Msg = "手机号已存在"
  263. br.Success = true
  264. br.Data = mobileItem
  265. br.IsSendEmail = false
  266. br.Ret = 600
  267. return
  268. }
  269. err = nil
  270. user := new(models.User)
  271. user.RealName = utils.TrimStr(req.RealName)
  272. user.CountryCode = utils.TrimStr(req.CountryCode)
  273. user.Mobile = utils.TrimStr(req.Mobile)
  274. user.UserName = user.Mobile
  275. user.Position = req.Position
  276. user.PositionStatus = req.PositionStatus
  277. user.Enabled = 1
  278. user.BusinessCode = businessInfo.BusinessCode
  279. user.EtaBusinessId = businessInfo.EtaBusinessId
  280. user.DepartmentName = req.DepartmentName
  281. user.CreatedTime = time.Now()
  282. user.RegisterTime = time.Now()
  283. newId, err := models.AddUser(user)
  284. user.UserId = int(newId)
  285. if err != nil {
  286. br.Msg = "新增失败"
  287. br.ErrMsg = "新增失败,Err:" + err.Error()
  288. return
  289. }
  290. br.Ret = 200
  291. br.Success = true
  292. br.Msg = "新增成功"
  293. br.Data = newId
  294. br.IsAddLog = true
  295. }
  296. // @Title 删除客户联系人
  297. // @Description 删除客户联系人接口
  298. // @Param request body company.DeleteUserReq true "type json string"
  299. // @router /user/delete [post]
  300. func (this *EtaBusinessUserController) DeleteUser() {
  301. br := new(models.BaseResponse).Init()
  302. defer func() {
  303. this.Data["json"] = br
  304. this.ServeJSON()
  305. }()
  306. sysUser := this.SysUser
  307. if sysUser == nil {
  308. br.Msg = "请登录"
  309. br.ErrMsg = "请登录,SysUser Is Empty"
  310. br.Ret = 408
  311. return
  312. }
  313. var req models.DeleteUserReq
  314. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  315. if err != nil {
  316. br.Msg = "参数解析异常!"
  317. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  318. return
  319. }
  320. if req.UserId <= 0 {
  321. br.Msg = "参数错误!"
  322. return
  323. }
  324. //获取联系人详情
  325. userInfo, err := models.GetUserByUserId(req.UserId)
  326. if err != nil {
  327. if err.Error() == utils.ErrNoRow() {
  328. br.Msg = "用户不存在"
  329. return
  330. }
  331. br.Msg = "获取联系人异常!"
  332. br.ErrMsg = "获取联系人异常,Err:" + err.Error()
  333. return
  334. }
  335. // 查询商户关联的销售信息
  336. businessObj := new(eta_business.EtaBusiness)
  337. businessInfo, err := businessObj.GetItemByBusinessCode(userInfo.BusinessCode)
  338. if err != nil {
  339. if err.Error() == utils.ErrNoRow() {
  340. br.Msg = "商户不存在"
  341. return
  342. }
  343. br.Msg = "客户信息有误"
  344. br.ErrMsg = "获取客户信息失败, Err: " + err.Error()
  345. return
  346. }
  347. //操作权限校验
  348. ok := eta_business2.CheckBusinessUserButton(sysUser.RoleTypeCode, businessInfo.SellerId, sysUser.AdminId)
  349. if !ok {
  350. br.Msg = "删除失败,没有权限"
  351. br.ErrMsg = "删除失败,没有权限"
  352. return
  353. }
  354. err = models.DeleteUser(req.UserId)
  355. if err != nil {
  356. br.Msg = "删除失败"
  357. br.ErrMsg = "删除失败,Err:" + err.Error()
  358. return
  359. }
  360. br.Ret = 200
  361. br.Success = true
  362. br.Msg = "删除成功"
  363. br.IsAddLog = true
  364. }
  365. // @Title 编辑客户联系人
  366. // @Description 编辑客户联系人接口
  367. // @Param request body company.EditUserReq true "type json string"
  368. // @router /user/edit [post]
  369. func (this *EtaBusinessUserController) EditUser() {
  370. br := new(models.BaseResponse).Init()
  371. defer func() {
  372. this.Data["json"] = br
  373. this.ServeJSON()
  374. }()
  375. sysUser := this.SysUser
  376. if sysUser == nil {
  377. br.Msg = "请登录"
  378. br.ErrMsg = "请登录,SysUser Is Empty"
  379. br.Ret = 408
  380. return
  381. }
  382. var req models.EditUserReq
  383. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  384. if err != nil {
  385. br.Msg = "参数解析异常!"
  386. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  387. return
  388. }
  389. if req.UserId <= 0 {
  390. br.Msg = "参数错误!"
  391. return
  392. }
  393. //移除空格
  394. req.Mobile = utils.TrimStr(req.Mobile)
  395. req.RealName = utils.TrimStr(req.RealName)
  396. if req.RealName == "" {
  397. br.Msg = "请填写姓名"
  398. br.IsSendEmail = false
  399. return
  400. }
  401. if req.Mobile == "" {
  402. br.Msg = "请输入手机号"
  403. br.IsSendEmail = false
  404. return
  405. }
  406. if req.EtaBusinessId == 0 {
  407. br.Msg = "请选择客户"
  408. br.IsSendEmail = false
  409. return
  410. }
  411. if req.CountryCode == "" {
  412. req.CountryCode = "86"
  413. }
  414. //操作权限校验
  415. userInfo, err := models.GetUserByUserId(req.UserId)
  416. if err != nil {
  417. if err.Error() == utils.ErrNoRow() {
  418. br.Msg = "用户不存在"
  419. return
  420. }
  421. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  422. br.Msg = "获取信息失败"
  423. return
  424. }
  425. businessObj := new(eta_business.EtaBusiness)
  426. businessInfo, err := businessObj.GetItemById(req.EtaBusinessId)
  427. if err != nil {
  428. if err.Error() == utils.ErrNoRow() {
  429. br.Msg = "商户不存在"
  430. return
  431. }
  432. br.Msg = "客户信息有误"
  433. br.ErrMsg = "获取客户信息失败, Err: " + err.Error()
  434. return
  435. }
  436. //操作权限校验
  437. ok := eta_business2.CheckBusinessUserButton(sysUser.RoleTypeCode, businessInfo.SellerId, sysUser.AdminId)
  438. if !ok {
  439. br.Msg = "没有操作权限"
  440. br.ErrMsg = "没有操作权限"
  441. return
  442. }
  443. if req.Mobile != "" && req.Mobile != userInfo.Mobile && req.CountryCode != userInfo.CountryCode {
  444. mobileItem, e := models.GetUserByMobileCountryCode(req.Mobile, req.CountryCode)
  445. if e != nil && e.Error() != utils.ErrNoRow() {
  446. br.Msg = "校验手机号有误"
  447. br.ErrMsg = "校验手机号有误, Err: " + err.Error()
  448. return
  449. }
  450. if e == nil && mobileItem.UserId > 0 && mobileItem.UserId != req.UserId {
  451. {
  452. br.Msg = "手机号已存在"
  453. br.Success = true
  454. br.Data = mobileItem
  455. br.IsSendEmail = false
  456. br.Ret = 600
  457. return
  458. }
  459. }
  460. }
  461. //待更新字段
  462. updateCol := []string{"RealName", "Mobile", "UserName", "LastUpdatedTime", "Position", "PositionStatus", "DepartmentName", "BusinessCode", "EtaBusinessId", "BusinessCode", "CountryCode"}
  463. userInfo.RealName = req.RealName
  464. userInfo.Mobile = req.Mobile
  465. userInfo.UserName = userInfo.Mobile
  466. userInfo.LastUpdatedTime = time.Now()
  467. userInfo.Position = req.Position
  468. userInfo.DepartmentName = req.DepartmentName
  469. userInfo.BusinessCode = businessInfo.BusinessCode
  470. userInfo.EtaBusinessId = businessInfo.EtaBusinessId
  471. userInfo.CountryCode = req.CountryCode
  472. userInfo.PositionStatus = req.PositionStatus
  473. err = userInfo.Update(updateCol)
  474. if err != nil {
  475. br.Msg = "编辑失败!"
  476. br.ErrMsg = "编辑失败,Err:" + err.Error()
  477. return
  478. }
  479. br.Ret = 200
  480. br.Success = true
  481. br.Msg = "编辑成功"
  482. br.IsAddLog = true
  483. }
  484. // @Title 获取批量导入联系人数据
  485. // @Description 获取批量导入联系人数据
  486. // @Param File query file true "文件"
  487. // @Param CompanyId query file true "客户id"
  488. // @Success 200 {object} models.ImportListResp
  489. // @router /user/import/list [post]
  490. func (this *EtaBusinessUserController) ImportList() {
  491. br := new(models.BaseResponse).Init()
  492. defer func() {
  493. this.Data["json"] = br
  494. this.ServeJSON()
  495. }()
  496. sysUser := this.SysUser
  497. if sysUser == nil {
  498. br.Msg = "请重新登录"
  499. return
  500. }
  501. file, h, err := this.GetFile("File")
  502. if err != nil {
  503. br.Msg = "获取文件失败"
  504. br.ErrMsg = "获取文件失败,Err:" + err.Error()
  505. return
  506. }
  507. //todo 没有选择对应的商户所以无操作权限校验
  508. uploadDir := "static/xls"
  509. err = os.MkdirAll(uploadDir, 766)
  510. if err != nil {
  511. br.Msg = "存储目录创建失败"
  512. br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
  513. return
  514. }
  515. path := uploadDir + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + h.Filename
  516. defer file.Close()
  517. err = this.SaveToFile("File", path)
  518. if err != nil {
  519. br.Msg = "文件保存失败"
  520. br.ErrMsg = "文件保存失败,Err:" + err.Error()
  521. return
  522. }
  523. xlFile, err := xlsx.OpenFile(path)
  524. if err != nil {
  525. br.Msg = "获取失败"
  526. br.ErrMsg = "打开文件失败,Err:" + err.Error() + ";path:" + path
  527. return
  528. }
  529. existUser := make([]*models.User, 0)
  530. addUser := make([]*models.User, 0)
  531. //excel中已经存在的数据,用来判断excel中是否存在相同手机号/邮箱,避免重复提交
  532. excelData := make(map[string]string)
  533. //重复数据
  534. repeatUser := make([]*models.User, 0)
  535. // 遍历sheet页读取
  536. for _, sheet := range xlFile.Sheets {
  537. //遍历行读取
  538. maxRow := sheet.MaxRow
  539. fmt.Println("maxRow:", maxRow)
  540. fmt.Println("maxRow")
  541. for i := 0; i < maxRow; i++ {
  542. if i == 1 {
  543. row := sheet.Row(i)
  544. cells := row.Cells
  545. for k, cell := range cells {
  546. text := cell.String()
  547. if k == 0 {
  548. if text != "姓名" {
  549. br.Msg = "模板格式错误"
  550. br.ErrMsg = "模板格式错误,title:" + text
  551. return
  552. }
  553. }
  554. if k == 1 {
  555. if !strings.Contains(text, "区号") {
  556. br.Msg = "模板格式错误"
  557. br.ErrMsg = "模板格式错误,title:" + text
  558. return
  559. }
  560. }
  561. if k == 2 {
  562. if !strings.Contains(text, "手机号") {
  563. br.Msg = "模板格式错误"
  564. br.ErrMsg = "模板格式错误,title:" + text
  565. return
  566. }
  567. }
  568. if k == 3 {
  569. if !strings.Contains(text, "岗位") {
  570. br.Msg = "模板格式错误"
  571. br.ErrMsg = "模板格式错误,title:" + text
  572. return
  573. }
  574. }
  575. if k == 4 {
  576. if !strings.Contains(text, "部门") {
  577. br.Msg = "模板格式错误"
  578. br.ErrMsg = "模板格式错误,title:" + text
  579. return
  580. }
  581. }
  582. if k == 5 {
  583. if !strings.Contains(text, "客户名称") {
  584. br.Msg = "模板格式错误"
  585. br.ErrMsg = "模板格式错误,title:" + text
  586. return
  587. }
  588. }
  589. if k == 6 {
  590. if !strings.Contains(text, "社会信用码") {
  591. br.Msg = "模板格式错误"
  592. br.ErrMsg = "模板格式错误,title:" + text
  593. return
  594. }
  595. }
  596. if k == 7 {
  597. if !strings.Contains(text, "在职状态") {
  598. br.Msg = "模板格式错误"
  599. br.ErrMsg = "模板格式错误,title:" + text
  600. return
  601. }
  602. }
  603. }
  604. }
  605. if i >= 2 {
  606. row := sheet.Row(i)
  607. cells := row.Cells
  608. var userName, countryCode, mobileOne, position, departmentName, businessName, creditCode, positionStatus string
  609. for k, cell := range cells {
  610. if k == 0 {
  611. userName = cell.String()
  612. }
  613. if k == 1 {
  614. countryCode = cell.String()
  615. }
  616. if k == 2 {
  617. mobileOne = cell.String()
  618. }
  619. if k == 3 {
  620. position = cell.String()
  621. }
  622. if k == 4 {
  623. departmentName = cell.String()
  624. }
  625. if k == 5 {
  626. businessName = cell.String()
  627. }
  628. if k == 6 {
  629. creditCode = cell.String()
  630. }
  631. if k == 7 {
  632. positionStatus = cell.String()
  633. }
  634. }
  635. //移除空格
  636. mobileOne = utils.TrimStr(mobileOne)
  637. //这些字段都没有的话,系统认为excel到底了
  638. if userName == "" {
  639. utils.FileLog.Info("姓名必填")
  640. continue
  641. }
  642. //如果手机号或者邮箱都没有填写的情况下
  643. if mobileOne == "" {
  644. utils.FileLog.Info("手机号必填")
  645. continue
  646. }
  647. if countryCode == "" {
  648. utils.FileLog.Info("导入数据中存在【国际区号】为空的用户,请检查")
  649. continue
  650. }
  651. if businessName == "" && creditCode == "" {
  652. utils.FileLog.Info("导入数据中存在【姓名】和【社会信用码】都为空的用户,请检查")
  653. continue
  654. }
  655. item := new(models.User)
  656. item.CountryCode = countryCode
  657. item.RealName = userName
  658. if positionStatus == "在职" {
  659. item.PositionStatus = 1
  660. } else if positionStatus == "离职" {
  661. item.PositionStatus = 0
  662. }
  663. item.Mobile = mobileOne
  664. item.UserName = item.Mobile
  665. item.Position = position
  666. item.DepartmentName = departmentName
  667. // 查询商户信息
  668. if creditCode != "" {
  669. businessObj := new(eta_business.EtaBusiness)
  670. businessInfo := new(eta_business.EtaBusiness)
  671. businessInfo, err = businessObj.GetItemByCreditCode(creditCode)
  672. if err != nil {
  673. if err.Error() == utils.ErrNoRow() {
  674. utils.FileLog.Info("商户不存在")
  675. continue
  676. }
  677. utils.FileLog.Info("获取商户信息失败, Err: " + err.Error())
  678. continue
  679. }
  680. item.BusinessCode = businessInfo.BusinessCode
  681. }
  682. if item.BusinessCode == "" && businessName != "" {
  683. businessObj := new(eta_business.EtaBusiness)
  684. businessInfo := new(eta_business.EtaBusiness)
  685. businessInfo, err = businessObj.GetItemByBusinessName(businessName)
  686. if err != nil {
  687. if err.Error() == utils.ErrNoRow() {
  688. utils.FileLog.Info("商户不存在")
  689. continue
  690. }
  691. utils.FileLog.Info("获取商户信息失败, Err: " + err.Error())
  692. continue
  693. }
  694. item.BusinessCode = businessInfo.BusinessCode
  695. }
  696. if _, ok := excelData[item.CountryCode+"_"+item.Mobile]; ok {
  697. //将用户插入其中,然后退出当前循环,进入下一循环
  698. //repeatUser = append(repeatUser, item)
  699. continue
  700. }
  701. excelData[item.CountryCode+"_"+item.Mobile] = item.CountryCode
  702. //没问题数据
  703. existUser = append(existUser, item)
  704. }
  705. }
  706. }
  707. // 判断系统里该手机号是否已存在
  708. mobiles := make([]string, 0)
  709. for k, _ := range excelData {
  710. mobile := strings.Split(k, "_")[1]
  711. mobiles = append(mobiles, mobile)
  712. }
  713. // 查询系统里是否存在
  714. existUserMap := make(map[string]struct{})
  715. if len(mobiles) > 0 {
  716. existUsers, e := models.GetUserByMobiles(mobiles)
  717. if e != nil {
  718. br.Msg = "查询用户失败"
  719. br.ErrMsg = "查询用户失败,Err:" + e.Error()
  720. return
  721. }
  722. for _, user := range existUsers {
  723. existUserMap[user.CountryCode+"_"+user.Mobile] = struct{}{}
  724. }
  725. }
  726. for _, v := range existUser {
  727. if _, ok := existUserMap[v.CountryCode+"_"+v.Mobile]; ok {
  728. repeatUser = append(repeatUser, v)
  729. } else {
  730. addUser = append(addUser, v)
  731. }
  732. }
  733. //defer func() {
  734. // os.Remove(path)
  735. //}()
  736. br.Msg = "获取成功"
  737. br.Ret = 200
  738. br.Success = true
  739. br.Data = models.ImportListResp{
  740. ValidUser: addUser,
  741. RepeatUser: repeatUser,
  742. }
  743. }
  744. // @Title 批量导入联系人数据
  745. // @Description 批量导入联系人数据
  746. // @Param File query file true "文件"
  747. // @Param CompanyId query file true "客户id"
  748. // @Success 600 {object} []*company.CompanyUser
  749. // @Success 200 Ret=200 导入成功
  750. // @router /user/import [post]
  751. func (this *EtaBusinessUserController) Import() {
  752. br := new(models.BaseResponse).Init()
  753. defer func() {
  754. this.Data["json"] = br
  755. this.ServeJSON()
  756. }()
  757. sysUser := this.SysUser
  758. if sysUser == nil {
  759. br.Msg = "请重新登录"
  760. return
  761. }
  762. var req models.ImportUserReq
  763. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  764. if err != nil {
  765. br.Msg = "参数解析异常!"
  766. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  767. return
  768. }
  769. /*file, h, err := this.GetFile("File")
  770. if err != nil {
  771. br.Msg = "获取文件失败"
  772. br.ErrMsg = "获取文件失败,Err:" + err.Error()
  773. return
  774. }
  775. //todo 没有选择对应的商户所以无操作权限校验
  776. uploadDir := "static/xls"
  777. err = os.MkdirAll(uploadDir, 766)
  778. if err != nil {
  779. br.Msg = "存储目录创建失败"
  780. br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
  781. return
  782. }
  783. path := uploadDir + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + h.Filename
  784. defer file.Close()
  785. err = this.SaveToFile("File", path)
  786. if err != nil {
  787. br.Msg = "文件保存失败"
  788. br.ErrMsg = "文件保存失败,Err:" + err.Error()
  789. return
  790. }
  791. xlFile, err := xlsx.OpenFile(path)
  792. if err != nil {
  793. br.Msg = "获取失败"
  794. br.ErrMsg = "打开文件失败,Err:" + err.Error() + ";path:" + path
  795. return
  796. }
  797. existUser := make([]*models.User, 0)
  798. addUser := make([]*models.User, 0)
  799. //excel中已经存在的数据,用来判断excel中是否存在相同手机号/邮箱,避免重复提交
  800. excelData := make(map[string]string)
  801. // 遍历sheet页读取
  802. for _, sheet := range xlFile.Sheets {
  803. //遍历行读取
  804. maxRow := sheet.MaxRow
  805. fmt.Println("maxRow:", maxRow)
  806. fmt.Println("maxRow")
  807. for i := 0; i < maxRow; i++ {
  808. if i == 1 {
  809. row := sheet.Row(i)
  810. cells := row.Cells
  811. for k, cell := range cells {
  812. text := cell.String()
  813. if k == 0 {
  814. if text != "姓名" {
  815. br.Msg = "模板格式错误"
  816. br.ErrMsg = "模板格式错误,title:" + text
  817. return
  818. }
  819. }
  820. if k == 1 {
  821. if !strings.Contains(text, "区号") {
  822. br.Msg = "模板格式错误"
  823. br.ErrMsg = "模板格式错误,title:" + text
  824. return
  825. }
  826. }
  827. if k == 2 {
  828. if !strings.Contains(text, "手机号") {
  829. br.Msg = "模板格式错误"
  830. br.ErrMsg = "模板格式错误,title:" + text
  831. return
  832. }
  833. }
  834. if k == 3 {
  835. if !strings.Contains(text, "岗位") {
  836. br.Msg = "模板格式错误"
  837. br.ErrMsg = "模板格式错误,title:" + text
  838. return
  839. }
  840. }
  841. if k == 4 {
  842. if !strings.Contains(text, "部门") {
  843. br.Msg = "模板格式错误"
  844. br.ErrMsg = "模板格式错误,title:" + text
  845. return
  846. }
  847. }
  848. if k == 5 {
  849. if !strings.Contains(text, "客户名称") {
  850. br.Msg = "模板格式错误"
  851. br.ErrMsg = "模板格式错误,title:" + text
  852. return
  853. }
  854. }
  855. if k == 6 {
  856. if !strings.Contains(text, "社会信用码") {
  857. br.Msg = "模板格式错误"
  858. br.ErrMsg = "模板格式错误,title:" + text
  859. return
  860. }
  861. }
  862. if k == 7 {
  863. if !strings.Contains(text, "在职状态") {
  864. br.Msg = "模板格式错误"
  865. br.ErrMsg = "模板格式错误,title:" + text
  866. return
  867. }
  868. }
  869. }
  870. }
  871. if i >= 2 {
  872. row := sheet.Row(i)
  873. cells := row.Cells
  874. var userName, countryCode, mobileOne, position, departmentName, businessName, creditCode, positionStatus string
  875. for k, cell := range cells {
  876. if k == 0 {
  877. userName = cell.String()
  878. }
  879. if k == 1 {
  880. countryCode = cell.String()
  881. }
  882. if k == 2 {
  883. mobileOne = cell.String()
  884. }
  885. if k == 3 {
  886. position = cell.String()
  887. }
  888. if k == 4 {
  889. departmentName = cell.String()
  890. }
  891. if k == 5 {
  892. businessName = cell.String()
  893. }
  894. if k == 6 {
  895. creditCode = cell.String()
  896. }
  897. if k == 7 {
  898. positionStatus = cell.String()
  899. }
  900. }
  901. //移除空格
  902. mobileOne = utils.TrimStr(mobileOne)
  903. //这些字段都没有的话,系统认为excel到底了
  904. if userName == "" {
  905. utils.FileLog.Info("姓名必填")
  906. continue
  907. }
  908. //如果手机号或者邮箱都没有填写的情况下
  909. if mobileOne == "" {
  910. utils.FileLog.Info("手机号必填")
  911. continue
  912. }
  913. if countryCode == "" {
  914. utils.FileLog.Info("导入数据中存在【国际区号】为空的用户,请检查")
  915. continue
  916. }
  917. if businessName == "" && creditCode == "" {
  918. utils.FileLog.Info("导入数据中存在【姓名】和【社会信用码】都为空的用户,请检查")
  919. continue
  920. }
  921. item := new(models.User)
  922. item.CountryCode = countryCode
  923. item.RealName = userName
  924. if positionStatus == "在职" {
  925. item.PositionStatus = 1
  926. } else if positionStatus == "离职" {
  927. item.PositionStatus = 0
  928. }
  929. item.Mobile = mobileOne
  930. item.UserName = item.Mobile
  931. item.Position = position
  932. item.DepartmentName = departmentName
  933. // 查询商户信息
  934. if creditCode != "" {
  935. businessObj := new(eta_business.EtaBusiness)
  936. businessInfo := new(eta_business.EtaBusiness)
  937. businessInfo, err = businessObj.GetItemByCreditCode(creditCode)
  938. if err != nil {
  939. if err.Error() == utils.ErrNoRow() {
  940. utils.FileLog.Info("商户不存在")
  941. continue
  942. }
  943. utils.FileLog.Info("获取商户信息失败, Err: " + err.Error())
  944. continue
  945. }
  946. item.BusinessCode = businessInfo.BusinessCode
  947. item.EtaBusinessId = businessInfo.EtaBusinessId
  948. }
  949. if item.BusinessCode == "" && businessName != "" {
  950. businessObj := new(eta_business.EtaBusiness)
  951. businessInfo := new(eta_business.EtaBusiness)
  952. businessInfo, err = businessObj.GetItemByBusinessName(businessName)
  953. if err != nil {
  954. if err.Error() == utils.ErrNoRow() {
  955. utils.FileLog.Info("商户不存在")
  956. continue
  957. }
  958. utils.FileLog.Info("获取商户信息失败, Err: " + err.Error())
  959. continue
  960. }
  961. item.BusinessCode = businessInfo.BusinessCode
  962. item.EtaBusinessId = businessInfo.EtaBusinessId
  963. }
  964. if _, ok := excelData[item.CountryCode+"_"+item.Mobile]; ok {
  965. //将用户插入其中,然后退出当前循环,进入下一循环
  966. //repeatUser = append(repeatUser, item)
  967. continue
  968. }
  969. excelData[item.CountryCode+"_"+item.Mobile] = item.CountryCode
  970. //没问题数据
  971. existUser = append(existUser, item)
  972. }
  973. }
  974. }
  975. */
  976. excelUser := make([]*models.User, 0)
  977. addUser := make([]*models.User, 0)
  978. //excel中已经存在的数据,用来判断excel中是否存在相同手机号/邮箱,避免重复提交
  979. excelData := make(map[string]string)
  980. for _, v := range req.ValidUser {
  981. // 查询商户信息
  982. item := new(models.User)
  983. item.CountryCode = v.CountryCode
  984. item.RealName = v.RealName
  985. item.PositionStatus = v.PositionStatus
  986. item.Mobile = v.Mobile
  987. item.UserName = v.Mobile
  988. item.Position = v.Position
  989. item.DepartmentName = v.DepartmentName
  990. if v.BusinessCode != "" {
  991. businessObj := new(eta_business.EtaBusiness)
  992. businessInfo := new(eta_business.EtaBusiness)
  993. businessInfo, err = businessObj.GetItemByBusinessCode(v.BusinessCode)
  994. if err != nil {
  995. if err.Error() == utils.ErrNoRow() {
  996. utils.FileLog.Info("商户不存在")
  997. continue
  998. }
  999. utils.FileLog.Info("获取商户信息失败, Err: " + err.Error())
  1000. continue
  1001. }
  1002. item.BusinessCode = businessInfo.BusinessCode
  1003. item.EtaBusinessId = businessInfo.EtaBusinessId
  1004. }
  1005. if _, ok := excelData[item.CountryCode+"_"+item.Mobile]; ok {
  1006. //将用户插入其中,然后退出当前循环,进入下一循环
  1007. //repeatUser = append(repeatUser, item)
  1008. continue
  1009. }
  1010. excelData[item.CountryCode+"_"+item.Mobile] = item.CountryCode
  1011. //没问题数据
  1012. excelUser = append(excelUser, item)
  1013. }
  1014. // 判断系统里该手机号是否已存在
  1015. mobiles := make([]string, 0)
  1016. for k, _ := range excelData {
  1017. mobile := strings.Split(k, "_")[1]
  1018. mobiles = append(mobiles, mobile)
  1019. }
  1020. // 查询系统里是否存在
  1021. existUserMap := make(map[string]struct{})
  1022. if len(mobiles) > 0 {
  1023. existUsers, e := models.GetUserByMobiles(mobiles)
  1024. if e != nil {
  1025. br.Msg = "查询用户失败"
  1026. br.ErrMsg = "查询用户失败,Err:" + e.Error()
  1027. return
  1028. }
  1029. for _, user := range existUsers {
  1030. existUserMap[user.CountryCode+"_"+user.Mobile] = struct{}{}
  1031. }
  1032. }
  1033. for _, v := range excelUser {
  1034. if _, ok := existUserMap[v.CountryCode+"_"+v.Mobile]; !ok {
  1035. addUser = append(addUser, v)
  1036. }
  1037. }
  1038. fmt.Println("表格中用户与系统中存在用户没有冲突")
  1039. //如果表格中用户与系统中存在用户 没有冲突,那么继续执行
  1040. for _, user := range addUser {
  1041. if user.RealName != "" && user.Mobile != "" {
  1042. userData := new(models.User)
  1043. userData.RealName = user.RealName
  1044. userData.UserName = user.Mobile
  1045. userData.Mobile = user.Mobile
  1046. userData.CountryCode = user.CountryCode
  1047. userData.Email = user.Email
  1048. userData.Position = user.Position
  1049. userData.PositionStatus = user.PositionStatus
  1050. userData.BusinessCode = user.BusinessCode
  1051. userData.EtaBusinessId = user.EtaBusinessId
  1052. userData.DepartmentName = user.DepartmentName
  1053. userData.CountryCode = user.CountryCode
  1054. userData.CreatedTime = time.Now()
  1055. userData.LastUpdatedTime = time.Now()
  1056. userData.Enabled = 1
  1057. //判断该手机号、邮箱是否已经添加,如果已经添加,那么就不再添加
  1058. var key string
  1059. key = "user:mobile:" + userData.Mobile
  1060. isHas := utils.Rc.IsExist(key)
  1061. if isHas == false {
  1062. newId, err := models.AddUser(userData)
  1063. userData.UserId = int(newId)
  1064. if err != nil {
  1065. br.Msg = "导入失败"
  1066. br.ErrMsg = "导入失败,Err:" + err.Error()
  1067. return
  1068. }
  1069. }
  1070. }
  1071. }
  1072. /*defer func() {
  1073. os.Remove(path)
  1074. }()*/
  1075. br.Msg = "导入成功"
  1076. br.Ret = 200
  1077. br.Success = true
  1078. }
  1079. // @Title 移动用户至新的商户下
  1080. // @Description 移动用户至新的商户下
  1081. // @Param request body company.EditUserReq true "type json string"
  1082. // @router /user/changeBusiness [post]
  1083. func (this *EtaBusinessUserController) ChangeUserBusiness() {
  1084. br := new(models.BaseResponse).Init()
  1085. defer func() {
  1086. this.Data["json"] = br
  1087. this.ServeJSON()
  1088. }()
  1089. sysUser := this.SysUser
  1090. if sysUser == nil {
  1091. br.Msg = "请登录"
  1092. br.ErrMsg = "请登录,SysUser Is Empty"
  1093. br.Ret = 408
  1094. return
  1095. }
  1096. var req models.ChangeUserBusinessReq
  1097. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1098. if err != nil {
  1099. br.Msg = "参数解析异常!"
  1100. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1101. return
  1102. }
  1103. if req.UserId <= 0 {
  1104. br.Msg = "参数错误!"
  1105. return
  1106. }
  1107. if req.EtaBusinessId == 0 {
  1108. br.Msg = "请选择商户"
  1109. br.IsSendEmail = false
  1110. return
  1111. }
  1112. //操作权限校验
  1113. userInfo, err := models.GetUserByUserId(req.UserId)
  1114. if err != nil {
  1115. if err.Error() == utils.ErrNoRow() {
  1116. br.Msg = "用户不存在"
  1117. return
  1118. }
  1119. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1120. br.Msg = "获取信息失败"
  1121. return
  1122. }
  1123. if userInfo.EtaBusinessId == req.EtaBusinessId {
  1124. br.Msg = "用户已经在该商户下"
  1125. return
  1126. }
  1127. businessObj := new(eta_business.EtaBusiness)
  1128. businessInfo, err := businessObj.GetItemById(req.EtaBusinessId)
  1129. if err != nil {
  1130. if err.Error() == utils.ErrNoRow() {
  1131. br.Msg = "商户不存在"
  1132. return
  1133. }
  1134. br.Msg = "商户信息有误"
  1135. br.ErrMsg = "获取商户信息失败, Err: " + err.Error()
  1136. return
  1137. }
  1138. //待更新字段
  1139. updateCol := []string{"LastUpdatedTime", "EtaBusinessId", "BusinessCode"}
  1140. userInfo.LastUpdatedTime = time.Now()
  1141. userInfo.EtaBusinessId = businessInfo.EtaBusinessId
  1142. userInfo.BusinessCode = businessInfo.BusinessCode
  1143. err = userInfo.Update(updateCol)
  1144. if err != nil {
  1145. br.Msg = "操作失败!"
  1146. br.ErrMsg = "操作失败,Err:" + err.Error()
  1147. return
  1148. }
  1149. br.Ret = 200
  1150. br.Success = true
  1151. br.Msg = "操作成功"
  1152. br.IsAddLog = true
  1153. }
  1154. // @Title 开启/禁用系统用户
  1155. // @Description 开启/禁用系统用户接口
  1156. // @Param request body system.SysuserEditReq true "type json string"
  1157. // @Success 200 操作成功
  1158. // @router /user/editEnabled [post]
  1159. func (this *EtaBusinessUserController) EditEnabled() {
  1160. br := new(models.BaseResponse).Init()
  1161. defer func() {
  1162. this.Data["json"] = br
  1163. this.ServeJSON()
  1164. }()
  1165. var req models.UserEditEnabledReq
  1166. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1167. if err != nil {
  1168. br.Msg = "参数解析异常!"
  1169. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1170. return
  1171. }
  1172. if req.UserId <= 0 {
  1173. br.Msg = "请选择用户"
  1174. return
  1175. }
  1176. //操作权限校验
  1177. userInfo, err := models.GetUserByUserId(req.UserId)
  1178. if err != nil {
  1179. if err.Error() == utils.ErrNoRow() {
  1180. br.Msg = "用户不存在"
  1181. return
  1182. }
  1183. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1184. br.Msg = "获取信息失败"
  1185. return
  1186. }
  1187. if req.Enabled != 0 && req.Enabled != 1 {
  1188. br.Msg = "参数错误"
  1189. return
  1190. }
  1191. //待更新字段
  1192. updateCol := []string{"LastUpdatedTime", "Enabled"}
  1193. userInfo.LastUpdatedTime = time.Now()
  1194. userInfo.Enabled = req.Enabled
  1195. err = userInfo.Update(updateCol)
  1196. if err != nil {
  1197. br.Msg = "操作失败!"
  1198. br.ErrMsg = "操作失败,Err:" + err.Error()
  1199. return
  1200. }
  1201. //todo 用户被禁用的情况下,需要将他对应的token给过期
  1202. /*if adminItem.Enabled == 1 && req.Enabled == 0 {
  1203. logOutSystemUser(adminItem.AdminId)
  1204. }*/
  1205. br.Ret = 200
  1206. br.Success = true
  1207. br.IsAddLog = true
  1208. br.Msg = "操作成功"
  1209. }
  1210. // AreaCodeList
  1211. // @Title 手机号区号列表
  1212. // @Description 手机号区号列表
  1213. // @Success 200 Ret=200 获取成功
  1214. // @router /area_code/list [get]
  1215. func (this *EtaBusinessUserController) AreaCodeList() {
  1216. br := new(models.BaseResponse).Init()
  1217. defer func() {
  1218. if br.ErrMsg == "" {
  1219. br.IsSendEmail = false
  1220. }
  1221. this.Data["json"] = br
  1222. this.ServeJSON()
  1223. }()
  1224. type AreaCodeListResp struct {
  1225. Name string `description:"地区"`
  1226. Value string `description:"区号"`
  1227. }
  1228. resp := make([]AreaCodeListResp, 0)
  1229. confAuth, e := system.GetCrmConfigDetailByCode(system.ConfAreaCodeListKey)
  1230. if e != nil {
  1231. br.Msg = "获取失败"
  1232. br.ErrMsg = "获取手机号区号配置失败, Err: " + e.Error()
  1233. return
  1234. }
  1235. if confAuth.ConfigValue == "" {
  1236. br.Msg = "获取失败"
  1237. br.ErrMsg = "手机号区号配置为空"
  1238. return
  1239. }
  1240. if e := json.Unmarshal([]byte(confAuth.ConfigValue), &resp); e != nil {
  1241. br.Msg = "获取失败"
  1242. br.ErrMsg = "手机号区号配置有误"
  1243. return
  1244. }
  1245. br.Data = resp
  1246. br.Ret = 200
  1247. br.Success = true
  1248. br.Msg = "获取成功"
  1249. }
  1250. // TemplateDownload
  1251. // @Title 下载模板
  1252. // @Description 下载模板
  1253. // @Success 200 {object} models.EdbdataClassifyResp
  1254. // @Param Source query int false "来源:1:模板1;2:模板2"
  1255. // @router /user/template [get]
  1256. func (this *EtaBusinessUserController) TemplateDownload() {
  1257. br := new(models.BaseResponse).Init()
  1258. defer func() {
  1259. this.Data["json"] = br
  1260. this.ServeJSON()
  1261. }()
  1262. this.Ctx.Output.Download("./static/template/用户导入模版.xlsx", "用户导入模版.xlsx")
  1263. //this.Ctx.Output.Download("./static/数据导入模板.xlsx", "数据导入模板.xlsx")
  1264. br.Ret = 200
  1265. br.Success = true
  1266. br.Msg = "下载成功"
  1267. }