Quellcode durchsuchen

添加his押金管理相关文件

mainqaq vor 2 Jahren
Ursprung
Commit
c38bc29c0e
4 geänderte Dateien mit 834 neuen und 1 gelöschten Zeilen
  1. 433 0
      controllers/his_deposit_controller.go
  2. 96 0
      models/his_deposit_models.go
  3. 2 1
      routers/router.go
  4. 303 0
      service/his_deposit_service.go

+ 433 - 0
controllers/his_deposit_controller.go Datei anzeigen

1
 package controllers
1
 package controllers
2
+
3
+import (
4
+	"XT_New/enums"
5
+	"XT_New/models"
6
+	"XT_New/service"
7
+	"XT_New/utils"
8
+	"encoding/json"
9
+	"fmt"
10
+	"github.com/astaxie/beego"
11
+	"github.com/shopspring/decimal"
12
+	"strings"
13
+	"time"
14
+)
15
+
16
+type HisDepositApiController struct {
17
+	BaseAuthAPIController
18
+}
19
+
20
+func HisDepositApiRegistRouters() {
21
+	beego.Router("/api/his/ttt", &HisDepositApiController{}, "get:TTT")                         //测试接口
22
+	beego.Router("/api/his/gethisuser", &HisDepositApiController{}, "get:GetHisUser")           //获取病例中心,有效患者名称
23
+	beego.Router("/api/his/adddeposit", &HisDepositApiController{}, "post:AddDeposit")          //新增押金
24
+	beego.Router("/api/his/getdepositcode", &HisDepositApiController{}, "get:GetDepositCode")   //获取新增押金编号
25
+	beego.Router("/api/his/getdeletecode", &HisDepositApiController{}, "get:GetDeleteCode")     //获取退款编号
26
+	beego.Router("/api/his/rechargedetails", &HisDepositApiController{}, "get:RechargeDetails") //充值明细列表
27
+	beego.Router("/api/his/updeposit", &HisDepositApiController{}, "get:UpDeposit")             //审核
28
+	beego.Router("/api/his/deletehistory", &HisDepositApiController{}, "get:DeleteHistory")     //删除
29
+	beego.Router("/api/his/rechargesummary", &HisDepositApiController{}, "get:RechargeSummary") //充值汇总列表
30
+	beego.Router("/api/his/getuserlist", &HisDepositApiController{}, "get:GetUserList")         //获取患者押金列表
31
+	beego.Router("/api/his/depositflow", &HisDepositApiController{}, "get:DepositFlow")         //根据患者id获取押金流水
32
+}
33
+func (this *HisDepositApiController) TTT() {
34
+	id, _ := this.GetInt64("id")
35
+	err := service.DelDecimalHistory(id)
36
+	this.ServeSuccessJSON(map[string]interface{}{
37
+		"list": err,
38
+	})
39
+	return
40
+}
41
+
42
+//获取病例中心,有效患者名称
43
+func (this *HisDepositApiController) GetHisUser() {
44
+	orgid := this.GetAdminUserInfo().CurrentOrgId
45
+	list, err := service.GetHisUser(orgid)
46
+	if err != nil {
47
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
48
+		return
49
+	}
50
+	this.ServeSuccessJSON(map[string]interface{}{
51
+		"list": list,
52
+	})
53
+	return
54
+}
55
+
56
+//新增押金
57
+func (this *HisDepositApiController) AddDeposit() {
58
+	orgid := this.GetAdminUserInfo().CurrentOrgId
59
+	dataBody := make(map[string]interface{}, 0)
60
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
61
+	if err != nil {
62
+		utils.ErrorLog(err.Error())
63
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
64
+		return
65
+	}
66
+	switch {
67
+	case dataBody["code"] == nil:
68
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金编号不能为空")
69
+		return
70
+	case dataBody["his_patient_id"] == nil:
71
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "患者名称不能为空")
72
+		return
73
+	case dataBody["deposit"] == nil:
74
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金金额不能为空")
75
+		return
76
+	case dataBody["trial_status"] == nil:
77
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "审核状态不能为空")
78
+		return
79
+	}
80
+	code := dataBody["code"].(string)                              //押金编号
81
+	his_patient_id := int64(dataBody["his_patient_id"].(float64))  //患者编号
82
+	deposit := decimal.NewFromFloat(dataBody["deposit"].(float64)) //押金金额
83
+	var remarks string
84
+	if dataBody["remarks"] == nil {
85
+		remarks = ""
86
+	} else {
87
+		remarks = dataBody["remarks"].(string) //备注
88
+	}
89
+	trial_status := int64(dataBody["trial_status"].(float64)) //审核状态
90
+	createid := this.GetAdminUserInfo().AdminUser.Id
91
+	pp := this.GetAdminUserInfo()
92
+	fmt.Println(pp)
93
+	err = service.UpDeposit(code, remarks, his_patient_id, orgid, trial_status, createid, deposit)
94
+	if err != nil {
95
+		utils.ErrorLog(err.Error())
96
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
97
+		return
98
+	}
99
+	this.ServeSuccessJSON(map[string]interface{}{
100
+		"list": "添加成功",
101
+	})
102
+	return
103
+}
104
+
105
+//获取新增押金编号
106
+func (this *HisDepositApiController) GetDepositCode() {
107
+	orgid := this.GetAdminUserInfo().CurrentOrgId
108
+	var code string
109
+	for a := true; a == true; {
110
+		code = service.CreateCPCode("CP")
111
+		tmp := service.FindDecimalCode(orgid, code)
112
+		if tmp == false {
113
+			a = false
114
+		}
115
+	}
116
+	this.ServeSuccessJSON(map[string]interface{}{
117
+		"list": code,
118
+	})
119
+	return
120
+}
121
+
122
+//获取退款编号
123
+func (this *HisDepositApiController) GetDeleteCode() {
124
+	orgid := this.GetAdminUserInfo().CurrentOrgId
125
+	var code string
126
+	for a := true; a == true; {
127
+		code = service.CreateCPCode("AF")
128
+		tmp := service.FindDecimalCode(orgid, code)
129
+		if tmp == false {
130
+			a = false
131
+		}
132
+	}
133
+	this.ServeSuccessJSON(map[string]interface{}{
134
+		"list": code,
135
+	})
136
+	return
137
+}
138
+
139
+//充值明细列表
140
+func (this *HisDepositApiController) RechargeDetails() {
141
+	orgid := this.GetAdminUserInfo().CurrentOrgId
142
+	timeLayout := "2006-01-02"
143
+	loc, _ := time.LoadLocation("Local")
144
+	keyword := this.GetString("keyword")
145
+	start_time := this.GetString("start_time")
146
+	end_time := this.GetString("end_time")
147
+	var stime int64 //开始时间
148
+	var etime int64 //结束时间
149
+
150
+	namemap := make(map[int64]string)
151
+	slicekey := make([]int64, 0)
152
+	if len(keyword) > 0 {
153
+		list, _ := service.GetHisUser(orgid)
154
+		for _, v := range list {
155
+			namemap[v.ID] = v.Name
156
+		}
157
+		for k, v := range namemap {
158
+			res := strings.Contains(v, keyword)
159
+			if res == true {
160
+				slicekey = append(slicekey, k)
161
+			}
162
+		}
163
+	}
164
+	if start_time == "" && end_time == "" {
165
+		stime, etime = service.GetMondayOfWeek()
166
+	} else {
167
+		stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
168
+		etmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
169
+		stime = stmp.Unix()
170
+		etime = etmp.Unix()
171
+	}
172
+	list, err := service.DetailsList(orgid, stime, etime, keyword, slicekey)
173
+	if err != nil {
174
+		utils.ErrorLog(err.Error())
175
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
176
+		return
177
+	}
178
+	var sum decimal.Decimal
179
+	for i := 0; i < len(list); i++ {
180
+		if list[i].TrialStatus == 1 {
181
+			sum = sum.Add(list[i].Deposit)
182
+		}
183
+		list[i].Name = service.GetCreateidName(list[i].CreateId)
184
+	}
185
+	this.ServeSuccessJSON(map[string]interface{}{
186
+		"list": list,
187
+		"sum":  sum,
188
+	})
189
+	return
190
+}
191
+
192
+//充值汇总列表
193
+func (this *HisDepositApiController) RechargeSummary() {
194
+	orgid := this.GetAdminUserInfo().CurrentOrgId
195
+	timeLayout := "2006-01-02"
196
+	loc, _ := time.LoadLocation("Local")
197
+	keyword := this.GetString("keyword")
198
+	start_time := this.GetString("start_time")
199
+	end_time := this.GetString("end_time")
200
+	var stime int64 //开始时间
201
+	var etime int64 //结束时间
202
+	namemap := make(map[int64]string)
203
+	slicekey := make([]int64, 0)
204
+	lists, _ := service.GetHisUser(orgid)
205
+	for _, v := range lists {
206
+		namemap[v.ID] = v.Name
207
+	}
208
+	if len(keyword) > 0 {
209
+		for k, v := range namemap {
210
+			res := strings.Contains(v, keyword)
211
+			if res == true {
212
+				slicekey = append(slicekey, k)
213
+			}
214
+		}
215
+	}
216
+	if start_time == "" && end_time == "" {
217
+		stime, etime = service.GetMondayOfWeek()
218
+	} else {
219
+		stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
220
+		etmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
221
+		stime = stmp.Unix()
222
+		etime = etmp.Unix()
223
+	}
224
+	list, err := service.SummaryList(orgid, stime, etime, keyword, slicekey)
225
+	if err != nil {
226
+		utils.ErrorLog(err.Error())
227
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
228
+		return
229
+	}
230
+	//list为详细数据,把list整理合并为maplist输出
231
+	maplist := make(map[int64]models.Summary)
232
+	Finlist := []models.Summary{}
233
+	tmpslice := make([]int64, 0)
234
+	var sum decimal.Decimal
235
+	for i := 0; i < len(list); i++ {
236
+		if list[i].TrialStatus == 1 {
237
+			if k, ok := maplist[list[i].HisPatientId]; ok {
238
+				k.SumDecimal = k.SumDecimal.Add(list[i].Deposit)
239
+				maplist[list[i].HisPatientId] = models.Summary{
240
+					namemap[list[i].HisPatientId],
241
+					k.SumDecimal,
242
+					service.GetUserMoney(list[i].HisPatientId, orgid),
243
+				}
244
+			} else {
245
+				maplist[list[i].HisPatientId] = models.Summary{
246
+					namemap[list[i].HisPatientId],
247
+					list[i].Deposit,
248
+					service.GetUserMoney(list[i].HisPatientId, orgid),
249
+				}
250
+				tmpslice = append(tmpslice, list[i].HisPatientId)
251
+			}
252
+			sum = sum.Add(list[i].Deposit)
253
+		}
254
+	}
255
+	//maplist虽然满足接口要求,但格式不行,整理为Finlist输出
256
+	for i := 0; i < len(tmpslice); i++ {
257
+		Finlist = append(Finlist, maplist[tmpslice[i]])
258
+	}
259
+	this.ServeSuccessJSON(map[string]interface{}{
260
+		"list": Finlist,
261
+		"sum":  sum,
262
+	})
263
+	return
264
+}
265
+
266
+//审核
267
+func (this *HisDepositApiController) UpDeposit() {
268
+	id, _ := this.GetInt64("id", 0)
269
+	if id == 0 {
270
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "id不能为空")
271
+		return
272
+	}
273
+	tmp, err := service.GetDecimalHistoryOne(id)
274
+	if err != nil {
275
+		utils.ErrorLog("无法查询该记录信息", err.Error())
276
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "无法查询该记录信息")
277
+		return
278
+	}
279
+	if tmp.TrialStatus == 0 {
280
+		err = service.UpDecimalHistory(id)
281
+		if err != nil {
282
+			utils.ErrorLog("更新押金历史表出错,原因为:", err.Error())
283
+			this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "系统错误")
284
+			return
285
+		}
286
+	} else {
287
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "当前状态不可审核")
288
+		return
289
+	}
290
+	this.ServeSuccessJSON(map[string]interface{}{
291
+		"list": "审核通过",
292
+	})
293
+	return
294
+}
295
+func (this *HisDepositApiController) DeleteHistory() {
296
+	id, _ := this.GetInt64("id", 0)
297
+	if id == 0 {
298
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "id不能为空")
299
+		return
300
+	}
301
+	tmp, err := service.GetDecimalHistoryOne(id)
302
+	if err != nil {
303
+		utils.ErrorLog("无法查询该记录信息", err.Error())
304
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "无法查询该记录信息")
305
+		return
306
+	}
307
+	if tmp.TrialStatus == 0 {
308
+		err = service.DelDecimalHistory(id)
309
+		if err != nil {
310
+			utils.ErrorLog("删除历史记录出错,原因为:", err.Error())
311
+			this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "系统错误")
312
+			return
313
+		}
314
+	} else {
315
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "已审核的单据不能进行删除操作")
316
+		return
317
+	}
318
+	this.ServeSuccessJSON(map[string]interface{}{
319
+		"list": "删除成功",
320
+	})
321
+	return
322
+}
323
+
324
+//根据id获取押金流水
325
+func (this *HisDepositApiController) DepositFlow() {
326
+	orgid := this.GetAdminUserInfo().CurrentOrgId
327
+	check := map[string][]string{
328
+		"id":             {"must", "int", "id"},
329
+		"deposit_status": {"must", "int", "deposit_status"},
330
+	}
331
+	_, err := checks(this, &check)
332
+	if err != nil {
333
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
334
+		return
335
+	}
336
+	id, _ := this.GetInt64("id") //患者id
337
+	//获取当前患者的姓名
338
+	tmp, _ := service.GetHisUserName(orgid, id)
339
+	name := tmp.Name
340
+	deposit_status, _ := this.GetInt64("deposit_status", 0) //押金类型
341
+	if deposit_status > 3 {
342
+		utils.ErrorLog("押金类型错误,deposit_status:", deposit_status)
343
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金类型错误")
344
+		return
345
+	}
346
+	start_time := this.GetString("start_time", "") //开始时间
347
+	end_time := this.GetString("end_time", "")     //结束时间
348
+	timeLayout := "2006-01-02"
349
+	loc, _ := time.LoadLocation("Local")
350
+	var stime int64 //开始时间
351
+	var etime int64 //结束时间
352
+	if start_time == "" && end_time == "" {
353
+		stime, etime = service.GetMonth()
354
+	} else {
355
+		stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
356
+		etmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
357
+		stime = stmp.Unix()
358
+		etime = etmp.Unix()
359
+	}
360
+	//获取该角色当前时间段的余额
361
+	decimal := service.GetMoneyforTime(id, orgid, etime)
362
+	//获取列表
363
+	deposirhistory, errs := service.GetFlowList(id, orgid, stime, etime, deposit_status)
364
+	if errs != nil {
365
+		utils.ErrorLog("获取列表失败,原因为:", errs.Error())
366
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, errs.Error())
367
+		return
368
+	}
369
+
370
+	this.ServeSuccessJSON(map[string]interface{}{
371
+		"list":    deposirhistory,
372
+		"name":    name,
373
+		"decimal": decimal,
374
+	})
375
+	return
376
+}
377
+
378
+//
379
+func (this *HisDepositApiController) GetUserList() {
380
+	orgid := this.GetAdminUserInfo().CurrentOrgId
381
+	keyword := this.GetString("keyword")
382
+	page, _ := this.GetInt64("page")   //页码
383
+	limit, _ := this.GetInt64("limit") //每一页查出来的条数
384
+	check := map[string][]string{
385
+		"page":  {"must", "string", "page"},
386
+		"limit": {"must", "string", "limit"},
387
+	}
388
+	_, err := checks(this, &check)
389
+	if err != nil {
390
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
391
+		return
392
+	}
393
+	namemap := make(map[int64]string)
394
+	slicekey := make([]int64, 0)
395
+	lists, _ := service.GetHisUser(orgid)
396
+	for _, v := range lists {
397
+		namemap[v.ID] = v.Name
398
+	}
399
+	if len(keyword) > 0 {
400
+		for k, v := range namemap {
401
+			res := strings.Contains(v, keyword)
402
+			if res == true {
403
+				slicekey = append(slicekey, k)
404
+			}
405
+		}
406
+	}
407
+	list, total, errs := service.GetUserList(page, limit, orgid, keyword, slicekey)
408
+	if errs != nil {
409
+		utils.ErrorLog(errs.Error())
410
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
411
+		return
412
+	}
413
+	for i := 0; i < len(list); i++ {
414
+		list[i].HisPatientName = namemap[list[i].HisPatientId]
415
+	}
416
+	this.ServeSuccessJSON(map[string]interface{}{
417
+		"list":  list,
418
+		"total": total,
419
+	})
420
+	return
421
+}
422
+
423
+//判断前端参数是否为空
424
+func checks(this *HisDepositApiController, m *map[string][]string) (map[string]string, error) {
425
+	tmp := make(map[string]string)
426
+	for k, v := range *m {
427
+		t := this.GetString(k)
428
+		if v[0] == "must" && t == "" {
429
+			return nil, fmt.Errorf(v[2] + "不能为空")
430
+		}
431
+		tmp[k] = t
432
+	}
433
+	return tmp, nil
434
+}

