修正和重构代码
This commit is contained in:
@@ -468,6 +468,7 @@ func WriteToExcel(task *tasksch.SeqTask, data map[int][]DiffData) {
|
|||||||
|
|
||||||
if len(sheetList) > 0 {
|
if len(sheetList) > 0 {
|
||||||
excelBin := excel.Obj2Excel(sheetList)
|
excelBin := excel.Obj2Excel(sheetList)
|
||||||
|
sheetList = nil
|
||||||
timeStr := utils.Int64ToStr(time.Now().Unix())
|
timeStr := utils.Int64ToStr(time.Now().Unix())
|
||||||
diffFullFileName := diffFileName[IsJXCS()] + timeStr + fileExt
|
diffFullFileName := diffFileName[IsJXCS()] + timeStr + fileExt
|
||||||
if canWriteTolocal {
|
if canWriteTolocal {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
"errors"
|
"errors"
|
||||||
|
"image"
|
||||||
"image/png"
|
"image/png"
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
@@ -465,15 +466,15 @@ func CaculateSkuEarningPrice(shopPrice, salePrice int64, storePayPercentage int)
|
|||||||
return earningPrice
|
return earningPrice
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetImgBase64(qrCode barcode.Barcode) (imgBase64 string, err error) {
|
func GetImgBase64(img image.Image) (imgBase64 string, err error) {
|
||||||
bufWriter := bytes.NewBuffer(nil)
|
bufWriter := bytes.NewBuffer(nil)
|
||||||
png.Encode(bufWriter, qrCode)
|
png.Encode(bufWriter, img)
|
||||||
imgBase64 = "data:image/png;base64," + base64.StdEncoding.EncodeToString(bufWriter.Bytes())
|
imgBase64 = "data:image/png;base64," + base64.StdEncoding.EncodeToString(bufWriter.Bytes())
|
||||||
|
|
||||||
return imgBase64, err
|
return imgBase64, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateQrAndBarCode(width, height int, codetype, srcData string) (imgBase64 string, err error) {
|
func CreateQrOrBarCode(width, height int, codeType, srcData string) (imgBase64 string, err error) {
|
||||||
if width > MaxCodeWidth {
|
if width > MaxCodeWidth {
|
||||||
width = MaxCodeWidth
|
width = MaxCodeWidth
|
||||||
}
|
}
|
||||||
@@ -481,24 +482,19 @@ func CreateQrAndBarCode(width, height int, codetype, srcData string) (imgBase64
|
|||||||
height = MaxCodeHeight
|
height = MaxCodeHeight
|
||||||
}
|
}
|
||||||
|
|
||||||
if codetype == CodeTypeQr {
|
var code barcode.Barcode
|
||||||
qrCode, err := qr.Encode(srcData, qr.M, qr.Auto)
|
if codeType == CodeTypeQr {
|
||||||
if err == nil {
|
code, err = qr.Encode(srcData, qr.M, qr.Auto)
|
||||||
qrCode, err = barcode.Scale(qrCode, width, height)
|
} else if codeType == CodeTypeBar {
|
||||||
if err == nil {
|
code, err = code128.Encode(srcData)
|
||||||
imgBase64, err = GetImgBase64(qrCode)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if codetype == CodeTypeBar {
|
|
||||||
cs, err := code128.Encode(srcData)
|
|
||||||
if err == nil {
|
|
||||||
qrCode, err2 := barcode.Scale(cs, width, height)
|
|
||||||
if err = err2; err == nil {
|
|
||||||
imgBase64, err = GetImgBase64(qrCode)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
err = errors.New(fmt.Sprintf("未知编码类型:%s", codetype))
|
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
|
return imgBase64, err
|
||||||
|
|||||||
@@ -328,25 +328,13 @@ func (p *PurchaseHandler) GetStoreSkusFullInfo(ctx *jxcontext.Context, parentTas
|
|||||||
}
|
}
|
||||||
return nil, err2
|
return nil, err2
|
||||||
}, pages)
|
}, pages)
|
||||||
tasksch.HandleTask(task, parentTask, false).Run()
|
tasksch.HandleTask(task, parentTask, true).Run()
|
||||||
result, err2 := task.GetResult(0)
|
result, err2 := task.GetResult(0)
|
||||||
if err = err2; err == nil {
|
if err = err2; err == nil {
|
||||||
for _, v := range result {
|
for _, v := range result {
|
||||||
skuNameList = append(skuNameList, vendorSku2Jx(v.(*ebaiapi.SkuInfo)))
|
skuNameList = append(skuNameList, vendorSku2Jx(v.(*ebaiapi.SkuInfo)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// for pageIndex := 2; pageIndex <= page1.Pages; pageIndex++ {
|
|
||||||
// callParams := &ebaiapi.SkuListParams{
|
|
||||||
// PageSize: ebaiapi.MaxSkuListPageSize,
|
|
||||||
// Page: pageIndex,
|
|
||||||
// }
|
|
||||||
// pageSku, err2 := api.EbaiAPI.SkuList(utils.Int2Str(storeID), callParams)
|
|
||||||
// if err2 == nil {
|
|
||||||
// for _, v := range pageSku.List {
|
|
||||||
// skuNameList = append(skuNameList, vendorSku2Jx(v))
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return skuNameList, err
|
return skuNameList, err
|
||||||
|
|||||||
@@ -289,10 +289,10 @@ func (c *CmsController) QueryConfigs() {
|
|||||||
// @Param srcData formData string true "二维码/条形码数据源"
|
// @Param srcData formData string true "二维码/条形码数据源"
|
||||||
// @Success 200 {object} controllers.CallResult
|
// @Success 200 {object} controllers.CallResult
|
||||||
// @Failure 200 {object} controllers.CallResult
|
// @Failure 200 {object} controllers.CallResult
|
||||||
// @router /CreateQrAndBarCode [post]
|
// @router /CreateQrOrBarCode [post]
|
||||||
func (c *CmsController) CreateQrAndBarCode() {
|
func (c *CmsController) CreateQrOrBarCode() {
|
||||||
c.callCreateQrAndBarCode(func(params *tCmsCreateQrAndBarCodeParams) (retVal interface{}, errCode string, err error) {
|
c.callCreateQrOrBarCode(func(params *tCmsCreateQrOrBarCodeParams) (retVal interface{}, errCode string, err error) {
|
||||||
retVal, err = jxutils.CreateQrAndBarCode(params.Width, params.Height, params.Codetype, params.SrcData)
|
retVal, err = jxutils.CreateQrOrBarCode(params.Width, params.Height, params.Codetype, params.SrcData)
|
||||||
return retVal, "", err
|
return retVal, "", err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -279,8 +279,8 @@ func init() {
|
|||||||
|
|
||||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:CmsController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:CmsController"],
|
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:CmsController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:CmsController"],
|
||||||
beego.ControllerComments{
|
beego.ControllerComments{
|
||||||
Method: "CreateQrAndBarCode",
|
Method: "CreateQrOrBarCode",
|
||||||
Router: `/CreateQrAndBarCode`,
|
Router: `/CreateQrOrBarCode`,
|
||||||
AllowHTTPMethods: []string{"post"},
|
AllowHTTPMethods: []string{"post"},
|
||||||
MethodParams: param.Make(),
|
MethodParams: param.Make(),
|
||||||
Filters: nil,
|
Filters: nil,
|
||||||
|
|||||||
Reference in New Issue
Block a user