فهرست منبع

Merge branch 'mfyx_2.0' of http://8.136.199.33:3000/cxzhang/hongze_mfyx

xingzai 10 ماه پیش
والد
کامیت
9a78e3ba49
4فایلهای تغییر یافته به همراه131 افزوده شده و 3 حذف شده
  1. 3 0
      controllers/wechat.go
  2. 12 3
      services/cygx_yanxuan_special_company.go
  3. 5 0
      services/order.go
  4. 111 0
      services/wx_pay.go

+ 3 - 0
controllers/wechat.go

@@ -472,7 +472,10 @@ func (this *WechatCommonController) WxpayNotify() {
 
 	if itemNotify.OutTradeNo != "" {
 		go services.HandleOrderByWechatPay(itemNotify)
+		item.Url = itemNotify.OutTradeNo // 记录一下同一笔订单微信推送了几次
+		go models.AddCygxShanghaiCompanyLog(item)
 	}
+
 	resp.Code = "SUCCESS"
 	br.Data = resp
 	br.Ret = 200

+ 12 - 3
services/cygx_yanxuan_special_company.go

@@ -15,13 +15,22 @@ func AddSpecialRecord(user *models.WxUserItem, specialId, stopTime int) (err err
 			go utils.SendAlarmMsg(fmt.Sprint("记录用户阅读时长 失败 AddSpecialRecord Err:"+err.Error(), "userId:", user.UserId, "specialId:", specialId), 2)
 		}
 	}()
