Merge branch 'mark' of git.coding.net:XJH-Rosy/jx-callback into mark
This commit is contained in:
@@ -468,6 +468,7 @@ func WriteToExcel(task *tasksch.SeqTask, data map[int][]DiffData) {
|
||||
|
||||
if len(sheetList) > 0 {
|
||||
excelBin := excel.Obj2Excel(sheetList)
|
||||
sheetList = nil
|
||||
timeStr := utils.Int64ToStr(time.Now().Unix())
|
||||
diffFullFileName := diffFileName[IsJXCS()] + timeStr + fileExt
|
||||
if canWriteTolocal {
|
||||
|
||||
@@ -588,7 +588,7 @@ func AddCreateFlagForJxStoreSku(ctx *jxcontext.Context, parentTask tasksch.ITask
|
||||
storeSkuBindIDs = append(storeSkuBindIDs, v.BindID)
|
||||
}
|
||||
}
|
||||
storeSkuBindIDs = nil
|
||||
localSkuList = nil
|
||||
}
|
||||
case 1:
|
||||
if len(storeSkuBindIDs) > 0 {
|
||||
|
||||
@@ -11,12 +11,26 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"errors"
|
||||
"image"
|
||||
"image/png"
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"git.rosy.net.cn/baseapi/platformapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"github.com/boombuler/barcode"
|
||||
"github.com/boombuler/barcode/qr"
|
||||
"github.com/boombuler/barcode/code128"
|
||||
)
|
||||
|
||||
const (
|
||||
MaxCodeWidth = 400
|
||||
MaxCodeHeight = 400
|
||||
CodeTypeQr = "qr"
|
||||
CodeTypeBar = "bar"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -451,3 +465,37 @@ func CaculateSkuEarningPrice(shopPrice, salePrice int64, storePayPercentage int)
|
||||
earningPrice = earningPrice * int64(storePayPercentage) / 100
|
||||
return earningPrice
|
||||
}
|
||||
|
||||
func GetImgBase64(img image.Image) (imgBase64 string, err error) {
|
||||
bufWriter := bytes.NewBuffer(nil)
|
||||
png.Encode(bufWriter, img)
|
||||
imgBase64 = "data:image/png;base64," + base64.StdEncoding.EncodeToString(bufWriter.Bytes())
|
||||
|
||||
return imgBase64, err
|
||||
}
|
||||
|
||||
func CreateQrOrBarCode(width, height int, codeType, srcData string) (imgBase64 string, err error) {
|
||||
if width > MaxCodeWidth {
|
||||
width = MaxCodeWidth
|
||||
}
|
||||
if height > MaxCodeHeight {
|
||||
height = MaxCodeHeight
|
||||
}
|
||||
|
||||
var code barcode.Barcode
|
||||
if codeType == CodeTypeQr {
|
||||
code, err = qr.Encode(srcData, qr.M, qr.Auto)
|
||||
} else if codeType == CodeTypeBar {
|
||||
code, err = code128.Encode(srcData)
|
||||
} else {
|
||||
err = errors.New(fmt.Sprintf("未知编码类型:%s", codeType))
|
||||
}
|
||||
if err == nil {
|
||||
code, err = barcode.Scale(code, width, height)
|
||||
if err == nil {
|
||||
imgBase64, err = GetImgBase64(code)
|
||||
}
|
||||
}
|
||||
|
||||
return imgBase64, err
|
||||
}
|
||||
|
||||
@@ -279,3 +279,20 @@ func (c *CmsController) QueryConfigs() {
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 生成二维码或条形码
|
||||
// @Description 生成二维码或条形码
|
||||
// @Param token header string true "认证token"
|
||||
// @Param width formData int true "图片宽"
|
||||
// @Param height formData int true "图片高"
|
||||
// @Param codetype formData string true "编码类型(二维码:qr; 条形码:bar)"
|
||||
// @Param srcData formData string true "二维码/条形码数据源"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /CreateQrOrBarCode [post]
|
||||
func (c *CmsController) CreateQrOrBarCode() {
|
||||
c.callCreateQrOrBarCode(func(params *tCmsCreateQrOrBarCodeParams) (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = jxutils.CreateQrOrBarCode(params.Width, params.Height, params.Codetype, params.SrcData)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
@@ -277,6 +277,15 @@ func init() {
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:CmsController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:CmsController"],
|
||||
beego.ControllerComments{
|
||||
Method: "CreateQrOrBarCode",
|
||||
Router: `/CreateQrOrBarCode`,
|
||||
AllowHTTPMethods: []string{"post"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:CmsController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:CmsController"],
|
||||
beego.ControllerComments{
|
||||
Method: "DeleteConfig",
|
||||
|
||||
Reference in New Issue
Block a user