wangfei пре 6 година
родитељ
комит
4b142763bf

+ 12
- 0
controllers/card/card.go Прегледај датотеку

@@ -198,3 +198,15 @@ func (c *CardController) GetCustomerCardByID() {
198 198
 
199 199
 	c.ResponseJSON(card)
200 200
 }
201
+
202
+// GetCaseUsableCard 获取案场可用券
203
+func (c *CardController) GetCaseUsableCard() {
204
+	page, _ := c.GetInt("page")
205
+	pageSize, _ := c.GetInt("pagesize")
206
+	cards, err := c.serv.GetCaseUsableCard(page, pageSize)
207
+	if err != nil {
208
+		c.ResponseError(err)
209
+	}
210
+
211
+	c.ResponseJSON(cards)
212
+}

+ 12
- 0
controllers/coupon/coupon.go Прегледај датотеку

@@ -210,3 +210,15 @@ func (c *CouponController) GetCustomerCouponByID() {
210 210
 
211 211
 	c.ResponseJSON(coupon)
212 212
 }
213
+
214
+// GetCaseUsableCoupon 获取案场可用券
215
+func (c *CouponController) GetCaseUsableCoupon() {
216
+	page, _ := c.GetInt("page")
217
+	pageSize, _ := c.GetInt("pagesize")
218
+	coupons, err := c.serv.GetCaseUsableCoupon(page, pageSize)
219
+	if err != nil {
220
+		c.ResponseError(err)
221
+	}
222
+
223
+	c.ResponseJSON(coupons)
224
+}

+ 6
- 0
log/common.log Прегледај датотеку

@@ -0,0 +1,6 @@
1
+2018/09/14 16:15:08 [E] 获取发送卡信息失败: Error 1054: Unknown column 'serial_code' in 'field list'
2
+2018/09/14 16:15:08 [E] 获取人员信息失败: 获取人员信息失败
3
+2018/09/14 16:20:29 [E] 获取发送卡信息失败: Error 1054: Unknown column 'serial_code' in 'field list'
4
+2018/09/14 16:20:29 [E] 获取人员信息失败: 获取人员信息失败
5
+2018/09/14 16:21:28 [E] 获取发送卡信息失败: Error 1054: Unknown column 'serial_code' in 'field list'
6
+2018/09/14 16:21:28 [E] 获取人员信息失败: 获取人员信息失败

+ 9
- 0
models/card/card.go Прегледај датотеку

@@ -235,6 +235,15 @@ func (m *CardDAO) GetCaseUsableCard(caseid, userid string, page, pageSize int) (
235 235
 	return cards, err
236 236
 }
237 237
 
238
+// GetCaseUsableCardCount 获取案场可用卡数量
239
+func (m *CardDAO) GetCaseUsableCardCount(caseid, userid string) (int, error) {
240
+	var Coupons []CaseUsableCard
241
+	sql := `select * from ta_coupon_card where case_id=? and status=? and end_date>now()`
242
+	err := m.db.Sql(sql, caseid, models.STATUS_NORMAL).Find(&Coupons)
243
+
244
+	return len(Coupons), err
245
+}
246
+
238 247
 // GetCustomerCardByCardAndUser 根据卡与用户获取领取的用户信息