+ 96 - 0
models/his_deposit_models.go Datei anzeigen

1
 package models
1
 package models
2
+
3
+import "github.com/shopspring/decimal"
4
+
5
+type Deposit struct {
6
+	ID           int64           `gorm:"column:id" json:"id" form:"id"`
7
+	UserOrgId    int64           `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`          //机构id
8
+	HisPatientId int64           `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"` //his病人id
9
+	Ctime        int64           `gorm:"column:ctime" json:"ctime" form:"ctime"`
10
+	Mtime        int64           `gorm:"column:mtime" json:"mtime" form:"mtime"`
11
+	Status       int64           `gorm:"column:status" json:"status" form:"status"`
12
+	Deposit      decimal.Decimal `gorm:"column:deposit" json:"deposit" form:"deposit"` //押金
13
+}
14
+
15
+func (Deposit) TableName() string {
16
+	return "sgj_xt.his_deposit"
17
+}
18
+
19
+type DepositHistory struct {
20
+	ID             int64           `gorm:"column:id" json:"id" form:"id"`
21
+	UserOrgId      int64           `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`          //机构id
22
+	HisPatientId   int64           `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"` //his病人id
23
+	DepositCode    string          `gorm:"column:deposit_code" json:"deposit_code" form:"deposit_code"`
24
+	Deposit        decimal.Decimal `gorm:"column:deposit" json:"deposit" form:"deposit"`                         //本次操作金额
25
+	SurplusDeposit decimal.Decimal `gorm:"column:surplus_deposit" json:"surplus_deposit" form:"surplus_deposit"` //剩余金额
26
+	DepositStatus  int64           `gorm:"column:deposit_status" json:"deposit_status" form:"deposit_status"`    //1:充值,2:扣费,3:退费
27
+	Status         int64           `gorm:"column:status" json:"status" form:"status"`
28
+	CreateId       int64           `gorm:"column:create_id" json:"create_id" form:"create_id"`
29
+	Ctime          int64           `gorm:"column:ctime" json:"ctime" form:"ctime"`
30
+	Mtime          int64           `gorm:"column:mtime" json:"mtime" form:"mtime"`
31
+	TrialStatus    int64           `gorm:"column:trial_status" json:"trial_status" form:"trial_status"` //审核状态0:未审核 ,1:已审核
32
+	Remarks        string          `gorm:"column:remarks" json:"remarks" form:"remarks"`                //备注
33
+}
34
+
35
+func (DepositHistory) TableName() string {
36
+	return "sgj_xt.his_deposit_history"
37
+}
38
+
39
+type GetHisName struct {
40
+	ID   int64  `gorm:"column:id" json:"id" form:"id"`
41
+	Name string `gorm:"column:name" json:"name" form:"name"`
42
+}
43
+
44
+func (GetHisName) TableName() string {
45
+	return "sgj_xt.xt_patients"
46
+}
47
+
48
+type DepositHistoryname struct {
49
+	ID             int64           `gorm:"column:id" json:"id" form:"id"`
50
+	UserOrgId      int64           `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`          //机构id
51
+	HisPatientId   int64           `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"` //his病人id
52
+	DepositCode    string          `gorm:"column:deposit_code" json:"deposit_code" form:"deposit_code"`
53
+	Deposit        decimal.Decimal `gorm:"column:deposit" json:"deposit" form:"deposit"`                         //本次操作金额
54
+	SurplusDeposit decimal.Decimal `gorm:"column:surplus_deposit" json:"surplus_deposit" form:"surplus_deposit"` //剩余金额
55
+	DepositStatus  int64           `gorm:"column:deposit_status" json:"deposit_status" form:"deposit_status"`    //1:充值,2:扣费,3:退费
56
+	Status         int64           `gorm:"column:status" json:"status" form:"status"`
57
+	CreateId       int64           `gorm:"column:create_id" json:"create_id" form:"create_id"`
58
+	Ctime          int64           `gorm:"column:ctime" json:"ctime" form:"ctime"`
59
+	Mtime          int64           `gorm:"column:mtime" json:"mtime" form:"mtime"`
60
+	TrialStatus    int64           `gorm:"column:trial_status" json:"trial_status" form:"trial_status"` //审核状态0:未审核 ,1:已审核
61
+	Remarks        string          `gorm:"column:remarks" json:"remarks" form:"remarks"`                //备注
62
+	Name           string          ` json:"name" `
63
+}
64
+
65
+func (DepositHistoryname) TableName() string {
66
+	return "sgj_xt.his_deposit_history"
67
+}
68
+
69
+type CreateUser struct {
70
+	ID   int64  `gorm:"column:id" json:"id" form:"id"`
71
+	Name string `gorm:"column:name" json:"name" form:"name"`
72
+}
73
+
74
+func (CreateUser) TableName() string {
75
+	return "sgj_users.sgj_user_admin"
76
+}
77
+
78
+type Summary struct {
79
+	HisName    string          `json:"his_name"`    //患者姓名
80
+	SumDecimal decimal.Decimal `json:"sum_decimal"` //充值金额
81
+	Decimal    decimal.Decimal `json:"decimal"`     //押金余额
82
+}
83
+
84
+type Deposit1 struct {
85
+	ID             int64           `gorm:"column:id" json:"id" form:"id"`
86
+	UserOrgId      int64           `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`          //机构id
87
+	HisPatientId   int64           `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"` //his病人id
88
+	HisPatientName string          `json:"his_patient_name"`
89
+	Ctime          int64           `gorm:"column:ctime" json:"ctime" form:"ctime"`
90
+	Mtime          int64           `gorm:"column:mtime" json:"mtime" form:"mtime"`
91
+	Status         int64           `gorm:"column:status" json:"status" form:"status"`
92
+	Deposit        decimal.Decimal `gorm:"column:deposit" json:"deposit" form:"deposit"` //押金
93
+}
94
+
95
+func (Deposit1) TableName() string {
96
+	return "sgj_xt.his_deposit"
97
+}

