|
@@ -1,14 +1,22 @@
|
|
|
package shanghu
|
|
|
|
|
|
import (
|
|
|
+ "duoduo/apis/common"
|
|
|
+ "duoduo/apis/pdd"
|
|
|
"duoduo/apis/shanghu/models"
|
|
|
"duoduo/models/shanghu"
|
|
|
"duoduo/tools"
|
|
|
"duoduo/tools/app"
|
|
|
+ "encoding/base64"
|
|
|
+ "encoding/json"
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
"github.com/gin-gonic/gin"
|
|
|
+ "github.com/go-pay/gopay"
|
|
|
+ "github.com/go-pay/gopay/wechat"
|
|
|
+ "github.com/shopspring/decimal"
|
|
|
"math/rand"
|
|
|
+ "strconv"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
@@ -152,6 +160,7 @@ func ActiveConfigInfo(c *gin.Context) {
|
|
|
outData.ActivityEndTime = tools.TimeToStr(configInfo.ActivityEndTime)
|
|
|
outData.ActivityStartTime = tools.TimeToStr(configInfo.ActivityStartTime)
|
|
|
outData.ActiveName = configInfo.ActiveName
|
|
|
+ outData.BackgroundImage = configInfo.BackgroundImage
|
|
|
|
|
|
//中奖商品
|
|
|
drawInfoSql.ActiveConfigID = configInfo.ID
|
|
@@ -232,6 +241,43 @@ func ActiveConfigInfo(c *gin.Context) {
|
|
|
|
|
|
}
|
|
|
|
|
|
+// whxy
|
|
|
+func UpdateActiveConfigWHXY(c *gin.Context) {
|
|
|
+ var inData models.ActiveConfigWHXYRequest
|
|
|
+ var sqlData shanghu.MerchantActiveConfig
|
|
|
+ var whxy []models.WHXYStr
|
|
|
+
|
|
|
+ err := c.ShouldBindJSON(&inData)
|
|
|
+ if err != nil {
|
|
|
+ app.Error(c, 400, err, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ 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.ActiveConfigId
|
|
|
+
|
|
|
+ err = sqlData.UpdateMerchantWHXY()
|
|
|
+ if err != nil {
|
|
|
+ app.Error(c, 400, err, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ app.OK(c, nil, app.Success)
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
// 活动列表
|
|
|
func ActiveConfigList(c *gin.Context) {
|
|
|
var inData models.ActiveConfigListRequest
|
|
@@ -562,3 +608,184 @@ func subStockAddLog(drawProductInfo shanghu.MerchantActiveDrawProduct, clientOpe
|
|
|
|
|
|
return nil
|
|
|
}
|
|
|
+
|
|
|
+func GetClientActiveQR(c *gin.Context) {
|
|
|
+ var inData models.ClientActiveQRRequest
|
|
|
+ //var sqlData shanghu.MerchantClientCard
|
|
|
+ var outData models.ClientCardQRReply
|
|
|
+ var qr models.QRRequest
|
|
|
+ var getQR models.GetQRRequest
|
|
|
+
|
|
|
+ err := c.ShouldBindJSON(&inData)
|
|
|
+ if err != nil {
|
|
|
+ app.Error(c, 400, err, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // sqlData.ID = inData.ActiveConfigId
|
|
|
+
|
|
|
+ val, err := pdd.DuoDuoGet("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx8595c589dd736486&secret=668f87d2bc24199688e53ee8a88434b8")
|
|
|
+ if err != nil {
|
|
|
+ app.Error(c, 500, err, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ err = tools.JsonUnmarshal(val, &outData)
|
|
|
+ if err != nil {
|
|
|
+ app.Error(c, 500, err, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if outData.AccessToken == "" {
|
|
|
+ app.Error(c, 500, err, "token error")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ url := "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + outData.AccessToken
|
|
|
+
|
|
|
+ qr.CheckPath = true
|
|
|
+ qr.Page = "pages/home/home"
|
|
|
+ qr.EnvVersion = "release"
|
|
|
+ qr.Scene = strconv.FormatInt(inData.ActiveConfigId, 10)
|
|
|
+
|
|
|
+ data, err := json.Marshal(&qr)
|
|
|
+ if err != nil {
|
|
|
+ app.Error(c, 500, err, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ reply, err := common.Post(data, url)
|
|
|
+ if err != nil {
|
|
|
+ app.Error(c, 500, err, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //err = json.Unmarshal(reply, &getQR)
|
|
|
+ //if err != nil {
|
|
|
+ // app.Error(c, 500, err, err.Error())
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+
|
|
|
+ if getQR.Errcode != 0 {
|
|
|
+ app.Error(c, 500, err, getQR.Errmsg)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //fmt.Println(string(reply))
|
|
|
+
|
|
|
+ encoded := base64.StdEncoding.EncodeToString(reply)
|
|
|
+
|
|
|
+ app.OK(c, encoded, app.Success)
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+func GroupByUnifiedOrder(c *gin.Context) {
|
|
|
+ var inData models.GroupBuyUnifiedOrderRequest
|
|
|
+ var sqlData shanghu.ClientActivePayTrans
|
|
|
+ var activeConfig shanghu.MerchantActiveConfig
|
|
|
+ var outData models.GroupBuyUnifiedOrderReply
|
|
|
+
|
|
|
+ err := c.ShouldBindJSON(&inData)
|
|
|
+ if err != nil {
|
|
|
+ app.Error(c, 400, err, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //校验活动id
|
|
|
+ activeConfig.ID = inData.ActiveConfigId
|
|
|
+
|
|
|
+ activeConfigInfo, err := activeConfig.GetConfigInfoById()
|
|
|
+ if err != nil {
|
|
|
+ app.Error(c, 400, err, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if activeConfigInfo.DrawMode != 1 { //虚拟开团
|
|
|
+ app.Error(c, 500, errors.New("非虚拟开团,不允许下单"), "非虚拟开团,不允许下单.")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if inData.ClientOpenId == "" {
|
|
|
+ app.OK(c, nil, app.Success)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //校验 防止同一笔记录存在
|
|
|
+ sqlData.RequestID = inData.RequestId
|
|
|
+ if sqlData.GetRequestNum() > 0 {
|
|
|
+ app.Error(c, 400, errors.New("交易已存在"), "交易已存在")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //校验金额
|
|
|
+ //检查微信相关参数
|
|
|
+ if !inData.Amount.GreaterThan(decimal.NewFromInt(0)) {
|
|
|
+ app.Error(c, 400, errors.New("amount:金额必须大于0"), "amount:金额必须大于0")
|
|
|
+ return
|
|
|
+
|
|
|
+ }
|
|
|
+ if inData.Amount.Round(2).String() != inData.Amount.String() {
|
|
|
+ app.Error(c, 400, errors.New("total_fee:金额最多只能保留两位小数"), "total_fee:金额最多只能保留两位小数")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //创建支付记录
|
|
|
+ sqlData.ClientOpenID = inData.ClientOpenId
|
|
|
+ sqlData.RequestID = inData.RequestId
|
|
|
+ sqlData.CreatedAt = time.Now()
|
|
|
+ sqlData.UpdatedAt = time.Now()
|
|
|
+ sqlData.Amount = inData.Amount
|
|
|
+ sqlData.OutTradeNo = strconv.FormatInt(inData.ActiveConfigId, 10) + strconv.FormatInt(time.Now().UnixNano(), 10)
|
|
|
+ sqlData.Status = 1 //未支付
|
|
|
+ sqlData.ActiveConfigID = inData.ActiveConfigId
|
|
|
+ sqlData.InvitationCode = inData.InvitationCode
|
|
|
+ _, err = sqlData.Create()
|
|
|
+ if err != nil {
|
|
|
+ app.Error(c, 400, err, "创建支付失败")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ fmt.Println(sqlData.OutTradeNo)
|
|
|
+ bm := make(gopay.BodyMap)
|
|
|
+ bm.Set("nonce_str", common.GetRandomString(32))
|
|
|
+ bm.Set("body", "商户卡")
|
|
|
+ bm.Set("out_trade_no", sqlData.OutTradeNo)
|
|
|
+ bm.Set("total_fee", inData.Amount.Mul(decimal.NewFromInt(100)).IntPart())
|
|
|
+ bm.Set("spbill_create_ip", "127.0.0.1")
|
|
|
+ bm.Set("notify_url", "https://tao1024.com/v1/client/pay/callback")
|
|
|
+ bm.Set("device_info", "WEB")
|
|
|
+ bm.Set("trade_type", "JSAPI")
|
|
|
+ bm.Set("sign_type", wechat.SignType_MD5)
|
|
|
+ bm.Set("openid", inData.ClientOpenId)
|
|
|
+
|
|
|
+ client := NewWechatService()
|
|
|
+ //请求支付下单,成功后得到结果
|
|
|
+ wxResp, err := client.UnifiedOrder(c, bm)
|
|
|
+ if err != nil {
|
|
|
+ app.Error(c, 400, err, "下单失败")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if wxResp.ReturnCode != "SUCCESS" {
|
|
|
+ app.Error(c, 400, errors.New(wxResp.ReturnMsg), "下单失败")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if wxResp.ResultCode != "SUCCESS" {
|
|
|
+ app.Error(c, 400, errors.New(wxResp.ErrCode+"--"+wxResp.ErrCodeDes), "下单失败")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ timestamp := strconv.FormatInt(time.Now().Unix(), 10)
|
|
|
+ pac := "prepay_id=" + wxResp.PrepayId
|
|
|
+ paySign := wechat.GetMiniPaySign("wx8595c589dd736486", wxResp.NonceStr, pac, wechat.SignType_MD5, timestamp, "33c424fAa69942086f82A003e283E9C8")
|
|
|
+
|
|
|
+ outData.Timestamp = timestamp
|
|
|
+ outData.NonceStr = wxResp.NonceStr
|
|
|
+ outData.Package = pac
|
|
|
+ outData.PaySign = paySign
|
|
|
+ outData.SignType = wechat.SignType_MD5
|
|
|
+
|
|
|
+ //merchant, count, err := sqlData.GetOpenIdList(pageSize, pageIndex)
|
|
|
+ //if err != nil {
|
|
|
+ // app.Error(c, 500, err, err.Error())
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ app.OK(c, outData, app.Success)
|
|
|
+}
|
|
|
+
|
|
|
+func Pay(c *gin.Context) {
|
|
|
+ // 获取参数
|
|
|
+ //
|
|
|
+}
|