-	if user.CompanyId <= 1 {
+	if user.CompanyId == 0 {
+		return
+	}
+	//校验研选专栏权限,以及无权限的时候的对应状态码
+	havePower, e := GetYanxuanSpecialDetailUserPower(user)
+	if e != nil {
+		err = errors.New("GetYanxuanSpecialDetailUserPower, Err: " + e.Error())
+		return
+	}
+
+	if !havePower {
 		return
 	}
 	var sellerName string
 	//获取销售信息
 	sellerName, _ = GetSellerName(user)
-
 	if stopTime >= 3 {
 
 		//判断一个用户是否阅读过 某一篇研选专栏
@@ -97,7 +106,7 @@ func AddSpecialRecord(user *models.WxUserItem, specialId, stopTime int) (err err
 	itemLog.RegisterPlatform = utils.REGISTER_PLATFORM
 	itemLog.YanxuanSpecialId = specialId
 	itemLog.StopTime = stopTime
-	_, e := models.AddCygxYanxuanSpecialRecordLog(itemLog) // 添加历史记录
+	_, e = models.AddCygxYanxuanSpecialRecordLog(itemLog) // 添加历史记录
 	if e != nil {
 		err = errors.New("AddCygxYanxuanSpecialRecordLog, Err: " + e.Error())
 		return

+ 5 - 0
services/order.go

@@ -168,6 +168,11 @@ func HandleOrderByWechatPay(itemCallback *WechatPayCallback) {
 		return
 	}
 
+	tradeState, _, _ := GetQueryOrderByOutTradeNo(outTradeNo) //主动查询微信支付信息
+	if tradeState != "SUCCESS" {
+		return
+	}
+
 	go AddCygxOrderPayment(itemCallback) // 记录支付交易信息
 
 	if itemCallback.TradeState != "SUCCESS" { // 回调显示支付不成功,模版消息推送

+ 111 - 0
services/wx_pay.go

@@ -142,3 +142,114 @@ func WxDecodeNotify(body []byte) (wechatPayCallback *WechatPayCallback) {
 	wechatPayCallback = datamap
 	return
 }
+
+// Transaction
+type Transaction struct {
+	Amount          TransactionAmount `json:"amount,omitempty"`
+	Appid           string            `json:"appid,omitempty"`
+	Attach          string            `json:"attach,omitempty"`
+	BankType        string            `json:"bank_type,omitempty"`
+	Mchid           string            `json:"mchid,omitempty"`
+	OutTradeNo      string            `json:"out_trade_no,omitempty"`
+	Payer           TransactionPayer  `json:"payer,omitempty"`
+	PromotionDetail []PromotionDetail `json:"promotion_detail,omitempty"`
+	SuccessTime     time.Time         `json:"success_time,omitempty"`
+	TradeState      string            `json:"trade_state,omitempty"`
+	TradeStateDesc  string            `json:"trade_state_desc,omitempty"`
+	TradeType       string            `json:"trade_type,omitempty"`
+	TransactionId   string            `json:"transaction_id,omitempty"`
+}
+
+// TransactionAmount
+type TransactionAmount struct {
+	Currency      string `json:"currency,omitempty"`
+	PayerCurrency string `json:"payer_currency,omitempty"`
+	PayerTotal    int64  `json:"payer_total,omitempty"`
+	Total         int64  `json:"total,omitempty"`
+}
+
+// PromotionDetail
+type PromotionDetail struct {
+	// 券ID
+	CouponId *string `json:"coupon_id,omitempty"`
+	// 优惠名称
+	Name *string `json:"name,omitempty"`
+	// GLOBAL:全场代金券;SINGLE:单品优惠
+	Scope *string `json:"scope,omitempty"`
+	// CASH:充值;NOCASH:预充值。
+	Type *string `json:"type,omitempty"`
+	// 优惠券面额
+	Amount *int64 `json:"amount,omitempty"`
+	// 活动ID,批次ID
+	StockId *string `json:"stock_id,omitempty"`
+	// 单位为分
+	WechatpayContribute *int64 `json:"wechatpay_contribute,omitempty"`
+	// 单位为分
+	MerchantContribute *int64 `json:"merchant_contribute,omitempty"`
+	// 单位为分
+	OtherContribute *int64 `json:"other_contribute,omitempty"`
+	// CNY:人民币,境内商户号仅支持人民币。
+	Currency    *string                `json:"currency,omitempty"`
+	GoodsDetail []PromotionGoodsDetail `json:"goods_detail,omitempty"`
+}
+
+// PromotionGoodsDetail
+type PromotionGoodsDetail struct {
+	// 商品编码
+	GoodsId *string `json:"goods_id"`
+	// 商品数量
+	Quantity *int64 `json:"quantity"`
+	// 商品价格
+	UnitPrice *int64 `json:"unit_price"`
+	// 商品优惠金额
+	DiscountAmount *int64 `json:"discount_amount"`
+	// 商品备注
+	GoodsRemark *string `json:"goods_remark,omitempty"`
+}
+
+// TransactionPayer
+type TransactionPayer struct {
+	Openid string `json:"openid,omitempty"`
+}
+
+// 根据订单号查询订单状态
+func GetQueryOrderByOutTradeNo(outTradeNo string) (tradeState string, statusCode int, itemResp *Transaction) {
+	var err error
+	defer func() {
+		if err != nil {
+			fmt.Println("err", err)
+			go utils.SendAlarmMsg(fmt.Sprint("根据订单号查询订单状态 失败 GetQueryOrderByOutTradeNo, err:", err.Error(), "outTradeNo", outTradeNo), 2)
+		}
+	}()
+	ctx := context.Background()
+	svc := jsapi.JsapiApiService{Client: utils.WechatCertClient}
+	resp, result, err := svc.QueryOrderByOutTradeNo(ctx,
+		jsapi.QueryOrderByOutTradeNoRequest{
+			OutTradeNo: core.String(outTradeNo),
+			Mchid:      core.String(utils.Mchid),
+		},
+	)
+	statusCode = result.Response.StatusCode
+
+	//订单状态码不存在直接返回
+	if statusCode == 404 {
+		err = nil
+		return
+	}
+	tradeState = *resp.TradeState
+	data, err := json.Marshal(resp)
+	if err != nil {
+		return
+	}
+	jsonstr := string(data)
+	//item := new(Transaction)
+	if err = json.Unmarshal([]byte(jsonstr), &itemResp); err != nil {
+		return
+	}
+	//utils.FileLog.Info(jsonstr)
+	////itemResp = item
+	//fmt.Println(itemResp)
+	//fmt.Println(tradeState)
+	//fmt.Println(itemResp.TransactionId)
+	return
+}