user.go 35 KB

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