This commit is contained in:
邹宗楠
2022-08-22 09:37:57 +08:00
parent 0349b56a6f
commit fec30ce3e7

View File

@@ -5,30 +5,31 @@ import (
"fmt"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-print/globals"
"strings"
"time"
)
//var SystemTempObj map[string]*model.SystemTemp
//
//func init() {
// SystemTempObj = make(map[string]*model.SystemTemp, 0)
// sysTempList, err := QuerySystemTemp()
// if err != nil {
// globals.SugarLogger.Debug("query system temp err :", err)
// return
// }
// if len(sysTempList) <= 0 {
// globals.SugarLogger.Debug("query system temp err :", "system temp don't have")
// // 不存在系统模板,初始化系统模板
// //InitSystemTemp()
// }
// temp := make(map[string]*model.SystemTemp, 0)
// for _, v := range sysTempList {
// temp[v.TempSize] = v
// SystemTempObj[v.TempSize] = v
// }
//
var SystemTempObj map[string]*model.SystemTemp
func init() {
SystemTempObj = make(map[string]*model.SystemTemp, 0)
sysTempList, err := QuerySystemTemp()
if err != nil {
globals.SugarLogger.Debug("query system temp err :", err)
return
}
if len(sysTempList) <= 0 {
globals.SugarLogger.Debug("query system temp err :", "system temp don't have")
// 不存在系统模板,初始化系统模板
//InitSystemTemp()
}
temp := make(map[string]*model.SystemTemp, 0)
for _, v := range sysTempList {
temp[v.TempSize] = v
SystemTempObj[v.TempSize] = v
}
//now := time.Now()
//param := &model.SystemTemp{
// CreatedAt: &now,
@@ -44,8 +45,8 @@ import (
// PrintSn: "system",
// IsUse: 1,
//}
//
// // 初始化大字体模板
// 初始化大字体模板
//if _, v := temp[model.SystemTempSizeBig]; !v {
// param.TempName = "system" + model.SystemTempSizeBig
// param.Temp = model.SystemTempValue
@@ -54,8 +55,8 @@ import (
// }
// SystemTempObj[model.SystemTempSizeBig] = param
//}
//
// // 初始化中字体模板
// 初始化中字体模板
//if _, v := temp[model.SystemTempSizeMedium]; !v {
// param.TempName = "system" + model.SystemTempSizeMedium
// medium := strings.Replace(model.SystemTempValue, "<b>", "<hb>", -1)
@@ -68,8 +69,8 @@ import (
// }
// SystemTempObj[model.SystemTempSizeMedium] = param
//}
//
// // 初始化小字体模板
// 初始化小字体模板
//if _, v := temp[model.SystemTempSizeSmall]; !v {
// param.TempName = "system" + model.SystemTempSizeSmall
// medium := strings.Replace(model.SystemTempValue, "<b>", " ", -1)
@@ -82,60 +83,60 @@ import (
// }
// SystemTempObj[model.SystemTempSizeSmall] = param
//}
//
//}
}
// MakePrintMsgOnTemp 将打印数据渲染到模板当中
func MakePrintMsgOnTemp(param map[string]string, userId string) (string, error) {
// 查询用户默认模板,不存在则使用系统默认模板
userTemp := &model.SystemTemp{}
userTemp, _, err := SelectUserDefaultTemp(userId, model.TempTypeMerchantUser)
userTemp, isHave, err := SelectUserDefaultTemp(userId, model.TempTypeMerchantUser)
if err != nil {
return "", err
}
//if userTemp == nil || !isHave || userTemp.TempType == model.TempTypeMerchant {
// if userTemp.TempType != "" {
// userTemp = SystemTempObj[userTemp.TempSize]
// } else {
// userTemp = SystemTempObj[model.SystemTempSizeBig]
// }
// // 需要打印数据
// printMsg := ""
// printValue := make([]interface{}, 0, 0)
// for _, v := range strings.Split(userTemp.TempRank, ",") {
// switch v {
// case "skuName", "skuNumber", "skuPrice", "skuAllPrice", "allSkuTypeCount", "allSkuCount":
// continue
// case "goodsListDetail":
// printMsg += model.TempTag[v]
// skuList := make([]*model.SkuListPrintOrder, 0, 0)
// if err := json.Unmarshal([]byte(param[v]), skuList); err != nil {
// return "", err
// }
// for i := 0; i < len(skuList); i++ {
// printMsg += model.TempTag["skuName"]
// printMsg += model.TempTag["skuNumber"]
// printMsg += model.TempTag["skuPrice"]
// printMsg += model.TempTag["skuAllPrice"]
// printValue = append(printValue, skuList[i].SkuName, skuList[i].SkuName, skuList[i].SalePrice, skuList[i].TotalCountPrice)
// if skuList[i].Upc != "" {
// printMsg += model.TempTag["sku"]
// printValue = append(printValue, skuList[i].Upc)
// }
//
// }
// case "businessType":
// if param[v] == "2" { // 是预订单
// printMsg += model.TempTag[v]
// }
// default:
// printMsg += model.TempTag[v]
// printValue = append(printValue, param[v])
// }
//
// }
// return strings.Replace(fmt.Sprintf(strings.Replace(printMsg, "\n", "", -1), printValue...), "\\n", "\r\n", -1), nil
//} else {
if userTemp == nil || !isHave {
if userTemp.TempType != "" {
userTemp = SystemTempObj[userTemp.TempSize]
} else {
userTemp = SystemTempObj[model.SystemTempSizeBig]
}
// 需要打印数据
printMsg := ""
printValue := make([]interface{}, 0, 0)
for _, v := range strings.Split(userTemp.TempRank, ",") {
switch v {
case "skuName", "skuNumber", "skuPrice", "skuAllPrice", "allSkuTypeCount", "allSkuCount":
continue
case "goodsListDetail":
printMsg += model.TempTag[v]
skuList := make([]*model.SkuListPrintOrder, 0, 0)
if err := json.Unmarshal([]byte(param[v]), skuList); err != nil {
return "", err
}
for i := 0; i < len(skuList); i++ {
printMsg += model.TempTag["skuName"]
printMsg += model.TempTag["skuNumber"]
printMsg += model.TempTag["skuPrice"]
printMsg += model.TempTag["skuAllPrice"]
printValue = append(printValue, skuList[i].SkuName, skuList[i].SkuName, skuList[i].SalePrice, skuList[i].TotalCountPrice)
if skuList[i].Upc != "" {
printMsg += model.TempTag["sku"]
printValue = append(printValue, skuList[i].Upc)
}
}
case "businessType":
if param[v] == "2" { // 是预订单
printMsg += model.TempTag[v]
}
default:
printMsg += model.TempTag[v]
printValue = append(printValue, param[v])
}
}
return strings.Replace(fmt.Sprintf(strings.Replace(printMsg, "\n", "", -1), printValue...), "\\n", "\r\n", -1), nil
} else {
// 需要打印数据
printMsg := ""
printValue := make([]interface{}, 0, 0)
@@ -177,8 +178,7 @@ func MakePrintMsgOnTemp(param map[string]string, userId string) (string, error)
}
return strings.Replace(fmt.Sprintf(strings.Replace(printMsg, "\n", "", -1), printValue...), "\\n", "\r\n", -1), nil
//}
//return "", nil
}
}
// MakePrintMsgOnTempVoice 制作平台语音