Sfoglia il codice sorgente

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

胡轶钦 6 anni fa
parent
commit
dccb5dbefb

+ 2
- 2
conf/db.conf Vedi File

@@ -5,9 +5,9 @@ db_type      = mysql
5 5
 con_protocol = tcp
6 6
 
7 7
 ; 数据库地址,可以使用IP
8
-; db_addr      = 47.101.36.130
8
+db_addr      = 47.101.36.130
9 9
 # db_addr        = 192.168.0.122
10
-db_addr = localhost
10
+; db_addr = localhost
11 11
 # db_addr      = rm-uf6z3z6jq11x653d77o.mysql.rds.aliyuncs.com
12 12
 
13 13
 ; 端口

+ 1
- 1
conf/log.conf Vedi File

@@ -1,4 +1,4 @@
1 1
 [common]
2
-filename="E:\\GoProject\\src\\spaceofcheng\\services\\log\\common.log"
2
+filename="E:\\GoProjects\\src\\spaceofcheng\\services\\log\\common.log"
3 3
 # log level "emergency", "alert", "critical", "error", "warning", "notice", "info", "debug"
4 4
 level="debug"

+ 1
- 1
models/card/card.go Vedi File

@@ -481,7 +481,7 @@ func (m *CardDAO) GetCustomerCardByCustomerAndSaleCount(customerid, saleid strin
481 481
 // GetCustomerCardByCustomerAndSale 获取用户的领取记录
482 482
 func (m *CardDAO) GetCustomerCardByCustomerAndSale(customerid, saleid string, page, pageSize int) ([]model.TaCustomerCard, error) {
483 483
 	var customerCard []model.TaCustomerCard
484
-	err := m.db.Where("customer_id=?", customerid).And("sales_id=?", saleid).Desc("status").Limit(pageSize, (page-1)*pageSize).Find(&customerCard)
484
+	err := m.db.Where("customer_id=?", customerid).And("sales_id=?", saleid).OrderBy("status asc,receive_date desc").Limit(pageSize, (page-1)*pageSize).Find(&customerCard)
485 485
 	return customerCard, err
486 486
 }
487 487
 

+ 1
- 1
models/coupon/coupon.go Vedi File

@@ -542,7 +542,7 @@ func (m *CouponDAO) GetCustomerCouponByCustomerAndSaleCount(customerid, saleid s
542 542
 // GetCustomerCouponByCustomerAndSale 获取用户的领取记录
543 543
 func (m *CouponDAO) GetCustomerCouponByCustomerAndSale(customerid, saleid string, page, pageSize int) ([]model.TaCustomerCoupon, error) {
544 544
 	var customerCoupon []model.TaCustomerCoupon
545
-	err := m.db.Where("customer_id=?", customerid).And("sales_id=?", saleid).Desc("status").Limit(pageSize, (page-1)*pageSize).Find(&customerCoupon)
545
+	err := m.db.Where("customer_id=?", customerid).And("sales_id=?", saleid).OrderBy("status asc,receive_date desc").Limit(pageSize, (page-1)*pageSize).Find(&customerCoupon)
546 546
 	return customerCoupon, err
547 547
 }
548 548
 

+ 4
- 0
models/flashbuy/flashbuy.go Vedi File

@@ -272,6 +272,10 @@ func (m *FlashbuyDAO) GetCustomerFlashBuy(id, customerid string) ([]model.TaCust
272 272
 func (m *FlashbuyDAO) UpdateFlashBuyJoin(id string) (int64, error) {
273 273
 	sql := `update ta_flash_buy set join_num = join_num + 1 where flash_buy_id=? and join_num < flash_buy_max_attendant`
274 274
 	result, err := m.db.Exec(sql, id)
275
+	if err != nil {
276
+		return 0, err
277
+	}
278
+
275 279
 	rowCount, err := result.RowsAffected()
276 280
 	return rowCount, err
277 281
 }

+ 4
- 4
models/statistics/cardcoupon.go Vedi File

@@ -278,8 +278,8 @@ func (m *StatisticsDAO) CardCouponUsedStatistics(caseids, tel, name, receivetype
278 278
 								INNER JOIN sys_case b ON a.case_id = b.case_id
279 279
 								INNER JOIN ta_customer cst ON a.customer_id = cst.customer_id
280 280
 								INNER JOIN ta_coupon cp ON a.coupon_id = cp.coupon_id
281
-								LEFT JOIN ta_goods_orders_coupon c ON a.coupon_id = c.coupon_id
282
-								LEFT JOIN ta_course_orders_coupon d ON a.coupon_id = d.coupon_id
281
+								LEFT JOIN ta_goods_orders_coupon c ON a.customer_coupon_id = c.customer_coupon_id
282
+								LEFT JOIN ta_course_orders_coupon d ON a.customer_coupon_id = d.customer_coupon_id
283 283
 								WHERE b.case_id in ('` + strings.Replace(caseids, ",", "','", -1) + `')`
284 284
 
285 285
 	sql := "select * from (" + cardsql + " union " + couponsql + ") tab where (1=1)"
@@ -378,8 +378,8 @@ func (m *StatisticsDAO) CardCouponUsedCountStatistics(caseids, tel, name, receiv
378 378
 								INNER JOIN sys_case b ON a.case_id = b.case_id
379 379
 								INNER JOIN ta_customer cst ON a.customer_id = cst.customer_id
380 380
 								INNER JOIN ta_coupon cp ON a.coupon_id = cp.coupon_id
381
-								LEFT JOIN ta_goods_orders_coupon c ON a.coupon_id = c.coupon_id
382
-								LEFT JOIN ta_course_orders_coupon d ON a.coupon_id = d.coupon_id
381
+								LEFT JOIN ta_goods_orders_coupon c ON a.customer_coupon_id = c.customer_coupon_id
382
+								LEFT JOIN ta_course_orders_coupon d ON a.customer_coupon_id = d.customer_coupon_id
383 383
 								WHERE b.case_id in ('` + strings.Replace(caseids, ",", "','", -1) + `')`
384 384
 
385 385
 	sql := "select * from (" + cardsql + " union " + couponsql + ") tab where (1=1)"

+ 8
- 0
models/sys.go Vedi File

@@ -270,3 +270,11 @@ func GetAllCases() ([]model.SysCase, error) {
270 270
 	err := DBEngine.Where("status=?", STATUS_NORMAL).Asc("org_id").Find(&cases)
271 271
 	return cases, err
272 272
 }
273
+
274
+// GetCaseByID 获取案场
275
+func GetCaseByID(caseID string) (cs *model.SysCase, err error) {
276
+	cs = new(model.SysCase)
277
+
278
+	_, err = DBEngine.Where("case_id=?", caseID).Get(cs)
279
+	return
280
+}

+ 12
- 0
service/course/order.go Vedi File

@@ -175,6 +175,18 @@ func (s *CourseServ) ConfirmOrders(ordersID, customercouponid string) error {
175 175
 			utils.LogError("优惠券核销出错: " + err.Error())
176 176
 			return errors.New("优惠券核销出错")
177 177
 		}
178
+		// 券库存处理
179
+		var couponinfo = model.TaCoupon{
180
+			CouponId:  coupon.CouponId,
181
+			UsedCount: coupon.UsedCount + 1,
182
+		}
183
+		cols := []string{
184
+			"used_count",
185
+		}
186
+		if err := s.couponDAO.UpdateCoupon(&couponinfo, cols); err != nil {
187
+			utils.LogError("回填优惠券信息失败:", err)
188
+			return errors.New("回填优惠券信息失败!")
189
+		}
178 190
 	} else {
179 191
 		couseOrder.PayType = models.CONSUME_COINCHG
180 192
 		couseOrder.CouponAmount = "0.0"

+ 12
- 2
service/events/events.go Vedi File

@@ -42,6 +42,7 @@ func ListenAllEvent(orgID, caseID string) {
42 42
 	for evt, acts := range allEvts {
43 43
 		for _, actKey := range acts {
44 44
 			act, ok := EvtActions[actKey]
45
+
45 46
 			if ok {
46 47
 				evtEngine.ListenEvent(evt, act)
47 48
 			}
@@ -66,7 +67,11 @@ func getAllEvents(orgID, caseID string) (map[string][]string, error) {
66 67
 
67 68
 	res := make(map[string][]string)
68 69
 	for _, evtSetting := range evts {
69
-		res[evtSetting.ActivityType] = make([]string, 0)
70
+		tpEvts, ok := res[evtSetting.ActivityType]
71
+		if !ok {
72
+			tpEvts = make([]string, 0)
73
+		}
74
+
70 75
 		acts = make([]model.SysActivityAction, 0)
71 76
 
72 77
 		if err := db.Where("activity_id=?", evtSetting.ActivityId).Find(&acts); err != nil {
@@ -75,8 +80,13 @@ func getAllEvents(orgID, caseID string) (map[string][]string, error) {
75 80
 		}
76 81
 
77 82
 		for _, act := range acts {
78
-			res[evtSetting.ActivityType] = append(res[evtSetting.ActivityType], act.ActiveType)
83
+			// 加入 tpEvts 需要去重
84
+			if utils.StrSliceIndexOf(tpEvts, act.ActiveType) == -1 {
85
+				tpEvts = append(tpEvts, act.ActiveType)
86
+			}
79 87
 		}
88
+
89
+		res[evtSetting.ActivityType] = tpEvts
80 90
 	}
81 91
 
82 92
 	return res, nil

+ 4
- 4
service/events/giveCard.go Vedi File

@@ -18,8 +18,8 @@ var giveCard = func(e tinyevent.Event) error {
18 18
 	defer DestroyContext(ctx, false)
19 19
 
20 20
 	if e.Payload == nil {
21
-		utils.LogError("注册送失败, 没有用户信息")
22
-		return errors.New("注册送失败, 没有用户信息")
21
+		utils.LogError("注册送失败, 没有用户信息")
22
+		return errors.New("注册送失败, 没有用户信息")
23 23
 	}
24 24
 	cust := e.Payload.(model.TaCustomer)
25 25
 	caseID := cust.RecommendCase
@@ -67,12 +67,12 @@ var giveCard = func(e tinyevent.Event) error {
67 67
 
68 68
 			cp, err := cpServ.GetCardByID(cpID.(string))
69 69
 			if err != nil {
70
-				utils.LogError("获取优惠券失败: " + err.Error())
70
+				utils.LogError("获取体验卡失败: " + err.Error())
71 71
 				continue
72 72
 			}
73 73
 
74 74
 			if err := cpServ.GiveCardTo(&fromUser, &cust, cp); err != nil {
75
-				utils.LogError("送失败: " + err.Error())
75
+				utils.LogError("送失败: " + err.Error())
76 76
 				continue
77 77
 			}
78 78
 		default:

+ 2
- 1
service/events/giveCoupon.go Vedi File

@@ -7,6 +7,7 @@ import (
7 7
 	"spaceofcheng/services/models/model"
8 8
 	"spaceofcheng/services/service/coupon"
9 9
 	"spaceofcheng/services/utils"
10
+	"strings"
10 11
 
11 12
 	"github.com/zjxpcyc/tinyevent"
12 13
 )
@@ -61,7 +62,7 @@ var giveCoupon = func(e tinyevent.Event) error {
61 62
 		switch act.ActiveType {
62 63
 		case ActGiveCoupon:
63 64
 			res := make(map[string]interface{})
64
-			if err := json.Unmarshal([]byte(act.ResourceDesc), &res); err != nil {
65
+			if err := json.Unmarshal([]byte(strings.Replace(act.ResourceDesc, "\n", "\\n", -1)), &res); err != nil {
65 66
 				utils.LogError("解析优惠券赠送规则失败: " + err.Error())
66 67
 				continue
67 68
 			}

+ 9
- 9
service/flashbuy/flashbuy.go Vedi File

@@ -206,6 +206,7 @@ func (s *FlashBuyServ) GetCustomerFlashBuyId(customerFlashBuyId string) (*flashb
206 206
 // FlashBuy 抢购
207 207
 func (s *FlashBuyServ) FlashBuy(id string) error {
208 208
 	flashbuy, err := s.dao.GetFlashBuyById(id)
209
+	utils.LogError("-----------------抢购校验开始")
209 210
 	if err != nil {
210 211
 		utils.LogError("获取抢购活动信息失败: " + err.Error())
211 212
 		return errors.New("获取抢购活动信息失败!")
@@ -231,6 +232,7 @@ func (s *FlashBuyServ) FlashBuy(id string) error {
231 232
 	if len(buys) > 0 {
232 233
 		return errors.New("您已参与过该活动!")
233 234
 	}
235
+	utils.LogError("-----------------抢购------")
234 236
 	if flashbuy.JoinNum >= flashbuy.FlashBuyMaxAttendant {
235 237
 		err = s.dao.UpdateFlashBuy(flashbuy.FlashBuyId, models.FLASH_BUY_OVER)
236 238
 		if err != nil {
@@ -279,23 +281,21 @@ func (s *FlashBuyServ) FlashBuy(id string) error {
279 281
 		utils.LogError("插入中奖二维码失败: " + err.Error())
280 282
 		return errors.New("写入中奖二维码失败")
281 283
 	}
284
+	// ---------------推送消息
282 285
 
283 286
 	// 推送微信消息
284 287
 	userMap := s.ctx.Get("userMap").(model.TaUserMapping)
285
-	userCases := s.ctx.Get("cases").([]model.SysUserCase)
286 288
 	clienturl := s.ctx.Get("clienturl").(string)
287 289
 	tplID := s.ctx.Get("tplid").(string)
288 290
 
289
-	var caseName string
290
-	if userCases != nil && len(userCases) > 0 {
291
-		for _, cs := range userCases {
292
-			if cs.CaseId == recored.CaseId {
293
-				caseName = cs.CaseName
294
-				break
295
-			}
296
-		}
291
+	cs, err := models.GetCaseByID(recored.CaseId)
292
+	if err != nil {
293
+		utils.LogError("推送微信消息失败, 查询案场信息出错: " + err.Error())
294
+		// 但是不返回错误
295
+		return nil
297 296
 	}
298 297
 
298
+	caseName := cs.CaseName
299 299
 	remarkTpl := "请在%s日前, 前往%s兑换"
300 300
 
301 301
 	message := utils.Message{

+ 15
- 2
service/goods/orders.go Vedi File

@@ -94,7 +94,7 @@ func (s *GoodsServ) ConfirmOrder(ordersID, customercouponid, remark string) erro
94 94
 		info.Remark = remark
95 95
 	}
96 96
 
97
-	if info.PayType == "sales" {
97
+	if info.PayType == models.CONSUME_INNER {
98 98
 		// 内部人员, 可以直接购买
99 99
 		// TODO
100 100
 	} else {
@@ -189,6 +189,18 @@ func (s *GoodsServ) ConfirmOrder(ordersID, customercouponid, remark string) erro
189 189
 					utils.LogError("优惠券核销出错: " + err.Error())
190 190
 					return errors.New("优惠券核销出错")
191 191
 				}
192
+				// 券库存处理
193
+				var couponinfo = model.TaCoupon{
194
+					CouponId:  coupon.CouponId,
195
+					UsedCount: coupon.UsedCount + 1,
196
+				}
197
+				cols := []string{
198
+					"used_count",
199
+				}
200
+				if err := s.couponDAO.UpdateCoupon(&couponinfo, cols); err != nil {
201
+					utils.LogError("回填优惠券信息失败:", err)
202
+					return errors.New("回填优惠券信息失败!")
203
+				}
192 204
 			} else {
193 205
 				return errors.New("优惠券不可抵用商品")
194 206
 			}
@@ -270,7 +282,8 @@ func (s *GoodsServ) ConfirmOrder(ordersID, customercouponid, remark string) erro
270 282
 	if err := s.dao.UpdateOrders(&orders, []string{
271 283
 		"status", "is_pay", "coupon_amount", "actual_amount",
272 284
 	}); err != nil {
273
-		return nil
285
+		utils.LogError("修改订单状态失败:", err.Error())
286
+		return err
274 287
 	}
275 288
 
276 289
 	newOrder, err := s.GetNewGoods(info.OrdersId)

+ 31
- 32
service/luckdraw/luckdraw.go Vedi File

@@ -2,6 +2,7 @@ package luckdraw
2 2
 
3 3
 import (
4 4
 	"errors"
5
+	"fmt"
5 6
 	"spaceofcheng/services/models"
6 7
 	"spaceofcheng/services/models/course"
7 8
 	"spaceofcheng/services/models/luckdraw"
@@ -336,38 +337,36 @@ func (s *LuckdrawServ) LuckDraw(id string, user *model.TaCustomer) (*model.TaLuc
336 337
 	}
337 338
 
338 339
 	// 推送微信消息
339
-	// userMap := s.ctx.Get("userMap").(model.TaUserMapping)
340
-	// userCases := s.ctx.Get("cases").([]model.SysUserCase)
341
-	// clienturl := s.ctx.Get("clienturl").(string)
342
-	// tplID := s.ctx.Get("tplid").(string)
343
-
344
-	// var caseName string
345
-	// if userCases != nil && len(userCases) > 0 {
346
-	// 	for _, cs := range userCases {
347
-	// 		if cs.CaseId == recored.CaseId {
348
-	// 			caseName = cs.CaseName
349
-	// 			break
350
-	// 		}
351
-	// 	}
352
-	// }
353
-
354
-	// remarkTpl := "请在%s日前, 前往%s兑换"
355
-
356
-	// message := utils.Message{
357
-	// 	To: utils.ClientID{ID: userMap.Openid},
358
-	// 	Data: map[string]interface{}{
359
-	// 		"orgid": recored.OrgId,
360
-	// 		"tplid": tplID,
361
-	// 		"link":  clienturl,
362
-	// 		"data": map[string]string{
363
-	// 			"first":    "抢券成功提醒",
364
-	// 			"keyword1": prize.PrizeName,
365
-	// 			"keyword2": time.Now().Local().Format("2006-01-02"),
366
-	// 			"remark":   fmt.Sprintf(remarkTpl, recored.VerificationEnd.Format("2006-01-02"), caseName),
367
-	// 		},
368
-	// 	},
369
-	// }
370
-	// go utils.SendWechat(message)
340
+	userMap := s.ctx.Get("userMap").(model.TaUserMapping)
341
+	clienturl := s.ctx.Get("clienturl").(string)
342
+	tplID := s.ctx.Get("tplid").(string)
343
+
344
+	cs, err := models.GetCaseByID(recored.CaseId)
345
+	if err != nil {
346
+		utils.LogError("推送微信消息失败, 查询案场信息出错: " + err.Error())
347
+		// 但是不返回错误
348
+		return nil, nil, nil
349
+	}
350
+
351
+	caseName := cs.CaseName
352
+	remarkTpl := "请在%s日前, 前往%s兑换"
353
+
354
+	message := utils.Message{
355
+		To: utils.ClientID{ID: userMap.Openid},
356
+		Data: map[string]interface{}{
357
+			"orgid": recored.OrgId,
358
+			"tplid": tplID,
359
+			"link":  clienturl,
360
+			"data": map[string]string{
361
+				"first":    "中奖成功提醒",
362
+				"keyword1": prize.PrizeName,
363
+				"keyword2": time.Now().Local().Format("2006-01-02"),
364
+				"remark":   fmt.Sprintf(remarkTpl, recored.VerificationEnd.Format("2006-01-02"), caseName),
365
+			},
366
+		},
367
+	}
368
+
369
+	go utils.SendWechat(message)
371 370
 
372 371
 	return prize, prizeDetail, nil
373 372
 }

+ 2
- 1
service/marketing/marketing.go Vedi File

@@ -12,6 +12,7 @@ import (
12 12
 	"spaceofcheng/services/service"
13 13
 	"spaceofcheng/services/service/events"
14 14
 	"spaceofcheng/services/utils"
15
+	"strings"
15 16
 
16 17
 	"github.com/astaxie/beego"
17 18
 )
@@ -70,7 +71,7 @@ func (s *MarketingServ) GetMarketingList(caseids string, page int, pageSize int)
70 71
  */
71 72
 func (s *MarketingServ) SaveMarketing(activity model.SysActivity, activeType, resourceDesc string) (*model.SysActivity, *model.SysActivityAction, error) {
72 73
 	res := make(map[string]interface{})
73
-	if err := json.Unmarshal([]byte(resourceDesc), &res); err != nil {
74
+	if err := json.Unmarshal([]byte(strings.Replace(resourceDesc, "\n", "\\n", -1)), &res); err != nil {
74 75
 		utils.LogError("校验活动数据失败: " + err.Error())
75 76
 		return nil, nil, errors.New("校验活动数据失败")
76 77
 	}

+ 0
- 1
service/sys.go Vedi File

@@ -182,7 +182,6 @@ func (s *SysServ) authWechat(gctx *context.Context) map[string]interface{} {
182 182
 
183 183
 		// 获取 token
184 184
 		token, err := s.getToken(gctx)
185
-		utils.LogError("token:", token)
186 185
 		if err != nil {
187 186
 			tokenStr := s.ctx.Get("token").(string)
188 187
 			if tokenStr != "" {