Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop
This commit is contained in:
commit
27c7b34555
|
@ -1,6 +0,0 @@
|
||||||
FROM alpine
|
|
||||||
|
|
||||||
WORKDIR /www/fusenapi/
|
|
||||||
COPY ./bin/api-backend-srv /www/fusenapi/
|
|
||||||
COPY ./etc /www/fusenapi/etc
|
|
||||||
CMD ["/www/fusenapi/api-backend-srv"]
|
|
|
@ -1,34 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"fusenapi/server/backend/internal/config"
|
|
||||||
"fusenapi/server/backend/internal/handler"
|
|
||||||
"fusenapi/server/backend/internal/svc"
|
|
||||||
"fusenapi/utils/auth"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/conf"
|
|
||||||
"github.com/zeromicro/go-zero/rest"
|
|
||||||
)
|
|
||||||
|
|
||||||
var configFile = flag.String("f", "etc/backend.yaml", "the config file")
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
flag.Parse()
|
|
||||||
|
|
||||||
var c config.Config
|
|
||||||
conf.MustLoad(*configFile, &c)
|
|
||||||
|
|
||||||
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
|
|
||||||
}))
|
|
||||||
defer server.Stop()
|
|
||||||
|
|
||||||
ctx := svc.NewServiceContext(c)
|
|
||||||
handler.RegisterHandlers(server, ctx)
|
|
||||||
|
|
||||||
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
|
|
||||||
server.Start()
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
Name: backend
|
|
||||||
Host: localhost
|
|
||||||
Port: 9901
|
|
||||||
Timeout: 15000 #服务超时时间
|
|
||||||
SourceMysql: "fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen"
|
|
||||||
Log:
|
|
||||||
Stat: false
|
|
||||||
Auth:
|
|
||||||
AccessSecret: fusen_backend_2023
|
|
||||||
AccessExpire: 2592000
|
|
||||||
RefreshAfter: 1592000
|
|
|
@ -1,14 +0,0 @@
|
||||||
package config
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fusenapi/server/backend/internal/types"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Config struct {
|
|
||||||
rest.RestConf
|
|
||||||
SourceMysql string
|
|
||||||
Auth types.Auth
|
|
||||||
ReplicaId uint64
|
|
||||||
}
|
|
|
@ -1,40 +0,0 @@
|
||||||
package handler
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
|
||||||
|
|
||||||
"fusenapi/utils/basic"
|
|
||||||
|
|
||||||
"fusenapi/server/backend/internal/logic"
|
|
||||||
"fusenapi/server/backend/internal/svc"
|
|
||||||
"fusenapi/server/backend/internal/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
func BackendUserLoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
|
|
||||||
var req types.RequestUserLogin
|
|
||||||
|
|
||||||
// 创建一个业务逻辑层实例
|
|
||||||
l := logic.NewBackendUserLoginLogic(r.Context(), svcCtx)
|
|
||||||
resp, token := l.BackendUserLogin(&req)
|
|
||||||
if resp.Code == basic.CodeOK.Code {
|
|
||||||
w.Header().Add("Authorization", fmt.Sprintf("Bearer %s", token))
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
|
||||||
// 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。
|
|
||||||
if resp != nil {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
} else {
|
|
||||||
err := errors.New("server logic is error, resp must not be nil")
|
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
logx.Error(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,34 +0,0 @@
|
||||||
package handler
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
"reflect"
|
|
||||||
|
|
||||||
"fusenapi/utils/basic"
|
|
||||||
|
|
||||||
"fusenapi/server/backend/internal/logic"
|
|
||||||
"fusenapi/server/backend/internal/svc"
|
|
||||||
"fusenapi/server/backend/internal/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
func QuotationDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
var req types.RequestQuotationId
|
|
||||||
userinfo, err := basic.RequestParseBackend(w, r, svcCtx, &req)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建一个业务逻辑层实例
|
|
||||||
l := logic.NewQuotationDetailLogic(r.Context(), svcCtx)
|
|
||||||
|
|
||||||
rl := reflect.ValueOf(l)
|
|
||||||
basic.BeforeLogic(w, r, rl)
|
|
||||||
|
|
||||||
resp := l.QuotationDetail(&req, userinfo)
|
|
||||||
|
|
||||||
if !basic.AfterLogic(w, r, rl, resp) {
|
|
||||||
basic.NormalAfterLogic(w, r, resp)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,27 +0,0 @@
|
||||||
// Code generated by goctl. DO NOT EDIT.
|
|
||||||
package handler
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"fusenapi/server/backend/internal/svc"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest"
|
|
||||||
)
|
|
||||||
|
|
||||||
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|
||||||
server.AddRoutes(
|
|
||||||
[]rest.Route{
|
|
||||||
{
|
|
||||||
Method: http.MethodGet,
|
|
||||||
Path: "/api/quotation/detail",
|
|
||||||
Handler: QuotationDetailHandler(serverCtx),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Method: http.MethodPost,
|
|
||||||
Path: "/api/backend-user/login",
|
|
||||||
Handler: BackendUserLoginHandler(serverCtx),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
|
@ -1,70 +0,0 @@
|
||||||
package logic
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fusenapi/utils/auth"
|
|
||||||
"fusenapi/utils/basic"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"fusenapi/server/backend/internal/svc"
|
|
||||||
"fusenapi/server/backend/internal/types"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
|
||||||
"gorm.io/gorm"
|
|
||||||
)
|
|
||||||
|
|
||||||
type BackendUserLoginLogic struct {
|
|
||||||
logx.Logger
|
|
||||||
ctx context.Context
|
|
||||||
svcCtx *svc.ServiceContext
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewBackendUserLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BackendUserLoginLogic {
|
|
||||||
return &BackendUserLoginLogic{
|
|
||||||
Logger: logx.WithContext(ctx),
|
|
||||||
ctx: ctx,
|
|
||||||
svcCtx: svcCtx,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *BackendUserLoginLogic) BackendUserLogin(req *types.RequestUserLogin) (resp *basic.Response, jwtToken string) {
|
|
||||||
// 创建一个 FsUserModel 对象 m 并实例化之,该对象用于操作 MySQL 数据库中的用户数据表。
|
|
||||||
m := l.svcCtx.AllModels.FsBackendUser
|
|
||||||
|
|
||||||
// 在用户数据表中根据登录名(email)查找用户记录,并返回 UserModel 类型的结构体对象 userModel。
|
|
||||||
user, err := m.FindUserByEmail(l.ctx, req.Name)
|
|
||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
||||||
return resp.SetStatus(basic.CodeEmailNotFoundErr), ""
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果在用户数据表中找到了登录名匹配的用户记录,则判断密码是否匹配。
|
|
||||||
if *user.PasswordHash != req.Password {
|
|
||||||
logx.Info("密码错误")
|
|
||||||
return resp.SetStatus(basic.CodePasswordErr), jwtToken
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果密码匹配,则生成 JWT Token。
|
|
||||||
nowSec := time.Now().UTC().Unix()
|
|
||||||
jwtToken, err = auth.GenerateBackendJwtToken(&l.svcCtx.Config.Auth.AccessSecret, l.svcCtx.Config.Auth.AccessExpire, nowSec, user.Id, 0)
|
|
||||||
|
|
||||||
// 如果生成 JWT Token 失败,则抛出错误并返回未认证的状态码。
|
|
||||||
if err != nil {
|
|
||||||
logx.Error(err)
|
|
||||||
return resp.SetStatus(basic.CodeUnAuth), jwtToken
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果更新 VerificationToken 字段失败,则返回未认证的状态码。
|
|
||||||
if err != nil {
|
|
||||||
return resp.SetStatus(basic.CodeUnAuth), jwtToken
|
|
||||||
}
|
|
||||||
|
|
||||||
// 构造 DataUserLogin 类型的数据对象 data 并设置其属性值为生成的 JWT Token。
|
|
||||||
data := &types.DataUserLogin{
|
|
||||||
Token: jwtToken,
|
|
||||||
}
|
|
||||||
|
|
||||||
// 返回认证成功的状态码以及数据对象 data 和 JWT Token。
|
|
||||||
return resp.SetStatus(basic.CodeOK, data), jwtToken
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
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"
|
|
||||||
}
|
|
|
@ -1,322 +0,0 @@
|
||||||
package logic
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
|
||||||
"fusenapi/model/gmodel"
|
|
||||||
"fusenapi/utils/auth"
|
|
||||||
"fusenapi/utils/basic"
|
|
||||||
"fusenapi/utils/collect"
|
|
||||||
"fusenapi/utils/format"
|
|
||||||
"log"
|
|
||||||
"strings"
|
|
||||||
"text/template"
|
|
||||||
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"fusenapi/server/backend/internal/svc"
|
|
||||||
"fusenapi/server/backend/internal/types"
|
|
||||||
|
|
||||||
"github.com/tidwall/gjson"
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
|
||||||
"gorm.io/gorm"
|
|
||||||
)
|
|
||||||
|
|
||||||
type QuotationDetailLogic struct {
|
|
||||||
logx.Logger
|
|
||||||
ctx context.Context
|
|
||||||
svcCtx *svc.ServiceContext
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewQuotationDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QuotationDetailLogic {
|
|
||||||
return &QuotationDetailLogic{
|
|
||||||
Logger: logx.WithContext(ctx),
|
|
||||||
ctx: ctx,
|
|
||||||
svcCtx: svcCtx,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetPrice(num int64, stepNum []int64, stepPrice []int64) int64 {
|
|
||||||
//阶梯价计算
|
|
||||||
if num > stepNum[len(stepNum)-1] {
|
|
||||||
return stepPrice[len(stepPrice)-1]
|
|
||||||
}
|
|
||||||
for k, v := range stepNum {
|
|
||||||
if num <= v {
|
|
||||||
return stepPrice[k]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetDemoHtml 报价单
|
|
||||||
func (l *QuotationDetailLogic) GetDemoHtml(quot *gmodel.FsQuotation, quotationProduct []*gmodel.FsQuotationProduct) (htmlcontent string, err error) {
|
|
||||||
|
|
||||||
// htmlContent := ""
|
|
||||||
priceHtml := ""
|
|
||||||
// productNum := len(quotationProduct)
|
|
||||||
// page := 3
|
|
||||||
// pageTotal := 3 + productNum
|
|
||||||
|
|
||||||
for _, quotProduct := range quotationProduct {
|
|
||||||
|
|
||||||
var priceInfo []map[string]interface{}
|
|
||||||
err := json.Unmarshal([]byte(*quotProduct.PriceInfo), &priceInfo)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
priceHtmlTpl := `
|
|
||||||
{{range $i, $parr := .priceInfo}}
|
|
||||||
{{if lt $i 3}}
|
|
||||||
<div class="pr-card">
|
|
||||||
<p class="pr">${{$parr.price}}</p>
|
|
||||||
<p class="num">{{$parr.num}}<span> Units</span></p>
|
|
||||||
</div>
|
|
||||||
{{else}}
|
|
||||||
<div class="pr-card" style="margin-right: 8px;">
|
|
||||||
<p class="pr">${{$parr.price}}</p>
|
|
||||||
<p class="num">{{$parr.num}}<span> Units</span></p>
|
|
||||||
</div>
|
|
||||||
{{end}}
|
|
||||||
{{end}}`
|
|
||||||
|
|
||||||
tpl := template.Must(template.New("prCardTpl").Parse(priceHtmlTpl))
|
|
||||||
buf := &bytes.Buffer{}
|
|
||||||
err = tpl.Execute(buf, map[string]interface{}{
|
|
||||||
"priceInfo": priceInfo,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
priceHtml = buf.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
tpl := template.New("quto")
|
|
||||||
tpl = tpl.Funcs(format.TemplateFuncMap)
|
|
||||||
|
|
||||||
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)
|
|
||||||
return htmlContent, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *QuotationDetailLogic) QuotationDetail(req *types.RequestQuotationId, userinfo *auth.BackendUserInfo) (resp *basic.Response) {
|
|
||||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
|
||||||
// userinfo 传入值时, 一定不为null
|
|
||||||
quot, err := l.svcCtx.AllModels.FsQuotation.FindOneOnlyById(l.ctx, req.QuotationId)
|
|
||||||
if err != nil {
|
|
||||||
if err == gorm.ErrRecordNotFound {
|
|
||||||
return resp.SetStatus(basic.CodeDbRecordNotFoundErr)
|
|
||||||
}
|
|
||||||
return resp.SetStatus(basic.CodeDbSqlErr)
|
|
||||||
}
|
|
||||||
|
|
||||||
CanteenProduct, err := l.svcCtx.AllModels.FsCanteenProduct.GetAllByCanteenTypeIdOrderAsc(l.ctx, *quot.CanteenType)
|
|
||||||
if err != nil {
|
|
||||||
if err == gorm.ErrRecordNotFound {
|
|
||||||
return resp.SetStatus(basic.CodeDbRecordNotFoundErr)
|
|
||||||
}
|
|
||||||
return resp.SetStatus(basic.CodeDbSqlErr)
|
|
||||||
}
|
|
||||||
|
|
||||||
quotationProduct, err := l.svcCtx.AllModels.FsQuotationProduct.GetAllByQuotationIdOrderAsc(l.ctx, req.QuotationId)
|
|
||||||
if err != nil {
|
|
||||||
if err != gorm.ErrRecordNotFound {
|
|
||||||
return resp.SetStatus(basic.CodeDbSqlErr)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var target any = quotationProduct
|
|
||||||
if len(quotationProduct) == 0 {
|
|
||||||
target = CanteenProduct
|
|
||||||
}
|
|
||||||
|
|
||||||
jdata, err := json.Marshal(target)
|
|
||||||
if err != nil {
|
|
||||||
logx.Error(err)
|
|
||||||
return resp.SetStatus(basic.CodeJsonErr)
|
|
||||||
}
|
|
||||||
|
|
||||||
list := gjson.ParseBytes(jdata)
|
|
||||||
|
|
||||||
qFlag := len(quotationProduct) > 0
|
|
||||||
|
|
||||||
//获取备注模板
|
|
||||||
// markList, err := l.svcCtx.AllModels.FsQuotationRemarkTemplate.GetAllSelectContent(l.ctx)
|
|
||||||
|
|
||||||
var productIds = collect.ArrayColumnTag[int64](CanteenProduct, "product_id")
|
|
||||||
productList, err := l.svcCtx.AllModels.FsProduct.FindAllOnlyByIds(l.ctx, productIds)
|
|
||||||
if err != nil {
|
|
||||||
logx.Error(err)
|
|
||||||
return resp.SetStatus(basic.CodeDbSqlErr)
|
|
||||||
}
|
|
||||||
productListMap := collect.Array2MapByKeyTag[int64](productList, "id")
|
|
||||||
|
|
||||||
//获取size信息
|
|
||||||
var sizeIds = collect.ArrayColumnTag[int64](CanteenProduct, "size_id")
|
|
||||||
sizes, err := l.svcCtx.AllModels.FsProductSize.GetAllSelectIdAndCapacityByIds(l.ctx, sizeIds)
|
|
||||||
if err != nil {
|
|
||||||
logx.Error(err)
|
|
||||||
return resp.SetStatus(basic.CodeDbSqlErr)
|
|
||||||
}
|
|
||||||
sizesMap := collect.Array2MapByKeyTag[int64](sizes, "id")
|
|
||||||
|
|
||||||
//获取价格信息
|
|
||||||
productPrice, err := l.svcCtx.AllModels.FsProductPrice.GetAllSelectBySizeId(l.ctx, sizeIds)
|
|
||||||
if err != nil {
|
|
||||||
logx.Error(err)
|
|
||||||
return resp.SetStatus(basic.CodeDbSqlErr)
|
|
||||||
}
|
|
||||||
productPriceMap := collect.Array2MapByKeyTag[int64](productPrice, "size_id")
|
|
||||||
// product := []map[string]interface{}{}
|
|
||||||
|
|
||||||
products := []map[string]interface{}{}
|
|
||||||
for _, parr := range list.Array() {
|
|
||||||
|
|
||||||
var priceList []map[string]int64
|
|
||||||
|
|
||||||
if !qFlag {
|
|
||||||
|
|
||||||
if price, ok := productPriceMap[parr.Get("size_id").Int()]; !ok {
|
|
||||||
priceList = []map[string]int64{
|
|
||||||
{"num": 1, "price": 0},
|
|
||||||
{"num": 1, "price": 0},
|
|
||||||
{"num": 1, "price": 0},
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
|
|
||||||
i := 0
|
|
||||||
price.StepNum = collect.ArrayString2Int(strings.Split(price.StepNum.(string), ","))
|
|
||||||
price.StepPrice = collect.ArrayString2Int(strings.Split(price.StepPrice.(string), ","))
|
|
||||||
for price.MinBuyNum < int64(len(price.StepNum.([]string))+5) && i < 3 {
|
|
||||||
priceList = append(priceList, map[string]int64{
|
|
||||||
"num": int64(price.MinBuyNum * price.EachBoxNum),
|
|
||||||
"price": GetPrice(price.MinBuyNum, price.StepNum.([]int64), price.StepPrice.([]int64)) / 100,
|
|
||||||
})
|
|
||||||
price.MinBuyNum++
|
|
||||||
i++
|
|
||||||
}
|
|
||||||
if len(priceList) < 3 {
|
|
||||||
for j := 0; j < 3-len(priceList); j++ {
|
|
||||||
priceList = append(priceList, map[string]int64{"num": 1, "price": 0})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
Id any
|
|
||||||
priceInfo any
|
|
||||||
mark any
|
|
||||||
sid any
|
|
||||||
|
|
||||||
isGift bool
|
|
||||||
name any
|
|
||||||
size any
|
|
||||||
cycle any
|
|
||||||
img any
|
|
||||||
|
|
||||||
num any
|
|
||||||
)
|
|
||||||
if qFlag {
|
|
||||||
|
|
||||||
Id = parr.Get("id")
|
|
||||||
|
|
||||||
err = json.Unmarshal([]byte(parr.Get("price_info").String()), &priceInfo)
|
|
||||||
if err != nil {
|
|
||||||
logx.Error(err)
|
|
||||||
return resp.SetStatus(basic.CodeJsonErr)
|
|
||||||
}
|
|
||||||
|
|
||||||
if parr.Get("sid").Exists() {
|
|
||||||
sid = parr.Get("sid").Int()
|
|
||||||
}
|
|
||||||
|
|
||||||
name = parr.Get("name").String()
|
|
||||||
size = parr.Get("size").Int()
|
|
||||||
cycle = parr.Get("cycle").Int()
|
|
||||||
img = parr.Get("img").String()
|
|
||||||
|
|
||||||
if parr.Get("remark").Exists() {
|
|
||||||
err = json.Unmarshal([]byte(parr.Get("remark").String()), &mark)
|
|
||||||
if err != nil {
|
|
||||||
logx.Error(err)
|
|
||||||
return resp.SetStatus(basic.CodeJsonErr)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
num = parr.Get("num").Int()
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
if parr.Get("sid").Exists() {
|
|
||||||
sid = parr.Get("sid").Int()
|
|
||||||
}
|
|
||||||
|
|
||||||
product := productListMap[parr.Get("product_id").Int()]
|
|
||||||
name = product.Title
|
|
||||||
size = sizesMap[parr.Get("size_id").Int()].Capacity
|
|
||||||
cycle = *product.ProduceDays + *product.DeliveryDays
|
|
||||||
img = ""
|
|
||||||
mark = []string{}
|
|
||||||
priceInfo = priceList
|
|
||||||
num = 1
|
|
||||||
}
|
|
||||||
|
|
||||||
products = append(products, map[string]interface{}{
|
|
||||||
"id": Id,
|
|
||||||
"s_id": sid,
|
|
||||||
"is_gift": isGift,
|
|
||||||
"name": name,
|
|
||||||
"size": size,
|
|
||||||
"cycle": cycle,
|
|
||||||
"img": img,
|
|
||||||
"mark": mark,
|
|
||||||
"price_list": priceInfo,
|
|
||||||
"num": num,
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
htmlContent, err := l.GetDemoHtml(", quotationProduct)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
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)
|
|
||||||
}
|
|
|
@ -1,62 +0,0 @@
|
||||||
package svc
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"fusenapi/server/backend/internal/config"
|
|
||||||
"fusenapi/shared"
|
|
||||||
"net/http"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"fusenapi/initalize"
|
|
||||||
"fusenapi/model/gmodel"
|
|
||||||
|
|
||||||
"github.com/golang-jwt/jwt"
|
|
||||||
"gorm.io/gorm"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ServiceContext struct {
|
|
||||||
Config config.Config
|
|
||||||
SharedState *shared.SharedState
|
|
||||||
|
|
||||||
MysqlConn *gorm.DB
|
|
||||||
AllModels *gmodel.AllModelsGen
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewServiceContext(c config.Config) *ServiceContext {
|
|
||||||
db := initalize.InitMysql(c.SourceMysql).Set("gorm:slow_query_time", time.Second*15)
|
|
||||||
return &ServiceContext{
|
|
||||||
Config: c,
|
|
||||||
MysqlConn: initalize.InitMysql(c.SourceMysql),
|
|
||||||
AllModels: gmodel.NewAllModels(db),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
|
|
||||||
AuthKey := r.Header.Get("Authorization")
|
|
||||||
|
|
||||||
if len(AuthKey) <= 50 {
|
|
||||||
return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey)))
|
|
||||||
}
|
|
||||||
|
|
||||||
AuthKey = AuthKey[7:]
|
|
||||||
|
|
||||||
token, err := jwt.Parse(AuthKey, func(token *jwt.Token) (interface{}, error) {
|
|
||||||
// 检查签名方法是否为 HS256
|
|
||||||
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
|
|
||||||
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
|
|
||||||
}
|
|
||||||
// 返回用于验证签名的密钥
|
|
||||||
return []byte(svcCtx.Config.Auth.AccessSecret), nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.New(fmt.Sprint("Error parsing token:", err))
|
|
||||||
}
|
|
||||||
|
|
||||||
// 验证成功返回
|
|
||||||
if claims, ok := token.Claims.(jwt.MapClaims); ok && token.Valid {
|
|
||||||
return claims, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, errors.New(fmt.Sprint("Invalid token", err))
|
|
||||||
}
|
|
|
@ -1,88 +0,0 @@
|
||||||
// Code generated by goctl. DO NOT EDIT.
|
|
||||||
package types
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fusenapi/utils/basic"
|
|
||||||
)
|
|
||||||
|
|
||||||
type RequestQuotationId struct {
|
|
||||||
QuotationId int64 `form:"id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type RequestUserLogin struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
Password string `json:"pwd"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type DataUserLogin struct {
|
|
||||||
Token string `json:"token"` // 登录jwt token
|
|
||||||
}
|
|
||||||
|
|
||||||
type Request struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
type Response struct {
|
|
||||||
Code int `json:"code"`
|
|
||||||
Message string `json:"msg"`
|
|
||||||
Data interface{} `json:"data"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Auth struct {
|
|
||||||
AccessSecret string `json:"accessSecret"`
|
|
||||||
AccessExpire int64 `json:"accessExpire"`
|
|
||||||
RefreshAfter int64 `json:"refreshAfter"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type File struct {
|
|
||||||
Filename string `fsfile:"filename"`
|
|
||||||
Header map[string][]string `fsfile:"header"`
|
|
||||||
Size int64 `fsfile:"size"`
|
|
||||||
Data []byte `fsfile:"data"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Meta struct {
|
|
||||||
TotalCount int64 `json:"totalCount"`
|
|
||||||
PageCount int64 `json:"pageCount"`
|
|
||||||
CurrentPage int `json:"currentPage"`
|
|
||||||
PerPage int `json:"perPage"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set 设置Response的Code和Message值
|
|
||||||
func (resp *Response) Set(Code int, Message string) *Response {
|
|
||||||
return &Response{
|
|
||||||
Code: Code,
|
|
||||||
Message: Message,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set 设置整个Response
|
|
||||||
func (resp *Response) SetWithData(Code int, Message string, Data interface{}) *Response {
|
|
||||||
return &Response{
|
|
||||||
Code: Code,
|
|
||||||
Message: Message,
|
|
||||||
Data: Data,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetStatus 设置默认StatusResponse(内部自定义) 默认msg, 可以带data, data只使用一个参数
|
|
||||||
func (resp *Response) SetStatus(sr *basic.StatusResponse, data ...interface{}) *Response {
|
|
||||||
newResp := &Response{
|
|
||||||
Code: sr.Code,
|
|
||||||
}
|
|
||||||
if len(data) == 1 {
|
|
||||||
newResp.Data = data[0]
|
|
||||||
}
|
|
||||||
return newResp
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetStatusWithMessage 设置默认StatusResponse(内部自定义) 非默认msg, 可以带data, data只使用一个参数
|
|
||||||
func (resp *Response) SetStatusWithMessage(sr *basic.StatusResponse, msg string, data ...interface{}) *Response {
|
|
||||||
newResp := &Response{
|
|
||||||
Code: sr.Code,
|
|
||||||
Message: msg,
|
|
||||||
}
|
|
||||||
if len(data) == 1 {
|
|
||||||
newResp.Data = data[0]
|
|
||||||
}
|
|
||||||
return newResp
|
|
||||||
}
|
|
|
@ -1,129 +0,0 @@
|
||||||
{{$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}}
|
|
|
@ -1,371 +0,0 @@
|
||||||
{{$html := .demoHtml}}
|
|
||||||
{{$saler := .salerInfo}}
|
|
||||||
{{$info := .qutoInfo}}
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<title>quotation</title>
|
|
||||||
<style>
|
|
||||||
@font-face {
|
|
||||||
font-family: \'Montserrat\';
|
|
||||||
src: url(\'https://fusenapi.kayue.cn:8010/storage/font/Montserrat-VariableFont_wght.ttf\');
|
|
||||||
}
|
|
||||||
body {
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
img {
|
|
||||||
max-width: 100%;
|
|
||||||
max-height: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
#quotation-pdf-box {
|
|
||||||
font-family: \'Montserrat\';
|
|
||||||
image-rendering: -moz-crisp-edges;
|
|
||||||
image-rendering: -o-crisp-edges;
|
|
||||||
image-rendering: -webkit-optimize-contrast;
|
|
||||||
image-rendering: crisp-edges;
|
|
||||||
-ms-interpolation-mode: nearest-neighbor;
|
|
||||||
-webkit-font-smooting: antialiased;
|
|
||||||
}
|
|
||||||
|
|
||||||
#quotation-pdf-box div {
|
|
||||||
box-sizing: content-box;
|
|
||||||
}
|
|
||||||
|
|
||||||
#quotation-pdf-box p {
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#quotation-pdf-box .box {
|
|
||||||
margin: 0 auto;
|
|
||||||
width: 722px;
|
|
||||||
height: 938px;
|
|
||||||
overflow: hidden;
|
|
||||||
padding-top: 55px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#quotation-pdf-box .box:last-child {
|
|
||||||
padding-top: 110px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#quotation-pdf-box .logo {
|
|
||||||
height: 27px;
|
|
||||||
width: 118px;
|
|
||||||
position: absolute;
|
|
||||||
right: 0;
|
|
||||||
top: 2px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#quotation-pdf-box .img-box {
|
|
||||||
background-color: #a4a4a4;
|
|
||||||
border-radius: 15px;
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
|
|
||||||
#quotation-pdf-box .img-box .img {
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
background-size: contain;
|
|
||||||
background-repeat: no-repeat;
|
|
||||||
background-position: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
#quotation-pdf-box .text-box {
|
|
||||||
background-color: #ff7f00;
|
|
||||||
border-radius: 13px;
|
|
||||||
color: #fff;
|
|
||||||
}
|
|
||||||
|
|
||||||
#quotation-pdf-box .page-box {
|
|
||||||
background-color: rgba(125, 125, 125, 0.16);
|
|
||||||
text-align: center;
|
|
||||||
height: 50px;
|
|
||||||
line-height: 50px;
|
|
||||||
margin-top: 30px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#quotation-pdf-box .card-box {
|
|
||||||
border-radius: 4px;
|
|
||||||
box-sizing: border-box;
|
|
||||||
}
|
|
||||||
|
|
||||||
#quotation-pdf-box .pr-card {
|
|
||||||
float: left;
|
|
||||||
width: 175px;
|
|
||||||
height: 156px;
|
|
||||||
margin-right: 3px;
|
|
||||||
color: #fff;
|
|
||||||
text-align: center;
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
|
|
||||||
#quotation-pdf-box .pr-card.big {
|
|
||||||
width: 530px;
|
|
||||||
height: 198px;
|
|
||||||
margin-right: 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#quotation-pdf-box .pr-card::after {
|
|
||||||
border-bottom: 1px dashed #fff;
|
|
||||||
content: "";
|
|
||||||
width: 100%;
|
|
||||||
top: 97.67px;
|
|
||||||
left: 0;
|
|
||||||
height: 1px;
|
|
||||||
position: absolute;
|
|
||||||
}
|
|
||||||
|
|
||||||
#quotation-pdf-box .pr-card.big::after {
|
|
||||||
top: 120px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#quotation-pdf-box .pr-card .pr {
|
|
||||||
width: 100%;
|
|
||||||
height: 98.67px;
|
|
||||||
border-radius: 7px;
|
|
||||||
background-color: #ff7f00;
|
|
||||||
line-height: 97.67px;
|
|
||||||
font-size: 50px;
|
|
||||||
font-weight: 800;
|
|
||||||
}
|
|
||||||
|
|
||||||
#quotation-pdf-box .pr-card.big .pr {
|
|
||||||
font-size: 97px;
|
|
||||||
font-weight: 850;
|
|
||||||
line-height: 120.85px;
|
|
||||||
height: 120.85px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#quotation-pdf-box .pr-card .num {
|
|
||||||
width: 100%;
|
|
||||||
height: 58.31px;
|
|
||||||
border-radius: 7px;
|
|
||||||
background-color: #ff7f00;
|
|
||||||
line-height: 58.31px;
|
|
||||||
font-size: 26px;
|
|
||||||
font-weight: 800;
|
|
||||||
}
|
|
||||||
|
|
||||||
#quotation-pdf-box .pr-card.big .num {
|
|
||||||
font-size: 58px;
|
|
||||||
font-weight: 700;
|
|
||||||
line-height: 76.1px;
|
|
||||||
height: 76.1px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#quotation-pdf-box .pr-card .num span {
|
|
||||||
font-size: 16px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#quotation-pdf-box .pr-card.big .num span {
|
|
||||||
font-size: 38px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#quotation-pdf-box .more-card {
|
|
||||||
display: inline-block;
|
|
||||||
width: 183px;
|
|
||||||
padding-left: 16px;
|
|
||||||
margin-bottom: 4px;
|
|
||||||
background-color: #47AA6C;
|
|
||||||
line-height: 30px;
|
|
||||||
font-size: 16px;
|
|
||||||
color: #fff;
|
|
||||||
}
|
|
||||||
|
|
||||||
#quotation-pdf-box .more-card .free {
|
|
||||||
font-weight: 800;
|
|
||||||
}
|
|
||||||
|
|
||||||
#quotation-pdf-box .more-card .text {
|
|
||||||
font-weight: 500;
|
|
||||||
}
|
|
||||||
|
|
||||||
#quotation-pdf-box .logos-list {
|
|
||||||
text-align: center;
|
|
||||||
height: 233px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#quotation-pdf-box .logos-list .logo-item {
|
|
||||||
float: left;
|
|
||||||
width: 93px;
|
|
||||||
height: 64px;
|
|
||||||
margin-right: 10px;
|
|
||||||
margin-bottom: 18px;
|
|
||||||
background-position: center;
|
|
||||||
background-size: contain;
|
|
||||||
background-repeat: no-repeat;
|
|
||||||
}
|
|
||||||
|
|
||||||
#quotation-pdf-box .logos-list .logo-item:nth-child(7n) {
|
|
||||||
margin-right: 0;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div id="quotation-pdf-box">
|
|
||||||
<!-- 首页 -->
|
|
||||||
<div class="box">
|
|
||||||
<div style="position: relative; margin-bottom: 31px;">
|
|
||||||
<p class="f-m" style="font-size: 40px; font-weight: 600; margin-bottom: 4px; line-height: 39px;">
|
|
||||||
Custom
|
|
||||||
Packaging For</p>
|
|
||||||
<p class="f-b" style="font-size: 60px; font-weight: 600;line-height: 54px;">{{$info.canteen_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: 558px;margin-bottom: 30px; overflow: hidden;">
|
|
||||||
<div class="img"
|
|
||||||
style="background-image: url({{$info.cover}});">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="text-box" style="padding: 27px;padding-right: 21px;">
|
|
||||||
<p class="f-b" style="margin-bottom: 16px; font-size: 23px;line-height: 24px;font-weight: 800;">
|
|
||||||
Hi, I\'m
|
|
||||||
Victor from Fusenpack.</p>
|
|
||||||
<p class="f-b" style="margin-bottom: 19px; font-weight:300; font-size: 16px; line-height: 20px;">We
|
|
||||||
offer simple custom packaging solutions for restaurants with a minimum order quantity that\'s 5X
|
|
||||||
lower than regular suppliers. Check out our custom designs and prices on the following pages.
|
|
||||||
Contact me at if you have any questions. Thanks!</p>
|
|
||||||
<div style="margin-bottom: 6px;">
|
|
||||||
<div
|
|
||||||
style="width: 18px; height: 18px; margin-right: 9px; display: inline-block;position: relative;">
|
|
||||||
<img style="position: absolute;top: 4px;left: 0;"
|
|
||||||
src="https://fusenapi.kayue.cn:8010/storage/pdf/phone.svg" alt="">
|
|
||||||
</div>
|
|
||||||
<p class="f-b" style="font-size: 19px; display: inline-block; line-height: 13px;font-weight: 500;">
|
|
||||||
{{$saler.phone}}</p>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<div
|
|
||||||
style="width: 18px; height: 18px; margin-right: 9px; display: inline-block; position: relative;">
|
|
||||||
<img style="position: absolute;top: 3px;left: 0;"
|
|
||||||
src="https://fusenapi.kayue.cn:8010/storage/pdf/email.svg" alt="">
|
|
||||||
</div>
|
|
||||||
<p class="f-b" style="font-size: 19px; display: inline-block; line-height: 17px;font-weight: 500;">
|
|
||||||
{{$saler.email}}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<!-- 首页结束 -->
|
|
||||||
<!-- <div class="page-box">1/6</div> -->
|
|
||||||
<!-- 对比页 -->
|
|
||||||
<div class="box">
|
|
||||||
<div style="position: relative; margin-bottom: 33px;">
|
|
||||||
<p class="f-m" style="font-size: 39px; font-weight: 800; margin-bottom: 4px; line-height: 39px;">
|
|
||||||
Why Custom Packaging?</p>
|
|
||||||
<div class="logo">
|
|
||||||
<img src="https://fusenapi.kayue.cn:8010/storage/pdf/logo.svg" alt="logo">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div style="height: 865px; overflow: hidden; position: relative;">
|
|
||||||
<div style="width: 100%;height: 100%;">
|
|
||||||
<img src="https://fusenapi.kayue.cn:8010/storage/pdf/page_img_1.png" alt="">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<!-- 对比页结束 -->
|
|
||||||
<!-- <div class="page-box">2/6</div> -->
|
|
||||||
<!-- 其他物料页 -->
|
|
||||||
<!-- 其他物料页结束 -->
|
|
||||||
<!-- <div class="page-box">3/6</div> -->
|
|
||||||
<!-- 餐具套装页 -->
|
|
||||||
<!-- 餐具套装页结束 -->
|
|
||||||
<!-- <div class="page-box">4/6</div> -->
|
|
||||||
<!-- 服装页 -->
|
|
||||||
<!-- 服装页结束 -->
|
|
||||||
<!-- <div class="page-box">5/6</div> -->
|
|
||||||
{{$html}}
|
|
||||||
<!-- 尾页 -->
|
|
||||||
<div class="box">
|
|
||||||
<div style="height: 404px; overflow: hidden;position: relative;">
|
|
||||||
<div class="logo" style="height: 42px;width: 191px;left: 0;top: 0;">
|
|
||||||
<img src="https://fusenapi.kayue.cn:8010/storage/pdf/logo.svg" alt="logo">
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
style="width: 100%;height: 100%;background: url(\'https://fusenapi.kayue.cn:8010/storage/pdf/page_img_2.png\') center no-repeat;background-size: contain;">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="text-box" style="padding: 25px 23px 25px 31px;margin-bottom: 44px;">
|
|
||||||
<p class="f-b" style="margin-bottom: 34px; font-weight: 500; font-size: 16.15px; line-height: 20px;">
|
|
||||||
There\'s more! If you don\'t see what you need on these pages, please contact us to inquire about
|
|
||||||
additional items.</p>
|
|
||||||
<p style="font-size: 26px;font-weight: 700;line-height: 22px;margin-bottom: 10px;">{{$saler.name}}</p>
|
|
||||||
<div style="margin-bottom: 6px;">
|
|
||||||
<div
|
|
||||||
style="width: 18px; height: 18px; margin-right: 9px; display: inline-block;position: relative;">
|
|
||||||
<img style="position: absolute;top: 4px;left: 0;"
|
|
||||||
src="https://fusenapi.kayue.cn:8010/storage/pdf/phone.svg" alt="">
|
|
||||||
</div>
|
|
||||||
<p class="f-b" style="font-size: 19px; display: inline-block; line-height: 13px;font-weight: 500;">
|
|
||||||
{{$saler.phone}}</p>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<div
|
|
||||||
style="width: 18px; height: 18px; margin-right: 9px; display: inline-block; position: relative;">
|
|
||||||
<img style="position: absolute;top: 3px;left: 0;"
|
|
||||||
src="https://fusenapi.kayue.cn:8010/storage/pdf/email.svg" alt="">
|
|
||||||
</div>
|
|
||||||
<p class="f-b" style="font-size: 19px; display: inline-block; line-height: 17px;font-weight: 500;">
|
|
||||||
{{$saler.email}}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="text-box"
|
|
||||||
style="padding: 0 31px;display:inline-block;line-height: 35px;margin-bottom: 15px;font-size: 19px;font-weight: 700;text-align: center;border-radius: 5px;">
|
|
||||||
Our Customers:</div>
|
|
||||||
<div class="logos-list">
|
|
||||||
<div class="logo-item"
|
|
||||||
style="background-image: url(\'https://fusenapi.kayue.cn:8010/storage/pdf/page_logo_1.png\');"></div>
|
|
||||||
<div class="logo-item"
|
|
||||||
style="background-image: url(\'https://fusenapi.kayue.cn:8010/storage/pdf/page_logo_2.png\');"></div>
|
|
||||||
<div class="logo-item"
|
|
||||||
style="background-image: url(\'https://fusenapi.kayue.cn:8010/storage/pdf/page_logo_3.png\');"></div>
|
|
||||||
<div class="logo-item"
|
|
||||||
style="background-image: url(\'https://fusenapi.kayue.cn:8010/storage/pdf/page_logo_4.png\');"></div>
|
|
||||||
<div class="logo-item"
|
|
||||||
style="background-image: url(\'https://fusenapi.kayue.cn:8010/storage/pdf/page_logo_5.png\');"></div>
|
|
||||||
<div class="logo-item"
|
|
||||||
style="background-image: url(\'https://fusenapi.kayue.cn:8010/storage/pdf/page_logo_6.png\');"></div>
|
|
||||||
<div class="logo-item"
|
|
||||||
style="background-image: url(\'https://fusenapi.kayue.cn:8010/storage/pdf/page_logo_7.png\');"></div>
|
|
||||||
<div class="logo-item"
|
|
||||||
style="background-image: url(\'https://fusenapi.kayue.cn:8010/storage/pdf/page_logo_8.png\');"></div>
|
|
||||||
<div class="logo-item"
|
|
||||||
style="background-image: url(\'https://fusenapi.kayue.cn:8010/storage/pdf/page_logo_9.png\');"></div>
|
|
||||||
<div class="logo-item"
|
|
||||||
style="background-image: url(\'https://fusenapi.kayue.cn:8010/storage/pdf/page_logo_10.png\');"></div>
|
|
||||||
<div class="logo-item"
|
|
||||||
style="background-image: url(\'https://fusenapi.kayue.cn:8010/storage/pdf/page_logo_11.png\');"></div>
|
|
||||||
<div class="logo-item"
|
|
||||||
style="background-image: url(\'https://fusenapi.kayue.cn:8010/storage/pdf/page_logo_12.png\');"></div>
|
|
||||||
<div class="logo-item"
|
|
||||||
style="background-image: url(\'https://fusenapi.kayue.cn:8010/storage/pdf/page_logo_13.png\');"></div>
|
|
||||||
<div class="logo-item"
|
|
||||||
style="background-image: url(\'https://fusenapi.kayue.cn:8010/storage/pdf/page_logo_14.png\');"></div>
|
|
||||||
<div class="logo-item"
|
|
||||||
style="background-image: url(\'https://fusenapi.kayue.cn:8010/storage/pdf/page_logo_15.png\');"></div>
|
|
||||||
<div class="logo-item"
|
|
||||||
style="background-image: url(\'https://fusenapi.kayue.cn:8010/storage/pdf/page_logo_16.png\');"></div>
|
|
||||||
<div class="logo-item"
|
|
||||||
style="background-image: url(\'https://fusenapi.kayue.cn:8010/storage/pdf/page_logo_17.png\');"></div>
|
|
||||||
<div class="logo-item"
|
|
||||||
style="background-image: url(\'https://fusenapi.kayue.cn:8010/storage/pdf/page_logo_18.png\');"></div>
|
|
||||||
<div class="logo-item"
|
|
||||||
style="background-image: url(\'https://fusenapi.kayue.cn:8010/storage/pdf/page_logo_19.png\');"></div>
|
|
||||||
<div class="logo-item"
|
|
||||||
style="background-image: url(\'https://fusenapi.kayue.cn:8010/storage/pdf/page_logo_20.png\');"></div>
|
|
||||||
<div class="logo-item"
|
|
||||||
style="background-image: url(\'https://fusenapi.kayue.cn:8010/storage/pdf/page_logo_21.png\');"></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<!-- 尾页结束 -->
|
|
||||||
<!-- <div class="page-box">6/6</div> -->
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
|
@ -1,43 +0,0 @@
|
||||||
package backendtest
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
authtest "fusenapi/server/auth/test"
|
|
||||||
"fusenapi/server/backend/internal/config"
|
|
||||||
"fusenapi/server/backend/internal/handler"
|
|
||||||
"fusenapi/server/backend/internal/svc"
|
|
||||||
"fusenapi/utils/fstests"
|
|
||||||
"log"
|
|
||||||
"runtime"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/conf"
|
|
||||||
"github.com/zeromicro/go-zero/rest"
|
|
||||||
)
|
|
||||||
|
|
||||||
var cnf config.Config
|
|
||||||
var userver, gserver *rest.Server
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
log.SetFlags(log.Llongfile)
|
|
||||||
userver = authtest.GetTestServer()
|
|
||||||
gserver = GetTestServer()
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetTestServer() *rest.Server {
|
|
||||||
|
|
||||||
conf.MustLoad(fstests.GetEtcYamlPathAuto(), &cnf)
|
|
||||||
|
|
||||||
server := rest.MustNewServer(cnf.RestConf)
|
|
||||||
runtime.SetFinalizer(server, func(server *rest.Server) {
|
|
||||||
if server != nil {
|
|
||||||
server.Stop()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
ctx := svc.NewServiceContext(cnf)
|
|
||||||
handler.RegisterHandlers(server, ctx)
|
|
||||||
|
|
||||||
fmt.Printf("Starting server at %s:%d...\n", cnf.Host, cnf.Port)
|
|
||||||
return server
|
|
||||||
}
|
|
|
@ -1,29 +0,0 @@
|
||||||
package backendtest
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
fstests "fusenapi/utils/fstests"
|
|
||||||
"log"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestCaseQuotationDetail(t *testing.T) {
|
|
||||||
ses := fstests.GetBackendSessionWithUserToken(t, gserver, cnf.Host, cnf.Port)
|
|
||||||
|
|
||||||
// 构建新增地址请求体
|
|
||||||
// addrReq := types.RequestQuotationId{
|
|
||||||
// QuotationId: 1003,
|
|
||||||
// }
|
|
||||||
|
|
||||||
// 向服务器发送 POST 请求,新增用户地址
|
|
||||||
tp := ses.Get(fmt.Sprintf("http://%s:%d/api//quotation/detail", cnf.Host, cnf.Port))
|
|
||||||
tp.QueryParam("id").Set(1003)
|
|
||||||
resp, err := tp.TestExecute(gserver)
|
|
||||||
log.Println(resp.Json())
|
|
||||||
if err != nil {
|
|
||||||
t.Error(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Println(resp.Json())
|
|
||||||
}
|
|
|
@ -1,314 +0,0 @@
|
||||||
package backendtest
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"fusenapi/model/gmodel"
|
|
||||||
"fusenapi/utils/collect"
|
|
||||||
"fusenapi/utils/format"
|
|
||||||
"html/template"
|
|
||||||
"log"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestCaseTpl(t *testing.T) {
|
|
||||||
|
|
||||||
priceInfo := []map[string]interface{}{
|
|
||||||
{"Price": "$10", "Num": 100},
|
|
||||||
{"Price": "$20", "Num": 200},
|
|
||||||
{"Price": "$30", "Num": 300},
|
|
||||||
{"Price": "$40", "Num": 400},
|
|
||||||
}
|
|
||||||
|
|
||||||
priceHtml := `
|
|
||||||
{{range $i, $parr := .}}
|
|
||||||
{{if lt $i 3}}
|
|
||||||
<div class="pr-card">
|
|
||||||
<p class="pr">${{$parr.Price}}</p>
|
|
||||||
<p class="num">{{$parr.Num}}<span> Units</span></p>
|
|
||||||
</div>
|
|
||||||
{{else}}
|
|
||||||
<div class="pr-card" style="margin-right: 8px;">
|
|
||||||
<p class="pr">${{$parr.Price}}</p>
|
|
||||||
<p class="num">{{$parr.Num}}<span> Units</span></p>
|
|
||||||
</div>
|
|
||||||
{{end}}
|
|
||||||
{{end}}`
|
|
||||||
|
|
||||||
tpl := template.Must(template.New("demoHtml").Parse(priceHtml))
|
|
||||||
buf := bytes.NewBufferString("")
|
|
||||||
tpl.Execute(buf, priceInfo)
|
|
||||||
html := buf.String()
|
|
||||||
log.Println(html)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Randomproduct() []*gmodel.FsQuotationProduct {
|
|
||||||
var quotationId1 int64 = 1
|
|
||||||
name1 := "T恤"
|
|
||||||
size1 := "S,M,L,XL,XXL"
|
|
||||||
var cycle1 int64 = 7
|
|
||||||
var isGift1 int64 = 0
|
|
||||||
img1 := "https://xxx.jpg"
|
|
||||||
var status1 int64 = 1
|
|
||||||
var ctime1 int64 = 1623311101
|
|
||||||
var sort1 int64 = 1
|
|
||||||
sid1 := "abcd1234"
|
|
||||||
priceInfo1 := `[{"num":500,"price":0.1},{"num":1000,"price":0.06},{"num":1500,"price":0.06}]`
|
|
||||||
remark1 := ""
|
|
||||||
var num1 int64 = 100
|
|
||||||
|
|
||||||
var quotationId2 int64 = 1
|
|
||||||
name2 := "帽子"
|
|
||||||
size2 := "通用"
|
|
||||||
var cycle2 int64 = 3
|
|
||||||
var isGift2 int64 = 1
|
|
||||||
img2 := "https://xxx.jpg"
|
|
||||||
var status2 int64 = 1
|
|
||||||
var ctime2 int64 = 1623311102
|
|
||||||
var sort2 int64 = 2
|
|
||||||
sid2 := "abcd1235"
|
|
||||||
priceInfo2 := `[{"num":500,"price":0.1},{"num":1000,"price":0.06},{"num":1500,"price":0.06}]`
|
|
||||||
remark2 := ""
|
|
||||||
var num2 int64 = 50
|
|
||||||
|
|
||||||
var quotationId3 int64 = 2
|
|
||||||
name3 := "水壶"
|
|
||||||
size3 := "350ml,500ml,650ml"
|
|
||||||
var cycle3 int64 = 14
|
|
||||||
var isGift3 int64 = 0
|
|
||||||
img3 := "https://xxx.jpg"
|
|
||||||
var status3 int64 = 1
|
|
||||||
var ctime3 int64 = 1623311103
|
|
||||||
var sort3 int64 = 1
|
|
||||||
sid3 := "abcd1236"
|
|
||||||
priceInfo3 := `[{"num":500,"price":0.1},{"num":1000,"price":0.06},{"num":1500,"price":0.06}]`
|
|
||||||
remark3 := ""
|
|
||||||
var num3 int64 = 200
|
|
||||||
|
|
||||||
var quotationId4 int64 = 2
|
|
||||||
name4 := "手机壳"
|
|
||||||
size4 := "iPhoneX,iPhoneXS,iPhoneXR"
|
|
||||||
var cycle4 int64 = 5
|
|
||||||
var isGift4 int64 = 1
|
|
||||||
img4 := "https://xxx.jpg"
|
|
||||||
var status4 int64 = 1
|
|
||||||
var ctime4 int64 = 1623311104
|
|
||||||
var sort4 int64 = 2
|
|
||||||
sid4 := "abcd1237"
|
|
||||||
priceInfo4 := `[{"num":500,"price":0.1},{"num":1000,"price":0.06},{"num":1500,"price":0.06}]`
|
|
||||||
remark4 := "可定制颜料颜色"
|
|
||||||
var num4 int64 = 150
|
|
||||||
|
|
||||||
products := []*gmodel.FsQuotationProduct{
|
|
||||||
&gmodel.FsQuotationProduct{
|
|
||||||
Id: 1,
|
|
||||||
QuotationId: "ationId1,
|
|
||||||
Name: &name1,
|
|
||||||
Size: &size1,
|
|
||||||
Cycle: &cycle1,
|
|
||||||
IsGift: &isGift1,
|
|
||||||
Img: &img1,
|
|
||||||
Status: &status1,
|
|
||||||
Ctime: &ctime1,
|
|
||||||
Sort: &sort1,
|
|
||||||
Sid: &sid1,
|
|
||||||
PriceInfo: &priceInfo1,
|
|
||||||
Remark: &remark1,
|
|
||||||
Num: &num1,
|
|
||||||
},
|
|
||||||
&gmodel.FsQuotationProduct{
|
|
||||||
Id: 2,
|
|
||||||
QuotationId: "ationId2,
|
|
||||||
Name: &name2,
|
|
||||||
Size: &size2,
|
|
||||||
Cycle: &cycle2,
|
|
||||||
IsGift: &isGift2,
|
|
||||||
Img: &img2,
|
|
||||||
Status: &status2,
|
|
||||||
Ctime: &ctime2,
|
|
||||||
Sort: &sort2,
|
|
||||||
Sid: &sid2,
|
|
||||||
PriceInfo: &priceInfo2,
|
|
||||||
Remark: &remark2,
|
|
||||||
Num: &num2,
|
|
||||||
},
|
|
||||||
&gmodel.FsQuotationProduct{
|
|
||||||
Id: 3,
|
|
||||||
QuotationId: "ationId3,
|
|
||||||
Name: &name3,
|
|
||||||
Size: &size3,
|
|
||||||
Cycle: &cycle3,
|
|
||||||
IsGift: &isGift3,
|
|
||||||
Img: &img3,
|
|
||||||
Status: &status3,
|
|
||||||
Ctime: &ctime3,
|
|
||||||
Sort: &sort3,
|
|
||||||
Sid: &sid3,
|
|
||||||
PriceInfo: &priceInfo3,
|
|
||||||
Remark: &remark3,
|
|
||||||
Num: &num3,
|
|
||||||
},
|
|
||||||
&gmodel.FsQuotationProduct{
|
|
||||||
Id: 4,
|
|
||||||
QuotationId: "ationId4,
|
|
||||||
Name: &name4,
|
|
||||||
Size: &size4,
|
|
||||||
Cycle: &cycle4,
|
|
||||||
IsGift: &isGift4,
|
|
||||||
Img: &img4,
|
|
||||||
Status: &status4,
|
|
||||||
Ctime: &ctime4,
|
|
||||||
Sort: &sort4,
|
|
||||||
Sid: &sid4,
|
|
||||||
PriceInfo: &priceInfo4,
|
|
||||||
Remark: &remark4,
|
|
||||||
Num: &num4,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
return products
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTpl2(t *testing.T) {
|
|
||||||
|
|
||||||
products := Randomproduct()
|
|
||||||
|
|
||||||
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.Funcs(format.TemplateFuncMap)
|
|
||||||
tpl = template.Must(tpl.Parse(tplcontent))
|
|
||||||
buf := bytes.NewBufferString("")
|
|
||||||
|
|
||||||
tpl.Execute(buf, map[string]interface{}{"products": collect.StructSliceJson2Maps(products)})
|
|
||||||
html := buf.String()
|
|
||||||
log.Println(html)
|
|
||||||
}
|
|
|
@ -1,6 +1,7 @@
|
||||||
Name: product-model
|
Name: product-model
|
||||||
Host: localhost
|
Host: localhost
|
||||||
Port: 9909
|
Port: 9909
|
||||||
|
ReplicaId: 60
|
||||||
SourceMysql: "fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen"
|
SourceMysql: "fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen"
|
||||||
Log:
|
Log:
|
||||||
Stat: false
|
Stat: false
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
Name: product-template
|
Name: product-template
|
||||||
Host: localhost
|
Host: localhost
|
||||||
Port: 9910
|
Port: 9910
|
||||||
ReplicaId: 60
|
ReplicaId: 100
|
||||||
Timeout: 15000 #服务超时时间
|
Timeout: 15000 #服务超时时间
|
||||||
SourceMysql: "fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen"
|
SourceMysql: "fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen"
|
||||||
Log:
|
Log:
|
||||||
|
|
|
@ -1,34 +0,0 @@
|
||||||
syntax = "v1"
|
|
||||||
|
|
||||||
info (
|
|
||||||
title: // TODO: add title
|
|
||||||
desc: // TODO: add description
|
|
||||||
author: ""
|
|
||||||
email: ""
|
|
||||||
)
|
|
||||||
|
|
||||||
import "basic.api"
|
|
||||||
|
|
||||||
service backend {
|
|
||||||
// 报价单详情
|
|
||||||
@handler QuotationDetailHandler
|
|
||||||
get /api/quotation/detail(RequestQuotationId) returns (response);
|
|
||||||
|
|
||||||
@handler BackendUserLoginHandler
|
|
||||||
post /api/backend-user/login(RequestUserLogin) returns (response);
|
|
||||||
}
|
|
||||||
|
|
||||||
type RequestQuotationId {
|
|
||||||
QuotationId int64 `form:"id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// BackendUserLoginHandler 用户登录请求结构
|
|
||||||
type RequestUserLogin {
|
|
||||||
Name string `json:"name"`
|
|
||||||
Password string `json:"pwd"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// BackendUserLoginHandler 用户登录请求结构
|
|
||||||
type DataUserLogin {
|
|
||||||
Token string `json:"token"` // 登录jwt token
|
|
||||||
}
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"fusenapi/shared"
|
"fusenapi/shared"
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
|
@ -58,14 +57,9 @@ func ParseJwtToken(r *http.Request, svcCtx any) (*auth.UserInfo, error) {
|
||||||
var userinfo *auth.UserInfo
|
var userinfo *auth.UserInfo
|
||||||
var err error
|
var err error
|
||||||
// log.Println(io.ReadAll(r.Body))
|
// log.Println(io.ReadAll(r.Body))
|
||||||
token := r.Header.Get("Authorization")
|
// token := r.Header.Get("Authorization")
|
||||||
userId, err := strconv.ParseInt(token, 10, 64)
|
// userId, err := strconv.ParseInt(token, 10, 64)
|
||||||
|
|
||||||
if err == nil {
|
|
||||||
userinfo = &auth.UserInfo{
|
|
||||||
UserId: userId,
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
var secret uint64 = 0
|
var secret uint64 = 0
|
||||||
token, info, err := auth.ParseJwtTokenHeader[auth.UserInfo](r) //解析Token头, 和payload信息
|
token, info, err := auth.ParseJwtTokenHeader[auth.UserInfo](r) //解析Token头, 和payload信息
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -76,11 +70,17 @@ func ParseJwtToken(r *http.Request, svcCtx any) (*auth.UserInfo, error) {
|
||||||
if info != nil {
|
if info != nil {
|
||||||
if info.IsUser() {
|
if info.IsUser() {
|
||||||
// us, err := state.GetUserState(info.UserId) //获取缓存的用户状态
|
// us, err := state.GetUserState(info.UserId) //获取缓存的用户状态
|
||||||
reflect.ValueOf(svcCtx)
|
|
||||||
ctxValue := reflect.ValueOf(svcCtx).FieldByName("MysqlConn")
|
rsvcCtx := reflect.ValueOf(svcCtx)
|
||||||
|
if rsvcCtx.Kind() == reflect.Ptr {
|
||||||
|
rsvcCtx = rsvcCtx.Elem()
|
||||||
|
}
|
||||||
|
ctxValue := rsvcCtx.FieldByName("MysqlConn")
|
||||||
gdb := ctxValue.Interface().(*gorm.DB)
|
gdb := ctxValue.Interface().(*gorm.DB)
|
||||||
us, err := shared.GetUserState(info.UserId, gdb)
|
us, err := shared.GetUserState(info.UserId, gdb)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Println("error", info)
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,6 @@ func ParseJwtToken(r *http.Request, svcCtx any) (*auth.UserInfo, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if secret != 0 {
|
if secret != 0 {
|
||||||
log.Println("secret != 0", info)
|
|
||||||
claims, err := auth.ParseJwtTokenUint64Secret(token, secret)
|
claims, err := auth.ParseJwtTokenUint64Secret(token, secret)
|
||||||
// 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息
|
// 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -115,7 +114,6 @@ func ParseJwtToken(r *http.Request, svcCtx any) (*auth.UserInfo, error) {
|
||||||
// 白板用户
|
// 白板用户
|
||||||
userinfo = &auth.UserInfo{UserId: 0, GuestId: 0}
|
userinfo = &auth.UserInfo{UserId: 0, GuestId: 0}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return userinfo, nil
|
return userinfo, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user