+ 2 - 1
routers/router.go Datei anzeigen

10
 
10
 
11
 func init() {
11
 func init() {
12
 	beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
12
 	beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
13
-		// AllowAllOrigins:  true,
13
+		//AllowAllOrigins:  true,
14
 		AllowOrigins: []string{"https://xt.kuyicloud.com", "http://localhost:9528", "http://localhost:9529", "http://localhost:9531", "http://xt.test.shengws.com", "http://new_mobile.test.sgjyun.com", "https://xt.test.shengws.com", "http://xt.test.sgjyun.com", "https://xt.test.sgjyun.com", "http://localhost:8081", "http://localhost:8082", "https://pad.kuyicloud.com", "http://pad.kuyicloud.com", "http://pad.test.sgjyun.com", "https://pad.test.sgjyun.com", "http://admin.xt.test.sgjyun.com", "http://admin.xt.kuyicloud.com", "http://mobile.sgjyun.com", "http://mobile.kuyicloud.com"},
14
 		AllowOrigins: []string{"https://xt.kuyicloud.com", "http://localhost:9528", "http://localhost:9529", "http://localhost:9531", "http://xt.test.shengws.com", "http://new_mobile.test.sgjyun.com", "https://xt.test.shengws.com", "http://xt.test.sgjyun.com", "https://xt.test.sgjyun.com", "http://localhost:8081", "http://localhost:8082", "https://pad.kuyicloud.com", "http://pad.kuyicloud.com", "http://pad.test.sgjyun.com", "https://pad.test.sgjyun.com", "http://admin.xt.test.sgjyun.com", "http://admin.xt.kuyicloud.com", "http://mobile.sgjyun.com", "http://mobile.kuyicloud.com"},
15
 		//AllowOrigins:     []string{"https://xt.kuyicloud.com", "http://localhost:9528", "http://xt.test.shengws.com","https://xt.test.shengws.com", "http://xt.test.sgjyun.com","https://xt.test.sgjyun.com", "http://localhost:8081", "http://localhost:8082", "https://pad.kuyicloud.com", "http://pad.kuyicloud.com", "http://pad.test.sgjyun.com","https://pad.test.sgjyun.com", "http://admin.xt.test.sgjyun.com", "http://admin.xt.kuyicloud.com","http://mobile.sgjyun.com","http://mobile.kuyicloud.com"},
15
 		//AllowOrigins:     []string{"https://xt.kuyicloud.com", "http://localhost:9528", "http://xt.test.shengws.com","https://xt.test.shengws.com", "http://xt.test.sgjyun.com","https://xt.test.sgjyun.com", "http://localhost:8081", "http://localhost:8082", "https://pad.kuyicloud.com", "http://pad.kuyicloud.com", "http://pad.test.sgjyun.com","https://pad.test.sgjyun.com", "http://admin.xt.test.sgjyun.com", "http://admin.xt.kuyicloud.com","http://mobile.sgjyun.com","http://mobile.kuyicloud.com"},
16
 		AllowMethods:     []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
16
 		AllowMethods:     []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
79
 
79
 
80
 	controllers.SupplyOrderApiRegistRouters()
80
 	controllers.SupplyOrderApiRegistRouters()
81
 	controllers.SecondaryOrderApiRegistRouters()
81
 	controllers.SecondaryOrderApiRegistRouters()
82
+	controllers.HisDepositApiRegistRouters()
82
 }
83
 }

