members_controller.go 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. package members
  2. import (
  3. base_ctl "SCRM/controllers"
  4. "SCRM/enums"
  5. "SCRM/models"
  6. "SCRM/service/member_service"
  7. "SCRM/utils"
  8. "encoding/json"
  9. "fmt"
  10. "reflect"
  11. "time"
  12. "github.com/astaxie/beego"
  13. )
  14. func MemberCtlRegistRouters() {
  15. beego.Router("/api/members", &MembersAPIController{}, "get:GetMembers")
  16. beego.Router("/api/members/all", &MembersAPIController{}, "get:GetAllMembers")
  17. beego.Router("/api/member/create", &MembersAPIController{}, "Post:CreateMember")
  18. beego.Router("/api/member/edit", &MembersAPIController{}, "Put:EditMember")
  19. beego.Router("/api/members/delete", &MembersAPIController{}, "Delete:DeleteMembers")
  20. }
  21. type MembersAPIController struct {
  22. base_ctl.BaseAuthAPIController
  23. }
  24. func (c *MembersAPIController) GetMembers() {
  25. page, _ := c.GetInt64("page", 1)
  26. limit, _ := c.GetInt64("limit", 10)
  27. startTime := c.GetString("start_time", "")
  28. endTime := c.GetString("end_time", "")
  29. searchKey := c.GetString("search", "")
  30. level, _ := c.GetInt64("level", 0)
  31. source, _ := c.GetInt64("source", 0)
  32. tag, _ := c.GetInt64("tag", 0)
  33. init, _ := c.GetInt64("init", 0)
  34. fmt.Println("level", level, "source", source)
  35. if page <= 0 {
  36. page = 1
  37. }
  38. if limit <= 0 {
  39. limit = 10
  40. }
  41. adminUserInfo := c.GetAdminUserInfo()
  42. timeLayout := "2006-01-02 15:04:05"
  43. var isStartTime bool
  44. var theStartTIme int64
  45. if len(startTime) > 0 {
  46. theTime, err := utils.ParseTimeStringToTime(timeLayout, startTime+" 00:00:00")
  47. if err != nil {
  48. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "开始时间错误")
  49. return
  50. }
  51. isStartTime = true
  52. theStartTIme = theTime.Unix()
  53. }
  54. var isEndTime bool
  55. var theEndtTIme int64
  56. if len(endTime) > 0 {
  57. theTime, err := utils.ParseTimeStringToTime(timeLayout, endTime+" 23:59:59")
  58. if err != nil {
  59. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "结束时间错误")
  60. return
  61. }
  62. isEndTime = true
  63. theEndtTIme = theTime.Unix()
  64. }
  65. members, total, err := member_service.GetMemberList(adminUserInfo.CurrentOrgId, page, limit, level, source, tag, theStartTIme, theEndtTIme, isStartTime, isEndTime, searchKey)
  66. if err != nil {
  67. c.ServeFailJsonSend(enums.ErrorCodeDataException, "获取会员列表失败")
  68. return
  69. }
  70. returnData := make(map[string]interface{}, 0)
  71. if init == 1 {
  72. cards, err := member_service.GetCardList(adminUserInfo.CurrentOrgId)
  73. if err != nil {
  74. c.ServeFailJsonSend(enums.ErrorCodeDataException, "获取会员卡列表失败")
  75. return
  76. }
  77. returnData["cards"] = cards
  78. tags, err := member_service.GetTagList(adminUserInfo.CurrentOrgId)
  79. if err != nil {
  80. c.ServeFailJsonSend(enums.ErrorCodeDataException, "获取标签列表失败")
  81. return
  82. }
  83. returnData["tags"] = tags
  84. illness, err := member_service.GetIllnessList()
  85. if err != nil {
  86. c.ServeFailJsonSend(enums.ErrorCodeDataException, "获取病种列表失败")
  87. return
  88. }
  89. returnData["illness"] = illness
  90. }
  91. returnData["members"] = members
  92. returnData["total"] = total
  93. c.ServeSuccessJSON(returnData)
  94. return
  95. }
  96. func (c *MembersAPIController) GetAllMembers() {
  97. adminUserInfo := c.GetAdminUserInfo()
  98. members, err := member_service.GetAllMemberList(adminUserInfo.CurrentOrgId)
  99. fmt.Println("members是什么", members)
  100. fmt.Println("资讯管理错误是什么", err)
  101. if err != nil {
  102. c.ServeFailJsonSend(enums.ErrorCodeDataException, "获取列表失败")
  103. return
  104. }
  105. returnData := make(map[string]interface{}, 0)
  106. returnData["members"] = members
  107. c.ServeSuccessJSON(returnData)
  108. return
  109. }
  110. func (c *MembersAPIController) CreateMember() {
  111. adminUserInfo := c.GetAdminUserInfo()
  112. timeNow := time.Now().Unix()
  113. dataBody := make(map[string]interface{}, 0)
  114. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  115. if err != nil {
  116. utils.ErrorLog(err.Error())
  117. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数错误")
  118. return
  119. }
  120. var member member_service.Members
  121. if dataBody["name"] == nil || reflect.TypeOf(dataBody["name"]).String() != "string" {
  122. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "缺少参数:姓名")
  123. return
  124. }
  125. name, _ := dataBody["name"].(string)
  126. if len(name) == 0 {
  127. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "姓名不能为空")
  128. return
  129. }
  130. member.Name = name
  131. if dataBody["mobile"] == nil || reflect.TypeOf(dataBody["mobile"]).String() != "string" {
  132. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "缺少参数:手机号")
  133. return
  134. }
  135. mobile, _ := dataBody["mobile"].(string)
  136. if len(mobile) == 0 {
  137. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "手机号不能为空")
  138. return
  139. }
  140. if !utils.CheckMobile(mobile) {
  141. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "手机号格式不正确")
  142. return
  143. }
  144. member.Mobile = mobile
  145. if dataBody["gender"] == nil || reflect.TypeOf(dataBody["gender"]).String() != "float64" {
  146. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "缺少参数:性别")
  147. return
  148. }
  149. gender := int64(dataBody["gender"].(float64))
  150. if gender != 1 && gender != 2 {
  151. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "性别选择不正确")
  152. return
  153. }
  154. member.Gender = gender
  155. if dataBody["birthday"] == nil || reflect.TypeOf(dataBody["birthday"]).String() != "string" {
  156. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "缺少参数:生日")
  157. return
  158. }
  159. birthday, _ := dataBody["birthday"].(string)
  160. if len(birthday) == 0 {
  161. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "生日格式不正确")
  162. return
  163. }
  164. timeLayout := "2006-01-02 15:04:05"
  165. theTime, err := utils.ParseTimeStringToTime(timeLayout, birthday+" 00:00:00")
  166. if err != nil {
  167. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "生日格式不正确")
  168. return
  169. }
  170. member.Birthday = theTime.Unix()
  171. if dataBody["province_id"] == nil || reflect.TypeOf(dataBody["province_id"]).String() != "float64" {
  172. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "缺少参数:地区(省)")
  173. return
  174. }
  175. provinceID := int64(dataBody["province_id"].(float64))
  176. if provinceID <= 0 {
  177. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "请选择地区")
  178. return
  179. }
  180. member.ProvinceId = provinceID
  181. if dataBody["city_id"] == nil || reflect.TypeOf(dataBody["city_id"]).String() != "float64" {
  182. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "缺少参数:地区(市)")
  183. return
  184. }
  185. cityID := int64(dataBody["city_id"].(float64))
  186. if cityID <= 0 {
  187. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "请选择地区")
  188. return
  189. }
  190. member.CityId = cityID
  191. if dataBody["district_id"] == nil || reflect.TypeOf(dataBody["district_id"]).String() != "float64" {
  192. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "缺少参数:地区(区/县)")
  193. return
  194. }
  195. districtID := int64(dataBody["district_id"].(float64))
  196. if districtID <= 0 {
  197. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "请选择地区")
  198. return
  199. }
  200. member.DistrictId = districtID
  201. if dataBody["illness"] == nil || reflect.TypeOf(dataBody["illness"]).String() != "[]interface {}" {
  202. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "缺少参数:病种")
  203. return
  204. }
  205. illnessInters := dataBody["illness"].([]interface{})
  206. if len(illnessInters) <= 0 {
  207. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "请选择病种")
  208. return
  209. }
  210. member.Illness = make([]*member_service.CustomerIllness, 0)
  211. for _, illnessInter := range illnessInters {
  212. id := int64(illnessInter.(float64))
  213. var illItem member_service.CustomerIllness
  214. illItem.UserOrgId = adminUserInfo.CurrentOrgId
  215. illItem.IllnessId = id
  216. illItem.Status = 1
  217. illItem.UpdatedTime = timeNow
  218. illItem.CreatedTime = timeNow
  219. member.Illness = append(member.Illness, &illItem)
  220. }
  221. if dataBody["ill_date"] == nil || reflect.TypeOf(dataBody["ill_date"]).String() != "string" {
  222. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "缺少参数:患病时间")
  223. return
  224. }
  225. illDate, _ := dataBody["ill_date"].(string)
  226. if len(illDate) == 0 {
  227. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "患病时间格式不正确")
  228. return
  229. }
  230. illDateTime, err := utils.ParseTimeStringToTime(timeLayout, illDate+" 00:00:00")
  231. if err != nil {
  232. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "患病时间格式不正确")
  233. return
  234. }
  235. member.IllDate = illDateTime.Unix()
  236. if dataBody["treat_type"] == nil || reflect.TypeOf(dataBody["treat_type"]).String() != "float64" {
  237. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "缺少参数:治疗方式")
  238. return
  239. }
  240. treatType := int64(dataBody["treat_type"].(float64))
  241. if treatType <= 0 {
  242. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "请选择治疗方式")
  243. return
  244. }
  245. member.TreatType = treatType
  246. if dataBody["tags"] != nil && reflect.TypeOf(dataBody["tags"]).String() == "[]interface {}" {
  247. tagsInters := dataBody["tags"].([]interface{})
  248. if len(tagsInters) > 0 {
  249. member.UserTags = make([]*models.UserTagLinks, 0)
  250. for _, tagsInter := range tagsInters {
  251. id := int64(tagsInter.(float64))
  252. var tagItem models.UserTagLinks
  253. tagItem.TagId = id
  254. tagItem.UserOrgId = adminUserInfo.CurrentOrgId
  255. tagItem.Status = 1
  256. tagItem.UpdatedTime = timeNow
  257. tagItem.CreatedTime = timeNow
  258. member.UserTags = append(member.UserTags, &tagItem)
  259. }
  260. }
  261. }
  262. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  263. remark, _ := dataBody["remark"].(string)
  264. if len(remark) > 0 {
  265. member.Remark = remark
  266. }
  267. }
  268. if dataBody["avatar"] != nil && reflect.TypeOf(dataBody["avatar"]).String() == "string" {
  269. avatar, _ := dataBody["avatar"].(string)
  270. if len(avatar) > 0 {
  271. member.Avatar = avatar
  272. }
  273. }
  274. customer, err := member_service.GetCustomerByMobile(adminUserInfo.CurrentOrgId, member.Mobile)
  275. if err != nil {
  276. c.ServeFailJsonSend(enums.ErrorCodeDBCreate, "添加会员失败:("+err.Error()+")")
  277. return
  278. }
  279. if customer != nil {
  280. c.ServeFailJsonSend(enums.ErrorCodeDBCreate, "添加会员失败:(已经存在该手机号的客户)")
  281. return
  282. }
  283. member.UserOrgId = adminUserInfo.CurrentOrgId
  284. member.Status = 1
  285. member.CreatedTime = timeNow
  286. member.UpdatedTime = timeNow
  287. member.Sources = 7
  288. user, err := member_service.GetUserByMobile(member.Mobile)
  289. if err != nil {
  290. c.ServeFailJsonSend(enums.ErrorCodeDBCreate, "添加会员失败:("+err.Error()+")")
  291. return
  292. }
  293. if user != nil {
  294. member.UserId = user.ID
  295. err = member_service.CreateMember(&member)
  296. if err != nil {
  297. c.ServeFailJsonSend(enums.ErrorCodeDBCreate, "添加会员失败:("+err.Error()+")")
  298. return
  299. }
  300. } else {
  301. var userData models.User
  302. userData.Avatar = member.Avatar
  303. userData.AvatarThumb = member.Avatar
  304. userData.Username = member.Name
  305. userData.Remarkname = member.Name
  306. userData.Mobile = member.Mobile
  307. userData.Gender = member.Gender
  308. userData.ProvinceId = member.ProvinceId
  309. userData.CityId = member.CityId
  310. userData.Address = member.Address
  311. userData.Birthday = member.Birthday
  312. userData.TreatType = member.TreatType
  313. userData.Relationship = member.Relationship
  314. userData.IllnessId = member.Illness[0].IllnessId
  315. userData.Sources = member.Sources
  316. userData.Status = 1
  317. userData.CreatedTime = timeNow
  318. userData.UpdatedTime = timeNow
  319. err = member_service.CreateMemberWithUser(&member, &userData)
  320. if err != nil {
  321. c.ServeFailJsonSend(enums.ErrorCodeDBCreate, "添加会员失败:("+err.Error()+")")
  322. return
  323. }
  324. }
  325. returnData := make(map[string]interface{}, 0)
  326. returnData["member"] = member
  327. c.ServeSuccessJSON(returnData)
  328. return
  329. }
  330. func (c *MembersAPIController) EditMember() {
  331. id, _ := c.GetInt64("id", 0)
  332. if id <= 0 {
  333. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数错误:id")
  334. return
  335. }
  336. adminUserInfo := c.GetAdminUserInfo()
  337. member, err := member_service.GetOnlyMemberByID(adminUserInfo.CurrentOrgId, id)
  338. if err != nil {
  339. c.ServeFailJsonSend(enums.ErrorCodeDBUpdate, "编辑会员失败:("+err.Error()+")")
  340. return
  341. }
  342. if member == nil {
  343. c.ServeFailJsonSend(enums.ErrorCodeDBUpdate, "编辑会员失败:(会员记录不存在)")
  344. return
  345. }
  346. timeNow := time.Now().Unix()
  347. dataBody := make(map[string]interface{}, 0)
  348. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  349. if err != nil {
  350. utils.ErrorLog(err.Error())
  351. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数错误")
  352. return
  353. }
  354. if dataBody["name"] == nil || reflect.TypeOf(dataBody["name"]).String() != "string" {
  355. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "缺少参数:姓名")
  356. return
  357. }
  358. name, _ := dataBody["name"].(string)
  359. if len(name) == 0 {
  360. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "姓名不能为空")
  361. return
  362. }
  363. member.Name = name
  364. if dataBody["mobile"] == nil || reflect.TypeOf(dataBody["mobile"]).String() != "string" {
  365. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "缺少参数:手机号")
  366. return
  367. }
  368. mobile, _ := dataBody["mobile"].(string)
  369. if len(mobile) == 0 {
  370. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "手机号不能为空")
  371. return
  372. }
  373. if !utils.CheckMobile(mobile) {
  374. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "手机号格式不正确")
  375. return
  376. }
  377. changeMobile := true
  378. if member.Mobile == mobile {
  379. changeMobile = false
  380. }
  381. member.Mobile = mobile
  382. if dataBody["gender"] == nil || reflect.TypeOf(dataBody["gender"]).String() != "float64" {
  383. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "缺少参数:性别")
  384. return
  385. }
  386. gender := int64(dataBody["gender"].(float64))
  387. if gender != 1 && gender != 2 {
  388. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "性别选择不正确")
  389. return
  390. }
  391. member.Gender = gender
  392. if dataBody["birthday"] == nil || reflect.TypeOf(dataBody["birthday"]).String() != "string" {
  393. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "缺少参数:生日")
  394. return
  395. }
  396. birthday, _ := dataBody["birthday"].(string)
  397. if len(birthday) == 0 {
  398. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "生日格式不正确")
  399. return
  400. }
  401. timeLayout := "2006-01-02 15:04:05"
  402. theTime, err := utils.ParseTimeStringToTime(timeLayout, birthday+" 00:00:00")
  403. if err != nil {
  404. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "生日格式不正确")
  405. return
  406. }
  407. member.Birthday = theTime.Unix()
  408. if dataBody["province_id"] == nil || reflect.TypeOf(dataBody["province_id"]).String() != "float64" {
  409. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "缺少参数:地区(省)")
  410. return
  411. }
  412. provinceID := int64(dataBody["province_id"].(float64))
  413. if provinceID <= 0 {
  414. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "请选择地区")
  415. return
  416. }
  417. member.ProvinceId = provinceID
  418. if dataBody["city_id"] == nil || reflect.TypeOf(dataBody["city_id"]).String() != "float64" {
  419. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "缺少参数:地区(市)")
  420. return
  421. }
  422. cityID := int64(dataBody["city_id"].(float64))
  423. if cityID <= 0 {
  424. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "请选择地区")
  425. return
  426. }
  427. member.CityId = cityID
  428. if dataBody["district_id"] == nil || reflect.TypeOf(dataBody["district_id"]).String() != "float64" {
  429. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "缺少参数:地区(区/县)")
  430. return
  431. }
  432. districtID := int64(dataBody["district_id"].(float64))
  433. if districtID <= 0 {
  434. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "请选择地区")
  435. return
  436. }
  437. member.DistrictId = districtID
  438. if dataBody["illness"] == nil || reflect.TypeOf(dataBody["illness"]).String() != "[]interface {}" {
  439. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "缺少参数:病种")
  440. return
  441. }
  442. illnessInters := dataBody["illness"].([]interface{})
  443. if len(illnessInters) <= 0 {
  444. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "请选择病种")
  445. return
  446. }
  447. member.Illness = make([]*member_service.CustomerIllness, 0)
  448. illnessIDS := make([]int64, 0)
  449. illnessIDMap := make(map[int64]int64, 0)
  450. for _, illnessInter := range illnessInters {
  451. id := int64(illnessInter.(float64))
  452. illnessIDS = append(illnessIDS, id)
  453. illnessIDMap[id] = id
  454. }
  455. allIllness, err := member_service.GetMemberAllIllness(adminUserInfo.CurrentOrgId, member.ID)
  456. if err != nil {
  457. c.ServeFailJsonSend(enums.ErrorCodeDBUpdate, "编辑会员失败:("+err.Error()+")")
  458. return
  459. }
  460. oldIllIDMap := make(map[int64]int64, 0)
  461. for _, illItem := range allIllness {
  462. item := *illItem
  463. item.Status = 1
  464. if _, exist := illnessIDMap[item.IllnessId]; !exist {
  465. item.Status = 0
  466. item.UpdatedTime = timeNow
  467. }
  468. member.Illness = append(member.Illness, &item)
  469. oldIllIDMap[item.IllnessId] = item.IllnessId
  470. }
  471. for _, id := range illnessIDMap {
  472. if _, exist := oldIllIDMap[id]; exist {
  473. continue
  474. }
  475. var illItem member_service.CustomerIllness
  476. illItem.UserOrgId = adminUserInfo.CurrentOrgId
  477. illItem.IllnessId = id
  478. illItem.Status = 1
  479. illItem.UpdatedTime = timeNow
  480. illItem.CreatedTime = timeNow
  481. member.Illness = append(member.Illness, &illItem)
  482. }
  483. if dataBody["ill_date"] == nil || reflect.TypeOf(dataBody["ill_date"]).String() != "string" {
  484. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "缺少参数:患病时间")
  485. return
  486. }
  487. illDate, _ := dataBody["ill_date"].(string)
  488. if len(illDate) == 0 {
  489. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "患病时间格式不正确")
  490. return
  491. }
  492. illDateTime, err := utils.ParseTimeStringToTime(timeLayout, illDate+" 00:00:00")
  493. if err != nil {
  494. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "患病时间格式不正确")
  495. return
  496. }
  497. member.IllDate = illDateTime.Unix()
  498. if dataBody["treat_type"] == nil || reflect.TypeOf(dataBody["treat_type"]).String() != "float64" {
  499. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "缺少参数:治疗方式")
  500. return
  501. }
  502. treatType := int64(dataBody["treat_type"].(float64))
  503. if treatType <= 0 {
  504. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "请选择治疗方式")
  505. return
  506. }
  507. member.TreatType = treatType
  508. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  509. remark, _ := dataBody["remark"].(string)
  510. if len(remark) > 0 {
  511. member.Remark = remark
  512. }
  513. }
  514. if dataBody["avatar"] != nil && reflect.TypeOf(dataBody["avatar"]).String() == "string" {
  515. avatar, _ := dataBody["avatar"].(string)
  516. if len(avatar) > 0 {
  517. member.Avatar = avatar
  518. }
  519. }
  520. if changeMobile {
  521. customer, err := member_service.GetCustomerByMobile(adminUserInfo.CurrentOrgId, member.Mobile)
  522. if err != nil {
  523. c.ServeFailJsonSend(enums.ErrorCodeDBUpdate, "编辑会员失败:("+err.Error()+")")
  524. return
  525. }
  526. if customer != nil && customer.ID != member.ID {
  527. c.ServeFailJsonSend(enums.ErrorCodeDBUpdate, "编辑会员失败:(已经存在该手机号的客户)")
  528. return
  529. }
  530. }
  531. member.UpdatedTime = timeNow
  532. err = member_service.EditMember(member)
  533. if err != nil {
  534. c.ServeFailJsonSend(enums.ErrorCodeDBUpdate, "编辑会员失败:("+err.Error()+")")
  535. return
  536. }
  537. illness := member.Illness
  538. member.Illness = make([]*member_service.CustomerIllness, 0)
  539. for _, ill := range illness {
  540. illItem := *ill
  541. if illItem.Status == 0 {
  542. continue
  543. }
  544. member.Illness = append(member.Illness, &illItem)
  545. }
  546. returnData := make(map[string]interface{}, 0)
  547. returnData["member"] = member
  548. c.ServeSuccessJSON(returnData)
  549. return
  550. }
  551. func (c *MembersAPIController) DeleteMembers() {
  552. adminUserInfo := c.GetAdminUserInfo()
  553. dataBody := make(map[string]interface{}, 0)
  554. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  555. if err != nil {
  556. utils.ErrorLog(err.Error())
  557. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数错误")
  558. return
  559. }
  560. idsInters := dataBody["ids"].([]interface{})
  561. if len(idsInters) == 0 {
  562. if err != nil {
  563. c.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除会员失败:(没有选择会员)")
  564. return
  565. }
  566. }
  567. ids := make([]int64, 0)
  568. for _, idsInter := range idsInters {
  569. id := int64(idsInter.(float64))
  570. ids = append(ids, id)
  571. }
  572. err = member_service.DeleteMembers(adminUserInfo.CurrentOrgId, ids)
  573. if err != nil {
  574. c.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除会员失败:("+err.Error()+")")
  575. return
  576. }
  577. returnData := make(map[string]interface{}, 0)
  578. returnData["msg"] = "ok"
  579. c.ServeSuccessJSON(returnData)
  580. return
  581. }