瀏覽代碼

打印单单位修改

mainqaq 2 年之前
父節點
當前提交
20ee98baa1
共有 2 個文件被更改,包括 160 次插入70 次删除
  1. 159 69
      service/pharmacy_service.go
  2. 1 1
      service/warhouse_service.go

+ 159 - 69
service/pharmacy_service.go 查看文件

40
 
40
 
41
 //查询药房中某一天的患者人数,is_medicine:0未发,1已发(改)
41
 //查询药房中某一天的患者人数,is_medicine:0未发,1已发(改)
42
 func GetTodayPharmacy(stime, etime, orgid, is_medicine int64) (num int, err error) {
42
 func GetTodayPharmacy(stime, etime, orgid, is_medicine int64) (num int, err error) {
43
+	//orgid = 9675
43
 	InitDrugidIsNil(orgid, stime, etime)
44
 	InitDrugidIsNil(orgid, stime, etime)
44
 	var tmp []*models.TmpTTT
45
 	var tmp []*models.TmpTTT
45
-	err = XTReadDB().Raw("select distinct patient_id from his_doctor_advice_info where "+
46
-		"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
47
-		"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) "+
48
-		"union "+
49
-		"select distinct patient_id from xt_doctor_advice where "+
50
-		"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
51
-		"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) ",
52
-		stime, etime, orgid, is_medicine, orgid, stime, etime, orgid, is_medicine, orgid).Scan(&tmp).Error
53
-	if err != nil {
54
-		return
46
+	if is_medicine == 0 {
47
+		err = XTReadDB().Raw("select distinct patient_id from his_doctor_advice_info where "+
48
+			"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = 0 and "+
49
+			"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) "+
50
+			"union "+
51
+			"select distinct patient_id from xt_doctor_advice where "+
52
+			"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = 0 and "+
53
+			"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) ",
54
+			stime, etime, orgid, orgid, stime, etime, orgid, orgid).Scan(&tmp).Error
55
+		if err != nil {
56
+			return
57
+		}
58
+	} else {
59
+		err = XTReadDB().Raw("select distinct patient_id from his_doctor_advice_info where "+
60
+			"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = 1 and "+
61
+			"drug_id in (select id from xt_base_drug where org_id = ? and status = 1) "+
62
+			"union "+
63
+			"select distinct patient_id from xt_doctor_advice where "+
64
+			"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = 1 and "+
65
+			"drug_id in (select id from xt_base_drug where org_id = ? and status = 1) ",
66
+			stime, etime, orgid, orgid, stime, etime, orgid, orgid).Scan(&tmp).Error
67
+		if err != nil {
68
+			return
69
+		}
55
 	}
70
 	}
71
+
56
 	return len(tmp), err
72
 	return len(tmp), err
57
 
73
 
58
 }
74
 }
63
 	//病人
79
 	//病人
64
 	var tmp []*models.TmpTTT
80
 	var tmp []*models.TmpTTT
65
 	//tmp := make([]string,0)
81
 	//tmp := make([]string,0)
