|
@@ -104,19 +104,8 @@ func (service *IntegralService) IntegralAddService(data entity.FlowJSON) (int, s
|
|
//消耗积分流水
|
|
//消耗积分流水
|
|
func (service *IntegralService) IntegralConsumeService(data entity.FlowJSON) (int, string) {
|
|
func (service *IntegralService) IntegralConsumeService(data entity.FlowJSON) (int, string) {
|
|
orm := entity.Engine
|
|
orm := entity.Engine
|
|
- flow := entity.Flow{}
|
|
|
|
- flow.UserId = data.UserId
|
|
|
|
- flow.PointType = data.PointType
|
|
|
|
- flow.BusinessTypeId = data.BusinessTypeId
|
|
|
|
- flow.BusinessType = data.BusinessType
|
|
|
|
- flow.Point = data.Point
|
|
|
|
- flow.CreateTime = time.Now().Format("2006-01-02 15:04:05")
|
|
|
|
- flow.EndDate = data.EndDate
|
|
|
|
- flow.AppId = data.AppId
|
|
|
|
- flow.Sort = entity.ReduceCode
|
|
|
|
- //判断是否为消耗积分:false
|
|
|
|
- balance := entity.Balance{}
|
|
|
|
//查询积分余额是否充足
|
|
//查询积分余额是否充足
|
|
|
|
+ balance := entity.Balance{}
|
|
b, err := orm.Table("integral_balance").Select("countPoints,id").
|
|
b, err := orm.Table("integral_balance").Select("countPoints,id").
|
|
Where("userId = ? AND appId = ?", data.UserId, data.AppId).
|
|
Where("userId = ? AND appId = ?", data.UserId, data.AppId).
|
|
Get(&balance)
|
|
Get(&balance)
|
|
@@ -127,15 +116,30 @@ func (service *IntegralService) IntegralConsumeService(data entity.FlowJSON) (in
|
|
if balance.CountPoints < data.Point {
|
|
if balance.CountPoints < data.Point {
|
|
return entity.ErrorCode, "积分余额不足"
|
|
return entity.ErrorCode, "积分余额不足"
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ //消耗积分流水记录
|
|
|
|
+ flow := entity.Flow{}
|
|
|
|
+ flow.UserId = data.UserId
|
|
|
|
+ flow.PointType = data.PointType
|
|
|
|
+ flow.BusinessTypeId = data.BusinessTypeId
|
|
|
|
+ flow.BusinessType = data.BusinessType
|
|
|
|
+ flow.Point = data.Point
|
|
|
|
+ flow.CreateTime = time.Now().Format("2006-01-02 15:04:05")
|
|
|
|
+ flow.EndDate = data.EndDate
|
|
|
|
+ flow.AppId = data.AppId
|
|
|
|
+ flow.Sort = entity.ReduceCode
|
|
af, err := orm.Table("integral_flow").Insert(&flow)
|
|
af, err := orm.Table("integral_flow").Insert(&flow)
|
|
if err != nil && af == 0 {
|
|
if err != nil && af == 0 {
|
|
- log.Print("积分记录失败-积分增减类型:", data.Sort)
|
|
|
|
|
|
+ log.Print("积分记录失败")
|
|
return entity.ErrorCode, "积分记录失败"
|
|
return entity.ErrorCode, "积分记录失败"
|
|
}
|
|
}
|
|
|
|
|
|
//结存消耗
|
|
//结存消耗
|
|
soldelist := []entity.Solde{}
|
|
soldelist := []entity.Solde{}
|
|
- err = entity.Engine.Table("integral_solde").Where("appId=? and userId=? and endDate> ? and( ( perManEntPoints != 0 AND timePoints = 0 ) OR ( perManEntPoints = 0 AND timePoints != 0 ))", data.AppId, data.UserId, time.Now().Format("2006-01-02")).Desc("endDate").Desc("timePoints").Find(&soldelist)
|
|
|
|
|
|
+ err = entity.Engine.Table("integral_solde").
|
|
|
|
+ Where("appId=? and userId=? and endDate> ? and( ( perManEntPoints != 0 AND timePoints = 0 ) OR ( perManEntPoints = 0 AND timePoints != 0 ))", data.AppId, data.UserId, time.Now().Format("2006-01-02")).
|
|
|
|
+ Desc("endDate").
|
|
|
|
+ Desc("timePoints").Find(&soldelist)
|
|
if len(soldelist) == 0 {
|
|
if len(soldelist) == 0 {
|
|
return entity.ErrorCode, "没有结存可以消耗"
|
|
return entity.ErrorCode, "没有结存可以消耗"
|
|
}
|
|
}
|