|
@@ -21,12 +21,11 @@ const (
|
|
|
)
|
|
|
|
|
|
//根据账户标识新增资源
|
|
|
-func (service *BalanceService) PurchaseUserBalance(balanceData *resourcesCenter.Balance, detailedData *resourcesCenter.Detailed) (int64, string) {
|
|
|
+func (service *BalanceService) PurchaseUserBalance(balanceData *resourcesCenter.Balance, detailedData *resourcesCenter.Detailed, producMap map[string]interface{}) (int64, string) {
|
|
|
orm := entity.Engine.NewSession()
|
|
|
err := orm.Begin()
|
|
|
balance := entity.Balance{}
|
|
|
- log.Println(balance.ResourceType, "附件下载包", balance.ResourceType == "附件下载包")
|
|
|
- if balanceData.ResourceType == "附件下载包" {
|
|
|
+ if producMap[balanceData.ResourceType] != nil {
|
|
|
fool, err := orm.Table(AccountResources).
|
|
|
Select("*").
|
|
|
Where("accountId=? and companyId=? and departmentId=? and ResourceType=? and endTime=? and vipTime=?", balanceData.AccountId, balanceData.CompanyId, balanceData.DepartmentId, balanceData.ResourceType, balanceData.EndTime, balanceData.VipTime).
|
|
@@ -105,7 +104,7 @@ func (service *BalanceService) PurchaseUserBalance(balanceData *resourcesCenter.
|
|
|
}
|
|
|
|
|
|
//根据账户标识使用资源
|
|
|
-func (service *BalanceService) UseUserDetailed(duplicateRemoval int64, balanceData *resourcesCenter.Balance, detailedData *resourcesCenter.Detailed, infoId, url string) (int64, string, int64) {
|
|
|
+func (service *BalanceService) UseUserDetailed(duplicateRemoval int64, balanceData *resourcesCenter.Balance, detailedData *resourcesCenter.Detailed, infoId, url string, producMap map[string]interface{}) (int64, string, int64) {
|
|
|
orm := entity.Engine.NewSession()
|
|
|
err := orm.Begin()
|
|
|
//去重
|
|
@@ -118,8 +117,8 @@ func (service *BalanceService) UseUserDetailed(duplicateRemoval int64, balanceDa
|
|
|
} else if detailedData.ResourceType == "高级字段包" {
|
|
|
dataDesc = 1
|
|
|
}
|
|
|
- url = url + "/data/dedupAndSave/"+fmt.Sprint(time.Now().Unix())+"?dataDesc=" + fmt.Sprint(dataDesc) + "&personId=" + detailedData.UserId + "&infoId=" + infoId + "&accountId=" + detailedData.AccountId
|
|
|
- log.Println( url)
|
|
|
+ url = url + "/data/dedupAndSave/" + fmt.Sprint(time.Now().Unix()) + "?dataDesc=" + fmt.Sprint(dataDesc) + "&personId=" + detailedData.UserId + "&infoId=" + infoId + "&accountId=" + detailedData.AccountId
|
|
|
+ log.Println(url)
|
|
|
res, urlerr := http.PostForm(url, nil)
|
|
|
if urlerr != nil {
|
|
|
return entity.ErrorCode, "去重失败", 0
|
|
@@ -133,30 +132,32 @@ func (service *BalanceService) UseUserDetailed(duplicateRemoval int64, balanceDa
|
|
|
if dat.Code == 0 {
|
|
|
deductionNumb = dat.Data.NewCount
|
|
|
deductionNumbs = dat.Data.NewCount
|
|
|
- var appheader = "application/x-www-form-urlencoded"
|
|
|
- param := "dataDesc=" + fmt.Sprint(dataDesc) + "&personId=" + detailedData.UserId + "&infoId=" + infoId + "&accountId=" + detailedData.AccountId
|
|
|
- resp, status, _ := HttpPost_M(url+"/data/dedupAndSave/"+fmt.Sprint(time.Now().Unix()), appheader, param, 20)
|
|
|
- log.Println(resp, status)
|
|
|
- if status != 200 && (resp == nil || len(resp) <= 0) {
|
|
|
- return entity.ErrorCode, "请求去重接口出错", 0
|
|
|
- }
|
|
|
- data := resp["data"].(map[string]interface{})
|
|
|
- if fmt.Sprint(resp["code"]) == "0" {
|
|
|
- deductionNumb, _ = strconv.ParseInt(fmt.Sprint(data["newCount"]), 10, 64)
|
|
|
- deductionNumbs, _ = strconv.ParseInt(fmt.Sprint(data["newCount"]), 10, 64)
|
|
|
- if fmt.Sprint(data["totalCount"]) == "0" {
|
|
|
- return entity.ErrorCode, "去重失败", 0
|
|
|
+ var appheader = "application/x-www-form-urlencoded"
|
|
|
+ param := "dataDesc=" + fmt.Sprint(dataDesc) + "&personId=" + detailedData.UserId + "&infoId=" + infoId + "&accountId=" + detailedData.AccountId
|
|
|
+ resp, status, _ := HttpPost_M(url+"/data/dedupAndSave/"+fmt.Sprint(time.Now().Unix()), appheader, param, 20)
|
|
|
+ log.Println(resp, status)
|
|
|
+ if status != 200 && (resp == nil || len(resp) <= 0) {
|
|
|
+ return entity.ErrorCode, "请求去重接口出错", 0
|
|
|
}
|
|
|
- } else {
|
|
|
+ data := resp["data"].(map[string]interface{})
|
|
|
+ if fmt.Sprint(resp["code"]) == "0" {
|
|
|
+ deductionNumb, _ = strconv.ParseInt(fmt.Sprint(data["newCount"]), 10, 64)
|
|
|
+ deductionNumbs, _ = strconv.ParseInt(fmt.Sprint(data["newCount"]), 10, 64)
|
|
|
+ if fmt.Sprint(data["totalCount"]) == "0" {
|
|
|
+ return entity.ErrorCode, "去重失败", 0
|
|
|
+ }
|
|
|
+ } else {
|
|
|
return entity.ErrorCode, "去重失败", 0
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
//查询结存是否够用
|
|
|
type SumStruct struct {
|
|
|
Age int `xorm:"age"`
|
|
|
}
|
|
|
sumStruct := "0"
|
|
|
- if balanceData.ResourceType == "附件下载包" {
|
|
|
+ if producMap[balanceData.ResourceType] != nil {
|
|
|
now1 := time.Now()
|
|
|
currentYear, currentMonth, _ := now1.Date()
|
|
|
currentLocation := now1.Location()
|
|
@@ -209,7 +210,7 @@ func (service *BalanceService) UseUserDetailed(duplicateRemoval int64, balanceDa
|
|
|
}
|
|
|
//修改结存
|
|
|
balanceList := []entity.Balance{}
|
|
|
- if balanceData.ResourceType == "附件下载包" {
|
|
|
+ if producMap[balanceData.ResourceType] != nil {
|
|
|
now1 := time.Now()
|
|
|
currentYear, currentMonth, _ := now1.Date()
|
|
|
currentLocation := now1.Location()
|
|
@@ -312,7 +313,7 @@ func HttpPost_M(href, contentType, param string, timeout int) (map[string]interf
|
|
|
}
|
|
|
|
|
|
//账号合并
|
|
|
-func (service *BalanceService) UserMerge(mergeUser, mergedUser, appId string) (int64, string) {
|
|
|
+func (service *BalanceService) UserMerge(mergeUser, mergedUser, appId string, producMap map[string]interface{}) (int64, string) {
|
|
|
orm := entity.Engine.NewSession()
|
|
|
err := orm.Begin()
|
|
|
if err != nil {
|
|
@@ -367,19 +368,18 @@ func (service *BalanceService) UserMerge(mergeUser, mergedUser, appId string) (i
|
|
|
}
|
|
|
filter, _ := json.Marshal(filter_map)
|
|
|
mergeDetailed := entity.Detailed{
|
|
|
- AccountId: mergeUser,
|
|
|
- CompanyId: int64(0),
|
|
|
- DepartmentId: int64(0),
|
|
|
- ResourceType: value.ResourceType + "(合并)",
|
|
|
- Number: value.Number,
|
|
|
- RuleId: "",
|
|
|
- CreateTime: time.Now().Local(),
|
|
|
- UserType: 1,
|
|
|
- UserId: mergeUser,
|
|
|
- Remarks: string(filter),
|
|
|
- DeductionNumb:
|
|
|
- int64(0),
|
|
|
- Name: value.Name + "(合并)",
|
|
|
+ AccountId: mergeUser,
|
|
|
+ CompanyId: int64(0),
|
|
|
+ DepartmentId: int64(0),
|
|
|
+ ResourceType: value.ResourceType + "(合并)",
|
|
|
+ Number: value.Number,
|
|
|
+ RuleId: "",
|
|
|
+ CreateTime: time.Now().Local(),
|
|
|
+ UserType: 1,
|
|
|
+ UserId: mergeUser,
|
|
|
+ Remarks: string(filter),
|
|
|
+ DeductionNumb: int64(0),
|
|
|
+ Name: value.Name + "(合并)",
|
|
|
}
|
|
|
insertNumb, err = orm.Table(ConsumeRecord).Insert(&mergeDetailed)
|
|
|
if err != nil || insertNumb <= 0 {
|
|
@@ -389,7 +389,7 @@ func (service *BalanceService) UserMerge(mergeUser, mergedUser, appId string) (i
|
|
|
}
|
|
|
//结存操作
|
|
|
balance := entity.Balance{}
|
|
|
- if value.ResourceType == "附件下载包" {
|
|
|
+ if producMap[value.ResourceType] != nil {
|
|
|
_, err = orm.Table(AccountResources).
|
|
|
Select("*").
|
|
|
Where("accountId=? and resourceType=? endTime=? and vipTime=?", mergeUser, value.ResourceType, value.EndTime, value.VipTime).
|
|
@@ -452,8 +452,8 @@ func (service *BalanceService) UserMerge(mergeUser, mergedUser, appId string) (i
|
|
|
|
|
|
}
|
|
|
|
|
|
-//根据账户标识使用资源
|
|
|
-func (service *BalanceService) UpdateVipTime(data *resourcesCenter.VipReq) (int64, string) {
|
|
|
+//超级订阅时间修改
|
|
|
+func (service *BalanceService) UpdateVipTime(data *resourcesCenter.VipReq, producMap map[string]interface{}) (int64, string) {
|
|
|
orm := entity.Engine.NewSession()
|
|
|
err := orm.Begin()
|
|
|
defer orm.Close()
|
|
@@ -465,10 +465,13 @@ func (service *BalanceService) UpdateVipTime(data *resourcesCenter.VipReq) (int6
|
|
|
lastOfMonth := firstOfMonth.AddDate(0, 1, -1)
|
|
|
endTime := lastOfMonth.Format("2006-01-02")
|
|
|
dataMap := map[string]interface{}{
|
|
|
- "vipTime": data.VipTime,
|
|
|
+ "vipTime": data.VipTime,
|
|
|
}
|
|
|
+ productValue, _ := entity.GetInForComma(producMap)
|
|
|
+ resourceTypeStr := `FIND_IN_SET(resourceType,%s)`
|
|
|
+ resourceTypeStr = fmt.Sprintf(` FIND_IN_SET(resourceType,"%s")`, productValue)
|
|
|
updateNumb, err = orm.Table(AccountResources).
|
|
|
- Cols("vipTime").Where("endTime = ? and accountId=? and resourceType=?",endTime,data.AccountId,"附件下载包").
|
|
|
+ Cols("vipTime").Where("endTime = ? and accountId=? and "+resourceTypeStr, endTime, data.AccountId).
|
|
|
Update(&dataMap)
|
|
|
if err != nil || updateNumb < 0 {
|
|
|
fmt.Println("结存修改失败:", err)
|