瀏覽代碼

Merge branch '20211122' of http://git.shengws.com/csx/XT_New into 20211122

XMLWAN 3 年之前
父節點
當前提交
ee175f1ca3

+ 434 - 0
controllers/his_deposit_controller.go 查看文件

@@ -0,0 +1,434 @@
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
+}

+ 5 - 2
controllers/his_project_api_controller.go 查看文件

@@ -1061,8 +1061,8 @@ func (this *HisProjectApiController) GetHisPatientHistory() {
1061 1061
 	register_type, _ := this.GetInt64("register_type")
1062 1062
 	limit, _ := this.GetInt64("limit")
1063 1063
 	page, _ := this.GetInt64("page")
1064
-	startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
1065
-	endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
1064
+	startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+":00", loc)
1065
+	endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+":59", loc)
1066 1066
 	adminUserInfo := this.GetAdminUserInfo()
1067 1067
 	orgId := adminUserInfo.CurrentOrgId
1068 1068
 	history, total, err := service.GetHisPatientHistory(keyword, startTime.Unix(), endTime.Unix(), register_type, limit, page, orgId)
@@ -1234,6 +1234,8 @@ func (this *HisProjectApiController) GetDoctorAdvicePrint() {
1234 1234
 	//hisPatient, _ := service.GetHisPatientById(patient_id)
1235 1235
 	hisHospitalRecord, _ := service.GetLastHospitalRecordTwo(patient_id, adminUserInfo.CurrentOrgId)
1236 1236
 
1237
+	eles, _ := service.GetNewAdminUserES(adminUserInfo.CurrentOrgId)
1238
+
1237 1239
 	if err != nil {
1238 1240
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
1239 1241
 		return
@@ -1245,6 +1247,7 @@ func (this *HisProjectApiController) GetDoctorAdvicePrint() {
1245 1247
 		"his":               his,
1246 1248
 		"hisHospitalRecord": hisHospitalRecord,
1247 1249
 		"info":              prescriptionInfo,
1250
+		"eles":              eles,
1248 1251
 	})
1249 1252
 }
1250 1253
 

文件差異過大導致無法顯示
+ 1039 - 345
controllers/secondary_order_api_contorller.go


+ 1 - 1
controllers/self_drug_api_congtroller.go 查看文件

