|
@@ -97,31 +97,6 @@ func (service *IntegralService) IntegralAddService(data entity.FlowJSON) (int64,
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- //余额修改
|
|
|
- balanceList := []*entity.Balance{}
|
|
|
- //查看是否存在本人的余额
|
|
|
- err = orm.Table("integral_balance").Where("appId=? and userId=? ", data.AppId, data.UserId).Find(&balanceList)
|
|
|
- if len(balanceList) == 0 {
|
|
|
- balance := entity.Balance{}
|
|
|
- balance.UserId = data.UserId
|
|
|
- balance.AppId = data.AppId
|
|
|
- balance.CountPoints = data.Point
|
|
|
- numb, err = orm.Table("integral_balance").Insert(&balance)
|
|
|
- if err != nil || numb == 0 {
|
|
|
- log.Print("新增余额失败:", err)
|
|
|
- orm.Rollback()
|
|
|
- return entity.ErrorCode, "新增余额失败", serialNumber
|
|
|
- }
|
|
|
- } else {
|
|
|
- //修改余额
|
|
|
- balanceList[0].CountPoints = balanceList[0].CountPoints + data.Point
|
|
|
- numb, err = orm.Table("integral_balance").ID(balanceList[0].Id).Cols("countPoints").Update(balanceList[0])
|
|
|
- if err != nil || numb == 0 {
|
|
|
- log.Print("余额新增失败:", err)
|
|
|
- orm.Rollback()
|
|
|
- return entity.ErrorCode, "余额新增失败", serialNumber
|
|
|
- }
|
|
|
- }
|
|
|
err = orm.Commit()
|
|
|
if err != nil {
|
|
|
log.Print("积分新增失败:", err)
|
|
@@ -140,8 +115,8 @@ func (service *IntegralService) IntegralConsumeService(data entity.FlowJSON) (in
|
|
|
var af = int64(0)
|
|
|
balance := entity.Balance{}
|
|
|
//查询积分余额是否充足
|
|
|
- b, err := orm.Table("integral_balance").Select("countPoints,id").
|
|
|
- Where("userId = ? AND appId = ?", data.UserId, data.AppId).
|
|
|
+ b, err := orm.Table("integral_solde").Select("sum(perManEntPoints)+sum(timePoints) as CountPoints ,userId").
|
|
|
+ Where("appId=? and userId=? and (endDate = '' OR endDate IS NULL OR endDate >= ?) and (( perManEntPoints != 0 AND timePoints = 0 ) OR ( perManEntPoints = 0 AND timePoints != 0 ))", data.AppId, data.UserId, time.Now().Format("2006-01-02")).
|
|
|
Get(&balance)
|
|
|
if err != nil {
|
|
|
log.Printf("积分余额查询出错,userId:[%s],err:[%v]", data.UserId, err)
|
|
@@ -217,14 +192,7 @@ func (service *IntegralService) IntegralConsumeService(data entity.FlowJSON) (in
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- //余额消耗
|
|
|
- balance.CountPoints = balance.CountPoints - data.Point
|
|
|
- af, err = orm.Table("integral_balance").
|
|
|
- ID(balance.Id).
|
|
|
- Cols("countPoints").
|
|
|
- Update(balance)
|
|
|
- if err != nil || af == 0 {
|
|
|
+ if err != nil {
|
|
|
log.Print("余额扣除失败:", err)
|
|
|
orm.Rollback()
|
|
|
return entity.ErrorCode, "余额扣除失败", serialNumber
|
|
@@ -423,8 +391,8 @@ func (service *IntegralService) IntegralGuardService(endDate string) bool {
|
|
|
for _, solde := range soldelist {
|
|
|
//查询积分余额是否充足
|
|
|
balance := entity.Balance{}
|
|
|
- b, err := orm.Table("integral_balance").Select("countPoints,id").
|
|
|
- Where("userId = ? AND appId = ?", solde.UserId, solde.AppId).
|
|
|
+ b, err := orm.Table("integral_solde").Select("sum(perManEntPoints)+sum(timePoints) as CountPoints ,userId").
|
|
|
+ Where("appId=? and userId=? and (endDate = '' OR endDate IS NULL OR endDate >= ?) and (( perManEntPoints != 0 AND timePoints = 0 ) OR ( perManEntPoints = 0 AND timePoints != 0 ))", solde.AppId, solde.UserId, time.Now().Format("2006-01-02")).
|
|
|
Get(&balance)
|
|
|
if !b || err != nil {
|
|
|
log.Printf("积分余额查询出错,userId:[%s],err:[%v]", solde.UserId, err)
|
|
@@ -433,20 +401,6 @@ func (service *IntegralService) IntegralGuardService(endDate string) bool {
|
|
|
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("余额扣除失败")
|
|
|
- orm.Rollback()
|
|
|
- return false
|
|
|
- }
|
|
|
-
|
|
|
//积分过期流水记录
|
|
|
flow := entity.Flow{}
|
|
|
flow.UserId = solde.UserId
|
|
@@ -490,8 +444,8 @@ func (service *IntegralService) IntegralBalanceCheckService(userId, appId string
|
|
|
orm := entity.Engine
|
|
|
//积分总余额
|
|
|
balance := entity.Balance{}
|
|
|
- _, err := orm.Table("integral_balance").
|
|
|
- Where("userId = ? AND appId = ?", userId, appId).
|
|
|
+ _, err := orm.Table("integral_solde").Select("sum(perManEntPoints)+sum(timePoints) as CountPoints ,userId").
|
|
|
+ Where("appId=? and userId=? and (endDate = '' OR endDate IS NULL OR endDate >= ?) and (( perManEntPoints != 0 AND timePoints = 0 ) OR ( perManEntPoints = 0 AND timePoints != 0 ))", appId, userId, time.Now().Format("2006-01-02")).
|
|
|
Get(&balance)
|
|
|
if err != nil {
|
|
|
log.Println("积分查询出错")
|
|
@@ -636,19 +590,7 @@ func (service *IntegralService) UserMerge(mergeUser, mergedUser, appId string) (
|
|
|
orm.Exec("UPDATE integral_solde SET perManEntPoints = perManEntPoints+? WHERE id= ?", value.PerManEntPoints, solde.Id)
|
|
|
perManEntBalanceNumb += value.PerManEntPoints
|
|
|
}
|
|
|
- balance := entity.Balance{}
|
|
|
- fool := true
|
|
|
- fool, err = orm.Table("integral_balance").Select("*").
|
|
|
- Where("userId = ? AND appId = ?", mergeUser, appId).
|
|
|
- Get(&balance)
|
|
|
- fmt.Println(fool)
|
|
|
- if err != nil {
|
|
|
- orm.Rollback()
|
|
|
- log.Println("积分余额查询出错,err")
|
|
|
- return false, "积分余额查询失败"
|
|
|
- }
|
|
|
numb := int64(0)
|
|
|
-
|
|
|
if timeBalanceNumb > 0 {
|
|
|
flow := entity.Flow{}
|
|
|
flow.UserId = mergeUser
|
|
@@ -691,21 +633,6 @@ func (service *IntegralService) UserMerge(mergeUser, mergedUser, appId string) (
|
|
|
return false, "新增永久流水失败"
|
|
|
}
|
|
|
}
|
|
|
- if balance.Id == 0 {
|
|
|
- balance := entity.Balance{}
|
|
|
- balance.UserId = mergeUser
|
|
|
- balance.AppId = appId
|
|
|
- balance.CountPoints = timeBalanceNumb + perManEntBalanceNumb
|
|
|
- numb, err = orm.Table("integral_balance").Insert(&balance)
|
|
|
- if err != nil || numb == 0 {
|
|
|
- log.Print("新增余额失败:", err)
|
|
|
- orm.Rollback()
|
|
|
- return false, "新增余额失败"
|
|
|
- }
|
|
|
- } else {
|
|
|
- //修改余额
|
|
|
- orm.Exec("UPDATE integral_balance SET countPoints = countPoints+? WHERE id = ?", timeBalanceNumb+perManEntBalanceNumb, balance.Id)
|
|
|
- }
|
|
|
orm.Commit()
|
|
|
return true, "合并成功"
|
|
|
}
|