|
@@ -9,9 +9,37 @@ import (
|
|
|
|
|
|
type IntegralService struct{}
|
|
type IntegralService struct{}
|
|
|
|
|
|
|
|
+//新增积分流水
|
|
|
|
+func (service *IntegralService) IntegralAddService(userId, businessType, endDate string, pointType, businessTypeId, point, appId int) (int, string) {
|
|
|
|
+ orm := entity.Engine
|
|
|
|
+ flow := entity.Flow{}
|
|
|
|
+ flow.UserId = userId
|
|
|
|
+ flow.PointType = pointType
|
|
|
|
+ flow.BusinessTypeId = businessTypeId
|
|
|
|
+ flow.BusinessType = businessType
|
|
|
|
+ flow.Point = point
|
|
|
|
+ flow.CreateTime = time.Now().Format("2006-01-02 15:04:05")
|
|
|
|
+ flow.EndDate = endDate
|
|
|
|
+ flow.AppId = appId
|
|
|
|
+ //查询积分余额是否充足
|
|
|
|
+ balance := entity.Balance{}
|
|
|
|
+ balance.UserId = userId
|
|
|
|
+ balance.AppId = appId
|
|
|
|
+ b, err := orm.Table("integral_balance").Select("countPoints").
|
|
|
|
+ Where("userId = ? AND appId = ?", userId, appId).
|
|
|
|
+ Get(&balance)
|
|
|
|
+ if !b || err != nil {
|
|
|
|
+ log.Printf("积分余额查询出错,userId:[%s],err:[%v]", userId, err)
|
|
|
|
+ return entity.ErrorCode, "积分余额不足"
|
|
|
|
+ }
|
|
|
|
+ if balance.CountPoints < point {
|
|
|
|
+ return entity.ErrorCode, "积分余额不足"
|
|
|
|
+ }
|
|
|
|
+ return entity.SuccessCode, "消耗积分成功"
|
|
|
|
+}
|
|
|
|
|
|
//消耗积分流水
|
|
//消耗积分流水
|
|
-func(service *IntegralService) IntegralConsumeService(userId, businessType, createTime, endDate string,pointType, businessTypeId, point, appId int) (int,string) {
|
|
|
|
|
|
+func (service *IntegralService) IntegralConsumeService(userId, businessType, createTime, endDate string, pointType, businessTypeId, point, appId int) (int, string) {
|
|
orm := entity.Engine
|
|
orm := entity.Engine
|
|
flow := entity.Flow{}
|
|
flow := entity.Flow{}
|
|
flow.UserId = userId
|
|
flow.UserId = userId
|
|
@@ -26,21 +54,27 @@ func(service *IntegralService) IntegralConsumeService(userId, businessType, crea
|
|
balance := entity.Balance{}
|
|
balance := entity.Balance{}
|
|
balance.UserId = userId
|
|
balance.UserId = userId
|
|
balance.AppId = appId
|
|
balance.AppId = appId
|
|
- b,err := orm.Table("integral_balance").Select("countPoints").
|
|
|
|
- Where("userId = ? AND appId = ?",userId,appId).
|
|
|
|
|
|
+ b, err := orm.Table("integral_balance").Select("countPoints").
|
|
|
|
+ Where("userId = ? AND appId = ?", userId, appId).
|
|
Get(&balance)
|
|
Get(&balance)
|
|
if !b || err != nil {
|
|
if !b || err != nil {
|
|
log.Printf("积分余额查询出错,userId:[%s],err:[%v]", userId, err)
|
|
log.Printf("积分余额查询出错,userId:[%s],err:[%v]", userId, err)
|
|
- return entity.ErrorCode,"积分余额不足"
|
|
|
|
|
|
+ return entity.ErrorCode, "积分余额不足"
|
|
}
|
|
}
|
|
if balance.CountPoints < point {
|
|
if balance.CountPoints < point {
|
|
- return entity.ErrorCode,"积分余额不足"
|
|
|
|
|
|
+ return entity.ErrorCode, "积分余额不足"
|
|
}
|
|
}
|
|
- return entity.SuccessCode,"消耗积分成功"
|
|
|
|
|
|
+ af, err := entity.Engine.Table("integral_flow").Insert(&flow)
|
|
|
|
+
|
|
|
|
+ if err != nil && af>0 {
|
|
|
|
+ log.Print("消耗积分记录失败")
|
|
|
|
+ return entity.ErrorCode,"消耗积分记录失败"
|
|
|
|
+ }
|
|
|
|
+ return entity.SuccessCode, "消耗积分成功"
|
|
}
|
|
}
|
|
|
|
|
|
//结存新增
|
|
//结存新增
|
|
-func (service *IntegralService) IntegralSoldeService(model entity.SoldeUpdate) (bool,string){
|
|
|
|
|
|
+func (service *IntegralService) IntegralSoldeService(model entity.SoldeUpdate) (bool, string) {
|
|
solde := entity.Solde{}
|
|
solde := entity.Solde{}
|
|
solde.AppId = model.AppId
|
|
solde.AppId = model.AppId
|
|
solde.UserId = model.UserId
|
|
solde.UserId = model.UserId
|
|
@@ -54,9 +88,9 @@ func (service *IntegralService) IntegralSoldeService(model entity.SoldeUpdate) (
|
|
numb, err = entity.Engine.Table("integral_solde").Insert(&solde)
|
|
numb, err = entity.Engine.Table("integral_solde").Insert(&solde)
|
|
if err != nil && numb == 0 {
|
|
if err != nil && numb == 0 {
|
|
log.Print("新增永久积分失败")
|
|
log.Print("新增永久积分失败")
|
|
- return false,"新增永久积分失败"
|
|
|
|
|
|
+ return false, "新增永久积分失败"
|
|
}
|
|
}
|
|
- return true,"新增永久积分成功"
|
|
|
|
|
|
+ return true, "新增永久积分成功"
|
|
}
|
|
}
|
|
//失效积分
|
|
//失效积分
|
|
//先查看是否有EndDate的积分
|
|
//先查看是否有EndDate的积分
|
|
@@ -67,31 +101,31 @@ func (service *IntegralService) IntegralSoldeService(model entity.SoldeUpdate) (
|
|
numb, err = entity.Engine.Table("integral_solde").ID(soldelist[0].Id).Cols("timePoints").Update(&soldelist[0])
|
|
numb, err = entity.Engine.Table("integral_solde").ID(soldelist[0].Id).Cols("timePoints").Update(&soldelist[0])
|
|
if err != nil && numb == 0 {
|
|
if err != nil && numb == 0 {
|
|
log.Print("修改时效积分失败")
|
|
log.Print("修改时效积分失败")
|
|
- return false,"修改时效积分失败"
|
|
|
|
|
|
+ return false, "修改时效积分失败"
|
|
}
|
|
}
|
|
- return true,"修改时效积分成功"
|
|
|
|
|
|
+ return true, "修改时效积分成功"
|
|
} else {
|
|
} else {
|
|
solde.TimePoints = model.Points
|
|
solde.TimePoints = model.Points
|
|
numb, err = entity.Engine.Table("integral_solde").Insert(&solde)
|
|
numb, err = entity.Engine.Table("integral_solde").Insert(&solde)
|
|
if err != nil && numb == 0 {
|
|
if err != nil && numb == 0 {
|
|
log.Print("新增时效积分失败")
|
|
log.Print("新增时效积分失败")
|
|
- return false,"新增时效积分失败"
|
|
|
|
|
|
+ return false, "新增时效积分失败"
|
|
}
|
|
}
|
|
- return true,"新增时效积分成功"
|
|
|
|
|
|
+ return true, "新增时效积分成功"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
//结存扣除
|
|
//结存扣除
|
|
-func (service *IntegralService) IntegralSoldeReduceService(model entity.SoldeUpdate)(bool,string) {
|
|
|
|
|
|
+func (service *IntegralService) IntegralSoldeReduceService(model entity.SoldeUpdate) (bool, string) {
|
|
var err error
|
|
var err error
|
|
var numb = int64(0)
|
|
var numb = int64(0)
|
|
soldelist := []entity.Solde{}
|
|
soldelist := []entity.Solde{}
|
|
- err = entity.Engine.Table("integral_solde").Where("appId=? and userId=? and endDate> ? ( perManEntPoints != 0 AND timePoints = 0 ) OR ( perManEntPoints = 0 AND timePoints != 0 )", model.AppId, model.UserId,time.Now().Format("2006/01/02/")).Desc("endDate,timePoints").Find(&soldelist)
|
|
|
|
|
|
+ err = entity.Engine.Table("integral_solde").Where("appId=? and userId=? and endDate> ? ( perManEntPoints != 0 AND timePoints = 0 ) OR ( perManEntPoints = 0 AND timePoints != 0 )", model.AppId, model.UserId, time.Now().Format("2006/01/02/")).Desc("endDate,timePoints").Find(&soldelist)
|
|
if len(soldelist) > 0 {
|
|
if len(soldelist) > 0 {
|
|
var point = model.Points
|
|
var point = model.Points
|
|
for _, solde := range soldelist {
|
|
for _, solde := range soldelist {
|
|
if point == 0 {
|
|
if point == 0 {
|
|
- return true,"积分消耗成功"
|
|
|
|
|
|
+ return true, "积分消耗成功"
|
|
}
|
|
}
|
|
if (solde.TimePoints == 0) {
|
|
if (solde.TimePoints == 0) {
|
|
//消耗永久积分
|
|
//消耗永久积分
|
|
@@ -102,7 +136,7 @@ func (service *IntegralService) IntegralSoldeReduceService(model entity.SoldeUpd
|
|
numb, err = entity.Engine.Table("integral_solde").ID(solde.Id).Cols("perManEntPoints").Update(&solde)
|
|
numb, err = entity.Engine.Table("integral_solde").ID(solde.Id).Cols("perManEntPoints").Update(&solde)
|
|
if err != nil && numb == 0 {
|
|
if err != nil && numb == 0 {
|
|
log.Print("消耗永久积分失败")
|
|
log.Print("消耗永久积分失败")
|
|
- return false,"消耗永久积分失败"
|
|
|
|
|
|
+ return false, "消耗永久积分失败"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -114,9 +148,9 @@ func (service *IntegralService) IntegralSoldeReduceService(model entity.SoldeUpd
|
|
numb, err = entity.Engine.Table("integral_solde").ID(solde.Id).Cols("timePoints").Update(&solde)
|
|
numb, err = entity.Engine.Table("integral_solde").ID(solde.Id).Cols("timePoints").Update(&solde)
|
|
if err != nil && numb == 0 {
|
|
if err != nil && numb == 0 {
|
|
log.Print("消耗时效积分失败")
|
|
log.Print("消耗时效积分失败")
|
|
- return false,"消耗时效积分失败"
|
|
|
|
|
|
+ return false, "消耗时效积分失败"
|
|
}
|
|
}
|
|
- return true,"消耗时效积分成功"
|
|
|
|
|
|
+ return true, "消耗时效积分成功"
|
|
}
|
|
}
|
|
//不够消耗
|
|
//不够消耗
|
|
point = point - solde.TimePoints
|
|
point = point - solde.TimePoints
|
|
@@ -124,14 +158,15 @@ func (service *IntegralService) IntegralSoldeReduceService(model entity.SoldeUpd
|
|
numb, err = entity.Engine.Table("integral_solde").ID(solde.Id).Cols("timePoints").Update(&solde)
|
|
numb, err = entity.Engine.Table("integral_solde").ID(solde.Id).Cols("timePoints").Update(&solde)
|
|
if err != nil && numb == 0 {
|
|
if err != nil && numb == 0 {
|
|
log.Print("消耗时效积分失败")
|
|
log.Print("消耗时效积分失败")
|
|
- return false,"消耗时效积分失败"
|
|
|
|
|
|
+ return false, "消耗时效积分失败"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- return false,"没有积分可以扣除"
|
|
|
|
|
|
+ return false, "没有积分可以扣除"
|
|
}
|
|
}
|
|
|
|
+
|
|
//调整余额
|
|
//调整余额
|
|
-func (service *IntegralService) IntegralBalanceService(model entity.BalanceUpdate) (bool,string) {
|
|
|
|
|
|
+func (service *IntegralService) IntegralBalanceService(model entity.BalanceUpdate) (bool, string) {
|
|
var err error
|
|
var err error
|
|
var numb = int64(0)
|
|
var numb = int64(0)
|
|
fmt.Println(numb)
|
|
fmt.Println(numb)
|
|
@@ -148,7 +183,7 @@ func (service *IntegralService) IntegralBalanceService(model entity.BalanceUpdat
|
|
numb, err = entity.Engine.Table("integral_balance").Insert(&balance)
|
|
numb, err = entity.Engine.Table("integral_balance").Insert(&balance)
|
|
if err != nil && numb == 0 {
|
|
if err != nil && numb == 0 {
|
|
log.Print("新增余额失败")
|
|
log.Print("新增余额失败")
|
|
- return false,"新增余额失败"
|
|
|
|
|
|
+ return false, "新增余额失败"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//修改余额
|
|
//修改余额
|
|
@@ -157,17 +192,17 @@ func (service *IntegralService) IntegralBalanceService(model entity.BalanceUpdat
|
|
//消耗
|
|
//消耗
|
|
if len(balanceList) == 0 {
|
|
if len(balanceList) == 0 {
|
|
log.Println("没有积分可以扣除")
|
|
log.Println("没有积分可以扣除")
|
|
- return false,"没有积分可以扣除"
|
|
|
|
|
|
+ return false, "没有积分可以扣除"
|
|
}
|
|
}
|
|
if (balanceList[0].CountPoints < model.CountPoints) {
|
|
if (balanceList[0].CountPoints < model.CountPoints) {
|
|
log.Println("积分余额不足")
|
|
log.Println("积分余额不足")
|
|
- return false,"积分余额不足"
|
|
|
|
|
|
+ return false, "积分余额不足"
|
|
}
|
|
}
|
|
balanceList[0].CountPoints = balanceList[0].CountPoints - model.CountPoints
|
|
balanceList[0].CountPoints = balanceList[0].CountPoints - model.CountPoints
|
|
numb, err = entity.Engine.Table("integral_balance").ID(balanceList[0].Id).Cols("countPoints").Update(&balanceList[0])
|
|
numb, err = entity.Engine.Table("integral_balance").ID(balanceList[0].Id).Cols("countPoints").Update(&balanceList[0])
|
|
if err != nil && numb == 0 {
|
|
if err != nil && numb == 0 {
|
|
log.Print("余额扣除失败")
|
|
log.Print("余额扣除失败")
|
|
- return false,"余额扣除失败"
|
|
|
|
|
|
+ return false, "余额扣除失败"
|
|
}
|
|
}
|
|
- return true,"余额扣除失败"
|
|
|
|
|
|
+ return true, "余额扣除失败"
|
|
}
|
|
}
|