diff --git a/api/service/order.go b/api/service/order.go index 77db679..90a3cd8 100644 --- a/api/service/order.go +++ b/api/service/order.go @@ -5,6 +5,7 @@ import ( "fmt" "hospital-admin-api/api/dao" "hospital-admin-api/extend/prescription" + "hospital-admin-api/global" "hospital-admin-api/utils" "strings" "time" @@ -262,6 +263,32 @@ func (r *OrderService) ReportPreProduct(orderProductId int64) (bool, error) { PresList: presRequests, } - fmt.Println(ReportPreRequest) + // 开始事务 + tx := global.Db.Begin() + defer func() { + if r := recover(); r != nil { + tx.Rollback() + } + }() + + // 上报处方 + _, err = ReportPreRequest.ReportPre() + if err != nil { + tx.Rollback() + return false, errors.New("上报处方失败1") + } + + orderProductData := make(map[string]interface{}) + orderProductData["report_pre_status"] = 1 + orderProductData["report_pre_time"] = time.Now().Format("2006-01-02 15:04:05") + + err = orderProductDao.EditOrderProductById(tx, orderProductId, orderProductData) + if err != nil { + tx.Rollback() + return false, errors.New("上报处方失败2") + } + + tx.Commit() + return true, nil } diff --git a/extend/prescription/prescription.go b/extend/prescription/prescription.go index a335060..8efc581 100644 --- a/extend/prescription/prescription.go +++ b/extend/prescription/prescription.go @@ -267,7 +267,6 @@ func NoticePreOrderCancel(orderNo string) (bool, error) { // ReportPre 上报处方 func (r ReportPreRequest) ReportPre() (bool, error) { - // 将 JSON 数据编码为字节数组 jsonData, err := json.Marshal(r) if err != nil { return false, err