175 lines
5.0 KiB
Go
175 lines
5.0 KiB
Go
package model
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"git.rosy.net.cn/baseapi/utils"
|
|
"git.rosy.net.cn/jx-callback/globals"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
var SystemTempObj map[string]*SystemTemp
|
|
|
|
func init() {
|
|
SystemTempObj = make(map[string]*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]*SystemTemp, 0)
|
|
for _, v := range sysTempList {
|
|
temp[v.TempSize] = v
|
|
SystemTempObj[v.TempSize] = v
|
|
}
|
|
|
|
now := time.Now()
|
|
param := &SystemTemp{
|
|
CreatedAt: &now,
|
|
UpdatedAt: &now,
|
|
LastOperator: "system",
|
|
DeletedAt: &utils.DefaultTimeValue,
|
|
TempName: "",
|
|
TempRank: SystemTempKey,
|
|
Temp: "",
|
|
UserId: "system_user",
|
|
TempType: TempTypeMerchant,
|
|
TempSize: SystemTempSizeBig,
|
|
PrintSn: "system",
|
|
IsUse: 1,
|
|
}
|
|
|
|
// 初始化大字体模板
|
|
if _, v := temp[SystemTempSizeBig]; !v {
|
|
param.TempName = "system" + SystemTempSizeBig
|
|
param.Temp = SystemTempValue
|
|
if err := AddTemp(param); err != nil {
|
|
globals.SugarLogger.Debug("init system temp err :", err)
|
|
}
|
|
SystemTempObj[SystemTempSizeBig] = param
|
|
}
|
|
|
|
// 初始化中字体模板
|
|
if _, v := temp[SystemTempSizeMedium]; !v {
|
|
param.TempName = "system" + SystemTempSizeMedium
|
|
medium := strings.Replace(SystemTempValue, "<b>", "<hb>", -1)
|
|
medium2 := strings.Replace(medium, "</b>", "</hb>", -1)
|
|
param.Temp = medium2
|
|
param.TempSize = SystemTempSizeMedium
|
|
param.IsUse = 2
|
|
if err := AddTemp(param); err != nil {
|
|
globals.SugarLogger.Debug("init system temp err :", err)
|
|
}
|
|
SystemTempObj[SystemTempSizeMedium] = param
|
|
}
|
|
|
|
// 初始化小字体模板
|
|
if _, v := temp[SystemTempSizeSmall]; !v {
|
|
param.TempName = "system" + SystemTempSizeSmall
|
|
medium := strings.Replace(SystemTempValue, "<b>", " ", -1)
|
|
medium2 := strings.Replace(medium, "</b>", " ", -1)
|
|
param.Temp = medium2
|
|
param.TempSize = SystemTempSizeSmall
|
|
param.IsUse = 2
|
|
if err := AddTemp(param); err != nil {
|
|
globals.SugarLogger.Debug("init system temp err :", err)
|
|
}
|
|
SystemTempObj[SystemTempSizeSmall] = param
|
|
}
|
|
|
|
}
|
|
|
|
// MakePrintMsgOnTemp 将打印数据渲染到模板当中
|
|
func MakePrintMsgOnTemp(param map[string]string, userId string) (string, error) {
|
|
// 查询用户默认模板,不存在则使用系统默认模板
|
|
var userTemp *SystemTemp
|
|
userTemp, isHave, err := SelectUserDefaultTemp(userId, TempTypeMerchant)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
if userTemp == nil || !isHave {
|
|
userTemp = SystemTempObj[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 += TempTag[v]
|
|
skuList := make([]*SkuListPrintOrder, 0, 0)
|
|
if err := json.Unmarshal([]byte(param[v]), skuList); err != nil {
|
|
return "", err
|
|
}
|
|
for i := 0; i < len(skuList); i++ {
|
|
printMsg += TempTag["skuName"]
|
|
printMsg += TempTag["skuNumber"]
|
|
printMsg += TempTag["skuPrice"]
|
|
printMsg += TempTag["skuAllPrice"]
|
|
printValue = append(printValue, skuList[i].SkuName, skuList[i].SkuName, skuList[i].SalePrice, skuList[i].TotalCountPrice)
|
|
if skuList[i].Upc != "" {
|
|
printMsg += TempTag["sku"]
|
|
printValue = append(printValue, skuList[i].Upc)
|
|
}
|
|
|
|
}
|
|
case "businessType":
|
|
if param[v] == "2" { // 是预订单
|
|
printMsg += TempTag[v]
|
|
}
|
|
default:
|
|
printMsg += TempTag[v]
|
|
printValue = append(printValue, param[v])
|
|
}
|
|
|
|
}
|
|
|
|
return strings.Replace(fmt.Sprintf(strings.Replace(printMsg, "\n", "", -1), printValue...), "\\n", "\r\n", -1), nil
|
|
}
|
|
|
|
// MakePrintMsgOnTempVoice 制作平台语音
|
|
func MakePrintMsgOnTempVoice(param map[string]string, setting *PrintSettingObj, userId string) (string, error) {
|
|
printVoiceMsg := ""
|
|
printVoiceValue := make([]interface{}, 0, 0)
|
|
// 称谓设置/平台语音设置
|
|
if (setting.CallNameSetting == 64 || setting.CallNameSetting == 65 || setting.CallNameSetting == 66) && setting.SystemVoice == SettingClose {
|
|
// 老板
|
|
printVoiceMsg += `<sound>%s</sound>`
|
|
printVoiceValue = append(printVoiceValue, setting.CallNameSetting)
|
|
}
|
|
|
|
// 打印机提示音设置(暂时不做)
|
|
|
|
textMsg := ""
|
|
switch param["orderStatus"] {
|
|
case "3", "5", "10": // 新订单
|
|
// 订单设置
|
|
if setting.OrderVoiceSetting.PrintOrder == SettingOpen { // 打印订单
|
|
textMsg, err := MakePrintMsgOnTemp(param, userId)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
}
|
|
if setting.OrderVoiceSetting.OrderNotice == SettingOpen { // 订单通知
|
|
printVoiceMsg += `<sound>%s</sound>` // 你来新订单了
|
|
if param[]
|
|
printVoiceValue = append(printVoiceValue, NewOrderVoice)
|
|
}
|
|
|
|
case "15": // 待拣货
|
|
case "110": // 送达
|
|
case "120": // 收货,好像没有
|
|
|
|
}
|
|
|
|
}
|