|
@@ -12,8 +12,8 @@ import (
|
12
|
12
|
"github.com/yl10/kit/guid"
|
13
|
13
|
)
|
14
|
14
|
|
15
|
|
-// Orders 下单
|
16
|
|
-func (s *CourseServ) Orders(
|
|
15
|
+// PreOrders 预下单
|
|
16
|
+func (s *CourseServ) PreOrders(
|
17
|
17
|
couseOrder *model.TaCourseOrders,
|
18
|
18
|
customercouponid string,
|
19
|
19
|
) error {
|
|
@@ -31,13 +31,6 @@ func (s *CourseServ) Orders(
|
31
|
31
|
couseOrder.PayType = models.CONSUME_COUPON
|
32
|
32
|
}
|
33
|
33
|
|
34
|
|
- // TODO
|
35
|
|
- // 校验案场
|
36
|
|
- // caseID := couseOrder.CaseId
|
37
|
|
- // if err := utils.NewAuthEngine(s.ctx).CheckCase(caseID); err != nil {
|
38
|
|
- // return err
|
39
|
|
- // }
|
40
|
|
-
|
41
|
34
|
// 校验课程
|
42
|
35
|
course, err := s.validCourse(couseOrder)
|
43
|
36
|
if err != nil {
|
|
@@ -53,10 +46,8 @@ func (s *CourseServ) Orders(
|
53
|
46
|
couseOrder.CourseName = course.CourseName
|
54
|
47
|
couseOrder.CourseNum = course.CourseNum
|
55
|
48
|
couseOrder.OrgId = org.OrgId
|
56
|
|
- couseOrder.Status = models.STATUS_NORMAL
|
57
|
|
-
|
58
|
|
- // 默认是已支付
|
59
|
|
- couseOrder.IsPay = models.BOOL_TRUE
|
|
49
|
+ couseOrder.Status = models.STATUS_READY
|
|
50
|
+ couseOrder.IsPay = models.BOOL_FALSE
|
60
|
51
|
|
61
|
52
|
if cust.Name != "" {
|
62
|
53
|
couseOrder.CustomerName = cust.Name
|
|
@@ -64,6 +55,20 @@ func (s *CourseServ) Orders(
|
64
|
55
|
couseOrder.CustomerName = cust.CustomerName
|
65
|
56
|
}
|
66
|
57
|
|
|
58
|
+ // 客户 VIP 卡
|
|
59
|
+ var vipAccount float64 = 0.0
|
|
60
|
+ vips, err := s.custDAO.GetValidVIPCards(cust.CustomerId)
|
|
61
|
+ if err != nil {
|
|
62
|
+ return nil, utils.LogError("查询用户VIP卡信息出错", err.Error())
|
|
63
|
+ }
|
|
64
|
+
|
|
65
|
+ if vips != nil && len(vips) > 0 {
|
|
66
|
+ for _, vip := range vips {
|
|
67
|
+ vipMoney, _ := strconv.ParseFloat(vip.Balance, 64)
|
|
68
|
+ vipAccount += vipMoney
|
|
69
|
+ }
|
|
70
|
+ }
|
|
71
|
+
|
67
|
72
|
account, err := s.custDAO.GetAccountByCust(cust.CustomerId)
|
68
|
73
|
if err != nil {
|
69
|
74
|
utils.LogError("查询用户账户信息出错: " + err.Error())
|
|
@@ -170,7 +175,7 @@ func (s *CourseServ) Orders(
|
170
|
175
|
// 用户账户 -- 内部人员也可以购买
|
171
|
176
|
if actualAmount > 0 {
|
172
|
177
|
|
173
|
|
- if actualAmount > accMoney {
|
|
178
|
+ if actualAmount > accMoney+vipAccount {
|
174
|
179
|
return errors.New("账户余额不足")
|
175
|
180
|
}
|
176
|
181
|
|
|
@@ -193,24 +198,25 @@ func (s *CourseServ) Orders(
|
193
|
198
|
return nil
|
194
|
199
|
}
|
195
|
200
|
|
|
201
|
+func (s *CourseServ) ConfirmOrders(ordersID string) error {
|
|
202
|
+ orders, err := s.dao.GetOrderByID(ordersID)
|
|
203
|
+ if err != nil {
|
|
204
|
+ return utils.LogError("获取订单失败", err)
|
|
205
|
+ }
|
|
206
|
+
|
|
207
|
+ if orders.Status != models.STATUS_READY {
|
|
208
|
+ return errors.New("没有订单信息")
|
|
209
|
+ }
|
|
210
|
+
|
|
211
|
+ return nil
|
|
212
|
+}
|
|
213
|
+
|
196
|
214
|
// validCourse 校验课程
|
197
|
215
|
func (s *CourseServ) validCourse(order *model.TaCourseOrders) (*course.CourseDetail, error) {
|
198
|
216
|
if order.CourseId == "" {
|
199
|
217
|
return nil, errors.New("没有获取到下单课程")
|
200
|
218
|
}
|
201
|
219
|
|
202
|
|
- // custCourse, err := s.dao.GetCourseOfCustomer(order.CustomerId, order.CourseId)
|
203
|
|
- // if err != nil {
|
204
|
|
- // utils.LogError("校验用户课程失败: " + err.Error())
|
205
|
|
- // return nil, errors.New("校验用户课程失败")
|
206
|
|
- // }
|
207
|
|
-
|
208
|
|
- // if custCourse != nil && custCourse.CustomerCourseId != "" {
|
209
|
|
- // if custCourse.Status != models.STATUS_DEL {
|
210
|
|
- // return nil, errors.New("用户已经拥有该课程, 不需要再次下单")
|
211
|
|
- // }
|
212
|
|
- // }
|
213
|
|
-
|
214
|
220
|
// 课程
|
215
|
221
|
course, err := s.dao.GetCourseInfo(order.CourseId)
|
216
|
222
|
if err != nil {
|