239 248
 func (m *CardDAO) GetCustomerCardByCardAndUser(cardid, userid string) ([]model.TaCustomerCard, error) {
240 249
 	var customerCards []model.TaCustomerCard

+ 14
- 0
models/coupon/coupon.go Прегледај датотеку

@@ -305,6 +305,15 @@ func (m *CouponDAO) GetCaseUsableCoupon(caseid, userid string, page, pageSize in
305 305
 	return Coupons, err
306 306
 }
307 307
 
308
+// GetCaseUsableCouponCount 获取案场可用优惠券数量
309
+func (m *CouponDAO) GetCaseUsableCouponCount(caseid, userid string) (int, error) {
310
+	var Coupons []CaseCouponDetail
311
+	sql := `select * from ta_coupon where case_id=? and status=? and end_date>now()`
312
+	err := m.db.Sql(sql, caseid, models.STATUS_NORMAL).Find(&Coupons)
313
+
314
+	return len(Coupons), err
315
+}
316
+
308 317
 // GetCustomerCouponByCouponAndUser 根据优惠券与用户获取领取的用户信息
309 318
 func (m *CouponDAO) GetCustomerCouponByCouponAndUser(couponid, userid string) ([]model.TaCustomerCoupon, error) {
310 319
 	var customerCoupons []model.TaCustomerCoupon
@@ -450,3 +459,8 @@ func (m *CouponDAO) VerifyCustomerCoupon(id string) error {
450 459
 	_, err := m.db.Cols(cols...).Where("customer_coupon_id=?", id).Update(customerCoupon)
451 460
 	return err
452 461
 }
462
+
463
+// ReceiveCoupon 领取优惠券
464
+func (m *CouponDAO) ReceiveCoupon(couponid string) {
465
+
466
+}

+ 1
- 0
models/model/ta_customer_card.go Прегледај датотеку

@@ -19,4 +19,5 @@ type TaCustomerCard struct {
19 19
 	CaseId           string    `xorm:"VARCHAR(64)"`
20 20
 	OrgId            string    `xorm:"VARCHAR(64)"`
21 21
 	VerifyStatus     string    `xorm:"VARCHAR(32)"`
22
+	SerialCode       string    `xorm:"VARCHAR(64)"`
22 23
 }

+ 1
- 0
models/model/ta_customer_coupon.go Прегледај датотеку

@@ -18,4 +18,5 @@ type TaCustomerCoupon struct {
18 18
 	UseDate            time.Time `xorm:"DATETIME"`
19 19
 	CaseId             string    `xorm:"VARCHAR(64)"`
20 20
 	OrgId              string    `xorm:"VARCHAR(64)"`
21
+	SerialCode         string    `xorm:"VARCHAR(64)"`
21 22
 }

+ 0
- 2
models/system/user.go Прегледај датотеку

@@ -405,7 +405,6 @@ type UserWithType struct {
405 405
 	model.SysUser `xorm:"extends"`
406 406
 	TypeId        string
407 407
 	TypeName      string
408
-	CaseId        string
409 408
 }
410 409
 
411 410
 // GetUserWithTypeByID 获取用户类型
@@ -414,7 +413,6 @@ func (m *UserDAO) GetUserWithTypeByID(userID string) ([]UserWithType, error) {
414 413
 		SELECT
415 414
 			t.*, m.type_id,
416 415
 			m.type_name,
417
-			m.case_id
418 416
 		FROM
419 417
 			sys_user t
420 418
 		JOIN sys_user_type s ON t.user_id = s.user_id

+ 2
- 0
routers/wechat.go Прегледај датотеку

@@ -53,10 +53,12 @@ func getWechatRoutes() beego.LinkNamespace {
53 53
 		beego.NSRouter("/user/detail/:id", &user.UserController{}, "get:GetCaseUserByID"),
54 54
 
55 55
 		// 优惠券
56
+		beego.NSRouter("/coupon", &coupon.CouponController{}, "get:GetCaseUsableCoupon"),
56 57
 		beego.NSRouter("/coupon/:id", &coupon.CouponController{}, "get:GetCouponByID"),
57 58
 		beego.NSRouter("/coupon/detail/:id", &coupon.CouponController{}, "get:GetCouponWithCustomer"),
58 59
 
59 60
 		// 卡
61
+		beego.NSRouter("/card", &card.CardController{}, "get:GetCaseUsableCard"),
60 62
 		beego.NSRouter("/card/:id", &card.CardController{}, "get:GetCardByID"),
61 63
 		beego.NSRouter("/card/detail/:id", &card.CardController{}, "get:GetCardWithCustomer"),
62 64
 	)

+ 50
- 0
service/card/card.go Прегледај датотеку

@@ -6,6 +6,8 @@ import (
6 6
 	"spaceofcheng/services/models/card"
7 7
 	"spaceofcheng/services/models/customer"
8 8
 	"spaceofcheng/services/models/model"
9
+	"spaceofcheng/services/models/system"
10
+	"spaceofcheng/services/service"
9 11
 	"spaceofcheng/services/utils"
10 12
 	"strings"
11 13
 	"time"
@@ -18,6 +20,7 @@ type CardServ struct {
18 20
 	ctx     *utils.Context
19 21
 	dao     *card.CardDAO
20 22
 	custDao *customer.CustomerDAO
23
+	userDao *system.UserDAO
21 24
 }
22 25
 
23 26
 // NewCardServ 初始化
@@ -26,6 +29,7 @@ func NewCardServ(ctx *utils.Context) *CardServ {
26 29
 		ctx:     ctx,
27 30
 		dao:     card.NewCardDAO(ctx),
28 31
 		custDao: customer.NewCustomerDAO(ctx),
32
+		userDao: system.NewUserDAO(ctx),
29 33
 	}
30 34
 }
31 35
 
@@ -309,3 +313,49 @@ func (s *CardServ) GetCustomerCardByID(id string) (*card.CustomerCardWithShare,
309 313
 	}
310 314
 	return card, nil
311 315
 }
316
+
317
+// GetCaseUsableCard 获取案场可用卡
318
+func (s *CardServ) GetCaseUsableCard(page, pageSize int) (map[string]interface{}, error) {
319
+
320
+	if pageSize == 0 {
321
+		pageSize = service.PAGENUM
322
+	}
323
+	if page == 0 {
324
+		page = 1
325
+	}
326
+	customer := s.ctx.Get("Customer").(model.TaCustomer)
327
+	if customer.UserId == "" {
328
+		return nil, errors.New("您没有权限查看数据")
329
+	}
330
+	userTypes, err := s.userDao.GetUserWithTypeByID(customer.UserId)
331
+	if err != nil {
332
+		utils.LogError("获取用户信息失败: " + err.Error())
333
+		return nil, errors.New("获取用户信息失败")
334
+	}
335
+	if len(userTypes) > 0 {
336
+		return nil, errors.New("您没有权限查看数据")
337
+	}
338
+	caseinfo, err := s.userDao.GetUserBelongCase(customer.UserId)
339
+	if err != nil {
340
+		return nil, errors.New("您没有案场信息!")
341
+	}
342
+	var userid = ""
343
+	if userTypes[0].TypeId != models.USERTYPE_MANAGER {
344
+		userid = customer.UserId
345
+	}
346
+	coupons, err := s.dao.GetCaseUsableCard(caseinfo.CaseId, userid, page, pageSize)
347
+	if err != nil {
348
+		return nil, errors.New("获取数据失败!")
349
+	}
350
+	total, err := s.dao.GetCaseUsableCardCount(caseinfo.CaseId, userid)
351
+	if err != nil {
352
+		utils.LogError("获取商品规格失败: " + err.Error())
353
+		return nil, errors.New("获取商品规格失败")
354
+	}
355
+	return map[string]interface{}{
356
+		"list":     coupons,
357
+		"pagesize": pageSize,
358
+		"pagenum":  total,
359
+		"page":     page,
360
+	}, nil
361
+}

+ 58
- 12
service/coupon/coupon.go Прегледај датотеку

@@ -6,12 +6,12 @@ import (
6 6
 	"spaceofcheng/services/models/coupon"
7 7
 	"spaceofcheng/services/models/customer"
8 8
 	"spaceofcheng/services/models/model"
9
+	"spaceofcheng/services/models/system"
10
+	"spaceofcheng/services/service"
9 11
 	"spaceofcheng/services/utils"
10 12
 	"strings"
11 13
 	"time"
12 14
 
13
-	"github.com/astaxie/beego"
14
-
15 15
 	"github.com/yl10/kit/guid"
16 16
 )
17 17
 
@@ -20,6 +20,7 @@ type CouponServ struct {
20 20
 	ctx     *utils.Context
21 21
 	dao     *coupon.CouponDAO
22 22
 	custDao *customer.CustomerDAO
23
+	userDao *system.UserDAO
23 24
 }
24 25
 
25 26
 // NewCouponServ 初始化
@@ -28,6 +29,7 @@ func NewCouponServ(ctx *utils.Context) *CouponServ {
28 29
 		ctx:     ctx,
29 30
 		dao:     coupon.NewCouponDAO(ctx),
30 31
 		custDao: customer.NewCustomerDAO(ctx),
32
+		userDao: system.NewUserDAO(ctx),
31 33
 	}
32 34
 }
33 35
 
@@ -269,15 +271,15 @@ func (s *CouponServ) GiveCouponTo(from *model.SysUser, to *model.TaCustomer, cp
269 271
 	}
270 272
 
271 273
 	// 检查用户是否已经有了该券
272
-	custCPS, err := s.dao.CheckCustCoupon(to.CustomerId, cp.CouponId, startDate, endDate)
273
-	if err != nil {
274
-		utils.LogError("校验客户优惠券失败: " + err.Error())
275
-		return errors.New("校验客户优惠券失败")
276
-	}
277
-	beego.Error(custCPS)
278
-	if custCPS != nil && len(custCPS) > 0 {
279
-		return errors.New("客户 " + to.CustomerName + " 已经拥有该券")
280
-	}
274
+	// custCPS, err := s.dao.CheckCustCoupon(to.CustomerId, cp.CouponId, startDate, endDate)
275
+	// if err != nil {
276
+	// 	utils.LogError("校验客户优惠券失败: " + err.Error())
277
+	// 	return errors.New("校验客户优惠券失败")
278
+	// }
279
+	// beego.Error(custCPS)
280
+	// if custCPS != nil && len(custCPS) > 0 {
281
+	// 	return errors.New("客户 " + to.CustomerName + " 已经拥有该券")
282
+	// }
281 283
 
282 284
 	// 放入我的卡券
283 285
 	custCP := model.TaCustomerCoupon{
@@ -404,4 +406,48 @@ func (s *CouponServ) GetCustomerCouponByID(id string) (*coupon.CustomerCouponWit
404 406
 	return coupon, nil
405 407
 }
406 408
 
407
-//
409
+// GetCaseUsableCoupon 获取案场可用券
410
+func (s *CouponServ) GetCaseUsableCoupon(page, pageSize int) (map[string]interface{}, error) {
411
+
412
+	if pageSize == 0 {
413
+		pageSize = service.PAGENUM
414
+	}
415
+	if page == 0 {
416
+		page = 1
417
+	}
418
+	customer := s.ctx.Get("Customer").(model.TaCustomer)
419
+	if customer.UserId == "" {
420
+		return nil, errors.New("您没有权限查看数据")
421
+	}
422
+	userTypes, err := s.userDao.GetUserWithTypeByID(customer.UserId)
423
+	if err != nil {
424
+		utils.LogError("获取用户信息失败: " + err.Error())
425
+		return nil, errors.New("获取用户信息失败")
426
+	}
427
+	if len(userTypes) > 0 {
428
+		return nil, errors.New("您没有权限查看数据")
429
+	}
430
+	caseinfo, err := s.userDao.GetUserBelongCase(customer.UserId)
431
+	if err != nil {
432
+		return nil, errors.New("您没有案场信息!")
433
+	}
434
+	var userid = ""
435
+	if userTypes[0].TypeId != models.USERTYPE_MANAGER {
436
+		userid = customer.UserId
437
+	}
438
+	coupons, err := s.dao.GetCaseUsableCoupon(caseinfo.CaseId, userid, page, pageSize)
439
+	if err != nil {
440
+		return nil, errors.New("获取数据失败!")
441
+	}
442
+	total, err := s.dao.GetCaseUsableCouponCount(caseinfo.CaseId, userid)
443
+	if err != nil {
444
+		utils.LogError("获取商品规格失败: " + err.Error())
445
+		return nil, errors.New("获取商品规格失败")
446
+	}
447
+	return map[string]interface{}{
448
+		"list":     coupons,
449
+		"pagesize": pageSize,
450
+		"pagenum":  total,
451
+		"page":     page,
452
+	}, nil
453
+}

+ 8
- 7
service/goods/orders.go Прегледај датотеку

@@ -284,15 +284,16 @@ func (s *GoodsServ) validOrdersInfo(info *model.TaGoodsOrders) error {
284 284
 					return errors.New("下单人状态不正确, 不能下单")
285 285
 				}
286 286
 
287
-				if ut.CaseId == caseID {
288
-					info.UserType = ut.TypeId
287
+				info.UserType = ut.TypeId
289 288
 
290
-					// 下单人姓名 - 姓名不存在则用昵称
291
-					info.UserName = ut.RealName
292
-					if info.UserName == "" {
293
-						info.UserName = cust.CustomerName
294
-					}
289
+				// 下单人姓名 - 姓名不存在则用昵称
290
+				info.UserName = ut.RealName
291
+				if info.UserName == "" {
292
+					info.UserName = cust.CustomerName
295 293
 				}
294
+				// if ut.CaseId == caseID {
295
+
296
+				// }
296 297
 			}
297 298
 		}
298 299