李哲 преди 4 години
родител
ревизия
a49c8188d9
променени са 2 файла, в които са добавени 18 реда и са изтрити 15 реда
  1. 0 1
      entity/integral.go
  2. 18 14
      service/integralService.go

+ 0 - 1
entity/integral.go

@@ -81,7 +81,6 @@ type FlowJSON struct {
 	Point          int64  `xorm:"point" form:"point" json:"point"`                            //积分
 	Point          int64  `xorm:"point" form:"point" json:"point"`                            //积分
 	EndDate        string `xorm:"endDate" form:"endDate" json:"endDate"`                      //截止时间
 	EndDate        string `xorm:"endDate" form:"endDate" json:"endDate"`                      //截止时间
 	AppId          int    `xorm:"appId" form:"appId" json:"appId"`                            //剑鱼标识
 	AppId          int    `xorm:"appId" form:"appId" json:"appId"`                            //剑鱼标识
-	Sort           int    `xorm:"sort" form:"sort" json:"sort"`                               //操作类型1加-1减
 	OperationType  bool   `xorm:"operationType" form:"operationType" json:"operationType"`    //永久:true、时效:false
 	OperationType  bool   `xorm:"operationType" form:"operationType" json:"operationType"`    //永久:true、时效:false
 }
 }
 
 

+ 18 - 14
service/integralService.go

@@ -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, "没有结存可以消耗"
 	}
 	}