user.go 37 KB

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