package xpyun

import (
	"fmt"
	"strings"
	"time"

	"git.rosy.net.cn/baseapi/utils"
	"git.rosy.net.cn/jx-callback/business/jxutils"

	"git.rosy.net.cn/baseapi/platformapi/xpyunapi"
	"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
	"git.rosy.net.cn/jx-callback/business/model"
	"git.rosy.net.cn/jx-callback/business/model/dao"
	"git.rosy.net.cn/jx-callback/business/partner"
	"git.rosy.net.cn/jx-callback/globals"
	"git.rosy.net.cn/jx-callback/globals/api"
)

var (
	CurPrinterHandler *PrinterHandler
)

type PrinterHandler struct {
}

func init() {
	CurPrinterHandler = new(PrinterHandler)
	partner.RegisterPrinterPlatform(CurPrinterHandler)
}
func (c *PrinterHandler) GetVendorID() int {
	return model.VendorIDXpYun
}
func (c *PrinterHandler) PrintMsg(ctx *jxcontext.Context, sn, copies, voiceType, msgContent string) (printerStatus *partner.PrinterStatus, err error) {
	if sn != "" {
		//if globals.EnableStoreWrite {
		printOrderID, err1 := api.XpyunAPI.Print(&xpyunapi.PrintRequest{
			Sn:        sn,
			Content:   msgContent,
			Copies:    1,
			Voice:     utils.Str2Int(voiceType),
			Mode:      xpyunapi.ModeCheckYes,
			ExpiresIn: xpyunapi.ExpiresInDefault,
		})
		if err1 == nil && printOrderID != "" {
			printerStatus, err = c.GetPrinterStatus(ctx, sn, "")
		}
		//}
	}
	//else {
	//	printerStatus = &partner.PrinterStatus{
	//		PrintResult: partner.PrintResultNoPrinter,
	//	}
	//}
	return printerStatus, err
}

func (c *PrinterHandler) GetPrinterStatus(ctx *jxcontext.Context, sn, s string) (printerStatus *partner.PrinterStatus, err error) {
	if status, err := api.XpyunAPI.QueryPrinterStatus(sn); err == nil {
		printerStatus = &partner.PrinterStatus{
			PrintResult: partner.PrintResultSuccess,
		}
		tempStatus := utils.Float64TwoInt(status.(float64))
		if tempStatus == xpyunapi.PrinterStateOffline {
			printerStatus.PrinterStatus = partner.PrinterStatusOffline
		} else if tempStatus == xpyunapi.PrinterStateOnlineNormal {
			printerStatus.PrinterStatus = partner.PrinterStatusOnlineOK
		} else if tempStatus == xpyunapi.PrinterStateOnlineUnusual {
			printerStatus.PrinterStatus = partner.PrinterStatusOnlineAbnormal
		} else {
			printerStatus.PrinterStatus = partner.PrinterStatusUnknown
		}
	}
	return printerStatus, err
}

func (c *PrinterHandler) RegisterPrinter(ctx *jxcontext.Context, sn, id2, printerName string, soreId int64) (newID1, newID2 string, err error) {
	if globals.EnableStoreWrite {
		err = api.XpyunAPI.AddPrinters(sn, printerName)
	}
	if strings.Contains(err.Error(), "打印机已存在") {
		return "", "", nil
	}
	return "", "", err
}

func (c *PrinterHandler) UnregisterPrinter(ctx *jxcontext.Context, sn, id2 string) (err error) {
	if globals.EnableStoreWrite {
		err = api.XpyunAPI.DelPrinters([]string{sn})
	}
	return err
}

func (c *PrinterHandler) BindPrinter(ctx *jxcontext.Context, mapData map[string]interface{}) (bindResult *partner.BindPrinterResult, err error) {
	return nil, fmt.Errorf("%s打印机当前不支持扫码绑定", model.VendorChineseNames[model.VendorIDXpYun])
}

func (c *PrinterHandler) RebindPrinter(ctx *jxcontext.Context, lastBindResult *partner.BindPrinterResult) (bindResult *partner.BindPrinterResult, err error) {
	return nil, fmt.Errorf("%s打印机当前不支持扫码解绑", model.VendorChineseNames[model.VendorIDXpYun])
}

