his_deposit_controller.go 30KB

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