zjxpcyc 6 年之前
父節點
當前提交
da98b8bd04
共有 5 個檔案被更改,包括 102 行新增17 行删除
  1. 4
    1
      controllers/goods/order.go
  2. 8
    0
      models/course/order.go
  3. 2
    13
      service/course/order.go
  4. 14
    3
      service/goods/orders.go
  5. 74
    0
      tests/courseorder_test.go

+ 4
- 1
controllers/goods/order.go 查看文件

146
 func (c *GoodsController) ConfirmOrders() {
146
 func (c *GoodsController) ConfirmOrders() {
147
 	ordersID := c.GetString(":ordersid")
147
 	ordersID := c.GetString(":ordersid")
148
 
148
 
149
+	// 备注
150
+	remark := c.GetString("remark")
151
+
149
 	// 订单优惠券
152
 	// 订单优惠券
150
 	customercouponid := c.GetString("customercouponid")
153
 	customercouponid := c.GetString("customercouponid")
151
 	if customercouponid == "undefined" {
154
 	if customercouponid == "undefined" {
152
 		customercouponid = ""
155
 		customercouponid = ""
153
 	}
156
 	}
154
-	if err := c.serv.ConfirmOrder(ordersID, customercouponid); err != nil {
157
+	if err := c.serv.ConfirmOrder(ordersID, customercouponid, remark); err != nil {
155
 		c.ResponseError(err)
158
 		c.ResponseError(err)
156
 	}
159
 	}
157
 
160
 

+ 8
- 0
models/course/order.go 查看文件

68
 
68
 
69
 // UpdateOrderPay 更新订单为已支付
69
 // UpdateOrderPay 更新订单为已支付
70
 func (m *CourseDAO) UpdateOrderPay(info *model.TaCourseOrders) error {
70
 func (m *CourseDAO) UpdateOrderPay(info *model.TaCourseOrders) error {
71
+	if info.ActualAmount == "" {
72
+		info.ActualAmount = "0.0"
73
+	}
74
+
75
+	if info.CouponAmount == "" {
76
+		info.CouponAmount = "0.0"
77
+	}
78
+
71
 	info.IsPay = models.BOOL_TRUE
79
 	info.IsPay = models.BOOL_TRUE
72
 	info.Status = models.STATUS_NORMAL
80
 	info.Status = models.STATUS_NORMAL
73
 	var cols = []string{
81
 	var cols = []string{

+ 2
- 13
service/course/order.go 查看文件

40
 	couseOrder.OrdersId = guid.NewGUIDString()
40
 	couseOrder.OrdersId = guid.NewGUIDString()
41
 	couseOrder.Price = course.Price // 课程价格, 即为订单价格
41
 	couseOrder.Price = course.Price // 课程价格, 即为订单价格
42
 	couseOrder.ActualAmount = course.Price
42
 	couseOrder.ActualAmount = course.Price
43
+	couseOrder.CouponAmount = "0.0"
43
 	couseOrder.CourseName = course.CourseName
44
 	couseOrder.CourseName = course.CourseName
44
 	couseOrder.CourseNum = course.CourseNum
45
 	couseOrder.CourseNum = course.CourseNum
45
 	couseOrder.OrgId = org.OrgId
46
 	couseOrder.OrgId = org.OrgId
72
 		return errors.New("没有订单信息")
73
 		return errors.New("没有订单信息")
73
 	}
74
 	}
74
 
75
 
75
-	if couseOrder.IsPay != models.BOOL_TRUE {
76
+	if couseOrder.IsPay == models.BOOL_TRUE {
76
 		return errors.New("订单已付款,请勿重复付款!")
77
 		return errors.New("订单已付款,请勿重复付款!")
77
 	}
78
 	}
78
 
79
 
402
 		return errors.New("下单失败, 请重试")
403
 		return errors.New("下单失败, 请重试")
403
 	}
404
 	}
404
 
405
 
405
-	// 默认城币购买
406
-	// courseObtaimType := models.COURSE_GETBY_COINCHG
407
-	// if coupons != nil && len(coupons) > 0 {
408
-	// 	for _, c := range coupons {
409
-	// 		if c.CouponType == models.COURSE_COUPON_CARD {
410
-	// 			courseObtaimType = models.COURSE_GETBY_CARD
411
-	// 		} else if c.CouponType == models.COURSE_COUPON_COUPON {
412
-	// 			courseObtaimType = models.COURSE_GETBY_COUPON
413
-	// 		}
414
-	// 	}
415
-	// }
416
-
417
 	// 我的课程信息
406
 	// 我的课程信息
418
 	custCourse := model.TaCustomerCourse{
407
 	custCourse := model.TaCustomerCourse{
419
 		CourseId:         order.CourseId,
408
 		CourseId:         order.CourseId,

+ 14
- 3
service/goods/orders.go 查看文件

76
 }
76
 }
77
 
77
 
78
 // ConfirmOrder 订单确认
78
 // ConfirmOrder 订单确认
79
-func (s *GoodsServ) ConfirmOrder(
80
-	ordersID, customercouponid string,
81
-) error {
79
+func (s *GoodsServ) ConfirmOrder(ordersID, customercouponid, remark string) error {
82
 	info, err := s.dao.GetOrdersByID(ordersID)
80
 	info, err := s.dao.GetOrdersByID(ordersID)
83
 	if err != nil {
81
 	if err != nil {
84
 		return utils.LogError("获取订单失败", err)
82
 		return utils.LogError("获取订单失败", err)
92
 		return errors.New("订单已付款,请勿重复付款!")
90
 		return errors.New("订单已付款,请勿重复付款!")
93
 	}
91
 	}
94
 
92
 
93
+	if info.Remark == "" {
94
+		info.Remark = remark
95
+	}
96
+
95
 	if info.PayType == "sales" {
97
 	if info.PayType == "sales" {
96
 		// 内部人员, 可以直接购买
98
 		// 内部人员, 可以直接购买
97
 		// TODO
99
 		// TODO
256
 	orders := info.TaGoodsOrders
258
 	orders := info.TaGoodsOrders
257
 	orders.IsPay = models.BOOL_TRUE
259
 	orders.IsPay = models.BOOL_TRUE
258
 	orders.Status = models.STATUS_NORMAL
260
 	orders.Status = models.STATUS_NORMAL
261
+
262
+	if orders.ActualAmount == "" {
263
+		orders.ActualAmount = "0.0"
264
+	}
265
+
266
+	if orders.CouponAmount == "" {
267
+		orders.CouponAmount = "0.0"
268
+	}
269
+
259
 	if err := s.dao.UpdateOrders(&orders, []string{
270
 	if err := s.dao.UpdateOrders(&orders, []string{
260
 		"status", "is_pay", "coupon_amount", "actual_amount",
271
 		"status", "is_pay", "coupon_amount", "actual_amount",
261
 	}); err != nil {
272
 	}); err != nil {

+ 74
- 0
tests/courseorder_test.go 查看文件

1
+package tests
2
+
3
+import (
4
+	"net/http"
5
+	"net/url"
6
+	"spaceofcheng/services/controllers"
7
+	"spaceofcheng/services/utils"
8
+	"testing"
9
+	"time"
10
+
11
+	"github.com/astaxie/beego"
12
+
13
+	. "github.com/smartystreets/goconvey/convey"
14
+)
15
+
16
+func TestPreCourseOrder(t *testing.T) {
17
+	Convey("课程下单", t, func() {
18
+
19
+		Convey("正常下单", func() {
20
+			params := url.Values{}
21
+			params.Add("info", `{"CourseId":"ecc55f91-52b4-4e9b-89a8-b9b3362730f9","CaseId":"10","Price":"2.00"}`)
22
+			result := &controllers.JSONMessage{}
23
+			api := "/api/wechat/MQ/order/course"
24
+
25
+			token := &utils.JWTToken{
26
+				Guest:   false,
27
+				ID:      "oMOpz0kgTrasoAA3G70R7phomn1g", // openid
28
+				Expire:  time.Now().Local().Add(24 * 30 * time.Hour),
29
+				BatchNo: "",
30
+			}
31
+
32
+			code, _, err := NewRequestMock().
33
+				AddToken(token.ToMap()).
34
+				AddWechatUA().
35
+				Request(http.MethodPost, api, params, result)
36
+
37
+			beego.Trace(result)
38
+
39
+			So(code, ShouldEqual, http.StatusOK)
40
+			So(err, ShouldBeNil)
41
+
42
+			// 业务返回判断
43
+			So(result.Code, ShouldEqual, http.StatusOK)
44
+			So(result.Result, ShouldNotBeEmpty)
45
+
46
+			orderID := result.Result.(map[string]interface{})["OrdersId"].(string)
47
+
48
+			Convey("下单确认", func() {
49
+				result := &controllers.JSONMessage{}
50
+				api := "/api/wechat/MQ/order/course/" + orderID
51
+
52
+				token := &utils.JWTToken{
53
+					Guest:   false,
54
+					ID:      "oMOpz0kgTrasoAA3G70R7phomn1g", // openid
55
+					Expire:  time.Now().Local().Add(24 * 30 * time.Hour),
56
+					BatchNo: "",
57
+				}
58
+
59
+				code, _, err := NewRequestMock().
60
+					AddToken(token.ToMap()).
61
+					AddWechatUA().
62
+					Request(http.MethodPut, api, nil, result)
63
+
64
+				beego.Trace(result)
65
+
66
+				So(code, ShouldEqual, http.StatusOK)
67
+				So(err, ShouldBeNil)
68
+
69
+				// 业务返回判断
70
+				So(result.Code, ShouldEqual, http.StatusOK)
71
+			})
72
+		})
73
+	})
74
+}