|
@@ -15,7 +15,7 @@ import (
|
15
|
15
|
// Orders 下单
|
16
|
16
|
func (s *CourseServ) Orders(
|
17
|
17
|
couseOrder *model.TaCourseOrders,
|
18
|
|
- coupons []model.TaCourseOrdersCoupon,
|
|
18
|
+ customercouponid string,
|
19
|
19
|
) error {
|
20
|
20
|
org := s.ctx.Get("org").(model.SysOrg)
|
21
|
21
|
cust := s.ctx.Get("customer").(model.TaCustomer)
|
|
@@ -47,11 +47,6 @@ func (s *CourseServ) Orders(
|
47
|
47
|
return errors.New("定单课程尚未排课, 不能下单")
|
48
|
48
|
}
|
49
|
49
|
|
50
|
|
- if coupons != nil && len(coupons) > 0 {
|
51
|
|
- // 校验卡券, 同时进行卡券的注销或者已使用的更新操作
|
52
|
|
- // TODO
|
53
|
|
- }
|
54
|
|
-
|
55
|
50
|
couseOrder.OrdersId = guid.NewGUIDString()
|
56
|
51
|
couseOrder.Price = course.Price // 课程价格, 即为订单价格
|
57
|
52
|
couseOrder.ActualAmount = course.Price
|
|
@@ -69,23 +64,90 @@ func (s *CourseServ) Orders(
|
69
|
64
|
couseOrder.CustomerName = cust.CustomerName
|
70
|
65
|
}
|
71
|
66
|
|
72
|
|
- // 校验金额
|
73
|
|
- if err := s.validBillCharges(couseOrder, coupons); err != nil {
|
74
|
|
- return err
|
|
67
|
+ account, err := s.custDAO.GetAccountByCust(cust.CustomerId)
|
|
68
|
+ if err != nil {
|
|
69
|
+ utils.LogError("查询用户账户信息出错: " + err.Error())
|
|
70
|
+ return errors.New("查询用户账户信息出错")
|
75
|
71
|
}
|
|
72
|
+ accMoney, _ := strconv.ParseFloat(account.Amount, 64)
|
|
73
|
+
|
|
74
|
+ if customercouponid != "" {
|
|
75
|
+ // 校验卡券, 同时进行卡券的注销或者已使用的更新操作
|
|
76
|
+ // TODO
|
|
77
|
+ couseOrder.PayType = models.CONSUME_COUPON
|
|
78
|
+
|
|
79
|
+ // 优惠券校验
|
|
80
|
+ customerCoupon, err := s.couponDAO.GetCustomerCouponByID(customercouponid)
|
|
81
|
+ if err != nil {
|
|
82
|
+ utils.LogError("查询优惠券信息失败: " + err.Error())
|
|
83
|
+ return errors.New("查询优惠券信息失败")
|
|
84
|
+ }
|
|
85
|
+ if customerCoupon == nil || customerCoupon.CustomerCouponId == "" {
|
|
86
|
+ return errors.New("优惠券无效!")
|
|
87
|
+ }
|
|
88
|
+ if customerCoupon.Status != models.STATUS_NORMAL || !customerCoupon.UseDate.IsZero() {
|
|
89
|
+ return errors.New("优惠券已被使用!请重新选择优惠券!")
|
|
90
|
+ }
|
|
91
|
+
|
|
92
|
+ // 根据id获取优惠券信息
|
|
93
|
+ coupon, err := s.couponDAO.GetCouponInfoByCustomerCouponID(customercouponid)
|
|
94
|
+ if err != nil {
|
|
95
|
+ utils.LogError("查询优惠券信息失败: " + err.Error())
|
|
96
|
+ return errors.New("查询优惠券信息失败")
|
|
97
|
+ }
|
|
98
|
+
|
|
99
|
+ // 判断优惠券是否可以抵用商品
|
|
100
|
+ var isdy = false
|
|
101
|
+ if coupon.IsAll == 1 {
|
|
102
|
+ isdy = true
|
|
103
|
+ } else {
|
|
104
|
+ for _, target := range coupon.Targets {
|
|
105
|
+ if target.TargetId == course.CourseId {
|
|
106
|
+ isdy = true
|
|
107
|
+ }
|
|
108
|
+ }
|
|
109
|
+ }
|
|
110
|
+ if !isdy {
|
|
111
|
+ return errors.New("优惠券不可抵用该课程")
|
|
112
|
+ }
|
|
113
|
+ var ordersCoupon = model.TaCourseOrdersCoupon{
|
|
114
|
+ OrdersId: couseOrder.OrdersId,
|
|
115
|
+ CouponId: coupon.CouponId,
|
|
116
|
+ CouponName: coupon.CouponName,
|
|
117
|
+ UsedAmount: coupon.Price,
|
|
118
|
+ }
|
|
119
|
+ if err := s.dao.SaveOrdersCoupon(&ordersCoupon, couseOrder); err != nil {
|
|
120
|
+ utils.LogError("保存优惠信息出错: " + err.Error())
|
|
121
|
+ return errors.New("保存优惠信息出错")
|
|
122
|
+ }
|
|
123
|
+ couseOrder.CouponAmount = coupon.Price
|
|
124
|
+
|
|
125
|
+ // 优惠券核销
|
|
126
|
+ err = s.couponDAO.VerifyCustomerCoupon(customercouponid)
|
|
127
|
+ if err != nil {
|
|
128
|
+ utils.LogError("优惠券核销出错: " + err.Error())
|
|
129
|
+ return errors.New("优惠券核销出错")
|
|
130
|
+ }
|
|
131
|
+ } else {
|
|
132
|
+ couseOrder.PayType = models.CONSUME_COINCHG
|
|
133
|
+ }
|
|
134
|
+
|
|
135
|
+ couponAmount, _ := strconv.ParseFloat(couseOrder.CouponAmount, 64)
|
|
136
|
+ payMoney, _ := strconv.ParseFloat(couseOrder.Price, 64)
|
|
137
|
+ payMoney = payMoney - couponAmount
|
|
138
|
+
|
|
139
|
+ couseOrder.ActualAmount = strconv.FormatFloat(payMoney, 'f', -1, 64)
|
|
140
|
+
|
|
141
|
+ // 校验金额
|
|
142
|
+ // if err := s.validBillCharges(couseOrder, coupons); err != nil {
|
|
143
|
+ // return err
|
|
144
|
+ // }
|
76
|
145
|
|
77
|
146
|
// 实际支付
|
78
|
|
- actualAmount, _ := strconv.ParseFloat(couseOrder.ActualAmount, 64)
|
|
147
|
+ actualAmount := payMoney
|
79
|
148
|
|
80
|
149
|
// 用户账户 -- 内部人员也可以购买
|
81
|
150
|
if actualAmount > 0 {
|
82
|
|
- couseOrder.PayType = models.CONSUME_COINCHG
|
83
|
|
- account, err := s.custDAO.GetAccountByCust(cust.CustomerId)
|
84
|
|
- if err != nil {
|
85
|
|
- utils.LogError("查询用户账户信息出错: " + err.Error())
|
86
|
|
- return errors.New("查询用户账户信息出错")
|
87
|
|
- }
|
88
|
|
- accMoney, _ := strconv.ParseFloat(account.Amount, 64)
|
89
|
151
|
|
90
|
152
|
if actualAmount > accMoney {
|
91
|
153
|
return errors.New("账户余额不足")
|
|
@@ -99,7 +161,7 @@ func (s *CourseServ) Orders(
|
99
|
161
|
}
|
100
|
162
|
|
101
|
163
|
// 入库
|
102
|
|
- if err := s.SaveOrder(couseOrder, coupons, course); err != nil {
|
|
164
|
+ if err := s.SaveOrder(couseOrder, course); err != nil {
|
103
|
165
|
utils.LogError("课程下单失败: " + err.Error())
|
104
|
166
|
return errors.New("下单失败, 请重试")
|
105
|
167
|
}
|
|
@@ -226,7 +288,7 @@ func (s *CourseServ) saveCustomerPayRec(account *model.TaCustomerAccount, info *
|
226
|
288
|
}
|
227
|
289
|
|
228
|
290
|
// SaveOrder 保存订单明细
|
229
|
|
-func (s *CourseServ) SaveOrder(order *model.TaCourseOrders, coupons []model.TaCourseOrdersCoupon, course *course.CourseDetail) error {
|
|
291
|
+func (s *CourseServ) SaveOrder(order *model.TaCourseOrders, course *course.CourseDetail) error {
|
230
|
292
|
// 订单信息
|
231
|
293
|
if err := s.dao.SaveCourseOrder(order); err != nil {
|
232
|
294
|
utils.LogError("课程下单失败: " + err.Error())
|
|
@@ -234,16 +296,16 @@ func (s *CourseServ) SaveOrder(order *model.TaCourseOrders, coupons []model.TaCo
|
234
|
296
|
}
|
235
|
297
|
|
236
|
298
|
// 默认城币购买
|
237
|
|
- courseObtaimType := models.COURSE_GETBY_COINCHG
|
238
|
|
- if coupons != nil && len(coupons) > 0 {
|
239
|
|
- for _, c := range coupons {
|
240
|
|
- if c.CouponType == models.COURSE_COUPON_CARD {
|
241
|
|
- courseObtaimType = models.COURSE_GETBY_CARD
|
242
|
|
- } else if c.CouponType == models.COURSE_COUPON_COUPON {
|
243
|
|
- courseObtaimType = models.COURSE_GETBY_COUPON
|
244
|
|
- }
|
245
|
|
- }
|
246
|
|
- }
|
|
299
|
+ // courseObtaimType := models.COURSE_GETBY_COINCHG
|
|
300
|
+ // if coupons != nil && len(coupons) > 0 {
|
|
301
|
+ // for _, c := range coupons {
|
|
302
|
+ // if c.CouponType == models.COURSE_COUPON_CARD {
|
|
303
|
+ // courseObtaimType = models.COURSE_GETBY_CARD
|
|
304
|
+ // } else if c.CouponType == models.COURSE_COUPON_COUPON {
|
|
305
|
+ // courseObtaimType = models.COURSE_GETBY_COUPON
|
|
306
|
+ // }
|
|
307
|
+ // }
|
|
308
|
+ // }
|
247
|
309
|
|
248
|
310
|
// 我的课程信息
|
249
|
311
|
custCourse := model.TaCustomerCourse{
|
|
@@ -257,7 +319,7 @@ func (s *CourseServ) SaveOrder(order *model.TaCourseOrders, coupons []model.TaCo
|
257
|
319
|
CourseNum: course.CourseNum,
|
258
|
320
|
JoinNum: 0,
|
259
|
321
|
CreateDate: time.Now().Local(),
|
260
|
|
- CourseObtaimType: courseObtaimType,
|
|
322
|
+ CourseObtaimType: order.PayType,
|
261
|
323
|
SourceId: order.OrdersId,
|
262
|
324
|
IsDone: models.BOOL_FALSE,
|
263
|
325
|
}
|