123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- package service
-
- import "XT_New/models"
-
- func FindAllDrugWarehousingInfo(org_id int64, is_pc int64, is_bg int64, start_time int64, end_time int64) (list []*models.DrugWarehouseInfoTenOne, err error) {
- db := readDb.Model(&models.DrugWarehouseInfoTenOne{}).Preload("BaseDrugLib", "org_id = ?", org_id)
- if is_pc == 1 {
- db = db.Where("is_pc = ?", is_pc)
- }
- if is_bg == 1 {
- db = db.Where("is_bg = ?", is_bg)
- }
- if is_pc == 2 {
- db = db.Where("is_pc = ?", 0)
- }
- if is_bg == 2 {
- db = db.Where("is_bg = ?", 0)
- }
-
- if start_time != 0 {
- db = db.Where("ctime >= ?", start_time)
-
- }
- if end_time != 0 {
- db = db.Where("ctime <= ?", end_time)
-
- }
-
- err = db.Where("status = 1 and org_id = ?", org_id).Find(&list).Error
- return list, err
- }
-
- func GetNewDrugFlow(orgid int64, limit int64, page int64, startTime int64, endTime int64, is_sale int64, is_bg int64) (drug_flow []*models.NewDrugFlow, total int64, err error) {
-
- offset := (page - 1) * limit
- db := XTReadDB().Model(drug_flow).Where("status = 1")
- if orgid > 0 {
- db = db.Where("user_org_id = ?", orgid)
- }
- if startTime > 0 {
- db = db.Where("ctime >=? ", startTime)
- }
- if endTime > 0 {
- db = db.Where("ctime<=?", endTime)
- }
- if is_sale != 3 {
- db = db.Where("is_sale = ?", is_sale)
- }
- if is_bg != 3 {
- db = db.Where("is_change = ?", is_bg)
- }
-
- //if stock_type > 0 {
-
- //手动入库
- //if stock_type == 1 {
- db = db.Where("consumable_type <> 1")
- //}
-
- //}
- err = db.Count(&total).Offset(offset).Limit(limit).Order("id desc").Preload("BaseDrugLib", "status = 1 and org_id =?", orgid).Preload("DrugWarehouseInfo", "status = 1 and org_id = ?", orgid).Preload("XtDrugWarehouseOutInfo", "status = 1 and org_id = ?", orgid).Preload("HisDoctorAdviceInfo", "status=1 and user_org_id =?", orgid).Find(&drug_flow).Error
- for _, item := range drug_flow {
- var doc models.HisDoctorAdviceInfo
- var p models.HisPrescription
- readDb.Model(&models.HisDoctorAdviceInfo{}).Where("id = ?", item.AdviceId).First(&doc)
- readDb.Model(&models.HisPrescription{}).Where("id = ?", doc.PrescriptionId).First(&p)
- item.PDate = p.RecordDate
- item.PCount = doc.PrescribingNumber
- item.Unit = doc.PrescribingNumberUnit
- if p.OrderStatus == 2 && len(p.BatchNumber) > 0 {
- var ho models.HisOrder
- readDb.Model(&models.HisOrder{}).Where("user_org_id = ? and number = ?", p.UserOrgId, p.BatchNumber).First(&ho)
- item.SDate = ho.SetlTime
- }
- }
- return drug_flow, total, err
- }
|