wangfei 6 gadus atpakaļ
vecāks
revīzija
64478f9f19

+ 8
- 0
log/common.log Parādīt failu

@@ -271,3 +271,11 @@
271 271
 2018/09/19 17:42:09 [E] 用户没有设置默认案场
272 272
 2018/09/19 17:42:09 [E] 用户没有设置默认案场
273 273
 2018/09/19 17:51:33 [E] 获取用户基本信息失败: 没有查询到 ID (OPENID) 对应的用户
274
+2018/09/19 18:58:01 [E] 获取发送卡信息失败: Error 1054: Unknown column 'serial_code' in 'field list'
275
+2018/09/19 18:58:01 [E] 获取人员信息失败: 获取人员信息失败
276
+2018/09/19 19:00:04 [E] 获取发送卡信息失败: Error 1054: Unknown column 'price' in 'field list'
277
+2018/09/19 19:00:04 [E] 获取人员信息失败: 获取人员信息失败
278
+2018/09/19 19:00:37 [E] 获取发送券信息失败: Error 1054: Unknown column 'serial_code' in 'field list'
279
+2018/09/19 19:00:37 [E] 获取人员信息失败: 获取人员信息失败
280
+2018/09/19 19:06:05 [E] 获取发送券信息失败: Error 1054: Unknown column 'price' in 'field list'
281
+2018/09/19 19:06:05 [E] 获取人员信息失败: 获取人员信息失败

+ 41
- 0
models/card/card.go Parādīt failu

@@ -34,6 +34,7 @@ type CardInfo struct {
34 34
 	Images             []model.TaExperienceCardImage
35 35
 	Targets            []model.TaCouponCardTarget
36 36
 	Share              *model.TaExperienceCardShare
37
+	ChannelId          string
37 38
 }
38 39
 
39 40
 // GetCardList 获取卡列表
@@ -83,6 +84,13 @@ func (m *CardDAO) GetCardByID(cardid string) (*CardInfo, error) {
83 84
 		return nil, err
84 85
 	}
85 86
 	card[0].Share = share
87
+	channel, err := m.GetCardChannel(cardid)
88
+	if err != nil {
89
+		return nil, err
90
+	}
91
+	if channel != nil {
92
+		card[0].ChannelId = channel.ChannelId
93
+	}
86 94
 	return &card[0], err
87 95
 }
88 96
 
@@ -414,3 +422,36 @@ func (m *CardDAO) GetCustomerNoCardByCustomer(customerid, orgid string) ([]model
414 422
 	}
415 423
 	return cards, nil
416 424
 }
425
+
426
+// GetCardChannel 获取卡对应渠道
427
+func (m *CardDAO) GetCardChannel(cardid string) (*model.TaCardCouponChannel, error) {
428
+	var channels []model.TaCardCouponChannel
429
+	err := m.db.Where("card_coupon_type=?", models.COURSE_COUPON_CARD).And("card_coupon_id=?", cardid).And("status=?", models.STATUS_NORMAL).Find(&channels)
430
+	if err != nil {
431
+		return nil, err
432
+	}
433
+	if len(channels) > 0 {
434
+		return &channels[0], nil
435
+	}
436
+	return nil, nil
437
+}
438
+
439
+// DelCardChannel 删除卡对应渠道
440
+func (m *CardDAO) DelCardChannel(cardid string) error {
441
+	sql := `delete from ta_card_coupon_channel where card_coupon_id=? and card_coupon_type=?`
442
+	_, err := m.db.Exec(sql, cardid, models.COURSE_COUPON_CARD)
443
+	return err
444
+}
445
+
446
+// SaveCardChannel 保存卡对应渠道
447
+func (m *CardDAO) SaveCardChannel(channelid, cardid string) error {
448
+	var cardChannel = model.TaCardCouponChannel{
449
+		CardCouponChannelId: utils.GetGUID(),
450
+		CardCouponId:        cardid,
451
+		ChannelId:           channelid,
452
+		CardCouponType:      models.COURSE_COUPON_CARD,
453
+		Status:              models.STATUS_NORMAL,
454
+	}
455
+	_, err := m.db.Insert(&cardChannel)
456
+	return err
457
+}

+ 41
- 0
models/coupon/coupon.go Parādīt failu

@@ -86,6 +86,14 @@ func (m *CouponDAO) GetCouponInfoByID(id string) (*CouponInfo, error) {
86 86
 	cp.Rules = rules
87 87
 	cp.Share = share
88 88
 
89
+	channel, err := m.GetCouponChannel(id)
90
+	if err != nil {
91
+		return nil, err
92
+	}
93
+	if channel != nil {
94
+		cp.ChannelId = channel.ChannelId
95
+	}
96
+
89 97
 	return cp, nil
90 98
 }
91 99
 
@@ -519,3 +527,36 @@ func (m *CouponDAO) GetNoCouponByCustomer(orgid, customerid string) ([]model.TaC
519 527
 	err := m.db.Sql(sql, models.STATUS_DEL, customerid, orgid).Find(&coupons)
520 528
 	return coupons, err
521 529
 }
