1
This commit is contained in:
@@ -5,136 +5,182 @@ import (
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/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
|
||||
// }
|
||||
//
|
||||
// now := time.Now()
|
||||
// param := &model.SystemTemp{
|
||||
// CreatedAt: &now,
|
||||
// UpdatedAt: &now,
|
||||
// LastOperator: "system",
|
||||
// DeletedAt: &utils.DefaultTimeValue,
|
||||
// TempName: "",
|
||||
// TempRank: model.SystemTempKey,
|
||||
// Temp: "",
|
||||
// UserId: "system_user",
|
||||
// TempType: model.TempTypeMerchant,
|
||||
// TempSize: model.SystemTempSizeBig,
|
||||
// PrintSn: "system",
|
||||
// IsUse: 1,
|
||||
// }
|
||||
//
|
||||
// // 初始化大字体模板
|
||||
// if _, v := temp[model.SystemTempSizeBig]; !v {
|
||||
// param.TempName = "system" + model.SystemTempSizeBig
|
||||
// param.Temp = model.SystemTempValue
|
||||
// if err := AddTemp(param); err != nil {
|
||||
// globals.SugarLogger.Debug("init system temp err :", err)
|
||||
// }
|
||||
// SystemTempObj[model.SystemTempSizeBig] = param
|
||||
// }
|
||||
//
|
||||
// // 初始化中字体模板
|
||||
// if _, v := temp[model.SystemTempSizeMedium]; !v {
|
||||
// param.TempName = "system" + model.SystemTempSizeMedium
|
||||
// medium := strings.Replace(model.SystemTempValue, "<b>", "<hb>", -1)
|
||||
// medium2 := strings.Replace(medium, "</b>", "</hb>", -1)
|
||||
// param.Temp = medium2
|
||||
// param.TempSize = model.SystemTempSizeMedium
|
||||
// param.IsUse = 2
|
||||
// if err := AddTemp(param); err != nil {
|
||||
// globals.SugarLogger.Debug("init system temp err :", err)
|
||||
// }
|
||||
// SystemTempObj[model.SystemTempSizeMedium] = param
|
||||
// }
|
||||
//
|
||||
// // 初始化小字体模板
|
||||
// if _, v := temp[model.SystemTempSizeSmall]; !v {
|
||||
// param.TempName = "system" + model.SystemTempSizeSmall
|
||||
// medium := strings.Replace(model.SystemTempValue, "<b>", " ", -1)
|
||||
// medium2 := strings.Replace(medium, "</b>", " ", -1)
|
||||
// param.Temp = medium2
|
||||
// param.TempSize = model.SystemTempSizeSmall
|
||||
// param.IsUse = 2
|
||||
// if err := AddTemp(param); err != nil {
|
||||
// globals.SugarLogger.Debug("init system temp err :", err)
|
||||
// }
|
||||
// SystemTempObj[model.SystemTempSizeSmall] = param
|
||||
// }
|
||||
//
|
||||
//}
|
||||
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,
|
||||
UpdatedAt: &now,
|
||||
LastOperator: "system",
|
||||
DeletedAt: &utils.DefaultTimeValue,
|
||||
TempName: "",
|
||||
TempRank: model.SystemTempKey,
|
||||
Temp: "",
|
||||
UserId: "system_user",
|
||||
TempType: model.TempTypeMerchant,
|
||||
TempSize: model.SystemTempSizeBig,
|
||||
PrintSn: "system",
|
||||
IsUse: 1,
|
||||
}
|
||||
|
||||
// 初始化大字体模板
|
||||
if _, v := temp[model.SystemTempSizeBig]; !v {
|
||||
param.TempName = "system" + model.SystemTempSizeBig
|
||||
param.Temp = model.SystemTempValue
|
||||
if err := AddTemp(param); err != nil {
|
||||
globals.SugarLogger.Debug("init system temp err :", err)
|
||||
}
|
||||
SystemTempObj[model.SystemTempSizeBig] = param
|
||||
}
|
||||
|
||||
// 初始化中字体模板
|
||||
if _, v := temp[model.SystemTempSizeMedium]; !v {
|
||||
param.TempName = "system" + model.SystemTempSizeMedium
|
||||
medium := strings.Replace(model.SystemTempValue, "<b>", "<hb>", -1)
|
||||
medium2 := strings.Replace(medium, "</b>", "</hb>", -1)
|
||||
param.Temp = medium2
|
||||
param.TempSize = model.SystemTempSizeMedium
|
||||
param.IsUse = 2
|
||||
if err := AddTemp(param); err != nil {
|
||||
globals.SugarLogger.Debug("init system temp err :", err)
|
||||
}
|
||||
SystemTempObj[model.SystemTempSizeMedium] = param
|
||||
}
|
||||
|
||||
// 初始化小字体模板
|
||||
if _, v := temp[model.SystemTempSizeSmall]; !v {
|
||||
param.TempName = "system" + model.SystemTempSizeSmall
|
||||
medium := strings.Replace(model.SystemTempValue, "<b>", " ", -1)
|
||||
medium2 := strings.Replace(medium, "</b>", " ", -1)
|
||||
param.Temp = medium2
|
||||
param.TempSize = model.SystemTempSizeSmall
|
||||
param.IsUse = 2
|
||||
if err := AddTemp(param); err != nil {
|
||||
globals.SugarLogger.Debug("init system temp err :", err)
|
||||
}
|
||||
SystemTempObj[model.SystemTempSizeSmall] = param
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MakePrintMsgOnTemp 将打印数据渲染到模板当中
|
||||
func MakePrintMsgOnTemp(param map[string]string, userId string) (string, error) {
|
||||
// 查询用户默认模板,不存在则使用系统默认模板
|
||||
var userTemp *model.SystemTemp
|
||||
userTemp, isHave, err := SelectUserDefaultTemp(userId, model.TempTypeMerchant)
|
||||
userTemp := &model.SystemTemp{}
|
||||
userTemp, isHave, err := SelectUserDefaultTemp(userId, model.TempTypeMerchantUser)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if userTemp == nil || !isHave {
|
||||
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" { // 是预订单
|
||||
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])
|
||||
}
|
||||
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)
|
||||
userTempMap := make(map[string]string, 0)
|
||||
if err := json.Unmarshal([]byte(userTemp.Temp), userTempMap); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
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 += userTempMap["skuName"]
|
||||
printMsg += userTempMap["skuNumber"]
|
||||
printMsg += userTempMap["skuPrice"]
|
||||
printMsg += userTempMap["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 += userTempMap[v]
|
||||
}
|
||||
default:
|
||||
printMsg += userTempMap[v]
|
||||
printValue = append(printValue, param[v])
|
||||
}
|
||||
|
||||
}
|
||||
return strings.Replace(fmt.Sprintf(strings.Replace(printMsg, "\n", "", -1), printValue...), "\\n", "\r\n", -1), nil
|
||||
}
|
||||
|
||||
return strings.Replace(fmt.Sprintf(strings.Replace(printMsg, "\n", "", -1), printValue...), "\\n", "\r\n", -1), nil
|
||||
return "", nil
|
||||
}
|
||||
|
||||
// MakePrintMsgOnTempVoice 制作平台语音
|
||||
|
||||
Reference in New Issue
Block a user