func (c *PrinterHandler) PrintOrder(ctx *jxcontext.Context, store *model.Store, storeDetail *dao.StoreDetail, order *model.GoodsOrder, printType string, asfOrder *model.AfsOrder) (printerStatus *partner.PrinterStatus, err error) {
	if len(order.Skus) == 0 {
		return
	}
	content := ""
	if store.PrinterFontSize == partner.PrinterFontSizeBig || store.PrinterFontSize == partner.PrinterFontSizeBig2 {
		//content = c.getOrderContentBig(order, store.Tel1, storeDetail)
		content = c.getOrderContentBigV2(order, store.Tel1, storeDetail)
	} else {
		//content = c.getOrderContent(order, store.Tel1, storeDetail)
		content = c.getOrderContentV2(order, store.Tel1, storeDetail)
	}
	count := 0
	for {
		printerStatus, err := c.PrintMsg(ctx, store.PrinterSN, "", utils.Int2Str(xpyunapi.VoicePlayOrder), content)
		if (store.PrinterFontSize == partner.PrinterFontSizeBig2 || store.PrinterFontSize == partner.PrinterFontSizeNormal2) && count < 1 {
			count += 1
			continue
		} else {
			return printerStatus, err
		}
	}
}

func (c *PrinterHandler) PrintStore(ctx *jxcontext.Context, store *model.Store, storeDetail *dao.StoreDetail, vendorId int) (printerStatus *partner.PrinterStatus, err error) {
	return nil, err
}

func (c *PrinterHandler) PrintCancelOrRefundOrder(ctx *jxcontext.Context, printType int, store *model.Store, storeDetail *dao.StoreDetail, order *model.GoodsOrder) (printerStatus *partner.PrinterStatus, err error) {
	if len(order.Skus) == 0 {
		return
	}
	content := ""
	voiceType := ""
	if printType == model.YES { // 取消订单
		voiceType = utils.Int2Str(xpyunapi.VoiceCancelOrder)
	} else { // 售后订单
		voiceType = utils.Int2Str(xpyunapi.VoiceUserChargeback)
	}
	if store.PrinterFontSize == partner.PrinterFontSizeBig || store.PrinterFontSize == partner.PrinterFontSizeBig2 {
		content = c.getCancelOrRefundOrderContent(order, printType, storeDetail)
	} else {
		content = c.getCancelOrRefundOrderContentBig(order, printType, storeDetail)
	}
	if content == "" {
		return nil, nil
	}

	return c.PrintMsg(ctx, store.PrinterSN, "", voiceType, content)
}

func (c *PrinterHandler) EmptyPrintList(ctx *jxcontext.Context, sn, id2 string) (err error) {
	if globals.EnableStoreWrite {
		err = api.XpyunAPI.EmptyPrinterQueue(sn)
	}
	return err
}

func (c *PrinterHandler) PlayText(ctx *jxcontext.Context, id1, id2, orderID, text string) (printerStatus *partner.PrinterStatus, err error) {
	return nil, err
}

func (c *PrinterHandler) SetSound(ctx *jxcontext.Context, sn, id2, sound string) (err error) {
	if globals.EnableStoreWrite {
		err = api.XpyunAPI.SetVoiceType(sn, utils.Str2Int(sound))
	}
	return err
}