530
+
531
+// GetCouponChannel 获取优惠券对应渠道
532
+func (m *CouponDAO) GetCouponChannel(couponid string) (*model.TaCardCouponChannel, error) {
533
+	var channels []model.TaCardCouponChannel
534
+	err := m.db.Where("card_coupon_type=?", models.COURSE_COUPON_COUPON).And("card_coupon_id=?", couponid).And("status=?", models.STATUS_NORMAL).Find(&channels)
535
+	if err != nil {
536
+		return nil, err
537
+	}
538
+	if len(channels) > 0 {
539
+		return &channels[0], nil
540
+	}
541
+	return nil, nil
542
+}
543
+
544
+// DelCouponChannel 删除优惠券对应渠道
545
+func (m *CouponDAO) DelCouponChannel(couponid string) error {
546
+	sql := `delete from ta_card_coupon_channel where card_coupon_id=? and card_coupon_type=?`
547
+	_, err := m.db.Exec(sql, couponid, models.COURSE_COUPON_COUPON)
548
+	return err
549
+}
550
+
551
+// SaveCouponChannel 保存优惠券对应渠道
552
+func (m *CouponDAO) SaveCouponChannel(channelid, couponid string) error {
553
+	var couponChannel = model.TaCardCouponChannel{
554
+		CardCouponChannelId: utils.GetGUID(),
555
+		CardCouponId:        couponid,
556
+		ChannelId:           channelid,
557
+		CardCouponType:      models.COURSE_COUPON_COUPON,
558
+		Status:              models.STATUS_NORMAL,
559
+	}
560
+	_, err := m.db.Insert(&couponChannel)
561
+	return err
562
+}

+ 1
- 0
models/coupon/types.go Parādīt failu

@@ -17,6 +17,7 @@ type CouponInfo struct {
17 17
 	Targets        []model.TaCouponTarget
18 18
 	Images         []model.TaCouponImage
19 19
 	Rules          []model.TaCouponRule
20
+	ChannelId      string
20 21
 }
21 22
 
22 23
 // CaseUsableCoupon 案场可用优惠券信息

+ 21
- 0
service/card/card.go Parādīt failu

@@ -122,6 +122,14 @@ func (s *CardServ) SaveCard(cd *card.CardInfo) error {
122 122
 		return errors.New("保存卡关联内容失败")
123 123
 	}
124 124
 
125
+	// 保存渠道
126
+	if cd.ChannelId != "" {
127
+		if err := s.dao.SaveCardChannel(cd.ChannelId, cd.CardId); err != nil {
128
+			utils.LogError("保存对应渠道失败: " + err.Error())
129
+			return errors.New("保存对应渠道失败")
130
+		}
131
+	}
132
+
125 133
 	return nil
126 134
 }
127 135
 
@@ -158,6 +166,19 @@ func (s *CardServ) UpdateCard(cd *card.CardInfo) error {
158 166
 		return errors.New("更新卡分享失败")
159 167
 	}
160 168
 
169
+	// 删除渠道
170
+	if err := s.dao.DelCardChannel(cd.CardId); err != nil {
171
+		utils.LogError("删除对应渠道信息失败: " + err.Error())
172
+		return errors.New("删除对应渠道信息失败")
173
+	}
174
+
175
+	// 保存渠道
176
+	if cd.ChannelId != "" {
177
+		if err := s.dao.SaveCardChannel(cd.ChannelId, cd.CardId); err != nil {
178
+			utils.LogError("保存对应渠道失败: " + err.Error())
179
+			return errors.New("保存对应渠道失败")
180
+		}
181
+	}
161 182
 	// 关联内容 规则 不允许更新
162 183
 	return nil
163 184
 }

+ 21
- 0
service/coupon/coupon.go Parādīt failu

@@ -124,6 +124,14 @@ func (s *CouponServ) SaveCoupon(cp *coupon.CouponInfo) error {
124 124
 		return errors.New("保存优惠券规则失败")
125 125
 	}
126 126
 
127
+	// 保存渠道
128
+	if cp.ChannelId != "" {
129
+		if err := s.dao.SaveCouponChannel(cp.ChannelId, cp.CouponId); err != nil {
130
+			utils.LogError("保存对应渠道失败: " + err.Error())
131
+			return errors.New("保存对应渠道失败")
132
+		}
133
+	}
134
+
127 135
 	return nil
128 136
 }
129 137
 
@@ -183,6 +191,19 @@ func (s *CouponServ) UpdateCoupon(cp *coupon.CouponInfo) error {
183 191
 		return errors.New("保存优惠券规则失败")
184 192
 	}
185 193
 
194
+	// 删除渠道
195
+	if err := s.dao.DelCouponChannel(cp.CouponId); err != nil {
196
+		utils.LogError("删除对应渠道信息失败: " + err.Error())
197
+		return errors.New("删除对应渠道信息失败")
198
+	}
199
+
200
+	// 保存渠道
201
+	if cp.ChannelId != "" {
202
+		if err := s.dao.SaveCouponChannel(cp.ChannelId, cp.CouponId); err != nil {
203
+			utils.LogError("保存对应渠道失败: " + err.Error())
204
+			return errors.New("保存对应渠道失败")
205
+		}
206
+	}
186 207
 	return nil
187 208
 }
188 209
 

+ 1
- 1
service/course/course.go Parādīt failu

@@ -141,7 +141,7 @@ func (s *CourseServ) SaveCourse(course model.TaCourse, tagids string) (*model.Ta
141 141
 	if course.BeginDate.IsZero() || course.EndDate.IsZero() {
142 142
 		return nil, utils.LogError("课程时间不允许为空!")
143 143
 	}
144
-	if !course.EndDate.After(course.BeginDate) {
144
+	if !course.EndDate.After(course.BeginDate) && course.EndDate != course.BeginDate {
145 145
 		return nil, utils.LogError("截止时间必须大于开始时间!")
146 146
 	}
147 147
 	if tagids == "" {