his_deposit_controller.go 31KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "github.com/shopspring/decimal"
  11. "strconv"
  12. "strings"
  13. "time"
  14. )
  15. type HisDepositApiController struct {
  16. BaseAuthAPIController
  17. }
  18. func HisDepositApiRegistRouters() {
  19. //beego.Router("/api/his/ttt", &HisDepositApiController{}, "get:TTT") //测试接口
  20. beego.Router("/api/his/gethisusertoalive", &HisDepositApiController{}, "get:GetHisUserToAlive") //获取病例中心,有效患者名称(去除了转出和死亡的)
  21. beego.Router("/api/his/gethisuser", &HisDepositApiController{}, "get:GetHisUser") //获取病例中心,有效患者名称
  22. beego.Router("/api/his/adddeposit", &HisDepositApiController{}, "post:AddDeposit") //新增押金
  23. beego.Router("/api/his/getdepositcode", &HisDepositApiController{}, "get:GetDepositCode") //获取新增押金编号
  24. beego.Router("/api/his/getdeletecode", &HisDepositApiController{}, "get:GetDeleteCode") //获取退款编号
  25. beego.Router("/api/his/rechargedetails", &HisDepositApiController{}, "get:RechargeDetails") //充值明细列表
  26. beego.Router("/api/his/updeposit", &HisDepositApiController{}, "get:UpDeposit") //押金审核
  27. beego.Router("/api/his/deletehistory", &HisDepositApiController{}, "get:DeleteHistory") //押金删除
  28. beego.Router("/api/his/rechargesummary", &HisDepositApiController{}, "get:RechargeSummary") //充值汇总列表
  29. beego.Router("/api/his/getuserlist", &HisDepositApiController{}, "get:GetUserList") //获取患者押金列表
  30. beego.Router("/api/his/depositflow", &HisDepositApiController{}, "get:DepositFlow") //根据患者id获取押金流水
  31. beego.Router("/api/his/deductiondetails", &HisDepositApiController{}, "get:DeductionDetails") //扣费明细查询
  32. beego.Router("/api/his/desummary", &HisDepositApiController{}, "get:DeSummary") //扣费汇总
  33. beego.Router("/api/his/idtobalance", &HisDepositApiController{}, "get:IdToBalance") //根据患者id查询患者的余额
  34. beego.Router("/api/his/refundapplication", &HisDepositApiController{}, "post:RefundApplication") //新增一条退款申请
  35. beego.Router("/api/his/refundreview", &HisDepositApiController{}, "get:RefundReview") //退款审核通过/拒绝
  36. beego.Router("/api/his/deleterefund", &HisDepositApiController{}, "get:DeleteRefund") //退款删除
  37. beego.Router("/api/his/changerefund", &HisDepositApiController{}, "post:ChangeRefund") //更改退款申请
  38. beego.Router("/api/his/refundlist", &HisDepositApiController{}, "get:RefundList") //退款分页
  39. beego.Router("/api/his/getorgname", &HisDepositApiController{}, "get:GetorgName") //获取供应商名字
  40. beego.Router("/api/his/getweektime", &HisDepositApiController{}, "get:GetWeekTime") //获取本周时间
  41. beego.Router("/api/his/getmonthtime", &HisDepositApiController{}, "get:GetMonthTime") //获取本月时间
  42. }
  43. //func (this *HisDepositApiController) TTT() {
  44. // orgid := this.GetAdminUserInfo().CurrentOrgId
  45. // id, _ := this.GetInt64("id")
  46. // code := this.GetString("code")
  47. // deposit,_ := this.GetInt64("depostit")
  48. // err := service.MoneyIncrease(orgid,id,code,deposit)
  49. // if err != nil {
  50. //
  51. // }
  52. // this.ServeSuccessJSON(map[string]interface{}{
  53. // "list": "成功",
  54. // })
  55. // return
  56. //}
  57. //获取病例中心,有效患者名称(去除了转出和死亡的)
  58. func (this *HisDepositApiController) GetHisUserToAlive() {
  59. orgid := this.GetAdminUserInfo().CurrentOrgId
  60. list, err := service.GetHisUserToAlive(orgid)
  61. if err != nil {
  62. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  63. return
  64. }
  65. this.ServeSuccessJSON(map[string]interface{}{
  66. "list": list,
  67. })
  68. return
  69. }
  70. //获取病例中心,有效患者名称
  71. func (this *HisDepositApiController) GetHisUser() {
  72. orgid := this.GetAdminUserInfo().CurrentOrgId
  73. token := this.Ctx.Request.Header.Get("Cookie")
  74. fmt.Println(token)
  75. this.Ctx.SetCookie("ppp", "lilili")
  76. this.Ctx.SetCookie("ppp01", "lilili01")
  77. list, err := service.GetHisUser(orgid)
  78. if err != nil {
  79. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  80. return
  81. }
  82. this.ServeSuccessJSON(map[string]interface{}{
  83. "list": list,
  84. })
  85. return
  86. }
  87. //新增押金
  88. func (this *HisDepositApiController) AddDeposit() {
  89. orgid := this.GetAdminUserInfo().CurrentOrgId
  90. dataBody := make(map[string]interface{}, 0)
  91. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  92. if err != nil {
  93. utils.ErrorLog(err.Error())
  94. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  95. return
  96. }
  97. switch {
  98. case dataBody["code"] == nil:
  99. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金编号不能为空")
  100. return
  101. case dataBody["his_patient_id"] == nil || dataBody["his_patient_id"] == "":
  102. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "患者名称不能为空")
  103. return
  104. case dataBody["deposit"] == nil || dataBody["deposit"] == "":
  105. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金金额不能为空")
  106. return
  107. case dataBody["trial_status"] == nil || dataBody["trial_status"] == "":
  108. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "审核状态不能为空")
  109. return
  110. }
  111. code := dataBody["code"].(string) //押金编号
  112. his_patient_id := int64(dataBody["his_patient_id"].(float64)) //患者编号
  113. var tmps float64
  114. switch dataBody["deposit"].(type) {
  115. case string:
  116. t_deposit := dataBody["deposit"].(string)
  117. if len(t_deposit) > 0 {
  118. if t_deposit[0] == 45 {
  119. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金金额错误")
  120. return
  121. }
  122. }
  123. tt, errs := strconv.ParseFloat(t_deposit, 64)
  124. if errs != nil {
  125. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金金额错误")
  126. return
  127. } else {
  128. tmps = tt
  129. }
  130. default:
  131. tmps = dataBody["deposit"].(float64)
  132. }
  133. if tmps == 0 {
  134. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金金额不能为0")
  135. return
  136. }
  137. deposit := decimal.NewFromFloat(tmps) //押金金额
  138. var remarks string
  139. if dataBody["remarks"] == nil {
  140. remarks = ""
  141. } else {
  142. remarks = dataBody["remarks"].(string) //备注
  143. }
  144. trial_status := int64(dataBody["trial_status"].(float64)) //审核状态
  145. createid := this.GetAdminUserInfo().AdminUser.Id
  146. pp := this.GetAdminUserInfo()
  147. fmt.Println(pp)
  148. err = service.UpDeposit(code, remarks, his_patient_id, orgid, trial_status, createid, deposit)
  149. if err != nil {
  150. utils.ErrorLog(err.Error())
  151. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  152. return
  153. }
  154. this.ServeSuccessJSON(map[string]interface{}{
  155. "list": "添加成功",
  156. })
  157. return
  158. }
  159. //获取新增押金编号
  160. func (this *HisDepositApiController) GetDepositCode() {
  161. orgid := this.GetAdminUserInfo().CurrentOrgId
  162. var code string
  163. for a := true; a == true; {
  164. code = service.CreateCPCode("CP")
  165. tmp := service.FindDecimalCode(orgid, code)
  166. if tmp == false {
  167. a = false
  168. }
  169. }
  170. this.ServeSuccessJSON(map[string]interface{}{
  171. "list": code,
  172. })
  173. return
  174. }
  175. //获取退款编号
  176. func (this *HisDepositApiController) GetDeleteCode() {
  177. orgid := this.GetAdminUserInfo().CurrentOrgId
  178. var code string
  179. for a := true; a == true; {
  180. code = service.CreateCPCode("AF")
  181. tmp := service.FindDecimalCode(orgid, code)
  182. if tmp == false {
  183. a = false
  184. }
  185. }
  186. this.ServeSuccessJSON(map[string]interface{}{
  187. "list": code,
  188. })
  189. return
  190. }
  191. //充值明细列表
  192. func (this *HisDepositApiController) RechargeDetails() {
  193. orgid := this.GetAdminUserInfo().CurrentOrgId
  194. timeLayout := "2006-01-02"
  195. loc, _ := time.LoadLocation("Local")
  196. keyword := this.GetString("keyword")
  197. start_time := this.GetString("start_time")
  198. end_time := this.GetString("end_time")
  199. var stime int64 //开始时间
  200. var etime int64 //结束时间
  201. namemap := make(map[int64]string)
  202. slicekey := make([]int64, 0)
  203. lists, _ := service.GetHisUser(orgid)
  204. for _, v := range lists {
  205. namemap[v.ID] = v.Name
  206. }
  207. if len(keyword) > 0 {
  208. for k, v := range namemap {
  209. res := strings.Contains(v, keyword)
  210. if res == true {
  211. slicekey = append(slicekey, k)
  212. }
  213. }
  214. }
  215. if start_time == "" && end_time == "" {
  216. //如果为空查询全部的
  217. _, etime = service.GetMondayOfWeek()
  218. stime = 0
  219. } else {
  220. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  221. etmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  222. stime = stmp.Unix()
  223. etime = etmp.Unix()
  224. }
  225. list, err := service.DetailsList(orgid, stime, etime, keyword, slicekey)
  226. if err != nil {
  227. utils.ErrorLog(err.Error())
  228. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  229. return
  230. }
  231. var sum decimal.Decimal
  232. for i := 0; i < len(list); i++ {
  233. if list[i].TrialStatus == 1 {
  234. sum = sum.Add(list[i].Deposit)
  235. }
  236. list[i].Name = service.GetCreateidName(list[i].CreateId)
  237. list[i].HisName = namemap[list[i].HisPatientId]
  238. list[i].Starttime = fmt.Sprintf(time.Unix(list[i].Ctime, 0).Format("2006-01-02"))
  239. }
  240. this.ServeSuccessJSON(map[string]interface{}{
  241. "list": list,
  242. "sum": sum,
  243. })
  244. return
  245. }
  246. //充值汇总列表
  247. func (this *HisDepositApiController) RechargeSummary() {
  248. orgid := this.GetAdminUserInfo().CurrentOrgId
  249. timeLayout := "2006-01-02"
  250. loc, _ := time.LoadLocation("Local")
  251. keyword := this.GetString("keyword")
  252. start_time := this.GetString("start_time")
  253. end_time := this.GetString("end_time")
  254. var stime int64 //开始时间
  255. var etime int64 //结束时间
  256. namemap := make(map[int64]string)
  257. slicekey := make([]int64, 0)
  258. lists, _ := service.GetHisUser(orgid)
  259. for _, v := range lists {
  260. namemap[v.ID] = v.Name
  261. }
  262. if len(keyword) > 0 {
  263. for k, v := range namemap {
  264. res := strings.Contains(v, keyword)
  265. if res == true {
  266. slicekey = append(slicekey, k)
  267. }
  268. }
  269. }
  270. if start_time == "" && end_time == "" {
  271. _, etime = service.GetMondayOfWeek()
  272. stime = 0
  273. } else {
  274. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  275. etmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  276. stime = stmp.Unix()
  277. etime = etmp.Unix()
  278. }
  279. list, err := service.SummaryList(orgid, stime, etime, keyword, slicekey)
  280. if err != nil {
  281. utils.ErrorLog(err.Error())
  282. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  283. return
  284. }
  285. //list为详细数据,把list整理合并为maplist输出
  286. maplist := make(map[int64]models.Summary)
  287. Finlist := []models.Summary{}
  288. tmpslice := make([]int64, 0)
  289. var sum decimal.Decimal
  290. for i := 0; i < len(list); i++ {
  291. if list[i].TrialStatus == 1 {
  292. if k, ok := maplist[list[i].HisPatientId]; ok {
  293. k.SumDecimal = k.SumDecimal.Add(list[i].Deposit)
  294. maplist[list[i].HisPatientId] = models.Summary{
  295. namemap[list[i].HisPatientId],
  296. k.SumDecimal,
  297. service.GetUserMoney(list[i].HisPatientId, orgid),
  298. }
  299. } else {
  300. maplist[list[i].HisPatientId] = models.Summary{
  301. namemap[list[i].HisPatientId],
  302. list[i].Deposit,
  303. service.GetUserMoney(list[i].HisPatientId, orgid),
  304. }
  305. tmpslice = append(tmpslice, list[i].HisPatientId)
  306. }
  307. sum = sum.Add(list[i].Deposit)
  308. }
  309. }
  310. //maplist虽然满足接口要求,但格式不行,整理为Finlist输出
  311. for i := 0; i < len(tmpslice); i++ {
  312. Finlist = append(Finlist, maplist[tmpslice[i]])
  313. }
  314. this.ServeSuccessJSON(map[string]interface{}{
  315. "list": Finlist,
  316. "sum": sum,
  317. })
  318. return
  319. }
  320. //审核
  321. func (this *HisDepositApiController) UpDeposit() {
  322. id, _ := this.GetInt64("id", 0)
  323. if id == 0 {
  324. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "id不能为空")
  325. return
  326. }
  327. tmp, err := service.GetDecimalHistoryOne(id)
  328. if err != nil {
  329. utils.ErrorLog("无法查询该记录信息", err.Error())
  330. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "无法查询该记录信息")
  331. return
  332. }
  333. if tmp.TrialStatus == 0 {
  334. err = service.UpDecimalHistory(id)
  335. if err != nil {
  336. utils.ErrorLog("更新押金历史表出错,原因为:", err.Error())
  337. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "系统错误")
  338. return
  339. }
  340. } else {
  341. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "当前状态不可审核")
  342. return
  343. }
  344. this.ServeSuccessJSON(map[string]interface{}{
  345. "list": "审核通过",
  346. })
  347. return
  348. }
  349. func (this *HisDepositApiController) DeleteHistory() {
  350. id, _ := this.GetInt64("id", 0)
  351. if id == 0 {
  352. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "id不能为空")
  353. return
  354. }
  355. tmp, err := service.GetDecimalHistoryOne(id)
  356. if err != nil {
  357. utils.ErrorLog("无法查询该记录信息", err.Error())
  358. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "无法查询该记录信息")
  359. return
  360. }
  361. if tmp.TrialStatus == 0 {
  362. err = service.DelDecimalHistory(id)
  363. if err != nil {
  364. utils.ErrorLog("删除历史记录出错,原因为:", err.Error())
  365. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "系统错误")
  366. return
  367. }
  368. } else {
  369. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "已审核的单据不能进行删除操作")
  370. return
  371. }
  372. this.ServeSuccessJSON(map[string]interface{}{
  373. "list": "删除成功",
  374. })
  375. return
  376. }
  377. //根据id获取押金流水
  378. func (this *HisDepositApiController) DepositFlow() {
  379. orgid := this.GetAdminUserInfo().CurrentOrgId
  380. check := map[string][]string{
  381. "id": {"must", "int", "id"},
  382. "deposit_status": {"must", "int", "deposit_status"},
  383. "page": {"must", "string", "page"},
  384. "limit": {"must", "string", "limit"},
  385. }
  386. _, err := checks(this, &check)
  387. if err != nil {
  388. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  389. return
  390. }
  391. id, _ := this.GetInt64("id") //患者id
  392. //获取当前患者的姓名
  393. tmp, _ := service.GetHisUserName(orgid, id)
  394. name := tmp.Name
  395. deposit_status, _ := this.GetInt64("deposit_status", 0) //押金类型
  396. if deposit_status > 4 {
  397. utils.ErrorLog("押金类型错误,deposit_status:", deposit_status)
  398. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金类型错误")
  399. return
  400. }
  401. start_time := this.GetString("start_time", "") //开始时间
  402. end_time := this.GetString("end_time", "") //结束时间
  403. page, _ := this.GetInt64("page") //页码
  404. limit, _ := this.GetInt64("limit") //每一页查出来的条数
  405. timeLayout := "2006-01-02"
  406. loc, _ := time.LoadLocation("Local")
  407. var stime int64 //开始时间
  408. var etime int64 //结束时间
  409. if start_time == "" && end_time == "" {
  410. //如果为空则查全部的
  411. _, etime = service.GetMonth()
  412. stime = 0
  413. } else {
  414. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  415. etmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  416. stime = stmp.Unix()
  417. etime = etmp.Unix()
  418. }
  419. //获取该角色当前时间段的余额
  420. decimal := service.GetMoneyforTime(id, orgid, etime)
  421. //获取列表
  422. deposirhistory, total, errs := service.GetFlowList(page, limit, id, orgid, stime, etime, deposit_status)
  423. if errs != nil {
  424. utils.ErrorLog("获取列表失败,原因为:", errs.Error())
  425. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, errs.Error())
  426. return
  427. }
  428. for i := 0; i < len(deposirhistory); i++ {
  429. //如果为扣费,或退费 则把订单id变为就诊号
  430. if deposirhistory[i].DepositStatus == 2 || deposirhistory[i].DepositStatus == 4 {
  431. tmpcode, _ := strconv.ParseInt(deposirhistory[i].DepositCode, 10, 64)
  432. deposirhistory[i].DepositCode = service.FindcodeToid(tmpcode)
  433. }
  434. }
  435. this.ServeSuccessJSON(map[string]interface{}{
  436. "list": deposirhistory,
  437. "name": name,
  438. "decimal": decimal,
  439. "total": total,
  440. })
  441. return
  442. }
  443. //获取患者押金列表
  444. func (this *HisDepositApiController) GetUserList() {
  445. orgid := this.GetAdminUserInfo().CurrentOrgId
  446. keyword := this.GetString("keyword")
  447. page, _ := this.GetInt64("page") //页码
  448. limit, _ := this.GetInt64("limit") //每一页查出来的条数
  449. check := map[string][]string{
  450. "page": {"must", "string", "page"},
  451. "limit": {"must", "string", "limit"},
  452. }
  453. _, err := checks(this, &check)
  454. if err != nil {
  455. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  456. return
  457. }
  458. namemap := make(map[int64]string)
  459. slicekey := make([]int64, 0)
  460. lists, _ := service.GetHisUser(orgid)
  461. for _, v := range lists {
  462. namemap[v.ID] = v.Name
  463. }
  464. if len(keyword) > 0 {
  465. for k, v := range namemap {
  466. res := strings.Contains(v, keyword)
  467. if res == true {
  468. slicekey = append(slicekey, k)
  469. }
  470. }
  471. }
  472. list, total, errs := service.GetUserList(page, limit, orgid, keyword, slicekey)
  473. if errs != nil {
  474. utils.ErrorLog(errs.Error())
  475. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  476. return
  477. }
  478. for i := 0; i < len(list); i++ {
  479. list[i].HisPatientName = namemap[list[i].HisPatientId]
  480. }
  481. this.ServeSuccessJSON(map[string]interface{}{
  482. "list": list,
  483. "total": total,
  484. })
  485. return
  486. }
  487. //扣费明细查询
  488. func (this *HisDepositApiController) DeductionDetails() {
  489. orgid := this.GetAdminUserInfo().CurrentOrgId
  490. //orgid = 9675
  491. timeLayout := "2006-01-02"
  492. loc, _ := time.LoadLocation("Local")
  493. keyword := this.GetString("keyword")
  494. start_time := this.GetString("start_time")
  495. end_time := this.GetString("end_time")
  496. var stime int64 //开始时间
  497. var etime int64 //结束时间
  498. namemap := make(map[int64]string)
  499. slicekey := make([]int64, 0)
  500. lists, _ := service.GetHisUser(orgid)
  501. for _, v := range lists {
  502. namemap[v.ID] = v.Name
  503. }
  504. if len(keyword) > 0 {
  505. for k, v := range namemap {
  506. res := strings.Contains(v, keyword)
  507. if res == true {
  508. slicekey = append(slicekey, k)
  509. }
  510. }
  511. }
  512. if start_time == "" && end_time == "" {
  513. _, etime = service.GetMondayOfWeek()
  514. stime = 0
  515. } else {
  516. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  517. etmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  518. stime = stmp.Unix()
  519. etime = etmp.Unix()
  520. }
  521. list, err := service.DeductionList(orgid, stime, etime, keyword, slicekey)
  522. if err != nil {
  523. utils.ErrorLog(err.Error())
  524. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  525. return
  526. }
  527. var sum decimal.Decimal
  528. var detailslist []models.Details
  529. var details models.Details
  530. for i := 0; i < len(list); i++ {
  531. sum = sum.Add(list[i].Deposit)
  532. tmp_id, _ := strconv.ParseInt(list[i].DepositCode, 10, 64)
  533. details.ID = tmp_id
  534. details.Code = service.FindcodeToid(tmp_id)
  535. details.NameId = list[i].HisPatientId
  536. details.Name = namemap[list[i].HisPatientId]
  537. details.Number = service.FindnumberToid(tmp_id)
  538. details.Decimal = list[i].Deposit
  539. details.ChargeDate = fmt.Sprintf(time.Unix(list[i].Ctime, 0).Format("2006-01-02 15:04:05"))
  540. details.Chargetype = service.CodeToChargetype(orgid, details.Code)
  541. details.Total = service.MedicalTotal(orgid, tmp_id)
  542. details.ButtonShow = service.IsButtonShow(list[i].DepositCode, orgid, list[i].HisPatientId)
  543. detailslist = append(detailslist, details)
  544. }
  545. this.ServeSuccessJSON(map[string]interface{}{
  546. "list": detailslist,
  547. "sum": sum,
  548. })
  549. return
  550. }
  551. //扣费汇总
  552. func (this *HisDepositApiController) DeSummary() {
  553. orgid := this.GetAdminUserInfo().CurrentOrgId
  554. orgid = 9675
  555. timeLayout := "2006-01-02"
  556. loc, _ := time.LoadLocation("Local")
  557. keyword := this.GetString("keyword")
  558. start_time := this.GetString("start_time")
  559. end_time := this.GetString("end_time")
  560. var stime int64 //开始时间
  561. var etime int64 //结束时间
  562. namemap := make(map[int64]string)
  563. slicekey := make([]int64, 0)
  564. lists, _ := service.GetHisUser(orgid)
  565. for _, v := range lists {
  566. namemap[v.ID] = v.Name
  567. }
  568. if len(keyword) > 0 {
  569. for k, v := range namemap {
  570. res := strings.Contains(v, keyword)
  571. if res == true {
  572. slicekey = append(slicekey, k)
  573. }
  574. }
  575. }
  576. if start_time == "" && end_time == "" {
  577. _, etime = service.GetMondayOfWeek()
  578. stime = 0
  579. } else {
  580. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  581. etmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  582. stime = stmp.Unix()
  583. etime = etmp.Unix()
  584. }
  585. list, err := service.DeductionList(orgid, stime, etime, keyword, slicekey)
  586. if err != nil {
  587. utils.ErrorLog(err.Error())
  588. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  589. return
  590. }
  591. var sum decimal.Decimal
  592. var detailslist []models.DeductionSummary
  593. var details models.DeductionSummary
  594. for i := 0; i < len(list); i++ {
  595. sum = sum.Add(list[i].Deposit)
  596. details.Name = namemap[list[i].HisPatientId]
  597. details.Decimal = list[i].Deposit
  598. tmp_id, _ := strconv.ParseInt(list[i].DepositCode, 10, 64)
  599. details.Total = service.MedicalTotal(orgid, tmp_id)
  600. detailslist = append(detailslist, details)
  601. }
  602. maplist := make(map[string]models.DeductionSummary)
  603. Finlist := []models.DeductionSummary{}
  604. tmpslice := make([]string, 0)
  605. for i := 0; i < len(detailslist); i++ {
  606. if k, ok := maplist[detailslist[i].Name]; ok {
  607. k.Total = k.Total.Add(detailslist[i].Total)
  608. k.Decimal = k.Decimal.Add(detailslist[i].Decimal)
  609. maplist[detailslist[i].Name] = models.DeductionSummary{
  610. detailslist[i].Name,
  611. k.Total,
  612. k.Decimal,
  613. }
  614. } else {
  615. maplist[detailslist[i].Name] = models.DeductionSummary{
  616. detailslist[i].Name,
  617. detailslist[i].Total,
  618. detailslist[i].Decimal,
  619. }
  620. tmpslice = append(tmpslice, detailslist[i].Name)
  621. }
  622. }
  623. for i := 0; i < len(tmpslice); i++ {
  624. Finlist = append(Finlist, maplist[tmpslice[i]])
  625. }
  626. this.ServeSuccessJSON(map[string]interface{}{
  627. "list": Finlist,
  628. "sum": sum,
  629. })
  630. return
  631. }
  632. //根据患者id查询患者的余额
  633. func (this *HisDepositApiController) IdToBalance() {
  634. check := map[string][]string{
  635. "his_patient_id": {"must", "int", "his_patient_id"},
  636. }
  637. _, err := checks(this, &check)
  638. if err != nil {
  639. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  640. return
  641. }
  642. orgid := this.GetAdminUserInfo().CurrentOrgId
  643. his_patient_id, _ := this.GetInt64("his_patient_id")
  644. tmp := service.GetUserMoney(his_patient_id, orgid)
  645. this.ServeSuccessJSON(map[string]interface{}{
  646. "list": tmp,
  647. })
  648. return
  649. }
  650. //新增一条退款申请
  651. func (this *HisDepositApiController) RefundApplication() {
  652. orgid := this.GetAdminUserInfo().CurrentOrgId
  653. createid := this.GetAdminUserInfo().AdminUser.Id
  654. dataBody := make(map[string]interface{}, 0)
  655. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  656. if err != nil {
  657. utils.ErrorLog(err.Error())
  658. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  659. return
  660. }
  661. switch {
  662. case dataBody["code"] == nil:
  663. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "申请编号不能为空")
  664. return
  665. case dataBody["his_patient_id"] == nil:
  666. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "患者名称不能为空")
  667. return
  668. case dataBody["deposit"] == nil || dataBody["deposit"] == "":
  669. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "退款金额不能为空")
  670. return
  671. case dataBody["trial_status"] == nil:
  672. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "审核状态不能为空")
  673. return
  674. }
  675. code := dataBody["code"].(string) //申请编号
  676. his_patient_id := int64(dataBody["his_patient_id"].(float64)) //患者编号
  677. //deposit := decimal.NewFromFloat(dataBody["deposit"].(float64)) //退款金额
  678. var tmps float64
  679. switch dataBody["deposit"].(type) {
  680. case string:
  681. t_deposit := dataBody["deposit"].(string)
  682. if len(t_deposit) > 0 {
  683. if t_deposit[0] == 45 {
  684. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "退款金额错误")
  685. return
  686. }
  687. }
  688. tt, errs := strconv.ParseFloat(t_deposit, 64)
  689. if errs != nil {
  690. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "退款金额错误")
  691. return
  692. } else {
  693. tmps = tt
  694. }
  695. default:
  696. tmps = dataBody["deposit"].(float64)
  697. }
  698. if tmps == 0 {
  699. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "退款金额不能为0")
  700. return
  701. }
  702. deposit := decimal.NewFromFloat(tmps) //押金金额
  703. trial_status := int64(dataBody["trial_status"].(float64)) //审核状态
  704. err = service.RefundApplication(orgid, his_patient_id, trial_status, createid, code, deposit)
  705. if err != nil {
  706. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  707. return
  708. }
  709. this.ServeSuccessJSON(map[string]interface{}{
  710. "list": "新增成功",
  711. })
  712. return
  713. }
  714. //退款审核通过/拒绝
  715. func (this *HisDepositApiController) RefundReview() {
  716. check := map[string][]string{
  717. "ids": {"must", "string", "ids"},
  718. "trial_status": {"must", "int", "trial_status"},
  719. }
  720. _, err := checks(this, &check)
  721. if err != nil {
  722. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  723. return
  724. }
  725. orgid := this.GetAdminUserInfo().CurrentOrgId
  726. ids := this.GetString("ids") //很多id
  727. trial_status, _ := this.GetInt64("trial_status")
  728. if trial_status != 1 && trial_status != 2 {
  729. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数trial_status值错误")
  730. return
  731. }
  732. err = service.RefundReviewMore(orgid, trial_status, ids)
  733. if err != nil {
  734. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  735. return
  736. }
  737. var tmplist string
  738. if trial_status == 1 {
  739. tmplist = "审核通过"
  740. } else {
  741. tmplist = "审核拒绝"
  742. }
  743. this.ServeSuccessJSON(map[string]interface{}{
  744. "list": tmplist,
  745. })
  746. return
  747. }
  748. //退款删除
  749. func (this *HisDepositApiController) DeleteRefund() {
  750. check := map[string][]string{
  751. "id": {"must", "int", "id"},
  752. }
  753. _, err := checks(this, &check)
  754. if err != nil {
  755. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  756. return
  757. }
  758. orgid := this.GetAdminUserInfo().CurrentOrgId
  759. id, _ := this.GetInt64("id")
  760. err = service.DeleteRefund(orgid, id)
  761. if err != nil {
  762. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  763. return
  764. }
  765. this.ServeSuccessJSON(map[string]interface{}{
  766. "list": "删除成功",
  767. })
  768. return
  769. }
  770. //更改退款申请
  771. func (this *HisDepositApiController) ChangeRefund() {
  772. orgid := this.GetAdminUserInfo().CurrentOrgId
  773. dataBody := make(map[string]interface{}, 0)
  774. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  775. if err != nil {
  776. utils.ErrorLog(err.Error())
  777. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  778. return
  779. }
  780. switch {
  781. case dataBody["id"] == nil:
  782. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "id不能为空")
  783. return
  784. case dataBody["code"] == nil:
  785. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "申请编号不能为空")
  786. return
  787. case dataBody["his_patient_id"] == nil:
  788. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "患者名称不能为空")
  789. return
  790. case dataBody["deposit"] == nil || dataBody["deposit"] == "":
  791. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "退款金额不能为空")
  792. return
  793. case dataBody["trial_status"] == nil:
  794. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "审核状态不能为空")
  795. return
  796. }
  797. id := int64(dataBody["id"].(float64))
  798. code := dataBody["code"].(string) //申请编号
  799. his_patient_id := int64(dataBody["his_patient_id"].(float64)) //患者编号
  800. //deposit := decimal.NewFromFloat(dataBody["deposit"].(float64)) //退款金额
  801. var tmps float64
  802. switch dataBody["deposit"].(type) {
  803. case string:
  804. t_deposit := dataBody["deposit"].(string)
  805. if len(t_deposit) > 0 {
  806. if t_deposit[0] == 45 {
  807. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "退款金额错误")
  808. return
  809. }
  810. }
  811. tt, errs := strconv.ParseFloat(t_deposit, 64)
  812. if errs != nil {
  813. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "退款金额错误")
  814. return
  815. } else {
  816. tmps = tt
  817. }
  818. default:
  819. tmps = dataBody["deposit"].(float64)
  820. }
  821. if tmps == 0 {
  822. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "退款金额不能为0")
  823. return
  824. }
  825. deposit := decimal.NewFromFloat(tmps) //押金金额
  826. trial_status := int64(dataBody["trial_status"].(float64)) //审核状态
  827. err = service.ChangeRefund(orgid, his_patient_id, trial_status, id, code, deposit)
  828. if err != nil {
  829. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  830. return
  831. }
  832. this.ServeSuccessJSON(map[string]interface{}{
  833. "list": "保存成功",
  834. })
  835. return
  836. }
  837. //退款分页
  838. func (this *HisDepositApiController) RefundList() {
  839. check := map[string][]string{
  840. "refundtype": {"must", "int", "refundtype"},
  841. "examinetype": {"must", "int", "examinetype"},
  842. "page": {"must", "string", "page"},
  843. "limit": {"must", "string", "limit"},
  844. }
  845. _, err := checks(this, &check)
  846. if err != nil {
  847. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  848. return
  849. }
  850. orgid := this.GetAdminUserInfo().CurrentOrgId
  851. timeLayout := "2006-01-02"
  852. loc, _ := time.LoadLocation("Local")
  853. keyword := this.GetString("keyword") //获取搜索框
  854. refundtype, _ := this.GetInt64("refundtype") //获取退款类型
  855. examinetype, _ := this.GetInt64("examinetype") //获取审核状态
  856. page, _ := this.GetInt64("page") //页码
  857. limit, _ := this.GetInt64("limit") //每一页查出来的条数
  858. start_time := this.GetString("start_time")
  859. end_time := this.GetString("end_time")
  860. var stime int64 //开始时间
  861. var etime int64 //结束时间
  862. namemap := make(map[int64]string)
  863. slicekey := make([]int64, 0)
  864. lists, _ := service.GetHisUser(orgid)
  865. for _, v := range lists {
  866. namemap[v.ID] = v.Name
  867. }
  868. if len(keyword) > 0 {
  869. for k, v := range namemap {
  870. res := strings.Contains(v, keyword)
  871. if res == true {
  872. slicekey = append(slicekey, k)
  873. }
  874. }
  875. }
  876. if start_time == "" && end_time == "" {
  877. stime, etime = service.GetMondayOfWeek()
  878. stime = 0
  879. } else {
  880. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  881. etmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  882. stime = stmp.Unix()
  883. etime = etmp.Unix()
  884. }
  885. depo := []models.RefundList{}
  886. var total int64
  887. depo, total, err = service.RefundList(page, limit, orgid, stime, etime, refundtype, examinetype, keyword, slicekey)
  888. if err != nil {
  889. utils.ErrorLog("查询失败,原因为:", err.Error())
  890. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  891. return
  892. }
  893. for i := 0; i < len(depo); i++ {
  894. depo[i].Name = service.GetCreateidName(depo[i].CreateId)
  895. depo[i].HisName = namemap[depo[i].HisPatientId]
  896. if depo[i].Mtime > depo[i].Ctime {
  897. depo[i].Starttime = fmt.Sprintf(time.Unix(depo[i].Mtime, 0).Format("2006-01-02 15:04:05"))
  898. } else {
  899. depo[i].Starttime = fmt.Sprintf(time.Unix(depo[i].Ctime, 0).Format("2006-01-02 15:04:05"))
  900. }
  901. if depo[i].DepositStatus == 4 {
  902. depo[i].Name = "-"
  903. tmpcode, _ := strconv.ParseInt(depo[i].DepositCode, 10, 64)
  904. depo[i].DepositCode = service.FindcodeToid(tmpcode)
  905. }
  906. }
  907. this.ServeSuccessJSON(map[string]interface{}{
  908. "list": depo,
  909. "total": total,
  910. })
  911. return
  912. }
  913. func (this *HisDepositApiController) GetorgName() {
  914. orgid := this.GetAdminUserInfo().CurrentOrgId
  915. name := service.GetorgName(orgid)
  916. this.ServeSuccessJSON(map[string]interface{}{
  917. "list": name,
  918. })
  919. return
  920. }
  921. //获取本月时间
  922. func (this *HisDepositApiController) GetMonthTime() {
  923. stime, etime := service.GetMonth()
  924. srart_time := fmt.Sprintf(time.Unix(stime, 0).Format("2006-01-02"))
  925. end_time := fmt.Sprintf(time.Unix(etime, 0).Format("2006-01-02"))
  926. this.ServeSuccessJSON(map[string]interface{}{
  927. "srart_time": srart_time,
  928. "end_time": end_time,
  929. })
  930. return
  931. }
  932. //获取本周时间
  933. func (this *HisDepositApiController) GetWeekTime() {
  934. stime, etime := service.GetMondayOfWeek()
  935. srart_time := fmt.Sprintf(time.Unix(stime, 0).Format("2006-01-02"))
  936. end_time := fmt.Sprintf(time.Unix(etime, 0).Format("2006-01-02"))
  937. this.ServeSuccessJSON(map[string]interface{}{
  938. "srart_time": srart_time,
  939. "end_time": end_time,
  940. })
  941. return
  942. }
  943. //判断前端参数是否为空
  944. func checks(this *HisDepositApiController, m *map[string][]string) (map[string]string, error) {
  945. tmp := make(map[string]string)
  946. for k, v := range *m {
  947. t := this.GetString(k)
  948. if v[0] == "must" && t == "" {
  949. return nil, fmt.Errorf(v[2] + "不能为空")
  950. }
  951. tmp[k] = t
  952. }
  953. return tmp, nil
  954. }