login_controller.go 21KB

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