TODO: 反射
This commit is contained in:
@@ -25,30 +25,27 @@ func QuotationDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
userinfo *auth.BackendUserInfo
|
||||
)
|
||||
// 解析JWT token,并对空用户进行判断
|
||||
// claims, err := svcCtx.ParseJwtToken(r)
|
||||
// // 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息
|
||||
// if err != nil || claims == nil {
|
||||
// httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||
// Code: 401, // 返回401状态码,表示未授权
|
||||
// Message: "unauthorized", // 返回未授权信息
|
||||
// })
|
||||
// logx.Info("unauthorized:", err.Error()) // 记录错误日志
|
||||
// return
|
||||
// }
|
||||
claims, err := svcCtx.ParseJwtToken(r)
|
||||
// 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息
|
||||
if err != nil || claims == nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||
Code: 401, // 返回401状态码,表示未授权
|
||||
Message: "unauthorized", // 返回未授权信息
|
||||
})
|
||||
logx.Info("unauthorized:", err.Error()) // 记录错误日志
|
||||
return
|
||||
}
|
||||
|
||||
// // 从token中获取对应的用户信息
|
||||
// userinfo, err = auth.GetBackendUserInfoFormMapClaims(claims)
|
||||
// // 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
||||
// if err != nil {
|
||||
// httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||
// Code: 401,
|
||||
// Message: "unauthorized",
|
||||
// })
|
||||
// logx.Info("unauthorized:", err.Error())
|
||||
// return
|
||||
// }
|
||||
// 从token中获取对应的用户信息
|
||||
userinfo, err = auth.GetBackendUserInfoFormMapClaims(claims)
|
||||
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
||||
if err != nil {
|
||||
|
||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||
Code: 401,
|
||||
Message: "unauthorized",
|
||||
})
|
||||
logx.Info("unauthorized:", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
var req types.RequestQuotationId
|
||||
|
||||
17
server/backend/internal/logic/init.go
Normal file
17
server/backend/internal/logic/init.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"os"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
var templatePath string
|
||||
|
||||
func init() {
|
||||
d, err := os.Getwd()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
templatePath = regexp.MustCompile(".+fusenapi/server").FindString(d) + "/backend/template"
|
||||
}
|
||||
@@ -51,13 +51,6 @@ func GetPrice(num int64, stepNum []int64, stepPrice []int64) int64 {
|
||||
|
||||
// GetDemoHtml 报价单
|
||||
func (l *QuotationDetailLogic) GetDemoHtml(quot *gmodel.FsQuotation, quotationProduct []*gmodel.FsQuotationProduct) (htmlcontent string, err error) {
|
||||
saler, err := l.svcCtx.AllModels.FsQuotationSaler.GetOne(l.ctx, quot.Id)
|
||||
if err != nil {
|
||||
|
||||
return "", err
|
||||
}
|
||||
|
||||
log.Println(saler)
|
||||
|
||||
// htmlContent := ""
|
||||
priceHtml := ""
|
||||
@@ -99,147 +92,18 @@ func (l *QuotationDetailLogic) GetDemoHtml(quot *gmodel.FsQuotation, quotationPr
|
||||
priceHtml = buf.String()
|
||||
}
|
||||
|
||||
tplcontent := `
|
||||
{{$product_num := len .products}}
|
||||
{{$page := 3}}
|
||||
{{$page_total := add $page $product_num}}
|
||||
{{range $arr := .products}}
|
||||
{{$price := json_decode $arr.price_info}}
|
||||
{{$price_html := .priceHtml}}
|
||||
|
||||
{{$price_html}}
|
||||
|
||||
{{if gt $arr.is_gift 0 }}{{/* 赠品 */}}
|
||||
|
||||
<div class="box">
|
||||
<div style="position: relative; margin-bottom: 30px;">
|
||||
<p class="f-m" style="font-size: 39px; font-weight: 800; margin-bottom: 12px; line-height: 32px;">{{$arr.name}}</p>
|
||||
<p class="f-b" style="font-size: 25px; font-weight: 800;line-height: 19px;">{{$arr.size}}</p>
|
||||
<div class="logo">
|
||||
<img src="https://fusenapi.kayue.cn:8010/storage/pdf/logo.svg" alt="logo">
|
||||
</div>
|
||||
</div>
|
||||
<div class="img-box" style="height: 611px;margin-bottom: 32px; overflow: hidden;">
|
||||
<div class="img" style="background-image: url({{$arr.img}});"></div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="pr-card big">
|
||||
<p class="pr">FREE!</p>
|
||||
<p class="num">{{$arr.num}}<span> Units</span></p>
|
||||
</div>
|
||||
<div>
|
||||
<div class="card-box" style="display: inline-block;width: 183px;line-height: 36px;padding-left: 16px;margin-bottom: 4px;background-color: #C2C5CB;font-size: 18px; font-weight: 500;">Lead Time</div>
|
||||
<div class="card-box" style="display: inline-block;width: 183px;height: 52px; padding-left: 15px;margin-bottom: 8px;background-color: #E0E2EB; font-weight: 600;">
|
||||
<span style="font-size: 35px;line-height: 52px;">{{$arr.cycle}}</span><span style="font-size: 26px;line-height: 52px;">Days</span>
|
||||
</div>
|
||||
<div class="card-box more-card">
|
||||
<span class="free">FREE </span><span class="text">Design</span>
|
||||
</div>
|
||||
<div class="card-box more-card">
|
||||
<span class="free">FREE </span><span class="text">Storage</span>
|
||||
</div>
|
||||
<div class="card-box more-card" style="margin-bottom: 0;">
|
||||
<span class="free">FREE </span><span class="text">Shipping</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{else}}{{/* 非赠品 */}}
|
||||
{{if $arr.size}}
|
||||
// 有尺寸的
|
||||
<div class="box">
|
||||
<div style="position: relative; margin-bottom: 30px;">
|
||||
<p class="f-m" style="font-size: 39px; font-weight: 800; margin-bottom: 12px; line-height: 32px;">{{$arr.name}}</p>
|
||||
<p class="f-b" style="font-size: 25px; font-weight: 800;line-height: 19px;">{{$arr.size}}</p>
|
||||
<div class="logo">
|
||||
<img src="https://fusenapi.kayue.cn:8010/storage/pdf/logo.svg" alt="logo">
|
||||
</div>
|
||||
</div>
|
||||
<div class="img-box" style="height: 611px;margin-bottom: 32px; overflow: hidden;">
|
||||
<div class="img"
|
||||
style="background-image: url({{$arr.img}});"></div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="card-box"
|
||||
style="float: left; width: 530px;line-height: 36px;padding-left: 19px;margin-right: 8px;margin-bottom: 4px;background-color: #C2C5CB;font-size: 18px; font-weight: 500;">Unit Price (Tax included)</div>
|
||||
<div class="card-box"
|
||||
style="display: inline-block;width: 183px;line-height: 36px;padding-left: 16px;margin-bottom: 4px;background-color: #C2C5CB;font-size: 18px; font-weight: 500;">
|
||||
Lead Time</div>
|
||||
{{$price_html}}
|
||||
<div>
|
||||
<div class="card-box"
|
||||
style="display: inline-block;width: 183px;height: 52px; padding-left: 15px;margin-bottom: 8px;background-color: #E0E2EB; font-weight: 600;">
|
||||
<span style="font-size: 35px;line-height: 52px;">{{$arr.cycle}}</span><span
|
||||
style="font-size: 26px;line-height: 52px;">Days</span>
|
||||
</div>
|
||||
<div class="card-box more-card">
|
||||
<span class="free">FREE </span><span class="text">Design</span>
|
||||
</div>
|
||||
<div class="card-box more-card">
|
||||
<span class="free">FREE </span><span class="text">Storage</span>
|
||||
</div>
|
||||
<div class="card-box more-card" style="margin-bottom: 0;">
|
||||
<span class="free">FREE </span><span class="text">Shipping</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{else}}
|
||||
<div class="box">
|
||||
<div style="position: relative; margin-bottom: 32px;">
|
||||
<p class="f-m" style="font-size: 39px; font-weight: 800; margin-bottom: 3px; line-height: 32px;">
|
||||
{{$arr.name}}</p>
|
||||
<div class="logo">
|
||||
<img src="https://fusenapi.kayue.cn:8010/storage/pdf/logo.svg" alt="logo">
|
||||
</div>
|
||||
</div>
|
||||
<div class="img-box" style="height: 641px;margin-bottom: 31px; overflow: hidden;">
|
||||
<div class="img" style="background-image: url({{$arr.img}});">
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="card-box"
|
||||
style="float: left;width: 530px;line-height: 36px;padding-left: 19px;margin-right: 8px;margin-bottom: 4px;background-color: #C2C5CB;font-size: 18px; font-weight: 500;">
|
||||
Unit Price (Tax included)</div>
|
||||
<div class="card-box"
|
||||
style="display: inline-block;width: 183px;line-height: 36px;padding-left: 16px;margin-bottom: 4px;background-color: #C2C5CB;font-size: 18px; font-weight: 500;">
|
||||
Lead Time</div>
|
||||
{{$price_html}}
|
||||
<div>
|
||||
<div class="card-box"
|
||||
style="display: inline-block;width: 183px;height: 52px; padding-left: 15px;margin-bottom: 8px;background-color: #E0E2EB; font-weight: 600;">
|
||||
<span style="font-size: 35px;line-height: 52px;">{{$arr.cycle}}</span><span
|
||||
style="font-size: 26px;line-height: 52px;">Days</span>
|
||||
</div>
|
||||
<div class="card-box more-card">
|
||||
<span class="free">FREE </span><span class="text">Design</span>
|
||||
</div>
|
||||
<div class="card-box more-card">
|
||||
<span class="free">FREE </span><span class="text">Storage</span>
|
||||
</div>
|
||||
<div class="card-box more-card" style="margin-bottom: 0;">
|
||||
<span class="free">FREE </span><span class="text">Shipping</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
{{end}}
|
||||
<div class="page-box" style="background-color: rgba(125, 125, 125, 0.16);color: #000;text-align: center;height: 50px;line-height: 50px;margin-top: 30px;">{{$page}}/{{$page_total}}</div>
|
||||
{{$page = add $page 1}}
|
||||
{{end}} `
|
||||
tpl := template.New("demo")
|
||||
tpl := template.New("quto")
|
||||
tpl = tpl.Funcs(format.TemplateFuncMap)
|
||||
tpl = template.Must(tpl.Parse(tplcontent))
|
||||
buf := bytes.NewBufferString("")
|
||||
|
||||
tpl = template.Must(tpl.ParseFiles(templatePath + "/products.tpl"))
|
||||
buf := &bytes.Buffer{}
|
||||
|
||||
tpl.Execute(buf, map[string]interface{}{
|
||||
"products": collect.StructSliceJson2Maps(quotationProduct),
|
||||
"price_html": priceHtml,
|
||||
})
|
||||
htmlContent := buf.String()
|
||||
log.Println(htmlContent)
|
||||
// log.Println(htmlContent)
|
||||
return htmlContent, nil
|
||||
}
|
||||
|
||||
@@ -427,5 +291,32 @@ func (l *QuotationDetailLogic) QuotationDetail(req *types.RequestQuotationId, us
|
||||
}
|
||||
log.Println(htmlContent)
|
||||
|
||||
saler, err := l.svcCtx.AllModels.FsQuotationSaler.GetOne(l.ctx, quot.Id)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
return resp.SetStatus(basic.CodeDbRecordNotFoundErr)
|
||||
}
|
||||
return resp.SetStatus(basic.CodeDbSqlErr)
|
||||
}
|
||||
|
||||
// log.Println(saler)
|
||||
|
||||
tpl := template.New("quto")
|
||||
tpl = tpl.Funcs(format.TemplateFuncMap)
|
||||
|
||||
tpl = template.Must(tpl.ParseFiles(templatePath + "/return_html.tpl"))
|
||||
buf := &bytes.Buffer{}
|
||||
|
||||
err = tpl.Execute(buf, map[string]interface{}{
|
||||
"demoHtml": htmlContent,
|
||||
"qutoInfo": collect.StructJson2Map(quot),
|
||||
"salerInfo": collect.StructJson2Map(saler),
|
||||
})
|
||||
if err != nil {
|
||||
return resp.SetStatus(basic.CodeApiErr)
|
||||
}
|
||||
// returnHtmlContent := buf.String()
|
||||
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user