//不包含价格版本
func (c *PrinterHandler) getOrderContentV2(order *model.GoodsOrder, storeTel string, storeDetail *dao.StoreDetail) (content string) {
	expectedDeliveryTime := order.ExpectedDeliveredTime
	if utils.IsTimeZero(expectedDeliveryTime) {
		expectedDeliveryTime = order.OrderCreatedAt.Add(1 * time.Hour)
	}
	getCode := ""
	if order.VendorID == model.VendorIDEBAI {
		getCode = fmt.Sprintf("<CB>淘宝闪购取货码:%s</CB>", jxutils.GetEbaiOrderGetCode(order))
	}
	if order.BuyerComment == "" {
		order.BuyerComment = "客户电话: " + order.ConsigneeMobile + ",配送遇到问题,可联系18048531223取消配送单,禁止未配送直接完成订单!"
	}
	orderParams := []interface{}{}
	orderFmt := ``
	if storeDetail != nil {
		if storeDetail.BrandIsPrint == model.NO {
			orderFmt += `<C><B>%s</B><C>`
			if order.VendorOrgCode == "34665" {
				orderParams = append(orderParams, globals.StoreNameEbai2)
			} else {
				orderParams = append(orderParams, storeDetail.BrandName)
			}
		}
	}
	if order.BusinessType == model.BusinessTypeDingshida {
		orderFmt += `<C><B>预订单</B><C>`
	} else {
		orderFmt += `<C><B>立即送达</B><C>`
	}
	orderFmt += `
` + xpyunapi.StrRepeat("-", 32) + `
<L>下单时间: %s
<L>预计送达: %s
<L>客户姓名: %s
<L>客户电话: %s<BR>
<HB>订单编号: %s</HB><BR>
<CB>%s#%d
<C><QRCODE s=6 e=L l=center>%s</QRCODE></C></CB>
` + getCode +
		xpyunapi.StrRepeat("-", 32) + `
<HB>客户地址: %s</HB>
` + xpyunapi.StrRepeat("-", 32) + `客户备注: %s
` + xpyunapi.StrRepeat("-", 32) + `
商品列表
商品名` + xpyunapi.StrRepeat(" ", 20) + `数量<BR>` + xpyunapi.StrRepeat("-", 32)
	orderParams = append(orderParams,
		utils.Time2Str(order.OrderCreatedAt),
		utils.Time2Str(expectedDeliveryTime),
		order.ConsigneeName,
		order.ConsigneeMobile,
		order.VendorOrderID,
		jxutils.GetVendorName(order.VendorID),
		order.OrderSeq,
		order.VendorOrderID,
		order.ConsigneeAddress,
		order.BuyerComment,
	)

	for k, sku := range order.Skus {
		orderFmt += xpyunapi.FormatPrintOrderItemV2(sku.SkuName, sku.Count, k+1)
	}
	orderFmt += `<BR><HB><L>共%d种%d件商品</L></HB>`
	orderFmt += `<BR>`
	orderFmt += "<HB>" + xpyunapi.StrRepeat("-", 14) + "#%d完" + xpyunapi.StrRepeat("-", 13) + `</HB><BR><BR>`
	orderParams = append(orderParams, order.SkuCount, order.GoodsCount, order.OrderSeq)
	return fmt.Sprintf(orderFmt, orderParams...)
}

func (c *PrinterHandler) getOrderContentBigV2(order *model.GoodsOrder, storeTel string, storeDetail *dao.StoreDetail) (content string) {
	expectedDeliveryTime := order.ExpectedDeliveredTime
	if utils.IsTimeZero(expectedDeliveryTime) {
		expectedDeliveryTime = order.OrderCreatedAt.Add(1 * time.Hour)
	}
	getCode := ""
	if order.VendorID == model.VendorIDEBAI {
		getCode = fmt.Sprintf("<CB>淘宝闪购取货码:%s</CB>", jxutils.GetEbaiOrderGetCode(order))
	}
	if order.BuyerComment == "" {
		order.BuyerComment = "客户电话: " + order.ConsigneeMobile + ",配送遇到问题,可联系18048531223取消配送单,禁止未配送直接完成订单!"
	}
	orderParams := []interface{}{}
	orderFmt := ``
	if storeDetail != nil {
		if storeDetail.BrandIsPrint == model.NO {
			orderFmt += `<C><B>%s</B><C>`
			if order.VendorOrgCode == "34665" {
				orderParams = append(orderParams, globals.StoreNameEbai2)
			} else {
				orderParams = append(orderParams, storeDetail.BrandName)
			}
		}
	}
	if order.BusinessType == model.BusinessTypeDingshida {
		orderFmt += `<C><B>预订单</B><C>`
	} else {
		orderFmt += `<C><B>立即送达</B><C>`
	}
	orderFmt += `
` + xpyunapi.StrRepeat("-", 32) + `
<HB><L>下单时间: %s
<L>预计送达: %s
<L>客户姓名: %s
<L>客户电话: %s</HB><BR>
<HB>订单编号: %s</HB><BR>
<CB>%s#%d
<C><QRCODE s=6 e=L l=center>%s</QRCODE></C></CB>
` + getCode +
		xpyunapi.StrRepeat("-", 32) + `
<HB>客户地址: %s</HB>
` + xpyunapi.StrRepeat("-", 32) + `客户备注: %s
` + xpyunapi.StrRepeat("-", 32) + `
商品列表
商品名` + xpyunapi.StrRepeat(" ", 20) + `数量<BR>` + xpyunapi.StrRepeat("-", 32)
	orderParams = append(orderParams,
		utils.Time2Str(order.OrderCreatedAt),
		utils.Time2Str(expectedDeliveryTime),
		order.ConsigneeName,
		order.ConsigneeMobile,
		order.VendorOrderID,
		jxutils.GetVendorName(order.VendorID),
		order.OrderSeq,
		order.VendorOrderID,
		order.ConsigneeAddress,
		order.BuyerComment,
	)

	for k, sku := range order.Skus {
		orderFmt += xpyunapi.FormatPrintOrderItemV2(sku.SkuName, sku.Count, k+1)
	}
	orderFmt += `<BR><HB><L>共%d种%d件商品</L></HB>`
	orderFmt += `<BR>`
	orderFmt += "<HB>" + xpyunapi.StrRepeat("-", 14) + "#%d完" + xpyunapi.StrRepeat("-", 13) + `</HB><BR><BR>`
	orderParams = append(orderParams, order.SkuCount, order.GoodsCount, order.OrderSeq)
	return fmt.Sprintf(orderFmt, orderParams...)
}

