new_stock_medical_insurance_service.go 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package service
  2. import "XT_New/models"
  3. func FindAllDrugWarehousingInfo(org_id int64, is_pc int64, is_bg int64, start_time int64, end_time int64) (list []*models.DrugWarehouseInfoTenOne, err error) {
  4. db := readDb.Model(&models.DrugWarehouseInfoTenOne{}).Preload("BaseDrugLib", "org_id = ?", org_id)
  5. if is_pc == 1 {
  6. db = db.Where("is_pc = ?", is_pc)
  7. }
  8. if is_bg == 1 {
  9. db = db.Where("is_bg = ?", is_bg)
  10. }
  11. if is_pc == 2 {
  12. db = db.Where("is_pc = ?", 0)
  13. }
  14. if is_bg == 2 {
  15. db = db.Where("is_bg = ?", 0)
  16. }
  17. if start_time != 0 {
  18. db = db.Where("ctime >= ?", start_time)
  19. }
  20. if end_time != 0 {
  21. db = db.Where("ctime <= ?", end_time)
  22. }
  23. err = db.Where("status = 1 and org_id = ?", org_id).Find(&list).Error
  24. return list, err
  25. }
  26. 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) {
  27. offset := (page - 1) * limit
  28. db := XTReadDB().Model(drug_flow).Where("status = 1")
  29. if orgid > 0 {
  30. db = db.Where("user_org_id = ?", orgid)
  31. }
  32. if startTime > 0 {
  33. db = db.Where("ctime >=? ", startTime)
  34. }
  35. if endTime > 0 {
  36. db = db.Where("ctime<=?", endTime)
  37. }
  38. if is_sale != 3 {
  39. db = db.Where("is_sale = ?", is_sale)
  40. }
  41. if is_bg != 3 {
  42. db = db.Where("is_change = ?", is_bg)
  43. }
  44. //if stock_type > 0 {
  45. //手动入库
  46. //if stock_type == 1 {
  47. db = db.Where("consumable_type <> 1")
  48. //}
  49. //}
  50. err = db.Count(&total).Offset(offset).Limit(limit).Order("id desc").Preload("BaseDrugLib", "status = 1").Preload("DrugWarehouseInfo", "status = 1").Preload("XtDrugWarehouseOutInfo", "status = 1").Find(&drug_flow).Error
  51. for _, item := range drug_flow {
  52. var doc models.HisDoctorAdviceInfo
  53. var p models.HisPrescription
  54. readDb.Model(&models.HisDoctorAdviceInfo{}).Where("id = ?", item.AdviceId).First(&doc)
  55. readDb.Model(&models.HisPrescription{}).Where("id = ?", doc.PrescriptionId).First(&p)
  56. item.PDate = p.RecordDate
  57. item.PCount = doc.PrescribingNumber
  58. item.Unit = doc.PrescribingNumberUnit
  59. if p.OrderStatus == 2 && len(p.BatchNumber) > 0 {
  60. var ho models.HisOrder
  61. readDb.Model(&models.HisOrder{}).Where("user_org_id = ? and number = ?", p.UserOrgId, p.BatchNumber).First(&ho)
  62. item.SDate = ho.SetlTime
  63. }
  64. }
  65. return drug_flow, total, err
  66. }