his_deposit_controller.go 31KB

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