1
This commit is contained in:
@@ -305,3 +305,12 @@ func connHandler(c net.Conn, printInfo *PrintInfo) (status int) {
|
|||||||
fmt.Println("server response:", string(buf[:n]))
|
fmt.Println("server response:", string(buf[:n]))
|
||||||
return status
|
return status
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//#region 打印机拼装模板
|
||||||
|
|
||||||
|
// QueryPrinterSetting 查询用户设置
|
||||||
|
func QueryPrinterSetting() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//#endregion 打印机
|
||||||
|
|||||||
@@ -5,6 +5,30 @@ import (
|
|||||||
"git.rosy.net.cn/jx-callback/business/model"
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// QueryUserPrinter 查询用户打印机
|
||||||
|
func QueryUserPrinter(userId, printNo string) (*model.Printer, error) {
|
||||||
|
sql := `
|
||||||
|
SELECT *
|
||||||
|
FROM printer
|
||||||
|
WHERE 1 = 1 AND deleted_at = ?
|
||||||
|
`
|
||||||
|
sqlParams := []interface{}{
|
||||||
|
utils.DefaultTimeValue,
|
||||||
|
}
|
||||||
|
|
||||||
|
if printNo != "" {
|
||||||
|
sql += " AND print_no = ?"
|
||||||
|
sqlParams = append(sqlParams, printNo)
|
||||||
|
}
|
||||||
|
if userId != "" {
|
||||||
|
sql += " AND user_id = ?"
|
||||||
|
sqlParams = append(sqlParams, userId)
|
||||||
|
}
|
||||||
|
var printer = &model.Printer{}
|
||||||
|
err := GetRow(GetDB(), &printer, sql, sqlParams)
|
||||||
|
return printer, err
|
||||||
|
}
|
||||||
|
|
||||||
func GetPrinters(db *DaoDB, appID int, printNo string, status, statusNeq int) (printers []*model.Printer, err error) {
|
func GetPrinters(db *DaoDB, appID int, printNo string, status, statusNeq int) (printers []*model.Printer, err error) {
|
||||||
sql := `
|
sql := `
|
||||||
SELECT *
|
SELECT *
|
||||||
|
|||||||
@@ -1,10 +1,16 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import "time"
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
// PrintSetting 打印机设置
|
// PrintSetting 打印机设置
|
||||||
type PrintSetting struct {
|
type PrintSetting 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"`
|
||||||
DeletedAt time.Time `json:"deleted_at" db:"deleted_at"`
|
DeletedAt time.Time `json:"deleted_at" db:"deleted_at"`
|
||||||
@@ -25,10 +31,19 @@ func (v *PrintSetting) TableUnique() [][]string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *PrintSetting) TableIndex() [][]string {
|
type PrintSettingObj struct {
|
||||||
return [][]string{
|
ID int
|
||||||
[]string{"CreatedAt"},
|
CreatedAt time.Time
|
||||||
}
|
UpdatedAt time.Time
|
||||||
|
DeletedAt time.Time
|
||||||
|
PrintNo string // 打印机编号
|
||||||
|
CallNameSetting int // 称谓设置 [64-默认老板]
|
||||||
|
SystemVoice int // 平台语音开关[1打开]
|
||||||
|
PrintVoiceSetting *PrintVoice // 打印机提示语音设置
|
||||||
|
OrderVoiceSetting *OrderVoice // 订单提示设置
|
||||||
|
RiderVoiceSetting *RiderVoice // 骑手动态提示设置
|
||||||
|
CustomerVoiceSetting *CustomerReceivingGoods // 客户收货提示设置
|
||||||
|
PickingSetting *ShopPickingVoice // 拣货语音设置
|
||||||
}
|
}
|
||||||
|
|
||||||
// PrintVoice 打印机提示语音设置
|
// PrintVoice 打印机提示语音设置
|
||||||
@@ -79,14 +94,75 @@ type ShopPickingVoice struct {
|
|||||||
WaitPickingVoice int `json:"wait_picking_voice"` // 待接单语音[1打开]
|
WaitPickingVoice int `json:"wait_picking_voice"` // 待接单语音[1打开]
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddPrintSetting 打印机设置添加
|
func GetPrintSetting(printNo string) (*PrintSettingObj, error) {
|
||||||
type AddPrintSetting struct {
|
sql := ` SELECT * FROM print_setting WHERE print_no = ? and deleted_at = ? `
|
||||||
PrintNo string `json:"print_no" form:"print_no" binding:"required"`
|
sqlParams := []interface{}{
|
||||||
CallNameSetting int `json:"call_name_setting" form:"call_name_setting"`
|
printNo,
|
||||||
SystemVoice int `json:"system_voice" form:"system_voice"`
|
utils.DefaultTimeValue,
|
||||||
PrintVoiceSetting *PrintVoice
|
}
|
||||||
OrderVoiceSetting *OrderVoice
|
|
||||||
RiderVoiceSetting *RiderVoice
|
var printSetting *PrintSetting
|
||||||
CustomerVoiceSetting *CustomerReceivingGoods
|
if err := dao.GetRows(dao.GetDB(), &printSetting, sql, sqlParams...); err != nil {
|
||||||
PickingSetting *ShopPickingVoice
|
return nil, err
|
||||||
|
}
|
||||||
|
if printSetting == nil {
|
||||||
|
return nil, errors.New("数据查询异常")
|
||||||
|
}
|
||||||
|
|
||||||
|
return UnMarshalString2Json(printSetting)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 将打印机设置转换一下
|
||||||
|
|
||||||
|
// UnMarshalString2Json 将字符串设置转换为对象设置
|
||||||
|
func UnMarshalString2Json(param *PrintSetting) (*PrintSettingObj, error) {
|
||||||
|
var (
|
||||||
|
printVoiceSetting = &PrintVoice{}
|
||||||
|
orderVoiceSetting = &OrderVoice{}
|
||||||
|
riderVoiceSetting = &RiderVoice{}
|
||||||
|
customerVoiceSetting = &CustomerReceivingGoods{}
|
||||||
|
pickingSetting = &ShopPickingVoice{}
|
||||||
|
)
|
||||||
|
|
||||||
|
result := &PrintSettingObj{
|
||||||
|
ID: param.ID,
|
||||||
|
CreatedAt: param.CreatedAt,
|
||||||
|
UpdatedAt: param.UpdatedAt,
|
||||||
|
DeletedAt: param.DeletedAt,
|
||||||
|
PrintNo: param.PrintNo,
|
||||||
|
CallNameSetting: param.CallNameSetting,
|
||||||
|
SystemVoice: param.SystemVoice,
|
||||||
|
PrintVoiceSetting: nil,
|
||||||
|
OrderVoiceSetting: nil,
|
||||||
|
RiderVoiceSetting: nil,
|
||||||
|
CustomerVoiceSetting: nil,
|
||||||
|
PickingSetting: nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := json.Unmarshal([]byte(param.PrintVoiceSetting), printVoiceSetting); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
result.PrintVoiceSetting = printVoiceSetting
|
||||||
|
|
||||||
|
if err := json.Unmarshal([]byte(param.OrderVoiceSetting), orderVoiceSetting); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
result.OrderVoiceSetting = orderVoiceSetting
|
||||||
|
|
||||||
|
if err := json.Unmarshal([]byte(param.RiderVoiceSetting), riderVoiceSetting); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
result.RiderVoiceSetting = riderVoiceSetting
|
||||||
|
|
||||||
|
if err := json.Unmarshal([]byte(param.CustomerVoiceSetting), customerVoiceSetting); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
result.CustomerVoiceSetting = customerVoiceSetting
|
||||||
|
|
||||||
|
if err := json.Unmarshal([]byte(param.PickingSetting), pickingSetting); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
result.PickingSetting = pickingSetting
|
||||||
|
|
||||||
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import "time"
|
import (
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
type SystemTemp struct {
|
type SystemTemp struct {
|
||||||
ID int `orm:"column(id)" json:"id" db:"id"`
|
ID int `orm:"column(id)" json:"id" db:"id"`
|
||||||
@@ -30,3 +34,43 @@ func (v *SystemTemp) TableIndex() [][]string {
|
|||||||
[]string{"PrintSn"},
|
[]string{"PrintSn"},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
TempTypeMerchantUser = `user_store` // 商户自定义模板-商户看
|
||||||
|
TempTypeConsumerUser = `user_consumer` // 商户自定义模板-消费用户看
|
||||||
|
TempTypeMerchant = `sys_store` // 系统模板-商户看
|
||||||
|
TempTypeConsumer = `sys_consumer` // 系统模板-消费用户看
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
SystemTempSizeBig = "big"
|
||||||
|
SystemTempSizeSmall = "small"
|
||||||
|
SystemTempSizeMedium = "medium"
|
||||||
|
)
|
||||||
|
const (
|
||||||
|
SettingOpen = 1 // 开启
|
||||||
|
SettingClose = -1 // 关闭
|
||||||
|
)
|
||||||
|
|
||||||
|
// SelectUserDefaultTemp 查询用户默认模板
|
||||||
|
func SelectUserDefaultTemp(userId string, tempType string) (*SystemTemp, bool, error) {
|
||||||
|
var result *SystemTemp
|
||||||
|
if err := dao.GetRow(dao.GetDB(), &result, `SELECT * FROM system_temp WHERE user_id = ? AND temp_type = ? AND is_use = ? AND deleted_at = ? ORDER BY created_at desc `, []interface{}{userId, tempType, 1, utils.DefaultTimeValue}...); err != nil {
|
||||||
|
return nil, false, err
|
||||||
|
}
|
||||||
|
return result, true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// QuerySystemTemp 查询系统模板
|
||||||
|
func QuerySystemTemp() ([]*SystemTemp, error) {
|
||||||
|
var result []*SystemTemp
|
||||||
|
if err := dao.GetRows(dao.GetDB(), &result, `SELECT * FROM system_temp WHERE user_id = ? ORDER BY created_at desc `, []interface{}{"system_user"}...); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddTemp 添加模板数据
|
||||||
|
func AddTemp(param *SystemTemp) error {
|
||||||
|
return dao.CreateEntity(dao.GetDB(), param)
|
||||||
|
}
|
||||||
|
|||||||
149
business/model/print_temp_config.go
Normal file
149
business/model/print_temp_config.go
Normal file
@@ -0,0 +1,149 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
var TempTag map[string]string
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
TempTag = make(map[string]string, 26)
|
||||||
|
TempTag["title"] = Title
|
||||||
|
TempTag["sound"] = Sound
|
||||||
|
TempTag["eBailOrderNo"] = EBailOrderNo
|
||||||
|
TempTag["payOrderTime"] = PayOrderTime
|
||||||
|
TempTag["trySendTime"] = TrySendTime
|
||||||
|
TempTag["orderNo"] = OrderNo
|
||||||
|
TempTag["businessType"] = BusinessType
|
||||||
|
TempTag["vendorName"] = VendorName
|
||||||
|
TempTag["eBaiCode"] = EBaiCode
|
||||||
|
TempTag["qRCOrder"] = QRCOrder
|
||||||
|
TempTag["eBaiVendorName"] = EBaiVendorName
|
||||||
|
TempTag["eBaiOrderNo"] = EBaiOrderNo
|
||||||
|
TempTag["consigneeName"] = ConsigneeName
|
||||||
|
TempTag["consigneeMobile"] = ConsigneeMobile
|
||||||
|
TempTag["consigneeAddress"] = ConsigneeAddress
|
||||||
|
TempTag["buyerComment"] = BuyerComment
|
||||||
|
TempTag["goodsListDetail"] = GoodsListDetail
|
||||||
|
TempTag["skuName"] = SkuName
|
||||||
|
TempTag["skuNumber"] = SkuNumber
|
||||||
|
TempTag["skuPrice"] = SkuPrice
|
||||||
|
TempTag["skuAllPrice"] = SkuAllPrice
|
||||||
|
TempTag["allSkuTypeCount"] = AllSkuTypeCount
|
||||||
|
TempTag["allSkuCount"] = AllSkuCount
|
||||||
|
TempTag["storeName"] = StoreName
|
||||||
|
TempTag["storeTel"] = StoreTel
|
||||||
|
TempTag["officialName"] = OfficialName
|
||||||
|
}
|
||||||
|
|
||||||
|
// SystemTempKey 系统数据库模板排序
|
||||||
|
const (
|
||||||
|
//SystemTempKey 公共参数 EBaiOrderNo= vendorName EBaiVendorName = vendorOrderNo
|
||||||
|
SystemTempKey = "title,sound,eBailOrderNo,payOrderTime,trySendTime,orderNo,businessType,vendorName,eBaiCode,qRCOrder,eBaiVendorName,eBaiOrderNo,consigneeName," +
|
||||||
|
"consigneeMobile,consigneeAddress,buyerComment,goodsListDetail,skuName,skuNumber,skuPrice,skuAllPrice,skuUpc,allSkuTypeCount,allSkuCount,storeName,storeTel,officialName"
|
||||||
|
SystemTempValue = "{" +
|
||||||
|
"title:" + Title + "," +
|
||||||
|
"sound:" + Sound + "," +
|
||||||
|
"eBailOrderNo:" + EBailOrderNo + "," +
|
||||||
|
"payOrderTime:" + PayOrderTime + "," +
|
||||||
|
"trySendTime:" + TrySendTime + "," +
|
||||||
|
"orderNo:" + OrderNo + "," +
|
||||||
|
"businessType:" + BusinessType + "," +
|
||||||
|
"vendorName:" + VendorName + "," +
|
||||||
|
"eBaiCode:" + EBaiCode + "," +
|
||||||
|
"qRCOrder:" + QRCOrder + "," +
|
||||||
|
"eBaiVendorName:" + EBaiVendorName + "," +
|
||||||
|
"eBaiOrderNo:" + EBaiOrderNo + "," +
|
||||||
|
"consigneeName:" + ConsigneeName + "," +
|
||||||
|
"consigneeMobile:" + ConsigneeMobile + "," +
|
||||||
|
"consigneeAddress:" + ConsigneeAddress + "," +
|
||||||
|
"buyerComment:" + BuyerComment + "," +
|
||||||
|
"goodsListDetail:" + GoodsListDetail + "," +
|
||||||
|
"skuName:" + SkuName + "," +
|
||||||
|
"skuNumber:" + SkuNumber + "," +
|
||||||
|
"skuPrice:" + SkuPrice + "," +
|
||||||
|
"skuAllPrice:" + SkuAllPrice + "," +
|
||||||
|
"skuUpc:" + SkuUpc + "," +
|
||||||
|
"allSkuTypeCount:" + AllSkuTypeCount + "," +
|
||||||
|
"allSkuCount:" + AllSkuCount + "," +
|
||||||
|
"storeName:" + StoreName + "," +
|
||||||
|
"storeTel:" + StoreTel + "," +
|
||||||
|
"officialName:" + OfficialName +
|
||||||
|
"}"
|
||||||
|
|
||||||
|
Title = `<center>手机买菜上京西</center><br>
|
||||||
|
<center>极速到家送惊喜</center><br>
|
||||||
|
--------------------------------<br>`
|
||||||
|
|
||||||
|
Sound = `<br><sound>%s</sound><br>`
|
||||||
|
EBailOrderNo = `<center><b>%s</b></center><br><br>`
|
||||||
|
PayOrderTime = ` <b>下单时间: %s</b><br>`
|
||||||
|
TrySendTime = ` <b>预计送达: %s</b><br>`
|
||||||
|
OrderNo = ` <b>订单编号: %s</b><br>`
|
||||||
|
BusinessType = `<center><b>预订单</b></center><br>`
|
||||||
|
|
||||||
|
VendorName = `<br><b>%s`
|
||||||
|
EBaiCode = `#%s</b><br>`
|
||||||
|
|
||||||
|
QRCOrder = `<qrc>%s</qrc><br>`
|
||||||
|
EBaiVendorName = `<b>%s:`
|
||||||
|
EBaiOrderNo = `%s</b><br><br>`
|
||||||
|
ConsigneeName = ` <b>客户: %s<br>`
|
||||||
|
ConsigneeMobile = ` <b>电话: %s<br>`
|
||||||
|
ConsigneeAddress = ` <b>地址: %s<br><br>`
|
||||||
|
|
||||||
|
BuyerComment = ` <b>客户备注:</b><br><b>%s</b><br><br>`
|
||||||
|
GoodsListDetail = `商品明细:<br>
|
||||||
|
品名 数量 单价 小计<br>
|
||||||
|
--------------------------------<br>`
|
||||||
|
|
||||||
|
SkuName = `<b>%s</b><br>`
|
||||||
|
SkuNumber = `<b>x%s</b>`
|
||||||
|
SkuPrice = ` <b>¥%s</b>`
|
||||||
|
SkuAllPrice = ` <b>¥%s</b><br>`
|
||||||
|
SkuUpc = `upc码: %s\n`
|
||||||
|
|
||||||
|
AllSkuTypeCount = `<br><br><b>共%s种,`
|
||||||
|
AllSkuCount = `%s件商品</b><br>--------------------------------<br>`
|
||||||
|
|
||||||
|
StoreName = `<center><b>商品质量问题请联系:</b></center><br><center><b>%s:`
|
||||||
|
StoreTel = `%s</b></center><br><br>更多信息请关注官方微信: `
|
||||||
|
|
||||||
|
OfficialName = `<b>%s</b><br><br><br>
|
||||||
|
--------------------------------<br>
|
||||||
|
--------------------------------<br><br>`
|
||||||
|
)
|
||||||
|
|
||||||
|
type SkuListPrintOrder struct {
|
||||||
|
SkuName string `json:"skuName"` // 商品名称
|
||||||
|
SkuCount string `json:"skuCount"` // 商品数量
|
||||||
|
SalePrice string `json:"salePrice"` // 单价
|
||||||
|
TotalCountPrice string `json:"totalCountPrice"` // 总价
|
||||||
|
Upc string `json:"upc"` // 条形码
|
||||||
|
}
|
||||||
|
|
||||||
|
type JXPrintData struct {
|
||||||
|
EBailOrderNo string `json:"e_bail_order_no"` // 饿百取货码(品牌名称)
|
||||||
|
BusinessType string `json:"business_type"` // 是否为预定单 2-是/1-否
|
||||||
|
PayOrderTime string `json:"pay_order_time"` // 下单时间
|
||||||
|
TrySendTime string `json:"try_send_time"` // 预计送达时间
|
||||||
|
OrderNo string `json:"order_no"` // 订单编号
|
||||||
|
VendorName string `json:"vendor_name"` // 订单来源平台名称
|
||||||
|
VendorID string `json:"vendor_id"` // 订单来源平台Id
|
||||||
|
VendorOrderNo string `json:"vendor_order_no"` // 订单序号
|
||||||
|
EBaiCode string `json:"e_bai_code"` // 饿百取货码
|
||||||
|
QRCOrder string `json:"qrc_order"` // 订单二维码单号,还是订单Id
|
||||||
|
ConsigneeName string `json:"consignee_name"` // 客户名称
|
||||||
|
ConsigneeMobile string `json:"consignee_mobile"` // 客户电话
|
||||||
|
ConsigneeAddress string `json:"consignee_address"` // 客户地址
|
||||||
|
BuyerComment string `json:"buyer_comment"` // 客户备注
|
||||||
|
SkuList []*SkuListPrintOrder `json:"sku_list"` // 商品列表
|
||||||
|
SkuName string `json:"sku_name"` // 商品名称
|
||||||
|
SkuCount string `json:"sku_count"` // 商品件数
|
||||||
|
SkuOnePrice string `json:"sku_one_price"` // 商品单价
|
||||||
|
SkuAllPrice string `json:"sku_all_price"` // 商品总价 = 商品件数 x 商品件数
|
||||||
|
AllSkuTypeCount string `json:"all_sku_type_count"` // 商品种类
|
||||||
|
AllSkuCount string `json:"all_sku_count"` // 商品总数量
|
||||||
|
UserPayMoney string `json:"user_pay_money"` // 用户支付
|
||||||
|
StoreName string `json:"store_name"` // 门店名称
|
||||||
|
StoreTel string `json:"store_tel"` // 门店电话
|
||||||
|
OfficialName string `json:"official_name"` // 官方名称
|
||||||
|
BigFont string `json:"big_font"` // 是否为大字体
|
||||||
|
PrintNumber string `json:"print_number"` // 打印次数
|
||||||
|
}
|
||||||
158
business/model/print_temp_utils.go
Normal file
158
business/model/print_temp_utils.go
Normal file
@@ -0,0 +1,158 @@
|
|||||||
|
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, setting *PrintSettingObj) (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)
|
||||||
|
if (setting.CallNameSetting == 64 || setting.CallNameSetting == 65 || setting.CallNameSetting == 66) && setting.SystemVoice == SettingOpen {
|
||||||
|
printMsg += `<sound>%s</sound>`
|
||||||
|
printValue = append(printValue, setting.CallNameSetting)
|
||||||
|
}
|
||||||
|
|
||||||
|
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(setting *PrintSettingObj) string {
|
||||||
|
// 关闭平台语音模板
|
||||||
|
if setting.SystemVoice == SettingClose {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
printMsg := ""
|
||||||
|
printValue := make([]interface{}, 0, 0)
|
||||||
|
if setting.CallNameSetting == 64 || setting.CallNameSetting == 65 || setting.CallNameSetting == 66 {
|
||||||
|
printMsg += `<sound>%s</sound>`
|
||||||
|
printValue = append(printValue, setting.CallNameSetting)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -341,6 +341,25 @@ func (c *ApiController) DoPrint(dataMap map[string]interface{}) (data, errCode s
|
|||||||
|
|
||||||
appID = utils.Str2Int(dataMap[keyAppID].(string))
|
appID = utils.Str2Int(dataMap[keyAppID].(string))
|
||||||
msgID := time.Now().Format("20060102150405") + "_" + jxutils.RandStringBytes(8)
|
msgID := time.Now().Format("20060102150405") + "_" + jxutils.RandStringBytes(8)
|
||||||
|
|
||||||
|
// 打印文件转结构体
|
||||||
|
contentMap := make(map[string]string)
|
||||||
|
if err := json.Unmarshal([]byte(content), contentMap); err != nil {
|
||||||
|
return "", model.ErrCodeGeneralFailed, err
|
||||||
|
}
|
||||||
|
// 查询打印机设置
|
||||||
|
printSetting, err := model.GetPrintSetting(printNo)
|
||||||
|
if err != nil {
|
||||||
|
return "", model.ErrCodeGeneralFailed, err
|
||||||
|
}
|
||||||
|
printObj, err := dao.QueryUserPrinter("", printNo)
|
||||||
|
if err != nil {
|
||||||
|
return "", model.ErrCodeGeneralFailed, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询用户模板
|
||||||
|
model.MakePrintMsgOnTemp(contentMap, printObj.UserId, printSetting)
|
||||||
|
|
||||||
if err = cms.DoPrint(appID, msgID, printNo, content, orderNo); err != nil {
|
if err = cms.DoPrint(appID, msgID, printNo, content, orderNo); err != nil {
|
||||||
return "", model.ErrCodeGeneralFailed, err
|
return "", model.ErrCodeGeneralFailed, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user