package third

import (
	"ordonnance/common/util"
	"ordonnance/server/dao"
	"ordonnance/server/model"
	"ordonnance/server/response"

	"github.com/gin-gonic/gin"
)

// 显示二维码
func GetordonnanceQrcode(c *gin.Context) {
	id := c.Param("ordonnanceId")
	ordonnance, err := dao.GetOrdonnance(id)
	if err != nil {
		response.FailWithMessage("要放不存在", c)
		return
	}
	filename := util.MakeImg(ordonnance)
	c.File(filename)
}

// 获取数据
func GetordonnanceDetail(c *gin.Context) {
	id := c.Param("ordonnanceId")
	ordonnance, err := dao.GetOrdonnance(id)
	if err != nil {
		response.FailWithMessage(id+"药方不存在", c)
		return
	}
	list, err := dao.GetOrdonnanceItemList(id)
	data := model.VordonnanceDetail{
		Ordonnance: ordonnance,
		Detail:     list,
	}
	response.OkWithData(data, c)
}
