This commit is contained in:
邹宗楠
2023-08-09 15:43:16 +08:00
parent d32a8cd198
commit 26c4c691bb

View File

@@ -1,13 +1,8 @@
package tao_vegetable
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"regexp"
"strings"
"time"
"git.rosy.net.cn/baseapi/platformapi/mtwmapi"
"git.rosy.net.cn/baseapi/platformapi/tao_vegetable"
request1475 "git.rosy.net.cn/baseapi/platformapi/tao_vegetable/sdk/ability1475/request"
@@ -26,6 +21,12 @@ import (
"git.rosy.net.cn/jx-callback/business/partner"
"git.rosy.net.cn/jx-callback/business/partner/putils"
"git.rosy.net.cn/jx-callback/globals"
"image/jpeg"
"io/ioutil"
"net/http"
"regexp"
"strings"
"time"
)
const (
@@ -445,6 +446,22 @@ func checkNameLength(name string, weight int, uint string) string {
return lastName[0:60]
}
// 图片压缩,大于3M
func decodeImg(data []byte) []byte {
if float64(len(data))/float64(1024)/float64(1024) > float64(3) {
jpgimg, err := jpeg.Decode(strings.NewReader(string(data))) // 文件解码成图像对象
if err != nil {
return nil
}
var buf bytes.Buffer
err = jpeg.Encode(&buf, jpgimg, &jpeg.Options{Quality: 30})
if err != nil {
return nil
}
return buf.Bytes()
}
return data
}
func uploadImg(api *tao_vegetable.API, skuId, vendorId int, imgs []string) *string {
vendorImg, _ := dao.GetVendorImg(skuId, vendorId)
result := make([]string, 0, 0)
@@ -468,6 +485,8 @@ func uploadImg(api *tao_vegetable.API, skuId, vendorId int, imgs []string) *stri
if strings.Contains(string(body), "Document not found") || len(body) == 0 {
continue
}
// 检查图片大小
body = decodeImg(body)
newImg, _ := api.UploadImg(&request1475.AlibabaWdkPictureUploadRequest{
PictureCategoryId: utils.Int64ToPointer(0),
Img: &body,
@@ -513,10 +532,16 @@ func uploadImg(api *tao_vegetable.API, skuId, vendorId int, imgs []string) *stri
}
}
if vendorImg.Img == "" && vendorImg.Img2 == "" && vendorImg.Img3 == "" && vendorImg.Img4 == "" && vendorImg.Img5 == "" && vendorImg.DescImg == "" {
return nil
}
taoImgs.SkuID = skuId
taoImgs.VendorID = vendorId
if isCreate {
taoImgs.SkuID = skuId
taoImgs.VendorID = vendorId
dao.CreateEntity(dao.GetDB(), taoImgs)
} else {
dao.UpdateEntity(dao.GetDB(), taoImgs, "Img", "Img2", "Img3", "Img4", "Img5", "DescImg")
}
// 商品图片最多五张
@@ -563,6 +588,7 @@ func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, vendorOr
SkuCode: utils.String2Pointer(utils.Int2Str(v.SkuID)),
OnlineSaleFlag: utils.Int64ToPointer(onlineStatus),
SubTitle: utils.String2Pointer("小时达"),
AllowAppSale: utils.Int64ToPointer(onlineStatus),
//CleanSkuMemberPrice: utils.Int64ToPointer(model.YES),
}
updateSkuList = append(updateSkuList, updateSku)