|
@@ -1,9 +1,11 @@
|
|
|
package shanghu
|
|
|
|
|
|
import (
|
|
|
+ "context"
|
|
|
"duoduo/apis/common"
|
|
|
"duoduo/apis/pdd"
|
|
|
"duoduo/apis/shanghu/models"
|
|
|
+ "duoduo/conf"
|
|
|
"duoduo/models/shanghu"
|
|
|
"duoduo/tools"
|
|
|
"duoduo/tools/app"
|
|
@@ -12,6 +14,8 @@ import (
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
"github.com/gin-gonic/gin"
|
|
|
+ "github.com/qiniu/go-sdk/v7/auth/qbox"
|
|
|
+ "github.com/qiniu/go-sdk/v7/storage"
|
|
|
"github.com/shopspring/decimal"
|
|
|
"strconv"
|
|
|
"time"
|
|
@@ -34,9 +38,6 @@ func CreateMerchantCard(c *gin.Context) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- //"json: cannot unmarshal string into Go struct field CreateMerchantCardRequest.inventory of type int64"
|
|
|
- //"json: cannot unmarshal bool into Go struct field CreateMerchantCardRequest.merchant_card_time of type string"
|
|
|
- //"json: cannot unmarshal string into Go struct field CreateMerchantCardRequest.inventory of type int64"
|
|
|
sqlData.CardProjectData = string(jsStr)
|
|
|
sqlData.CardPrice = inData.CardPrice
|
|
|
sqlData.ActivityEndTime, err = tools.TimeToInt64(inData.ActivityEndTime, "2006-01-02")
|
|
@@ -73,7 +74,13 @@ func CreateMerchantCard(c *gin.Context) {
|
|
|
}
|
|
|
sqlData.UseRule = inData.UseRule
|
|
|
sqlData.MerchantCardName = inData.MerchantCardName
|
|
|
- sqlData.CancelNumber = inData.CancelNumber
|
|
|
+
|
|
|
+ sqlData.CancelNumber, err = strconv.Atoi(inData.CancelNumber)
|
|
|
+ if err != nil {
|
|
|
+ app.Error(c, 400, err, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ sqlData.BackgroundImage = inData.BackgroundImage
|
|
|
|
|
|
_, err = sqlData.Create()
|
|
|
if err != nil {
|
|
@@ -131,6 +138,11 @@ func GetMerchantCard(c *gin.Context) {
|
|
|
outData.Inventory = merchantCard.Inventory
|
|
|
outData.RebateRate = merchantCard.RebateRate
|
|
|
outData.CardPrice = merchantCard.CardPrice
|
|
|
+ outData.X = merchantCard.X
|
|
|
+ outData.Y = merchantCard.Y
|
|
|
+ outData.W = merchantCard.W
|
|
|
+ outData.H = merchantCard.H
|
|
|
+ outData.BackgroundImage = merchantCard.BackgroundImage
|
|
|
|
|
|
app.OK(c, outData, app.Success)
|
|
|
|
|
@@ -144,7 +156,13 @@ func GetMerchantCanvasCard(c *gin.Context) {
|
|
|
var qr models.QRRequest
|
|
|
var getQR models.GetQRRequest
|
|
|
|
|
|
- err := c.ShouldBindJSON(&inData)
|
|
|
+ confIni, err := conf.ConnIni()
|
|
|
+ if err != nil {
|
|
|
+ app.Error(c, 400, err, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ err = c.ShouldBindJSON(&inData)
|
|
|
if err != nil {
|
|
|
app.Error(c, 400, err, err.Error())
|
|
|
return
|
|
@@ -322,6 +340,46 @@ func GetMerchantCanvasCard(c *gin.Context) {
|
|
|
|
|
|
outData.Base64Img = encoded
|
|
|
|
|
|
+ //上传二维码文件
|
|
|
+ timeUnixNano := time.Now().UnixNano() //单位纳秒
|
|
|
+ fileName := fmt.Sprintf("%d.jpg", timeUnixNano)
|
|
|
+
|
|
|
+ //七牛云上传图片
|
|
|
+ bucket := "imgxx"
|
|
|
+ key := "shanghuka/" + "erweima/" + time.Now().Format(time.DateOnly) + "/" + fileName
|
|
|
+
|
|
|
+ putPolicy := storage.PutPolicy{
|
|
|
+ Scope: bucket,
|
|
|
+ }
|
|
|
+
|
|
|
+ mac := qbox.NewMac(confIni.MustValue("ly-qn", "access_key"), confIni.MustValue("ly-qn", "secret_key"))
|
|
|
+ upToken := putPolicy.UploadToken(mac)
|
|
|
+
|
|
|
+ cfg := storage.Config{}
|
|
|
+ // 空间对应的机房
|
|
|
+ cfg.Zone = &storage.ZoneHuanan
|
|
|
+ // 是否使用https域名
|
|
|
+ cfg.UseHTTPS = false
|
|
|
+ // 上传是否使用CDN上传加速
|
|
|
+ cfg.UseCdnDomains = false
|
|
|
+
|
|
|
+ // 构建表单上传的对象
|
|
|
+ baseUploader := storage.NewBase64Uploader(&cfg)
|
|
|
+ ret := storage.PutRet{}
|
|
|
+ //data, err := base64.RawStdEncoding.DecodeString(inData.Pictures[i])
|
|
|
+ //if err != nil {
|
|
|
+ // app.Error(c, 500, err, "上传图片失败")
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+
|
|
|
+ err = baseUploader.Put(context.Background(), &ret, upToken, key, []byte(encoded), nil)
|
|
|
+ if err != nil {
|
|
|
+ app.Error(c, 500, err, "上传图片失败")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ outData.QRUrl = "http://lingyang.shisanmiao.com/" + key
|
|
|
+
|
|
|
//err = json.Unmarshal([]byte(merchantCard.CardProjectData), &project)
|
|
|
//if err != nil {
|
|
|
// app.Error(c, 500, err, err.Error())
|
|
@@ -448,6 +506,42 @@ func UpdateMerchantCard(c *gin.Context) {
|
|
|
app.OK(c, nil, app.Success)
|
|
|
}
|
|
|
|
|
|
+func UpdateMerchantCardWXYZ(c *gin.Context) {
|
|
|
+ var inData models.UpdateMerchantCardWHXYRequest
|
|
|
+ var sqlData shanghu.MerchantCard
|
|
|
+ var whxy []models.WHXYStr
|
|
|
+
|
|
|
+ err := c.ShouldBindJSON(&inData)
|
|
|
+ if err != nil {
|
|
|
+ app.Error(c, 400, err, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //"json: cannot unmarshal number -0.33279827286174424 into Go struct field WHXYStr.rotate of type int"
|
|
|
+ err = json.Unmarshal([]byte(inData.Whxy), &whxy)
|
|
|
+ if err != nil {
|
|
|
+ app.Error(c, 400, err, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for i := 0; i < len(whxy); i++ {
|
|
|
+ if !whxy[i].Y.IsZero() {
|
|
|
+ sqlData.W = whxy[i].W.String()
|
|
|
+ sqlData.X = whxy[i].X.String()
|
|
|
+ sqlData.Y = whxy[i].Y.String()
|
|
|
+ sqlData.H = whxy[i].H.String()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sqlData.ID = inData.MerchantCardId
|
|
|
+
|
|
|
+ err = sqlData.UpdateMerchantWHXY()
|
|
|
+ if err != nil {
|
|
|
+ app.Error(c, 400, err, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ app.OK(c, nil, app.Success)
|
|
|
+}
|
|
|
+
|
|
|
// 核销次数
|
|
|
func CancelNumber(c *gin.Context) {
|
|
|
var inData models.CancelCardRequest
|