|
@@ -102,21 +102,8 @@ func (service *IntegralService) IntegralAddService(data entity.FlowJSON) (int, s
|
|
|
|
|
|
//消耗积分流水
|
|
|
func (service *IntegralService) IntegralConsumeService(data entity.FlowJSON) (int, string) {
|
|
|
+ var af = int64(0)
|
|
|
orm := entity.Engine
|
|
|
- //查询积分余额是否充足
|
|
|
- balance := entity.Balance{}
|
|
|
- b, err := orm.Table("integral_balance").Select("countPoints,id").
|
|
|
- Where("userId = ? AND appId = ?", data.UserId, data.AppId).
|
|
|
- Get(&balance)
|
|
|
- if !b || err != nil {
|
|
|
- log.Printf("积分余额查询出错,userId:[%s],err:[%v]", data.UserId, err)
|
|
|
- return entity.ErrorCode, "积分余额不足"
|
|
|
- }
|
|
|
- if balance.CountPoints < data.Point {
|
|
|
- return entity.ErrorCode, "积分余额不足"
|
|
|
- }
|
|
|
-
|
|
|
- //消耗积分流水记录
|
|
|
flow := entity.Flow{}
|
|
|
flow.UserId = data.UserId
|
|
|
flow.PointType = data.PointType
|
|
@@ -127,10 +114,17 @@ func (service *IntegralService) IntegralConsumeService(data entity.FlowJSON) (in
|
|
|
flow.EndDate = data.EndDate
|
|
|
flow.AppId = data.AppId
|
|
|
flow.Sort = entity.ReduceCode
|
|
|
- af, err := orm.Table("integral_flow").Insert(&flow)
|
|
|
- if err != nil && af == 0 {
|
|
|
- log.Print("积分记录失败")
|
|
|
- return entity.ErrorCode, "积分记录失败"
|
|
|
+ balance := entity.Balance{}
|
|
|
+ //查询积分余额是否充足
|
|
|
+ b, err := orm.Table("integral_balance").Select("countPoints,id").
|
|
|
+ Where("userId = ? AND appId = ?", data.UserId, data.AppId).
|
|
|
+ Get(&balance)
|
|
|
+ if !b || err != nil {
|
|
|
+ log.Printf("积分余额查询出错,userId:[%s],err:[%v]", data.UserId, err)
|
|
|
+ return entity.ErrorCode, "积分余额不足"
|
|
|
+ }
|
|
|
+ if balance.CountPoints < data.Point {
|
|
|
+ return entity.ErrorCode, "积分余额不足"
|
|
|
}
|
|
|
|
|
|
//结存消耗
|
|
@@ -439,19 +433,19 @@ func (service *IntegralService) IntegralBalanceCheckService(userId, appId string
|
|
|
}
|
|
|
|
|
|
//按月查询积分使用情况
|
|
|
-func (service *IntegralService) IntegralExpireCheck(data entity.ExpireJSON) []entity.FlowReq {
|
|
|
+func (service *IntegralService) IntegralDetailedCheck(data entity.FlowJSON) ([]entity.FlowReq,int64) {
|
|
|
orm := entity.Engine
|
|
|
- var err error
|
|
|
flowReq := []entity.FlowReq{}
|
|
|
- err = orm.Table("integral_flow").Alias("flow").
|
|
|
+ numb,err := orm.Table("integral_flow").Alias("flow").
|
|
|
Select("flow.*,pt.name").
|
|
|
Join("left", "point_type pt", "flow.pointType=pt.code").
|
|
|
- Where("userId = ? AND appId = ? AND DATE_FORMAT(createTime,'%Y-%m') ", data.UserId, data.AppId, data.EndDate).
|
|
|
- GroupBy("pointType").
|
|
|
- Find(&flowReq)
|
|
|
+ Where("flow.userId = ? AND flow.appId = ? AND DATE_FORMAT(flow.createTime,'%Y-%m')=? ", data.UserId, data.AppId, data.EndDate).
|
|
|
+ Desc("flow.createTime").
|
|
|
+ Limit(data.PageSize, (data.Page-1)*data.PageSize).
|
|
|
+ FindAndCount(&flowReq)
|
|
|
if err != nil {
|
|
|
log.Println(err)
|
|
|
- return nil
|
|
|
+ return nil,int64(0)
|
|
|
}
|
|
|
- return flowReq
|
|
|
+ return flowReq,numb
|
|
|
}
|