1
This commit is contained in:
@@ -6,110 +6,142 @@ import (
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-print/dao"
|
||||
"git.rosy.net.cn/jx-print/globals"
|
||||
tempModel "git.rosy.net.cn/jx-print/model/app_model"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var SystemTemp map[string]*tempModel.SystemTemp
|
||||
|
||||
func init() {
|
||||
SystemTemp = make(map[string]*tempModel.SystemTemp, 0)
|
||||
var sysTemp = TempServer{}
|
||||
sysTempList, err := sysTemp.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]*tempModel.SystemTemp, 0)
|
||||
for _, v := range sysTempList {
|
||||
temp[v.TempSize] = v
|
||||
SystemTemp[v.TempSize] = v
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
param := &tempModel.SystemTemp{
|
||||
CreatedAt: &now,
|
||||
UpdatedAt: &now,
|
||||
LastOperator: "system",
|
||||
DeletedAt: &utils.DefaultTimeValue,
|
||||
TempName: "",
|
||||
TempRank: SystemTempKey,
|
||||
Temp: "",
|
||||
UserId: "system_user",
|
||||
TempType: tempModel.TempTypeMerchant,
|
||||
TempSize: tempModel.SystemTempSizeBig,
|
||||
PrintSn: "system",
|
||||
IsUse: 1,
|
||||
}
|
||||
|
||||
// 初始化大字体模板
|
||||
if _, v := temp[tempModel.SystemTempSizeBig]; !v {
|
||||
param.TempName = "system" + tempModel.SystemTempSizeBig
|
||||
param.Temp = SystemTempValue
|
||||
if err := dao.AddTemp(param); err != nil {
|
||||
globals.SugarLogger.Debug("init system temp err :", err)
|
||||
}
|
||||
SystemTemp[tempModel.SystemTempSizeBig] = param
|
||||
}
|
||||
|
||||
// 初始化中字体模板
|
||||
if _, v := temp[tempModel.SystemTempSizeMedium]; !v {
|
||||
param.TempName = "system" + tempModel.SystemTempSizeMedium
|
||||
medium := strings.Replace(SystemTempValue, "<b>", "<hb>", -1)
|
||||
medium2 := strings.Replace(medium, "</b>", "</hb>", -1)
|
||||
param.Temp = medium2
|
||||
param.TempSize = tempModel.SystemTempSizeMedium
|
||||
param.IsUse = 2
|
||||
if err := dao.AddTemp(param); err != nil {
|
||||
globals.SugarLogger.Debug("init system temp err :", err)
|
||||
}
|
||||
SystemTemp[tempModel.SystemTempSizeMedium] = param
|
||||
}
|
||||
|
||||
// 初始化小字体模板
|
||||
if _, v := temp[tempModel.SystemTempSizeSmall]; !v {
|
||||
param.TempName = "system" + tempModel.SystemTempSizeSmall
|
||||
medium := strings.Replace(SystemTempValue, "<b>", " ", -1)
|
||||
medium2 := strings.Replace(medium, "</b>", " ", -1)
|
||||
param.Temp = medium2
|
||||
param.TempSize = tempModel.SystemTempSizeSmall
|
||||
param.IsUse = 2
|
||||
if err := dao.AddTemp(param); err != nil {
|
||||
globals.SugarLogger.Debug("init system temp err :", err)
|
||||
}
|
||||
SystemTemp[tempModel.SystemTempSizeSmall] = param
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
type TempServer struct {
|
||||
}
|
||||
|
||||
// MakeSystemTempFontSmall 制作系统模板小字体
|
||||
func (t *TempServer) MakeSystemTempFontSmall(param map[string]interface{}) (string, error) {
|
||||
if len(param) <= 0 {
|
||||
return "", errors.New("参数不能为空")
|
||||
// MakePrintMsgOnTemp 将打印数据渲染到模板当中
|
||||
func (t *TempServer) MakePrintMsgOnTemp(param map[string]string, userId string) (string, error) {
|
||||
// 查询用户默认模板,不存在则使用系统默认模板
|
||||
var userTemp *tempModel.SystemTemp
|
||||
userTemp, isHave, err := dao.SelectUserDefaultTemp(userId, tempModel.TempTypeMerchant)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
orderPrint := &JXPrintData{}
|
||||
if err := utils.Map2StructByJson(param, orderPrint, false); err != nil {
|
||||
return "", errors.New("参数不能为空")
|
||||
}
|
||||
// 头部模板,订单
|
||||
var orderParams []interface{}
|
||||
headTemp := tempBegin
|
||||
orderParams = append(orderParams, orderPrint.EBailOrderNo, orderPrint.PayOrderTime, orderPrint.TrySendTime, orderPrint.OrderNo)
|
||||
// 是否为预订单
|
||||
if orderPrint.BusinessType == "2" {
|
||||
headTemp += tempBusiness
|
||||
if userTemp == nil || !isHave {
|
||||
userTemp = SystemTemp[tempModel.SystemTempSizeBig]
|
||||
}
|
||||
|
||||
// 订单来源信息
|
||||
pickupTemp := tempBegin2
|
||||
orderParams = append(orderParams, orderPrint.VendorName, orderPrint.VendorOrderNo, orderPrint.QRCOrder)
|
||||
if orderPrint.VendorID == utils.Int2Str(tempModel.VendorIDEBAI) {
|
||||
getCode := fmt.Sprintf(tempEBail, orderPrint.VendorName, orderPrint.EBaiCode)
|
||||
pickupTemp += getCode
|
||||
}
|
||||
// 需要打印数据
|
||||
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)
|
||||
}
|
||||
|
||||
// 客户信息
|
||||
userInfo := tempBegin3
|
||||
orderParams = append(orderParams, orderPrint.ConsigneeName, orderPrint.ConsigneeMobile, orderPrint.ConsigneeAddress, orderPrint.BuyerComment)
|
||||
|
||||
// 商品信息
|
||||
skuList := ""
|
||||
for _, v := range orderPrint.SkuList {
|
||||
sku := fmt.Sprintf(skuListTemp, v.SkuName, v.SkuCount, v.SalePrice, v.TotalCountPrice)
|
||||
if v.Upc != "" {
|
||||
sku += fmt.Sprintf(`<center>upc码:%s</center><br>`, v.Upc)
|
||||
}
|
||||
case "businessType":
|
||||
if param[v] == "2" { // 是预订单
|
||||
printMsg += TempTag[v]
|
||||
}
|
||||
default:
|
||||
printMsg += TempTag[v]
|
||||
printValue = append(printValue, param[v])
|
||||
}
|
||||
skuList += sku
|
||||
|
||||
}
|
||||
|
||||
// 统计信息
|
||||
statInfo := tempEnd
|
||||
orderParams = append(orderParams, orderPrint.AllSkuTypeCount, orderPrint.AllSkuCount, orderPrint.StoreName, orderPrint.StoreTel, orderPrint.OfficialName)
|
||||
// 语音模板
|
||||
soundTemp := fmt.Sprintf(soundTemp, "老板,你有新订单了")
|
||||
orderFmt := soundTemp + pickupTemp + userInfo + skuList + statInfo
|
||||
return fmt.Sprintf(orderFmt, orderParams), nil
|
||||
}
|
||||
|
||||
// MakeSystemTempFontBig 制作系统模板大字体
|
||||
func (t *TempServer) MakeSystemTempFontBig(param map[string]interface{}) (string, error) {
|
||||
if len(param) <= 0 {
|
||||
return "", errors.New("参数不能为空")
|
||||
}
|
||||
orderPrint := &JXPrintData{}
|
||||
if err := utils.Map2StructByJson(param, orderPrint, false); err != nil {
|
||||
return "", errors.New("参数不能为空")
|
||||
}
|
||||
// 头部模板,订单
|
||||
var orderParams []interface{}
|
||||
headTemp := tempBeginBig
|
||||
orderParams = append(orderParams, orderPrint.EBailOrderNo, orderPrint.PayOrderTime, orderPrint.TrySendTime, orderPrint.OrderNo)
|
||||
// 是否为预订单
|
||||
if orderPrint.BusinessType == "2" {
|
||||
headTemp += tempBusinessBig
|
||||
}
|
||||
|
||||
// 订单来源信息
|
||||
pickupTemp := tempBegin2Big
|
||||
orderParams = append(orderParams, orderPrint.VendorName, orderPrint.VendorOrderNo, orderPrint.QRCOrder)
|
||||
if orderPrint.VendorID == utils.Int2Str(tempModel.VendorIDEBAI) {
|
||||
getCode := fmt.Sprintf(tempEBailBig, orderPrint.VendorName, orderPrint.EBaiCode)
|
||||
pickupTemp += getCode
|
||||
}
|
||||
|
||||
// 客户信息
|
||||
userInfo := tempBegin3Big
|
||||
orderParams = append(orderParams, orderPrint.ConsigneeName, orderPrint.ConsigneeMobile, orderPrint.ConsigneeAddress, orderPrint.BuyerComment)
|
||||
|
||||
// 商品信息
|
||||
skuList := ""
|
||||
for _, v := range orderPrint.SkuList {
|
||||
sku := fmt.Sprintf(skuListTempBig, v.SkuName, v.SkuCount, v.SalePrice, v.TotalCountPrice)
|
||||
if v.Upc != "" {
|
||||
sku += fmt.Sprintf(`<center>upc码:%s</center><br>`, v.Upc)
|
||||
}
|
||||
skuList += sku
|
||||
}
|
||||
|
||||
// 统计信息
|
||||
statInfo := tempEndBig
|
||||
orderParams = append(orderParams, orderPrint.AllSkuTypeCount, orderPrint.AllSkuCount, orderPrint.StoreName, orderPrint.StoreTel, orderPrint.OfficialName)
|
||||
// 语音模板
|
||||
soundTemp := fmt.Sprintf(soundTemp, "老板,你有新订单了")
|
||||
orderFmt := soundTemp + pickupTemp + userInfo + skuList + statInfo
|
||||
return fmt.Sprintf(orderFmt, orderParams), nil
|
||||
return strings.Replace(fmt.Sprintf(strings.Replace(printMsg, "\n", "", -1), printValue...), "\\n", "\r\n", -1), nil
|
||||
}
|
||||
|
||||
// AddOrUpdateTemp 添加或者修改模板
|
||||
|
||||
Reference in New Issue
Block a user