|
@@ -3,6 +3,7 @@ package service
|
|
import (
|
|
import (
|
|
"ElectronicInvoice/internal/consts"
|
|
"ElectronicInvoice/internal/consts"
|
|
"ElectronicInvoice/util"
|
|
"ElectronicInvoice/util"
|
|
|
|
+ "context"
|
|
"fmt"
|
|
"fmt"
|
|
"github.com/gogf/gf/v2/database/gdb"
|
|
"github.com/gogf/gf/v2/database/gdb"
|
|
"github.com/gogf/gf/v2/encoding/gjson"
|
|
"github.com/gogf/gf/v2/encoding/gjson"
|
|
@@ -66,11 +67,30 @@ func InvoicingMakeRedCallBackLogic(r *ghttp.Request) error {
|
|
InvoiceStatus: "1",
|
|
InvoiceStatus: "1",
|
|
BillingTime: invoiceTime.Unix(),
|
|
BillingTime: invoiceTime.Unix(),
|
|
})
|
|
})
|
|
-
|
|
|
|
- _, err = g.DB().Update(ctx, "invoice", g.Map{
|
|
|
|
- "invoice_status": -2,
|
|
|
|
- "red": string(redByte),
|
|
|
|
- }, "invoice_changed = 0 AND invoice_number= ? ", num)
|
|
|
|
|
|
+ err = g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
|
|
|
|
+ //旧蓝票状态修改已红冲
|
|
|
|
+ affect, t_err := g.DB().Update(ctx, "invoice", g.Map{
|
|
|
|
+ "invoice_status": -2,
|
|
|
|
+ "red": string(redByte),
|
|
|
|
+ }, "invoice_changed = 0 AND invoice_number= ? ", num)
|
|
|
|
+ if t_err != nil {
|
|
|
|
+ return t_err
|
|
|
|
+ }
|
|
|
|
+ if row, _ := affect.RowsAffected(); row != 1 {
|
|
|
|
+ return gerror.Newf("InvoicingMakeRedCallBackLogic 旧蓝票状态修改已红冲异常 sql(invoice_changed = 0 AND invoice_number= %s)", num)
|
|
|
|
+ }
|
|
|
|
+ //新蓝票状态改为可以开票
|
|
|
|
+ affect, t_err = g.DB().Update(ctx, "invoice", g.Map{
|
|
|
|
+ "invoice_status": 2,
|
|
|
|
+ }, "invoice_changed = 1 AND invoice_number= ? ", num)
|
|
|
|
+ if t_err != nil {
|
|
|
|
+ return t_err
|
|
|
|
+ }
|
|
|
|
+ if row, _ := affect.RowsAffected(); row != 1 {
|
|
|
|
+ return gerror.Newf("InvoicingMakeRedCallBackLogic 新蓝票状态改为可以开票异常 sql(invoice_changed = 0 AND invoice_number= %s)", num)
|
|
|
|
+ }
|
|
|
|
+ return nil
|
|
|
|
+ })
|
|
if err != nil {
|
|
if err != nil {
|
|
return gerror.Wrap(err, "InvoicingMakeRedCallBackLogic 更新发票状态异常")
|
|
return gerror.Wrap(err, "InvoicingMakeRedCallBackLogic 更新发票状态异常")
|
|
}
|
|
}
|