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