浏览代码

代码上传

wangfei 6 年前
父节点
当前提交
a681642d9c
共有 6 个文件被更改,包括 64 次插入15 次删除
  1. 32
    6
      models/card/card.go
  2. 18
    3
      models/coupon/coupon.go
  3. 8
    2
      models/gymcard/gymcard.go
  4. 2
    2
      service/card/card.go
  5. 3
    1
      service/coupon/coupon.go
  6. 1
    1
      service/gymcard/gymcard.go

+ 32
- 6
models/card/card.go 查看文件

@@ -296,19 +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
 }
305 323
 
306 324
 // GetCustomerCardByID 获取我的体验卡详情
307
-func (m *CardDAO) GetCustomerCardByID(id string) (*model.TaCustomerCard, error) {
325
+func (m *CardDAO) GetCustomerCardByID(id string) (*CustomerCardWithShare, error) {
308 326
 	if id == "" {
309 327
 		return nil, errors.New("无优惠券信息")
310 328
 	}
311
-	var customerCard = new(model.TaCustomerCard)
312
-	_, err := m.db.Where("customer_card_id=?", id).Get(customerCard)
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
313 339
 	return customerCard, err
314 340
 }

+ 18
- 3
models/coupon/coupon.go 查看文件

@@ -382,13 +382,28 @@ func (m *CouponDAO) GetCouponByCustomer(orgid, customerid string) ([]CustomerCou
382 382
 	return coupons, err
383 383
 }
384 384
 
385
+// CustomerCouponWithShare 我的卡券关联分享信息
386
+type CustomerCouponWithShare struct {
387
+	model.TaCustomerCoupon `xorm:"extends"`
388
+	Share                  *model.TaCouponShare
389
+}
390
+
385 391
 // GetCustomerCouponByID 获取我的优惠券详情
386
-func (m *CouponDAO) GetCustomerCouponByID(id string) (*model.TaCustomerCoupon, error) {
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
 

+ 8
- 2
models/gymcard/gymcard.go 查看文件

@@ -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 新增赠送记录

+ 2
- 2
service/card/card.go 查看文件

@@ -289,7 +289,7 @@ func (s *CardServ) GetCardWithCustomer(cardid string) (*card.CaseUsableCard, err
289 289
 }
290 290
 
291 291
 // GetCardByCustomer 获取我的体验卡
292
-func (s *CardServ) GetCardByCustomer() ([]model.TaCustomerCard, error) {
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)
@@ -301,7 +301,7 @@ func (s *CardServ) GetCardByCustomer() ([]model.TaCustomerCard, error) {
301 301
 }
302 302
 
303 303
 // GetCustomerCardByID 获取我的体验卡详情
304
-func (s *CardServ) GetCustomerCardByID(id string) (*model.TaCustomerCard, error) {
304
+func (s *CardServ) GetCustomerCardByID(id string) (*card.CustomerCardWithShare, error) {
305 305
 	card, err := s.dao.GetCustomerCardByID(id)
306 306
 	if err != nil {
307 307
 		utils.LogError("获取体验卡失败: " + err.Error())

+ 3
- 1
service/coupon/coupon.go 查看文件

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

+ 1
- 1
service/gymcard/gymcard.go 查看文件

@@ -117,7 +117,7 @@ func (s *GymcardServ) GetCustomerGymDetailById(customerGymId string) (*gymcard.C
117 117
 		utils.LogError("获取健身卡详情失败" + err.Error())
118 118
 		return nil, errors.New("获取健身卡详情失败")
119 119
 	}
120
-	return &customerGym, err
120
+	return customerGym, err
121 121
 }
122 122
 
123 123
 // SaveGymcard 保存游泳健身卡