新增了 退还用户优惠卷、新增了处理用户处方图片
This commit is contained in:
parent
63ee23e60f
commit
2db307941e
@ -110,6 +110,11 @@ func (r *InquiryConfig) PutDoctorInquiryConfig(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if req.InquiryMode == 6 {
|
||||
responses.FailWithMessage("疑难问诊暂不可使用", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 业务处理
|
||||
doctorInquiryConfigService := service.DoctorInquiryConfigService{}
|
||||
_, err = doctorInquiryConfigService.PutDoctorInquiryConfig(inquiryConfigId, req)
|
||||
|
||||
@ -87,6 +87,17 @@ func (r *OrderInquiry) GetOrderInquiry(c *gin.Context) {
|
||||
|
||||
// CancelOrderInquiry 取消问诊订单
|
||||
func (r *OrderInquiry) CancelOrderInquiry(c *gin.Context) {
|
||||
//OrderService := service.OrderService{}
|
||||
//
|
||||
//_, err := OrderService.PdfToImg()
|
||||
//if err != nil {
|
||||
// responses.FailWithMessage(err.Error(), c)
|
||||
// return
|
||||
//}
|
||||
//
|
||||
//responses.Ok(c)
|
||||
//return
|
||||
|
||||
id := c.Param("order_inquiry_id")
|
||||
if id == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
|
||||
62
api/dao/order.go
Normal file
62
api/dao/order.go
Normal file
@ -0,0 +1,62 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"hospital-admin-api/api/model"
|
||||
"hospital-admin-api/global"
|
||||
)
|
||||
|
||||
type OrderDao struct {
|
||||
}
|
||||
|
||||
// GetOrderById 获取数据-id
|
||||
func (r *OrderDao) GetOrderById(orderId int64) (m *model.Order, err error) {
|
||||
err = global.Db.First(&m, orderId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// AddOrder 新增
|
||||
func (r *OrderDao) AddOrder(tx *gorm.DB, model *model.Order) (*model.Order, error) {
|
||||
if err := tx.Create(model).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return model, nil
|
||||
}
|
||||
|
||||
// GetOrderList 获取列表
|
||||
func (r *OrderDao) GetOrderList(maps interface{}) (m []*model.Order, err error) {
|
||||
err = global.Db.Where(maps).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetOrder 获取单个
|
||||
func (r *OrderDao) GetOrder(maps interface{}) (m *model.Order, err error) {
|
||||
err = global.Db.Where(maps).First(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// DeleteOrderById 删除-id
|
||||
func (r *OrderDao) DeleteOrderById(tx *gorm.DB, orderId int64) error {
|
||||
if err := tx.Delete(&model.Order{}, orderId).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditOrderById 修改-id
|
||||
func (r *OrderDao) EditOrderById(tx *gorm.DB, orderId int64, data interface{}) error {
|
||||
err := tx.Model(&model.Order{}).Where("order_id = ?", orderId).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
53
api/dao/orderCoupon.go
Normal file
53
api/dao/orderCoupon.go
Normal file
@ -0,0 +1,53 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"hospital-admin-api/api/model"
|
||||
"hospital-admin-api/global"
|
||||
)
|
||||
|
||||
type OrderCouponDao struct {
|
||||
}
|
||||
|
||||
// GetOrderCouponById 获取数据-接口id
|
||||
func (r *OrderCouponDao) GetOrderCouponById(orderCouponId int64) (m *model.OrderCoupon, err error) {
|
||||
err = global.Db.First(&m, orderCouponId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// AddOrderCoupon 新增
|
||||
func (r *OrderCouponDao) AddOrderCoupon(tx *gorm.DB, model *model.OrderCoupon) (*model.OrderCoupon, error) {
|
||||
if err := tx.Create(model).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return model, nil
|
||||
}
|
||||
|
||||
// GetOrderCouponList 获取列表
|
||||
func (r *OrderCouponDao) GetOrderCouponList(maps interface{}) (m []*model.OrderCoupon, err error) {
|
||||
err = global.Db.Where(maps).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// DeleteOrderCouponById 删除-id
|
||||
func (r *OrderCouponDao) DeleteOrderCouponById(tx *gorm.DB, orderCouponId int64) error {
|
||||
if err := tx.Delete(&model.OrderCoupon{}, orderCouponId).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditOrderCouponById 修改-id
|
||||
func (r *OrderCouponDao) EditOrderCouponById(tx *gorm.DB, orderCouponId int64, data interface{}) error {
|
||||
err := tx.Model(&model.OrderCoupon{}).Where("order_coupon_id = ?", orderCouponId).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
79
api/dao/orderPrescriptionFile.go
Normal file
79
api/dao/orderPrescriptionFile.go
Normal file
@ -0,0 +1,79 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"hospital-admin-api/api/model"
|
||||
"hospital-admin-api/global"
|
||||
)
|
||||
|
||||
type OrderPrescriptionFileDao struct {
|
||||
}
|
||||
|
||||
// GetOrderPrescriptionFileById 获取处方关联CA数据-处方关联CAid
|
||||
func (r *OrderPrescriptionFileDao) GetOrderPrescriptionFileById(PrescriptionFileId int64) (m *model.OrderPrescriptionFile, err error) {
|
||||
err = global.Db.First(&m, PrescriptionFileId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (r *OrderPrescriptionFileDao) GetOrderPrescriptionFileByOrderPrescriptionId(orderPrescriptionId int64) (m *model.OrderPrescriptionFile, err error) {
|
||||
err = global.Db.Where("order_prescription_id = ?", orderPrescriptionId).First(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (r *OrderPrescriptionFileDao) GetOrderPrescriptionFileListByOrderPrescriptionId(orderPrescriptionId int64) (m []*model.OrderPrescriptionFile, err error) {
|
||||
err = global.Db.Where("order_prescription_id = ?", orderPrescriptionId).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// DeleteOrderPrescriptionFile 删除处方关联CA
|
||||
func (r *OrderPrescriptionFileDao) DeleteOrderPrescriptionFile(tx *gorm.DB, maps interface{}) error {
|
||||
err := tx.Where(maps).Delete(&model.OrderPrescriptionFile{}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditOrderPrescriptionFile 修改处方关联CA
|
||||
func (r *OrderPrescriptionFileDao) EditOrderPrescriptionFile(tx *gorm.DB, maps interface{}, data interface{}) error {
|
||||
err := tx.Model(&model.OrderPrescriptionFile{}).Where(maps).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditOrderPrescriptionFileById 修改处方关联CA
|
||||
func (r *OrderPrescriptionFileDao) EditOrderPrescriptionFileById(tx *gorm.DB, PrescriptionFileId int64, data interface{}) error {
|
||||
err := tx.Model(&model.OrderPrescriptionFile{}).Where("prescription_file_id = ?", PrescriptionFileId).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetOrderPrescriptionFileList 获取处方关联CA列表
|
||||
func (r *OrderPrescriptionFileDao) GetOrderPrescriptionFileList(maps interface{}) (m []*model.OrderPrescriptionFile, err error) {
|
||||
err = global.Db.Where(maps).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// AddOrderPrescriptionFile 新增处方关联CA
|
||||
func (r *OrderPrescriptionFileDao) AddOrderPrescriptionFile(tx *gorm.DB, model *model.OrderPrescriptionFile) (*model.OrderPrescriptionFile, error) {
|
||||
if err := tx.Create(model).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return model, nil
|
||||
}
|
||||
53
api/dao/orderRefund.go
Normal file
53
api/dao/orderRefund.go
Normal file
@ -0,0 +1,53 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"hospital-admin-api/api/model"
|
||||
"hospital-admin-api/global"
|
||||
)
|
||||
|
||||
type OrderRefundDao struct {
|
||||
}
|
||||
|
||||
// GetOrderRefundById 获取接口数据-接口id
|
||||
func (r *OrderRefundDao) GetOrderRefundById(orderRefundId int64) (m *model.OrderRefund, err error) {
|
||||
err = global.Db.First(&m, orderRefundId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// AddOrderRefund 新增接口
|
||||
func (r *OrderRefundDao) AddOrderRefund(tx *gorm.DB, model *model.OrderRefund) (*model.OrderRefund, error) {
|
||||
if err := tx.Create(model).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return model, nil
|
||||
}
|
||||
|
||||
// GetOrderRefundList 获取接口列表
|
||||
func (r *OrderRefundDao) GetOrderRefundList(maps interface{}) (m []*model.OrderRefund, err error) {
|
||||
err = global.Db.Where(maps).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// DeleteOrderRefundById 删除接口-接口id
|
||||
func (r *OrderRefundDao) DeleteOrderRefundById(tx *gorm.DB, orderRefundId int64) error {
|
||||
if err := tx.Delete(&model.OrderRefund{}, orderRefundId).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditOrderRefundById 修改接口-接口id
|
||||
func (r *OrderRefundDao) EditOrderRefundById(tx *gorm.DB, orderRefundId int64, data interface{}) error {
|
||||
err := tx.Model(&model.OrderRefund{}).Where("order_refund_id = ?", orderRefundId).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -7,6 +7,7 @@ import (
|
||||
|
||||
type OrderInquiryDto struct {
|
||||
OrderInquiryId string `json:"order_inquiry_id"` // 主键id
|
||||
OrderId string `json:"order_id"` // 订单id
|
||||
UserId string `json:"user_id"` // 用户id-患者
|
||||
PatientId string `json:"patient_id"` // 患者id
|
||||
DoctorId string `json:"doctor_id"` // 医生id(未分配时为null)
|
||||
@ -62,6 +63,7 @@ func GetOrderInquiryDto(m *model.OrderInquiry) *OrderInquiryDto {
|
||||
|
||||
return &OrderInquiryDto{
|
||||
OrderInquiryId: fmt.Sprintf("%d", m.OrderInquiryId),
|
||||
OrderId: fmt.Sprintf("%d", m.OrderId),
|
||||
UserId: fmt.Sprintf("%d", m.UserId),
|
||||
DoctorId: doctorId,
|
||||
PatientId: fmt.Sprintf("%d", m.PatientId),
|
||||
@ -107,6 +109,7 @@ func GetOrderInquiryListDto(m []*model.OrderInquiry) []*OrderInquiryDto {
|
||||
for i, v := range m {
|
||||
response := &OrderInquiryDto{
|
||||
OrderInquiryId: fmt.Sprintf("%d", v.OrderInquiryId),
|
||||
OrderId: fmt.Sprintf("%d", v.OrderId),
|
||||
UserId: fmt.Sprintf("%d", v.UserId),
|
||||
PatientId: fmt.Sprintf("%d", v.PatientId),
|
||||
DoctorId: fmt.Sprintf("%d", v.DoctorId),
|
||||
@ -165,6 +168,7 @@ func GetOrderInquiryRecordListDto(m []*model.OrderInquiry) []*OrderInquiryDto {
|
||||
for i, v := range m {
|
||||
response := &OrderInquiryDto{
|
||||
OrderInquiryId: fmt.Sprintf("%d", v.OrderInquiryId),
|
||||
OrderId: fmt.Sprintf("%d", v.OrderId),
|
||||
UserId: fmt.Sprintf("%d", v.UserId),
|
||||
PatientId: fmt.Sprintf("%d", v.PatientId),
|
||||
DoctorId: fmt.Sprintf("%d", v.DoctorId),
|
||||
@ -220,6 +224,7 @@ func GetOrderInquiryForAccountListDto(m []*model.OrderInquiry) []*OrderInquiryDt
|
||||
for i, v := range m {
|
||||
response := &OrderInquiryDto{
|
||||
OrderInquiryId: fmt.Sprintf("%d", v.OrderInquiryId),
|
||||
OrderId: fmt.Sprintf("%d", v.OrderId),
|
||||
UserId: fmt.Sprintf("%d", v.UserId),
|
||||
PatientId: fmt.Sprintf("%d", v.PatientId),
|
||||
DoctorId: fmt.Sprintf("%d", v.DoctorId),
|
||||
@ -276,6 +281,7 @@ func GetOrderInquiryRecordDto(m *model.OrderInquiry) *OrderInquiryDto {
|
||||
|
||||
return &OrderInquiryDto{
|
||||
OrderInquiryId: fmt.Sprintf("%d", m.OrderInquiryId),
|
||||
OrderId: fmt.Sprintf("%d", m.OrderId),
|
||||
UserId: fmt.Sprintf("%d", m.UserId),
|
||||
DoctorId: doctorId,
|
||||
PatientId: fmt.Sprintf("%d", m.PatientId),
|
||||
|
||||
@ -10,6 +10,7 @@ type OrderProductDto struct {
|
||||
OrderProductId string `json:"order_product_id"` // 主键id
|
||||
OrderInquiryId string `json:"order_inquiry_id"` // 订单-问诊id;NOT NULL
|
||||
OrderPrescriptionId string `json:"order_prescription_id"` // 订单-处方id;NOT NULL
|
||||
OrderId string `json:"order_id"` // 订单id
|
||||
DoctorId string `json:"doctor_id"` // 医生id
|
||||
PatientId string `json:"patient_id"` // 患者id
|
||||
FamilyId string `json:"family_id"` // 家庭成员id(就诊用户)
|
||||
|
||||
51
api/model/order.go
Normal file
51
api/model/order.go
Normal file
@ -0,0 +1,51 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"hospital-admin-api/global"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Order 订单表
|
||||
type Order struct {
|
||||
OrderId int64 `gorm:"column:order_id;type:bigint(19);primary_key;comment:主键id" json:"order_id"`
|
||||
UserId int64 `gorm:"column:user_id;type:bigint(19);comment:用户id-患者;NOT NULL" json:"user_id"`
|
||||
PatientId int64 `gorm:"column:patient_id;type:bigint(19);comment:患者id;NOT NULL" json:"patient_id"`
|
||||
DoctorId int64 `gorm:"column:doctor_id;type:bigint(19);comment:医生id(存在为null的情况)" json:"doctor_id"`
|
||||
OrderType int `gorm:"column:order_type;type:tinyint(1);comment:订单类型(1:问诊订单 2:药品订单 3:检测订单 4:随访包订单 5:健康包订单);NOT NULL" json:"order_type"`
|
||||
IsDelete int `gorm:"column:is_delete;type:tinyint(1);default:0;comment:删除状态(0:否 1:是)" json:"is_delete"`
|
||||
PayChannel int `gorm:"column:pay_channel;type:tinyint(1);default:1;comment:支付渠道(1:小程序支付 2:微信扫码支付 3:模拟支付);NOT NULL" json:"pay_channel"`
|
||||
PayStatus int `gorm:"column:pay_status;type:tinyint(1);default:1;comment:支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款);NOT NULL" json:"pay_status"`
|
||||
PayTime LocalTime `gorm:"column:pay_time;type:datetime;comment:支付时间" json:"pay_time"`
|
||||
RefundStatus int `gorm:"column:refund_status;type:tinyint(1);default:0;comment:订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常 7:部分退款);NOT NULL" json:"refund_status"`
|
||||
OrderNo string `gorm:"column:order_no;type:varchar(30);comment:系统订单编号;NOT NULL" json:"order_no"`
|
||||
EscrowTradeNo string `gorm:"column:escrow_trade_no;type:varchar(100);comment:第三方支付流水号" json:"escrow_trade_no"`
|
||||
AmountTotal float64 `gorm:"column:amount_total;type:decimal(10,2) unsigned;default:0.00;comment:订单金额" json:"amount_total"`
|
||||
CouponAmountTotal float64 `gorm:"column:coupon_amount_total;type:decimal(10,2) unsigned;default:0.00;comment:优惠卷总金额" json:"coupon_amount_total"`
|
||||
PaymentAmountTotal float64 `gorm:"column:payment_amount_total;type:decimal(10,2) unsigned;default:0.00;comment:实际付款金额" json:"payment_amount_total"`
|
||||
CancelStatus int `gorm:"column:cancel_status;type:tinyint(1);default:0;comment:取消状态(0:否 1:是)" json:"cancel_status"`
|
||||
CancelTime LocalTime `gorm:"column:cancel_time;type:datetime;comment:订单取消时间" json:"cancel_time"`
|
||||
CancelRemarks string `gorm:"column:cancel_remarks;type:varchar(255);comment:取消订单备注" json:"cancel_remarks"`
|
||||
OrderRemarks string `gorm:"column:order_remarks;type:varchar(255);comment:订单备注" json:"order_remarks"`
|
||||
IsWithdrawal int `gorm:"column:is_withdrawal;type:tinyint(1);default:0;comment:是否提现(0:否 1:是 2:提现中 3:无需提现)" json:"is_withdrawal"`
|
||||
WithdrawalTime LocalTime `gorm:"column:withdrawal_time;type:datetime;comment:提现时间" json:"withdrawal_time"`
|
||||
Model
|
||||
}
|
||||
|
||||
func (m *Order) TableName() string {
|
||||
return "gdxz_order"
|
||||
}
|
||||
|
||||
func (m *Order) BeforeCreate(tx *gorm.DB) error {
|
||||
if m.OrderId == 0 {
|
||||
m.OrderId = global.Snowflake.Generate().Int64()
|
||||
}
|
||||
|
||||
m.CreatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
|
||||
|
||||
m.UpdatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
|
||||
|
||||
return nil
|
||||
}
|
||||
34
api/model/orderCoupon.go
Normal file
34
api/model/orderCoupon.go
Normal file
@ -0,0 +1,34 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"hospital-admin-api/global"
|
||||
"time"
|
||||
)
|
||||
|
||||
type OrderCoupon struct {
|
||||
OrderCouponId int64 `gorm:"column:order_coupon_id;type:bigint(19);primary_key;comment:主键id" json:"order_coupon_id"`
|
||||
OrderId int64 `gorm:"column:order_id;type:bigint(19);comment:订单id;NOT NULL" json:"order_id"`
|
||||
UserCouponId int64 `gorm:"column:user_coupon_id;type:bigint(19);comment:用户优惠卷表id;NOT NULL" json:"user_coupon_id"`
|
||||
CouponName string `gorm:"column:coupon_name;type:varchar(255);comment:优惠卷名称" json:"coupon_name"`
|
||||
CouponUsePrice float64 `gorm:"column:coupon_use_price;type:decimal(10,2);default:0.00;comment:优惠卷使用金额" json:"coupon_use_price"`
|
||||
Model
|
||||
}
|
||||
|
||||
func (m *OrderCoupon) TableName() string {
|
||||
return "gdxz_order_coupon"
|
||||
}
|
||||
|
||||
func (m *OrderCoupon) BeforeCreate(tx *gorm.DB) error {
|
||||
if m.OrderCouponId == 0 {
|
||||
m.OrderCouponId = global.Snowflake.Generate().Int64()
|
||||
}
|
||||
|
||||
m.CreatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
|
||||
|
||||
m.UpdatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -9,6 +9,7 @@ import (
|
||||
// OrderInquiry 订单-问诊表
|
||||
type OrderInquiry struct {
|
||||
OrderInquiryId int64 `gorm:"column:order_inquiry_id;type:bigint(19);primary_key;comment:主键id" json:"order_inquiry_id"`
|
||||
OrderId int64 `gorm:"column:order_id;type:bigint(19);comment:订单id" json:"order_id"`
|
||||
UserId int64 `gorm:"column:user_id;type:bigint(19);comment:用户id-患者;NOT NULL" json:"user_id"`
|
||||
PatientId int64 `gorm:"column:patient_id;type:bigint(19);comment:患者id;NOT NULL" json:"patient_id"`
|
||||
DoctorId int64 `gorm:"column:doctor_id;type:bigint(19);comment:医生id(未分配时为null)" json:"doctor_id"`
|
||||
|
||||
37
api/model/orderPrescriptionFile.go
Normal file
37
api/model/orderPrescriptionFile.go
Normal file
@ -0,0 +1,37 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"hospital-admin-api/global"
|
||||
"time"
|
||||
)
|
||||
|
||||
// OrderPrescriptionFile 订单-处方表-ca处方文件
|
||||
type OrderPrescriptionFile struct {
|
||||
PrescriptionFileId int64 `gorm:"column:prescription_file_id;type:bigint(19);primary_key;comment:主键id" json:"prescription_file_id"`
|
||||
OrderPrescriptionId int64 `gorm:"column:order_prescription_id;type:bigint(19);comment:订单-处方id" json:"order_prescription_id"`
|
||||
DoctorCaFileId string `gorm:"column:doctor_ca_file_id;type:varchar(100);comment:医生签章pdf文件id(可请求ca下载)" json:"doctor_ca_file_id"`
|
||||
HospitalCaFileId string `gorm:"column:hospital_ca_file_id;type:varchar(100);comment:医院签章pdf文件id(可请求ca下载)" json:"hospital_ca_file_id"`
|
||||
PrescriptionImgOssPath string `gorm:"column:prescription_img_oss_path;type:varchar(255);comment:签章img文件oss路径" json:"prescription_img_oss_path"`
|
||||
PrescriptionPdfOssPath string `gorm:"column:prescription_pdf_oss_path;type:varchar(255);comment:签章pdf文件oss路径" json:"prescription_pdf_oss_path"`
|
||||
IsConvertedPdf int `gorm:"column:is_converted_pdf;type:tinyint(1);default:0;comment:是否已转换pdf为图片(0:否 1:是)" json:"is_converted_pdf"`
|
||||
Model
|
||||
}
|
||||
|
||||
func (m *OrderPrescriptionFile) TableName() string {
|
||||
return "gdxz_order_prescription_file"
|
||||
}
|
||||
|
||||
func (m *OrderPrescriptionFile) BeforeCreate(tx *gorm.DB) error {
|
||||
if m.PrescriptionFileId == 0 {
|
||||
m.PrescriptionFileId = global.Snowflake.Generate().Int64()
|
||||
}
|
||||
|
||||
m.CreatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
|
||||
|
||||
m.UpdatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -11,6 +11,7 @@ type OrderProduct struct {
|
||||
OrderProductId int64 `gorm:"column:order_product_id;type:bigint(20);primary_key;comment:主键id" json:"order_product_id"`
|
||||
OrderInquiryId int64 `gorm:"column:order_inquiry_id;type:bigint(19);comment:订单-问诊id;NOT NULL" json:"order_inquiry_id"`
|
||||
OrderPrescriptionId int64 `gorm:"column:order_prescription_id;type:bigint(19);comment:订单-处方id;NOT NULL" json:"order_prescription_id"`
|
||||
OrderId int64 `gorm:"column:order_id;type:bigint(19);comment:订单id" json:"order_id"`
|
||||
DoctorId int64 `gorm:"column:doctor_id;type:bigint(19);comment:医生id" json:"doctor_id"`
|
||||
PatientId int64 `gorm:"column:patient_id;type:bigint(19);comment:患者id" json:"patient_id"`
|
||||
FamilyId int64 `gorm:"column:family_id;type:bigint(19);comment:家庭成员id(就诊用户)" json:"family_id"`
|
||||
|
||||
40
api/model/orderRefund.go
Normal file
40
api/model/orderRefund.go
Normal file
@ -0,0 +1,40 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"hospital-admin-api/global"
|
||||
"time"
|
||||
)
|
||||
|
||||
// OrderRefund 订单-退款表
|
||||
type OrderRefund struct {
|
||||
OrderRefundId int64 `gorm:"column:order_refund_id;type:bigint(19);primary_key;comment:主键id" json:"order_refund_id"`
|
||||
OrderId int64 `gorm:"column:order_id;type:bigint(19);comment:订单id;NOT NULL" json:"order_id"`
|
||||
PatientId int64 `gorm:"column:patient_id;type:bigint(19);comment:患者id" json:"patient_id"`
|
||||
OrderNo string `gorm:"column:order_no;type:varchar(40);comment:系统订单编号" json:"order_no"`
|
||||
RefundNo string `gorm:"column:refund_no;type:varchar(50);comment:系统退款编号;NOT NULL" json:"refund_no"`
|
||||
RefundId string `gorm:"column:refund_id;type:varchar(50);comment:第三方退款单号" json:"refund_id"`
|
||||
RefundStatus int `gorm:"column:refund_status;type:tinyint(1);default:0;comment:订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常 7:部分退款)" json:"refund_status"`
|
||||
RefundTotal float64 `gorm:"column:refund_total;type:decimal(10,2);default:0.00;comment:退款金额" json:"refund_total"`
|
||||
RefundReason string `gorm:"column:refund_reason;type:varchar(255);comment:退款原因" json:"refund_reason"`
|
||||
SuccessTime LocalTime `gorm:"column:success_time;type:datetime;comment:退款成功时间" json:"success_time"`
|
||||
Model
|
||||
}
|
||||
|
||||
func (m *OrderRefund) TableName() string {
|
||||
return "gdxz_order_refund"
|
||||
}
|
||||
|
||||
func (m *OrderRefund) BeforeCreate(tx *gorm.DB) error {
|
||||
if m.OrderRefundId == 0 {
|
||||
m.OrderRefundId = global.Snowflake.Generate().Int64()
|
||||
}
|
||||
|
||||
m.CreatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
|
||||
|
||||
m.UpdatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -70,6 +70,11 @@ func (r *OrderInquiryService) CancelOrderInquiry(req requests.CancelOrderInquiry
|
||||
return false, errors.New("订单未支付,无需取消")
|
||||
}
|
||||
|
||||
// 检测问诊类型-服务包类型不允许取消
|
||||
if orderInquiry.InquiryMode == 8 || orderInquiry.InquiryMode == 9 {
|
||||
return false, errors.New("服务包类型订单不允许退款")
|
||||
}
|
||||
|
||||
// 检测退款金额
|
||||
if req.RefundAmount > orderInquiry.PaymentAmountTotal {
|
||||
return false, errors.New("退款金额不可超过实付金额")
|
||||
@ -100,14 +105,11 @@ func (r *OrderInquiryService) CancelOrderInquiry(req requests.CancelOrderInquiry
|
||||
}
|
||||
}()
|
||||
|
||||
// 问诊订单修改数据
|
||||
orderInquiryData := make(map[string]interface{})
|
||||
|
||||
// 退款编号
|
||||
inquiryRefundNo := strconv.FormatInt(global.Snowflake.Generate().Int64(), 10)
|
||||
refundNo := strconv.FormatInt(global.Snowflake.Generate().Int64(), 10)
|
||||
|
||||
// 退款状态转换
|
||||
var inquiryRefundStatus int
|
||||
var refundStatus int
|
||||
var successTime time.Time
|
||||
var refundId string
|
||||
|
||||
@ -116,7 +118,7 @@ func (r *OrderInquiryService) CancelOrderInquiry(req requests.CancelOrderInquiry
|
||||
refundRequest := weChat.RefundRequest{
|
||||
TransactionId: orderInquiry.EscrowTradeNo,
|
||||
OutTradeNo: orderInquiry.InquiryNo,
|
||||
OutRefundNo: inquiryRefundNo,
|
||||
OutRefundNo: refundNo,
|
||||
Reason: "客服取消",
|
||||
RefundAmount: int64(req.RefundAmount * 100),
|
||||
PaymentAmountTotal: int64(orderInquiry.PaymentAmountTotal * 100),
|
||||
@ -136,18 +138,18 @@ func (r *OrderInquiryService) CancelOrderInquiry(req requests.CancelOrderInquiry
|
||||
|
||||
if *refund.Status == "SUCCESS" {
|
||||
// 退款成功
|
||||
inquiryRefundStatus = 3
|
||||
refundStatus = 3
|
||||
|
||||
if refund.SuccessTime != nil {
|
||||
successTime = *refund.SuccessTime
|
||||
}
|
||||
} else if *refund.Status == "CLOSED" {
|
||||
// 退款关闭
|
||||
inquiryRefundStatus = 5
|
||||
refundStatus = 5
|
||||
|
||||
} else if *refund.Status == "PROCESSING" {
|
||||
// 退款处理中
|
||||
inquiryRefundStatus = 2
|
||||
refundStatus = 2
|
||||
|
||||
} else if *refund.Status == "ABNORMAL" {
|
||||
// 退款异常
|
||||
@ -168,26 +170,40 @@ func (r *OrderInquiryService) CancelOrderInquiry(req requests.CancelOrderInquiry
|
||||
} else {
|
||||
// 支付金额为0,模拟退款
|
||||
refundId = "模拟退款:" + strconv.FormatInt(global.Snowflake.Generate().Int64(), 10)
|
||||
inquiryRefundStatus = 3
|
||||
refundStatus = 3
|
||||
successTime = time.Now()
|
||||
|
||||
// 模拟退款时手动退还优惠卷
|
||||
if orderInquiry.CouponAmountTotal > 0 {
|
||||
res := ReturnInquiryCoupon(tx, orderInquiry.OrderInquiryId)
|
||||
if !res {
|
||||
orderService := OrderService{}
|
||||
res, err := orderService.ReturnOrderCoupon(orderInquiry.InquiryNo, tx)
|
||||
if err != nil || !res {
|
||||
// 退还优惠卷失败
|
||||
tx.Rollback()
|
||||
return false, errors.New("退还优惠卷失败")
|
||||
return false, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
orderInquiryData["inquiry_refund_status"] = inquiryRefundStatus
|
||||
// 修改订单为取消
|
||||
orderData := make(map[string]interface{})
|
||||
orderData["cancel_status"] = 1
|
||||
orderData["cancel_time"] = time.Now().Format("2006-01-02 15:04:05")
|
||||
orderData["cancel_remarks"] = req.CancelRemarks
|
||||
|
||||
orderDao := dao.OrderDao{}
|
||||
err = orderDao.EditOrderById(tx, orderInquiry.OrderId, orderData)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New("取消订单失败")
|
||||
}
|
||||
|
||||
// 修改问诊订单为取消
|
||||
orderInquiryData := make(map[string]interface{})
|
||||
orderInquiryData["inquiry_status"] = 7 // 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||||
orderInquiryData["cancel_time"] = time.Now().Format("2006-01-02 15:04:05") // 订单取消时间
|
||||
orderInquiryData["cancel_reason"] = 4 // 取消订单原因(1:医生未接诊 2:主动取消 3:无可分配医生 4:客服取消 5:支付超时)
|
||||
orderInquiryData["cancel_remarks"] = req.CancelRemarks // 取消订单备注(自动添加)
|
||||
|
||||
// 修改问诊订单退款状态
|
||||
err = orderInquiryDao.EditOrderInquiryById(tx, orderInquiryId, orderInquiryData)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
@ -195,18 +211,45 @@ func (r *OrderInquiryService) CancelOrderInquiry(req requests.CancelOrderInquiry
|
||||
}
|
||||
|
||||
// 新增退款表
|
||||
orderRefund := &model.OrderRefund{
|
||||
OrderId: orderInquiry.OrderId,
|
||||
PatientId: orderInquiry.PatientId,
|
||||
OrderNo: orderInquiry.InquiryNo,
|
||||
RefundNo: refundNo,
|
||||
RefundId: refundId,
|
||||
RefundStatus: refundStatus,
|
||||
RefundTotal: req.RefundAmount,
|
||||
RefundReason: req.CancelRemarks,
|
||||
}
|
||||
|
||||
if refundStatus == 3 && !successTime.IsZero() {
|
||||
orderRefund.SuccessTime = model.LocalTime(successTime)
|
||||
}
|
||||
|
||||
orderRefundDao := dao.OrderRefundDao{}
|
||||
orderRefund, err = orderRefundDao.AddOrderRefund(tx, orderRefund)
|
||||
if err != nil || orderRefund == nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
|
||||
// 新增问诊退款表
|
||||
orderInquiryRefund := &model.OrderInquiryRefund{
|
||||
PatientId: orderInquiry.PatientId,
|
||||
OrderInquiryId: orderInquiryId,
|
||||
InquiryNo: orderInquiry.InquiryNo,
|
||||
InquiryRefundNo: inquiryRefundNo,
|
||||
InquiryRefundNo: refundNo,
|
||||
RefundId: refundId,
|
||||
InquiryRefundStatus: inquiryRefundStatus,
|
||||
InquiryRefundStatus: refundStatus,
|
||||
RefundTotal: req.RefundAmount,
|
||||
RefundReason: req.CancelRemarks,
|
||||
SuccessTime: model.LocalTime(successTime),
|
||||
}
|
||||
|
||||
if refundStatus == 3 && !successTime.IsZero() {
|
||||
orderRefund.SuccessTime = model.LocalTime(successTime)
|
||||
}
|
||||
|
||||
orderInquiryRefundDao := dao.OrderInquiryRefundDao{}
|
||||
orderInquiryRefund, err = orderInquiryRefundDao.AddOrderInquiryRefund(tx, orderInquiryRefund)
|
||||
if err != nil || orderInquiryRefund == nil {
|
||||
|
||||
@ -3,8 +3,10 @@ package service
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"gorm.io/gorm"
|
||||
"hospital-admin-api/api/dao"
|
||||
"hospital-admin-api/api/model"
|
||||
"hospital-admin-api/extend/aliyun"
|
||||
"hospital-admin-api/extend/prescription"
|
||||
"hospital-admin-api/global"
|
||||
"hospital-admin-api/utils"
|
||||
@ -310,3 +312,145 @@ func (r *OrderService) ReportPreProduct(orderProductId, adminUserId int64) (bool
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// 发起订单退款-未完成
|
||||
func (r *OrderService) orderRefund(orderNo string, refundReason string) (bool, error) {
|
||||
orderDao := dao.OrderDao{}
|
||||
|
||||
// 获取订单数据
|
||||
maps := make(map[string]interface{})
|
||||
maps["order_no"] = orderNo
|
||||
order, err := orderDao.GetOrder(maps)
|
||||
if err != nil || order == nil {
|
||||
return false, errors.New("订单数据错误")
|
||||
}
|
||||
|
||||
// 检测订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常)
|
||||
if order.RefundStatus == 2 {
|
||||
return false, errors.New("订单退款中")
|
||||
}
|
||||
|
||||
if order.RefundStatus == 3 {
|
||||
return false, errors.New("订单已退款成功")
|
||||
}
|
||||
|
||||
if order.RefundStatus == 5 {
|
||||
return false, errors.New("订单已退款关闭")
|
||||
}
|
||||
|
||||
// 检测支付状态 (1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
if order.PayStatus != 2 {
|
||||
return false, errors.New("订单支付状态错误")
|
||||
}
|
||||
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// PdfToImg 处理pdf转图片
|
||||
func (r *OrderService) PdfToImg() (bool, error) {
|
||||
//orderPrescription := dao.OrderPrescriptionDao{}
|
||||
orderPrescriptionFileDao := dao.OrderPrescriptionFileDao{}
|
||||
|
||||
// 获取订单数据
|
||||
maps := make(map[string]interface{})
|
||||
orderPrescriptionFiles, err := orderPrescriptionFileDao.GetOrderPrescriptionFileList(maps)
|
||||
if err != nil {
|
||||
return false, errors.New("订单数据错误")
|
||||
}
|
||||
|
||||
for _, orderPrescriptionFile := range orderPrescriptionFiles {
|
||||
if orderPrescriptionFile.PrescriptionPdfOssPath == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
if orderPrescriptionFile.IsConvertedPdf != 1 {
|
||||
continue
|
||||
}
|
||||
|
||||
OrderPrescriptionId := fmt.Sprintf("%d", orderPrescriptionFile.OrderPrescriptionId)
|
||||
|
||||
PrescriptionImgOssPath := strings.TrimLeft(orderPrescriptionFile.PrescriptionImgOssPath, "/")
|
||||
|
||||
// 下载处方pdf到本地
|
||||
local, err := aliyun.GetObjectToLocal(PrescriptionImgOssPath,
|
||||
"/Users/wucongxing/Desktop/work/go/hospital-admin-api/data/bak/"+OrderPrescriptionId+".jpg")
|
||||
if err != nil || !local {
|
||||
return false, err
|
||||
}
|
||||
|
||||
//pdfPath := "/Users/wucongxing/Desktop/work/go/hospital-admin-api/data/" + OrderPrescriptionId + ".pdf"
|
||||
//outputDir := "/Users/wucongxing/Desktop/work/go/hospital-admin-api/data/img"
|
||||
//
|
||||
//if err := utils.ConvertPDFToImages(pdfPath, outputDir, OrderPrescriptionId+".jpg"); err != nil {
|
||||
// return false, err
|
||||
//}
|
||||
//
|
||||
//// 修改为已转换
|
||||
//// 开始事务
|
||||
//tx := global.Db.Begin()
|
||||
//defer func() {
|
||||
// if r := recover(); r != nil {
|
||||
// tx.Rollback()
|
||||
// }
|
||||
//}()
|
||||
//
|
||||
//data := make(map[string]interface{})
|
||||
//data["is_converted_pdf"] = 1
|
||||
//err = orderPrescriptionFileDao.EditOrderPrescriptionFileById(tx, orderPrescriptionFile.PrescriptionFileId, data)
|
||||
//if err != nil {
|
||||
// tx.Rollback()
|
||||
// return false, err
|
||||
//}
|
||||
//
|
||||
//tx.Commit()
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// ReturnOrderCoupon 退还用户优惠卷
|
||||
func (r *OrderService) ReturnOrderCoupon(orderNo string, tx *gorm.DB) (bool, error) {
|
||||
orderCouponDao := dao.OrderCouponDao{}
|
||||
userCouponDao := dao.UserCouponDao{}
|
||||
|
||||
// 获取该订单全部优惠卷数据
|
||||
maps := make(map[string]interface{})
|
||||
maps["order_no"] = orderNo
|
||||
orderCoupons, err := orderCouponDao.GetOrderCouponList(maps)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
// 无优惠卷数据
|
||||
if len(orderCoupons) == 0 {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
for _, coupon := range orderCoupons {
|
||||
// 获取用户优惠卷数据
|
||||
userCoupon, err := userCouponDao.GetUserCouponById(coupon.UserCouponId)
|
||||
if err != nil || userCoupon == nil {
|
||||
// 无该优惠卷数据,无需处理
|
||||
continue
|
||||
}
|
||||
|
||||
// 恢复优惠卷
|
||||
userCouponData := make(map[string]interface{})
|
||||
|
||||
// 检测优惠卷过期时间。判断是否需要退还
|
||||
if userCoupon.ValidEndTime.Before(time.Now()) {
|
||||
userCouponData["user_coupon_status"] = 3
|
||||
} else {
|
||||
userCouponData["user_coupon_status"] = 0
|
||||
userCouponData["coupon_use_date"] = nil
|
||||
}
|
||||
|
||||
err = userCouponDao.EditUserCouponById(tx, userCoupon.UserCouponId, userCouponData)
|
||||
if err != nil {
|
||||
// 恢复优惠卷失败
|
||||
return false, errors.New("恢复优惠卷失败")
|
||||
}
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
1
go.mod
1
go.mod
@ -54,6 +54,7 @@ require (
|
||||
github.com/facebookgo/stats v0.0.0-20151006221625-1b76add642e4 // indirect
|
||||
github.com/facebookgo/subset v0.0.0-20200203212716-c811ad88dec4 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
|
||||
github.com/gen2brain/go-fitz v1.23.7 // indirect
|
||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||
github.com/go-sql-driver/mysql v1.7.1 // indirect
|
||||
github.com/goccy/go-json v0.10.2 // indirect
|
||||
|
||||
2
go.sum
2
go.sum
@ -151,6 +151,8 @@ github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4
|
||||
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
|
||||
github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU=
|
||||
github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA=
|
||||
github.com/gen2brain/go-fitz v1.23.7 h1:HPhzEVzmOINvCKqQgB/DwMzYh4ArIgy3tMwq1eJTcbg=
|
||||
github.com/gen2brain/go-fitz v1.23.7/go.mod h1:HU04vc+RisUh/kvEd2pB0LAxmK1oyXdN4ftyshUr9rQ=
|
||||
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
|
||||
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
|
||||
github.com/gin-gonic/gin v1.9.0 h1:OjyFBKICoexlu99ctXNR2gg+c5pKrKMuyjgARg9qeY8=
|
||||
|
||||
@ -1,5 +1,13 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gen2brain/go-fitz"
|
||||
"image/jpeg"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// 一些计算
|
||||
|
||||
// ComputeIndividualIncomeTax 计算个人所得税
|
||||
@ -35,3 +43,43 @@ func ComputeIndividualIncomeTax(income float64) float64 {
|
||||
|
||||
return incomeTax
|
||||
}
|
||||
|
||||
// ConvertPDFToImages converts a PDF file to images and saves them in the specified output directory.
|
||||
func ConvertPDFToImages(pdfPath string, outputDir string, filename string) error {
|
||||
// Open the PDF file
|
||||
doc, err := fitz.New(pdfPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open PDF file: %v", err)
|
||||
}
|
||||
defer doc.Close()
|
||||
|
||||
// Ensure the output directory exists
|
||||
if err := os.MkdirAll(outputDir, os.ModePerm); err != nil {
|
||||
return fmt.Errorf("failed to create output directory: %v", err)
|
||||
}
|
||||
|
||||
// Iterate over each page in the PDF
|
||||
for i := 0; i < doc.NumPage(); i++ {
|
||||
// Render the page to an image
|
||||
img, err := doc.Image(i)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to render page %d: %v", i, err)
|
||||
}
|
||||
|
||||
// Create the output file
|
||||
outputFile := filepath.Join(outputDir, filename)
|
||||
file, err := os.Create(outputFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create output file: %v", err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
// Encode the image as JPEG and save it to the file
|
||||
opts := &jpeg.Options{Quality: 80}
|
||||
if err := jpeg.Encode(file, img, opts); err != nil {
|
||||
return fmt.Errorf("failed to encode image: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user