//包含价格版本
// 新订单正常尺寸打印模板
func (c *PrinterHandler) getOrderContent(order *model.GoodsOrder, storeTel string, storeDetail *dao.StoreDetail) (content string) {
	expectedDeliveryTime := order.ExpectedDeliveredTime
	if utils.IsTimeZero(expectedDeliveryTime) {
		expectedDeliveryTime = order.OrderCreatedAt.Add(1 * time.Hour)
	}
	getCode := ""
	if order.VendorID == model.VendorIDEBAI {
		getCode = fmt.Sprintf("<CB>淘宝闪购取货码:%s</CB>", jxutils.GetEbaiOrderGetCode(order))
	}
	if order.BuyerComment == "" {
		order.BuyerComment = "客户电话: " + order.ConsigneeMobile + ",配送遇到问题,可联系18048531223取消配送单,禁止未配送直接完成订单!"
	}
	orderParams := []interface{}{}
	orderFmt := ``
	if storeDetail != nil {
		if storeDetail.BrandIsPrint == model.NO {
			orderFmt += `<C><B>%s</B><C>`
			if order.VendorOrgCode == "34665" {
				orderParams = append(orderParams, globals.StoreNameEbai2)
			} else {
				orderParams = append(orderParams, storeDetail.BrandName)
			}
		}
	}
	if order.BusinessType == model.BusinessTypeDingshida {
		orderFmt += `<C><B>预订单</B><C>`
	} else {
		orderFmt += `<C><B>立即送达</B><C>`
	}
	orderFmt += `
` + xpyunapi.StrRepeat("-", 32) + `
<L>下单时间: %s
<L>预计送达: %s
<L>客户姓名: %s
<L>客户电话: %s<BR>
<HB>订单编号: %s</HB><BR>
<CB>%s#%d
<C><QRCODE s=6 e=L l=center>%s</QRCODE></C></CB>
` + getCode +
		xpyunapi.StrRepeat("-", 32) + `
<HB>客户地址: %s</HB>
` + xpyunapi.StrRepeat("-", 32) + `客户备注: %s
` + xpyunapi.StrRepeat("-", 32) + `
商品列表
商品名`
	switch order.EarningType {
	case model.EarningTypePoints: // 扣点
		orderFmt += xpyunapi.StrRepeat(" ", 2) + `数量` + xpyunapi.StrRepeat(" ", 3) + `单价` + xpyunapi.StrRepeat(" ", 5) + `小计
` + xpyunapi.StrRepeat("-", 32) + `
`
	case model.EarningTypeQuote: // 报价
		orderFmt += xpyunapi.StrRepeat(" ", 20) + `数量<BR>` + xpyunapi.StrRepeat("-", 32)
	}
	orderParams = append(orderParams,
		utils.Time2Str(order.OrderCreatedAt),
		utils.Time2Str(expectedDeliveryTime),
		order.ConsigneeName,
		order.ConsigneeMobile,
		order.VendorOrderID,
		jxutils.GetVendorName(order.VendorID),
		order.OrderSeq,
		order.VendorOrderID,
		order.ConsigneeAddress,
		order.BuyerComment,
	)

	for k, sku := range order.Skus {
		switch order.EarningType {
		case model.EarningTypePoints: // 扣点
			orderFmt += xpyunapi.FormatPrintOrderItem(sku.SkuName, sku.Count, utils.Int64ToFloat64(sku.VendorPrice))
		case model.EarningTypeQuote: // 报价
			orderFmt += xpyunapi.FormatPrintOrderItemV2(sku.SkuName, sku.Count, k+1)
		}
	}
	orderFmt += `
<L>共%d种%d件商品</L>
<L>实际支付: %s</L>
`
	orderFmt += `<BR>`
	orderFmt += xpyunapi.StrRepeat("-", 14) + "#%d完" + xpyunapi.StrRepeat("-", 14) + `<BR>`
	orderParams = append(orderParams, order.SkuCount, order.GoodsCount, jxutils.IntPrice2StandardCurrencyString(order.ActualPayPrice), order.OrderSeq)
	return fmt.Sprintf(orderFmt, orderParams...)
}

