瀏覽代碼

update 一个圈圈

master
DengBiao 10 月之前
父節點
當前提交
0936db344e
共有 1 個文件被更改,包括 40 次插入17 次删除
  1. +40
    -17
      rule/one_circles/one_circles_available_green_energy_settlement.go

+ 40
- 17
rule/one_circles/one_circles_available_green_energy_settlement.go 查看文件

@@ -4,9 +4,11 @@ import (
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db"
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db/model"
md2 "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/one_circles/md"
zhios_order_relate_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils"
"encoding/json"
"errors"
"github.com/shopspring/decimal"
"time"
"xorm.io/xorm"
)

@@ -107,23 +109,44 @@ func NewCalcPriceReductionFormula(userExchangeNumsValue string, oneCirclesGreenE
}

// JudgeUserIsCanBuyWelfareOrders 判断用户是否可以购买福利订单
func JudgeUserIsCanBuyWelfareOrders(engine *xorm.Engine, uid int) (err error, values, nowPriceValue, afterPriceValue string) {
func JudgeUserIsCanBuyWelfareOrders(engine *xorm.Engine, uid int) (err error) {
now := time.Now()
//1、查找 `one_circles_green_energy_basic_setting` 基础设置
//oneCirclesGreenEnergyBasicSetting, err := db.OneCirclesGreenEnergyBasicSettingGetOneByParams(engine, map[string]interface{}{
// "key": "is_open",
// "value": 1,
//})
//if err != nil {
// return
//}
//userAmount, _ := decimal.NewFromString(userAmountValue) //用户资金
//nowPrice, _ := decimal.NewFromString(oneCirclesGreenEnergyBasicSetting.NowPrice) //当前价格
//originalQuantityNums, _ := decimal.NewFromString(oneCirclesGreenEnergyBasicSetting.OriginalQuantityNums) //原始数量
//originalQuantityFunds, _ := decimal.NewFromString(oneCirclesGreenEnergyBasicSetting.OriginalFunds) //原始资金
//afterPrice := (userAmount.Add(originalQuantityFunds)).Div(originalQuantityNums).Truncate(8) //涨价后的价格
//
//values = userAmount.Div(afterPrice).Truncate(8).String() //用户得到绿色能量个数
//nowPriceValue = nowPrice.String()
//afterPriceValue = afterPrice.String()
oneCirclesGreenEnergyBasicSetting, err := db.OneCirclesGreenEnergyBasicSettingGetOneByParams(engine, map[string]interface{}{
"key": "is_open",
"value": 1,
})
if err != nil {
return
}
var welfareOrdersLimit *md2.WelfareOrdersLimit
err = json.Unmarshal([]byte(oneCirclesGreenEnergyBasicSetting.WelfareOrdersLimit), &welfareOrdersLimit)
if err != nil {
return
}

//2、计算当前用户连续日活
startDate := now.AddDate(0, 0, -7).Format("2006-01-02")
endDate := now.Format("2006-01-02")
err, days, isContinuousDailyActivity := CalcUserContinuousDailyActivityDays(engine, "", uid, startDate, endDate)
if err != nil {
return
}
if !isContinuousDailyActivity {
err = errors.New("未连续日活不可购买")
}
if days < zhios_order_relate_utils.StrToInt(welfareOrdersLimit.ContinuousDailyActivityNums) {
err = errors.New("连续日活天数不够")
}

//3、计算直推人数
userRelates, err := db.DbsUserRelateByParentUid(engine, uid, 1)
if err != nil {
return
}
if len(*userRelates) < zhios_order_relate_utils.StrToInt(welfareOrdersLimit.DirectPushLimit.DirectPushUserNums) {
err = errors.New("直推人数不够")
}

return
}

Loading…
取消
儲存