diff --git a/api/controller/doctorPharmacy.go b/api/controller/doctorPharmacy.go index 5821429..7a2873c 100644 --- a/api/controller/doctorPharmacy.go +++ b/api/controller/doctorPharmacy.go @@ -152,7 +152,7 @@ func (r *DoctorPharmacy) UnbindDoctorPharmacy(c *gin.Context) { pharmacyIdStr := c.Query("pharmacy_id") if pharmacyIdStr != "" { pharmacyId, err := strconv.ParseInt(pharmacyIdStr, 10, 64) - if err == nil && pharmacyId > 0 { + if err == nil && pharmacyId >= 0 { _, err = doctorPharmacyService.UnbindDoctorPharmacy(id, pharmacyId) if err != nil { responses.FailWithMessage(err.Error(), c) @@ -236,7 +236,7 @@ func (r *DoctorPharmacy) SetDefaultDoctorPharmacy(c *gin.Context) { pharmacyIdStr := c.Query("pharmacy_id") if pharmacyIdStr != "" { pharmacyId, err := strconv.ParseInt(pharmacyIdStr, 10, 64) - if err == nil && pharmacyId > 0 { + if err == nil && pharmacyId >= 0 { _, err = doctorPharmacyService.SetDefaultPharmacy(id, pharmacyId) if err != nil { responses.FailWithMessage(err.Error(), c) diff --git a/api/service/doctorPharmacy.go b/api/service/doctorPharmacy.go index 6d19038..9d3ca34 100644 --- a/api/service/doctorPharmacy.go +++ b/api/service/doctorPharmacy.go @@ -32,7 +32,7 @@ func (r *DoctorPharmacyService) BindDoctorPharmacies(doctorId int64, req request } pharmacyDao := dao.PharmacyDao{} - var defaultPharmacyId int64 + var defaultPharmacyId int64 = -1 if req.DefaultPharmacyId != "" { defaultPharmacyId, _ = strconv.ParseInt(req.DefaultPharmacyId, 10, 64) } @@ -56,7 +56,7 @@ func (r *DoctorPharmacyService) BindDoctorPharmacies(doctorId int64, req request // 遍历新增绑定 for i, v := range req.PharmacyIds { pharmacyId, err := strconv.ParseInt(v, 10, 64) - if err != nil || pharmacyId == 0 { + if err != nil || pharmacyId < 0 { continue } @@ -68,9 +68,9 @@ func (r *DoctorPharmacyService) BindDoctorPharmacies(doctorId int64, req request } isDefault := 0 - if defaultPharmacyId != 0 && pharmacyId == defaultPharmacyId { + if defaultPharmacyId >= 0 && pharmacyId == defaultPharmacyId { isDefault = 1 - } else if defaultPharmacyId == 0 && i == 0 { + } else if defaultPharmacyId < 0 && i == 0 { // 未指定默认药房时,默认第1个为默认药房 isDefault = 1 } @@ -103,7 +103,7 @@ func (r *DoctorPharmacyService) AddDoctorPharmacy(doctorId int64, req requests.A } pharmacyId, err := strconv.ParseInt(req.PharmacyId, 10, 64) - if err != nil || pharmacyId == 0 { + if err != nil || pharmacyId < 0 { return false, errors.New("药房id无效") } diff --git a/api/service/pharmacy.go b/api/service/pharmacy.go index c9595a5..c7290b7 100644 --- a/api/service/pharmacy.go +++ b/api/service/pharmacy.go @@ -264,7 +264,7 @@ func (r *PharmacyService) GetPharmacy(pharmacyId int64) (*dto.PharmacyDto, error // GetPharmacyDoctorPage 获取药房绑定的医生列表-分页 func (r *PharmacyService) GetPharmacyDoctorPage(req requests.GetPharmacyDoctorPage) (map[string]interface{}, error) { pharmacyId, err := strconv.ParseInt(req.PharmacyId, 10, 64) - if err != nil || pharmacyId == 0 { + if err != nil || pharmacyId < 0 { return nil, errors.New("药房id无效") }