//新订单大尺寸打印模板
func (c *PrinterHandler) getOrderContentBig(order *model.GoodsOrder, storeTel string, storeDetail *dao.StoreDetail) (content string) {
	expectedDeliveryTime := order.ExpectedDeliveredTime
	if utils.IsTimeZero(expectedDeliveryTime) {
		expectedDeliveryTime = order.OrderCreatedAt.Add(1 * time.Hour)
	}
	getCode := ""
	if order.VendorID == model.VendorIDEBAI {
		getCode = fmt.Sprintf("<CB>淘宝闪购取货码:%s</CB>", jxutils.GetEbaiOrderGetCode(order))
	}
	if order.BuyerComment == "" {
		order.BuyerComment = "客户电话: " + order.ConsigneeMobile + ",配送遇到问题,可联系18048531223取消配送单,禁止未配送直接完成订单!"
	}
	orderParams := []interface{}{}
	orderFmt := ``
	if storeDetail != nil {
		if storeDetail.BrandIsPrint == model.NO {
			orderFmt += `<C><B>%s</B><C>`
			if order.VendorOrgCode == "34665" {
				orderParams = append(orderParams, globals.StoreNameEbai2)
			} else {
				orderParams = append(orderParams, storeDetail.BrandName)
			}
		}
	}
	if order.BusinessType == model.BusinessTypeDingshida {
		orderFmt += `<C><B>预订单</B><C>`
	} else {
		orderFmt += `<C><B>立即送达</B><C>`
	}
	orderFmt += `
` + xpyunapi.StrRepeat("-", 32) + `
<HB><L>下单时间: %s
<L>预计送达: %s
<L>客户姓名: %s
<L>客户电话: %s</HB><BR>
<HB2>订单编号: %s</HB2><BR>
<CB>%s#%d
<C><QRCODE s=6 e=L l=center>%s</QRCODE></C></CB>
` + getCode +
		xpyunapi.StrRepeat("-", 32) + `
<HB>客户地址: %s</HB>
` + xpyunapi.StrRepeat("-", 32) + `<HB>客户备注: %s
` + xpyunapi.StrRepeat("-", 32) + `
商品列表
商品名`
	switch order.EarningType {
	case model.EarningTypePoints: // 扣点
		orderFmt += xpyunapi.StrRepeat(" ", 2) + `数量` + xpyunapi.StrRepeat(" ", 3) + `单价` + xpyunapi.StrRepeat(" ", 5) + `小计</HB>
` + xpyunapi.StrRepeat("-", 32) + "<HB>" + `
`
	case model.EarningTypeQuote: // 报价
		orderFmt += xpyunapi.StrRepeat(" ", 20) + `数量<BR>` + xpyunapi.StrRepeat("-", 32)
	}

	orderParams = append(orderParams,
		utils.Time2Str(order.OrderCreatedAt),
		utils.Time2Str(expectedDeliveryTime),
		order.ConsigneeName,
		order.ConsigneeMobile,
		order.VendorOrderID,
		jxutils.GetVendorName(order.VendorID),
		order.OrderSeq,
		order.VendorOrderID,
		order.ConsigneeAddress,
		order.BuyerComment,
	)

	for k2, sku := range order.Skus {
		switch order.EarningType {
		case model.EarningTypePoints: // 扣点
			orderFmt += xpyunapi.FormatPrintOrderItem(sku.SkuName, sku.Count, utils.Int64ToFloat64(sku.VendorPrice))
		case model.EarningTypeQuote: // 报价
			orderFmt += xpyunapi.FormatPrintOrderItemV2(sku.SkuName, sku.Count, k2+1)
		}
	}
	orderFmt += `<L>共%d种%d件商品</L>
<L>实际支付: %s</L>
`
	orderFmt += `<BR>`
	orderFmt += xpyunapi.StrRepeat("-", 14) + "#%d完</HB>" + xpyunapi.StrRepeat("-", 14) + `<BR>`
	orderParams = append(orderParams, order.SkuCount, order.GoodsCount, jxutils.IntPrice2StandardCurrencyString(order.ActualPayPrice), order.OrderSeq)
	return fmt.Sprintf(orderFmt, orderParams...)
}

