修改打印

This commit is contained in:
邹宗楠
2022-08-19 11:08:52 +08:00
parent 75ad109b81
commit c25bdc27f7
2 changed files with 170 additions and 171 deletions

View File

@@ -5,182 +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-callback/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, isHave, err := SelectUserDefaultTemp(userId, model.TempTypeMerchantUser) userTemp, _, 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 || userTemp.TempType == model.TempTypeMerchant {
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++ { // for i := 0; i < len(skuList); i++ {
printMsg += model.TempTag["skuName"] // printMsg += model.TempTag["skuName"]
printMsg += model.TempTag["skuNumber"] // printMsg += model.TempTag["skuNumber"]
printMsg += model.TempTag["skuPrice"] // printMsg += model.TempTag["skuPrice"]
printMsg += model.TempTag["skuAllPrice"] // printMsg += model.TempTag["skuAllPrice"]
printValue = append(printValue, skuList[i].SkuName, skuList[i].SkuName, skuList[i].SalePrice, skuList[i].TotalCountPrice) // printValue = append(printValue, skuList[i].SkuName, skuList[i].SkuName, skuList[i].SalePrice, skuList[i].TotalCountPrice)
if skuList[i].Upc != "" { // if skuList[i].Upc != "" {
printMsg += model.TempTag["sku"] // printMsg += model.TempTag["sku"]
printValue = append(printValue, skuList[i].Upc) // printValue = append(printValue, skuList[i].Upc)
} // }
//
} // }
case "businessType": // case "businessType":
if param[v] == "2" { // 是预订单 // if param[v] == "2" { // 是预订单
printMsg += model.TempTag[v] // printMsg += model.TempTag[v]
} // }
default: // default:
printMsg += model.TempTag[v] // printMsg += model.TempTag[v]
printValue = append(printValue, param[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
} else { //} else {
// 需要打印数据 // 需要打印数据
printMsg := "" printMsg := ""
printValue := make([]interface{}, 0, 0) printValue := make([]interface{}, 0, 0)
userTempMap := make(map[string]string, 0) userTempMap := make(map[string]string, 0)
if err := json.Unmarshal([]byte(userTemp.Temp), userTempMap); err != nil { if err := json.Unmarshal([]byte(userTemp.Temp), userTempMap); err != nil {
return "", err 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 "", nil 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 "", nil
} }
// MakePrintMsgOnTempVoice 制作平台语音 // MakePrintMsgOnTempVoice 制作平台语音

View File

@@ -5,19 +5,20 @@ import (
) )
type SystemTemp struct { type SystemTemp struct {
ID int `orm:"column(id)" json:"id" db:"id"` ID int `json:"id" db:"id"`
CreatedAt *time.Time `json:"created_at" db:"created_at"` CreatedAt *time.Time `json:"created_at" db:"created_at"`
UpdatedAt *time.Time `json:"updated_at" db:"updated_at"` UpdatedAt *time.Time `json:"updated_at" db:"updated_at"`
LastOperator string `json:"last_operator" db:"last_operator"` LastOperator string `json:"last_operator" db:"last_operator"`
DeletedAt *time.Time `json:"deleted_at" db:"deleted_at"` DeletedAt *time.Time `json:"deleted_at" db:"deleted_at"`
TempName string `json:"temp_name" db:"temp_name"` // 模板名称 TempName string `json:"temp_name" db:"temp_name"` // 模板名称
TempRank string `orm:"type(text)" json:"temp_rank" db:"temp_rank"` // 模板顺序 TempRank string `json:"temp_rank" db:"temp_rank"` // 模板顺序
Temp string `orm:"type(text)" json:"temp" db:"temp"` // 模板 Temp string `json:"temp" db:"temp"` // 模板
UserId string `json:"user_id" db:"user_id"` // 所属用户 UserId string `json:"user_id" db:"user_id"` // 所属用户
TempType string `json:"temp_type" db:"temp_type"` // 模板类型 TempType string `json:"temp_type" db:"temp_type"` // 模板类型 user_store/user_consumer
TempSize string `json:"temp_size" db:"temp_size"` // 模板尺寸 big/medium/small TempSize string `json:"temp_size" db:"temp_size"` // 模板尺寸 big/medium/small
PrintSn string `json:"print_sn" db:"print_sn"` // 模板所属打印机 PrintSn string `json:"print_sn" db:"print_sn"` // 模板所属打印机
IsUse int `json:"is_use" db:"is_use"` // 默认使用 1-使用/2-不使用 IsUse int `json:"is_use" db:"is_use"` // 默认使用 1-使用/2-不使用
Properties string `json:"properties" db:"properties"` // 模板字段属性
} }
//func (v *SystemTemp) TableUnique() [][]string { //func (v *SystemTemp) TableUnique() [][]string {