fix:订单发票调整
This commit is contained in:
parent
56f4460995
commit
ef06ecd774
|
@ -9,6 +9,7 @@ import (
|
||||||
"fusenapi/model/gmodel"
|
"fusenapi/model/gmodel"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
"fusenapi/utils/file"
|
"fusenapi/utils/file"
|
||||||
|
"fusenapi/utils/format"
|
||||||
"fusenapi/utils/handlers"
|
"fusenapi/utils/handlers"
|
||||||
"fusenapi/utils/hash"
|
"fusenapi/utils/hash"
|
||||||
"fusenapi/utils/order"
|
"fusenapi/utils/order"
|
||||||
|
@ -16,6 +17,7 @@ import (
|
||||||
"fusenapi/utils/pdf"
|
"fusenapi/utils/pdf"
|
||||||
"fusenapi/utils/queue"
|
"fusenapi/utils/queue"
|
||||||
"math"
|
"math"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go/aws/session"
|
"github.com/aws/aws-sdk-go/aws/session"
|
||||||
|
@ -374,19 +376,47 @@ func (d *defaultOrder) Invoice(ctx context.Context, in *InvoiceReq) (res *Invoic
|
||||||
state = ress.OrderDetail.DeliveryAddress.State
|
state = ress.OrderDetail.DeliveryAddress.State
|
||||||
suite = ress.OrderDetail.DeliveryAddress.Suite
|
suite = ress.OrderDetail.DeliveryAddress.Suite
|
||||||
zipCode = ress.OrderDetail.DeliveryAddress.ZipCode
|
zipCode = ress.OrderDetail.DeliveryAddress.ZipCode
|
||||||
|
} else {
|
||||||
|
// 邮箱
|
||||||
|
model1 := d.MysqlConn.Where("is_del = ?", 0).Model(&gmodel.FsUser{})
|
||||||
|
if in.UserId != 0 {
|
||||||
|
model1 = model.Where("user_id = ?", in.UserId)
|
||||||
|
}
|
||||||
|
var userInfo = gmodel.FsUser{}
|
||||||
|
result1 := model1.Take(&userInfo)
|
||||||
|
if result1.Error != nil {
|
||||||
|
if errors.Is(result1.Error, gorm.ErrRecordNotFound) {
|
||||||
|
errorCode = *basic.CodeErrOrderCreatePrePaymentInfoNoFound
|
||||||
|
} else {
|
||||||
|
errorCode = *basic.CodeServiceErr
|
||||||
|
}
|
||||||
|
logc.Errorf(ctx, "order invoice trade failed, err: %v", err)
|
||||||
|
return &InvoiceRes{
|
||||||
|
ErrorCode: errorCode,
|
||||||
|
}, result1.Error
|
||||||
|
}
|
||||||
|
name = *userInfo.Email
|
||||||
}
|
}
|
||||||
|
|
||||||
var products string
|
var products string
|
||||||
for _, orderProduct := range ress.OrderDetail.OrderProduct {
|
for _, orderProduct := range ress.OrderDetail.OrderProduct {
|
||||||
var model00301 = constants.INVOICE_TEMPLATE_0301
|
var model00301 = constants.INVOICE_TEMPLATE_0301
|
||||||
var price = fmt.Sprintf("%s%s", constants.OrderCurrencyMessage[constants.Currency(orderProduct.ItemPrice.Current.CurrentCurrency)], orderProduct.ItemPrice.Current.CurrentAmount.(string))
|
|
||||||
var priceTotal = fmt.Sprintf("%s%s", constants.OrderCurrencyMessage[constants.Currency(orderProduct.TotalPrice.Current.CurrentCurrency)], orderProduct.TotalPrice.Current.CurrentAmount.(string))
|
var priceStr = format.NumToStringWithThousandthPercentile(orderProduct.ItemPrice.Current.CurrentAmount.(string))
|
||||||
var productsInfo = fmt.Sprintf(model00301, orderProduct.ProductName, price, orderProduct.PurchaseQuantity.Current, priceTotal)
|
var price = fmt.Sprintf("%s%s", constants.OrderCurrencyMessage[constants.Currency(orderProduct.ItemPrice.Current.CurrentCurrency)], priceStr)
|
||||||
|
|
||||||
|
var priceTotalStr = format.NumToStringWithThousandthPercentile(orderProduct.TotalPrice.Current.CurrentAmount.(string))
|
||||||
|
var priceTotal = fmt.Sprintf("%s%s", constants.OrderCurrencyMessage[constants.Currency(orderProduct.TotalPrice.Current.CurrentCurrency)], priceTotalStr)
|
||||||
|
|
||||||
|
productNum := strconv.FormatFloat(orderProduct.PurchaseQuantity.Current.(float64), 'f', -1, 64)
|
||||||
|
var productNumStr = format.NumToStringWithThousandthPercentile(productNum)
|
||||||
|
|
||||||
|
var productsInfo = fmt.Sprintf(model00301, orderProduct.ProductName, price, productNumStr, priceTotal)
|
||||||
products = products + productsInfo
|
products = products + productsInfo
|
||||||
}
|
}
|
||||||
model003 = fmt.Sprintf(constants.INVOICE_TEMPLATE_03, products)
|
model003 = fmt.Sprintf(constants.INVOICE_TEMPLATE_03, products)
|
||||||
|
var subtotalStr = format.NumToStringWithThousandthPercentile(ress.OrderDetail.OrderAmount.Subtotal.Current.CurrentAmount.(string))
|
||||||
var subtotal = fmt.Sprintf("%s%s", constants.OrderCurrencyMessage[constants.Currency(ress.OrderDetail.OrderAmount.Subtotal.Current.CurrentCurrency)], ress.OrderDetail.OrderAmount.Subtotal.Current.CurrentAmount.(string))
|
var subtotal = fmt.Sprintf("%s%s", constants.OrderCurrencyMessage[constants.Currency(ress.OrderDetail.OrderAmount.Subtotal.Current.CurrentCurrency)], subtotalStr)
|
||||||
var taxStr = "0.00"
|
var taxStr = "0.00"
|
||||||
if ress.OrderDetail.OrderAmount.Tax.Current.CurrentAmount != nil {
|
if ress.OrderDetail.OrderAmount.Tax.Current.CurrentAmount != nil {
|
||||||
taxStr = ress.OrderDetail.OrderAmount.Tax.Current.CurrentAmount.(string)
|
taxStr = ress.OrderDetail.OrderAmount.Tax.Current.CurrentAmount.(string)
|
||||||
|
@ -396,14 +426,16 @@ func (d *defaultOrder) Invoice(ctx context.Context, in *InvoiceReq) (res *Invoic
|
||||||
taxCurrency = constants.OrderCurrencyMessage[constants.Currency(ress.OrderDetail.OrderAmount.Total.Current.CurrentCurrency)]
|
taxCurrency = constants.OrderCurrencyMessage[constants.Currency(ress.OrderDetail.OrderAmount.Total.Current.CurrentCurrency)]
|
||||||
}
|
}
|
||||||
var tax = fmt.Sprintf("%s%s", taxCurrency, taxStr)
|
var tax = fmt.Sprintf("%s%s", taxCurrency, taxStr)
|
||||||
var total = fmt.Sprintf("%s%s", constants.OrderCurrencyMessage[constants.Currency(ress.OrderDetail.OrderAmount.Total.Current.CurrentCurrency)], ress.OrderDetail.OrderAmount.Total.Current.CurrentAmount.(string))
|
var totalStr = format.NumToStringWithThousandthPercentile(ress.OrderDetail.OrderAmount.Total.Current.CurrentAmount.(string))
|
||||||
|
var total = fmt.Sprintf("%s%s", constants.OrderCurrencyMessage[constants.Currency(ress.OrderDetail.OrderAmount.Total.Current.CurrentCurrency)], totalStr)
|
||||||
|
|
||||||
// 生成收据发票--首款
|
// 生成收据发票--首款
|
||||||
if receiptSnsDeposit != "" {
|
if receiptSnsDeposit != "" {
|
||||||
model002 = fmt.Sprintf(constants.INVOICE_TEMPLATE_02, receiptSnsDeposit, name, ctimeDate, street+" "+suite, city, state+zipCode)
|
model002 = fmt.Sprintf(constants.INVOICE_TEMPLATE_02, receiptSnsDeposit, name, ctimeDate, street+" "+suite, city, state+zipCode)
|
||||||
|
|
||||||
|
var payAmountStr01 = format.NumToStringWithThousandthPercentile(ress.OrderDetail.OrderAmount.Deposit.PayAmount.Current.CurrentAmount.(string))
|
||||||
v7 := "Deposit Requested"
|
v7 := "Deposit Requested"
|
||||||
v8 := fmt.Sprintf("%s%s", constants.OrderCurrencyMessage[constants.Currency(ress.OrderDetail.OrderAmount.Deposit.PayAmount.Current.CurrentCurrency)], ress.OrderDetail.OrderAmount.Deposit.PayAmount.Current.CurrentAmount.(string))
|
v8 := fmt.Sprintf("%s%s", constants.OrderCurrencyMessage[constants.Currency(ress.OrderDetail.OrderAmount.Deposit.PayAmount.Current.CurrentCurrency)], payAmountStr01)
|
||||||
v9 := "Deposit Due"
|
v9 := "Deposit Due"
|
||||||
v10 := v8
|
v10 := v8
|
||||||
model004 = fmt.Sprintf(constants.INVOICE_TEMPLATE_04, subtotal, tax, total, v7, v8, v9, v10)
|
model004 = fmt.Sprintf(constants.INVOICE_TEMPLATE_04, subtotal, tax, total, v7, v8, v9, v10)
|
||||||
|
@ -413,7 +445,7 @@ func (d *defaultOrder) Invoice(ctx context.Context, in *InvoiceReq) (res *Invoic
|
||||||
|
|
||||||
var content = model001 + model002 + model003 + model004 + model005 + model006
|
var content = model001 + model002 + model003 + model004 + model005 + model006
|
||||||
|
|
||||||
base64, err := pdf.HtmlToPdfBase64(content, "html")
|
base64, err := pdf.HtmlToPdfBase64(content, "html", "Letter")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logc.Errorf(ctx, "order invoice HtmlToPdfBase64 failed, err: %v", err)
|
logc.Errorf(ctx, "order invoice HtmlToPdfBase64 failed, err: %v", err)
|
||||||
errorCode = *basic.CodeServiceErr
|
errorCode = *basic.CodeServiceErr
|
||||||
|
@ -455,9 +487,9 @@ func (d *defaultOrder) Invoice(ctx context.Context, in *InvoiceReq) (res *Invoic
|
||||||
// 生成收据发票--尾款
|
// 生成收据发票--尾款
|
||||||
if receiptSnsFinal != "" {
|
if receiptSnsFinal != "" {
|
||||||
model002 = fmt.Sprintf(constants.INVOICE_TEMPLATE_02, receiptSnsDeposit, name, ctimeDate, street+" "+suite, city, state+zipCode)
|
model002 = fmt.Sprintf(constants.INVOICE_TEMPLATE_02, receiptSnsDeposit, name, ctimeDate, street+" "+suite, city, state+zipCode)
|
||||||
|
var payAmountStr02 = format.NumToStringWithThousandthPercentile(ress.OrderDetail.OrderAmount.RemainingBalance.PayAmount.Current.CurrentAmount.(string))
|
||||||
v7 := "Balance Requested"
|
v7 := "Balance Requested"
|
||||||
v8 := fmt.Sprintf("%s%s", constants.OrderCurrencyMessage[constants.Currency(ress.OrderDetail.OrderAmount.RemainingBalance.PayAmount.Current.CurrentCurrency)], ress.OrderDetail.OrderAmount.RemainingBalance.PayAmount.Current.CurrentAmount.(string))
|
v8 := fmt.Sprintf("%s%s", constants.OrderCurrencyMessage[constants.Currency(ress.OrderDetail.OrderAmount.RemainingBalance.PayAmount.Current.CurrentCurrency)], payAmountStr02)
|
||||||
v9 := "Balance Due"
|
v9 := "Balance Due"
|
||||||
v10 := v8
|
v10 := v8
|
||||||
model004 = fmt.Sprintf(constants.INVOICE_TEMPLATE_04, subtotal, tax, total, v7, v8, v9, v10)
|
model004 = fmt.Sprintf(constants.INVOICE_TEMPLATE_04, subtotal, tax, total, v7, v8, v9, v10)
|
||||||
|
@ -465,7 +497,7 @@ func (d *defaultOrder) Invoice(ctx context.Context, in *InvoiceReq) (res *Invoic
|
||||||
cardSn := "****" + *orderTradeFinal.CardSn
|
cardSn := "****" + *orderTradeFinal.CardSn
|
||||||
model005 = fmt.Sprintf(constants.INVOICE_TEMPLATE_05, *orderTradeDeposit.CardBrand, cardSn)
|
model005 = fmt.Sprintf(constants.INVOICE_TEMPLATE_05, *orderTradeDeposit.CardBrand, cardSn)
|
||||||
var content = model001 + model002 + model003 + model004 + model005 + model006
|
var content = model001 + model002 + model003 + model004 + model005 + model006
|
||||||
base64, err := pdf.HtmlToPdfBase64(content, "html")
|
base64, err := pdf.HtmlToPdfBase64(content, "html", "Letter")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logc.Errorf(ctx, "order invoice HtmlToPdfBase64 failed, err: %v", err)
|
logc.Errorf(ctx, "order invoice HtmlToPdfBase64 failed, err: %v", err)
|
||||||
errorCode = *basic.CodeServiceErr
|
errorCode = *basic.CodeServiceErr
|
||||||
|
|
|
@ -3,15 +3,16 @@ package pdf
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/SebastiaanKlippert/go-wkhtmltopdf"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/SebastiaanKlippert/go-wkhtmltopdf"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
html转 Pdf
|
html转 Pdf
|
||||||
outFile为空则不保存(使用该方法需要安装工具 sudo apt-get install wkhtmltopdf)
|
outFile为空则不保存(使用该方法需要安装工具 sudo apt-get install wkhtmltopdf)
|
||||||
*/
|
*/
|
||||||
func HtmlToPdfBase64(content string, dataType string, outFile ...string) (string, error) {
|
func HtmlToPdfBase64(content string, dataType string, pageSize string, outFile ...string) (string, error) {
|
||||||
pdfg, err := wkhtmltopdf.NewPDFGenerator()
|
pdfg, err := wkhtmltopdf.NewPDFGenerator()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -27,7 +28,7 @@ func HtmlToPdfBase64(content string, dataType string, outFile ...string) (string
|
||||||
//模式
|
//模式
|
||||||
pdfg.Orientation.Set(wkhtmltopdf.OrientationPortrait)
|
pdfg.Orientation.Set(wkhtmltopdf.OrientationPortrait)
|
||||||
//pdf尺寸默认A4纸
|
//pdf尺寸默认A4纸
|
||||||
pdfg.PageSize.Set(wkhtmltopdf.PageSizeA4)
|
pdfg.PageSize.Set(pageSize)
|
||||||
// Create PDF document in memory
|
// Create PDF document in memory
|
||||||
if err = pdfg.Create(); err != nil {
|
if err = pdfg.Create(); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
|
Loading…
Reference in New Issue
Block a user