208 lines
6.2 KiB
Go
208 lines
6.2 KiB
Go
package app_server
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
"git.rosy.net.cn/baseapi/utils"
|
|
"git.rosy.net.cn/jx-callback/business/model"
|
|
"git.rosy.net.cn/jx-print/dao"
|
|
tempModel "git.rosy.net.cn/jx-print/model/app_model"
|
|
"sort"
|
|
"time"
|
|
)
|
|
|
|
type TempServer struct {
|
|
}
|
|
|
|
// MakeSystemTempFontSmall 制作系统模板小字体
|
|
func (t *TempServer) MakeSystemTempFontSmall(param map[string]interface{}) (string, error) {
|
|
if len(param) <= 0 {
|
|
return "", errors.New("参数不能为空")
|
|
}
|
|
orderPrint := &JXPrintData{}
|
|
if err := utils.Map2StructByJson(param, orderPrint, false); err != nil {
|
|
return "", errors.New("参数不能为空")
|
|
}
|
|
// 头部模板,订单
|
|
var orderParams []interface{}
|
|
headTemp := tempBegin
|
|
orderParams = append(orderParams, orderPrint.EBailOrderNo, orderPrint.PayOrderTime, orderPrint.TrySendTime, orderPrint.OrderNo)
|
|
// 是否为预订单
|
|
if orderPrint.BusinessType == "2" {
|
|
headTemp += tempBusiness
|
|
}
|
|
|
|
// 订单来源信息
|
|
pickupTemp := tempBegin2
|
|
orderParams = append(orderParams, orderPrint.VendorName, orderPrint.VendorOrderNo, orderPrint.QRCOrder)
|
|
if orderPrint.VendorID == utils.Int2Str(tempModel.VendorIDEBAI) {
|
|
getCode := fmt.Sprintf(tempEBail, orderPrint.VendorName, orderPrint.EBaiCode)
|
|
pickupTemp += getCode
|
|
}
|
|
|
|
// 客户信息
|
|
userInfo := tempBegin3
|
|
orderParams = append(orderParams, orderPrint.ConsigneeName, orderPrint.ConsigneeMobile, orderPrint.ConsigneeAddress, orderPrint.BuyerComment)
|
|
|
|
// 商品信息
|
|
skuList := ""
|
|
for _, v := range orderPrint.SkuList {
|
|
sku := fmt.Sprintf(skuListTemp, v.SkuName, v.SkuCount, v.SalePrice, v.TotalCountPrice)
|
|
if v.Upc != "" {
|
|
sku += fmt.Sprintf(`<center>upc码:%s</center><br>`, v.Upc)
|
|
}
|
|
skuList += sku
|
|
}
|
|
|
|
// 统计信息
|
|
statInfo := tempEnd
|
|
orderParams = append(orderParams, orderPrint.AllSkuTypeCount, orderPrint.AllSkuCount, orderPrint.StoreName, orderPrint.StoreTel, orderPrint.OfficialName)
|
|
// 语音模板
|
|
soundTemp := fmt.Sprintf(soundTemp, "老板,你有新订单了")
|
|
orderFmt := soundTemp + pickupTemp + userInfo + skuList + statInfo
|
|
return fmt.Sprintf(orderFmt, orderParams), nil
|
|
}
|
|
|
|
// MakeSystemTempFontBig 制作系统模板大字体
|
|
func (t *TempServer) MakeSystemTempFontBig(param map[string]interface{}) (string, error) {
|
|
if len(param) <= 0 {
|
|
return "", errors.New("参数不能为空")
|
|
}
|
|
orderPrint := &JXPrintData{}
|
|
if err := utils.Map2StructByJson(param, orderPrint, false); err != nil {
|
|
return "", errors.New("参数不能为空")
|
|
}
|
|
// 头部模板,订单
|
|
var orderParams []interface{}
|
|
headTemp := tempBeginBig
|
|
orderParams = append(orderParams, orderPrint.EBailOrderNo, orderPrint.PayOrderTime, orderPrint.TrySendTime, orderPrint.OrderNo)
|
|
// 是否为预订单
|
|
if orderPrint.BusinessType == "2" {
|
|
headTemp += tempBusinessBig
|
|
}
|
|
|
|
// 订单来源信息
|
|
pickupTemp := tempBegin2Big
|
|
orderParams = append(orderParams, orderPrint.VendorName, orderPrint.VendorOrderNo, orderPrint.QRCOrder)
|
|
if orderPrint.VendorID == utils.Int2Str(model.VendorIDEBAI) {
|
|
getCode := fmt.Sprintf(tempEBailBig, orderPrint.VendorName, orderPrint.EBaiCode)
|
|
pickupTemp += getCode
|
|
}
|
|
|
|
// 客户信息
|
|
userInfo := tempBegin3Big
|
|
orderParams = append(orderParams, orderPrint.ConsigneeName, orderPrint.ConsigneeMobile, orderPrint.ConsigneeAddress, orderPrint.BuyerComment)
|
|
|
|
// 商品信息
|
|
skuList := ""
|
|
for _, v := range orderPrint.SkuList {
|
|
sku := fmt.Sprintf(skuListTempBig, v.SkuName, v.SkuCount, v.SalePrice, v.TotalCountPrice)
|
|
if v.Upc != "" {
|
|
sku += fmt.Sprintf(`<center>upc码:%s</center><br>`, v.Upc)
|
|
}
|
|
skuList += sku
|
|
}
|
|
|
|
// 统计信息
|
|
statInfo := tempEndBig
|
|
orderParams = append(orderParams, orderPrint.AllSkuTypeCount, orderPrint.AllSkuCount, orderPrint.StoreName, orderPrint.StoreTel, orderPrint.OfficialName)
|
|
// 语音模板
|
|
soundTemp := fmt.Sprintf(soundTemp, "老板,你有新订单了")
|
|
orderFmt := soundTemp + pickupTemp + userInfo + skuList + statInfo
|
|
return fmt.Sprintf(orderFmt, orderParams), nil
|
|
}
|
|
|
|
// AddOrUpdateTemp 添加或者修改模板
|
|
func (t *TempServer) AddOrUpdateTemp(param *tempModel.AddTemp) error {
|
|
temp, err := dao.GetTempByName(param.UserId, param.TempName)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if len(temp) > 0 {
|
|
return errors.New("模板名称重复")
|
|
}
|
|
|
|
// 解析模板
|
|
var tempTagList []*tempModel.TempContext
|
|
if err := json.Unmarshal([]byte(param.Temp), tempTagList); err != nil {
|
|
return err
|
|
}
|
|
sort.Slice(tempTagList, func(i, j int) bool {
|
|
if tempTagList[i].Rank > tempTagList[j].Rank {
|
|
return false
|
|
}
|
|
return true
|
|
})
|
|
|
|
rankKey := ""
|
|
contextStr := "{"
|
|
for i := 0; i < len(tempTagList); i++ {
|
|
if i != len(tempTagList)-1 {
|
|
key := tempTagList[i].MatchContext + ","
|
|
rankKey += key
|
|
} else {
|
|
rankKey += tempTagList[i].MatchContext
|
|
}
|
|
}
|
|
for i := 0; i < len(tempTagList); i++ {
|
|
if i != len(tempTagList)-1 {
|
|
contextStr += tempTagList[i].MatchContext + ":" + tempTagList[i].MatchContext + ","
|
|
} else {
|
|
contextStr += tempTagList[i].MatchContext + ":" + tempTagList[i].MatchContext + "}"
|
|
}
|
|
}
|
|
|
|
now := time.Now()
|
|
userTemp := &tempModel.SystemTemp{
|
|
TempName: param.TempName,
|
|
TempRank: rankKey,
|
|
Temp: contextStr,
|
|
UserId: param.UserId,
|
|
TempType: param.TempType,
|
|
TempSize: param.TempSize,
|
|
LastOperator: param.UserId,
|
|
DeletedAt: &utils.DefaultTimeValue,
|
|
PrintSn: param.PrintSn,
|
|
IsUse: param.IsUse,
|
|
}
|
|
|
|
// 如果默认打印改模板,其他打印模板则改成不使用
|
|
if param.IsUse == 1 {
|
|
if err := dao.UpdateOtherTempStatus(param.UserId); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
// 新增
|
|
if param.ID == 0 {
|
|
userTemp.CreatedAt = &now
|
|
userTemp.UpdatedAt = &now
|
|
return dao.AddTemp(userTemp)
|
|
}
|
|
|
|
// 修改
|
|
userTemp.UpdatedAt = &now
|
|
userTemp.ID = param.ID
|
|
return dao.UpdateTemp(userTemp, []string{"id"})
|
|
}
|
|
|
|
// DeleteTemp 删除模板
|
|
func (t *TempServer) DeleteTemp(id int, userId string) error {
|
|
return dao.DeleteTemp(id, userId)
|
|
}
|
|
|
|
// QueryTempList 查询用户模板
|
|
func (t *TempServer) QueryTempList(userId string) ([]*tempModel.SystemTemp, error) {
|
|
return dao.SelectUserTemp(userId)
|
|
}
|
|
|
|
// QuerySystemTemp 查询系统模板
|
|
func (t *TempServer) QuerySystemTemp() ([]*tempModel.SystemTemp, error) {
|
|
return dao.QuerySystemTemp()
|
|
}
|
|
|
|
// SwitchTemp 切换使用模板
|
|
func (t *TempServer) SwitchTemp(userId string, tempId int) error {
|
|
return dao.SwitchTemp2User(tempId, userId)
|
|
}
|