2
This commit is contained in:
@@ -8,6 +8,15 @@ import (
|
||||
|
||||
type DoctorPharmacyDao struct{}
|
||||
|
||||
// GetDoctorPharmacyById 获取绑定关系-主键id
|
||||
func (r *DoctorPharmacyDao) GetDoctorPharmacyById(doctorPharmacyId int64) (m *model.DoctorPharmacy, err error) {
|
||||
err = global.Db.Where("doctor_pharmacy_id = ?", doctorPharmacyId).First(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetDoctorPharmacyListByDoctorId 获取医生绑定的药房列表(带预加载药房详情)
|
||||
func (r *DoctorPharmacyDao) GetDoctorPharmacyListByDoctorId(doctorId int64) (m []*model.DoctorPharmacy, err error) {
|
||||
err = global.Db.Preload("Pharmacy").Where("doctor_id = ? AND status = 1", doctorId).Order("is_default desc, created_at desc").Find(&m).Error
|
||||
@@ -43,6 +52,15 @@ func (r *DoctorPharmacyDao) DeleteDoctorPharmacy(tx *gorm.DB, maps interface{})
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteDoctorPharmacyById 根据绑定关系主键id删除
|
||||
func (r *DoctorPharmacyDao) DeleteDoctorPharmacyById(tx *gorm.DB, doctorPharmacyId int64) error {
|
||||
err := tx.Where("doctor_pharmacy_id = ?", doctorPharmacyId).Delete(&model.DoctorPharmacy{}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteDoctorPharmacyByDoctorAndPharmacy 解绑指定医生和指定药房
|
||||
func (r *DoctorPharmacyDao) DeleteDoctorPharmacyByDoctorAndPharmacy(tx *gorm.DB, doctorId, pharmacyId int64) error {
|
||||
err := tx.Where("doctor_id = ? AND pharmacy_id = ?", doctorId, pharmacyId).Delete(&model.DoctorPharmacy{}).Error
|
||||
@@ -69,3 +87,12 @@ func (r *DoctorPharmacyDao) SetDefaultPharmacy(tx *gorm.DB, doctorId, pharmacyId
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetDefaultPharmacyById 根据主键设为默认
|
||||
func (r *DoctorPharmacyDao) SetDefaultPharmacyById(tx *gorm.DB, doctorPharmacyId int64) error {
|
||||
err := tx.Model(&model.DoctorPharmacy{}).Where("doctor_pharmacy_id = ?", doctorPharmacyId).Update("is_default", 1).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user