his_deposit_controller.go 31KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993
  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, orgid)
  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. timeLayout := "2006-01-02"
  555. loc, _ := time.LoadLocation("Local")
  556. keyword := this.GetString("keyword")
  557. start_time := this.GetString("start_time")
  558. end_time := this.GetString("end_time")
  559. var stime int64 //开始时间
  560. var etime int64 //结束时间
  561. namemap := make(map[int64]string)
  562. slicekey := make([]int64, 0)
  563. lists, _ := service.GetHisUser(orgid)
  564. for _, v := range lists {
  565. namemap[v.ID] = v.Name
  566. }
  567. if len(keyword) > 0 {
  568. for k, v := range namemap {
  569. res := strings.Contains(v, keyword)
  570. if res == true {
  571. slicekey = append(slicekey, k)
  572. }
  573. }
  574. }
  575. if start_time == "" && end_time == "" {
  576. _, etime = service.GetMondayOfWeek()
  577. stime = 0
  578. } else {
  579. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  580. etmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  581. stime = stmp.Unix()
  582. etime = etmp.Unix()
  583. }
  584. list, err := service.DeductionList(orgid, stime, etime, keyword, slicekey)
  585. if err != nil {
  586. utils.ErrorLog(err.Error())
  587. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  588. return
  589. }
  590. var sum decimal.Decimal
  591. var detailslist []models.DeductionSummary
  592. var details models.DeductionSummary
  593. for i := 0; i < len(list); i++ {
  594. sum = sum.Add(list[i].Deposit)
  595. details.Name = namemap[list[i].HisPatientId]
  596. details.Decimal = list[i].Deposit
  597. tmp_id, _ := strconv.ParseInt(list[i].DepositCode, 10, 64)
  598. details.Total = service.MedicalTotal(orgid, tmp_id)
  599. detailslist = append(detailslist, details)
  600. }
  601. maplist := make(map[string]models.DeductionSummary)
  602. Finlist := []models.DeductionSummary{}
  603. tmpslice := make([]string, 0)
  604. for i := 0; i < len(detailslist); i++ {
  605. if k, ok := maplist[detailslist[i].Name]; ok {
  606. k.Total = k.Total.Add(detailslist[i].Total)
  607. k.Decimal = k.Decimal.Add(detailslist[i].Decimal)
  608. maplist[detailslist[i].Name] = models.DeductionSummary{
  609. detailslist[i].Name,
  610. k.Total,
  611. k.Decimal,
  612. }
  613. } else {
  614. maplist[detailslist[i].Name] = models.DeductionSummary{
  615. detailslist[i].Name,
  616. detailslist[i].Total,
  617. detailslist[i].Decimal,
  618. }
  619. tmpslice = append(tmpslice, detailslist[i].Name)
  620. }
  621. }
  622. for i := 0; i < len(tmpslice); i++ {
  623. Finlist = append(Finlist, maplist[tmpslice[i]])
  624. }
  625. this.ServeSuccessJSON(map[string]interface{}{
  626. "list": Finlist,
  627. "sum": sum,
  628. })
  629. return
  630. }
  631. //根据患者id查询患者的余额
  632. func (this *HisDepositApiController) IdToBalance() {
  633. check := map[string][]string{
  634. "his_patient_id": {"must", "int", "his_patient_id"},
  635. }
  636. _, err := checks(this, &check)
  637. if err != nil {
  638. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  639. return
  640. }
  641. orgid := this.GetAdminUserInfo().CurrentOrgId
  642. his_patient_id, _ := this.GetInt64("his_patient_id")
  643. tmp := service.GetUserMoney(his_patient_id, orgid)
  644. this.ServeSuccessJSON(map[string]interface{}{
  645. "list": tmp,
  646. })
  647. return
  648. }
  649. //新增一条退款申请
  650. func (this *HisDepositApiController) RefundApplication() {
  651. orgid := this.GetAdminUserInfo().CurrentOrgId
  652. createid := this.GetAdminUserInfo().AdminUser.Id
  653. dataBody := make(map[string]interface{}, 0)
  654. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  655. if err != nil {
  656. utils.ErrorLog(err.Error())
  657. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  658. return
  659. }
  660. switch {
  661. case dataBody["code"] == nil:
  662. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "申请编号不能为空")
  663. return
  664. case dataBody["his_patient_id"] == nil:
  665. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "患者名称不能为空")
  666. return
  667. case dataBody["deposit"] == nil || dataBody["deposit"] == "":
  668. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "退款金额不能为空")
  669. return
  670. case dataBody["trial_status"] == nil:
  671. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "审核状态不能为空")
  672. return
  673. }
  674. code := dataBody["code"].(string) //申请编号
  675. his_patient_id := int64(dataBody["his_patient_id"].(float64)) //患者编号
  676. //deposit := decimal.NewFromFloat(dataBody["deposit"].(float64)) //退款金额
  677. var tmps float64
  678. switch dataBody["deposit"].(type) {
  679. case string:
  680. t_deposit := dataBody["deposit"].(string)
  681. if len(t_deposit) > 0 {
  682. if t_deposit[0] == 45 {
  683. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "退款金额错误")
  684. return
  685. }
  686. }
  687. tt, errs := strconv.ParseFloat(t_deposit, 64)
  688. if errs != nil {
  689. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "退款金额错误")
  690. return
  691. } else {
  692. tmps = tt
  693. }
  694. default:
  695. tmps = dataBody["deposit"].(float64)
  696. }
  697. if tmps == 0 {
  698. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "退款金额不能为0")
  699. return
  700. }
  701. deposit := decimal.NewFromFloat(tmps) //押金金额
  702. trial_status := int64(dataBody["trial_status"].(float64)) //审核状态
  703. err = service.RefundApplication(orgid, his_patient_id, trial_status, createid, code, deposit)
  704. if err != nil {
  705. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  706. return
  707. }
  708. this.ServeSuccessJSON(map[string]interface{}{
  709. "list": "新增成功",
  710. })
  711. return
  712. }
  713. //退款审核通过/拒绝
  714. func (this *HisDepositApiController) RefundReview() {
  715. check := map[string][]string{
  716. "ids": {"must", "string", "ids"},
  717. "trial_status": {"must", "int", "trial_status"},
  718. }
  719. _, err := checks(this, &check)
  720. if err != nil {
  721. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  722. return
  723. }
  724. orgid := this.GetAdminUserInfo().CurrentOrgId
  725. ids := this.GetString("ids") //很多id
  726. trial_status, _ := this.GetInt64("trial_status")
  727. if trial_status != 1 && trial_status != 2 {
  728. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数trial_status值错误")
  729. return
  730. }
  731. err = service.RefundReviewMore(orgid, trial_status, ids)
  732. if err != nil {
  733. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  734. return
  735. }
  736. var tmplist string
  737. if trial_status == 1 {
  738. tmplist = "审核通过"
  739. } else {
  740. tmplist = "审核拒绝"
  741. }
  742. this.ServeSuccessJSON(map[string]interface{}{
  743. "list": tmplist,
  744. })
  745. return
  746. }
  747. //退款删除
  748. func (this *HisDepositApiController) DeleteRefund() {
  749. check := map[string][]string{
  750. "id": {"must", "int", "id"},
  751. }
  752. _, err := checks(this, &check)
  753. if err != nil {
  754. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  755. return
  756. }
  757. orgid := this.GetAdminUserInfo().CurrentOrgId
  758. id, _ := this.GetInt64("id")
  759. err = service.DeleteRefund(orgid, id)
  760. if err != nil {
  761. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  762. return
  763. }
  764. this.ServeSuccessJSON(map[string]interface{}{
  765. "list": "删除成功",
  766. })
  767. return
  768. }
  769. //更改退款申请
  770. func (this *HisDepositApiController) ChangeRefund() {
  771. orgid := this.GetAdminUserInfo().CurrentOrgId
  772. dataBody := make(map[string]interface{}, 0)
  773. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  774. if err != nil {
  775. utils.ErrorLog(err.Error())
  776. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  777. return
  778. }
  779. switch {
  780. case dataBody["id"] == nil:
  781. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "id不能为空")
  782. return
  783. case dataBody["code"] == nil:
  784. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "申请编号不能为空")
  785. return
  786. case dataBody["his_patient_id"] == nil:
  787. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "患者名称不能为空")
  788. return
  789. case dataBody["deposit"] == nil || dataBody["deposit"] == "":
  790. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "退款金额不能为空")
  791. return
  792. case dataBody["trial_status"] == nil:
  793. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "审核状态不能为空")
  794. return
  795. }
  796. id := int64(dataBody["id"].(float64))
  797. code := dataBody["code"].(string) //申请编号
  798. his_patient_id := int64(dataBody["his_patient_id"].(float64)) //患者编号
  799. //deposit := decimal.NewFromFloat(dataBody["deposit"].(float64)) //退款金额
  800. var tmps float64
  801. switch dataBody["deposit"].(type) {
  802. case string:
  803. t_deposit := dataBody["deposit"].(string)
  804. if len(t_deposit) > 0 {
  805. if t_deposit[0] == 45 {
  806. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "退款金额错误")
  807. return
  808. }
  809. }
  810. tt, errs := strconv.ParseFloat(t_deposit, 64)
  811. if errs != nil {
  812. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "退款金额错误")
  813. return
  814. } else {
  815. tmps = tt
  816. }
  817. default:
  818. tmps = dataBody["deposit"].(float64)
  819. }
  820. if tmps == 0 {
  821. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "退款金额不能为0")
  822. return
  823. }
  824. deposit := decimal.NewFromFloat(tmps) //押金金额
  825. trial_status := int64(dataBody["trial_status"].(float64)) //审核状态
  826. err = service.ChangeRefund(orgid, his_patient_id, trial_status, id, code, deposit)
  827. if err != nil {
  828. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  829. return
  830. }
  831. this.ServeSuccessJSON(map[string]interface{}{
  832. "list": "保存成功",
  833. })
  834. return
  835. }
  836. //退款分页
  837. func (this *HisDepositApiController) RefundList() {
  838. check := map[string][]string{
  839. "refundtype": {"must", "int", "refundtype"},
  840. "examinetype": {"must", "int", "examinetype"},
  841. "page": {"must", "string", "page"},
  842. "limit": {"must", "string", "limit"},
  843. }
  844. _, err := checks(this, &check)
  845. if err != nil {
  846. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  847. return
  848. }
  849. orgid := this.GetAdminUserInfo().CurrentOrgId
  850. timeLayout := "2006-01-02"
  851. loc, _ := time.LoadLocation("Local")
  852. keyword := this.GetString("keyword") //获取搜索框
  853. refundtype, _ := this.GetInt64("refundtype") //获取退款类型
  854. examinetype, _ := this.GetInt64("examinetype") //获取审核状态
  855. page, _ := this.GetInt64("page") //页码
  856. limit, _ := this.GetInt64("limit") //每一页查出来的条数
  857. start_time := this.GetString("start_time")
  858. end_time := this.GetString("end_time")
  859. var stime int64 //开始时间
  860. var etime int64 //结束时间
  861. namemap := make(map[int64]string)
  862. slicekey := make([]int64, 0)
  863. lists, _ := service.GetHisUser(orgid)
  864. for _, v := range lists {
  865. namemap[v.ID] = v.Name
  866. }
  867. if len(keyword) > 0 {
  868. for k, v := range namemap {
  869. res := strings.Contains(v, keyword)
  870. if res == true {
  871. slicekey = append(slicekey, k)
  872. }
  873. }
  874. }
  875. if start_time == "" && end_time == "" {
  876. stime, etime = service.GetMondayOfWeek()
  877. stime = 0
  878. } else {
  879. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  880. etmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  881. stime = stmp.Unix()
  882. etime = etmp.Unix()
  883. }
  884. depo := []models.RefundList{}
  885. var total int64
  886. depo, total, err = service.RefundList(page, limit, orgid, stime, etime, refundtype, examinetype, keyword, slicekey)
  887. if err != nil {
  888. utils.ErrorLog("查询失败,原因为:", err.Error())
  889. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  890. return
  891. }
  892. for i := 0; i < len(depo); i++ {
  893. depo[i].Name = service.GetCreateidName(depo[i].CreateId, orgid)
  894. depo[i].HisName = namemap[depo[i].HisPatientId]
  895. if depo[i].Mtime > depo[i].Ctime {
  896. depo[i].Starttime = fmt.Sprintf(time.Unix(depo[i].Mtime, 0).Format("2006-01-02 15:04:05"))
  897. } else {
  898. depo[i].Starttime = fmt.Sprintf(time.Unix(depo[i].Ctime, 0).Format("2006-01-02 15:04:05"))
  899. }
  900. if depo[i].DepositStatus == 4 {
  901. depo[i].Name = "-"
  902. tmpcode, _ := strconv.ParseInt(depo[i].DepositCode, 10, 64)
  903. depo[i].DepositCode = service.FindcodeToid(tmpcode)
  904. }
  905. }
  906. this.ServeSuccessJSON(map[string]interface{}{
  907. "list": depo,
  908. "total": total,
  909. })
  910. return
  911. }
  912. func (this *HisDepositApiController) GetorgName() {
  913. orgid := this.GetAdminUserInfo().CurrentOrgId
  914. name := service.GetorgName(orgid)
  915. this.ServeSuccessJSON(map[string]interface{}{
  916. "list": name,
  917. })
  918. return
  919. }
  920. //获取本月时间
  921. func (this *HisDepositApiController) GetMonthTime() {
  922. stime, etime := service.GetMonth()
  923. srart_time := fmt.Sprintf(time.Unix(stime, 0).Format("2006-01-02"))
  924. end_time := fmt.Sprintf(time.Unix(etime, 0).Format("2006-01-02"))
  925. this.ServeSuccessJSON(map[string]interface{}{
  926. "srart_time": srart_time,
  927. "end_time": end_time,
  928. })
  929. return
  930. }
  931. //获取本周时间
  932. func (this *HisDepositApiController) GetWeekTime() {
  933. stime, etime := service.GetMondayOfWeek()
  934. srart_time := fmt.Sprintf(time.Unix(stime, 0).Format("2006-01-02"))
  935. end_time := fmt.Sprintf(time.Unix(etime, 0).Format("2006-01-02"))
  936. this.ServeSuccessJSON(map[string]interface{}{
  937. "srart_time": srart_time,
  938. "end_time": end_time,
  939. })
  940. return
  941. }
  942. //判断前端参数是否为空
  943. func checks(this *HisDepositApiController, m *map[string][]string) (map[string]string, error) {
  944. tmp := make(map[string]string)
  945. for k, v := range *m {
  946. t := this.GetString(k)
  947. if v[0] == "must" && t == "" {
  948. return nil, fmt.Errorf(v[2] + "不能为空")
  949. }
  950. tmp[k] = t
  951. }
  952. return tmp, nil
  953. }