//退货/取消订单 正常尺寸模板
func (c *PrinterHandler) getCancelOrRefundOrderContent(order *model.GoodsOrder, printType int, storeDetail *dao.StoreDetail) (content string) {
	expectedDeliveryTime := order.ExpectedDeliveredTime
	if utils.IsTimeZero(expectedDeliveryTime) {
		expectedDeliveryTime = order.OrderCreatedAt.Add(1 * time.Hour)
	}
	var orderParams []interface{}
	orderFmt := ``
	if storeDetail != nil {
		if storeDetail.BrandIsPrint == model.NO {
			orderFmt += `<C><B>%s</B></C>`
			if order.VendorOrgCode == "34665" {
				orderParams = append(orderParams, globals.StoreNameEbai2)
			} else {
				orderParams = append(orderParams, storeDetail.BrandName)
			}
		}
	}
	title := ``
	if printType == model.YES { // 取消订单
		title = `<HB><L>取消订单详情</HB><BR>`
	} else { // 售后订单
		title = `<HB><L>售后订单详情</HB><BR>`
	}

	orderFmt +=
		xpyunapi.StrRepeat("-", 32) + `
<L>下单时间: %s
<HB>订单编号: %s</HB><BR>
<C><B>%s#%d</C></B>
` + title
	orderParams = append(orderParams,
		utils.Time2Str(order.OrderCreatedAt),
		order.VendorOrderID,
		jxutils.GetVendorName(order.VendorID),
		order.OrderSeq,
	)
	orderFmt += xpyunapi.StrRepeat("-", 32)
	orderFmt += `<L>共%d种%d件商品</L>`
	/*实际支付:%s<BR>`*/
	orderFmt += xpyunapi.StrRepeat("-", 14) + "#%d完</HB>" + xpyunapi.StrRepeat("-", 14) + `<BR>`
	orderParams = append(orderParams, order.SkuCount, order.GoodsCount /*jxutils.IntPrice2StandardCurrencyString(order.ActualPayPrice),*/, order.OrderSeq)
	return fmt.Sprintf(orderFmt, orderParams...)
}

//退货/取消订单 大尺寸模板
func (c *PrinterHandler) getCancelOrRefundOrderContentBig(order *model.GoodsOrder, printType int, storeDetail *dao.StoreDetail) (content string) {
	expectedDeliveryTime := order.ExpectedDeliveredTime
	if utils.IsTimeZero(expectedDeliveryTime) {
		expectedDeliveryTime = order.OrderCreatedAt.Add(1 * time.Hour)
	}
	var orderParams []interface{}
	orderFmt := ``
	if storeDetail != nil {
		if storeDetail.BrandIsPrint == model.NO {
			orderFmt += `<C><B>%s</B></C>`
			if order.VendorOrgCode == "34665" {
				orderParams = append(orderParams, globals.StoreNameEbai2)
			} else {
				orderParams = append(orderParams, storeDetail.BrandName)
			}
		}
	}
	title := ``
	if printType == model.YES { // 取消订单
		title = `<HB><L>取消订单详情</HB><BR>`
	} else { // 售后订单
		title = `<HB><L>售后订单详情</HB><BR>`
	}

	orderFmt +=
		xpyunapi.StrRepeat("-", 32) + `
<L><HB>下单时间: %s</HB>
<HB>订单编号: %s</HB><BR>
<C><B>%s#%d</C></B>
` + title
	orderParams = append(orderParams,
		utils.Time2Str(order.OrderCreatedAt),
		order.VendorOrderID,
		jxutils.GetVendorName(order.VendorID),
		order.OrderSeq,
	)
	orderFmt += xpyunapi.StrRepeat("-", 32)
	orderFmt += `<L><HB>共%d种%d件商品</L>`
	/*实际支付:%s</HB><BR>`*/
	orderFmt += xpyunapi.StrRepeat("-", 14) + "#%d完</HB>" + xpyunapi.StrRepeat("-", 14) + `<BR>`
	orderParams = append(orderParams, order.SkuCount, order.GoodsCount /*jxutils.IntPrice2StandardCurrencyString(order.ActualPayPrice),*/, order.OrderSeq)
	return fmt.Sprintf(orderFmt, orderParams...)
}
