修改打印
This commit is contained in:
@@ -5,182 +5,180 @@ 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
|
||||
}
|
||||
|
||||
}
|
||||
//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
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
||||
// MakePrintMsgOnTemp 将打印数据渲染到模板当中
|
||||
func MakePrintMsgOnTemp(param map[string]string, userId string) (string, error) {
|
||||
// 查询用户默认模板,不存在则使用系统默认模板
|
||||
userTemp := &model.SystemTemp{}
|
||||
userTemp, isHave, err := SelectUserDefaultTemp(userId, model.TempTypeMerchantUser)
|
||||
userTemp, _, 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 {
|
||||
// 需要打印数据
|
||||
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
|
||||
//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 {
|
||||
// 需要打印数据
|
||||
printMsg := ""
|
||||
printValue := make([]interface{}, 0, 0)
|
||||
userTempMap := make(map[string]string, 0)
|
||||
if err := json.Unmarshal([]byte(userTemp.Temp), userTempMap); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
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 制作平台语音
|
||||
|
||||
@@ -5,19 +5,20 @@ import (
|
||||
)
|
||||
|
||||
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"`
|
||||
UpdatedAt *time.Time `json:"updated_at" db:"updated_at"`
|
||||
LastOperator string `json:"last_operator" db:"last_operator"`
|
||||
DeletedAt *time.Time `json:"deleted_at" db:"deleted_at"`
|
||||
TempName string `json:"temp_name" db:"temp_name"` // 模板名称
|
||||
TempRank string `orm:"type(text)" json:"temp_rank" db:"temp_rank"` // 模板顺序
|
||||
Temp string `orm:"type(text)" json:"temp" db:"temp"` // 模板
|
||||
UserId string `json:"user_id" db:"user_id"` // 所属用户
|
||||
TempType string `json:"temp_type" db:"temp_type"` // 模板类型
|
||||
TempSize string `json:"temp_size" db:"temp_size"` // 模板尺寸 big/medium/small
|
||||
PrintSn string `json:"print_sn" db:"print_sn"` // 模板所属打印机
|
||||
IsUse int `json:"is_use" db:"is_use"` // 默认使用 1-使用/2-不使用
|
||||
TempName string `json:"temp_name" db:"temp_name"` // 模板名称
|
||||
TempRank string `json:"temp_rank" db:"temp_rank"` // 模板顺序
|
||||
Temp string `json:"temp" db:"temp"` // 模板
|
||||
UserId string `json:"user_id" db:"user_id"` // 所属用户
|
||||
TempType string `json:"temp_type" db:"temp_type"` // 模板类型 user_store/user_consumer
|
||||
TempSize string `json:"temp_size" db:"temp_size"` // 模板尺寸 big/medium/small
|
||||
PrintSn string `json:"print_sn" db:"print_sn"` // 模板所属打印机
|
||||
IsUse int `json:"is_use" db:"is_use"` // 默认使用 1-使用/2-不使用
|
||||
Properties string `json:"properties" db:"properties"` // 模板字段属性
|
||||
}
|
||||
|
||||
//func (v *SystemTemp) TableUnique() [][]string {
|
||||
|
||||
Reference in New Issue
Block a user