66
-	if keyword != "" {
67
-		keyword = "%" + keyword + "%"
68
-		err = XTReadDB().Raw("select a.* from(select distinct patient_id,dispensing_time from his_doctor_advice_info where "+
69
-			"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
70
-			"patient_id in (select id from xt_patients where user_org_id = ? and name like ? or dialysis_no like ?) and "+
71
-			"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) "+
72
-			"union "+
73
-			"select distinct patient_id,dispensing_time from xt_doctor_advice where "+
74
-			"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
75
-			"patient_id in (select id from xt_patients where user_org_id = ? and name like ? or dialysis_no like ?) and "+
76
-			"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1))a order by dispensing_time desc ",
77
-			stime, etime, orgid, is_medicine, orgid, keyword, keyword, orgid, stime, etime, orgid, is_medicine, orgid, keyword, keyword, orgid).Scan(&tmp).Error
82
+	if is_medicine == 0 {
83
+		if keyword != "" {
84
+			keyword = "%" + keyword + "%"
85
+			err = XTReadDB().Raw("select a.* from(select distinct patient_id,dispensing_time from his_doctor_advice_info where "+
86
+				"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
87
+				"patient_id in (select id from xt_patients where user_org_id = ? and name like ? or dialysis_no like ?) and "+
88
+				"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) "+
89
+				"union "+
90
+				"select distinct patient_id,dispensing_time from xt_doctor_advice where "+
91
+				"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
92
+				"patient_id in (select id from xt_patients where user_org_id = ? and name like ? or dialysis_no like ?) and "+
93
+				"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1))a order by dispensing_time desc ",
94
+				stime, etime, orgid, is_medicine, orgid, keyword, keyword, orgid, stime, etime, orgid, is_medicine, orgid, keyword, keyword, orgid).Scan(&tmp).Error
95
+		} else {
96
+			err = XTReadDB().Raw("select a.* from(select distinct patient_id,dispensing_time from his_doctor_advice_info where "+
97
+				"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
98
+				"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) "+
99
+				"union "+
100
+				"select distinct patient_id,dispensing_time from xt_doctor_advice where "+
101
+				"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
102
+				"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1))a order by dispensing_time desc",
103
+				stime, etime, orgid, is_medicine, orgid, stime, etime, orgid, is_medicine, orgid).Scan(&tmp).Error
104
+		}
105
+
106
+		if err != nil {
107
+			return
108
+		}
78
 	} else {
109
 	} else {
79
-		err = XTReadDB().Raw("select a.* from(select distinct patient_id,dispensing_time from his_doctor_advice_info where "+
80
-			"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
81
-			"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) "+
82
-			"union "+
83
-			"select distinct patient_id,dispensing_time from xt_doctor_advice where "+
84
-			"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
85
-			"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1))a order by dispensing_time desc",
86
-			stime, etime, orgid, is_medicine, orgid, stime, etime, orgid, is_medicine, orgid).Scan(&tmp).Error
87
-	}
110
+		if keyword != "" {
111
+			keyword = "%" + keyword + "%"
112
+			err = XTReadDB().Raw("select a.* from(select distinct patient_id,dispensing_time from his_doctor_advice_info where "+
113
+				"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
114
+				"patient_id in (select id from xt_patients where user_org_id = ? and name like ? or dialysis_no like ?) and "+
115
+				"drug_id in (select id from xt_base_drug where org_id = ? and status = 1) "+
116
+				"union "+
117
+				"select distinct patient_id,dispensing_time from xt_doctor_advice where "+
118
+				"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
119
+				"patient_id in (select id from xt_patients where user_org_id = ? and name like ? or dialysis_no like ?) and "+
120
+				"drug_id in (select id from xt_base_drug where org_id = ? and status = 1))a order by dispensing_time desc ",
121
+				stime, etime, orgid, is_medicine, orgid, keyword, keyword, orgid, stime, etime, orgid, is_medicine, orgid, keyword, keyword, orgid).Scan(&tmp).Error
122
+		} else {
123
+			err = XTReadDB().Raw("select a.* from(select distinct patient_id,dispensing_time from his_doctor_advice_info where "+
124
+				"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
125
+				"drug_id in (select id from xt_base_drug where org_id = ? and status = 1) "+
126
+				"union "+
127
+				"select distinct patient_id,dispensing_time from xt_doctor_advice where "+
128
+				"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
129
+				"drug_id in (select id from xt_base_drug where org_id = ? and status = 1))a order by dispensing_time desc",
130
+				stime, etime, orgid, is_medicine, orgid, stime, etime, orgid, is_medicine, orgid).Scan(&tmp).Error
131
+		}
88
 
132
 
89
-	if err != nil {
90
-		return
133
+		if err != nil {
134
+			return
135
+		}
91
 	}
136
 	}
137
+
92
 	tmp_s := make([]int64, 0)
138
 	tmp_s := make([]int64, 0)
93
 	s_map := make(map[int64]int64)
139
 	s_map := make(map[int64]int64)