@@ -2653,7 +2653,7 @@ func (this *SelfDrugApiController) SaveInventoryList() {
2653 2653
 func (this *SelfDrugApiController) GetDamageByDrugId() {
2654 2654
 
2655 2655
 	drug_id, _ := this.GetInt64("drug_id")
2656
-	warehousing_order := this.GetString("warehousing_order")
2656
+	warehousing_order := this.GetString("warehouseing_order")
2657 2657
 	drug_type, _ := this.GetInt64("type")
2658 2658
 	list, err := service.GetDamageByDrugId(drug_id, warehousing_order, drug_type)
2659 2659
 	if err != nil {

+ 3 - 2
controllers/supply_order_api_contorller.go 查看文件

@@ -454,14 +454,15 @@ func (this *SupplyOrderApiController) DelSupply() {
454 454
 	supply := models.SpSupplierName{
455 455
 		ID: suid,
456 456
 	}
457
-	err := service.DelSupply(supply, orgId)
457
+	shiwu, err := service.DelSupply(supply, orgId)
458 458
 	if err != nil {
459 459
 		utils.ErrorLog(err.Error())
460 460
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
461 461
 		return
462 462
 	}
463 463
 	this.ServeSuccessJSON(map[string]interface{}{
464
-		"list": "删除成功",
464
+		"list":  "删除成功",
465
+		"shiwu": shiwu,
465 466
 	})
466 467
 	return
467 468
 }

+ 9 - 0
controllers/verify_login_controller.go 查看文件

@@ -301,6 +301,15 @@ func (this *VerifyUserLoginAPIController) VerifyToken() {
301 301
 			}
302 302
 
303 303
 			subscibe, _ := service.GetOrgSubscibe(adminUserInfo.CurrentOrgId)
304
+			//判断该机构是否需要生成默认仓库
305
+			orgid := adminUserInfo.CurrentOrgId
306
+			boolean := service.IsStorehouse(orgid)
307
+			if boolean == false {
308
+				err = service.GetDefaultStorehouse(orgid)
309
+				if err != nil {
310
+					utils.ErrorLog("创建默认仓库失败,原因为:", err)
311
+				}
312
+			}
304 313
 
305 314
 			this.SetSession("admin_user_info", adminUserInfo)
306 315
 

+ 97 - 0
models/his_deposit_models.go 查看文件

@@ -0,0 +1,97 @@
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
+}

+ 83 - 0
models/secondary_models.go 查看文件

@@ -136,7 +136,90 @@ type XtStorehouseConfig struct {
136 136
 func (XtStorehouseConfig) TableName() string {
137 137
 	return "xt_storehouse_config"
138 138
 }
139
+//二级仓库
140
+type Storehouse struct {
141
+	ID                int64  `gorm:"column:id" json:"id" form:"id"`
142
+	StorehouseCode    string `gorm:"column:storehouse_code" json:"storehouse_code" form:"storehouse_code"`             //仓库编号
143
+	StorehouseName    string `gorm:"column:storehouse_name" json:"storehouse_name" form:"storehouse_name"`             //仓库名称
144
+	StorehouseAddress string `gorm:"column:storehouse_address" json:"storehouse_address" form:"storehouse_address"`    //仓库地址
145
+	StorehouseStatus  int64  `gorm:"column:storehouse_status" json:"storehouse_status" form:"storehouse_status"`       //仓库状态
146
+	Status            int64  `gorm:"column:status" json:"status" form:"status"`                                        //数据状态
147
+	StorehouseAdminId int64  `gorm:"column:storehouse_admin_id" json:"storehouse_admin_id" form:"storehouse_admin_id"` //仓库管理员id
148
+	UserOrgId         int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
149
+	Ctime             int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
150
+	Mtime             int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
151
+}
152
+
153
+func (Storehouse) TableName() string {
154
+	return "xt_storehouse"
155
+}
156
+
157
+//仓库配置
158
+type StorehouseConfig struct {
159
+	ID                 int64 `gorm:"column:id" json:"id" form:"id"`
160
+	UserOrgId          int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`                         //机构id
161
+	StorehouseInfo     int64 `gorm:"column:storehouse_info" json:"storehouse_info" form:"storehouse_info"`             //耗材 自动入库 的仓库id
162
+	StorehouseOutInfo  int64 `gorm:"column:storehouse_out_info" json:"storehouse_out_info" form:"storehouse_out_info"` //耗材 自动出库 的仓库id
163
+	DrugStorehouseInfo int64 `gorm:"drug_storehouse_info" json:"drug_storehouse_info" form:"drug_storehouse_info"`     //药品 自动入库 的仓库id
164
+	DrugStorehouseOut  int64 `gorm:"drug_storehouse_out" json:"drug_storehouse_out" form:"drug_storehouse_out"`        //药品 自动出库 的仓库id
165
+	Status             int64 `gorm:"status" json:"status" form:"status"`
166
+	Ctime              int64 `gorm:"ctime" json:"ctime" form:"ctime"`
167
+	Mtime              int64 `gorm:"mtime" json:"mtime" form:"mtime"`
168
+}
139 169
 
170
+func (StorehouseConfig) TableName() string {
171
+	return "xt_storehouse_config"
172
+}
173
+
174
+type App_Role_byli struct {
175
+	Id          int64  `gorm:"PRIMARY_KEY;AUTO_INCREMENT" json:"id"`
176
+	OrgId       int64  `gorm:"column:org_id" json:"org_id"`
177
+	AdminUserId int64  `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
178
+	UserName    string `gorm:"column:user_name" json:"user_name"` // 用户名称
179
+}
180
+
181
+func (App_Role_byli) TableName() string {
182
+	return "sgj_users.sgj_user_admin_role"
183
+}
184
+
185
+type UserOrg struct {
186
+	Id      int64 `gorm:"PRIMARY_KEY;AUTO_INCREMENT" json:"id"`
187
+	Creator int64 `gorm:"column:creator" json:"creator"`
188
+}
189
+
190
+func (UserOrg) TableName() string {
191
+	return "sgj_users.sgj_user_org"
192
+}
193
+
194
+//分页
195
+type Storehouselist struct {
196
+	ID                  int64  `gorm:"column:id" json:"id" form:"id"`
197
+	StorehouseCode      string `gorm:"column:storehouse_code" json:"storehouse_code" form:"storehouse_code"`                 //仓库编号
198
+	StorehouseName      string `gorm:"column:storehouse_name" json:"storehouse_name" form:"storehouse_name"`                 //仓库名称
199
+	StorehouseAddress   string `gorm:"column:storehouse_address" json:"storehouse_address" form:"storehouse_address"`        //仓库地址
200
+	StorehouseStatus    int64  `gorm:"column:storehouse_status" json:"storehouse_status" form:"storehouse_status"`           //仓库状态
201
+	Status              int64  `gorm:"column:status" json:"status" form:"status"`                                            //数据状态
202
+	StorehouseAdminId   int64  `gorm:"column:storehouse_admin_id" json:"storehouse_admin_id" form:"storehouse_admin_id"`     //仓库管理员id
203
+	StorehouseAdminName string `gorm:"column:storehouse_admin_name" json:"storehouse_admin_name" form:"storehouse_admin_id"` //仓库管理员名字
204
+	UserOrgId           int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
205
+	Ctime               int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
206
+	Mtime               int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
207
+}
208
+
209
+type RolePurviews struct {
210
+	Id         int64 `gorm:"PRIMARY_KEY;AUTO_INCREMENT"`
211
+	RoleId     int64
212
+	OrgId      int64
213
+	AppId      int64
214
+	PurviewIds string `gorm:"column:purview_ids"`
215
+	Status     int8   // 状态 0.无效 1.有效 2.禁用
216
+	CreateTime int64  `gorm:"column:ctime"` // 创建时间
217
+	ModifyTime int64  `gorm:"column:mtime"` // 修改时间
218
+	Role       Role   `gorm:"ForeignKey:RoleId;AssociationForeignKey:ID" json:"role_info"`
219
+}
220
+
221
+func (RolePurviews) TableName() string {
222
+	return "sgj_users.sgj_user_role_purview"
140 223
 type XtSecondWarehouse struct {
141 224
 	ID                int64  `gorm:"column:id" json:"id" form:"id"`
142 225
 	SecondOrderNumber string `gorm:"column:second_order_number" json:"second_order_number" form:"second_order_number"`

+ 2 - 1
models/stock_models.go 查看文件

@@ -141,6 +141,7 @@ type WarehousingInfo struct {
141 141
 	SupplyWarehouseId         int64       `gorm:"column:supply_warehouse_id" json:"supply_warehouse_id" form:"supply_warehouse_id"`
142 142
 	SupplyWarehouseDetailInfo int64       `gorm:"column:supply_warehouse_detail_info" json:"supply_warehouse_detail_info" form:"supply_warehouse_detail_info"`
143 143
 	StorehouseId              int64       `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
144
+	StorehouseId              int64       `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
144 145
 	SecondWarehouseInfoId     int64       `gorm:"column:second_warehouse_info_id" json:"second_warehouse_info_id" form:"second_warehouse_info_id"`
145 146
 }
146 147
 
@@ -256,6 +257,7 @@ type WarehouseOutInfo struct {
256 257
 	StorehouseId            int64        `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
257 258
 	SecondWarehouseInfoId   int64        `gorm:"column:second_warehouse_info_id" json:"second_warehouse_info_id" form:"second_warehouse_info_id"`
258 259
 	AdminUserId             int64        `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
260
+	StorehouseId            int64        `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
259 261
 }
260 262
 
261 263
 func (WarehouseOutInfo) TableName() string {
@@ -355,7 +357,6 @@ type CancelStock struct {
355 357
 	Manufacturer      int64                `gorm:"column:manufacturer" json:"manufacturer"`
356 358
 	Type              int64                `gorm:"column:type" json:"type"`
357 359
 	XtCancelStockInfo []*XtCancelStockInfo `gorm:"ForeignKey:CancelStockId;AssociationForeignKey:ID" json:"XtCancelStockInfo"`
358
-	StorehouseId      int64                `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
359 360
 }
360 361
 
361 362
 func (CancelStock) TableName() string {

+ 10 - 10
models/supply.models.go 查看文件

@@ -2,16 +2,16 @@ package models
2 2
 
3 3
 //供应商联系人
4 4
 type SpSupplierContacts struct {
5
-	ID           int64  `gorm:"column:id" json:"id" from:"id"`
6
-	Name         string `gorm:"column:name" json:"name" from:"name"`
7
-	Phone        string `gorm:"column:phone" json:"phone" from:"phone"`
8
-	Address      string `gorm:"column:address" json:"address" from:"address"`
9
-	IsFirst      int64  `gorm:"column:is_first" json:"is_first" from:"is_first"`
10
-	SupplierCode string `gorm:"column:supplier_code" json:"supplier_code" from:"supplier_code"`
11
-	UserOrgId    int64  `gorm:"column:user_org_id" json:"user_org_id" from:"user_org_id"`
12
-	Status       int64  `gorm:"column:status" json:"status" from:"status"`
13
-	Ctime        int64  `gorm:"column:ctime" json:"ctime" from:"ctime"`
14
-	Mtime        int64  `gorm:"column:mtime" json:"mtime" from:"mtime"`
5
+	ID           int64  `gorm:"column:id" json:"id" form:"id"`
6
+	Name         string `gorm:"column:name" json:"name" form:"name"`
7
+	Phone        string `gorm:"column:phone" json:"phone" form:"phone"`
8
+	Address      string `gorm:"column:address" json:"address" form:"address"`
9
+	IsFirst      int64  `gorm:"column:is_first" json:"is_first" form:"is_first"`
10
+	SupplierCode string `gorm:"column:supplier_code" json:"supplier_code" form:"supplier_code"`
11
+	UserOrgId    int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
12
+	Status       int64  `gorm:"column:status" json:"status" form:"status"`
13
+	Ctime        int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
14
+	Mtime        int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
15 15
 }
16 16
 
17 17
 func (SpSupplierContacts) TableName() string {

+ 2 - 1
routers/router.go 查看文件

@@ -10,7 +10,7 @@ import (
10 10
 
11 11
 func init() {
12 12
 	beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
13
-		// AllowAllOrigins:  true,
13
+		//AllowAllOrigins:  true,
14 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 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 16
 		AllowMethods:     []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
@@ -79,4 +79,5 @@ func init() {
79 79
 
80 80
 	controllers.SupplyOrderApiRegistRouters()
81 81
 	controllers.SecondaryOrderApiRegistRouters()
82
+	controllers.HisDepositApiRegistRouters()
82 83
 }

+ 304 - 0
service/his_deposit_service.go 查看文件

@@ -0,0 +1,304 @@
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
+}

+ 5 - 0
service/his_project_service.go 查看文件

@@ -747,3 +747,8 @@ func GetLastHisPatient(patient_id int64, org_id int64) (his models.HisPatient, e
747 747
 	err = XTReadDB().Model(&models.HisPatient{}).Where("user_org_id = ? AND patient_id = ? and status = 1 AND patient_info <> ''", org_id, patient_id).First(&his).Error
748 748
 	return
749 749
 }
750
+
751
+func GetNewAdminUserES(orgID int64) (es []*models.AdminUserElectronicSignature, err error) {
752
+	err = readUserDb.Model(&models.AdminUserElectronicSignature{}).Where("org_id=?  and status=1", orgID).Find(&es).Error
753
+	return
754
+}

+ 19 - 0
service/role_service.go 查看文件

@@ -485,6 +485,25 @@ func GetAllGeneralPurviewVMsProcessed(module int) ([]*PurviewTreeViewModel, erro
485 485
 	return purviewVMs, nil
486 486
 }
487 487
 
488
+//用来处理树形结构
489
+func Totree(map1 map[int64]int64, map2 map[int64]*PurviewTreeViewModel, tmp int64) []*PurviewTreeViewModel {
490
+	var j int //用来计数
491
+	var tmp_purview []*PurviewTreeViewModel
492
+	for k, v := range map1 {
493
+		if v == tmp {
494
+			tmp_purview = append(tmp_purview, map2[k])
495
+			delete(map1, k)
496
+			for k1, v1 := range tmp_purview {
497
+				if k1 == j {
498
+					v1.Childs = Totree(map1, map2, k)
499
+				}
500
+			}
501
+			j++
502
+		}
503
+	}
504
+	return tmp_purview
505
+}
506
+
488 507
 func GetAllGeneralFuncPurviewVMsProcessed() ([]*PurviewTreeViewModel, error) {
489 508
 	var originPurviews []*models.SgjUserOperatePurview
490 509
 	getPurviewErr := readUserDb.Model(models.SgjUserOperatePurview{}).Where(" status = 1").Order("number asc").Find(&originPurviews).Error

+ 770 - 0
service/secondary_service.go 查看文件

@@ -966,7 +966,777 @@ func GetStoreWarehouseOutById(id int64, orgid int64) (models.WarehouseOut, error
966 966
 	err := XTReadDB().Where("id = ? and org_id = ?", id, orgid).Find(&out).Error
967 967
 	return out, err
968 968
 }
969
+import (
970
+	"XT_New/models"
971
+	"XT_New/utils"
972
+	"fmt"
973
+	"github.com/jinzhu/gorm"
974
+	"math/rand"
975
+	"strconv"
976
+	"time"
977
+)
978
+
979
+//生成编号,规则为:"SH-"+4位随机数
980
+func CreateCode() string {
981
+	s := fmt.Sprintf("%04v", rand.New(rand.NewSource(time.Now().UnixNano())).Int63n(10000))
982
+	code := "SH-" + s
983
+	return code
984
+}
985
+
986
+//查询编号是否重复
987
+func FindStorehouseCode(orgid int64, code string) bool {
988
+	var total int
989
+	XTReadDB().Model(&models.Storehouse{}).Where(" storehouse_code = ? and user_org_id = ? and status = 1", code, orgid).Count(&total)
990
+	if total > 0 {
991
+		return true
992
+	} else {
993
+		return false
994
+	}
995
+}
996
+
997
+//判断仓库的库存是否为零 true为零,false不为零
998
+func IsStorehouseNil(id, orgid int64) bool { //根据 id gro_id 查为零的库存
999
+	var h, y int
1000
+	//判断耗材是否为零
1001
+	XTReadDB().Model(&models.WarehousingInfo{}).Where("stock_count > 0 and status = 1 and org_id = ? and storehouse_id = ?", orgid, id).Count(&h)
1002
+	if h > 0 {
1003
+		return false
1004
+	}
1005
+	//判断药品是否为零
1006
+	XTReadDB().Model(&models.XtDrugWarehouseInfo{}).Where("stock_max_number > 0 or stock_min_number > 0 ").Where(" org_id = ? and storehouse_id = ?", orgid, id).Count(&y)
1007
+	if y > 0 {
1008
+		return false
1009
+	}
1010
+	return true
1011
+}
1012
+
1013
+//修改仓库状态
1014
+func UpdateStorehouseStatus(id int64) error {
1015
+	err := XTWriteDB().Exec("UPDATE xt_storehouse,(SELECT CASE storehouse_status WHEN 1 THEN 0 WHEN 0 THEN 1 END AS tt FROM xt_storehouse WHERE id=?)tmp SET storehouse_status = tmp.tt where id=?", id, id).Error
1016
+	return err
1017
+}
1018
+
1019
+//删除仓库
1020
+func DeleteStorehouse(id int64) error {
1021
+	err := XTWriteDB().Model(&models.Storehouse{}).Where("id = ?", id).Update("status", 0).Error
1022
+	return err
1023
+}
1024
+
1025
+//查询仓库名称是否重复
1026
+func IsStorehouseName(orgid int64, storehouse_name string) (bool, error) {
1027
+	var total int
1028
+	var tmp bool
1029
+	err := XTReadDB().Model(&models.Storehouse{}).Where("storehouse_name = ? and user_org_id = ? and status = 1", storehouse_name, orgid).Count(&total).Error
1030
+	if total > 0 {
1031
+		tmp = true //有重复的
1032
+	} else {
1033
+		tmp = false
1034
+	}
1035
+	return tmp, err
1036
+}
1037
+
1038
+//查询仓库地址是否重复
1039
+func IsStorehouseAddress(orgid int64, storehouse_address string) (bool, error) {
1040
+	var total int
1041
+	var tmp bool
1042
+	err := XTReadDB().Model(&models.Storehouse{}).Where("storehouse_address = ? and user_org_id = ? and status = 1", storehouse_address, orgid).Count(&total).Error
1043
+	if total > 0 {
1044
+		tmp = true //有重复的
1045
+	} else {
1046
+		tmp = false
1047
+	}
1048
+	return tmp, err
1049
+}
1050
+
1051
+//查询仓库名称是否重复(用于修改)
1052
+func IsStorehouseNameUp(orgid, id int64, storehouse_name string) (bool, error) {
1053
+	var total int
1054
+	var tmp bool
1055
+	err := XTReadDB().Model(&models.Storehouse{}).Where("storehouse_name = ? and user_org_id = ? and status = 1 and id != ?", storehouse_name, orgid, id).Count(&total).Error
1056
+	if total > 0 {
1057
+		tmp = true //有重复的
1058
+	} else {
1059
+		tmp = false
1060
+	}
1061
+	return tmp, err
1062
+}
1063
+
1064
+//查询仓库地址是否重复(用于修改)
1065
+func IsStorehouseAddressUp(orgid, id int64, storehouse_address string) (bool, error) {
1066
+	var total int
1067
+	var tmp bool
1068
+	err := XTReadDB().Model(&models.Storehouse{}).Where("storehouse_address = ? and user_org_id = ? and status = 1 and id != ?", storehouse_address, orgid, id).Count(&total).Error
1069
+	if total > 0 {
1070
+		tmp = true //有重复的
1071
+	} else {
1072
+		tmp = false
1073
+	}
1074
+	return tmp, err
1075
+}
1076
+
1077
+//新增仓库
1078
+func AddStroehouse(storehouse models.Storehouse) error {
1079
+	tx := XTWriteDB().Begin()
1080
+	defer func() {
1081
+		if err != nil {
1082
+			utils.ErrorLog("新增仓库_事务失败,原因为", err)
1083
+			tx.Rollback()
1084
+		} else {
1085
+			tx.Commit()
1086
+		}
1087
+	}()
1088
+	//创建仓库
1089
+	err := tx.Create(&storehouse).Error
1090
+	if err != nil {
1091
+		return err
1092
+	}
1093
+	var id models.Storehouse
1094
+	//获取创建仓库的id
1095
+	err = tx.Model(&models.Storehouse{}).Select("id").Where("status = 1 and user_org_id = ?", storehouse.UserOrgId).Order("id desc").First(&id).Error
1096
+	if err != nil {
1097
+		return err
1098
+	}
1099
+	//判断是否存在仓库配置
1100
+	boolean := IsStorehouseconfigXT(storehouse.UserOrgId, tx)
1101
+	if boolean == false {
1102
+		//创建仓库配置
1103
+		err = CreateStorehouseConfigXT(storehouse.UserOrgId, id.ID, tx)
1104
+	} else {
1105
+		utils.ErrorLog("仓库配置已存在")
1106
+	}
1107
+
1108
+	return err
1109
+}
1110
+
1111
+//修改仓库
1112
+func UpdateStroehouse(storehouse models.Storehouse) error {
1113
+	err := XTWriteDB().Model(&models.Storehouse{}).Where("id = ? and status = 1", storehouse.ID).Updates(
1114
+		map[string]interface{}{
1115
+			"storehouse_name":     storehouse.StorehouseName,
1116
+			"storehouse_address":  storehouse.StorehouseAddress,
1117
+			"storehouse_status":   storehouse.StorehouseStatus,
1118
+			"storehouse_admin_id": storehouse.StorehouseAdminId,
1119
+			"mtime":               storehouse.Mtime,
1120
+		}).Error
1121
+	return err
1122
+}
1123
+
1124
+//查询一条仓库的信息
1125
+func GetOneStorehouse(id, orgid int64) (storehouse models.Storehouse, err error) {
1126
+	err = XTReadDB().Model(&models.Storehouse{}).Where("id = ? and user_org_id = ?", id, orgid).Find(&storehouse).Error
1127
+	return
1128
+}
1129
+
1130
+//分页
1131
+func StorehouseList(page, limit, orgid int64, keyword string, slicekey []int64) (storehouse []models.Storehouse, total int64, err error) {
1132
+	db := XTReadDB().Model(&storehouse).Where("status = 1 and user_org_id = ?", orgid)
1133
+	offset := (page - 1) * limit
1134
+	if len(keyword) > 0 {
1135
+		var adminid string = "storehouse_code like ? or storehouse_name like ? or storehouse_address like ? "
1136
+		if len(slicekey) > 0 {
1137
+			for i := 0; i < len(slicekey); i++ {
1138
+				adminid = adminid + " or storehouse_admin_id =" + strconv.FormatInt(slicekey[i], 10)
1139
+			}
1140
+		}
1141
+		keyword = "%" + keyword + "%"
1142
+		db = db.Where(adminid, keyword, keyword, keyword)
1143
+	}
1144
+	err = db.Count(&total).Offset(offset).Order("id").Limit(limit).Find(&storehouse).Error
1145
+	return storehouse, total, err
1146
+}
1147
+
1148
+//获取当前机构所有可用的仓库名字
1149
+func GetAllStorehouseName(orgid int64) (storehouse []models.Storehouse, err error) {
1150
+	err = XTReadDB().Model(&models.Storehouse{}).Where("storehouse_status = 1 and status = 1 and user_org_id = ?", orgid).Find(&storehouse).Error
1151
+	return
1152
+}
1153
+
1154
+//根据机构id,生成一个默认仓库
1155
+func GetDefaultStorehouse(orgid int64) error {
1156
+	var code string
1157
+	for a := true; a == true; {
1158
+		code = CreateCode()
1159
+		tmp := FindStorehouseCode(orgid, code)
1160
+		//如果没有重复的编码结束循环
1161
+		if tmp == false {
1162
+			a = false
1163
+		}
1164
+	}
1165
+	createid, err := Getcreateid(orgid)
1166
+	if err != nil {
1167
+		return err
1168
+	}
1169
+	storehouse := models.Storehouse{
1170
+		StorehouseCode:    code,
1171
+		StorehouseName:    "默认仓库",
1172
+		StorehouseAddress: "",
1173
+		StorehouseStatus:  1,
1174
+		UserOrgId:         orgid,
1175
+		StorehouseAdminId: createid.Creator,
1176
+		Status:            1,
1177
+		Ctime:             time.Now().Unix(),
1178
+	}
1179
+	err = AddStroehouse(storehouse)
1180
+	return err
1181
+}
1182
+
1183
+//查找该机构id是否有仓库存在,ture存在,false不存在
1184
+func IsStorehouse(orgid int64) bool {
1185
+	var total int
1186
+	XTReadDB().Model(&models.Storehouse{}).Where("user_org_id = ?", orgid).Count(&total)
1187
+	if total > 0 {
1188
+		return true
1189
+	} else {
1190
+		return false
1191
+	}
1192
+}
1193
+
1194
+//查找该机构id是否有仓库配置存在,ture存在,false不存在
1195
+func IsStorehouseconfigXT(orgid int64, tx *gorm.DB) bool {
1196
+	var total int
1197
+	tx.Model(&models.StorehouseConfig{}).Where("user_org_id = ? and status = 1", orgid).Count(&total)
1198
+	if total > 0 {
1199
+		return true
1200
+	} else {
1201
+		return false
1202
+	}
1203
+}
1204
+
1205
+//  根据机构id查询仓库配置
1206
+//storehouse_info:耗材 自动入库 的仓库id
1207
+//storehouse_out_info:耗材 自动出库 的仓库id
1208
+//drug_storehouse_info:药品 自动入库 的仓库id
1209
+//drug_storehouse_out:药品 自动出库 的仓库id
1210
+func FindStorehouseConfig(orgid int64) (storehouse_config models.StorehouseConfig, err error) {
1211
+	err = XTReadDB().Model(&models.StorehouseConfig{}).Where("status = 1 and user_org_id = ?", orgid).Find(&storehouse_config).Error
1212
+	return
1213
+}
1214
+
1215
+//根据机构id,仓库id新建一个仓库配置
1216
+func CreateStorehouseConfig(orgid, id int64) (err error) {
1217
+	storeconfig := models.StorehouseConfig{
1218
+		UserOrgId:          orgid,
1219
+		StorehouseInfo:     id,
1220
+		StorehouseOutInfo:  id,
1221
+		DrugStorehouseInfo: id,
1222
+		DrugStorehouseOut:  id,
1223
+		Status:             1,
1224
+		Ctime:              time.Now().Unix(),
1225
+	}
1226
+	err = XTWriteDB().Create(&storeconfig).Error
1227
+	return
1228
+}
1229
+
1230
+//根据机构id,仓库id新建一个仓库配置,带事务
1231
+func CreateStorehouseConfigXT(orgid, id int64, tx *gorm.DB) (err error) {
1232
+	storeconfig := models.StorehouseConfig{
1233
+		UserOrgId:          orgid,
1234
+		StorehouseInfo:     id,
1235
+		StorehouseOutInfo:  id,
1236
+		DrugStorehouseInfo: id,
1237
+		DrugStorehouseOut:  id,
1238
+		Status:             1,
1239
+		Ctime:              time.Now().Unix(),
1240
+	}
1241
+	err = tx.Create(&storeconfig).Error
1242
+	return
1243
+}
1244
+
1245
+//更改耗材自动入库仓库
1246
+func UpdateInfo(orgid, id int64) (err error) {
1247
+	mtime := time.Now().Unix()
1248
+	err = XTWriteDB().Model(&models.StorehouseConfig{}).Where("user_org_id = ? and status = 1", orgid).Updates(map[string]interface{}{"storehouse_info": id, "mtime": mtime}).Error
1249
+	return
1250
+}
1251
+
1252
+//更改耗材自动出库仓库
1253
+func UpdateOutInfo(orgid, id int64) (err error) {
1254
+	mtime := time.Now().Unix()
1255
+	err = XTWriteDB().Model(&models.StorehouseConfig{}).Where("user_org_id = ? and status = 1", orgid).Updates(map[string]interface{}{"storehouse_out_info": id, "mtime": mtime}).Error
1256
+	return
1257
+}
1258
+
1259
+//更改药品自动入库仓库
1260
+func UpdateDrugInfo2(orgid, id int64) (err error) {
1261
+	mtime := time.Now().Unix()
1262
+	err = XTWriteDB().Model(&models.StorehouseConfig{}).Where("user_org_id = ? and status = 1", orgid).Updates(map[string]interface{}{"drug_storehouse_info": id, "mtime": mtime}).Error
1263
+	return
1264
+}
1265
+
1266
+//更改药品自动出库仓库
1267
+func UpdateDrugOut(orgid, id int64) (err error) {
1268
+	mtime := time.Now().Unix()
1269
+	err = XTWriteDB().Model(&models.StorehouseConfig{}).Where("user_org_id = ? and status = 1", orgid).Updates(map[string]interface{}{"drug_storehouse_out": id, "mtime": mtime}).Error
1270
+	return
1271
+}
1272
+
1273
+//根据id查询仓库名称
1274
+func FindStorehouseName(id int64) (storehouse models.Storehouse, err error) {
1275
+	err = XTReadDB().Model(&models.Storehouse{}).Where("id = ?", id).Find(&storehouse).Error
1276
+	return
1277
+}
1278
+
1279
+//判断该仓库是否在仓库配置表中
1280
+func IsInConfig(orgid, id int64) bool {
1281
+	var total int
1282
+	XTReadDB().Model(&models.StorehouseConfig{}).Where("user_org_id = ? and status = 1", orgid).Where(
1283
+		"storehouse_info = ? or storehouse_out_info = ? or drug_storehouse_info = ? or drug_storehouse_out = ?", id, id, id, id).Count(&total)
1284
+	if total > 0 {
1285
+		return true //存在
1286
+	} else {
1287
+		return false
1288
+	}
1289
+}
1290
+
1291
+//兼容旧数据
1292
+func Byliinit() (err error) {
1293
+	tx := XTWriteDB().Begin()
1294
+	defer func() {
1295
+		if err != nil && err.Error() != "record not found" {
1296
+			tx.Rollback()
1297
+		} else {
1298
+			tx.Commit()
1299
+		}
1300
+	}()
1301
+	err = initsgj_user_admin(tx)
1302
+	if err != nil && err.Error() != "record not found" {
1303
+		return
1304
+	}
1305
+	err = StoreReduceOrg(tx)
1306
+	if err != nil && err.Error() != "record not found" {
1307
+		return
1308
+	}
1309
+	err = StoreReduceConfig(tx)
1310
+	if err != nil && err.Error() != "record not found" {
1311
+		return
1312
+	}
1313
+	err = initxt_storehouse(tx)
1314
+	if err != nil && err.Error() != "record not found" {
1315
+		return
1316
+	}
1317
+	err = initxt_stock_flow(tx)
1318
+	if err != nil && err.Error() != "record not found" {
1319
+		return
1320
+	}
1321
+	err = initxt_drug_flow(tx)
1322
+	if err != nil && err.Error() != "record not found" {
1323
+		return
1324
+	}
1325
+	err = initdialysis_before_prepare(tx)
1326
+	if err != nil && err.Error() != "record not found" {
1327
+		return
1328
+	}
1329
+	err = initxt_automatic_reduce_detail(tx)
1330
+	if err != nil && err.Error() != "record not found" {
1331
+		return
1332
+	}
1333
+	err = initxt_drug_automatic_reduce_detail(tx)
1334
+	if err != nil && err.Error() != "record not found" {
1335
+		return
1336
+	}
1337
+	err = initxt_warehouse(tx)
1338
+	if err != nil && err.Error() != "record not found" {
1339
+		return
1340
+	}
1341
+	err = initxt_warehouse_info(tx)
1342
+	if err != nil && err.Error() != "record not found" {
1343
+		return
1344
+	}
1345
+	err = initxt_warehouse_out(tx)
1346
+	if err != nil && err.Error() != "record not found" {
1347
+		return
1348
+	}
1349
+	err = initxt_warehouse_out_info(tx)
1350
+	if err != nil && err.Error() != "record not found" {
1351
+		return
1352
+	}
1353
+	err = initxt_drug_warehouse(tx)
1354
+	if err != nil && err.Error() != "record not found" {
1355
+		return
1356
+	}
1357
+	err = initxt_drug_warehouse_info(tx)
1358
+	if err != nil && err.Error() != "record not found" {
1359
+		return
1360
+	}
1361
+	err = initxt_drug_warehouse_out(tx)
1362
+	if err != nil && err.Error() != "record not found" {
1363
+		return
1364
+	}
1365
+	err = initxt_drug_warehouse_out_info(tx)
1366
+	if err != nil && err.Error() != "record not found" {
1367
+		return
1368
+	}
1369
+	err = initxt_cancel_stock(tx)
1370
+	if err != nil && err.Error() != "record not found" {
1371
+		return
1372
+	}
1373
+	err = initxt_cancel_stock_info(tx)
1374
+	if err != nil && err.Error() != "record not found" {
1375
+		return
1376
+	}
1377
+	err = initxt_drug_cancel_stock(tx)
1378
+	if err != nil && err.Error() != "record not found" {
1379
+		return
1380
+	}
1381
+	err = initxt_drug_cancel_stock_info(tx)
1382
+	if err != nil && err.Error() != "record not found" {
1383
+		return
1384
+	}
1385
+	err = initxt_supplier_warehouse_info(tx)
1386
+	if err != nil && err.Error() != "record not found" {
1387
+		return
1388
+	}
1389
+	err = initxt_supplier_warehousing_info_order(tx)
1390
+	if err != nil && err.Error() != "record not found" {
1391
+		return
1392
+	}
1393
+	err = initxt_supplier_warehouse_out(tx)
1394
+	if err != nil && err.Error() != "record not found" {
1395
+		return
1396
+	}
1397
+	err = initxt_supplier_warehousing_out_order(tx)
1398
+	if err != nil && err.Error() != "record not found" {
1399
+		return
1400
+	}
1401
+	err = initxt_supplier_warehouse_cancel(tx)
1402
+	if err != nil && err.Error() != "record not found" {
1403
+		return
1404
+	}
1405
+	err = initxt_supplier_warehousing_cancel_order(tx)
1406
+
1407
+	return
1408
+}
1409
+
1410
+//初始化管理员名字
1411
+func initsgj_user_admin(tx *gorm.DB) (err error) {
1412
+	err = tx.Exec("update sgj_users.sgj_user_admin set name = \"超级管理员\" where name is null or name = \"\"").Error
1413
+	return
1414
+}
1415
+
1416
+//根据xt_gobal_template 获取的机构id减去仓库表存在的机构id,把结果插入到仓库表
1417
+func StoreReduceOrg(tx *gorm.DB) (err error) {
1418
+	err = tx.Exec("INSERT INTO sgj_xt.xt_storehouse(storehouse_code,storehouse_name,user_org_id,ctime)" +
1419
+		"SELECT CONCAT(\"SH-\",FLOOR(RAND()*9000+1000)),\"默认仓库\",tmp.id,UNIX_TIMESTAMP()" +
1420
+		"FROM" +
1421
+		"(select t1.org_id as id FROM sgj_xt.xt_gobal_template as t1 LEFT JOIN " +
1422
+		"(SELECT distinct user_org_id as i FROM sgj_xt.xt_storehouse) as t2 on t1.org_id = t2.i WHERE t2.i is null and t1.status = 1)tmp").Error
1423
+	//err = tx.Exec("INSERT INTO sgj_xt.xt_storehouse(storehouse_code,storehouse_name,user_org_id,ctime)" +
1424
+	//	"SELECT CONCAT(\"sh-\",FLOOR(RAND()*9000+1000)),\"默认仓库\",tmp.id,UNIX_TIMESTAMP()" +
1425
+	//	"FROM" +
1426
+	//	"(select t1.id FROM sgj_users.sgj_user_org as t1 LEFT JOIN " +
1427
+	//	"(SELECT distinct user_org_id as i FROM sgj_xt.xt_storehouse) as t2 on t1.id = t2.i WHERE t2.i is null and t1.status != 0 and t1.import = 0)tmp").Error
1428
+	return
1429
+}
1430
+
1431
+//查找仓库表的orgid 减去仓库配置表的orgid,把结果插入到仓库配置表
1432
+func StoreReduceConfig(tx *gorm.DB) (err error) {
1433
+	err = tx.Exec("INSERT INTO sgj_xt.xt_storehouse_config(user_org_id,storehouse_info,storehouse_out_info,drug_storehouse_info,drug_storehouse_out,ctime)" +
1434
+		"SELECT tmp.user_org_id,tmp.id,tmp.id,tmp.id,tmp.id,UNIX_TIMESTAMP()" +
1435
+		"FROM(select t1.id,t1.user_org_id FROM sgj_xt.xt_storehouse as t1 LEFT JOIN " +
1436
+		"(SELECT user_org_id as i FROM sgj_xt.xt_storehouse_config) as t2 on t1.user_org_id = t2.i WHERE t2.i is null and t1.status = 1)tmp").Error
1437
+	return
1438
+}
1439
+
1440
+//初始化 xt_storehouse 管理员的名字
1441
+func initxt_storehouse(tx *gorm.DB) (err error) {
1442
+	err = tx.Exec("UPDATE sgj_xt.xt_storehouse as t," +
1443
+		"(SELECT o.id,o.creator from sgj_users.sgj_user_org as o," +
1444
+		"(SELECT DISTINCT org_id from sgj_xt.xt_gobal_template)as t " +
1445
+		"WHERE t.org_id = o.id )tmp " +
1446
+		"SET t.storehouse_admin_id = tmp.creator,t.mtime = UNIX_TIMESTAMP()" +
1447
+		"WHERE t.status = 1 and t.user_org_id = tmp.id").Error
1448
+	return
1449
+}
1450
+
1451
+//初始化 xt_stock_flow(完成)
1452
+func initxt_stock_flow(tx *gorm.DB) (err error) {
1453
+	err = tx.Exec("UPDATE sgj_xt.xt_stock_flow as t," +
1454
+		"(SELECT t1.user_org_id as orgid,t1.storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
1455
+		"(SELECT distinct user_org_id as orgid FROM sgj_xt.xt_stock_flow  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1456
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
1457
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1458
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.user_org_id = tmp.orgid").Error
1459
+	return
1460
+}
1461
+
1462
+//初始化 xt_drug_flow(完成)
1463
+func initxt_drug_flow(tx *gorm.DB) (err error) {
1464
+	err = tx.Exec("UPDATE sgj_xt.xt_drug_flow as t," +
1465
+		"(SELECT t1.user_org_id as orgid,t1.storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
1466
+		"(SELECT distinct user_org_id as orgid FROM sgj_xt.xt_drug_flow  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1467
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
1468
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1469
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.user_org_id = tmp.orgid").Error
1470
+	return
1471
+}
1472
+
1473
+//初始化 dialysis_before_prepare(完成)
1474
+func initdialysis_before_prepare(tx *gorm.DB) (err error) {
1475
+	err = tx.Exec("UPDATE sgj_xt.dialysis_before_prepare as t," +
1476
+		"(SELECT t1.user_org_id as orgid,t1.storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
1477
+		"(SELECT distinct user_org_id as orgid FROM sgj_xt.dialysis_before_prepare  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1478
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
1479
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1480
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.user_org_id = tmp.orgid").Error
1481
+	return
1482
+}
969 1483
 
1484
+//初始化 xt_automatic_reduce_detail(完成)
1485
+func initxt_automatic_reduce_detail(tx *gorm.DB) (err error) {
1486
+	err = tx.Exec("UPDATE sgj_xt.xt_automatic_reduce_detail as t," +
1487
+		"(SELECT t1.user_org_id as orgid,t1.storehouse_out_info as id from sgj_xt.xt_storehouse_config as t1," +
1488
+		"(SELECT distinct org_id as orgid FROM sgj_xt.xt_automatic_reduce_detail  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1489
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
1490
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1491
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
1492
+	return
1493
+}
1494
+
1495
+//初始化 xt_drug_automatic_reduce_detail(完成)
1496
+func initxt_drug_automatic_reduce_detail(tx *gorm.DB) (err error) {
1497
+	err = tx.Exec("UPDATE sgj_xt.xt_drug_automatic_reduce_detail as t," +
1498
+		"(SELECT t1.user_org_id as orgid,t1.drug_storehouse_out as id from sgj_xt.xt_storehouse_config as t1," +
1499
+		"(SELECT distinct org_id as orgid FROM sgj_xt.xt_drug_automatic_reduce_detail  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1500
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
1501
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1502
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
1503
+	return
1504
+}
1505
+
1506
+//初始化 xt_warehouse(完成)
1507
+func initxt_warehouse(tx *gorm.DB) (err error) {
1508
+	err = tx.Exec("UPDATE sgj_xt.xt_warehouse as t," +
1509
+		"(SELECT t1.user_org_id as orgid,t1.storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
1510
+		"(SELECT distinct org_id as orgid FROM sgj_xt.xt_warehouse  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1511
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
1512
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1513
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
1514
+	return
1515
+}
1516
+
1517
+//初始化 xt_warehouse_info(完成)
1518
+func initxt_warehouse_info(tx *gorm.DB) (err error) {
1519
+	err = tx.Exec("UPDATE sgj_xt.xt_warehouse_info as t," +
1520
+		"(SELECT t1.user_org_id as orgid,t1.storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
1521
+		"(SELECT distinct org_id as orgid FROM sgj_xt.xt_warehouse_info  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1522
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
1523
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1524
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
1525
+	return
1526
+}
1527
+
1528
+//初始化 xt_warehouse_out(完成)
1529
+func initxt_warehouse_out(tx *gorm.DB) (err error) {
1530
+	err = tx.Exec("UPDATE sgj_xt.xt_warehouse_out as t," +
1531
+		"(SELECT t1.user_org_id as orgid,t1.storehouse_out_info as id from sgj_xt.xt_storehouse_config as t1," +
1532
+		"(SELECT distinct org_id as orgid FROM sgj_xt.xt_warehouse_out  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1533
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
1534
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1535
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
1536
+	return
1537
+}
1538
+
1539
+//初始化 xt_warehouse_out_info(完成)
1540
+func initxt_warehouse_out_info(tx *gorm.DB) (err error) {
1541
+	err = tx.Exec("UPDATE sgj_xt.xt_warehouse_out_info as t," +
1542
+		"(SELECT t1.user_org_id as orgid,t1.storehouse_out_info as id from sgj_xt.xt_storehouse_config as t1," +
1543
+		"(SELECT distinct org_id as orgid FROM sgj_xt.xt_warehouse_out_info  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1544
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
1545
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1546
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
1547
+	return
1548
+}
1549
+
1550
+//初始化 xt_drug_warehouse(完成)
1551
+func initxt_drug_warehouse(tx *gorm.DB) (err error) {
1552
+	err = tx.Exec("UPDATE sgj_xt.xt_drug_warehouse as t," +
1553
+		"(SELECT t1.user_org_id as orgid,t1.drug_storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
1554
+		"(SELECT distinct org_id as orgid FROM sgj_xt.xt_drug_warehouse  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1555
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
1556
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1557
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
1558
+	return
1559
+}
1560
+
1561
+//初始化 xt_drug_warehouse_info(完成)
1562
+func initxt_drug_warehouse_info(tx *gorm.DB) (err error) {
1563
+	err = tx.Exec("UPDATE sgj_xt.xt_drug_warehouse_info as t," +
1564
+		"(SELECT t1.user_org_id as orgid,t1.drug_storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
1565
+		"(SELECT distinct org_id as orgid FROM sgj_xt.xt_drug_warehouse_info  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1566
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
1567
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1568
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
1569
+	return
1570
+}
1571
+
1572
+//初始化 xt_drug_warehouse_out(完成)
1573
+func initxt_drug_warehouse_out(tx *gorm.DB) (err error) {
1574
+	err = tx.Exec("UPDATE sgj_xt.xt_drug_warehouse_out as t," +
1575
+		"(SELECT t1.user_org_id as orgid,t1.drug_storehouse_out as id from sgj_xt.xt_storehouse_config as t1," +
1576
+		"(SELECT distinct org_id as orgid FROM sgj_xt.xt_drug_warehouse_out  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1577
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
1578
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1579
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
1580
+	return
1581
+}
1582
+
1583
+//初始化 xt_drug_warehouse_out_info(完成)
1584
+func initxt_drug_warehouse_out_info(tx *gorm.DB) (err error) {
1585
+	err = tx.Exec("UPDATE sgj_xt.xt_drug_warehouse_out_info as t," +
1586
+		"(SELECT t1.user_org_id as orgid,t1.drug_storehouse_out as id from sgj_xt.xt_storehouse_config as t1," +
1587
+		"(SELECT distinct org_id as orgid FROM sgj_xt.xt_drug_warehouse_out_info  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1588
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
1589
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1590
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
1591
+	return
1592
+}
1593
+
1594
+//初始化 xt_cancel_stock(完成)
1595
+func initxt_cancel_stock(tx *gorm.DB) (err error) {
1596
+	err = tx.Exec("UPDATE sgj_xt.xt_cancel_stock as t," +
1597
+		"(SELECT t1.user_org_id as orgid,t1.storehouse_out_info as id from sgj_xt.xt_storehouse_config as t1," +
1598
+		"(SELECT distinct org_id as orgid FROM sgj_xt.xt_cancel_stock  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1599
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
1600
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1601
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
1602
+	return
1603
+}
1604
+
1605
+//初始化 xt_cancel_stock_info(完成)
1606
+func initxt_cancel_stock_info(tx *gorm.DB) (err error) {
1607
+	err = tx.Exec("UPDATE sgj_xt.xt_cancel_stock_info as t," +
1608
+		"(SELECT t1.user_org_id as orgid,t1.storehouse_out_info as id from sgj_xt.xt_storehouse_config as t1," +
1609
+		"(SELECT distinct org_id as orgid FROM sgj_xt.xt_cancel_stock_info  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1610
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
1611
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1612
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
1613
+	return
1614
+}
1615
+
1616
+//初始化 xt_drug_cancel_stock(完成)
1617
+func initxt_drug_cancel_stock(tx *gorm.DB) (err error) {
1618
+	err = tx.Exec("UPDATE sgj_xt.xt_drug_cancel_stock as t," +
1619
+		"(SELECT t1.user_org_id as orgid,t1.drug_storehouse_out as id from sgj_xt.xt_storehouse_config as t1," +
1620
+		"(SELECT distinct org_id as orgid FROM sgj_xt.xt_drug_cancel_stock  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1621
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
1622
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1623
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
1624
+	return
1625
+}
1626
+
1627
+//初始化 xt_drug_cancel_stock_info(完成)
1628
+func initxt_drug_cancel_stock_info(tx *gorm.DB) (err error) {
1629
+	err = tx.Exec("UPDATE sgj_xt.xt_drug_cancel_stock_info as t," +
1630
+		"(SELECT t1.user_org_id as orgid,t1.drug_storehouse_out as id from sgj_xt.xt_storehouse_config as t1," +
1631
+		"(SELECT distinct org_id as orgid FROM sgj_xt.xt_drug_cancel_stock_info  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1632
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
1633
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1634
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
1635
+	return
1636
+}
1637
+
1638
+//初始化 xt_supplier_warehouse_info(完成)
1639
+func initxt_supplier_warehouse_info(tx *gorm.DB) (err error) {
1640
+	err = tx.Exec("UPDATE sgj_xt.xt_supplier_warehouse_info as t," +
1641
+		"(SELECT t1.user_org_id as orgid,t1.storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
1642
+		"(SELECT distinct user_org_id as orgid FROM sgj_xt.xt_supplier_warehouse_info  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1643
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
1644
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1645
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.user_org_id = tmp.orgid").Error
1646
+	return
1647
+}
1648
+
1649
+//初始化 xt_supplier_warehousing_info_order(完成)
1650
+func initxt_supplier_warehousing_info_order(tx *gorm.DB) (err error) {
1651
+	err = tx.Exec("UPDATE sgj_xt.xt_supplier_warehousing_info_order as t," +
1652
+		"(SELECT t1.user_org_id as orgid,t1.storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
1653
+		"(SELECT distinct user_org_id as orgid FROM sgj_xt.xt_supplier_warehousing_info_order  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1654
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
1655
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1656
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.user_org_id = tmp.orgid").Error
1657
+	return
1658
+}
1659
+
1660
+//初始化 xt_supplier_warehouse_out(完成)
1661
+func initxt_supplier_warehouse_out(tx *gorm.DB) (err error) {
1662
+	err = tx.Exec("UPDATE sgj_xt.xt_supplier_warehouse_out as t," +
1663
+		"(SELECT t1.user_org_id as orgid,t1.storehouse_out_info as id from sgj_xt.xt_storehouse_config as t1," +
1664
+		"(SELECT distinct user_org_id as orgid FROM sgj_xt.xt_supplier_warehouse_out  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1665
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
1666
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1667
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.user_org_id = tmp.orgid").Error
1668
+	return
1669
+}
1670
+
1671
+//初始化 xt_supplier_warehousing_out_order(完成)
1672
+func initxt_supplier_warehousing_out_order(tx *gorm.DB) (err error) {
1673
+	err = tx.Exec("UPDATE sgj_xt.xt_supplier_warehousing_out_order as t," +
1674
+		"(SELECT t1.user_org_id as orgid,t1.storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
1675
+		"(SELECT distinct user_org_id as orgid FROM sgj_xt.xt_supplier_warehousing_out_order  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1676
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
1677
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1678
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.user_org_id = tmp.orgid").Error
1679
+	return
1680
+}
1681
+
1682
+//初始化 xt_supplier_warehouse_cancel(完成)
1683
+func initxt_supplier_warehouse_cancel(tx *gorm.DB) (err error) {
1684
+	err = tx.Exec("UPDATE sgj_xt.xt_supplier_warehouse_cancel as t," +
1685
+		"(SELECT t1.user_org_id as orgid,t1.storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
1686
+		"(SELECT distinct user_org_id as orgid FROM sgj_xt.xt_supplier_warehouse_cancel  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1687
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
1688
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1689
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.user_org_id = tmp.orgid").Error
1690
+	return
1691
+}
1692
+
1693
+//初始化 xt_supplier_warehousing_cancel_order(完成)
1694
+func initxt_supplier_warehousing_cancel_order(tx *gorm.DB) (err error) {
1695
+	err = tx.Exec("UPDATE sgj_xt.xt_supplier_warehousing_cancel_order as t," +
1696
+		"(SELECT t1.user_org_id as orgid,t1.storehouse_info as id from sgj_xt.xt_storehouse_config as t1," +
1697
+		"(SELECT distinct user_org_id as orgid FROM sgj_xt.xt_supplier_warehousing_cancel_order  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
1698
+		"WHERE t1.user_org_id = t2.orgid)tmp " +
1699
+		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
1700
+		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.user_org_id = tmp.orgid").Error
1701
+	return
1702
+}
1703
+
1704
+//查询机构创建者的id
1705
+func Getcreateid(orgid int64) (createid models.UserOrg, err error) {
1706
+	err = XTReadDB().Select("id,creator").Where("id = ? and status = 1", orgid).Find(&createid).Error
1707
+	return
1708
+}
1709
+
1710
+//根据机构id查询拥有仓库管理权限的角色
1711
+func FindRoles(orgid int64) map[string]int {
1712
+	role := []models.RolePurviews{}
1713
+	roles := make(map[string]int)
1714
+	XTReadDB().Select("role_id").Where("purview_ids like \"%299%\" and org_id = ? and status = 1", orgid).Find(&role)
1715
+	for i := 0; i < len(role); i++ {
1716
+		roles[strconv.FormatInt(role[i].RoleId, 10)] = i
1717
+	}
1718
+	return roles
1719
+}
1720
+
1721
+//判断两个切片中的元素是否有重复的,true有重复的元素,false无相同元素
1722
+func IsIdentical(str1 []string, str2 []string) (t bool) {
1723
+	t = false
1724
+	if len(str1) == 0 || len(str2) == 0 {
1725
+		return
1726
+	}
1727
+	map1, map2 := make(map[string]int), make(map[string]int)
1728
+	for i := 0; i < len(str1); i++ {
1729
+		map1[str1[i]] = i
1730
+	}
1731
+	for i := 0; i < len(str2); i++ {
1732
+		map2[str2[i]] = i
1733
+	}
1734
+	for k, _ := range map1 {
1735
+		if _, ok := map2[k]; ok {
1736
+			t = true
1737
+		}
1738
+	}
1739
+	return
970 1740
 func ModifyWarehouseOut(id int64, orgid int64, good_id int64) error {
971 1741
 	err := XTWriteDB().Model(&models.WarehouseOut{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"status": 0}).Error
972 1742
 

+ 2 - 1
service/self_drug_service.go 查看文件

@@ -1006,7 +1006,7 @@ func GetDrugInventoryList(keyword string, page int64, limit int64, orgid int64,
1006 1006
 	if endtime > 0 {
1007 1007
 		db = db.Where("x.start_time<=?", endtime)
1008 1008
 	}
1009
-	err = db.Select("x.id,x.drug_name,x.specification_name,x.warehousing_unit,x.count,x.last_price,x.retail_price,x.manufacturer,x.dealer,x.remark,x.drug_id,x.warehousing_order,x.number,x.batch_number,x.start_time,x.creater,x.checker,x.checker_status,x.checker_time,x.min_count,x.min_unit,t.dose,t.dose_unit,t.max_unit,t.min_unit").Joins("left join sgj_users.sgj_user_admin_role as r on r.id = x.creater").Joins("left join xt_base_drug as t on t.id =x.drug_id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Scan(&list).Error
1009
+	err = db.Select("x.id,x.drug_name,x.specification_name,x.warehousing_unit,x.count,x.last_price,x.retail_price,x.manufacturer,x.dealer,x.remark,x.drug_id,x.warehousing_order,x.number,x.batch_number,x.start_time,x.creater,x.checker,x.checker_status,x.checker_time,x.min_count,x.min_unit,t.dose,t.dose_unit,t.max_unit,t.min_unit").Joins("left join sgj_users.sgj_user_admin_role as r on r.id = x.creater").Joins("left join xt_base_drug as t on t.id =x.drug_id").Count(&total).Order("x.id desc").Offset(offset).Limit(limit).Order("x.ctime desc").Scan(&list).Error
1010 1010
 	return list, total, err
1011 1011
 }
1012 1012
 
@@ -1111,6 +1111,7 @@ func GetDrugInventoryDetailList(keyword string, page int64, limit int64, orgid i
1111 1111
 		db = db.Where("x.storehouse_id = ?", storehouse_id)
1112 1112
 	}
1113 1113
 	err = db.Select("x.id,x.drug_name,x.specification_name,x.warehousing_unit,x.count,x.last_price,x.retail_price,x.manufacturer,x.dealer,x.remark,x.drug_id,x.warehousing_order,x.number,x.batch_number,x.start_time,x.creater,x.checker,x.checker_status,x.checker_time,x.total,x.drug_origin_place,x.expiry_date,x.product_date,x.min_count,x.storehouse_id,t.dose,t.dose_unit,t.max_unit,x.min_unit,x.stock_max_number,x.stock_min_number,x.last_stock_max_number,x.last_stock_min_number,x.inventory_type").Joins("left join sgj_users.sgj_user_admin_role as r on r.id = x.creater").Joins("left join xt_base_drug as t on t.id =x.drug_id").Count(&total).Offset(offset).Limit(limit).Scan(&list).Error
1114
+	err = db.Select("x.id,x.drug_name,x.specification_name,x.warehousing_unit,x.count,x.last_price,x.retail_price,x.manufacturer,x.dealer,x.remark,x.drug_id,x.warehousing_order,x.number,x.batch_number,x.start_time,x.creater,x.checker,x.checker_status,x.checker_time,x.total,x.drug_origin_place,x.expiry_date,x.product_date,x.min_count,t.dose,t.dose_unit,t.max_unit,x.min_unit,x.stock_max_number,x.stock_min_number,x.last_stock_max_number,x.last_stock_min_number,x.inventory_type").Joins("left join sgj_users.sgj_user_admin_role as r on r.id = x.creater").Joins("left join xt_base_drug as t on t.id =x.drug_id").Count(&total).Order("x.ctime desc").Offset(offset).Limit(limit).Scan(&list).Error
1114 1115
 	return list, total, err
1115 1116
 }
1116 1117
 

+ 1 - 0
service/stock_service.go 查看文件

@@ -5626,6 +5626,7 @@ func GetInventoryDetailList(keyword string, limit int64, page int64, orgid int64
5626 5626
 		db = db.Where("x.storehouse_id = ?", storehouse_id)
5627 5627
 	}
5628 5628
 	err = db.Select("x.id,x.good_name,x.specification_name,x.warehousing_unit,x.count,x.buy_price,x.packing_price,x.new_price,x.manufacturer,x.dealer,x.remark,x.good_id,x.warehousing_order,x.license_number,x.start_time,x.creater,x.checker,x.checker_status,x.checker_time,x.total,x.number,x.expire_date,x.product_date,t.packing_unit,x.last_stock_count,x.type,x.inventory_type,x.stock_count,x.storehouse_id").Joins("left join sgj_users.sgj_user_admin_role as r on r.id = x.creater").Joins("left join xt_good_information as t on t.id =x.good_id").Count(&total).Offset(offset).Limit(limit).Scan(&list).Error
5629
+	err = db.Select("x.id,x.good_name,x.specification_name,x.warehousing_unit,x.count,x.buy_price,x.packing_price,x.new_price,x.manufacturer,x.dealer,x.remark,x.good_id,x.warehousing_order,x.license_number,x.start_time,x.creater,x.checker,x.checker_status,x.checker_time,x.total,x.number,x.expire_date,x.product_date,t.packing_unit,x.last_stock_count,x.type,x.inventory_type,x.stock_count,x.ctime").Joins("left join sgj_users.sgj_user_admin_role as r on r.id = x.creater").Joins("left join xt_good_information as t on t.id =x.good_id").Count(&total).Order("x.ctime desc").Offset(offset).Limit(limit).Scan(&list).Error
5629 5630
 	return list, total, err
5630 5631
 }
5631 5632
 

+ 7 - 5
service/supply_service.go 查看文件

@@ -169,30 +169,32 @@ func GetSupplyAndContactOne(id, orgId int64) (supply models.SpSupplierName, cont
169 169
 }
170 170
 
171 171
 //删除供应商及联系人
172
-func DelSupply(supply models.SpSupplierName, orgId int64) error {
172
+func DelSupply(supply models.SpSupplierName, orgId int64) (shiwu string, err error) {
173 173
 	tx := XTWriteDB().Begin()
174 174
 	defer func() {
175 175
 		if err != nil {
176
+			shiwu = "失败"
176 177
 			tx.Rollback()
177 178
 		} else {
179
+			shiwu = "成功"
178 180
 			tx.Commit()
179 181
 		}
180 182
 	}()
181 183
 	//删除供应商
182
-	err := tx.Model(&supply).Update("status", 0).Error
184
+	err = tx.Model(&supply).Update("status", 0).Error
183 185
 	if err != nil {
184
-		return err
186
+		return shiwu, err
185 187
 	}
186 188
 	var spcode models.SpSupplierName
187 189
 	//获取供应商编号
188 190
 	err = tx.Model(&models.SpSupplierName{}).Select("supplier_code").Where("user_org_id = ? and id = ?", orgId, supply.ID).First(&spcode).Error
189 191
 	if err != nil {
190
-		return err
192
+		return shiwu, err
191 193
 	}
192 194
 	//删除联系人
193 195
 	err = tx.Model(&models.SpSupplierContacts{}).Where("supplier_code = ? and user_org_id = ?", spcode.SupplierCode, orgId).Update("status", 0).Error
194 196
 
195
-	return err
197
+	return shiwu, err
196 198
 }
197 199
 
198 200
 //保存供应商和联系人