login_controller.go 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. package login
  2. import (
  3. "Kya_New/controllers"
  4. "Kya_New/enums"
  5. "Kya_New/models"
  6. "Kya_New/service/login_service"
  7. "Kya_New/service/patient_service"
  8. "Kya_New/sms_service"
  9. "Kya_New/utils"
  10. "encoding/json"
  11. "fmt"
  12. "github.com/astaxie/beego"
  13. "github.com/jinzhu/gorm"
  14. "strconv"
  15. "strings"
  16. "time"
  17. )
  18. func LoginRouter() {
  19. beego.Router("/api/qiniu/uptoken", &LoginManagement{}, "Get:GetQNUpToken")
  20. beego.Router("/api/site/gettologin", &LoginManagement{}, "Post:GetToLogin")
  21. beego.Router("/api/password/code", &LoginManagement{}, "Post:CodeOfModifyPwd")
  22. beego.Router("/api/save/register", &LoginManagement{}, "Post:SaveRegisterData")
  23. beego.Router("/api/login/getallprovince", &LoginManagement{}, "Get:GetAllProvince")
  24. beego.Router("/api/login/nopasslogin", &LoginManagement{}, "Get:NoPassLogin")
  25. beego.Router("/api/login/getcode", &LoginManagement{}, "Post:GetCode")
  26. beego.Router("/api/login/nextstep", &LoginManagement{}, "Get:NextStep")
  27. beego.Router("/api/login/accomplish", &LoginManagement{}, "Post:Accomplish")
  28. beego.Router("/api/login/getallorgname", &LoginManagement{}, "Get:GetAllOrgName")
  29. beego.Router("/api/login/getcitybyid", &LoginManagement{}, "Get:GetCityById")
  30. beego.Router("/api/login/getallorgtype", &LoginManagement{}, "Get:GetAllOrgType")
  31. beego.Router("/api/login/saveorginformation", &LoginManagement{}, "Post:SaveOrginInformation")
  32. beego.Router("/api/patient/getneratedialysisno", &LoginManagement{}, "Get:GetneratedDialysisNo")
  33. beego.Router("/api/login/getblooddialysispatient", &LoginManagement{}, "Get:GetBloodDialysisPatient")
  34. beego.Router("/api/site/getdoctoradvice", &LoginManagement{}, "Get:GetDoctorAdvice")
  35. beego.Router("/api/site/savesearch", &LoginManagement{}, "Get:SaveSearch")
  36. beego.Router("/api/site/toseacherdoctoradvice", &LoginManagement{}, "Get:ToSeacherDoctorAdvice")
  37. beego.Router("/api/site/deleteDoctorAdvice", &LoginManagement{}, "Get:DeleteDoctorAdvice")
  38. }
  39. type LoginManagement struct {
  40. controllers.BaseAPIController
  41. }
  42. func (this *LoginManagement) GetQNUpToken() {
  43. redisClient := login_service.RedisClient()
  44. fmt.Println("redisClient", redisClient)
  45. defer redisClient.Close()
  46. token, err := redisClient.Get("qn_token").Result()
  47. fmt.Println("token是什么", token)
  48. fmt.Println("错误", err)
  49. fmt.Println("token", token)
  50. if err != nil {
  51. defer fmt.Println(err)
  52. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGetQiniuUpToken)
  53. return
  54. }
  55. this.ServeSuccessJSON(map[string]interface{}{
  56. "uptoken": token,
  57. })
  58. return
  59. }
  60. func (this *LoginManagement) ServeFailJsonSend(code int, msg string) {
  61. fmt.Println("code", code)
  62. this.Data["json"] = enums.MakeFailResponseJSON(msg, code)
  63. this.ServeJSON()
  64. }
  65. func (this *LoginManagement) ServeSuccessJSON(data map[string]interface{}) {
  66. this.Data["json"] = enums.MakeSuccessResponseJSON(data)
  67. this.ServeJSON()
  68. }
  69. func (this *LoginManagement) GetToLogin() {
  70. tel := this.GetString("tel")
  71. fmt.Println("账号啊", tel)
  72. psd := this.GetString("psd")
  73. fmt.Println("密码哈", psd)
  74. admin, err := login_service.QueryLogin(tel, psd)
  75. fmt.Println("admin", admin)
  76. fmt.Println("err", err)
  77. if err != nil {
  78. fmt.Println("代码进来了没哟u")
  79. this.ServeFailJsonSend(enums.ErrorCodeDataException, "账号密码错误")
  80. return
  81. } else {
  82. fmt.Println("admin", admin.ID)
  83. org, error := login_service.GetQueryUserOrgId(admin.ID)
  84. fmt.Println("error", error)
  85. if error == gorm.ErrRecordNotFound {
  86. this.ServeSuccessJSON(map[string]interface{}{
  87. "org": org,
  88. "info": admin,
  89. })
  90. } else if error == nil {
  91. fmt.Println("heeeee")
  92. this.ServeSuccessJSON(map[string]interface{}{
  93. "admin": admin,
  94. })
  95. }
  96. }
  97. //fmt.Println("==============================================",admin.ID)
  98. //org, errcode := login_service.GetQueryUserOrgId(admin.ID)
  99. //fmt.Println("org是什么",org)
  100. //fmt.Println("errcode",errcode)
  101. //fmt.Println("org",org)
  102. //if err == gorm.ErrRecordNotFound{
  103. // this.ServeSuccessJSON(map[string]interface{}{
  104. // "Userorg":admin,
  105. // })
  106. //}else if err == nil {
  107. // if(admin.Mobile != tel && admin.Mobile != psd){
  108. // this.ServeFailJsonSend(enums.ErrorCodeDataException, "登录失败")
  109. // return
  110. // }
  111. // this.ServeSuccessJSON(map[string]interface{}{
  112. // "admin":admin,
  113. // })
  114. //}
  115. }
  116. func (this *LoginManagement) CodeOfModifyPwd() {
  117. redisClient := login_service.RedisClient()
  118. defer redisClient.Close()
  119. mobile := this.GetString("phone")
  120. fmt.Println("错误错误错误错误错误错误错误错误错误错误错误错误错误错误错误错误错误错误错误错误错误错误", mobile)
  121. //var mobile = "13318464642"
  122. admin, errcode := login_service.GetQueryMobileData(mobile)
  123. fmt.Println("admin是设么", admin)
  124. fmt.Println("errcode是设么", errcode)
  125. if errcode == gorm.ErrRecordNotFound {
  126. cur_date := time.Now().Format("2006-01-02")
  127. moblie_count, _ := redisClient.Get("scrm_verification_code_" + mobile + "_" + cur_date).Result()
  128. fmt.Println("moblie_count", moblie_count)
  129. moblie_count_int, _ := strconv.Atoi(moblie_count)
  130. if moblie_max := 5; moblie_count_int >= moblie_max {
  131. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeVerificationCodeLimit)
  132. return
  133. }
  134. if code, err := sms_service.SMSSendVerificationCode(mobile); err != nil {
  135. //this.ErrorLog("修改密码发送验证码失败:%v", err)
  136. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  137. return
  138. } else {
  139. cur_date := time.Now().Format("2006-01-02")
  140. set := redisClient.Set("scrm_verification_code_"+mobile, code, time.Minute*10)
  141. fmt.Println("set", set)
  142. Incr, _ := redisClient.Incr("scrm_verification_code_" + mobile + "_" + cur_date).Result()
  143. fmt.Println("Incr", Incr)
  144. this.ServeSuccessJSON(map[string]interface{}{
  145. "msg": "短信发送成功,有效期为10分钟",
  146. })
  147. }
  148. returnData := make(map[string]interface{}, 0)
  149. returnData["admin"] = admin
  150. this.ServeSuccessJSON(returnData)
  151. } else if errcode == nil {
  152. returnData := make(map[string]interface{}, 0)
  153. returnData["admin"] = admin
  154. this.ServeSuccessJSON(returnData)
  155. }
  156. }
  157. func (this *LoginManagement) SaveRegisterData() {
  158. phone := this.GetString("phone")
  159. fmt.Println("电话是多少", phone)
  160. password := this.GetString("password")
  161. fmt.Println("密码是多少", password)
  162. code := this.GetString("code")
  163. fmt.Println("code", code)
  164. redisClient := login_service.RedisClient()
  165. fmt.Println("redisClient", redisClient)
  166. defer redisClient.Close()
  167. cachedCode, err := redisClient.Get("scrm_verification_code_" + phone).Result()
  168. fmt.Println("错误是设么", err)
  169. fmt.Println("cachedCode", cachedCode)
  170. //admin := models.SgjUserAdmin{
  171. // Mobile: phone,
  172. // Password: password,
  173. // Status: 1,
  174. // IsSuperAdmin: 1,
  175. // Ctime: time.Now().Unix(),
  176. //}
  177. //err := login_service.AddAdmin(&admin)
  178. //fmt.Println("错误",err)
  179. //returnData := make(map[string]interface{}, 0)
  180. //returnData["admin"] = admin
  181. //this.ServeSuccessJSON(returnData)
  182. //if err != nil {
  183. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAccountOrVerCodeWrong)
  184. // return
  185. //}
  186. if code != cachedCode {
  187. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAccountOrVerCodeWrong)
  188. return
  189. } else {
  190. admin := models.SgjUserAdmin{
  191. Mobile: phone,
  192. Password: password,
  193. Status: 1,
  194. IsSuperAdmin: 1,
  195. Ctime: time.Now().Unix(),
  196. }
  197. err = login_service.AddAdmin(&admin)
  198. fmt.Println("错误", err)
  199. returnData := make(map[string]interface{}, 0)
  200. returnData["admin"] = admin
  201. this.ServeSuccessJSON(returnData)
  202. }
  203. }
  204. func (this *LoginManagement) GetAllProvince() {
  205. provice, err := login_service.GetAllProvince(0)
  206. fmt.Println("错误", err)
  207. //returnData := make(map[string]interface{}, 0)
  208. //returnData["provice"] = provice
  209. //this.ServeSuccessJSON(returnData)
  210. this.ServeSuccessJSON(map[string]interface{}{
  211. "provice": provice,
  212. })
  213. }
  214. func (this *LoginManagement) NoPassLogin() {
  215. phone := this.GetString("phone")
  216. fmt.Println("phone是什么", phone)
  217. code := this.GetString("code")
  218. fmt.Println("code是什么", code)
  219. admin, err := login_service.GetQueryPhoneData(phone)
  220. fmt.Println("admin", admin)
  221. if err != nil {
  222. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAccountOrVerCodeWrong)
  223. return
  224. }
  225. redisClient := login_service.RedisClient()
  226. defer redisClient.Close()
  227. cachedCode, err := redisClient.Get("scrm_verification_code_" + phone).Result()
  228. fmt.Println("cachedCode", cachedCode)
  229. if err != nil {
  230. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAccountOrVerCodeWrong)
  231. return
  232. }
  233. if code == cachedCode {
  234. returnData := make(map[string]interface{}, 0)
  235. returnData["msg"] = "ok"
  236. this.ServeSuccessJSON(returnData)
  237. }
  238. if code != cachedCode {
  239. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAccountOrVerCodeWrong)
  240. return
  241. }
  242. }
  243. func (this *LoginManagement) GetCode() {
  244. phone := this.GetString("phone")
  245. fmt.Println("phone", phone)
  246. redisClient := login_service.RedisClient()
  247. defer redisClient.Close()
  248. cur_date := time.Now().Format("2006-01-02")
  249. moblie_count, _ := redisClient.Get("scrm_verification_code_" + phone + "_" + cur_date).Result()
  250. moblie_count_int, _ := strconv.Atoi(moblie_count)
  251. if moblie_max := 5; moblie_count_int >= moblie_max {
  252. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeVerificationCodeLimit)
  253. return
  254. }
  255. if code, err := sms_service.SMSSendVerificationCode(phone); err != nil {
  256. //this.ErrorLog("修改密码发送验证码失败:%v", err)
  257. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  258. return
  259. } else {
  260. cur_date := time.Now().Format("2006-01-02")
  261. redisClient.Set("scrm_verification_code_"+phone, code, time.Minute*10)
  262. redisClient.Incr("scrm_verification_code_" + phone + "_" + cur_date).Result()
  263. this.ServeSuccessJSON(map[string]interface{}{
  264. "msg": "短信发送成功,有效期为10分钟",
  265. })
  266. }
  267. }
  268. func (this *LoginManagement) NextStep() {
  269. phone := this.GetString("phone")
  270. fmt.Println("电话", phone)
  271. code := this.GetString("code")
  272. fmt.Println("code", code)
  273. redisClient := login_service.RedisClient()
  274. defer redisClient.Close()
  275. cachedCode, err := redisClient.Get("scrm_verification_code_" + phone).Result()
  276. fmt.Println("cachedCode", cachedCode)
  277. if err != nil {
  278. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAccountOrVerCodeWrong)
  279. return
  280. }
  281. if code == cachedCode {
  282. returnData := make(map[string]interface{}, 0)
  283. returnData["msg"] = "ok"
  284. this.ServeSuccessJSON(returnData)
  285. }
  286. if code != cachedCode {
  287. fmt.Println("hehehhhhhhhhhheheh")
  288. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAccountOrVerCodeWrong)
  289. return
  290. }
  291. }
  292. func (this *LoginManagement) Accomplish() {
  293. phone := this.GetString("phone")
  294. fmt.Println("phone", phone)
  295. newpassword := this.GetString("newpassword")
  296. fmt.Println("newpassword", newpassword)
  297. confirmpassword := this.GetString("confirmpassword")
  298. fmt.Println("confirmpassword", confirmpassword)
  299. if newpassword != confirmpassword {
  300. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAccountOrVerCodeWrong)
  301. return
  302. }
  303. if newpassword == confirmpassword {
  304. admin := models.SgjUserAdmin{
  305. Password: newpassword,
  306. }
  307. err := login_service.UpdatedPassword(phone, &admin)
  308. fmt.Println("错误", err)
  309. returnData := make(map[string]interface{}, 0)
  310. returnData["admin"] = admin
  311. this.ServeSuccessJSON(returnData)
  312. }
  313. }
  314. func (this *LoginManagement) GetAllOrgName() {
  315. id, _ := this.GetInt64("id")
  316. org, err := login_service.GetAllOrgName(id)
  317. fmt.Println("错误", err)
  318. returnData := make(map[string]interface{}, 0)
  319. returnData["org"] = org
  320. this.ServeSuccessJSON(returnData)
  321. }
  322. func (this *LoginManagement) GetCityById() {
  323. id, _ := this.GetInt64("id")
  324. //fmt.Println("id是什么",id)
  325. ids, err := login_service.GetCityById(id)
  326. fmt.Println("err是设么", err)
  327. returnData := make(map[string]interface{}, 0)
  328. returnData["ids"] = ids
  329. this.ServeSuccessJSON(returnData)
  330. }
  331. func (this *LoginManagement) GetAllOrgType() {
  332. orgtypes, err := login_service.GetAllOrgType()
  333. fmt.Println("err是什么", err)
  334. fmt.Println("orgtypes", orgtypes)
  335. returnData := make(map[string]interface{}, 0)
  336. returnData["orgtypes"] = orgtypes
  337. this.ServeSuccessJSON(returnData)
  338. }
  339. func (this *LoginManagement) SaveOrginInformation() {
  340. id, _ := this.GetInt64("id")
  341. fmt.Println("id", id)
  342. dataBody := make(map[string]interface{}, 0)
  343. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  344. fmt.Println("视频发布是什么呢", err)
  345. //orgname := this.GetString("org_name")
  346. orgname := dataBody["org_name"].(string)
  347. fmt.Println("orgname", orgname)
  348. address := dataBody["address"].(string)
  349. fmt.Println("address", address)
  350. contactname := dataBody["contact_name"].(string)
  351. fmt.Println("contactname", contactname)
  352. telephone := dataBody["telephone"].(string)
  353. fmt.Println("telephone", telephone)
  354. provincesName := dataBody["provinces_name"].(string)
  355. fmt.Println("provincesName", provincesName)
  356. district, err := login_service.GetProvinceByName(provincesName)
  357. fmt.Println("district", district)
  358. cityname := dataBody["city_name"].(string)
  359. fmt.Println("cityname", cityname)
  360. cityDistrict, err := login_service.GetCityByName(cityname, district.ID)
  361. fmt.Println("err", err)
  362. fmt.Println("cityDistrict", cityDistrict)
  363. countname := dataBody["count_name"].(string)
  364. fmt.Println("countname", countname)
  365. orgtype := dataBody["org_type"].(string)
  366. fmt.Println("orgtype", orgtype)
  367. Orgtype, err := login_service.GetOrgTypeByName(orgtype)
  368. userDistrict, err := login_service.GetCountByName(countname, cityDistrict.ID)
  369. fmt.Println("错误", err)
  370. fmt.Println("userDistrict", userDistrict)
  371. org := models.SgjUserOrg{
  372. OrgName: orgname,
  373. Address: address,
  374. ContactName: contactname,
  375. Telephone: telephone,
  376. Ctime: time.Now().Unix(),
  377. Status: 1,
  378. Province: district.ID,
  379. City: cityDistrict.ID,
  380. District: userDistrict.ID,
  381. OrgType: Orgtype.ID,
  382. Creator: id,
  383. }
  384. fmt.Println("org", org)
  385. err = login_service.AddUserOrgInfo(&org)
  386. userOrg, err := login_service.GeLastUserOrgLastData(id)
  387. fmt.Println("uerOrg", userOrg)
  388. fmt.Println("heeeeeeeeeeeeeeee", userOrg.ID)
  389. fmt.Println("err", err)
  390. nextMonthDate := time.Now().AddDate(0, 0, 30)
  391. subscibe := models.ServeSubscibe{
  392. OrgId: userOrg.ID,
  393. PeriodStart: time.Now().Unix(),
  394. PeriodEnd: nextMonthDate.Unix(),
  395. Status: 1,
  396. State: 9,
  397. CreatedTime: time.Now().Unix(),
  398. UpdatedTime: time.Now().Unix(),
  399. }
  400. err = login_service.CreateSubscibe(&subscibe)
  401. fmt.Println("err", err)
  402. role := models.UserRole{
  403. RoleName: "超级管理员",
  404. Creator: id,
  405. OrgId: userOrg.ID,
  406. IsSuperAdmin: 1,
  407. Status: 1,
  408. Ctime: time.Now().Unix(),
  409. Mtime: time.Now().Unix(),
  410. }
  411. err = login_service.AddRole(&role)
  412. userRole, err := login_service.GetRoleLastDate(userOrg.ID)
  413. fmt.Println("添加权限", err)
  414. orgApp := models.UserOrgApp{
  415. AppType: 1,
  416. Creator: id,
  417. OrgId: userOrg.ID,
  418. OpenStatus: 0,
  419. Status: 1,
  420. Ctime: time.Now().Unix(),
  421. Mtime: time.Now().Unix(),
  422. }
  423. errcode := login_service.AddUserOrgApp(&orgApp)
  424. fmt.Println("addUserOrgApp", errcode)
  425. orgApp, _ = login_service.GetLastData(userOrg.ID)
  426. fmt.Println("oooooooooooooooooooooooooooooooooooooooooo")
  427. fmt.Println("orgApp是什么东西", orgApp)
  428. fmt.Println("orgapp", orgApp.ID)
  429. adminRole := models.UserAdminRole{
  430. AdminUserId: id,
  431. OrgId: userOrg.ID,
  432. AppId: orgApp.ID,
  433. RoleId: userRole.ID,
  434. UserType: 1,
  435. UserTitle: 1,
  436. Status: 1,
  437. UserName: telephone,
  438. Ctime: time.Now().Unix(),
  439. }
  440. err = login_service.AddAdimnRole(&adminRole)
  441. app := models.UserOrgApp{
  442. AppType: 3,
  443. Creator: id,
  444. OrgId: userOrg.ID,
  445. OpenStatus: 1,
  446. Status: 1,
  447. Ctime: time.Now().Unix(),
  448. Mtime: time.Now().Unix(),
  449. }
  450. err = login_service.AddUserOrgApp(&app)
  451. getLastDatas, _ := login_service.GetLastData(userOrg.ID)
  452. adminRolethee := models.UserAdminRole{
  453. AdminUserId: id,
  454. OrgId: userOrg.ID,
  455. AppId: getLastDatas.ID,
  456. RoleId: userRole.ID,
  457. UserType: 1,
  458. UserTitle: 1,
  459. Status: 1,
  460. UserName: telephone,
  461. Ctime: time.Now().Unix(),
  462. }
  463. err = login_service.AddAdimnRole(&adminRolethee)
  464. userOrgApp := models.UserOrgApp{
  465. AppType: 4,
  466. Creator: id,
  467. OrgId: userOrg.ID,
  468. OpenStatus: 0,
  469. Status: 1,
  470. Ctime: time.Now().Unix(),
  471. Mtime: time.Now().Unix(),
  472. }
  473. err = login_service.AddUserOrgApp(&userOrgApp)
  474. data, _ := login_service.GetLastData(userOrg.ID)
  475. adminRoleone := models.UserAdminRole{
  476. AdminUserId: id,
  477. OrgId: userOrg.ID,
  478. AppId: data.ID,
  479. RoleId: userRole.ID,
  480. UserType: 1,
  481. UserTitle: 1,
  482. Status: 1,
  483. UserName: telephone,
  484. Ctime: time.Now().Unix(),
  485. }
  486. err = login_service.AddAdimnRole(&adminRoleone)
  487. iuser := models.UserOrgApp{
  488. AppType: 5,
  489. Creator: id,
  490. OrgId: userOrg.ID,
  491. OpenStatus: 0,
  492. Status: 1,
  493. Ctime: time.Now().Unix(),
  494. Mtime: time.Now().Unix(),
  495. }
  496. err = login_service.AddUserOrgApp(&iuser)
  497. fmt.Println("错误", err)
  498. lastData, _ := login_service.GetLastData(userOrg.ID)
  499. adminRoletwo := models.UserAdminRole{
  500. AdminUserId: id,
  501. OrgId: userOrg.ID,
  502. AppId: lastData.ID,
  503. RoleId: userRole.ID,
  504. UserType: 1,
  505. UserTitle: 1,
  506. Status: 1,
  507. UserName: telephone,
  508. Ctime: time.Now().Unix(),
  509. }
  510. err = login_service.AddAdimnRole(&adminRoletwo)
  511. returnData := make(map[string]interface{}, 0)
  512. returnData["org"] = org
  513. this.ServeSuccessJSON(returnData)
  514. }
  515. func (this *LoginManagement) GetneratedDialysisNo() {
  516. phone := this.GetString("phone")
  517. fmt.Println("phone是什么", phone)
  518. admin, err := patient_service.GetCreatorId(phone)
  519. fmt.Println("获取注册id错误", err)
  520. org, err := patient_service.GetOrgId(admin.ID)
  521. fmt.Println("获取机构id错误", err)
  522. fmt.Println("机构id", org.ID)
  523. dialysisNo := patient_service.GetneratedDialysisNo(org.ID)
  524. fmt.Println("dialysisNo是什么", dialysisNo)
  525. if dialysisNo == 0 {
  526. dialysisNo = 1
  527. } else {
  528. dialysisNo++
  529. }
  530. no := strconv.FormatInt(dialysisNo, 10)
  531. fmt.Println("no", no)
  532. rep := 3 - len(no)
  533. if rep > 0 {
  534. no = strings.Repeat("0", rep) + no
  535. }
  536. this.ServeSuccessJSON(map[string]interface{}{
  537. "no": no,
  538. })
  539. returnData := make(map[string]interface{}, 0)
  540. returnData["no"] = no
  541. this.ServeSuccessJSON(returnData)
  542. }
  543. func (this *LoginManagement) GetBloodDialysisPatient() {
  544. page, _ := this.GetInt64("page")
  545. fmt.Println("page", page)
  546. limit, _ := this.GetInt64("limit")
  547. fmt.Println("limit", limit)
  548. id, _ := this.GetInt64("id")
  549. org, _ := patient_service.GetOrgId(id)
  550. fmt.Println("org是什么", org.ID)
  551. patients, total, err := login_service.GetBloodDialysisPatient(org.ID, page, limit)
  552. fmt.Println("patients", patients)
  553. fmt.Println("err", err)
  554. returnData := make(map[string]interface{}, 0)
  555. returnData["patients"] = patients
  556. returnData["total"] = total
  557. this.ServeSuccessJSON(returnData)
  558. if err != nil {
  559. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加医院失败")
  560. return
  561. }
  562. this.ServeSuccessJSON(map[string]interface{}{
  563. "patients": patients,
  564. "total": total,
  565. })
  566. }
  567. func (this *LoginManagement) GetDoctorAdvice() {
  568. patientid, _ := this.GetInt64("patientid")
  569. fmt.Println("patientid", patientid)
  570. starttime := this.GetString("starttime")
  571. fmt.Println("starttime", starttime)
  572. timeLayout := "2006-01-02 15:04:05"
  573. theTime, _ := utils.ParseTimeStringToTime(timeLayout, starttime+" 00:00:00")
  574. fmt.Println("err")
  575. star := theTime.Unix()
  576. fmt.Println("star", star)
  577. orgid, _ := this.GetInt64("orgid")
  578. fmt.Println("orgid是什么", orgid)
  579. endtime := this.GetString("endtime")
  580. fmt.Println("endtime", endtime)
  581. toTime, _ := utils.ParseTimeStringToTime(timeLayout, endtime+" 00:00:00")
  582. end := toTime.Unix()
  583. fmt.Println("end", end)
  584. searchval := this.GetString("searchval")
  585. fmt.Println("searchval", searchval)
  586. patients, err := login_service.GetPatintsInfo(patientid, orgid)
  587. diseases, err := login_service.GetPatientInfectious(patientid)
  588. fmt.Println("徐欧文", err)
  589. //根据机构id获取创建者id
  590. org, _ := login_service.GetCreatorId(orgid)
  591. fmt.Println("创建者", org)
  592. //根据创建者id获取apptype id
  593. app, _ := login_service.GetOrgAppId(org.Creator, orgid)
  594. fmt.Println("appid", app.ID)
  595. //获取开嘱医生
  596. role, _ := login_service.GetAdvceDoctor(org.Creator, orgid, app.ID)
  597. doctoradvice, total, err := login_service.GetDoctorAdvice(patientid, orgid, star, end, searchval)
  598. fmt.Println("err", err)
  599. fmt.Println("doctorradvice", doctoradvice)
  600. if err != nil {
  601. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加医院失败")
  602. return
  603. }
  604. this.ServeSuccessJSON(map[string]interface{}{
  605. "doctoradvice": doctoradvice,
  606. "patients": patients,
  607. "diseases": diseases,
  608. "role": role,
  609. "total": total,
  610. })
  611. }
  612. func (this *LoginManagement) SaveSearch() {
  613. searchval := this.GetString("searchval")
  614. fmt.Println("searchval", searchval)
  615. }
  616. func (this *LoginManagement) ToSeacherDoctorAdvice() {
  617. patientid, _ := this.GetInt64("patientid")
  618. fmt.Println("patientid", patientid)
  619. orgid, _ := this.GetInt64("orgid")
  620. fmt.Println("orgid", orgid)
  621. searchval := this.GetString("searchval")
  622. fmt.Println("searchval", searchval)
  623. doctoradvice, err := login_service.SeacherDoctorAdviceByAdviceName(patientid, orgid, searchval)
  624. if err != nil {
  625. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加医院失败")
  626. return
  627. }
  628. this.ServeSuccessJSON(map[string]interface{}{
  629. "doctoradvice": doctoradvice,
  630. })
  631. }
  632. func (this *LoginManagement) DeleteDoctorAdvice() {
  633. id, _ := this.GetInt64("id")
  634. fmt.Println("id是什么", id)
  635. err := login_service.DeleteDoctorAdvice(id)
  636. fmt.Println("err", err)
  637. returnData := make(map[string]interface{}, 0)
  638. returnData["msg"] = "ok"
  639. this.ServeSuccessJSON(returnData)
  640. return
  641. }