+ 303 - 0
service/his_deposit_service.go Datei anzeigen

1
 package service
1
 package service
2
+
3
+import (
4
+	"XT_New/models"
5
+	"XT_New/utils"
6
+	"fmt"
7
+	"github.com/shopspring/decimal"
8
+	"math/rand"
9
+	"strconv"
10
+	"time"
11
+)
12
+
13
+//生成编号?+yymmdd+随机数(4位)
14
+//新增参数为CP
15
+//退款参数为AF
16
+func CreateCPCode(str string) string {
17
+	s := fmt.Sprintf("%04v", rand.New(rand.NewSource(time.Now().UnixNano())).Int63n(10000))
18
+	t := time.Now().Format("20060102")
19
+	code := str + t + s
20
+	return code
21
+}
22
+
23
+//获取his中的有效患者
24
+func GetHisUser(orgid int64) (hisname []models.GetHisName, err error) {
25
+	err = XTReadDB().Model(&models.GetHisName{}).Where("status = 1 and user_org_id = ?", orgid).Find(&hisname).Error
26
+	return
27
+}
28
+
29
+//获取his中的有效患者
30
+func GetHisUserName(orgid, id int64) (hisname models.GetHisName, err error) {
31
+	err = XTReadDB().Model(&models.GetHisName{}).Where("status = 1 and user_org_id = ? and id = ?", orgid, id).Find(&hisname).Error
32
+	return
33
+}
34
+
35
+//添加押金(开始)调用接口前记得判断审核状态,确认通过审核后在调用
36
+func UpDeposit(code, remarks string, his_patient_id, orgid, trial_status, createid int64, deposit decimal.Decimal) (err error) {
37
+	//查押金表是否存在记录
38
+	tmp, tmpdeposit := IsHisPatientId(his_patient_id, orgid)
39
+	if tmp == 0 {
40
+		//需要生成一条数据
41
+		de := models.Deposit{
42
+			UserOrgId:    orgid,
43
+			HisPatientId: his_patient_id,
44
+			Ctime:        time.Now().Unix(),
45
+			Status:       1,
46
+		}
47
+		i, d, err := AddDeposit(de)
48
+		if err != nil || i == 0 {
49
+			utils.ErrorLog("添加用户押金记录失败: %v", err.Error())
50
+			return err
51
+		}
52
+		tmp = i
53
+		tmpdeposit = d
54
+	}
55
+	if trial_status == 1 {
56
+		de := models.Deposit{
57
+			ID:      tmp,
58
+			Mtime:   time.Now().Unix(),
59
+			Deposit: deposit.Add(tmpdeposit),
60
+		}
61
+		err = UpdateDeposit(de)
62
+		if err != nil {
63
+			utils.ErrorLog("添加用户押金失败: %v", err.Error())
64
+			return
65
+		}
66
+	}
67
+	dehistory := models.DepositHistory{
68
+		UserOrgId:      orgid,
69
+		HisPatientId:   his_patient_id,
70
+		DepositCode:    code,
71
+		Deposit:        deposit,                 //本次操作的押金
72
+		SurplusDeposit: tmpdeposit.Add(deposit), //剩余金额
73
+		DepositStatus:  1,
74
+		Status:         1,
75
+		CreateId:       createid,
76
+		Ctime:          time.Now().Unix(),
77
+		Mtime:          time.Now().Unix(),
78
+		TrialStatus:    trial_status,
79
+		Remarks:        remarks,
80
+	}
81
+	err = AddDepositHistory(dehistory)
82
+	if err != nil {
83
+		utils.ErrorLog("添加用户押金历史记录失败: %v", err.Error())
84
+	}
85
+	return
86
+}
87
+
88
+//添加押金记录
89
+func AddDepositHistory(dh models.DepositHistory) error {
90
+	err := XTWriteDB().Create(&dh).Error
91
+	return err
92
+}
93
+
94
+//押金中添加一条记录,并返回该数据的id和押金余额(当没有该用户记录时调用)
95
+func AddDeposit(de models.Deposit) (int64, decimal.Decimal, error) {
96
+	var tmp models.Deposit
97
+	err := XTWriteDB().Create(&de).Find(&tmp).Error
98
+	if err != nil {
99
+		return 0, decimal.NewFromFloat(0.00), err
100
+	}
101
+	return tmp.ID, tmp.Deposit, err
102
+}
103
+
104
+//更改押金记录
105
+func UpdateDeposit(de models.Deposit) (err error) {
106
+	err = XTWriteDB().Model(&models.Deposit{}).Where("id = ? and status = 1", de.ID).Updates(map[string]interface{}{
107
+		"mtime":   de.Mtime,
108
+		"deposit": de.Deposit,
109
+	}).Error
110
+	return
111
+}
112
+
113
+//判断押金表是否存在当前的患者的一条有效数据,如果有返回id和押金余额,没有返回0
114
+func IsHisPatientId(his_patient_id, orgid int64) (int64, decimal.Decimal) {
115
+	var tmp []models.Deposit
116
+	XTReadDB().Model(&models.Deposit{}).Where("user_org_id = ? and his_patient_id = ? and status = 1", orgid, his_patient_id).Find(&tmp)
117
+	if len(tmp) != 1 {
118
+		return 0, decimal.NewFromFloat(0.00)
119
+	}
120
+	return tmp[0].ID, tmp[0].Deposit
121
+}
122
+
123
+//查询押金编号是否重复
124
+func FindDecimalCode(orgid int64, code string) bool {
125
+	var total int
126
+	XTReadDB().Model(&models.DepositHistory{}).Where("user_org_id = ? and deposit_code = ? and status = 1", orgid, code).Count(&total)
127
+	if total > 0 {
128
+		return true
129
+	} else {
130
+		return false
131
+	}
132
+}
133
+
134
+//充值明细列表
135
+func DetailsList(orgid, stime, etime int64, keyword string, slicekey []int64) (deposithistory []models.DepositHistoryname, err error) {
136
+	db := XTReadDB().Model(&models.DepositHistory{}).Where("status = 1 and user_org_id = ? and deposit_status = 1 ", orgid).Where("ctime >= ? and ctime <= ?", stime, etime)
137
+	if len(keyword) > 0 {
138
+		var tmp string = "deposit_code like ?"
139
+		if len(slicekey) > 0 {
140
+			for i := 0; i < len(slicekey); i++ {
141
+				tmp = tmp + " or his_patient_id = " + strconv.FormatInt(slicekey[i], 10)
142
+			}
143
+		}
144
+		keyword = "%" + keyword + "%"
145
+		db = db.Where(tmp, keyword)
146
+	}
147
+	err = db.Order("ctime desc").Find(&deposithistory).Error
148
+	return
149
+}
150
+
151
+//充值汇总列表
152
+func SummaryList(orgid, stime, etime int64, keyword string, slicekey []int64) (deposithistory []models.DepositHistory, err error) {
153
+	db := XTReadDB().Model(&models.DepositHistory{}).Where("status = 1 and trial_status = 1 and user_org_id = ? and deposit_status = 1 ", orgid).Where("ctime >= ? and ctime <= ?", stime, etime)
154
+	if len(slicekey) > 0 {
155
+		tmp := ""
156
+		for i := 0; i < len(slicekey); i++ {
157
+			tmp = tmp + " his_patient_id = " + strconv.FormatInt(slicekey[i], 10)
158
+			if i < len(slicekey)-1 {
159
+				tmp = tmp + " or "
160
+			}
161
+		}
162
+		db = db.Where(tmp)
163
+	} else {
164
+		if len(keyword) > 0 {
165
+			return
166
+		}
167
+	}
168
+	err = db.Order("ctime desc").Find(&deposithistory).Error
169
+	return
170
+}
171
+
172
+//获取本周周一和周日的起止时间戳
173
+func GetMondayOfWeek() (int64, int64) {
174
+	t := time.Now()
175
+	dayObj := GetZeroTime(t)
176
+	var dayStr string
177
+	loc, _ := time.LoadLocation("Local")
178
+	if t.Weekday() == time.Monday {
179
+		dayStr = dayObj.Format("2006-01-02")
180
+	} else {
181
+		offset := int(time.Monday - t.Weekday())
182
+		if offset > 0 {
183
+			offset = -6
184
+		}
185
+		dayStr = dayObj.AddDate(0, 0, offset).Format("2006-01-02")
186
+	}
187
+	dayStr = dayStr + " 00:00:00"
188
+	stime, _ := time.ParseInLocation("2006-01-02 15:04:05", dayStr, loc)
189
+	return stime.Unix(), stime.Unix() + 604799
190
+}
191
+
192
+//获取本月的起止时间戳
193
+func GetMonth() (int64, int64) {
194
+	timeNow := time.Now()
195
+	timeToday := time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 0, 0, 0, 0, timeNow.Location()) // 获取当天0点时间 time类型
196
+	timeMonthStartUnix1 := timeToday.AddDate(0, 0, -timeToday.Day()+1).Unix()                              // 获取本月第一天0点 时间戳类型
197
+	timeMonthEndUnix1 := timeToday.AddDate(0, 1, -timeToday.Day()+1).Unix() - 1                            // 获取下个月第一天/ 本月最后一天24点 时间戳类型
198
+	return timeMonthStartUnix1, timeMonthEndUnix1
199
+}
200
+func GetCreateidName(id int64) string {
201
+	var tmp models.CreateUser
202
+	XTReadDB().Select("name").Where("id = ?", id).Find(&tmp)
203
+	return tmp.Name
204
+}
205
+
206
+//审核通过
207
+func UpDecimalHistory(id int64) (err error) {
208
+	//开事务
209
+	tx := XTWriteDB().Begin()
210
+	defer func() {
211
+		if err != nil {
212
+			utils.ErrorLog("事务失败,原因为", err)
213
+			tx.Rollback()
214
+		} else {
215
+			tx.Commit()
216
+		}
217
+	}()
218
+	//改状态
219
+	err = tx.Model(models.DepositHistory{}).Where("id = ?", id).Updates(map[string]interface{}{
220
+		"trial_status": 1,
221
+		"mtime":        time.Now().Unix(),
222
+	}).Error
223
+	if err != nil {
224
+		return
225
+	}
226
+	//查记录x2
227
+	var history models.DepositHistory
228
+	var detmp models.Deposit
229
+	err = tx.Model(&models.DepositHistory{}).Where("id = ?", id).Find(&history).Error
230
+	if err != nil {
231
+		return
232
+	}
233
+	err = tx.Model(&models.Deposit{}).Where("user_org_id = ? and his_patient_id = ? and status = 1 ", history.UserOrgId, history.HisPatientId).Find(&detmp).Error
234
+	if err != nil {
235
+		return
236
+	}
237
+	//相加
238
+	err = tx.Model(&models.Deposit{}).Where("id = ? and status = 1", detmp.ID).Updates(map[string]interface{}{
239
+		"mtime":   time.Now().Unix(),
240
+		"deposit": detmp.Deposit.Add(history.Deposit),
241
+	}).Error
242
+
243
+	return
244
+}
245
+
246
+//删除本次记录
247
+func DelDecimalHistory(id int64) (err error) {
248
+	err = XTWriteDB().Model(models.DepositHistory{}).Where("id = ?", id).Updates(map[string]interface{}{
249
+		"status": 0,
250
+		"mtime":  time.Now().Unix(),
251
+	}).Error
252
+	return
253
+}
254
+
255
+//根据id获取一条押金历史记录
256
+func GetDecimalHistoryOne(id int64) (history models.DepositHistory, err error) {
257
+	err = XTReadDB().Model(&models.DepositHistory{}).Where("id = ?", id).Find(&history).Error
258
+	return
259
+}
260
+
261
+//根据患者id获取该患者当前剩余的押金
262
+func GetUserMoney(id, orgid int64) decimal.Decimal {
263
+	tmp := models.Deposit{}
264
+	XTReadDB().Model(&models.Deposit{}).Where("his_patient_id = ? and user_org_id = ? and status = 1", id, orgid).Find(&tmp)
265
+	return tmp.Deposit
266
+}
267
+
268
+//查询时间段内患者的余额
269
+func GetMoneyforTime(id, orgid, etime int64) decimal.Decimal {
270
+	tmp := models.DepositHistory{}
271
+	XTReadDB().Model(&models.DepositHistory{}).Where("his_patient_id = ? and user_org_id = ? and status = 1 and mtime <= ?", id, orgid, etime).Order("mtime").Find(&tmp)
272
+	return tmp.SurplusDeposit
273
+}
274
+
275
+//押金流水
276
+func GetFlowList(id, orgid, stime, etime, deposit_status int64) (deposit []models.DepositHistory, err error) {
277
+	s := "status = 1 and trial_status = 1 and user_org_id = ? and his_patient_id = ? and mtime >= ? and mtime <= ?"
278
+	if deposit_status != 0 {
279
+		s = s + " and deposit_status = " + string(deposit_status)
280
+	}
281
+	err = XTReadDB().Model(&models.DepositHistory{}).Where(s, orgid, id, stime, etime).Order("mtime desc").Find(&deposit).Error
282
+	return
283
+}
284
+
285
+func GetUserList(page, limit, orgid int64, keyword string, slicekey []int64) (m []models.Deposit1, total int64, err error) {
286
+	db := XTReadDB().Model(&models.Deposit{}).Where("status = 1 and user_org_id = ? ", orgid)
287
+	offset := (page - 1) * limit
288
+	if len(slicekey) > 0 {
289
+		tmp := ""
290
+		for i := 0; i < len(slicekey); i++ {
291
+			tmp = tmp + " his_patient_id = " + strconv.FormatInt(slicekey[i], 10)
292
+			if i < len(slicekey)-1 {
293
+				tmp = tmp + " or "
294
+			}
295
+		}
296
+		db = db.Where(tmp)
297
+	} else {
298
+		if len(keyword) > 0 {
299
+			return
300
+		}
301
+	}
302
+	err = db.Count(&total).Offset(offset).Order("mtime desc").Find(&m).Error
303
+	return
304
+}