|
@@ -98,8 +98,12 @@ func (service *IntegralService) IntegralAddService(data entity.FlowJSON) (int, s
|
|
|
return entity.ErrorCode, "余额新增失败"
|
|
|
}
|
|
|
}
|
|
|
+<<<<<<< HEAD
|
|
|
|
|
|
return entity.SuccessCode, "余额新增成功"
|
|
|
+=======
|
|
|
+ return entity.SuccessCode, "余额扣除失败"
|
|
|
+>>>>>>> fe8bc988f5e435ac07c7685f68745db1a4ebc0f4
|
|
|
}
|
|
|
|
|
|
//消耗积分流水
|
|
@@ -114,12 +118,13 @@ func (service *IntegralService) IntegralConsumeService(data entity.FlowJSON) (in
|
|
|
flow.CreateTime = time.Now().Format("2006-01-02 15:04:05")
|
|
|
flow.EndDate = data.EndDate
|
|
|
flow.AppId = data.AppId
|
|
|
+<<<<<<< HEAD
|
|
|
flow.Sort = entity.ReduceCode
|
|
|
//判断是否为消耗积分:false
|
|
|
+=======
|
|
|
+>>>>>>> fe8bc988f5e435ac07c7685f68745db1a4ebc0f4
|
|
|
balance := entity.Balance{}
|
|
|
//查询积分余额是否充足
|
|
|
- balance.UserId = data.UserId
|
|
|
- balance.AppId = data.AppId
|
|
|
b, err := orm.Table("integral_balance").Select("countPoints,id").
|
|
|
Where("userId = ? AND appId = ?", data.UserId, data.AppId).
|
|
|
Get(&balance)
|
|
@@ -131,8 +136,13 @@ func (service *IntegralService) IntegralConsumeService(data entity.FlowJSON) (in
|
|
|
return entity.ErrorCode, "积分余额不足"
|
|
|
}
|
|
|
af, err := orm.Table("integral_flow").Insert(&flow)
|
|
|
+<<<<<<< HEAD
|
|
|
if err != nil && af == 0 {
|
|
|
log.Print("积分记录失败-积分增减类型:", data.Sort)
|
|
|
+=======
|
|
|
+ if err != nil && af==0{
|
|
|
+ log.Print("积分记录失败")
|
|
|
+>>>>>>> fe8bc988f5e435ac07c7685f68745db1a4ebc0f4
|
|
|
return entity.ErrorCode, "积分记录失败"
|
|
|
}
|
|
|
|
|
@@ -191,8 +201,12 @@ func (service *IntegralService) IntegralConsumeService(data entity.FlowJSON) (in
|
|
|
log.Print("余额扣除失败")
|
|
|
return entity.ErrorCode, "余额扣除失败"
|
|
|
}
|
|
|
+<<<<<<< HEAD
|
|
|
|
|
|
return entity.SuccessCode, "积分消耗成功"
|
|
|
+=======
|
|
|
+ return entity.SuccessCode, "积分记录成功"
|
|
|
+>>>>>>> fe8bc988f5e435ac07c7685f68745db1a4ebc0f4
|
|
|
}
|
|
|
|
|
|
//到期积分查询
|
|
@@ -225,7 +239,7 @@ func (service *IntegralService) IntegralSoldeService(model entity.SoldeUpdate) (
|
|
|
var err error
|
|
|
var numb = int64(0)
|
|
|
//新增积分
|
|
|
- if (model.PointsType) {
|
|
|
+ if model.PointsType {
|
|
|
//永久积分
|
|
|
solde.PerManEntPoints = model.Points
|
|
|
numb, err = entity.Engine.Table("integral_solde").Insert(&solde)
|
|
@@ -270,9 +284,9 @@ func (service *IntegralService) IntegralSoldeReduceService(model entity.SoldeUpd
|
|
|
if point == 0 {
|
|
|
return true, "积分消耗成功"
|
|
|
}
|
|
|
- if (solde.TimePoints == 0) {
|
|
|
+ if solde.TimePoints == 0 {
|
|
|
//消耗永久积分
|
|
|
- if (solde.PerManEntPoints >= point) {
|
|
|
+ if solde.PerManEntPoints >= point {
|
|
|
//够消耗
|
|
|
point = 0
|
|
|
solde.PerManEntPoints = solde.PerManEntPoints - point
|
|
@@ -284,7 +298,7 @@ func (service *IntegralService) IntegralSoldeReduceService(model entity.SoldeUpd
|
|
|
}
|
|
|
}
|
|
|
//消耗时效积分
|
|
|
- if (solde.TimePoints > point) {
|
|
|
+ if solde.TimePoints > point {
|
|
|
//够消耗
|
|
|
point = 0
|
|
|
solde.TimePoints = solde.TimePoints - point
|
|
@@ -337,7 +351,7 @@ func (service *IntegralService) IntegralBalanceService(model entity.BalanceUpdat
|
|
|
log.Println("没有积分可以扣除")
|
|
|
return false, "没有积分可以扣除"
|
|
|
}
|
|
|
- if (balanceList[0].CountPoints < model.CountPoints) {
|
|
|
+ if balanceList[0].CountPoints < model.CountPoints {
|
|
|
log.Println("积分余额不足")
|
|
|
return false, "积分余额不足"
|
|
|
}
|
|
@@ -351,24 +365,85 @@ func (service *IntegralService) IntegralBalanceService(model entity.BalanceUpdat
|
|
|
}
|
|
|
*/
|
|
|
//积分守护
|
|
|
-func (service *IntegralService) IntegralGuardService(data entity.ExpireJSON) []entity.Flow {
|
|
|
+func (service *IntegralService) IntegralGuardService(endDate string) bool {
|
|
|
orm := entity.Engine
|
|
|
- var flow []entity.Flow
|
|
|
var err error
|
|
|
- point := ""
|
|
|
- if data.PointType != 0 {
|
|
|
- point = "AND pointType = " + fmt.Sprint(data.PointType) + ""
|
|
|
- }
|
|
|
- err = orm.Table("integral_flow").
|
|
|
- Select("id,pointType,SUM(point) AS point").
|
|
|
- Where("userId = ? AND appId = ? AND endDate < ? "+point+"", data.UserId, data.AppId, data.EndDate).
|
|
|
- GroupBy("pointType").
|
|
|
- Find(&flow)
|
|
|
+ soldelist := []entity.Solde{}
|
|
|
+ err = orm.Table("integral_solde").
|
|
|
+ Where("timePoints != 0 AND endDate < ? ", endDate).
|
|
|
+ Desc("endDate").Find(&soldelist)
|
|
|
if err != nil {
|
|
|
- log.Println(err)
|
|
|
- return nil
|
|
|
+ log.Println("积分结存查询失败")
|
|
|
}
|
|
|
- return flow
|
|
|
+ for _, solde := range soldelist {
|
|
|
+ //查询积分余额是否充足
|
|
|
+ balance := entity.Balance{}
|
|
|
+ b, err := orm.Table("integral_balance").Select("countPoints,id").
|
|
|
+ Where("userId = ? AND appId = ?", solde.UserId, solde.AppId).
|
|
|
+ Get(&balance)
|
|
|
+ if !b || err != nil {
|
|
|
+ log.Printf("积分余额查询出错,userId:[%s],err:[%v]", solde.UserId, err)
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ if balance.CountPoints < solde.TimePoints {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+ //积分余额-时效过期积分=当前总积分余额
|
|
|
+ balance.CountPoints = balance.CountPoints - solde.TimePoints
|
|
|
+ orm.Table("integral_balance")
|
|
|
+ numb, err := orm.Table("integral_balance").
|
|
|
+ ID(balance.Id).
|
|
|
+ Cols("countPoints").
|
|
|
+ Update(balance)
|
|
|
+ if err != nil && numb == 0 {
|
|
|
+ log.Print("余额扣除失败")
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+ //积分过期流水记录
|
|
|
+ flow := entity.Flow{}
|
|
|
+ flow.UserId = solde.UserId
|
|
|
+ flow.PointType = 9
|
|
|
+ flow.BusinessTypeId = 0
|
|
|
+ flow.BusinessType = "0"
|
|
|
+ flow.Point = solde.TimePoints
|
|
|
+ flow.CreateTime = time.Now().Format("2006-01-02 15:04:05")
|
|
|
+ flow.EndDate = solde.EndDate
|
|
|
+ flow.AppId = solde.AppId
|
|
|
+ af, err := orm.Table("integral_flow").Insert(&flow)
|
|
|
+ if err != nil && af==0{
|
|
|
+ log.Print("积分记录失败")
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+ //清空过期积分的时效积分
|
|
|
+ soldeUpdate := &entity.Solde{}
|
|
|
+ soldeUpdate.TimePoints = 0
|
|
|
+ af, err = orm.Table("integral_solde").
|
|
|
+ Cols("timePoints").
|
|
|
+ ID(solde.Id).
|
|
|
+ Update(soldeUpdate)
|
|
|
+ if af == 0 && err != nil {
|
|
|
+ log.Println("过期时效积分清空失败", solde.Id)
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true
|
|
|
+}
|
|
|
+
|
|
|
+//积分余额查询
|
|
|
+func (service *IntegralService) IntegralBalanceCheckService(userId,appId string) (bool,int64) {
|
|
|
+ orm := entity.Engine
|
|
|
+ balance := entity.Balance{}
|
|
|
+ b,err := orm.Table("integral_balance").
|
|
|
+ Where("userId = ? AND appId = ?", userId,appId).
|
|
|
+ Get(&balance)
|
|
|
+ if !b || err != nil {
|
|
|
+ log.Println("积分余额查询失败")
|
|
|
+ return false,0
|
|
|
+ }
|
|
|
+ return true,balance.CountPoints
|
|
|
}
|
|
|
|
|
|
//按月查询积分使用情况
|