package services

import (
	"errors"
	"gin-vue-admin/common"
	"gin-vue-admin/repository"
)

func RevenueTodayListService(phone, t string) (interface{}, error) {

	// 1. 查询当前手机号是否有默认医院
	chainCode, employeeId, err := repository.QueryChainCodeAndLocalIDByPhone(phone)
	if err != nil {
		return nil, err
	}

	if chainCode == "" {
		return nil, errors.New("请设置默认医院")
	}

	// 2. 拿到db
	safeMap := common.NewSafeMap()
	db, err := safeMap.GetOrStore(chainCode)
	if err != nil {
		return nil, err
	}

	return repository.RevenueTodayList(db, t, employeeId)
}
