Bläddra i källkod

取消订单前-关闭订单

zhangxinlei1996 5 år sedan
förälder
incheckning
47b63b81b7

+ 10 - 2
src/jfw/modules/subscribepay/src/entity/dataexport.go

@@ -324,8 +324,16 @@ func SendMailToBJFinance(order *map[string]interface{}, pay_time, transaction_id
 				}
 				}
 			}
 			}
 		}
 		}
-		mail_title = "电子发票申请,剑鱼标讯历史数据订单【" + order_code + "】,请查收"
-		mailcontent = fmt.Sprintf(ExConf.Mail_invoice_finance_content, bill_title, company_flag, bill_company, taxnum_flag, bill_taxnum, order_code, create_time, pay_time, product_type, isShowTransaction, pay_way, transaction_id, offlineImgSrc, data_spec, data_count, order_money, user_mail, user_phone)
+		//历史数据导出
+		if product_type == "历史数据导出" {
+			mail_title = "电子发票申请,剑鱼标讯历史数据订单【" + order_code + "】,请查收"
+			mailcontent = fmt.Sprintf(ExConf.Mail_invoice_finance_content, bill_title, company_flag, bill_company, taxnum_flag, bill_taxnum, order_code, create_time, pay_time, product_type, isShowTransaction, pay_way, transaction_id, offlineImgSrc, data_spec, data_count, order_money, user_mail, user_phone)
+		} else if product_type == "VIP订阅导出" {
+			//vip
+			product_type = "VIP订阅"
+			mail_title = "电子发票申请,剑鱼标讯VIP订单【" + order_code + "】,请查收"
+			mailcontent = fmt.Sprintf("", bill_title, company_flag, bill_company, taxnum_flag, bill_taxnum, order_code, create_time, pay_time, product_type, isShowTransaction, pay_way, transaction_id, offlineImgSrc, data_spec, data_count, order_money, user_mail, user_phone)
+		}
 	}
 	}
 	//发送邮件
 	//发送邮件
 	for _, finance_mail := range ExConf.Finance_emails {
 	for _, finance_mail := range ExConf.Finance_emails {

+ 37 - 8
src/jfw/modules/subscribepay/src/entity/subscribeVip.go

@@ -5,6 +5,7 @@ import (
 	"encoding/json"
 	"encoding/json"
 	"errors"
 	"errors"
 	"log"
 	"log"
+	"pay"
 	"time"
 	"time"
 	"util"
 	"util"
 
 
@@ -362,7 +363,7 @@ func (this *vipSubscribeStruct) PayCallBack(param *CallBackParam) (ok bool) {
 			if ok {
 			if ok {
 				//支付成功后 其他未支付vip订阅订单 变为已取消
 				//支付成功后 其他未支付vip订阅订单 变为已取消
 				if PayCancel(userid) {
 				if PayCancel(userid) {
-					log.Println(userid, "更改其余未支付订单失")
+					log.Println(userid, "更改其余未支付订单失")
 				}
 				}
 			}
 			}
 		} else {
 		} else {
@@ -583,14 +584,42 @@ func getSetMealPrice(c, i, u int) int {
 	}
 	}
 }
 }
 
 
-//支付成功后,将该订单以外的所有订单状态改为已取消状态 已取消:-2
+//支付成功后,将该订单以外的所有订单状态改为已取消状态 已取消:-2  先关闭订单再改状态
 func PayCancel(userId string) bool {
 func PayCancel(userId string) bool {
-	bl := util.Mysql.Update("dataexport_order", bson.M{
+	queryMap := map[string]interface{}{
 		"user_id":      userId,
 		"user_id":      userId,
-		"product_type": "VIP订阅",
 		"order_status": 0,
 		"order_status": 0,
-	}, bson.M{
-		"order_status": -2,
-	})
-	return bl
+		"product_type": "VIP订阅",
+	}
+	i, order_len := 0, 0
+	order := util.Mysql.Find("dataexport_order", queryMap, "order_code,pay_way,out_trade_no,prepay_time,order_status", "create_time desc", -1, 0)
+	if order != nil {
+		order_len = len(*order)
+		//遍历未支付订单
+		for _, v := range *order {
+			flag := false
+			if qutil.Int64All(v["order_status"]) == 0 {
+				//关闭未支付订单
+				flag = pay.CloseDataExportOrder(qutil.ObjToString(v["pay_way"]), qutil.ObjToString(v["out_trade_no"]), qutil.ObjToString(v["prepay_time"]))
+
+			} else {
+				flag = true
+			}
+			if flag {
+				//更改未支付订单状态 -2
+				bl := util.Mysql.Update("dataexport_order", bson.M{
+					"user_id":      userId,
+					"product_type": "VIP订阅",
+					"order_status": 0,
+					"order_code":   v["order_code"],
+				}, bson.M{
+					"order_status": -2,
+				})
+				if bl {
+					i++
+				}
+			}
+		}
+	}
+	return i == order_len //更改成功次数是否等于需要更改次数
 }
 }

+ 13 - 8
src/jfw/modules/subscribepay/src/main_test.go

@@ -1,6 +1,7 @@
 package main
 package main
 
 
 import (
 import (
+	"entity"
 	"fmt"
 	"fmt"
 	"log"
 	"log"
 	"testing"
 	"testing"
@@ -15,16 +16,20 @@ func Test_asd(t *testing.T) {
 	fmt.Println(cc)
 	fmt.Println(cc)
 }
 }
 func Test_update(t *testing.T) {
 func Test_update(t *testing.T) {
-	if !util.MQFW.UpdateById("user", "5db11594f4e498161c85fcf2", bson.M{"$set": bson.M{"o_vipjy.i_trial": 1}}) {
+	if !util.MQFW.UpdateById("user", "5cda80dd2757344674c10c71", bson.M{"$set": bson.M{"o_vipjy.i_trial": 1}}) {
 		log.Println("更新使用状态出错")
 		log.Println("更新使用状态出错")
 	}
 	}
 }
 }
-
-func Test_CanTrial(t *testing.T) {
-	f := util.CanTrial("5db11594f4e498161c85fcf2")
-	fmt.Println(f)
+func Test_cancelOrder(t *testing.T) {
+	userId := "5d9fe93a27573439d033b294"
+	entity.PayCancel(userId)
 }
 }
 
 
-func Test_SetTrialed(t *testing.T) {
-	util.SetTrialed("5db11594f4e498161c85fcf2")
-}
+//func Test_CanTrial(t *testing.T) {
+//	f := util.CanTrial("5d9fe93a27573439d033b294")
+//	fmt.Println(f)
+//}
+
+//func Test_SetTrialed(t *testing.T) {
+//	util.SetTrialed("5d9fe93a27573439d033b294")
+//}

+ 5 - 4
src/jfw/modules/subscribepay/src/service/commonAction.go

@@ -3,11 +3,12 @@ package service
 import (
 import (
 	"config"
 	"config"
 	"entity"
 	"entity"
-	"github.com/go-xweb/xweb"
 	"pay"
 	"pay"
 	qutil "qfw/util"
 	qutil "qfw/util"
 	"time"
 	"time"
 	"util"
 	"util"
+
+	"github.com/go-xweb/xweb"
 )
 )
 
 
 //付费公用方法
 //付费公用方法
@@ -15,9 +16,9 @@ type CommonAction struct {
 	*xweb.Action
 	*xweb.Action
 	isPaySuccess xweb.Mapper `xweb:"/isPaySuccess"`          //数据导出是否支付成功
 	isPaySuccess xweb.Mapper `xweb:"/isPaySuccess"`          //数据导出是否支付成功
 	paySuccess   xweb.Mapper `xweb:"/dataReport/paySuccess"` //数据报告支付完成
 	paySuccess   xweb.Mapper `xweb:"/dataReport/paySuccess"` //数据报告支付完成
-	deleteOrder xweb.Mapper `xweb:"/deleteOrder"` //删除订单
+	deleteOrder  xweb.Mapper `xweb:"/deleteOrder"`           //删除订单
 
 
-	applyInvoice xweb.Mapper `xweb:"/applyInvoice"`          //申请发票
+	applyInvoice xweb.Mapper `xweb:"/applyInvoice"` //申请发票
 }
 }
 
 
 //----------------------------申请发票------------------------------------
 //----------------------------申请发票------------------------------------
@@ -44,7 +45,7 @@ func (d *CommonAction) ApplyInvoice() error {
 			"applyBill_taxnum":  applyBill_taxnum,
 			"applyBill_taxnum":  applyBill_taxnum,
 			"applyBill_status":  applyBill_status,
 			"applyBill_status":  applyBill_status,
 			"applyBill_type":    1,
 			"applyBill_type":    1,
-		})                                                   //修改操作
+		}) //修改操作
 	}
 	}
 	//判断条件
 	//判断条件
 	if updateBl {
 	if updateBl {

+ 20 - 7
src/jfw/modules/subscribepay/src/service/orderListDetails.go

@@ -6,6 +6,7 @@ import (
 	"errors"
 	"errors"
 	"fmt"
 	"fmt"
 	"log"
 	"log"
+	"pay"
 	qutil "qfw/util"
 	qutil "qfw/util"
 	"regexp"
 	"regexp"
 	"strconv"
 	"strconv"
@@ -203,13 +204,26 @@ func (o *OrderListDetails) DeleteOrder() error {
 			o.SetRes(res, queryM)
 			o.SetRes(res, queryM)
 		}
 		}
 		var boo = false
 		var boo = false
-		if cancel == "cancel" {
-			//取消订单
-			boo = util.Mysql.Update(tableName_order, queryMap, map[string]interface{}{"order_status": -2})
-		} else {
-			//删除订单
-			boo = util.Mysql.Update(tableName_order, queryMap, map[string]interface{}{"order_status": -1})
+		var flag = false
+		//删除 取消前 先关闭订单
+		order := util.Mysql.FindOne(tableName_order, queryMap, "pay_way,out_trade_no,prepay_time,order_status", "")
+		if order != nil {
+			if qutil.IntAll((*order)["order_status"]) == 0 { //未支付状态下 删除订单需要先关闭订单
+				flag = pay.CloseDataExportOrder(qutil.ObjToString((*order)["pay_way"]), qutil.ObjToString((*order)["out_trade_no"]), qutil.ObjToString((*order)["prepay_time"]))
+			} else {
+				flag = true
+			}
 		}
 		}
+		if flag {
+			if cancel == "cancel" {
+				//取消订单
+				boo = util.Mysql.Update(tableName_order, queryMap, map[string]interface{}{"order_status": -2})
+			} else {
+				//删除订单
+				boo = util.Mysql.Update(tableName_order, queryMap, map[string]interface{}{"order_status": -1})
+			}
+		}
+
 		o.ServeJson(map[string]interface{}{
 		o.ServeJson(map[string]interface{}{
 			"success":     boo,
 			"success":     boo,
 			"res":         res,
 			"res":         res,
@@ -222,7 +236,6 @@ func (o *OrderListDetails) DeleteOrder() error {
 
 
 //设置邮箱-发送验证码
 //设置邮箱-发送验证码
 func (o *OrderListDetails) SetEmail() {
 func (o *OrderListDetails) SetEmail() {
-	log.Println("--")
 	email := o.GetString("email")
 	email := o.GetString("email")
 	userId := qutil.ObjToString(o.GetSession("userId"))
 	userId := qutil.ObjToString(o.GetSession("userId"))
 	if userId != "" {
 	if userId != "" {