Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop

This commit is contained in:
laodaming 2023-10-25 12:30:43 +08:00
commit 5855ba8dde
3 changed files with 109 additions and 48 deletions

View File

@ -27,10 +27,16 @@ type PreLogoSearchResult struct {
// 搜索 // 搜索
func (p *FsPreprocessLogoModel) PreLogoSearch(ctx context.Context, zipcode string, keywordsStr string, count int) (resp []PreLogoSearchResult, err error) { func (p *FsPreprocessLogoModel) PreLogoSearch(ctx context.Context, zipcode string, keywordsStr string, count int) (resp []PreLogoSearchResult, err error) {
keywords := regexp.MustCompile(`\s+`).Split(keywordsStr, -1) keywordsList := SplitSearchKeywords(keywordsStr)
for i, v := range keywords { var keywords []string
keywords[i] = "+" + v + "*" for _, v := range keywordsList {
if len(v) > 1 {
keywords = append(keywords, "+"+v+"*")
} }
}
if len(keywords) != 0 {
sqlstr := fmt.Sprintf("SELECT id,restaurant_name,resource_url,address,zip_code,phone,website,is_branch FROM fs_preprocess_logo WHERE MATCH(restaurant_name) AGAINST(? IN BOOLEAN MODE) and zip_code = ? limit %d;", count) sqlstr := fmt.Sprintf("SELECT id,restaurant_name,resource_url,address,zip_code,phone,website,is_branch FROM fs_preprocess_logo WHERE MATCH(restaurant_name) AGAINST(? IN BOOLEAN MODE) and zip_code = ? limit %d;", count)
tx := p.db.WithContext(ctx).Model(&FsPreprocessLogo{}).Raw(sqlstr, strings.Join(keywords, " "), zipcode) tx := p.db.WithContext(ctx).Model(&FsPreprocessLogo{}).Raw(sqlstr, strings.Join(keywords, " "), zipcode)
@ -44,8 +50,12 @@ func (p *FsPreprocessLogoModel) PreLogoSearch(ctx context.Context, zipcode strin
if resp[i].RestaurantType == nil { if resp[i].RestaurantType == nil {
resp[i].RestaurantType = FsString("") resp[i].RestaurantType = FsString("")
} }
if len(*resp[i].ResourceUrl) < 10 {
resp[i].ResourceUrl = FsString(testData[rand.Uint64()%uint64(len(testData))]) resp[i].ResourceUrl = FsString(testData[rand.Uint64()%uint64(len(testData))])
} }
}
}
if resp == nil { if resp == nil {
resp = make([]PreLogoSearchResult, 0) resp = make([]PreLogoSearchResult, 0)
@ -54,12 +64,22 @@ func (p *FsPreprocessLogoModel) PreLogoSearch(ctx context.Context, zipcode strin
return resp, nil return resp, nil
} }
func SplitSearchKeywords(keywordsStr string) []string {
return regexp.MustCompile(`\s+|\++`).Split(keywordsStr, -1)
}
// 搜索建议 // 搜索建议
func (p *FsPreprocessLogoModel) PreLogoSearchSuggestions(ctx context.Context, keywordsStr string, count int) (resp []PreLogoSearchResult, err error) { func (p *FsPreprocessLogoModel) PreLogoSearchSuggestions(ctx context.Context, keywordsStr string, count int) (resp []PreLogoSearchResult, err error) {
keywords := regexp.MustCompile(`\s+`).Split(keywordsStr, -1) // keywordsList := regexp.MustCompile(`\s+|\++`).Split(keywordsStr, -1)
for i, v := range keywords { keywordsList := SplitSearchKeywords(keywordsStr)
keywords[i] = "+" + v + "*" var keywords []string
for _, v := range keywordsList {
if len(v) > 1 {
keywords = append(keywords, "+"+v+"*")
} }
}
if len(keywords) != 0 {
sqlstr := fmt.Sprintf("SELECT id,restaurant_name,resource_url,address,zip_code,phone,website,is_branch FROM fs_preprocess_logo WHERE MATCH(restaurant_name) AGAINST(? IN BOOLEAN MODE) limit %d;", count) sqlstr := fmt.Sprintf("SELECT id,restaurant_name,resource_url,address,zip_code,phone,website,is_branch FROM fs_preprocess_logo WHERE MATCH(restaurant_name) AGAINST(? IN BOOLEAN MODE) limit %d;", count)
tx := p.db.WithContext(ctx).Model(&FsPreprocessLogo{}).Raw(sqlstr, strings.Join(keywords, " ")) tx := p.db.WithContext(ctx).Model(&FsPreprocessLogo{}).Raw(sqlstr, strings.Join(keywords, " "))
@ -73,9 +93,15 @@ func (p *FsPreprocessLogoModel) PreLogoSearchSuggestions(ctx context.Context, ke
if resp[i].RestaurantType == nil { if resp[i].RestaurantType == nil {
resp[i].RestaurantType = FsString("") resp[i].RestaurantType = FsString("")
} }
if len(*resp[i].ResourceUrl) < 10 {
resp[i].ResourceUrl = FsString(testData[rand.Uint64()%uint64(len(testData))]) resp[i].ResourceUrl = FsString(testData[rand.Uint64()%uint64(len(testData))])
} }
}
}
if resp == nil { if resp == nil {
resp = make([]PreLogoSearchResult, 0) resp = make([]PreLogoSearchResult, 0)
} }

View File

@ -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,49 @@ 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 {
// 邮箱
modelUser := d.MysqlConn.Model(&gmodel.FsUser{})
if in.UserId != 0 {
modelUser = modelUser.Where("id = ?", in.UserId)
}
var userInfo = &gmodel.FsUser{}
result1 := modelUser.Debug().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
}
if userInfo.Email != nil {
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 +428,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 +447,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 +489,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 +499,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

View File

@ -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