소스 검색

Merge branch '2.1.0' of http://git.ycjcjy.com/SpaceOfCheng/services into 2.1.0

胡轶钦 6 년 전
부모
커밋
35a871412f
6개의 변경된 파일65개의 추가작업 그리고 59개의 파일을 삭제
  1. 0
    1
      conf/app.conf
  2. 2
    2
      models/coupon/coupon.go
  3. 7
    7
      models/luckdraw/luckdraw.go
  4. 32
    26
      service/course/order.go
  5. 4
    0
      service/goods/orders.go
  6. 20
    23
      tests/goodsorder_test.go

+ 0
- 1
conf/app.conf 파일 보기

@@ -12,7 +12,6 @@ qrcodePrefix = bodycheck_
12 12
 followText = 您正在使用悦琦设备进行体检~
13 13
 resultURL = http://spaceofcheng.ycjcjy.com/wechat/bodyCheck.html
14 14
 
15
-clientShareURL = http://spaceofcheng.ycjcjy.com/wechat/user.html
16 15
 defaultShareUserID = 1
17 16
 
18 17
 [cros]

+ 2
- 2
models/coupon/coupon.go 파일 보기

@@ -313,7 +313,7 @@ func (m *CouponDAO) GetCouponBySendType(caseids, sendtype string) ([]model.TaCou
313 313
 // GetCaseUsableCoupon 获取案场可用优惠券信息
314 314
 func (m *CouponDAO) GetCaseUsableCoupon(caseid, userid string, page, pageSize int) ([]CaseCouponDetail, error) {
315 315
 	var Coupons []CaseCouponDetail
316
-	sql := `select * from ta_coupon where case_id=? and status=? and DATE_FORMAT(end_date, '%Y-%m-%d')>=DATE_FORMAT(NOW(), '%Y-%m-%d') and send_type=? order by create_date desc limit ` + strconv.Itoa((page-1)*pageSize) + `, ` + strconv.Itoa(pageSize)
316
+	sql := `select * from ta_coupon where case_id=? and status=? and (DATE_FORMAT(end_date, '%Y-%m-%d')>=DATE_FORMAT(NOW(), '%Y-%m-%d') or valid_days>0) and send_type=? order by create_date desc limit ` + strconv.Itoa((page-1)*pageSize) + `, ` + strconv.Itoa(pageSize)
317 317
 	err := m.db.Sql(sql, caseid, models.STATUS_NORMAL, models.GIVE_TYPE_CASE).Find(&Coupons)
318 318
 	for inx, coupon := range Coupons {
319 319
 		if userid != "" {
@@ -342,7 +342,7 @@ func (m *CouponDAO) GetCouponShareByCouponID(couponid string) (*model.TaCouponSh
342 342
 // GetCaseUsableCouponCount 获取案场可用优惠券数量
343 343
 func (m *CouponDAO) GetCaseUsableCouponCount(caseid, userid string) (int, error) {
344 344
 	var Coupons []CaseCouponDetail
345
-	sql := `select * from ta_coupon where case_id=? and status=? and DATE_FORMAT(end_date, '%Y-%m-%d')>=DATE_FORMAT(NOW(), '%Y-%m-%d') and send_type=?`
345
+	sql := `select * from ta_coupon where case_id=? and status=? and (DATE_FORMAT(end_date, '%Y-%m-%d')>=DATE_FORMAT(NOW(), '%Y-%m-%d') or valid_days>0) and send_type=?`
346 346
 	err := m.db.Sql(sql, caseid, models.STATUS_NORMAL, models.GIVE_TYPE_CASE).Find(&Coupons)
347 347
 
348 348
 	return len(Coupons), err

+ 7
- 7
models/luckdraw/luckdraw.go 파일 보기

@@ -318,7 +318,7 @@ func (m *LuckDrawDao) SavePrizeDetail(prize model.TaLuckdrawPrize) error {
318 318
 			var d = model.TaPrizeDetail{
319 319
 				Id:      utils.GetGUID(),
320 320
 				PrizeId: prize.Id,
321
-				Url:     beego.AppConfig.String("clientShareURL") + url,
321
+				Url:     url,
322 322
 				Status:  models.STATUS_NORMAL,
323 323
 			}
324 324
 			details = append(details, d)
@@ -431,7 +431,7 @@ func (m *LuckDrawDao) LuckDraw(id string, user *model.TaCustomer) (*model.TaLuck
431 431
 			if err != nil {
432 432
 				return nil, nil, nil, errors.New("获取信息失败!")
433 433
 			}
434
-			if sysuser != nil {
434
+			if sysuser != nil && sysuser.UserId != "" {
435 435
 				return nil, nil, nil, errors.New("内部人员不允许进行抽奖!")
436 436
 			}
437 437
 		}
@@ -618,8 +618,8 @@ type PrizeWithDefault struct {
618 618
 // GetPrizeDefaultByUser 获取默认用户
619 619
 func (m *LuckDrawDao) GetPrizeDefaultByUser(id string, customer *model.TaCustomer) (*PrizeWithDefault, error) {
620 620
 	var prize = PrizeWithDefault{}
621
-	sql := `select a.default_id,b.* from ta_prize_default a inner join ta_prize_default b on a.prize_id=b.id where a.luckdraw_id=? and a.tel=? and is_receive=?`
622
-	_, err := m.db.Sql(sql, id, customer.Phone, models.BOOL_FALSE).Get(prize)
621
+	sql := `select a.default_id,b.* from ta_prize_default a inner join ta_luckdraw_prize b on a.prize_id=b.id where a.luckdraw_id=? and a.tel=? and a.is_receive=?`
622
+	_, err := m.db.Sql(sql, id, customer.Phone, models.BOOL_FALSE).Get(&prize)
623 623
 	return &prize, err
624 624
 }
625 625
 
@@ -636,7 +636,7 @@ func (m *LuckDrawDao) UpdatePrizeDefault(id, recordid string) error {
636 636
 		"receive_date",
637 637
 		"is_receive",
638 638
 	}
639
-	_, err := m.db.Cols(cols...).Where("id=?", prizeDefault.DefaultId).Update(prizeDefault)
639
+	_, err := m.db.Cols(cols...).Where("default_id=?", prizeDefault.DefaultId).Update(prizeDefault)
640 640
 	return err
641 641
 }
642 642
 
@@ -797,7 +797,7 @@ func (m *LuckDrawDao) GetPrizeStock(luckdrawid string) ([]model.TaLuckdrawPrize,
797 797
 	a.* from ta_luckdraw_prize a 
798 798
 	left join (select prize_id,count(1) as default_num from ta_prize_default where luckdraw_id) b 
799 799
 	on a.id=b.prize_id where a.luckdraw_id=? and a.status=? and (a.remainder-(case when b.default_num is null then 0 else b.default_num end)>0 or is_reality=0)`
800
-	err := m.db.Sql(sql).Find(&prizes)
800
+	err := m.db.Sql(sql, luckdrawid, models.STATUS_NORMAL).Find(&prizes)
801 801
 	// err := m.db.Where("luckdraw_id=?", luckdrawid).And("status=?", models.STATUS_NORMAL).And("(remainder>0 or is_reality=0)").Find(&prizes)
802 802
 	return prizes, err
803 803
 }
@@ -876,7 +876,7 @@ func (m *LuckDrawDao) GetUserRecordByLuckDraw(userid string, luckdrawid string)
876 876
 // GetUserLuckDrawSet 获取用户抽奖设置
877 877
 func (m *LuckDrawDao) GetUserLuckDrawSet(customer model.TaCustomer, luckdrawid string) (*model.TaLuckdrawCustomer, error) {
878 878
 	var cstluckdraw = model.TaLuckdrawCustomer{}
879
-	_, err := m.db.Where("customer_id=?").And("luckdraw_id=?", luckdrawid).Get(&cstluckdraw)
879
+	_, err := m.db.Where("customer_id=?", customer.CustomerId).And("luckdraw_id=?", luckdrawid).Get(&cstluckdraw)
880 880
 	if err != nil {
881 881
 		return nil, err
882 882
 	}

+ 32
- 26
service/course/order.go 파일 보기

@@ -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 {

+ 4
- 0
service/goods/orders.go 파일 보기

@@ -209,6 +209,10 @@ func (s *GoodsServ) ConfirmOrder(ordersID string) error {
209 209
 		return utils.LogError("获取订单失败", err)
210 210
 	}
211 211
 
212
+	if orders.Status != models.STATUS_READY {
213
+		return errors.New("没有订单信息")
214
+	}
215
+
212 216
 	// 如果是内部人员
213 217
 	if orders.PayType == models.CONSUME_INNER {
214 218
 		// 查找禁用名单

+ 20
- 23
tests/goodsorder_test.go 파일 보기

@@ -40,34 +40,31 @@ func TestPreGoodsOrder(t *testing.T) {
40 40
 			// 业务返回判断
41 41
 			So(result.Code, ShouldEqual, http.StatusOK)
42 42
 			So(result.Result, ShouldNotBeEmpty)
43
-		})
44
-	})
45
-}
46 43
 
47
-func TestConfirmOrders(t *testing.T) {
48
-	orderID := "cc84338e-488e-463b-a33e-7dc7f2cd10b6"
44
+			orderID := result.Result.(map[string]interface{})["OrdersId"].(string)
49 45
 
50
-	Convey("下单确认", t, func() {
51
-		result := &controllers.JSONMessage{}
52
-		api := "/api/wechat/MQ/order/goods/" + orderID
46
+			Convey("下单确认", func() {
47
+				result := &controllers.JSONMessage{}
48
+				api := "/api/wechat/MQ/order/goods/" + orderID
53 49
 
54
-		token := &utils.JWTToken{
55
-			Guest:   false,
56
-			ID:      "oMOpz0kgTrasoAA3G70R7phomn1g", // openid
57
-			Expire:  time.Now().Local().Add(24 * 30 * time.Hour),
58
-			BatchNo: "",
59
-		}
50
+				token := &utils.JWTToken{
51
+					Guest:   false,
52
+					ID:      "oMOpz0kgTrasoAA3G70R7phomn1g", // openid
53
+					Expire:  time.Now().Local().Add(24 * 30 * time.Hour),
54
+					BatchNo: "",
55
+				}
60 56
 
61
-		code, _, err := NewRequestMock().
62
-			AddToken(token.ToMap()).
63
-			AddWechatUA().
64
-			Request(http.MethodPut, api, nil, result)
57
+				code, _, err := NewRequestMock().
58
+					AddToken(token.ToMap()).
59
+					AddWechatUA().
60
+					Request(http.MethodPut, api, nil, result)
65 61
 
66
-		So(code, ShouldEqual, http.StatusOK)
67
-		So(err, ShouldBeNil)
62
+				So(code, ShouldEqual, http.StatusOK)
63
+				So(err, ShouldBeNil)
68 64
 
69
-		// 业务返回判断
70
-		So(result.Code, ShouldEqual, http.StatusOK)
65
+				// 业务返回判断
66
+				So(result.Code, ShouldEqual, http.StatusOK)
67
+			})
68
+		})
71 69
 	})
72
-
73 70
 }