123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435 |
- package controllers
-
- import (
- "XT_New/enums"
- "XT_New/models"
- "XT_New/service"
- "XT_New/utils"
- "encoding/json"
- "fmt"
- "github.com/astaxie/beego"
- "github.com/shopspring/decimal"
- "strings"
- "time"
- )
-
- type HisDepositApiController struct {
- BaseAuthAPIController
- }
-
- func HisDepositApiRegistRouters() {
- beego.Router("/api/his/ttt", &HisDepositApiController{}, "get:TTT")
- beego.Router("/api/his/gethisuser", &HisDepositApiController{}, "get:GetHisUser")
- beego.Router("/api/his/adddeposit", &HisDepositApiController{}, "post:AddDeposit")
- beego.Router("/api/his/getdepositcode", &HisDepositApiController{}, "get:GetDepositCode")
- beego.Router("/api/his/getdeletecode", &HisDepositApiController{}, "get:GetDeleteCode")
- beego.Router("/api/his/rechargedetails", &HisDepositApiController{}, "get:RechargeDetails")
- beego.Router("/api/his/updeposit", &HisDepositApiController{}, "get:UpDeposit")
- beego.Router("/api/his/deletehistory", &HisDepositApiController{}, "get:DeleteHistory")
- beego.Router("/api/his/rechargesummary", &HisDepositApiController{}, "get:RechargeSummary")
- beego.Router("/api/his/getuserlist", &HisDepositApiController{}, "get:GetUserList")
- beego.Router("/api/his/depositflow", &HisDepositApiController{}, "get:DepositFlow")
- }
- func (this *HisDepositApiController) TTT() {
- id, _ := this.GetInt64("id")
- err := service.DelDecimalHistory(id)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": err,
- })
- return
- }
-
-
- func (this *HisDepositApiController) GetHisUser() {
- orgid := this.GetAdminUserInfo().CurrentOrgId
- list, err := service.GetHisUser(orgid)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- return
- }
-
-
- func (this *HisDepositApiController) AddDeposit() {
- orgid := this.GetAdminUserInfo().CurrentOrgId
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- switch {
- case dataBody["code"] == nil:
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金编号不能为空")
- return
- case dataBody["his_patient_id"] == nil:
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "患者名称不能为空")
- return
- case dataBody["deposit"] == nil:
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金金额不能为空")
- return
- case dataBody["trial_status"] == nil:
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "审核状态不能为空")
- return
- }
- code := dataBody["code"].(string)
- his_patient_id := int64(dataBody["his_patient_id"].(float64))
- deposit := decimal.NewFromFloat(dataBody["deposit"].(float64))
- var remarks string
- if dataBody["remarks"] == nil {
- remarks = ""
- } else {
- remarks = dataBody["remarks"].(string)
- }
- trial_status := int64(dataBody["trial_status"].(float64))
- createid := this.GetAdminUserInfo().AdminUser.Id
- pp := this.GetAdminUserInfo()
- fmt.Println(pp)
- err = service.UpDeposit(code, remarks, his_patient_id, orgid, trial_status, createid, deposit)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": "添加成功",
- })
- return
- }
-
-
- func (this *HisDepositApiController) GetDepositCode() {
- orgid := this.GetAdminUserInfo().CurrentOrgId
- var code string
- for a := true; a == true; {
- code = service.CreateCPCode("CP")
- tmp := service.FindDecimalCode(orgid, code)
- if tmp == false {
- a = false
- }
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": code,
- })
- return
- }
-
-
- func (this *HisDepositApiController) GetDeleteCode() {
- orgid := this.GetAdminUserInfo().CurrentOrgId
- var code string
- for a := true; a == true; {
- code = service.CreateCPCode("AF")
- tmp := service.FindDecimalCode(orgid, code)
- if tmp == false {
- a = false
- }
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": code,
- })
- return
- }
-
-
- func (this *HisDepositApiController) RechargeDetails() {
- orgid := this.GetAdminUserInfo().CurrentOrgId
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- keyword := this.GetString("keyword")
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- var stime int64
- var etime int64
-
- namemap := make(map[int64]string)
- slicekey := make([]int64, 0)
- if len(keyword) > 0 {
- list, _ := service.GetHisUser(orgid)
- for _, v := range list {
- namemap[v.ID] = v.Name
- }
- for k, v := range namemap {
- res := strings.Contains(v, keyword)
- if res == true {
- slicekey = append(slicekey, k)
- }
- }
- }
- if start_time == "" && end_time == "" {
- stime, etime = service.GetMondayOfWeek()
- } else {
- stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- etmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- stime = stmp.Unix()
- etime = etmp.Unix()
- }
- list, err := service.DetailsList(orgid, stime, etime, keyword, slicekey)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- var sum decimal.Decimal
- for i := 0; i < len(list); i++ {
- if list[i].TrialStatus == 1 {
- sum = sum.Add(list[i].Deposit)
- }
- list[i].Name = service.GetCreateidName(list[i].CreateId)
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "sum": sum,
- })
- return
- }
-
-
- func (this *HisDepositApiController) RechargeSummary() {
- orgid := this.GetAdminUserInfo().CurrentOrgId
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- keyword := this.GetString("keyword")
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- var stime int64
- var etime int64
- namemap := make(map[int64]string)
- slicekey := make([]int64, 0)
- lists, _ := service.GetHisUser(orgid)
- for _, v := range lists {
- namemap[v.ID] = v.Name
- }
- if len(keyword) > 0 {
- for k, v := range namemap {
- res := strings.Contains(v, keyword)
- if res == true {
- slicekey = append(slicekey, k)
- }
- }
- }
- if start_time == "" && end_time == "" {
- stime, etime = service.GetMondayOfWeek()
- } else {
- stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- etmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- stime = stmp.Unix()
- etime = etmp.Unix()
- }
- list, err := service.SummaryList(orgid, stime, etime, keyword, slicekey)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- maplist := make(map[int64]models.Summary)
- Finlist := []models.Summary{}
- tmpslice := make([]int64, 0)
- var sum decimal.Decimal
- for i := 0; i < len(list); i++ {
- if list[i].TrialStatus == 1 {
- if k, ok := maplist[list[i].HisPatientId]; ok {
- k.SumDecimal = k.SumDecimal.Add(list[i].Deposit)
- maplist[list[i].HisPatientId] = models.Summary{
- namemap[list[i].HisPatientId],
- k.SumDecimal,
- service.GetUserMoney(list[i].HisPatientId, orgid),
- }
- } else {
- maplist[list[i].HisPatientId] = models.Summary{
- namemap[list[i].HisPatientId],
- list[i].Deposit,
- service.GetUserMoney(list[i].HisPatientId, orgid),
- }
- tmpslice = append(tmpslice, list[i].HisPatientId)
- }
- sum = sum.Add(list[i].Deposit)
- }
- }
-
- for i := 0; i < len(tmpslice); i++ {
- Finlist = append(Finlist, maplist[tmpslice[i]])
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": Finlist,
- "sum": sum,
- })
- return
- }
-
-
- func (this *HisDepositApiController) UpDeposit() {
- id, _ := this.GetInt64("id", 0)
- if id == 0 {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "id不能为空")
- return
- }
- tmp, err := service.GetDecimalHistoryOne(id)
- if err != nil {
- utils.ErrorLog("无法查询该记录信息", err.Error())
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "无法查询该记录信息")
- return
- }
- if tmp.TrialStatus == 0 {
- err = service.UpDecimalHistory(id)
- if err != nil {
- utils.ErrorLog("更新押金历史表出错,原因为:", err.Error())
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "系统错误")
- return
- }
- } else {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "当前状态不可审核")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": "审核通过",
- })
- return
- }
- func (this *HisDepositApiController) DeleteHistory() {
- id, _ := this.GetInt64("id", 0)
- if id == 0 {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "id不能为空")
- return
- }
- tmp, err := service.GetDecimalHistoryOne(id)
- if err != nil {
- utils.ErrorLog("无法查询该记录信息", err.Error())
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "无法查询该记录信息")
- return
- }
- if tmp.TrialStatus == 0 {
- err = service.DelDecimalHistory(id)
- if err != nil {
- utils.ErrorLog("删除历史记录出错,原因为:", err.Error())
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "系统错误")
- return
- }
- } else {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "已审核的单据不能进行删除操作")
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": "删除成功",
- })
- return
- }
-
-
- func (this *HisDepositApiController) DepositFlow() {
- orgid := this.GetAdminUserInfo().CurrentOrgId
- check := map[string][]string{
- "id": {"must", "int", "id"},
- "deposit_status": {"must", "int", "deposit_status"},
- }
- _, err := checks(this, &check)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- id, _ := this.GetInt64("id")
-
- tmp, _ := service.GetHisUserName(orgid, id)
- name := tmp.Name
- deposit_status, _ := this.GetInt64("deposit_status", 0)
- if deposit_status > 3 {
- utils.ErrorLog("押金类型错误,deposit_status:", deposit_status)
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金类型错误")
- return
- }
- start_time := this.GetString("start_time", "")
- end_time := this.GetString("end_time", "")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var stime int64
- var etime int64
- if start_time == "" && end_time == "" {
- stime, etime = service.GetMonth()
- } else {
- stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- etmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- stime = stmp.Unix()
- etime = etmp.Unix()
- }
-
- decimal := service.GetMoneyforTime(id, orgid, etime)
-
- deposirhistory, errs := service.GetFlowList(id, orgid, stime, etime, deposit_status)
- if errs != nil {
- utils.ErrorLog("获取列表失败,原因为:", errs.Error())
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, errs.Error())
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": deposirhistory,
- "name": name,
- "decimal": decimal,
- })
- return
- }
-
-
- func (this *HisDepositApiController) GetUserList() {
- orgid := this.GetAdminUserInfo().CurrentOrgId
- keyword := this.GetString("keyword")
- page, _ := this.GetInt64("page")
- limit, _ := this.GetInt64("limit")
- check := map[string][]string{
- "page": {"must", "string", "page"},
- "limit": {"must", "string", "limit"},
- }
- _, err := checks(this, &check)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- namemap := make(map[int64]string)
- slicekey := make([]int64, 0)
- lists, _ := service.GetHisUser(orgid)
- for _, v := range lists {
- namemap[v.ID] = v.Name
- }
- if len(keyword) > 0 {
- for k, v := range namemap {
- res := strings.Contains(v, keyword)
- if res == true {
- slicekey = append(slicekey, k)
- }
- }
- }
- list, total, errs := service.GetUserList(page, limit, orgid, keyword, slicekey)
- if errs != nil {
- utils.ErrorLog(errs.Error())
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- for i := 0; i < len(list); i++ {
- list[i].HisPatientName = namemap[list[i].HisPatientId]
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "total": total,
- })
- return
- }
-
-
- func checks(this *HisDepositApiController, m *map[string][]string) (map[string]string, error) {
- tmp := make(map[string]string)
- for k, v := range *m {
- t := this.GetString(k)
- if v[0] == "must" && t == "" {
- return nil, fmt.Errorf(v[2] + "不能为空")
- }
- tmp[k] = t
- }
- return tmp, nil
- }
|