zhangxinlei1996 5 år sedan
förälder
incheckning
5606cac018

+ 2 - 281
src/jfw/modules/subscribepay/src/service/order.go

@@ -6,11 +6,6 @@ import (
 
 	"log"
 
-	"jfw/config"
-	"jfw/public"
-	"log"
-	"strconv"
-
 	"strings"
 	"time"
 	"util"
@@ -23,27 +18,11 @@ import (
 //订单结构
 type Order struct {
 	*xweb.Action
-	getOrderPayMsg    xweb.Mapper `xweb:"/order/getOrderPayMsg"`    //订单数据展示(支付成功页面)
-	trialPay          xweb.Mapper `xweb:"/order/trialPay"`          //试用用户创建订单
-	getOrderPayAllMsg xweb.Mapper `xweb:"/order/getOrderPayAllMsg"` //订单数据展示(订单详情页面)vip
-	myOrder           xweb.Mapper `xweb:"/order/myOrder"`           //查询订单首页
-	myOrderPaging     xweb.Mapper `xweb:"/order/myOrderPaging"`     //查询订单分页
-	deleteOrder       xweb.Mapper `xweb:"/order/deleteOrder"`       //删除订单
-	applyInvoice      xweb.Mapper `xweb:"/order/applyInvoice"`      //开发票
+	getOrderPayMsg xweb.Mapper `xweb:"/order/getOrderPayMsg"` //订单数据展示(支付成功页面)
+	trialPay       xweb.Mapper `xweb:"/order/trialPay"`       //试用用户创建订单
 
 }
 
-var (
-	layout_date             = "2006.01.02"
-	orderStatus_unPaid      = "0"                //订单状态-待支付
-	orderStatus_paid        = "1"                //订单状态-已完成
-	orderStatus_deleted     = "-1"               //订单状态-已删除
-	orderStatus_cancel      = "-2"               //订单状态-已取消
-	tableName_order         = "dataexport_order" //订单表
-	order_pageSize          = 10
-	pagesize_max        int = 10
-)
-
 type orderResult struct {
 	Success bool  //是否成功
 	Err     error //错误
@@ -85,264 +64,6 @@ func (this *Order) GetOrderPayMsg() {
 
 }
 
-//订单数据展示(订单详情页面)
-func (this *Order) GetOrderPayAllMsg() {
-	orderCode := this.GetString("orderCode")
-	userId := qutil.ObjToString(this.GetSession("userId"))
-	r := func() *orderResult {
-		if orderCode == "" {
-			return &orderResult{false, errors.New("订单号不能为空"), nil}
-		}
-		query := map[string]interface{}{
-			"user_id":    "5db11594f4e498161c85fcf2",
-			"order_code": orderCode,
-			//"order_status": 1,
-		}
-		oData := util.Mysql.FindOne("dataexport_order", query, "prepay_time,pay_time,pay_way,original_price,applybill_status,out_trade_no,filter,product_type,order_status,applybill_type,applybill_taxnum,applybill_company", "")
-		log.Println("odata:", oData)
-		//查询订单信息
-		if oData == nil || len(*oData) == 0 {
-			return &orderResult{false, errors.New("未找到此订单"), nil}
-		}
-		//已支付订单查询有效时间   -已取消的也查看有效时间 用于判断再次购买
-		uData, ok := util.MQFW.FindById("user", userId, `{"l_vip_starttime":1,"l_vip_endtime":1}`)
-		if uData == nil || len(*uData) == 0 || !ok {
-			return &orderResult{false, errors.New("数据库查询异常"), nil}
-		}
-		//
-		if qutil.IntAll((*oData)["order_status"]) != 1 {
-			return &orderResult{true, nil, map[string]interface{}{
-				"order": oData,
-				"time":  uData,
-			}}
-		}
-		delete(*uData, "_id")
-		return &orderResult{true, nil, map[string]interface{}{
-			"order":          oData,
-			"time":           uData,
-			"transaction_id": getPayTransactionId(qutil.ObjToString((*oData)["pay_way"]), qutil.ObjToString((*oData)["out_trade_no"])),
-		}}
-	}()
-	if r.Err != nil {
-		log.Printf("%s CreateOrder err:%v\n", userId, r.Err.Error())
-	}
-	this.ServeJson(r.Format())
-}
-
-//订单列表首页
-func (o *Order) MyOrder() error {
-	//每页显示数
-	userId := o.Session().Get("userId")
-	openid := o.Session().Get("s_m_openid")
-	queryM := map[string]interface{}{}
-	if userId == nil || openid == nil {
-		return errors.New("未登录")
-	} else {
-		queryM["user_id"] = userId
-	}
-	// 0全部 1未支付 2已支付
-	typ := o.GetString("type")
-	if typ != "0" && typ != "" {
-		var status string
-		if typ == "1" {
-			status = orderStatus_unPaid
-		} else if typ == "2" {
-			status = orderStatus_paid
-		} else if typ == "3" {
-			status = orderStatus_cancel
-		}
-		queryM["order_status"] = status
-	} else {
-		queryM["order_status"] = map[string]interface{}{"ne": orderStatus_deleted}
-	}
-	//总数
-	haveNextPage, res, _ := o.Datas(queryM, 1)
-	if res != nil {
-		o.SetRes(res, queryM)
-	}
-	o.ServeJson(map[string]interface{}{
-		"res":         res,
-		"pageSize":    order_pageSize,
-		"hasNextPage": haveNextPage,
-	})
-	return nil
-}
-
-//订单列表分页
-func (o *Order) MyOrderPaging() error {
-	userId := o.Session().Get("userId")
-	openid := o.Session().Get("s_m_openid")
-	queryM := map[string]interface{}{}
-	if userId == nil || openid == nil {
-		return errors.New("未登录")
-	} else {
-		queryM["user_id"] = userId
-	}
-	// 0全部 1未支付 2已支付
-	typ := o.GetString("type")
-	pageNum, _ := o.GetInteger("pageNum")
-	if typ != "0" && typ != "" {
-		var status string
-		if typ == "1" {
-			status = orderStatus_unPaid
-		} else if typ == "2" {
-			status = orderStatus_paid
-		} else if typ == "3" {
-			status = orderStatus_cancel
-		}
-		queryM["order_status"] = status
-	} else {
-		queryM["order_status"] = map[string]interface{}{"ne": orderStatus_deleted}
-	}
-	haveNextPage, res, _ := o.Datas(queryM, pageNum)
-	if res != nil {
-		o.SetRes(res, queryM)
-	}
-	o.ServeJson(map[string]interface{}{
-		"hasNextPage": haveNextPage,
-		"res":         res,
-	})
-	return nil
-}
-
-//删除或取消订单
-func (o *Order) DeleteOrder() error {
-	if userId := o.GetSession("userId"); userId != nil {
-		queryMap := map[string]interface{}{
-			"id":      o.GetString("id"),
-			"user_id": userId.(string),
-		}
-		queryM := map[string]interface{}{}
-		queryM["user_id"] = userId
-		nextPage := false
-		// 0全部 1未支付 2已支付
-		typ := o.GetString("type")
-		cancel := o.GetString("cancel")
-		pageNum, _ := o.GetInteger("pageNum")
-		if typ != "0" && typ != "" {
-			var status string
-			if typ == "1" {
-				status = orderStatus_unPaid
-			} else if typ == "2" {
-				status = orderStatus_paid
-			} else if typ == "3" {
-				status = orderStatus_cancel
-			}
-			queryM["order_status"] = status
-		} else {
-			queryM["order_status"] = map[string]interface{}{"ne": orderStatus_deleted}
-		}
-		haveNextPage, res, _ := o.Datas(queryM, pageNum)
-		if len(res) > 0 {
-			res = res[0:1]
-			//用于删除订单后 判断新增的订单之后 是否有下一页
-			nextPage = true
-		}
-		if res != nil {
-			o.SetRes(res, queryM)
-		}
-		var boo = false
-		if cancel == "cancel" {
-			//取消订单
-			boo = public.Mysql.Update(tableName_order, queryMap, map[string]interface{}{"order_status": -2})
-		} else {
-			//删除订单
-			boo = public.Mysql.Update(tableName_order, queryMap, map[string]interface{}{"order_status": -1})
-		}
-		o.ServeJson(map[string]interface{}{
-			"success":     boo,
-			"res":         res,
-			"hasNextPage": haveNextPage,
-			"nextPage":    nextPage,
-		})
-	}
-	return nil
-}
-
-//开发票
-func (o *Order) ApplyInvoice() error {
-	var applyBill_status int
-	var order_code, applyBill_company, applyBill_taxnum, applyBill_type string
-	var updateBl bool = false
-	order_code = o.GetString("order_code")
-	//获取数据
-	applyBill_type = o.GetString("demo-radio") //个人 单位
-	queryMap := map[string]interface{}{
-		"order_code": order_code,
-	}
-	if applyBill_type == "个人" {
-		applyBill_status = 1
-		updateBl = public.Mysql.Update(tableName_order, queryMap, map[string]interface{}{"applyBill_status": applyBill_status})
-
-	} else if applyBill_type == "单位" {
-		applyBill_status = 1                                 //状态
-		applyBill_company = o.GetString("applyBill_company") //公司名
-		applyBill_taxnum = o.GetString("applyBill_taxnum")   //纳税人识别号
-		updateBl = public.Mysql.Update(tableName_order, queryMap, map[string]interface{}{
-			"applyBill_company": applyBill_company,
-			"applyBill_taxnum":  applyBill_taxnum,
-			"applyBill_status":  applyBill_status,
-			"applyBill_type":    1,
-		}) //修改操作
-	}
-	//判断条件
-	if updateBl {
-		go func() {
-			orderdata := public.Mysql.FindOne(tableName_order, map[string]interface{}{
-				"order_code": order_code,
-			}, "id,filter,user_mail,user_phone,product_type,data_spec,filter_id,order_code,data_count,order_status,order_money,out_trade_no,applybill_type,applybill_company,applybill_taxnum,user_openid,create_time,pay_time,pay_way", "")
-			tt := time.Now()
-			pay_time := qutil.FormatDate(&tt, qutil.Date_Full_Layout)
-			public.SendMailToBJFinance(orderdata, pay_time, "", 2, config.GmailAuth)
-		}()
-	}
-	o.ServeJson(map[string]interface{}{
-		"flag": updateBl,
-	})
-	return nil
-}
-
-func (o *Order) SetRes(res []map[string]interface{}, queryM map[string]interface{}) {
-	for _, v := range res {
-		filter_publishtime := v["filter_publishtime"]
-		if filter_publishtime != nil || filter_publishtime != "" {
-			timeArr := strings.Split(filter_publishtime.(string), "_")
-			if len(timeArr) == 2 {
-				start, err := strconv.ParseInt(timeArr[0], 10, 64)
-				end, erro := strconv.ParseInt(timeArr[1], 10, 64)
-				if err == nil && erro == nil {
-					v["filter_publishtime"] = qutil.FormatDateByInt64(&start, layout_date) + "-" + qutil.FormatDateByInt64(&end, layout_date)
-				}
-			}
-		}
-		v["filter_id"] = qutil.SE.Encode2Hex(v["filter_id"].(string))
-		orderMoney := v["order_money"]
-		if orderMoney != nil {
-			v["order_money"] = float64(orderMoney.(int64)) / 100
-		}
-		if v["id"] != nil && orderMoney != nil && v["order_code"] != nil {
-			v["token"] = public.GetWaitPayToken(v["id"].(int64), int(orderMoney.(int64)), v["order_code"].(string), v["pay_way"].(string), queryM["user_id"].(string))
-		}
-	}
-}
-
-//查询数据
-func (o *Order) Datas(queryM map[string]interface{}, pageNum int) (haveNextPage bool, result []map[string]interface{}, err error) {
-	res := *public.Mysql.Find(tableName_order, queryM, "id,order_code,filter_publishtime,create_time,data_spec,filter_id,filter_keys,order_money,data_count,order_status,pay_way", "create_time desc", -1, 0)
-	if len(res) > 0 {
-		start := (pageNum - 1) * pagesize_max
-		end := pageNum * pagesize_max
-		if end > len(res) {
-			end = len(res)
-		}
-		if start < len(res) {
-			result = res[start:end]
-		}
-	}
-	haveNextPage = len(result) >= pagesize_max
-	return
-}
-
 //获取支付单号
 func getPayTransactionId(payWay, tradeNo string) (transaction_id string) {
 	if payWay == "" || tradeNo == "" {

+ 294 - 0
src/jfw/modules/subscribepay/src/service/orderListDetails.go

@@ -0,0 +1,294 @@
+package service
+
+import (
+	"errors"
+	"jfw/config"
+	"jfw/public"
+	"log"
+	"strconv"
+	"strings"
+	"time"
+	"util"
+
+	"github.com/go-xweb/xweb"
+
+	qutil "qfw/util"
+)
+
+type OrderListDetails struct {
+	*xweb.Action
+	getOrderPayAllMsg xweb.Mapper `xweb:"/orderListDetails/getOrderPayAllMsg"` //订单数据展示(订单详情页面)vip
+	myOrder           xweb.Mapper `xweb:"/orderListDetails/myOrder"`           //查询订单首页
+	myOrderPaging     xweb.Mapper `xweb:"/orderListDetails/myOrderPaging"`     //查询订单分页
+	deleteOrder       xweb.Mapper `xweb:"/orderListDetails/deleteOrder"`       //删除订单
+	applyInvoice      xweb.Mapper `xweb:"/orderListDetails/applyInvoice"`      //开发票
+}
+
+var (
+	layout_date             = "2006.01.02"
+	orderStatus_unPaid      = "0"                //订单状态-待支付
+	orderStatus_paid        = "1"                //订单状态-已完成
+	orderStatus_deleted     = "-1"               //订单状态-已删除
+	orderStatus_cancel      = "-2"               //订单状态-已取消
+	tableName_order         = "dataexport_order" //订单表
+	order_pageSize          = 10
+	pagesize_max        int = 10
+)
+
+//订单数据展示(订单详情页面)
+func (this *OrderListDetails) GetOrderPayAllMsg() {
+	orderCode := this.GetString("orderCode")
+	userId := qutil.ObjToString(this.GetSession("userId"))
+	r := func() *orderResult {
+		if orderCode == "" {
+			return &orderResult{false, errors.New("订单号不能为空"), nil}
+		}
+		query := map[string]interface{}{
+			"user_id":    "5db11594f4e498161c85fcf2",
+			"order_code": orderCode,
+			//"order_status": 1,
+		}
+		oData := util.Mysql.FindOne("dataexport_order", query, "prepay_time,pay_time,pay_way,original_price,applybill_status,out_trade_no,filter,product_type,order_status,applybill_type,applybill_taxnum,applybill_company", "")
+		log.Println("odata:", oData)
+		//查询订单信息
+		if oData == nil || len(*oData) == 0 {
+			return &orderResult{false, errors.New("未找到此订单"), nil}
+		}
+		//已支付订单查询有效时间   -已取消的也查看有效时间 用于判断再次购买
+		uData, ok := util.MQFW.FindById("user", userId, `{"l_vip_starttime":1,"l_vip_endtime":1}`)
+		if uData == nil || len(*uData) == 0 || !ok {
+			return &orderResult{false, errors.New("数据库查询异常"), nil}
+		}
+		//
+		if qutil.IntAll((*oData)["order_status"]) != 1 {
+			return &orderResult{true, nil, map[string]interface{}{
+				"order": oData,
+				"time":  uData,
+			}}
+		}
+		delete(*uData, "_id")
+		return &orderResult{true, nil, map[string]interface{}{
+			"order":          oData,
+			"time":           uData,
+			"transaction_id": getPayTransactionId(qutil.ObjToString((*oData)["pay_way"]), qutil.ObjToString((*oData)["out_trade_no"])),
+		}}
+	}()
+	if r.Err != nil {
+		log.Printf("%s CreateOrder err:%v\n", userId, r.Err.Error())
+	}
+	this.ServeJson(r.Format())
+}
+
+//订单列表首页
+func (o *OrderListDetails) MyOrder() error {
+	//每页显示数
+	userId := o.Session().Get("userId")
+	openid := o.Session().Get("s_m_openid")
+	queryM := map[string]interface{}{}
+	if userId == nil || openid == nil {
+		return errors.New("未登录")
+	} else {
+		queryM["user_id"] = userId
+	}
+	// 0全部 1未支付 2已支付
+	typ := o.GetString("type")
+	if typ != "0" && typ != "" {
+		var status string
+		if typ == "1" {
+			status = orderStatus_unPaid
+		} else if typ == "2" {
+			status = orderStatus_paid
+		} else if typ == "3" {
+			status = orderStatus_cancel
+		}
+		queryM["order_status"] = status
+	} else {
+		queryM["order_status"] = map[string]interface{}{"ne": orderStatus_deleted}
+	}
+	//总数
+	haveNextPage, res, _ := o.Datas(queryM, 1)
+	if res != nil {
+		o.SetRes(res, queryM)
+	}
+	o.ServeJson(map[string]interface{}{
+		"res":         res,
+		"pageSize":    order_pageSize,
+		"hasNextPage": haveNextPage,
+	})
+	return nil
+}
+
+//订单列表分页
+func (o *OrderListDetails) MyOrderPaging() error {
+	userId := o.Session().Get("userId")
+	openid := o.Session().Get("s_m_openid")
+	queryM := map[string]interface{}{}
+	if userId == nil || openid == nil {
+		return errors.New("未登录")
+	} else {
+		queryM["user_id"] = userId
+	}
+	// 0全部 1未支付 2已支付
+	typ := o.GetString("type")
+	pageNum, _ := o.GetInteger("pageNum")
+	if typ != "0" && typ != "" {
+		var status string
+		if typ == "1" {
+			status = orderStatus_unPaid
+		} else if typ == "2" {
+			status = orderStatus_paid
+		} else if typ == "3" {
+			status = orderStatus_cancel
+		}
+		queryM["order_status"] = status
+	} else {
+		queryM["order_status"] = map[string]interface{}{"ne": orderStatus_deleted}
+	}
+	haveNextPage, res, _ := o.Datas(queryM, pageNum)
+	if res != nil {
+		o.SetRes(res, queryM)
+	}
+	o.ServeJson(map[string]interface{}{
+		"hasNextPage": haveNextPage,
+		"res":         res,
+	})
+	return nil
+}
+
+//删除或取消订单
+func (o *OrderListDetails) DeleteOrder() error {
+	if userId := o.GetSession("userId"); userId != nil {
+		queryMap := map[string]interface{}{
+			"id":      o.GetString("id"),
+			"user_id": userId.(string),
+		}
+		queryM := map[string]interface{}{}
+		queryM["user_id"] = userId
+		nextPage := false
+		// 0全部 1未支付 2已支付
+		typ := o.GetString("type")
+		cancel := o.GetString("cancel")
+		pageNum, _ := o.GetInteger("pageNum")
+		if typ != "0" && typ != "" {
+			var status string
+			if typ == "1" {
+				status = orderStatus_unPaid
+			} else if typ == "2" {
+				status = orderStatus_paid
+			} else if typ == "3" {
+				status = orderStatus_cancel
+			}
+			queryM["order_status"] = status
+		} else {
+			queryM["order_status"] = map[string]interface{}{"ne": orderStatus_deleted}
+		}
+		haveNextPage, res, _ := o.Datas(queryM, pageNum)
+		if len(res) > 0 {
+			res = res[0:1]
+			//用于删除订单后 判断新增的订单之后 是否有下一页
+			nextPage = true
+		}
+		if res != nil {
+			o.SetRes(res, queryM)
+		}
+		var boo = false
+		if cancel == "cancel" {
+			//取消订单
+			boo = public.Mysql.Update(tableName_order, queryMap, map[string]interface{}{"order_status": -2})
+		} else {
+			//删除订单
+			boo = public.Mysql.Update(tableName_order, queryMap, map[string]interface{}{"order_status": -1})
+		}
+		o.ServeJson(map[string]interface{}{
+			"success":     boo,
+			"res":         res,
+			"hasNextPage": haveNextPage,
+			"nextPage":    nextPage,
+		})
+	}
+	return nil
+}
+
+//开发票
+func (o *OrderListDetails) ApplyInvoice() error {
+	var applyBill_status int
+	var order_code, applyBill_company, applyBill_taxnum, applyBill_type string
+	var updateBl bool = false
+	order_code = o.GetString("order_code")
+	//获取数据
+	applyBill_type = o.GetString("demo-radio") //个人 单位
+	queryMap := map[string]interface{}{
+		"order_code": order_code,
+	}
+	if applyBill_type == "个人" {
+		applyBill_status = 1
+		updateBl = public.Mysql.Update(tableName_order, queryMap, map[string]interface{}{"applyBill_status": applyBill_status})
+
+	} else if applyBill_type == "单位" {
+		applyBill_status = 1                                 //状态
+		applyBill_company = o.GetString("applyBill_company") //公司名
+		applyBill_taxnum = o.GetString("applyBill_taxnum")   //纳税人识别号
+		updateBl = public.Mysql.Update(tableName_order, queryMap, map[string]interface{}{
+			"applyBill_company": applyBill_company,
+			"applyBill_taxnum":  applyBill_taxnum,
+			"applyBill_status":  applyBill_status,
+			"applyBill_type":    1,
+		}) //修改操作
+	}
+	//判断条件
+	if updateBl {
+		go func() {
+			orderdata := public.Mysql.FindOne(tableName_order, map[string]interface{}{
+				"order_code": order_code,
+			}, "id,filter,user_mail,user_phone,product_type,data_spec,filter_id,order_code,data_count,order_status,order_money,out_trade_no,applybill_type,applybill_company,applybill_taxnum,user_openid,create_time,pay_time,pay_way", "")
+			tt := time.Now()
+			pay_time := qutil.FormatDate(&tt, qutil.Date_Full_Layout)
+			public.SendMailToBJFinance(orderdata, pay_time, "", 2, config.GmailAuth)
+		}()
+	}
+	o.ServeJson(map[string]interface{}{
+		"flag": updateBl,
+	})
+	return nil
+}
+
+func (o *OrderListDetails) SetRes(res []map[string]interface{}, queryM map[string]interface{}) {
+	for _, v := range res {
+		filter_publishtime := v["filter_publishtime"]
+		if filter_publishtime != nil || filter_publishtime != "" {
+			timeArr := strings.Split(filter_publishtime.(string), "_")
+			if len(timeArr) == 2 {
+				start, err := strconv.ParseInt(timeArr[0], 10, 64)
+				end, erro := strconv.ParseInt(timeArr[1], 10, 64)
+				if err == nil && erro == nil {
+					v["filter_publishtime"] = qutil.FormatDateByInt64(&start, layout_date) + "-" + qutil.FormatDateByInt64(&end, layout_date)
+				}
+			}
+		}
+		v["filter_id"] = qutil.SE.Encode2Hex(v["filter_id"].(string))
+		orderMoney := v["order_money"]
+		if orderMoney != nil {
+			v["order_money"] = float64(orderMoney.(int64)) / 100
+		}
+		if v["id"] != nil && orderMoney != nil && v["order_code"] != nil {
+			v["token"] = public.GetWaitPayToken(v["id"].(int64), int(orderMoney.(int64)), v["order_code"].(string), v["pay_way"].(string), queryM["user_id"].(string))
+		}
+	}
+}
+
+//查询数据
+func (o *OrderListDetails) Datas(queryM map[string]interface{}, pageNum int) (haveNextPage bool, result []map[string]interface{}, err error) {
+	res := *public.Mysql.Find(tableName_order, queryM, "id,order_code,filter_publishtime,create_time,data_spec,filter_id,filter_keys,order_money,data_count,order_status,pay_way", "create_time desc", -1, 0)
+	if len(res) > 0 {
+		start := (pageNum - 1) * pagesize_max
+		end := pageNum * pagesize_max
+		if end > len(res) {
+			end = len(res)
+		}
+		if start < len(res) {
+			result = res[start:end]
+		}
+	}
+	haveNextPage = len(result) >= pagesize_max
+	return
+}