zjxpcyc 6 years ago
parent
commit
da98b8bd04
5 changed files with 102 additions and 17 deletions
  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 View File

@@ -146,12 +146,15 @@ func (c *GoodsController) PostOrder() {
146 146
 func (c *GoodsController) ConfirmOrders() {
147 147
 	ordersID := c.GetString(":ordersid")
148 148
 
149
+	// 备注
150
+	remark := c.GetString("remark")
151
+
149 152
 	// 订单优惠券
150 153
 	customercouponid := c.GetString("customercouponid")
151 154
 	if customercouponid == "undefined" {
152 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 158
 		c.ResponseError(err)
156 159
 	}
157 160
 

+ 8
- 0
models/course/order.go View File

@@ -68,6 +68,14 @@ func (m *CourseDAO) SaveOrdersCoupon(coupon *model.TaCourseOrdersCoupon, order *
68 68
 
69 69
 // UpdateOrderPay 更新订单为已支付
70 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 79
 	info.IsPay = models.BOOL_TRUE
72 80
 	info.Status = models.STATUS_NORMAL
73 81
 	var cols = []string{

+ 2
- 13
service/course/order.go View File

@@ -40,6 +40,7 @@ func (s *CourseServ) PreOrders(
40 40
 	couseOrder.OrdersId = guid.NewGUIDString()
41 41
 	couseOrder.Price = course.Price // 课程价格, 即为订单价格
42 42
 	couseOrder.ActualAmount = course.Price
43
+	couseOrder.CouponAmount = "0.0"
43 44
 	couseOrder.CourseName = course.CourseName
44 45
 	couseOrder.CourseNum = course.CourseNum
45 46
 	couseOrder.OrgId = org.OrgId
@@ -72,7 +73,7 @@ func (s *CourseServ) ConfirmOrders(ordersID, customercouponid string) error {
72 73
 		return errors.New("没有订单信息")
73 74
 	}
74 75
 
75
-	if couseOrder.IsPay != models.BOOL_TRUE {
76
+	if couseOrder.IsPay == models.BOOL_TRUE {
76 77
 		return errors.New("订单已付款,请勿重复付款!")
77 78
 	}
78 79
 
@@ -402,18 +403,6 @@ func (s *CourseServ) SaveOrder(order *model.TaCourseOrders, course *course.Cours
402 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 407
 	custCourse := model.TaCustomerCourse{
419 408
 		CourseId:         order.CourseId,

+ 14
- 3
service/goods/orders.go View File

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

+ 74
- 0
tests/courseorder_test.go View File

@@ -0,0 +1,74 @@
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
+}