|
@@ -9,27 +9,34 @@ import (
|
|
|
|
|
|
type IntegralService struct{}
|
|
|
|
|
|
-//新增、消耗积分流水
|
|
|
-func (service *IntegralService) IntegralConsumeService() bool {
|
|
|
+
|
|
|
+//消耗积分流水
|
|
|
+func(service *IntegralService) IntegralConsumeService(userId, businessType, createTime, endDate string,pointType, businessTypeId, point, appId int) (int,string) {
|
|
|
+ orm := entity.Engine
|
|
|
flow := entity.Flow{}
|
|
|
- flow.UserId = "222"
|
|
|
- flow.PointType = 1
|
|
|
- flow.BusinessTypeId = 1
|
|
|
- flow.BusinessType = "1"
|
|
|
- flow.Point = 2
|
|
|
- flow.CreateTime = time.Now().Format("2006-01-02 15:04:05")
|
|
|
- flow.EndDate = time.Now().Format("2006-01-02")
|
|
|
- flow.AppId = 10000
|
|
|
- af, err := entity.Engine.Table("integral_flow").Insert(&flow)
|
|
|
- if err != nil {
|
|
|
- log.Print("消耗积分记录失败")
|
|
|
- return true
|
|
|
+ flow.UserId = userId
|
|
|
+ flow.PointType = pointType
|
|
|
+ flow.BusinessTypeId = businessTypeId
|
|
|
+ flow.BusinessType = businessType
|
|
|
+ flow.Point = point
|
|
|
+ flow.CreateTime = 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 af > 0 {
|
|
|
- log.Println("消耗积分记录成功")
|
|
|
- return true
|
|
|
+ if balance.CountPoints < point {
|
|
|
+ return entity.ErrorCode,"积分余额不足"
|
|
|
}
|
|
|
- return true
|
|
|
+ return entity.SuccessCode,"消耗积分成功"
|
|
|
}
|
|
|
|
|
|
//结存新增
|