|
@@ -4,6 +4,7 @@ import (
|
|
|
"config"
|
|
|
"encoding/json"
|
|
|
"entity"
|
|
|
+ "errors"
|
|
|
"log"
|
|
|
"net/rpc"
|
|
|
"pay"
|
|
@@ -26,8 +27,9 @@ type CommonAction struct {
|
|
|
deleteOrder xweb.Mapper `xweb:"/deleteOrder"` //删除订单
|
|
|
vipPaySuccess xweb.Mapper `xweb:"/vipPaySuccess"` //数据导出是否支付成功
|
|
|
|
|
|
- applyInvoice xweb.Mapper `xweb:"/applyInvoice"` //申请发票
|
|
|
- getwxSdkSign xweb.Mapper `xweb:"/wx/getwxSdkSign"` //微信js参数
|
|
|
+ applyInvoice xweb.Mapper `xweb:"/applyInvoice"` //申请发票
|
|
|
+ getwxSdkSign xweb.Mapper `xweb:"/wx/getwxSdkSign"` //微信js参数
|
|
|
+ getWxjsPayParam xweb.Mapper `xweb:"/wx/getWxjsPayParam"` //获取微信支付参数
|
|
|
}
|
|
|
|
|
|
//----------------------------申请发票------------------------------------
|
|
@@ -250,3 +252,67 @@ func SignJSSDK(url string) []string {
|
|
|
}
|
|
|
return signature
|
|
|
}
|
|
|
+
|
|
|
+func (this *CommonAction) GetWxjsPayParam() {
|
|
|
+ orderCode := this.GetString("orderCode")
|
|
|
+ userId := qutil.ObjToString(this.GetSession("userId"))
|
|
|
+ r := func() *entity.FuncResult {
|
|
|
+ //根据订单号获取订单数据
|
|
|
+ query := map[string]interface{}{
|
|
|
+ "user_id": userId,
|
|
|
+ "order_code": orderCode,
|
|
|
+ "order_status": 0,
|
|
|
+ }
|
|
|
+ oData := util.Mysql.FindOne("dataexport_order", query, "id,code_url,prepay_time,pay_way,order_money,vip_type", "")
|
|
|
+ if oData == nil || len(*oData) == 0 {
|
|
|
+ return &entity.FuncResult{false, errors.New("未知订单"), nil}
|
|
|
+ }
|
|
|
+ //判断订单是否超过两小时
|
|
|
+ prepayTime, _ := time.ParseInLocation(qutil.Date_Full_Layout, qutil.ObjToString((*oData)["prepay_time"]), time.Local)
|
|
|
+ jsPayParam := qutil.ObjToString((*oData)["code_url"])
|
|
|
+ payway := qutil.ObjToString((*oData)["pay_way"])
|
|
|
+ if time.Now().Before(prepayTime.Add(time.Hour*2)) && jsPayParam != "" && payway == "wx_js" {
|
|
|
+ //未过期
|
|
|
+ return &entity.FuncResult{true, nil, map[string]interface{}{"res": jsPayParam}}
|
|
|
+ }
|
|
|
+ //重新生成订单
|
|
|
+ totalfee := qutil.IntAll((*oData)["order_money"])
|
|
|
+ tradeno, prepayid := "", ""
|
|
|
+
|
|
|
+ var ret *map[string]string
|
|
|
+ tradeno, ret = pay.WxStruct.CreatePrepayOrder("e", this.IP(), qutil.ObjToString(this.GetSession("s_m_openid")), "", totalfee)
|
|
|
+ if ret == nil || (*ret)["status"] != "1" {
|
|
|
+ errMsg := "创建微信订单出错"
|
|
|
+ if (*ret)["errcodedes"] != "" {
|
|
|
+ errMsg = (*ret)["errcodedes"]
|
|
|
+ } else if (*ret)["errcode"] != "" {
|
|
|
+ errMsg = (*ret)["errcode"]
|
|
|
+ }
|
|
|
+ return &entity.FuncResult{false, errors.New(errMsg), nil}
|
|
|
+ }
|
|
|
+ prepayid = qutil.ObjToString((*ret)["prepayid"])
|
|
|
+ jsPayParam = pay.GetWxJsPayStr(prepayid)
|
|
|
+
|
|
|
+ //更新订单表
|
|
|
+ now := time.Now()
|
|
|
+ ok := util.Mysql.Update("dataexport_order", query, map[string]interface{}{
|
|
|
+ "code_url": jsPayParam,
|
|
|
+ "prepay_time": qutil.FormatDate(&now, qutil.Date_Full_Layout),
|
|
|
+ "out_trade_no": tradeno,
|
|
|
+ "prepay_id": prepayid,
|
|
|
+ "pay_way": payway,
|
|
|
+ })
|
|
|
+ if !ok {
|
|
|
+ return &entity.FuncResult{false, errors.New("数据库操作异常"), nil}
|
|
|
+ }
|
|
|
+ vip_type := qutil.IntAll((*oData)["vip_type"])
|
|
|
+ if vip_type == 0 {
|
|
|
+ vip_type = -1
|
|
|
+ }
|
|
|
+ return &entity.FuncResult{true, nil, map[string]interface{}{"orderCode": orderCode, "res": jsPayParam}}
|
|
|
+ }()
|
|
|
+ if r.Err != nil {
|
|
|
+ log.Printf("%s CreateOrder err:%v\n", userId, r.Err.Error())
|
|
|
+ }
|
|
|
+ this.ServeJson(r.Format())
|
|
|
+}
|