zjxpcyc 6 vuotta sitten
vanhempi
commit
88f04725b0

+ 1
- 1
conf/log.conf Näytä tiedosto

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

+ 28
- 1
controllers/card/card.go Näytä tiedosto

@@ -169,5 +169,32 @@ func (c *CardController) GiveCard() {
169 169
 
170 170
 // GetCardWithCustomer 获取卡及领取信息
171 171
 func (c *CardController) GetCardWithCustomer() {
172
-	c.ResponseJSON("ok")
172
+	cardid := c.GetString(":id")
173
+	cardDetail, err := c.serv.GetCardWithCustomer(cardid)
174
+	if err != nil {
175
+		c.ResponseError(err)
176
+	}
177
+
178
+	c.ResponseJSON(cardDetail)
179
+}
180
+
181
+// GetCardByCustomer 获取我的卡信息
182
+func (c *CardController) GetCardByCustomer() {
183
+	cards, err := c.serv.GetCardByCustomer()
184
+	if err != nil {
185
+		c.ResponseError(err)
186
+	}
187
+
188
+	c.ResponseJSON(cards)
189
+}
190
+
191
+// GetCustomerCardByID 获取我的卡详情
192
+func (c *CardController) GetCustomerCardByID() {
193
+	id := c.GetString(":id")
194
+	card, err := c.serv.GetCustomerCardByID(id)
195
+	if err != nil {
196
+		c.ResponseError(err)
197
+	}
198
+
199
+	c.ResponseJSON(card)
173 200
 }

+ 11
- 0
controllers/coupon/coupon.go Näytä tiedosto

@@ -199,3 +199,14 @@ func (c *CouponController) GetCouponByCustomer() {
199 199
 
200 200
 	c.ResponseJSON(coupons)
201 201
 }
202
+
203
+// GetCustomerCouponByID 获取我的优惠券详情
204
+func (c *CouponController) GetCustomerCouponByID() {
205
+	id := c.GetString(":id")
206
+	coupon, err := c.serv.GetCustomerCouponByID(id)
207
+	if err != nil {
208
+		c.ResponseError(err)
209
+	}
210
+
211
+	c.ResponseJSON(coupon)
212
+}

+ 7
- 7
controllers/course/order.go Näytä tiedosto

@@ -16,21 +16,21 @@ func (c *CourseController) PostOrder() {
16 16
 	}
17 17
 
18 18
 	// 订单优惠券
19
-	coupons := c.GetString("coupons")
19
+	customercouponid := c.GetString("customercouponid")
20 20
 
21 21
 	//
22 22
 	var orderInfo model.TaCourseOrders
23
-	var orderCoupon []model.TaCourseOrdersCoupon
23
+	//	var orderCoupon []model.TaCourseOrdersCoupon
24 24
 
25 25
 	if err := json.Unmarshal([]byte(info), &orderInfo); err != nil {
26 26
 		utils.LogError("下单转换JSON失败: " + err.Error())
27 27
 		c.ResponseError(errors.New("下单数据格式不正确"))
28 28
 	}
29 29
 
30
-	if err := json.Unmarshal([]byte(coupons), &orderCoupon); err != nil {
31
-		utils.LogError("下单优惠转换JSON失败: " + err.Error())
32
-		c.ResponseError(errors.New("优惠数据格式不正确"))
33
-	}
30
+	// if err := json.Unmarshal([]byte(coupons), &orderCoupon); err != nil {
31
+	// 	utils.LogError("下单优惠转换JSON失败: " + err.Error())
32
+	// 	c.ResponseError(errors.New("优惠数据格式不正确"))
33
+	// }
34 34
 	cust := c.Context.Get("customer").(model.TaCustomer)
35 35
 
36 36
 	if cust.Phone == "" {
@@ -40,7 +40,7 @@ func (c *CourseController) PostOrder() {
40 40
 		)
41 41
 	}
42 42
 
43
-	if err := c.serv.Orders(&orderInfo, orderCoupon); err != nil {
43
+	if err := c.serv.Orders(&orderInfo, customercouponid); err != nil {
44 44
 		c.ResponseError(err)
45 45
 	}
46 46
 

+ 89
- 0
controllers/luckdrawlist/luckdrawlist.go Näytä tiedosto

@@ -0,0 +1,89 @@
1
+package luckdrawlist
2
+
3
+import (
4
+	"spaceofcheng/services/controllers"
5
+	"spaceofcheng/services/models/model"
6
+	"spaceofcheng/services/service/luckdrawlist"
7
+)
8
+
9
+// LuckdrawlistController 信息
10
+type LuckdrawlistController struct {
11
+	dao *luckdrawlist.LuckdrawlistServ
12
+	controllers.BaseController
13
+}
14
+
15
+// Constructor 初始化 Controller
16
+// @Title Constructor
17
+// @Description 初始化 Controller, 系统自动调用
18
+func (c *LuckdrawlistController) Constructor() {
19
+	c.dao = luckdrawlist.NewLuckdrawlistServ(c.Context)
20
+}
21
+func (c *LuckdrawlistController) GetLuckdrawList() {
22
+	caseid := c.GetString("caseid")
23
+	page, _ := c.GetInt("page")
24
+	pagesize, _ := c.GetInt("pagesize")
25
+	if page < 0 {
26
+		page = 1
27
+	}
28
+
29
+	if pagesize <= 0 {
30
+		pagesize = 10
31
+	}
32
+	list, total, err := c.dao.GetLuckdrawList(caseid, page, pagesize)
33
+	if err != nil {
34
+		c.ResponseError(err)
35
+	}
36
+	c.ResponseJSON(map[string]interface{}{
37
+		"list":     list,
38
+		"page":     page,
39
+		"pagesize": pagesize,
40
+		"pagenum":  total,
41
+	})
42
+}
43
+
44
+func (c *LuckdrawlistController) GetLuckShareList() {
45
+	caseid := c.GetString("caseid")
46
+	page, _ := c.GetInt("page")
47
+	pagesize, _ := c.GetInt("pagesize")
48
+	if page < 0 {
49
+		page = 1
50
+	}
51
+
52
+	if pagesize <= 0 {
53
+		pagesize = 10
54
+	}
55
+	toPhone := c.GetString(":toPhone")
56
+	fromPhone := c.GetString(":fromPhone")
57
+	list, total, err := c.dao.GetLuckShareList(caseid, fromPhone, toPhone, page, pagesize)
58
+	if err != nil {
59
+		c.ResponseError(err)
60
+	}
61
+	c.ResponseJSON(map[string]interface{}{
62
+		"list":     list,
63
+		"page":     page,
64
+		"pagesize": pagesize,
65
+		"pagenum":  total,
66
+	})
67
+
68
+}
69
+
70
+func (c *LuckdrawlistController) GetVerifyList() {
71
+	luckdrawId := c.GetString(":luckdrawId")
72
+	luckdraw, err := c.dao.GetVerifyList(luckdrawId)
73
+	if err != nil {
74
+		c.ResponseError(err)
75
+	}
76
+	c.ResponseJSON(luckdraw)
77
+}
78
+
79
+func (c *LuckdrawlistController) VerifyLuckdraw() {
80
+	sysUser := c.Context.Get("user").(model.SysUser)
81
+	userId := sysUser.UserId
82
+	luckdrawId := c.GetString("luckdrawId")
83
+	err := c.dao.VerifyLuckdraw(luckdrawId, userId)
84
+	if err != nil {
85
+		c.ResponseError(err)
86
+	}
87
+	c.ResponseJSON("核销成功")
88
+
89
+}

+ 0
- 23
log/common.log Näytä tiedosto

@@ -1,23 +0,0 @@
1
-2018/09/14 10:52:50 [E] 保存用户映射信息失败: Error 1205: Lock wait timeout exceeded; try restarting transaction
2
-2018/09/14 10:52:51 [E] 保存用户映射信息失败: Error 1205: Lock wait timeout exceeded; try restarting transaction
3
-2018/09/14 10:58:25 [E] 保存用户映射信息失败: Error 1205: Lock wait timeout exceeded; try restarting transaction
4
-2018/09/14 10:58:26 [E] 保存用户映射信息失败: Error 1205: Lock wait timeout exceeded; try restarting transaction
5
-2018/09/14 10:58:27 [E] 保存用户映射信息失败: Error 1205: Lock wait timeout exceeded; try restarting transaction
6
-2018/09/14 11:02:26 [E] 保存用户映射信息失败: Error 1205: Lock wait timeout exceeded; try restarting transaction
7
-2018/09/14 11:04:11 [E] 保存用户映射信息失败: Error 1205: Lock wait timeout exceeded; try restarting transaction
8
-2018/09/14 11:05:15 [E] 保存用户映射信息失败: Error 1205: Lock wait timeout exceeded; try restarting transaction
9
-2018/09/14 11:08:22 [E] 保存用户映射信息失败: Error 1205: Lock wait timeout exceeded; try restarting transaction
10
-2018/09/14 11:15:49 [E] 解析 Token 失败: token contains an invalid number of segments
11
-2018/09/14 11:15:51 [E] 解析 Token 失败: token contains an invalid number of segments
12
-2018/09/14 11:16:16 [E] 保存用户映射信息失败: Error 1205: Lock wait timeout exceeded; try restarting transaction
13
-2018/09/14 11:16:17 [E] 保存用户映射信息失败: Error 1205: Lock wait timeout exceeded; try restarting transaction
14
-2018/09/14 11:17:36 [E] 用户没有设置默认案场
15
-2018/09/14 11:17:44 [E] 用户没有设置默认案场
16
-2018/09/14 11:17:48 [E] 用户没有设置默认案场
17
-2018/09/14 11:36:01 [E] 保存用户映射信息失败: Error 1205: Lock wait timeout exceeded; try restarting transaction
18
-2018/09/14 11:47:35 [E] 保存用户映射信息失败: Error 1205: Lock wait timeout exceeded; try restarting transaction
19
-2018/09/14 11:47:36 [E] 保存用户映射信息失败: Error 1205: Lock wait timeout exceeded; try restarting transaction
20
-2018/09/14 13:33:00 [E] 保存用户映射信息失败: Error 1205: Lock wait timeout exceeded; try restarting transaction
21
-2018/09/14 13:40:39 [E] 保存用户映射信息失败: Error 1205: Lock wait timeout exceeded; try restarting transaction
22
-2018/09/14 13:40:40 [E] 保存用户映射信息失败: Error 1205: Lock wait timeout exceeded; try restarting transaction
23
-2018/09/14 15:01:53 [E] 用户没有设置默认案场

+ 1
- 1
models/bodychecklist/bodychecklist.go Näytä tiedosto

@@ -54,7 +54,7 @@ FROM
54 54
 	ta_body_check a
55 55
 	INNER JOIN ta_customer b ON a.user_id = b.customer_id
56 56
 	INNER JOIN sys_case c ON c.case_id = a.case_id
57
-	where and  a.status > ` + strconv.Itoa(models.STATUS_DEL)
57
+	where %s and  a.status > ` + strconv.Itoa(models.STATUS_DEL)
58 58
 	if phone != "" {
59 59
 		sql += `and b.phone = '` + phone + `'`
60 60
 	}

+ 39
- 3
models/card/card.go Näytä tiedosto

@@ -296,9 +296,45 @@ func (m *CardDAO) GetCardWithCustomer(cardid string) (*CaseUsableCard, error) {
296 296
 	return card, nil
297 297
 }
298 298
 
299
+// CustomerCardWithShare 我的卡券关联分享信息
300
+type CustomerCardWithShare struct {
301
+	model.TaCouponCard `xorm:"extends"`
302
+	Share              *model.TaExperienceCardShare
303
+}
304
+
299 305
 // GetCardByCustomer 获取我的体验卡
300
-func (m *CardDAO) GetCardByCustomer(orgid, customerid string) ([]model.TaCustomerCard, error) {
301
-	var cards []model.TaCustomerCard
302
-	err := m.db.Where("status>?", models.STATUS_DEL).And("customer_id=?", customerid).And("org_id=?", orgid).Find(&cards)
306
+func (m *CardDAO) GetCardByCustomer(orgid, customerid string) ([]CustomerCardWithShare, error) {
307
+	var cards []CustomerCardWithShare
308
+	sql := `select * from ta_customer_card where status>? and customer_id=? and org_id=?`
309
+	err := m.db.Sql(sql, models.STATUS_DEL, customerid, orgid).Find(&cards)
310
+	if err != nil {
311
+		return nil, err
312
+	}
313
+	for inx, card := range cards {
314
+		share, err := m.GetCardShareByCardID(card.CardId)
315
+		if err != nil {
316
+			utils.LogError("获取体验卡失败: " + err.Error())
317
+			return nil, errors.New("获取体验卡失败")
318
+		}
319
+		cards[inx].Share = share
320
+	}
303 321
 	return cards, err
304 322
 }
323
+
324
+// GetCustomerCardByID 获取我的体验卡详情
325
+func (m *CardDAO) GetCustomerCardByID(id string) (*CustomerCardWithShare, error) {
326
+	if id == "" {
327
+		return nil, errors.New("无优惠券信息")
328
+	}
329
+	var customerCard = new(CustomerCardWithShare)
330
+	sql := `select * from ta_customer_card where status>? and customer_card_id=?`
331
+	_, err := m.db.Sql(sql, models.STATUS_DEL, id).Get(customerCard)
332
+
333
+	share, err := m.GetCardShareByCardID(customerCard.CardId)
334
+	if err != nil {
335
+		utils.LogError("获取体验卡失败: " + err.Error())
336
+		return nil, errors.New("获取体验卡失败")
337
+	}
338
+	customerCard.Share = share
339
+	return customerCard, err
340
+}

+ 22
- 9
models/coupon/coupon.go Näytä tiedosto

@@ -382,13 +382,28 @@ func (m *CouponDAO) GetCouponByCustomer(orgid, customerid string) ([]CustomerCou
382 382
 	return coupons, err
383 383
 }
384 384
 
385
-// GetCustomerCouponByID 获取我的优惠券想想
386
-func (m *CouponDAO) GetCustomerCouponByID(id string) (*model.TaCustomerCoupon, error) {
385
+// CustomerCouponWithShare 我的卡券关联分享信息
386
+type CustomerCouponWithShare struct {
387
+	model.TaCustomerCoupon `xorm:"extends"`
388
+	Share                  *model.TaCouponShare
389
+}
390
+
391
+// GetCustomerCouponByID 获取我的优惠券详情
392
+func (m *CouponDAO) GetCustomerCouponByID(id string) (*CustomerCouponWithShare, error) {
387 393
 	if id == "" {
388 394
 		return nil, errors.New("无优惠券信息")
389 395
 	}
390
-	var customerCoupon = new(model.TaCustomerCoupon)
391
-	_, err := m.db.Where("customer_coupon_id=?", id).Get(&customerCoupon)
396
+	var customerCoupon = new(CustomerCouponWithShare)
397
+	sql := `select * from ta_customer_coupon where customer_coupon_id=?`
398
+	_, err := m.db.Sql(sql, id).Get(customerCoupon)
399
+	if err != nil {
400
+		return nil, err
401
+	}
402
+	share := new(model.TaCouponShare)
403
+	if _, err := m.db.Where("coupon_id=?", id).And("status=?", models.STATUS_NORMAL).Get(share); err != nil {
404
+		return nil, err
405
+	}
406
+	customerCoupon.Share = share
392 407
 	return customerCoupon, err
393 408
 }
394 409
 
@@ -426,13 +441,11 @@ func (m *CouponDAO) VerifyCustomerCoupon(id string) error {
426 441
 	var customerCoupon = model.TaCustomerCoupon{
427 442
 		CustomerCouponId: id,
428 443
 		UseDate:          time.Now(),
444
+		Status:           models.STATUS_READY,
429 445
 	}
430 446
 	var cols = []string{
431
-		"area_name",
432
-		"area_icon",
433
-		"area_icon_white",
434
-		"order",
435
-		"case_id",
447
+		"use_date",
448
+		"status",
436 449
 	}
437 450
 	_, err := m.db.Cols(cols...).Where("customer_coupon_id=?", id).Update(customerCoupon)
438 451
 	return err

+ 16
- 0
models/course/order.go Näytä tiedosto

@@ -1,6 +1,8 @@
1 1
 package course
2 2
 
3 3
 import (
4
+	"errors"
5
+	"spaceofcheng/services/models"
4 6
 	"spaceofcheng/services/models/model"
5 7
 	"spaceofcheng/services/utils"
6 8
 	"strings"
@@ -48,3 +50,17 @@ func (m *CourseDAO) SaveCourseOrderDetail(details []model.TaCourseOrdersDetail)
48 50
 	_, err := m.db.Insert(details)
49 51
 	return err
50 52
 }
53
+
54
+// SaveOrdersCoupon 保存订单优惠券
55
+func (m *CourseDAO) SaveOrdersCoupon(coupon *model.TaCourseOrdersCoupon, order *model.TaCourseOrders) error {
56
+	if order.OrdersId == "" {
57
+		return errors.New("内部错误, 订单事务顺序出错")
58
+	}
59
+	coupon.OrdersCouponId = utils.GetGUID()
60
+	coupon.Status = models.STATUS_NORMAL
61
+	coupon.CreateDate = time.Now().Local()
62
+	if _, err := m.db.Insert(coupon); err != nil {
63
+		return err
64
+	}
65
+	return nil
66
+}

+ 5
- 3
models/goods/orders.go Näytä tiedosto

@@ -73,12 +73,14 @@ func (m *GoodsDAO) SaveOrdersDetail(list []model.TaGoodsOrdersDetail, ordersID s
73 73
 }
74 74
 
75 75
 // SaveOrdersCoupon 保存订单优惠券
76
-func (m *GoodsDAO) SaveOrdersCoupon(coupons *model.TaGoodsOrdersCoupon, order *model.TaGoodsOrders) error {
76
+func (m *GoodsDAO) SaveOrdersCoupon(coupon *model.TaGoodsOrdersCoupon, order *model.TaGoodsOrders) error {
77 77
 	if order.OrdersId == "" {
78 78
 		return errors.New("内部错误, 订单事务顺序出错")
79 79
 	}
80
-
81
-	if _, err := m.db.Insert(coupons); err != nil {
80
+	coupon.OrdersCouponId = utils.GetGUID()
81
+	coupon.Status = models.STATUS_NORMAL
82
+	coupon.CreateDate = time.Now().Local()
83
+	if _, err := m.db.Insert(coupon); err != nil {
82 84
 		return err
83 85
 	}
84 86
 

+ 8
- 2
models/gymcard/gymcard.go Näytä tiedosto

@@ -369,7 +369,7 @@ WHERE
369 369
 }
370 370
 
371 371
 // GetCustomerGymById 根据id获取用户健身卡详情
372
-func (m *GymcardDAO) GetCustomerGymById(customerCardId string) (CustomerGym, error) {
372
+func (m *GymcardDAO) GetCustomerGymById(customerCardId string) (*CustomerGym, error) {
373 373
 	var customerGym []CustomerGym
374 374
 	sql := `SELECT
375 375
 	a.*,
@@ -386,7 +386,13 @@ INNER JOIN ta_gym_card d ON a.gym_card_id = d.gym_card_id
386 386
 WHERE
387 387
 	a.customer_gym_id = '` + customerCardId + `' and a.status >` + strconv.Itoa(models.STATUS_DEL)
388 388
 	err := m.db.Sql(sql).Find(&customerGym)
389
-	return customerGym[0], err
389
+	if err != nil {
390
+		return nil, err
391
+	}
392
+	if len(customerGym) > 0 {
393
+		return &customerGym[0], nil
394
+	}
395
+	return nil, err
390 396
 }
391 397
 
392 398
 // AddGiveRecord 新增赠送记录

+ 111
- 0
models/luckdrawlist/luckdrawlist.go Näytä tiedosto

@@ -1,8 +1,11 @@
1 1
 package luckdrawlist
2 2
 
3 3
 import (
4
+	"fmt"
4 5
 	"spaceofcheng/services/models/model"
5 6
 	"spaceofcheng/services/utils"
7
+	"strings"
8
+	"time"
6 9
 
7 10
 	"github.com/go-xorm/xorm"
8 11
 )
@@ -29,3 +32,111 @@ type Luckdraw struct {
29 32
 	CustomerName           string
30 33
 	Phone                  string
31 34
 }
35
+
36
+func (m *LuckdrawDAO) GetLuckdrawList(filters []string, limit []int) ([]Luckdraw, int64, error) {
37
+	var luckdraw []Luckdraw
38
+	filterString := ""
39
+	if len(filters) > 0 {
40
+		filterString = strings.Join(filters, " and ")
41
+		filterString += " and "
42
+	}
43
+	sql := `SELECT
44
+	a.* ,
45
+	c.case_name,
46
+	b.name AS ActivityName,
47
+	d.name,
48
+	d.customer_name,
49
+	d.phone
50
+FROM
51
+	ta_luckdraw_record a
52
+	LEFT JOIN ta_luckdraw b ON a.luckdraw_id = b.id
53
+	LEFT JOIN sys_case c ON a.case_id = c.case_id
54
+	LEFT JOIN ta_customer d ON a.user_id = d.customer_id
55
+	where %s 1=1 `
56
+	sql += ` order by a.create_date desc `
57
+	total, err := utils.NewPageNaviEngine(m.ctx).GetPageList(&luckdraw, fmt.Sprintf(sql, filterString), limit)
58
+	if err != nil {
59
+		return nil, 0, err
60
+	}
61
+	return luckdraw, total, err
62
+
63
+}
64
+
65
+func (m *LuckdrawDAO) GetLuckShareList(fromPhone, toPhone string, filters []string, limit []int) ([]model.TaShareLuckyRecord, int64, error) {
66
+	var luckShare []model.TaShareLuckyRecord
67
+	filterString := ""
68
+	if len(filters) > 0 {
69
+		filterString = strings.Join(filters, " and ")
70
+		filterString += " and "
71
+	}
72
+	sql := `select * from ta_share_lucky_record where %s 1=1`
73
+	if fromPhone != "" {
74
+		sql += ` and from_customer_tel = ` + fromPhone
75
+	}
76
+	if toPhone != "" {
77
+		sql += ` and to_customer_tel = ` + toPhone
78
+	}
79
+	sql += ` order by a.create_date desc `
80
+	total, err := utils.NewPageNaviEngine(m.ctx).GetPageList(&luckShare, fmt.Sprintf(sql, filterString), limit)
81
+	if err != nil {
82
+		return nil, 0, err
83
+	}
84
+	return luckShare, total, err
85
+}
86
+
87
+func (m *LuckdrawDAO) GetLuckdrawById(luckdrawId string) (*Luckdraw, error) {
88
+	var luckdraw []Luckdraw
89
+	sql := `SELECT
90
+	a.*,
91
+	c.case_name,
92
+	b.NAME AS ActivityName,
93
+	d.NAME,
94
+	d.customer_name,
95
+	d.phone 
96
+FROM
97
+	ta_luckdraw_record a
98
+	INNER JOIN ta_luckdraw b ON a.luckdraw_id = b.id
99
+	INNER JOIN sys_case c ON a.case_id = c.case_id
100
+	INNER JOIN ta_customer d ON a.user_id = d.customer_id
101
+	INNER JOIN ta_luckdraw_prize e ON e.id = a.prize_id 
102
+WHERE
103
+	 DATE_FORMAT( e.verification_start, '%Y-%m-%d' ) <= DATE_FORMAT( NOW( ), '%Y-%m-%d' )
104
+	 AND DATE_FORMAT( e.verification_end, '%Y-%m-%d' ) >= DATE_FORMAT( NOW( ), '%Y-%m-%d' )
105
+	 AND a.id = '` + luckdrawId + `'`
106
+	err := m.db.Sql(sql).Find(&luckdraw)
107
+	if err != nil {
108
+		return nil, err
109
+	}
110
+	if len(luckdraw) > 0 {
111
+		return &luckdraw[0], err
112
+	}
113
+	return nil, nil
114
+}
115
+
116
+func (m *LuckdrawDAO) VerifyLuckdraw(luckdrawId int) error {
117
+	var luckdraw = model.TaLuckdrawRecord{
118
+		Id:           luckdrawId,
119
+		WriteoffDate: time.Now(),
120
+		Status:       1,
121
+	}
122
+	var cols = []string{
123
+		"writeoff_date",
124
+		"status",
125
+	}
126
+	_, err := m.db.Cols(cols...).Where("id = ?", luckdraw.Id).Update(luckdraw)
127
+	return err
128
+}
129
+
130
+func (m *LuckdrawDAO) AddWriteoffRecord(luckdraw *Luckdraw, userId string) error {
131
+	var luckWriteoff model.TaLuckdrawWriteoff
132
+	luckWriteoff.CaseId = luckdraw.CaseId
133
+	luckWriteoff.LuckdrawId = luckdraw.LuckdrawId
134
+	luckWriteoff.OrgId = luckdraw.OrgId
135
+	luckWriteoff.RecordId = luckdraw.Id
136
+	luckWriteoff.Status = 0
137
+	luckWriteoff.WriteoffDate = time.Now()
138
+	luckWriteoff.WriteoffUser = userId
139
+	_, err := m.db.Insert(luckWriteoff)
140
+	return err
141
+
142
+}

+ 2
- 2
models/model/ta_luckdraw_record.go Näytä tiedosto

@@ -9,12 +9,12 @@ type TaLuckdrawRecord struct {
9 9
 	LuckdrawId   int       `xorm:"INT(11)"`
10 10
 	PrizeId      int       `xorm:"INT(11)"`
11 11
 	PrizeName    string    `xorm:"VARCHAR(50)"`
12
-	UserId       int       `xorm:"INT(11)"`
12
+	UserId       string    `xorm:"VARCHAR(64)"`
13 13
 	UserName     string    `xorm:"VARCHAR(50)"`
14 14
 	UserHeadImg  string    `xorm:"TEXT"`
15 15
 	CreateDate   time.Time `xorm:"DATETIME"`
16 16
 	Status       int       `xorm:"SMALLINT(6)"`
17 17
 	WriteoffDate time.Time `xorm:"DATETIME"`
18 18
 	OrgId        string    `xorm:"VARCHAR(64)"`
19
-	CaseId       int       `xorm:"INT(11)"`
19
+	CaseId       string    `xorm:"VARCHAR(64)"`
20 20
 }

+ 2
- 2
models/model/ta_luckdraw_writeoff.go Näytä tiedosto

@@ -9,8 +9,8 @@ type TaLuckdrawWriteoff struct {
9 9
 	LuckdrawId   int       `xorm:"INT(11)"`
10 10
 	RecordId     int       `xorm:"INT(11)"`
11 11
 	WriteoffDate time.Time `xorm:"DATETIME"`
12
-	WriteoffUser int       `xorm:"INT(11)"`
12
+	WriteoffUser string    `xorm:"VARCHAR(64)"`
13 13
 	Status       int       `xorm:"SMALLINT(6)"`
14 14
 	OrgId        string    `xorm:"VARCHAR(64)"`
15
-	CaseId       int       `xorm:"INT(11)"`
15
+	CaseId       string    `xorm:"VARCHAR(64)"`
16 16
 }

+ 3
- 3
models/model/ta_share_lucky_record.go Näytä tiedosto

@@ -6,16 +6,16 @@ import (
6 6
 
7 7
 type TaShareLuckyRecord struct {
8 8
 	Id                 int       `xorm:"not null pk autoincr INT(11)"`
9
-	FromCustomerId     int       `xorm:"INT(11)"`
9
+	FromCustomerId     string    `xorm:"VARCHAR(64)"`
10 10
 	FromCustomerName   string    `xorm:"VARCHAR(32)"`
11 11
 	FromCustomerWxname string    `xorm:"VARCHAR(64)"`
12 12
 	FromCustomerTel    string    `xorm:"VARCHAR(32)"`
13
-	ToCustomerId       int       `xorm:"INT(11)"`
13
+	ToCustomerId       string    `xorm:"VARCHAR(64)"`
14 14
 	ToCustomerName     string    `xorm:"VARCHAR(32)"`
15 15
 	ToCustomerWxname   string    `xorm:"VARCHAR(64)"`
16 16
 	ToCustomerTel      string    `xorm:"VARCHAR(32)"`
17 17
 	CreateDate         time.Time `xorm:"DATETIME"`
18
-	CaseId             int       `xorm:"INT(11)"`
18
+	CaseId             string    `xorm:"VARCHAR(64)"`
19 19
 	Status             int       `xorm:"SMALLINT(6)"`
20 20
 	LuckydrawId        int       `xorm:"INT(11)"`
21 21
 	LuckydrawName      string    `xorm:"VARCHAR(128)"`

+ 9
- 0
routers/common.go Näytä tiedosto

@@ -2,6 +2,7 @@ package routers
2 2
 
3 3
 import (
4 4
 	"spaceofcheng/services/controllers"
5
+	"spaceofcheng/services/controllers/bodychecklist"
5 6
 	"spaceofcheng/services/controllers/card"
6 7
 	"spaceofcheng/services/controllers/cases"
7 8
 	"spaceofcheng/services/controllers/channel"
@@ -10,6 +11,7 @@ import (
10 11
 	"spaceofcheng/services/controllers/customer"
11 12
 	"spaceofcheng/services/controllers/goods"
12 13
 	"spaceofcheng/services/controllers/gymcard"
14
+	"spaceofcheng/services/controllers/luckdrawlist"
13 15
 	"spaceofcheng/services/controllers/marketing"
14 16
 	"spaceofcheng/services/controllers/message"
15 17
 	"spaceofcheng/services/controllers/system"
@@ -177,6 +179,13 @@ func getCommonRoutes() beego.LinkNamespace {
177 179
 		beego.NSRouter("/gymcard", &gymcard.GymcardController{}, "post:SaveGymcard"),
178 180
 		beego.NSRouter("/gymcard", &gymcard.GymcardController{}, "put:SaveGymcard"),
179 181
 		beego.NSRouter("/gymcard/:customerGymId", &gymcard.GymcardController{}, "put:VerifyCustomerGymcard"),
182
+		// luckdrawlist 抽奖
183
+		beego.NSRouter("luckdrawlist", &luckdrawlist.LuckdrawlistController{}, "get:GetLuckdrawList"),
184
+		beego.NSRouter("luckdrawlist/:toPhone/:fromPhone", &luckdrawlist.LuckdrawlistController{}, "get:GetLuckShareList"),
185
+		beego.NSRouter("luckdrawlist/:luckdrawId", &luckdrawlist.LuckdrawlistController{}, "get:GetVerifyList"),
186
+		beego.NSRouter("luckdrawlist/:luckdrawId", &luckdrawlist.LuckdrawlistController{}, "put:VerifyLuckdraw"),
187
+		// bodychecklist 体检列表
188
+		beego.NSRouter("bodychecklist", &bodychecklist.BodychecklistController{}, "get:GetBodyCheckList"),
180 189
 		// role 角色
181 190
 		beego.NSRouter("/role", &system.RoleController{}, "get:GetRoleList"),
182 191
 		beego.NSRouter("/role/:roleid", &system.RoleController{}, "get:GetRoleByID"),

+ 3
- 1
routers/wechat.go Näytä tiedosto

@@ -20,7 +20,9 @@ func getWechatRoutes() beego.LinkNamespace {
20 20
 		beego.NSRouter("/customer", &customer.CustomerController{}, "get:GetCustWXByID"),
21 21
 		beego.NSRouter("/customer/user", &user.UserController{}, "get:GetUserCustomer"),
22 22
 		beego.NSRouter("/customer/coupon", &coupon.CouponController{}, "get:GetCouponByCustomer"),
23
-		// beego.NSRouter("/customer/card", &card.CardController{}, "get:GetCardByCustomer"),
23
+		beego.NSRouter("/customer/card", &card.CardController{}, "get:GetCardByCustomer"),
24
+		beego.NSRouter("/customer/coupon/:id", &coupon.CouponController{}, "get:GetCustomerCouponByID"),
25
+		beego.NSRouter("/customer/card/:id", &card.CardController{}, "get:GetCustomerCardByID"),
24 26
 
25 27
 		// 下单
26 28
 		beego.NSRouter("/order/goods", &goods.GoodsController{}, "post:PostOrder"),

+ 15
- 5
service/card/card.go Näytä tiedosto

@@ -275,21 +275,21 @@ func (s *CardServ) GetCardByIDWithCheck(cardID string) (*card.CardInfo, error) {
275 275
 	return card, nil
276 276
 }
277 277
 
278
-// GetCardWithCustomer 获取优惠券明细
278
+// GetCardWithCustomer 获取体验卡明细
279 279
 func (s *CardServ) GetCardWithCustomer(cardid string) (*card.CaseUsableCard, error) {
280 280
 	if cardid == "" {
281 281
 		return nil, errors.New("没有卡信息!")
282 282
 	}
283 283
 	cardDetail, err := s.dao.GetCardDetail(cardid)
284 284
 	if err != nil {
285
-		utils.LogError("获取优惠券失败: " + err.Error())
286
-		return nil, errors.New("获取优惠券失败")
285
+		utils.LogError("获取体验卡失败: " + err.Error())
286
+		return nil, errors.New("获取体验卡失败")
287 287
 	}
288 288
 	return cardDetail, nil
289 289
 }
290 290
 
291
-// GetCardByCustomer 获取我的优惠券
292
-func (s *CardServ) GetCardByCustomer() ([]model.TaCustomerCard, error) {
291
+// GetCardByCustomer 获取我的体验卡
292
+func (s *CardServ) GetCardByCustomer() ([]card.CustomerCardWithShare, error) {
293 293
 	org := s.ctx.Get("org").(model.SysOrg)
294 294
 	customer := s.ctx.Get("customer").(model.TaCustomer)
295 295
 	cards, err := s.dao.GetCardByCustomer(org.OrgId, customer.CustomerId)
@@ -299,3 +299,13 @@ func (s *CardServ) GetCardByCustomer() ([]model.TaCustomerCard, error) {
299 299
 	}
300 300
 	return cards, nil
301 301
 }
302
+
303
+// GetCustomerCardByID 获取我的体验卡详情
304
+func (s *CardServ) GetCustomerCardByID(id string) (*card.CustomerCardWithShare, error) {
305
+	card, err := s.dao.GetCustomerCardByID(id)
306
+	if err != nil {
307
+		utils.LogError("获取体验卡失败: " + err.Error())
308
+		return nil, errors.New("获取体验卡失败")
309
+	}
310
+	return card, nil
311
+}

+ 12
- 0
service/coupon/coupon.go Näytä tiedosto

@@ -393,3 +393,15 @@ func (s *CouponServ) GetCouponByCustomer() ([]coupon.CustomerCoupon, error) {
393 393
 	}
394 394
 	return coupons, nil
395 395
 }
396
+
397
+// GetCustomerCouponByID 获取我的优惠券详情
398
+func (s *CouponServ) GetCustomerCouponByID(id string) (*coupon.CustomerCouponWithShare, error) {
399
+	coupon, err := s.dao.GetCustomerCouponByID(id)
400
+	if err != nil {
401
+		utils.LogError("获取优惠券失败: " + err.Error())
402
+		return nil, errors.New("获取优惠券失败")
403
+	}
404
+	return coupon, nil
405
+}
406
+
407
+//

+ 15
- 10
service/course/course.go Näytä tiedosto

@@ -4,6 +4,7 @@ import (
4 4
 	"errors"
5 5
 	"spaceofcheng/services/models"
6 6
 	"spaceofcheng/services/models/cases"
7
+	"spaceofcheng/services/models/coupon"
7 8
 	"spaceofcheng/services/models/course"
8 9
 	"spaceofcheng/services/models/customer"
9 10
 	"spaceofcheng/services/models/model"
@@ -15,21 +16,23 @@ import (
15 16
 
16 17
 // CourseServ 系统处理
17 18
 type CourseServ struct {
18
-	ctx     *utils.Context
19
-	dao     *course.CourseDAO
20
-	casedao *cases.CaseDAO
21
-	custDAO *customer.CustomerDAO
22
-	userDAO *system.UserDAO
19
+	ctx       *utils.Context
20
+	dao       *course.CourseDAO
21
+	casedao   *cases.CaseDAO
22
+	custDAO   *customer.CustomerDAO
23
+	userDAO   *system.UserDAO
24
+	couponDAO *coupon.CouponDAO
23 25
 }
24 26
 
25 27
 // NewCourseServ 初始化
26 28
 func NewCourseServ(ctx *utils.Context) *CourseServ {
27 29
 	return &CourseServ{
28
-		ctx:     ctx,
29
-		dao:     course.NewCourseDAO(ctx),
30
-		casedao: cases.NewCaseDAO(ctx),
31
-		custDAO: customer.NewCustomerDAO(ctx),
32
-		userDAO: system.NewUserDAO(ctx),
30
+		ctx:       ctx,
31
+		dao:       course.NewCourseDAO(ctx),
32
+		casedao:   cases.NewCaseDAO(ctx),
33
+		custDAO:   customer.NewCustomerDAO(ctx),
34
+		userDAO:   system.NewUserDAO(ctx),
35
+		couponDAO: coupon.NewCouponDAO(ctx),
33 36
 	}
34 37
 }
35 38
 
@@ -145,6 +148,8 @@ func (s *CourseServ) SaveCourse(course model.TaCourse, tagids string) (*model.Ta
145 148
 		return nil, utils.LogError("请选择课程标签!")
146 149
 	}
147 150
 	if course.CourseId == "" {
151
+		org := s.ctx.Get("org").(model.SysOrg)
152
+		course.OrgId = org.OrgId
148 153
 		newInfo, err = s.dao.AddCourse(course)
149 154
 		if err != nil {
150 155
 			utils.LogError("保存课程信息失败: " + err.Error())

+ 93
- 30
service/course/order.go Näytä tiedosto

@@ -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,91 @@ 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
+			couseOrder.CouponAmount = couseOrder.Price
104
+		} else {
105
+			for _, target := range coupon.Targets {
106
+				if target.TargetId == course.CourseId {
107
+					isdy = true
108
+				}
109
+			}
110
+			couseOrder.CouponAmount = coupon.Price
111
+		}
112
+		if !isdy {
113
+			return errors.New("优惠券不可抵用该课程")
114
+		}
115
+		var ordersCoupon = model.TaCourseOrdersCoupon{
116
+			OrdersId:   couseOrder.OrdersId,
117
+			CouponId:   coupon.CouponId,
118
+			CouponName: coupon.CouponName,
119
+			UsedAmount: couseOrder.CouponAmount,
120
+		}
121
+		if err := s.dao.SaveOrdersCoupon(&ordersCoupon, couseOrder); err != nil {
122
+			utils.LogError("保存优惠信息出错: " + err.Error())
123
+			return errors.New("保存优惠信息出错")
124
+		}
125
+
126
+		// 优惠券核销
127
+		err = s.couponDAO.VerifyCustomerCoupon(customercouponid)
128
+		if err != nil {
129
+			utils.LogError("优惠券核销出错: " + err.Error())
130
+			return errors.New("优惠券核销出错")
131
+		}
132
+	} else {
133
+		couseOrder.PayType = models.CONSUME_COINCHG
134
+	}
135
+
136
+	couponAmount, _ := strconv.ParseFloat(couseOrder.CouponAmount, 64)
137
+	payMoney, _ := strconv.ParseFloat(couseOrder.Price, 64)
138
+	payMoney = payMoney - couponAmount
139
+
140
+	couseOrder.ActualAmount = strconv.FormatFloat(payMoney, 'f', -1, 64)
141
+
142
+	// 校验金额
143
+	// if err := s.validBillCharges(couseOrder, coupons); err != nil {
144
+	// 	return err
145
+	// }
76 146
 
77 147
 	// 实际支付
78
-	actualAmount, _ := strconv.ParseFloat(couseOrder.ActualAmount, 64)
148
+	actualAmount := payMoney
79 149
 
80 150
 	// 用户账户  -- 内部人员也可以购买
81 151
 	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 152
 
90 153
 		if actualAmount > accMoney {
91 154
 			return errors.New("账户余额不足")
@@ -99,7 +162,7 @@ func (s *CourseServ) Orders(
99 162
 	}
100 163
 
101 164
 	// 入库
102
-	if err := s.SaveOrder(couseOrder, coupons, course); err != nil {
165
+	if err := s.SaveOrder(couseOrder, course); err != nil {
103 166
 		utils.LogError("课程下单失败: " + err.Error())
104 167
 		return errors.New("下单失败, 请重试")
105 168
 	}
@@ -226,7 +289,7 @@ func (s *CourseServ) saveCustomerPayRec(account *model.TaCustomerAccount, info *
226 289
 }
227 290
 
228 291
 // SaveOrder 保存订单明细
229
-func (s *CourseServ) SaveOrder(order *model.TaCourseOrders, coupons []model.TaCourseOrdersCoupon, course *course.CourseDetail) error {
292
+func (s *CourseServ) SaveOrder(order *model.TaCourseOrders, course *course.CourseDetail) error {
230 293
 	// 订单信息
231 294
 	if err := s.dao.SaveCourseOrder(order); err != nil {
232 295
 		utils.LogError("课程下单失败: " + err.Error())
@@ -234,16 +297,16 @@ func (s *CourseServ) SaveOrder(order *model.TaCourseOrders, coupons []model.TaCo
234 297
 	}
235 298
 
236 299
 	// 默认城币购买
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
-	}
300
+	// courseObtaimType := models.COURSE_GETBY_COINCHG
301
+	// if coupons != nil && len(coupons) > 0 {
302
+	// 	for _, c := range coupons {
303
+	// 		if c.CouponType == models.COURSE_COUPON_CARD {
304
+	// 			courseObtaimType = models.COURSE_GETBY_CARD
305
+	// 		} else if c.CouponType == models.COURSE_COUPON_COUPON {
306
+	// 			courseObtaimType = models.COURSE_GETBY_COUPON
307
+	// 		}
308
+	// 	}
309
+	// }
247 310
 
248 311
 	// 我的课程信息
249 312
 	custCourse := model.TaCustomerCourse{
@@ -257,7 +320,7 @@ func (s *CourseServ) SaveOrder(order *model.TaCourseOrders, coupons []model.TaCo
257 320
 		CourseNum:        course.CourseNum,
258 321
 		JoinNum:          0,
259 322
 		CreateDate:       time.Now().Local(),
260
-		CourseObtaimType: courseObtaimType,
323
+		CourseObtaimType: order.PayType,
261 324
 		SourceId:         order.OrdersId,
262 325
 		IsDone:           models.BOOL_FALSE,
263 326
 	}

+ 29
- 9
service/goods/orders.go Näytä tiedosto

@@ -57,26 +57,46 @@ func (s *GoodsServ) Orders(
57 57
 		// 如果是使用优惠券
58 58
 		if customercouponid != "" {
59 59
 			info.PayType = models.CONSUME_COUPON
60
+
61
+			// 优惠券校验
62
+			customerCoupon, err := s.couponDAO.GetCustomerCouponByID(customercouponid)
63
+			if err != nil {
64
+				utils.LogError("查询优惠券信息失败: " + err.Error())
65
+				return errors.New("查询优惠券信息失败")
66
+			}
67
+			if customerCoupon == nil || customerCoupon.CustomerCouponId == "" {
68
+				return errors.New("优惠券无效!")
69
+			}
70
+			if customerCoupon.Status != models.STATUS_NORMAL || !customerCoupon.UseDate.IsZero() {
71
+				return errors.New("优惠券已被使用!请重新选择优惠券!")
72
+			}
73
+
60 74
 			// 根据id获取优惠券信息
61 75
 			coupon, err := s.couponDAO.GetCouponInfoByCustomerCouponID(customercouponid)
62 76
 			if err != nil {
63 77
 				utils.LogError("查询优惠券信息失败: " + err.Error())
64 78
 				return errors.New("查询优惠券信息失败")
65 79
 			}
66
-			// 优惠券校验
67
-			// s.couponDAO.GetCustomerCouponByID
68 80
 			// 遍历优惠券可抵用的商品
69 81
 			var dyGoods = model.TaGoodsOrdersDetail{
70 82
 				Price:   "0.0",
71 83
 				GoodsId: "",
72 84
 			}
73 85
 			for _, detail := range details {
74
-				for _, target := range coupon.Targets {
75
-					if target.TargetId == detail.GoodsId {
76
-						dyprice, _ := strconv.ParseFloat(dyGoods.Price, 64)
77
-						detailprice, _ := strconv.ParseFloat(detail.Price, 64)
78
-						if dyprice < detailprice {
79
-							dyGoods = detail
86
+				if coupon.IsAll == 1 {
87
+					dyprice, _ := strconv.ParseFloat(dyGoods.Price, 64)
88
+					detailprice, _ := strconv.ParseFloat(detail.Price, 64)
89
+					if dyprice < detailprice {
90
+						dyGoods = detail
91
+					}
92
+				} else {
93
+					for _, target := range coupon.Targets {
94
+						if target.TargetId == detail.GoodsId {
95
+							dyprice, _ := strconv.ParseFloat(dyGoods.Price, 64)
96
+							detailprice, _ := strconv.ParseFloat(detail.Price, 64)
97
+							if dyprice < detailprice {
98
+								dyGoods = detail
99
+							}
80 100
 						}
81 101
 					}
82 102
 				}
@@ -107,7 +127,7 @@ func (s *GoodsServ) Orders(
107 127
 					return errors.New("优惠券核销出错")
108 128
 				}
109 129
 			} else {
110
-				info.CouponAmount = "0.0"
130
+				return errors.New("优惠券不可抵用商品")
111 131
 			}
112 132
 		} else {
113 133
 			// 如果是使用城币

+ 1
- 6
service/gymcard/gymcard.go Näytä tiedosto

@@ -10,8 +10,6 @@ import (
10 10
 	"spaceofcheng/services/utils"
11 11
 	"strings"
12 12
 	"time"
13
-
14
-	"github.com/astaxie/beego"
15 13
 )
16 14
 
17 15
 // GymcardServ 系统处理
@@ -119,7 +117,7 @@ func (s *GymcardServ) GetCustomerGymDetailById(customerGymId string) (*gymcard.C
119 117
 		utils.LogError("获取健身卡详情失败" + err.Error())
120 118
 		return nil, errors.New("获取健身卡详情失败")
121 119
 	}
122
-	return &customerGym, err
120
+	return customerGym, err
123 121
 }
124 122
 
125 123
 // SaveGymcard 保存游泳健身卡
@@ -161,9 +159,6 @@ func (s *GymcardServ) SaveGymcard(newGym gymcard.Gymcard) (*gymcard.Gymcard, err
161 159
 		utils.LogError("保存健身卡信息失败" + err.Error())
162 160
 		return nil, errors.New("保存健身卡信息失败")
163 161
 	}
164
-	beego.Error("-------------------------------------")
165
-	beego.Error(newGym)
166
-	beego.Error("-------------------------------------")
167 162
 	return &newGym, nil
168 163
 }
169 164
 

+ 131
- 0
service/luckdrawlist/luckdrawlist.go Näytä tiedosto

@@ -0,0 +1,131 @@
1
+package luckdrawlist
2
+
3
+import (
4
+	"errors"
5
+	"spaceofcheng/services/models/luckdrawlist"
6
+	"spaceofcheng/services/models/model"
7
+	"spaceofcheng/services/utils"
8
+	"strconv"
9
+	"strings"
10
+)
11
+
12
+// LuckdrawlistServ 系统处理
13
+type LuckdrawlistServ struct {
14
+	ctx *utils.Context
15
+	dao *luckdrawlist.LuckdrawDAO
16
+}
17
+
18
+// NewLuckdrawlistServ 初始化
19
+func NewLuckdrawlistServ(ctx *utils.Context) *LuckdrawlistServ {
20
+	return &LuckdrawlistServ{
21
+		ctx: ctx,
22
+		dao: luckdrawlist.NewLuckdrawDAO(ctx),
23
+	}
24
+}
25
+func (s *LuckdrawlistServ) GetLuckShareList(caseID, fromPhone, toPhone string, pagenavi ...int) ([]model.TaShareLuckyRecord, int64, error) {
26
+	filters := []string{}
27
+	if caseID != "" {
28
+		if err := utils.NewAuthEngine(s.ctx).CheckCase(caseID); err != nil {
29
+			return nil, 0, err
30
+		}
31
+
32
+		filters = []string{
33
+			"case_id='" + caseID + "'",
34
+		}
35
+	} else {
36
+		casesRaw := s.ctx.Get("cases")
37
+		if casesRaw == nil {
38
+			return nil, 0, errors.New("请设置过滤案场")
39
+		}
40
+
41
+		cases := casesRaw.([]model.SysUserCase)
42
+		caseIDs := []string{}
43
+		for _, cs := range cases {
44
+			caseIDs = append(caseIDs, cs.CaseId)
45
+		}
46
+
47
+		filters = []string{
48
+			"case_id in ('" + strings.Join(caseIDs, "','") + "')",
49
+		}
50
+	}
51
+
52
+	limit := utils.GetPageNaviLimit(pagenavi...)
53
+	res, total, err := s.dao.GetLuckShareList(fromPhone, toPhone, filters, limit)
54
+	if err != nil {
55
+		utils.LogError("查询卡列表失败: " + err.Error())
56
+		return nil, 0, errors.New("查询卡列表失败")
57
+	}
58
+
59
+	return res, total, nil
60
+
61
+}
62
+
63
+func (s *LuckdrawlistServ) GetLuckdrawList(caseID string, pagenavi ...int) ([]luckdrawlist.Luckdraw, int64, error) {
64
+	filters := []string{}
65
+	if caseID != "" {
66
+		if err := utils.NewAuthEngine(s.ctx).CheckCase(caseID); err != nil {
67
+			return nil, 0, err
68
+		}
69
+
70
+		filters = []string{
71
+			"case_id='" + caseID + "'",
72
+		}
73
+	} else {
74
+		casesRaw := s.ctx.Get("cases")
75
+		if casesRaw == nil {
76
+			return nil, 0, errors.New("请设置过滤案场")
77
+		}
78
+
79
+		cases := casesRaw.([]model.SysUserCase)
80
+		caseIDs := []string{}
81
+		for _, cs := range cases {
82
+			caseIDs = append(caseIDs, cs.CaseId)
83
+		}
84
+
85
+		filters = []string{
86
+			"case_id in ('" + strings.Join(caseIDs, "','") + "')",
87
+		}
88
+	}
89
+
90
+	limit := utils.GetPageNaviLimit(pagenavi...)
91
+	res, total, err := s.dao.GetLuckdrawList(filters, limit)
92
+	if err != nil {
93
+		utils.LogError("查询抽奖列表失败: " + err.Error())
94
+		return nil, 0, errors.New("查询抽奖列表失败")
95
+	}
96
+
97
+	return res, total, nil
98
+
99
+}
100
+
101
+func (s *LuckdrawlistServ) GetVerifyList(luckdrawId string) (*luckdrawlist.Luckdraw, error) {
102
+	luckdraw, err := s.dao.GetLuckdrawById(luckdrawId)
103
+	if err != nil {
104
+		utils.LogError("查询抽奖列表失败: " + err.Error())
105
+		return nil, errors.New("查询抽奖列表失败")
106
+	}
107
+	return luckdraw, nil
108
+
109
+}
110
+
111
+func (s *LuckdrawlistServ) VerifyLuckdraw(luckdrawId, userId string) error {
112
+	luckdraw, err := s.dao.GetLuckdrawById(luckdrawId)
113
+
114
+	luckdrawIdInt, err := strconv.Atoi(luckdrawId)
115
+	if err != nil {
116
+		utils.LogError("核销失败: " + err.Error())
117
+		return errors.New("核销失败")
118
+	}
119
+	err = s.dao.VerifyLuckdraw(luckdrawIdInt)
120
+	if err != nil {
121
+		utils.LogError("核销失败: " + err.Error())
122
+		return errors.New("核销失败")
123
+	}
124
+	err = s.dao.AddWriteoffRecord(luckdraw, userId)
125
+	if err != nil {
126
+		utils.LogError("核销失败: " + err.Error())
127
+		return errors.New("核销失败")
128
+	}
129
+	return nil
130
+
131
+}