94
 	for _, v := range tmp {
140
 	for _, v := range tmp {
123
 func GetPatientMedication(orgid, patient_id, stime, etime, is_medicine int64) (pp []*models.PharmacyContent, err error) {
169
 func GetPatientMedication(orgid, patient_id, stime, etime, is_medicine int64) (pp []*models.PharmacyContent, err error) {
124
 	InitDrugidIsNil(orgid, stime, etime)
170
 	InitDrugidIsNil(orgid, stime, etime)
125
 	var tmp []*models.HisDoctorAdviceInfoL
171
 	var tmp []*models.HisDoctorAdviceInfoL
126
-	err = XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where(
127
-		"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and patient_id = ? and is_medicine = ? and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1)", stime, etime, orgid, patient_id, is_medicine, orgid).Find(&tmp).Error
128
-	if err != nil {
129
-		return pp, err
172
+	if is_medicine == 0 {
173
+		err = XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where(
174
+			"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and patient_id = ? and is_medicine = ? and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1)", stime, etime, orgid, patient_id, is_medicine, orgid).Find(&tmp).Error
175
+		if err != nil {
176
+			return pp, err
177
+		}
178
+	} else {
179
+		err = XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where(
180
+			"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and patient_id = ? and is_medicine = ? and drug_id in (select id from xt_base_drug where org_id = ? and status = 1)", stime, etime, orgid, patient_id, is_medicine, orgid).Find(&tmp).Error
181
+		if err != nil {
182
+			return pp, err
183
+		}
130
 	}
184
 	}
185
+
131
 	for _, v := range tmp {
186
 	for _, v := range tmp {
132
 		pp = append(pp, &models.PharmacyContent{
187
 		pp = append(pp, &models.PharmacyContent{
133
 			Name:         v.AdviceName,
188
 			Name:         v.AdviceName,
143
 	}
198
 	}
144
 
199
 
145
 	var tmp_advice []*models.XtDoctorAdviceL
200
 	var tmp_advice []*models.XtDoctorAdviceL
146
-	err = XTReadDB().Model(&models.XtDoctorAdviceL{}).Where(
147
-		"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and patient_id = ? and is_medicine = ? and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1)", stime, etime, orgid, patient_id, is_medicine, orgid).Find(&tmp_advice).Error
148
-	if err != nil {
149
-		return pp, err
201
+	if is_medicine == 0 {
202
+		err = XTReadDB().Model(&models.XtDoctorAdviceL{}).Where(
203
+			"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and patient_id = ? and is_medicine = ? and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1)", stime, etime, orgid, patient_id, is_medicine, orgid).Find(&tmp_advice).Error
204
+		if err != nil {
205
+			return pp, err
206
+		}
207
+	} else {
208
+		err = XTReadDB().Model(&models.XtDoctorAdviceL{}).Where(
209
+			"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and patient_id = ? and is_medicine = ? and drug_id in (select id from xt_base_drug where org_id = ? and status = 1)", stime, etime, orgid, patient_id, is_medicine, orgid).Find(&tmp_advice).Error
210
+		if err != nil {
211
+			return pp, err
212
+		}
150
 	}
213
 	}
214
+
151
 	for _, v := range tmp_advice {
215
 	for _, v := range tmp_advice {
152
 		pp = append(pp, &models.PharmacyContent{
216
 		pp = append(pp, &models.PharmacyContent{
153
 			Name:         v.AdviceName,
217
 			Name:         v.AdviceName,
267
 func PrescriptionDetails(patient_id, record_date, orgid int64) (pre []*models.PrescripDetails, err error) {
331
 func PrescriptionDetails(patient_id, record_date, orgid int64) (pre []*models.PrescripDetails, err error) {
268
 	var tmp []*models.HisDoctorAdviceInfoL
332
 	var tmp []*models.HisDoctorAdviceInfoL
269
 	err = XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where(
333
 	err = XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where(
270
-		"status = 1 and patient_id = ? and user_org_id = ? and dispensing_time = ? and is_medicine = 1 and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1)", patient_id, orgid, record_date, orgid).Find(&tmp).Error
334
+		"status = 1 and patient_id = ? and user_org_id = ? and dispensing_time = ? and is_medicine = 1 and drug_id in (select id from xt_base_drug where org_id = ? and status = 1)", patient_id, orgid, record_date, orgid).Find(&tmp).Error
271
 	if err != nil {
335
 	if err != nil {
272
 		return
336
 		return
273
 	}
337
 	}
286
 
350
 
287
 	var tmp_advice []*models.XtDoctorAdviceL
351
 	var tmp_advice []*models.XtDoctorAdviceL
288
 	err = XTReadDB().Model(&models.XtDoctorAdviceL{}).Where(
352
 	err = XTReadDB().Model(&models.XtDoctorAdviceL{}).Where(
289
-		"status = 1 and (advice_type = 2 or advice_type = 3) and patient_id = ? and user_org_id = ? and dispensing_time = ? and is_medicine = 1 and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1)", patient_id, orgid, record_date, orgid).Find(&tmp_advice).Error
353
+		"status = 1 and (advice_type = 2 or advice_type = 3) and patient_id = ? and user_org_id = ? and dispensing_time = ? and is_medicine = 1 and drug_id in (select id from xt_base_drug where org_id = ? and status = 1)", patient_id, orgid, record_date, orgid).Find(&tmp_advice).Error
290
 	if err != nil {
354
 	if err != nil {
291
 		return
355
 		return
292
 	}
356
 	}
341
 func GetTodayMedicine(stime, etime, orgid, is_medicine int64, keyword string) (finlly []*models.ListOfDrugs, err error) {
405
 func GetTodayMedicine(stime, etime, orgid, is_medicine int64, keyword string) (finlly []*models.ListOfDrugs, err error) {
342
 	InitDrugidIsNil(orgid, stime, etime)
406
 	InitDrugidIsNil(orgid, stime, etime)
343
 	var tmp []*models.TmpLLL
407
 	var tmp []*models.TmpLLL
344
-	if keyword != "" {
345
-		keyword = "%" + keyword + "%"
346
-		err = XTReadDB().Raw("select distinct drug_id from his_doctor_advice_info where "+
347
-			"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
348
-			"drug_id in (select id from xt_base_drug where org_id = ? and drug_name like ? and is_pharmacy = 1) "+
349
-			"union "+
350
-			"select distinct drug_id from xt_doctor_advice where "+
351
-			"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
352
-			"drug_id in (select id from xt_base_drug where org_id = ? and drug_name like ? and is_pharmacy = 1)",
353
-			stime, etime, orgid, is_medicine, orgid, keyword, stime, etime, orgid, is_medicine, orgid, keyword).Scan(&tmp).Error
408
+	if is_medicine == 0 {
409
+		if keyword != "" {
410
+			keyword = "%" + keyword + "%"
411
+			err = XTReadDB().Raw("select distinct drug_id from his_doctor_advice_info where "+
412
+				"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
413
+				"drug_id in (select id from xt_base_drug where org_id = ? and drug_name like ? and is_pharmacy = 1) "+
414
+				"union "+
415
+				"select distinct drug_id from xt_doctor_advice where "+
416
+				"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
417
+				"drug_id in (select id from xt_base_drug where org_id = ? and drug_name like ? and is_pharmacy = 1)",
418
+				stime, etime, orgid, is_medicine, orgid, keyword, stime, etime, orgid, is_medicine, orgid, keyword).Scan(&tmp).Error
419
+		} else {
420
+			err = XTReadDB().Raw("select distinct drug_id from his_doctor_advice_info where "+
421
+				"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
422
+				"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) "+
423
+				"union "+
424
+				"select distinct drug_id from xt_doctor_advice where "+
425
+				"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
426
+				"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) ",
427
+				stime, etime, orgid, is_medicine, orgid, stime, etime, orgid, is_medicine, orgid).Scan(&tmp).Error
428
+		}
429
+		if err != nil {
430
+			return
431
+		}
354
 	} else {
432
 	} else {
355
-		err = XTReadDB().Raw("select distinct drug_id from his_doctor_advice_info where "+
356
-			"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
357
-			"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) "+
358
-			"union "+
359
-			"select distinct drug_id from xt_doctor_advice where "+
360
-			"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
361
-			"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) ",
362
-			stime, etime, orgid, is_medicine, orgid, stime, etime, orgid, is_medicine, orgid).Scan(&tmp).Error
433
+		if keyword != "" {
434
+			keyword = "%" + keyword + "%"
435
+			err = XTReadDB().Raw("select distinct drug_id from his_doctor_advice_info where "+
436
+				"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
437
+				"drug_id in (select id from xt_base_drug where org_id = ? and drug_name like ? and is_pharmacy = 1) "+
438
+				"union "+
439
+				"select distinct drug_id from xt_doctor_advice where "+
440
+				"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
441
+				"drug_id in (select id from xt_base_drug where org_id = ? and drug_name like ? and is_pharmacy = 1)",
442
+				stime, etime, orgid, is_medicine, orgid, keyword, stime, etime, orgid, is_medicine, orgid, keyword).Scan(&tmp).Error
443
+		} else {
444
+			err = XTReadDB().Raw("select distinct drug_id from his_doctor_advice_info where "+
445
+				"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
446
+				"drug_id in (select id from xt_base_drug where org_id = ? and status = 1) "+
447
+				"union "+
448
+				"select distinct drug_id from xt_doctor_advice where "+
449
+				"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
450
+				"drug_id in (select id from xt_base_drug where org_id = ? and status = 1) ",
451
+				stime, etime, orgid, is_medicine, orgid, stime, etime, orgid, is_medicine, orgid).Scan(&tmp).Error
452
+		}
453
+		if err != nil {
454
+			return
455
+		}
363
 	}
456
 	}
364
 
457
 
365
-	if err != nil {
366
-		return
367
-	}
368
 	for _, v := range tmp {
458
 	for _, v := range tmp {
369
 		name, specifications := FindDrugSpecifications(v.DrugId)
459
 		name, specifications := FindDrugSpecifications(v.DrugId)
370
 		number, errs := GetInventoryQuantity(orgid, v.DrugId)
460
 		number, errs := GetInventoryQuantity(orgid, v.DrugId)
607
 	var xids []*models.TmpID
697
 	var xids []*models.TmpID
608
 	//var hid,xid []int64//查询已发药的药品
698
 	//var hid,xid []int64//查询已发药的药品
609
 	err = tx.Raw("select id,dispensing_time from his_doctor_advice_info where status = 1 and created_time >= ? and created_time <= ? "+
699
 	err = tx.Raw("select id,dispensing_time from his_doctor_advice_info where status = 1 and created_time >= ? and created_time <= ? "+
610
-		"and user_org_id = ? and patient_id = ? and is_medicine = 1 and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1)", stime, etime, orgid, patient_id, orgid).Scan(&hids).Error
700
+		"and user_org_id = ? and patient_id = ? and is_medicine = 1 and drug_id in (select id from xt_base_drug where org_id = ? and status = 1)", stime, etime, orgid, patient_id, orgid).Scan(&hids).Error
611
 	if err != nil {
701
 	if err != nil {
612
 		return
702
 		return
613
 	}
703
 	}
655
 	}
745
 	}
656
 
746
 
657
 	err = tx.Raw("select id,dispensing_time from xt_doctor_advice where status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and "+
747
 	err = tx.Raw("select id,dispensing_time from xt_doctor_advice where status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and "+
658
-		"user_org_id = ? and patient_id = ? and is_medicine = 1 and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1)", stime, etime, orgid, patient_id, orgid).Scan(&xids).Error
748
+		"user_org_id = ? and patient_id = ? and is_medicine = 1 and drug_id in (select id from xt_base_drug where org_id = ? and status = 1)", stime, etime, orgid, patient_id, orgid).Scan(&xids).Error
659
 	if err != nil {
749
 	if err != nil {
660
 		return
750
 		return
661
 	}
751
 	}
700
 
790
 
701
 	//删除掉发药明细
791
 	//删除掉发药明细
702
 	for k, _ := range map_time {
792
 	for k, _ := range map_time {
703
-		err = tx.Model(&models.Pharmary{}).Where("user_org_id = ? and record_date = ? ", orgid, k).Updates(map[string]interface{}{
793
+		err = tx.Model(&models.Pharmary{}).Where("user_org_id = ? and record_date = ? and patient_id = ? ", orgid, k, patient_id).Updates(map[string]interface{}{
704
 			"status": 0,
794
 			"status": 0,
705
 			"mtime":  time.Now().Unix(),
795
 			"mtime":  time.Now().Unix(),
706
 		}).Error
796
 		}).Error
954
 	var tmp []*models.TmpAdviceDoctor
1044
 	var tmp []*models.TmpAdviceDoctor
955
 	//var tmp []int64
1045
 	//var tmp []int64
956
 	err = XTReadDB().Raw("select distinct advice_doctor from his_doctor_advice_info where "+
1046
 	err = XTReadDB().Raw("select distinct advice_doctor from his_doctor_advice_info where "+
957
-		"status = 1 and dispensing_time = ? and user_org_id = ? and is_medicine = 1 and patient_id = ? and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) "+
1047
+		"status = 1 and dispensing_time = ? and user_org_id = ? and is_medicine = 1 and patient_id = ? and drug_id in (select id from xt_base_drug where org_id = ? and status = 1) "+
958
 		"union "+
1048
 		"union "+
959
 		"select distinct advice_doctor from xt_doctor_advice where "+
1049
 		"select distinct advice_doctor from xt_doctor_advice where "+
960
-		"status = 1 and (advice_type = 2 or advice_type = 3) and dispensing_time = ? and user_org_id = ? and is_medicine = 1 and patient_id = ? and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) ",
1050
+		"status = 1 and (advice_type = 2 or advice_type = 3) and dispensing_time = ? and user_org_id = ? and is_medicine = 1 and patient_id = ? and drug_id in (select id from xt_base_drug where org_id = ? and status = 1) ",
961
 		recordtime, orgid, id, orgid, recordtime, orgid, id, orgid).Scan(&tmp).Error
1051
 		recordtime, orgid, id, orgid, recordtime, orgid, id, orgid).Scan(&tmp).Error
962
 	if err != nil || len(tmp) == 0 {
1052
 	if err != nil || len(tmp) == 0 {
963
 		return
1053
 		return

+ 1 - 1
service/warhouse_service.go 查看文件

268
 				warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
268
 				warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
269
 			}
269
 			}
270
 
270
 
271
-			if minNumber == 0 && maxNumber != 1 {
271
+			if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
272
 				if warehouse.StockMinNumber > 0 {
272
 				if warehouse.StockMinNumber > 0 {
273
 					warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
273
 					warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
274
 				}
274
 				}