@@ -0,0 +1,153 @@ | |||||
package db | |||||
import ( | |||||
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db/model" | |||||
zhios_order_relate_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils" | |||||
zhios_order_relate_logx "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils/logx" | |||||
"errors" | |||||
"fmt" | |||||
"reflect" | |||||
"xorm.io/xorm" | |||||
) | |||||
// BatchSelectOneCirclesAvailableGreenEnergyPointsFlows 批量查询数据 TODO::和下面的方法重复了,建议采用下面的 `OneCirclesAvailableGreenEnergyPointsFlowFindByParams` 方法 | |||||
func BatchSelectOneCirclesAvailableGreenEnergyPointsFlows(Db *xorm.Engine, params map[string]interface{}) (*[]model.OneCirclesAvailableGreenEnergyPointsFlow, error) { | |||||
var OneCirclesAvailableGreenEnergyPointsFlowData []model.OneCirclesAvailableGreenEnergyPointsFlow | |||||
if err := Db.In(zhios_order_relate_utils.AnyToString(params["key"]), params["value"]). | |||||
Find(&OneCirclesAvailableGreenEnergyPointsFlowData); err != nil { | |||||
return nil, zhios_order_relate_logx.Warn(err) | |||||
} | |||||
return &OneCirclesAvailableGreenEnergyPointsFlowData, nil | |||||
} | |||||
// OneCirclesAvailableGreenEnergyPointsFlowInsert 插入单条数据 | |||||
func OneCirclesAvailableGreenEnergyPointsFlowInsert(session *xorm.Session, OneCirclesAvailableGreenEnergyPointsFlow *model.OneCirclesAvailableGreenEnergyPointsFlow) (int64, error) { | |||||
_, err := session.InsertOne(OneCirclesAvailableGreenEnergyPointsFlow) | |||||
if err != nil { | |||||
return 0, err | |||||
} | |||||
return OneCirclesAvailableGreenEnergyPointsFlow.Id, nil | |||||
} | |||||
// BatchAddOneCirclesAvailableGreenEnergyPointsFlows 批量新增数据 | |||||
func BatchAddOneCirclesAvailableGreenEnergyPointsFlows(Db *xorm.Engine, OneCirclesAvailableGreenEnergyPointsFlowData []*model.OneCirclesAvailableGreenEnergyPointsFlow) (int64, error) { | |||||
affected, err := Db.Insert(OneCirclesAvailableGreenEnergyPointsFlowData) | |||||
if err != nil { | |||||
return 0, err | |||||
} | |||||
return affected, nil | |||||
} | |||||
func GetOneCirclesAvailableGreenEnergyPointsFlowCount(Db *xorm.Engine) int { | |||||
var OneCirclesAvailableGreenEnergyPointsFlow model.OneCirclesAvailableGreenEnergyPointsFlow | |||||
session := Db.Where("") | |||||
count, err := session.Count(&OneCirclesAvailableGreenEnergyPointsFlow) | |||||
if err != nil { | |||||
return 0 | |||||
} | |||||
return int(count) | |||||
} | |||||
// OneCirclesAvailableGreenEnergyPointsFlowDelete 删除记录 | |||||
func OneCirclesAvailableGreenEnergyPointsFlowDelete(Db *xorm.Engine, id interface{}) (int64, error) { | |||||
if reflect.TypeOf(id).Kind() == reflect.Slice { | |||||
return Db.In("id", id).Delete(model.OneCirclesAvailableGreenEnergyPointsFlow{}) | |||||
} else { | |||||
return Db.Where("id = ?", id).Delete(model.OneCirclesAvailableGreenEnergyPointsFlow{}) | |||||
} | |||||
} | |||||
// OneCirclesAvailableGreenEnergyPointsFlowUpdate 更新记录 | |||||
func OneCirclesAvailableGreenEnergyPointsFlowUpdate(session *xorm.Session, id interface{}, OneCirclesAvailableGreenEnergyPointsFlow *model.OneCirclesAvailableGreenEnergyPointsFlow, forceColums ...string) (int64, error) { | |||||
var ( | |||||
affected int64 | |||||
err error | |||||
) | |||||
if forceColums != nil { | |||||
affected, err = session.Where("id=?", id).Cols(forceColums...).Update(OneCirclesAvailableGreenEnergyPointsFlow) | |||||
} else { | |||||
affected, err = session.Where("id=?", id).Update(OneCirclesAvailableGreenEnergyPointsFlow) | |||||
} | |||||
if err != nil { | |||||
return 0, err | |||||
} | |||||
return affected, nil | |||||
} | |||||
// OneCirclesAvailableGreenEnergyPointsFlowGetOneByParams 通过传入的参数查询数据(单条) | |||||
func OneCirclesAvailableGreenEnergyPointsFlowGetOneByParams(Db *xorm.Engine, params map[string]interface{}) (*model.OneCirclesAvailableGreenEnergyPointsFlow, error) { | |||||
var m model.OneCirclesAvailableGreenEnergyPointsFlow | |||||
var query = fmt.Sprintf("%s =?", params["key"]) | |||||
if has, err := Db.Where(query, params["value"]).Get(&m); err != nil || has == false { | |||||
return nil, zhios_order_relate_logx.Error(err) | |||||
} | |||||
return &m, nil | |||||
} | |||||
// OneCirclesAvailableGreenEnergyPointsFlowFindByParams 通过传入的参数查询数据(多条) | |||||
func OneCirclesAvailableGreenEnergyPointsFlowFindByParams(Db *xorm.Engine, params map[string]interface{}) (*[]model.OneCirclesAvailableGreenEnergyPointsFlow, error) { | |||||
var m []model.OneCirclesAvailableGreenEnergyPointsFlow | |||||
if params["value"] == nil { | |||||
return nil, errors.New("参数有误") | |||||
} | |||||
if params["key"] == nil { | |||||
//查询全部数据 | |||||
err := Db.Find(&m) | |||||
if err != nil { | |||||
return nil, zhios_order_relate_logx.Error(err) | |||||
} | |||||
return &m, nil | |||||
} else { | |||||
if reflect.TypeOf(params["value"]).Kind() == reflect.Slice { | |||||
//指定In查询 | |||||
if err := Db.In(zhios_order_relate_utils.AnyToString(params["key"]), params["value"]).Find(&m); err != nil { | |||||
return nil, zhios_order_relate_logx.Warn(err) | |||||
} | |||||
return &m, nil | |||||
} else { | |||||
var query = fmt.Sprintf("%s =?", params["key"]) | |||||
err := Db.Where(query, params["value"]).Find(&m) | |||||
if err != nil { | |||||
return nil, zhios_order_relate_logx.Error(err) | |||||
} | |||||
return &m, nil | |||||
} | |||||
} | |||||
} | |||||
func OneCirclesAvailableGreenEnergyPointsFlowFindByParamsByPage(Db *xorm.Engine, params map[string]interface{}, page, pageSize int) (*[]model.OneCirclesAvailableGreenEnergyPointsFlow, error) { | |||||
var m []model.OneCirclesAvailableGreenEnergyPointsFlow | |||||
if params["value"] == nil { | |||||
return nil, errors.New("参数有误") | |||||
} | |||||
if page == 0 && pageSize == 0 { | |||||
page = 1 | |||||
pageSize = 10 | |||||
} | |||||
if params["key"] == nil { | |||||
//查询全部数据 | |||||
err := Db.Limit(pageSize, (page-1)*pageSize).Find(&m) | |||||
if err != nil { | |||||
return nil, zhios_order_relate_logx.Error(err) | |||||
} | |||||
return &m, nil | |||||
} else { | |||||
if reflect.TypeOf(params["value"]).Kind() == reflect.Slice { | |||||
//指定In查询 | |||||
if err := Db.In(zhios_order_relate_utils.AnyToString(params["key"]), params["value"]).Limit(pageSize, (page-1)*pageSize).Find(&m); err != nil { | |||||
return nil, zhios_order_relate_logx.Warn(err) | |||||
} | |||||
return &m, nil | |||||
} else { | |||||
var query = fmt.Sprintf("%s =?", params["key"]) | |||||
err := Db.Where(query, params["value"]).Limit(pageSize, (page-1)*pageSize).Find(&m) | |||||
if err != nil { | |||||
return nil, zhios_order_relate_logx.Error(err) | |||||
} | |||||
return &m, nil | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,167 @@ | |||||
package db | |||||
import ( | |||||
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db/model" | |||||
zhios_order_relate_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils" | |||||
zhios_order_relate_logx "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils/logx" | |||||
"errors" | |||||
"fmt" | |||||
"reflect" | |||||
"xorm.io/xorm" | |||||
) | |||||
// BatchSelectOneCirclesGreenEnergyBasicSettings 批量查询数据 TODO::和下面的方法重复了,建议采用下面的 `OneCirclesGreenEnergyBasicSettingFindByParams` 方法 | |||||
func BatchSelectOneCirclesGreenEnergyBasicSettings(Db *xorm.Engine, params map[string]interface{}) (*[]model.OneCirclesGreenEnergyBasicSetting, error) { | |||||
var OneCirclesGreenEnergyBasicSettingData []model.OneCirclesGreenEnergyBasicSetting | |||||
if err := Db.In(zhios_order_relate_utils.AnyToString(params["key"]), params["value"]). | |||||
Find(&OneCirclesGreenEnergyBasicSettingData); err != nil { | |||||
return nil, zhios_order_relate_logx.Warn(err) | |||||
} | |||||
return &OneCirclesGreenEnergyBasicSettingData, nil | |||||
} | |||||
// OneCirclesGreenEnergyBasicSettingInsert 插入单条数据 | |||||
func OneCirclesGreenEnergyBasicSettingInsert(Db *xorm.Engine, OneCirclesGreenEnergyBasicSetting *model.OneCirclesGreenEnergyBasicSetting) (int, error) { | |||||
_, err := Db.InsertOne(OneCirclesGreenEnergyBasicSetting) | |||||
if err != nil { | |||||
return 0, err | |||||
} | |||||
return OneCirclesGreenEnergyBasicSetting.Id, nil | |||||
} | |||||
// BatchAddOneCirclesGreenEnergyBasicSettings 批量新增数据 | |||||
func BatchAddOneCirclesGreenEnergyBasicSettings(Db *xorm.Engine, OneCirclesGreenEnergyBasicSettingData []*model.OneCirclesGreenEnergyBasicSetting) (int64, error) { | |||||
affected, err := Db.Insert(OneCirclesGreenEnergyBasicSettingData) | |||||
if err != nil { | |||||
return 0, err | |||||
} | |||||
return affected, nil | |||||
} | |||||
func GetOneCirclesGreenEnergyBasicSettingCount(Db *xorm.Engine) int { | |||||
var OneCirclesGreenEnergyBasicSetting model.OneCirclesGreenEnergyBasicSetting | |||||
session := Db.Where("") | |||||
count, err := session.Count(&OneCirclesGreenEnergyBasicSetting) | |||||
if err != nil { | |||||
return 0 | |||||
} | |||||
return int(count) | |||||
} | |||||
// OneCirclesGreenEnergyBasicSettingDelete 删除记录 | |||||
func OneCirclesGreenEnergyBasicSettingDelete(Db *xorm.Engine, id interface{}) (int64, error) { | |||||
if reflect.TypeOf(id).Kind() == reflect.Slice { | |||||
return Db.In("id", id).Delete(model.OneCirclesGreenEnergyBasicSetting{}) | |||||
} else { | |||||
return Db.Where("id = ?", id).Delete(model.OneCirclesGreenEnergyBasicSetting{}) | |||||
} | |||||
} | |||||
// OneCirclesGreenEnergyBasicSettingUpdate 更新记录 | |||||
func OneCirclesGreenEnergyBasicSettingUpdate(session *xorm.Session, id interface{}, OneCirclesGreenEnergyBasicSetting *model.OneCirclesGreenEnergyBasicSetting, forceColums ...string) (int64, error) { | |||||
var ( | |||||
affected int64 | |||||
err error | |||||
) | |||||
if forceColums != nil { | |||||
affected, err = session.Where("id=?", id).Cols(forceColums...).Update(OneCirclesGreenEnergyBasicSetting) | |||||
} else { | |||||
affected, err = session.Where("id=?", id).Update(OneCirclesGreenEnergyBasicSetting) | |||||
} | |||||
if err != nil { | |||||
return 0, err | |||||
} | |||||
return affected, nil | |||||
} | |||||
// OneCirclesGreenEnergyBasicSettingGetOneByParamsBySession 通过传入的参数查询数据(单条) | |||||
func OneCirclesGreenEnergyBasicSettingGetOneByParamsBySession(session *xorm.Session, params map[string]interface{}) (*model.OneCirclesGreenEnergyBasicSetting, error) { | |||||
var m model.OneCirclesGreenEnergyBasicSetting | |||||
var query = fmt.Sprintf("%s =?", params["key"]) | |||||
has, err := session.Where(query, params["value"]).Get(&m) | |||||
if err != nil { | |||||
return nil, zhios_order_relate_logx.Error(err) | |||||
} | |||||
if has == false { | |||||
return nil, errors.New("未查询到相应的 block_star_chain 记录") | |||||
} | |||||
return &m, nil | |||||
} | |||||
// OneCirclesGreenEnergyBasicSettingGetOneByParams 通过传入的参数查询数据(单条) | |||||
func OneCirclesGreenEnergyBasicSettingGetOneByParams(Db *xorm.Engine, params map[string]interface{}) (*model.OneCirclesGreenEnergyBasicSetting, error) { | |||||
var m model.OneCirclesGreenEnergyBasicSetting | |||||
var query = fmt.Sprintf("%s =?", params["key"]) | |||||
if has, err := Db.Where(query, params["value"]).Get(&m); err != nil || has == false { | |||||
return nil, zhios_order_relate_logx.Error(err) | |||||
} | |||||
return &m, nil | |||||
} | |||||
// OneCirclesGreenEnergyBasicSettingFindByParams 通过传入的参数查询数据(多条) | |||||
func OneCirclesGreenEnergyBasicSettingFindByParams(Db *xorm.Engine, params map[string]interface{}) (*[]model.OneCirclesGreenEnergyBasicSetting, error) { | |||||
var m []model.OneCirclesGreenEnergyBasicSetting | |||||
if params["value"] == nil { | |||||
return nil, errors.New("参数有误") | |||||
} | |||||
if params["key"] == nil { | |||||
//查询全部数据 | |||||
err := Db.Find(&m) | |||||
if err != nil { | |||||
return nil, zhios_order_relate_logx.Error(err) | |||||
} | |||||
return &m, nil | |||||
} else { | |||||
if reflect.TypeOf(params["value"]).Kind() == reflect.Slice { | |||||
//指定In查询 | |||||
if err := Db.In(zhios_order_relate_utils.AnyToString(params["key"]), params["value"]).Find(&m); err != nil { | |||||
return nil, zhios_order_relate_logx.Warn(err) | |||||
} | |||||
return &m, nil | |||||
} else { | |||||
var query = fmt.Sprintf("%s =?", params["key"]) | |||||
err := Db.Where(query, params["value"]).Find(&m) | |||||
if err != nil { | |||||
return nil, zhios_order_relate_logx.Error(err) | |||||
} | |||||
return &m, nil | |||||
} | |||||
} | |||||
} | |||||
func OneCirclesGreenEnergyBasicSettingFindByParamsByPage(Db *xorm.Engine, params map[string]interface{}, page, pageSize int) (*[]model.OneCirclesGreenEnergyBasicSetting, error) { | |||||
var m []model.OneCirclesGreenEnergyBasicSetting | |||||
if params["value"] == nil { | |||||
return nil, errors.New("参数有误") | |||||
} | |||||
if page == 0 && pageSize == 0 { | |||||
page = 1 | |||||
pageSize = 10 | |||||
} | |||||
if params["key"] == nil { | |||||
//查询全部数据 | |||||
err := Db.Limit(pageSize, (page-1)*pageSize).Find(&m) | |||||
if err != nil { | |||||
return nil, zhios_order_relate_logx.Error(err) | |||||
} | |||||
return &m, nil | |||||
} else { | |||||
if reflect.TypeOf(params["value"]).Kind() == reflect.Slice { | |||||
//指定In查询 | |||||
if err := Db.In(zhios_order_relate_utils.AnyToString(params["key"]), params["value"]).Limit(pageSize, (page-1)*pageSize).Find(&m); err != nil { | |||||
return nil, zhios_order_relate_logx.Warn(err) | |||||
} | |||||
return &m, nil | |||||
} else { | |||||
var query = fmt.Sprintf("%s =?", params["key"]) | |||||
err := Db.Where(query, params["value"]).Limit(pageSize, (page-1)*pageSize).Find(&m) | |||||
if err != nil { | |||||
return nil, zhios_order_relate_logx.Error(err) | |||||
} | |||||
return &m, nil | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,167 @@ | |||||
package db | |||||
import ( | |||||
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db/model" | |||||
zhios_order_relate_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils" | |||||
zhios_order_relate_logx "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils/logx" | |||||
"errors" | |||||
"fmt" | |||||
"reflect" | |||||
"xorm.io/xorm" | |||||
) | |||||
// BatchSelectOneCirclesGreenEnergySignIns 批量查询数据 TODO::和下面的方法重复了,建议采用下面的 `OneCirclesGreenEnergySignInFindByParams` 方法 | |||||
func BatchSelectOneCirclesGreenEnergySignIns(Db *xorm.Engine, params map[string]interface{}) (*[]model.OneCirclesGreenEnergySignIn, error) { | |||||
var OneCirclesGreenEnergySignInData []model.OneCirclesGreenEnergySignIn | |||||
if err := Db.In(zhios_order_relate_utils.AnyToString(params["key"]), params["value"]). | |||||
Find(&OneCirclesGreenEnergySignInData); err != nil { | |||||
return nil, zhios_order_relate_logx.Warn(err) | |||||
} | |||||
return &OneCirclesGreenEnergySignInData, nil | |||||
} | |||||
// OneCirclesGreenEnergySignInInsert 插入单条数据 | |||||
func OneCirclesGreenEnergySignInInsert(Db *xorm.Engine, OneCirclesGreenEnergySignIn *model.OneCirclesGreenEnergySignIn) (int64, error) { | |||||
_, err := Db.InsertOne(OneCirclesGreenEnergySignIn) | |||||
if err != nil { | |||||
return 0, err | |||||
} | |||||
return OneCirclesGreenEnergySignIn.Id, nil | |||||
} | |||||
// BatchAddOneCirclesGreenEnergySignIns 批量新增数据 | |||||
func BatchAddOneCirclesGreenEnergySignIns(Db *xorm.Engine, OneCirclesGreenEnergySignInData []*model.OneCirclesGreenEnergySignIn) (int64, error) { | |||||
affected, err := Db.Insert(OneCirclesGreenEnergySignInData) | |||||
if err != nil { | |||||
return 0, err | |||||
} | |||||
return affected, nil | |||||
} | |||||
func GetOneCirclesGreenEnergySignInCount(Db *xorm.Engine) int { | |||||
var OneCirclesGreenEnergySignIn model.OneCirclesGreenEnergySignIn | |||||
session := Db.Where("") | |||||
count, err := session.Count(&OneCirclesGreenEnergySignIn) | |||||
if err != nil { | |||||
return 0 | |||||
} | |||||
return int(count) | |||||
} | |||||
// OneCirclesGreenEnergySignInDelete 删除记录 | |||||
func OneCirclesGreenEnergySignInDelete(Db *xorm.Engine, id interface{}) (int64, error) { | |||||
if reflect.TypeOf(id).Kind() == reflect.Slice { | |||||
return Db.In("id", id).Delete(model.OneCirclesGreenEnergySignIn{}) | |||||
} else { | |||||
return Db.Where("id = ?", id).Delete(model.OneCirclesGreenEnergySignIn{}) | |||||
} | |||||
} | |||||
// OneCirclesGreenEnergySignInUpdate 更新记录 | |||||
func OneCirclesGreenEnergySignInUpdate(session *xorm.Session, id interface{}, OneCirclesGreenEnergySignIn *model.OneCirclesGreenEnergySignIn, forceColums ...string) (int64, error) { | |||||
var ( | |||||
affected int64 | |||||
err error | |||||
) | |||||
if forceColums != nil { | |||||
affected, err = session.Where("id=?", id).Cols(forceColums...).Update(OneCirclesGreenEnergySignIn) | |||||
} else { | |||||
affected, err = session.Where("id=?", id).Update(OneCirclesGreenEnergySignIn) | |||||
} | |||||
if err != nil { | |||||
return 0, err | |||||
} | |||||
return affected, nil | |||||
} | |||||
// OneCirclesGreenEnergySignInGetOneByParamsBySession 通过传入的参数查询数据(单条) | |||||
func OneCirclesGreenEnergySignInGetOneByParamsBySession(session *xorm.Session, params map[string]interface{}) (*model.OneCirclesGreenEnergySignIn, error) { | |||||
var m model.OneCirclesGreenEnergySignIn | |||||
var query = fmt.Sprintf("%s =?", params["key"]) | |||||
has, err := session.Where(query, params["value"]).Get(&m) | |||||
if err != nil { | |||||
return nil, zhios_order_relate_logx.Error(err) | |||||
} | |||||
if has == false { | |||||
return nil, errors.New("未查询到相应的 block_star_chain 记录") | |||||
} | |||||
return &m, nil | |||||
} | |||||
// OneCirclesGreenEnergySignInGetOneByParams 通过传入的参数查询数据(单条) | |||||
func OneCirclesGreenEnergySignInGetOneByParams(Db *xorm.Engine, params map[string]interface{}) (*model.OneCirclesGreenEnergySignIn, error) { | |||||
var m model.OneCirclesGreenEnergySignIn | |||||
var query = fmt.Sprintf("%s =?", params["key"]) | |||||
if has, err := Db.Where(query, params["value"]).Get(&m); err != nil || has == false { | |||||
return nil, zhios_order_relate_logx.Error(err) | |||||
} | |||||
return &m, nil | |||||
} | |||||
// OneCirclesGreenEnergySignInFindByParams 通过传入的参数查询数据(多条) | |||||
func OneCirclesGreenEnergySignInFindByParams(Db *xorm.Engine, params map[string]interface{}) (*[]model.OneCirclesGreenEnergySignIn, error) { | |||||
var m []model.OneCirclesGreenEnergySignIn | |||||
if params["value"] == nil { | |||||
return nil, errors.New("参数有误") | |||||
} | |||||
if params["key"] == nil { | |||||
//查询全部数据 | |||||
err := Db.Find(&m) | |||||
if err != nil { | |||||
return nil, zhios_order_relate_logx.Error(err) | |||||
} | |||||
return &m, nil | |||||
} else { | |||||
if reflect.TypeOf(params["value"]).Kind() == reflect.Slice { | |||||
//指定In查询 | |||||
if err := Db.In(zhios_order_relate_utils.AnyToString(params["key"]), params["value"]).Find(&m); err != nil { | |||||
return nil, zhios_order_relate_logx.Warn(err) | |||||
} | |||||
return &m, nil | |||||
} else { | |||||
var query = fmt.Sprintf("%s =?", params["key"]) | |||||
err := Db.Where(query, params["value"]).Find(&m) | |||||
if err != nil { | |||||
return nil, zhios_order_relate_logx.Error(err) | |||||
} | |||||
return &m, nil | |||||
} | |||||
} | |||||
} | |||||
func OneCirclesGreenEnergySignInFindByParamsByPage(Db *xorm.Engine, params map[string]interface{}, page, pageSize int) (*[]model.OneCirclesGreenEnergySignIn, error) { | |||||
var m []model.OneCirclesGreenEnergySignIn | |||||
if params["value"] == nil { | |||||
return nil, errors.New("参数有误") | |||||
} | |||||
if page == 0 && pageSize == 0 { | |||||
page = 1 | |||||
pageSize = 10 | |||||
} | |||||
if params["key"] == nil { | |||||
//查询全部数据 | |||||
err := Db.Limit(pageSize, (page-1)*pageSize).Find(&m) | |||||
if err != nil { | |||||
return nil, zhios_order_relate_logx.Error(err) | |||||
} | |||||
return &m, nil | |||||
} else { | |||||
if reflect.TypeOf(params["value"]).Kind() == reflect.Slice { | |||||
//指定In查询 | |||||
if err := Db.In(zhios_order_relate_utils.AnyToString(params["key"]), params["value"]).Limit(pageSize, (page-1)*pageSize).Find(&m); err != nil { | |||||
return nil, zhios_order_relate_logx.Warn(err) | |||||
} | |||||
return &m, nil | |||||
} else { | |||||
var query = fmt.Sprintf("%s =?", params["key"]) | |||||
err := Db.Where(query, params["value"]).Limit(pageSize, (page-1)*pageSize).Find(&m) | |||||
if err != nil { | |||||
return nil, zhios_order_relate_logx.Error(err) | |||||
} | |||||
return &m, nil | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,107 @@ | |||||
package db | |||||
import ( | |||||
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db/model" | |||||
zhios_order_relate_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils" | |||||
zhios_order_relate_logx "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils/logx" | |||||
"errors" | |||||
"fmt" | |||||
"reflect" | |||||
"xorm.io/xorm" | |||||
) | |||||
// OneCirclesPublicPlatoonBasicSettingInsert 插入单条数据 | |||||
func OneCirclesPublicPlatoonBasicSettingInsert(Db *xorm.Engine, OneCirclesPublicPlatoonBasicSetting *model.OneCirclesPublicPlatoonBasicSetting) (int, error) { | |||||
_, err := Db.InsertOne(OneCirclesPublicPlatoonBasicSetting) | |||||
if err != nil { | |||||
return 0, err | |||||
} | |||||
return OneCirclesPublicPlatoonBasicSetting.Id, nil | |||||
} | |||||
// BatchAddOneCirclesPublicPlatoonBasicSettings 批量新增数据 | |||||
func BatchAddOneCirclesPublicPlatoonBasicSettings(Db *xorm.Engine, OneCirclesPublicPlatoonBasicSettingData []*model.OneCirclesPublicPlatoonBasicSetting) (int64, error) { | |||||
affected, err := Db.Insert(OneCirclesPublicPlatoonBasicSettingData) | |||||
if err != nil { | |||||
return 0, err | |||||
} | |||||
return affected, nil | |||||
} | |||||
func GetOneCirclesPublicPlatoonBasicSettingCount(Db *xorm.Engine) int { | |||||
var OneCirclesPublicPlatoonBasicSetting model.OneCirclesPublicPlatoonBasicSetting | |||||
session := Db.Where("") | |||||
count, err := session.Count(&OneCirclesPublicPlatoonBasicSetting) | |||||
if err != nil { | |||||
return 0 | |||||
} | |||||
return int(count) | |||||
} | |||||
// OneCirclesPublicPlatoonBasicSettingDelete 删除记录 | |||||
func OneCirclesPublicPlatoonBasicSettingDelete(Db *xorm.Engine, id interface{}) (int64, error) { | |||||
if reflect.TypeOf(id).Kind() == reflect.Slice { | |||||
return Db.In("id", id).Delete(model.OneCirclesPublicPlatoonBasicSetting{}) | |||||
} else { | |||||
return Db.Where("id = ?", id).Delete(model.OneCirclesPublicPlatoonBasicSetting{}) | |||||
} | |||||
} | |||||
// OneCirclesPublicPlatoonBasicSettingUpdate 更新记录 | |||||
func OneCirclesPublicPlatoonBasicSettingUpdate(Db *xorm.Engine, id interface{}, OneCirclesPublicPlatoonBasicSetting *model.OneCirclesPublicPlatoonBasicSetting, forceColums ...string) (int64, error) { | |||||
var ( | |||||
affected int64 | |||||
err error | |||||
) | |||||
if forceColums != nil { | |||||
affected, err = Db.Where("id=?", id).Cols(forceColums...).Update(OneCirclesPublicPlatoonBasicSetting) | |||||
} else { | |||||
affected, err = Db.Where("id=?", id).Update(OneCirclesPublicPlatoonBasicSetting) | |||||
} | |||||
if err != nil { | |||||
return 0, err | |||||
} | |||||
return affected, nil | |||||
} | |||||
// OneCirclesPublicPlatoonBasicSettingGetOneByParams 通过传入的参数查询数据(单条) | |||||
func OneCirclesPublicPlatoonBasicSettingGetOneByParams(Db *xorm.Engine, params map[string]interface{}) (*model.OneCirclesPublicPlatoonBasicSetting, error) { | |||||
var m model.OneCirclesPublicPlatoonBasicSetting | |||||
var query = fmt.Sprintf("%s =?", params["key"]) | |||||
if has, err := Db.Where(query, params["value"]).Get(&m); err != nil || has == false { | |||||
return nil, zhios_order_relate_logx.Error(err) | |||||
} | |||||
return &m, nil | |||||
} | |||||
// OneCirclesPublicPlatoonBasicSettingFindByParams 通过传入的参数查询数据(多条) | |||||
func OneCirclesPublicPlatoonBasicSettingFindByParams(Db *xorm.Engine, params map[string]interface{}) (*[]model.OneCirclesPublicPlatoonBasicSetting, error) { | |||||
var m []model.OneCirclesPublicPlatoonBasicSetting | |||||
if params["value"] == nil { | |||||
return nil, errors.New("参数有误") | |||||
} | |||||
if params["key"] == nil { | |||||
//查询全部数据 | |||||
err := Db.Find(&m) | |||||
if err != nil { | |||||
return nil, zhios_order_relate_logx.Error(err) | |||||
} | |||||
return &m, nil | |||||
} else { | |||||
if reflect.TypeOf(params["value"]).Kind() == reflect.Slice { | |||||
//指定In查询 | |||||
if err := Db.In(zhios_order_relate_utils.AnyToString(params["key"]), params["value"]).Find(&m); err != nil { | |||||
return nil, zhios_order_relate_logx.Warn(err) | |||||
} | |||||
return &m, nil | |||||
} else { | |||||
var query = fmt.Sprintf("%s =?", params["key"]) | |||||
err := Db.Where(query, params["value"]).Find(&m) | |||||
if err != nil { | |||||
return nil, zhios_order_relate_logx.Error(err) | |||||
} | |||||
return &m, nil | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,195 @@ | |||||
package db | |||||
import ( | |||||
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db/model" | |||||
zhios_order_relate_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils" | |||||
zhios_order_relate_logx "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils/logx" | |||||
"errors" | |||||
"fmt" | |||||
"reflect" | |||||
"xorm.io/xorm" | |||||
) | |||||
// OneCirclesPublicPlatoonUserRelationInsert 插入单条数据 | |||||
func OneCirclesPublicPlatoonUserRelationInsert(Db *xorm.Engine, OneCirclesPublicPlatoonUserRelation *model.OneCirclesPublicPlatoonUserRelation) (int, error) { | |||||
_, err := Db.InsertOne(OneCirclesPublicPlatoonUserRelation) | |||||
if err != nil { | |||||
return 0, err | |||||
} | |||||
return OneCirclesPublicPlatoonUserRelation.Id, nil | |||||
} | |||||
// BatchAddOneCirclesPublicPlatoonUserRelations 批量新增数据 | |||||
func BatchAddOneCirclesPublicPlatoonUserRelations(Db *xorm.Engine, OneCirclesPublicPlatoonUserRelationData []*model.OneCirclesPublicPlatoonUserRelation) (int64, error) { | |||||
affected, err := Db.Insert(OneCirclesPublicPlatoonUserRelationData) | |||||
if err != nil { | |||||
return 0, err | |||||
} | |||||
return affected, nil | |||||
} | |||||
func GetOneCirclesPublicPlatoonUserRelationCount(Db *xorm.Engine) int { | |||||
var OneCirclesPublicPlatoonUserRelation model.OneCirclesPublicPlatoonUserRelation | |||||
session := Db.Where("") | |||||
count, err := session.Count(&OneCirclesPublicPlatoonUserRelation) | |||||
if err != nil { | |||||
return 0 | |||||
} | |||||
return int(count) | |||||
} | |||||
// OneCirclesPublicPlatoonUserRelationDelete 删除记录 | |||||
func OneCirclesPublicPlatoonUserRelationDelete(Db *xorm.Engine, id interface{}) (int64, error) { | |||||
if reflect.TypeOf(id).Kind() == reflect.Slice { | |||||
return Db.In("id", id).Delete(model.OneCirclesPublicPlatoonUserRelation{}) | |||||
} else { | |||||
return Db.Where("id = ?", id).Delete(model.OneCirclesPublicPlatoonUserRelation{}) | |||||
} | |||||
} | |||||
// OneCirclesPublicPlatoonUserRelationUpdate 更新记录 | |||||
func OneCirclesPublicPlatoonUserRelationUpdate(session *xorm.Session, id interface{}, OneCirclesPublicPlatoonUserRelation *model.OneCirclesPublicPlatoonUserRelation, forceColums ...string) (int64, error) { | |||||
var ( | |||||
affected int64 | |||||
err error | |||||
) | |||||
if forceColums != nil { | |||||
affected, err = session.Where("id=?", id).Cols(forceColums...).Update(OneCirclesPublicPlatoonUserRelation) | |||||
} else { | |||||
affected, err = session.Where("id=?", id).Update(OneCirclesPublicPlatoonUserRelation) | |||||
} | |||||
if err != nil { | |||||
return 0, err | |||||
} | |||||
return affected, nil | |||||
} | |||||
// OneCirclesPublicPlatoonUserRelationGetOneByParams 通过传入的参数查询数据(单条) | |||||
func OneCirclesPublicPlatoonUserRelationGetOneByParams(Db *xorm.Engine, params map[string]interface{}) (*model.OneCirclesPublicPlatoonUserRelation, error) { | |||||
var m model.OneCirclesPublicPlatoonUserRelation | |||||
var query = fmt.Sprintf("%s =?", params["key"]) | |||||
if has, err := Db.Where(query, params["value"]).Get(&m); err != nil || has == false { | |||||
return nil, zhios_order_relate_logx.Error(err) | |||||
} | |||||
return &m, nil | |||||
} | |||||
func OneCirclesPublicPlatoonUserRelationFindByEmptyPosition(Db *xorm.Engine) (*model.OneCirclesPublicPlatoonUserRelation, error) { | |||||
var m model.OneCirclesPublicPlatoonUserRelation | |||||
if has, err := Db.Where("uid = -1").Or("uid = -2").Get(&m); err != nil || has == false { | |||||
return nil, zhios_order_relate_logx.Error(err) | |||||
} | |||||
return &m, nil | |||||
} | |||||
func OneCirclesPublicPlatoonUserRelationGetOneByPid(Db *xorm.Engine, recommendUid string, params map[string]interface{}) (*model.OneCirclesPublicPlatoonUserRelation, error) { | |||||
var m model.OneCirclesPublicPlatoonUserRelation | |||||
var query = fmt.Sprintf("%s <=?", params["key"]) | |||||
if has, err := Db.Where("recommend_uid = ?", recommendUid).And(query, params["value"]).OrderBy("id ASC").Get(&m); err != nil || has == false { | |||||
return nil, zhios_order_relate_logx.Error(err) | |||||
} | |||||
return &m, nil | |||||
} | |||||
func OneCirclesPublicPlatoonUserRelationFindByPid(Db *xorm.Engine, fatherUid int, fatherName, positionName string) ([]model.OneCirclesPublicPlatoonUserRelation, error) { | |||||
var m []model.OneCirclesPublicPlatoonUserRelation | |||||
//var query1 = fmt.Sprintf("%s >= ?", pidName) | |||||
var query2 = fmt.Sprintf("%s = ?", fatherName) | |||||
var order = fmt.Sprintf("%s Desc", positionName) | |||||
if err := Db.Where(query2, fatherUid).OrderBy(order). | |||||
Find(&m); err != nil { | |||||
return nil, zhios_order_relate_logx.Warn(err) | |||||
} | |||||
return m, nil | |||||
} | |||||
func OneCirclesPublicPlatoonUserRelationFindCountByPosition(Db *xorm.Engine, fatherUid int, fatherName, positionName string, startPosition, endPosition int64) ([]model.OneCirclesPublicPlatoonUserRelation, int64, error) { | |||||
var m []model.OneCirclesPublicPlatoonUserRelation | |||||
var count int64 | |||||
var query1 = fmt.Sprintf("%s >= ?", positionName) | |||||
var query2 = fmt.Sprintf("%s <= ?", positionName) | |||||
var query3 = fmt.Sprintf("%s = ?", fatherName) | |||||
if count, err := Db.Where(query3, fatherUid).And(query1, startPosition).And(query2, endPosition).OrderBy("has_son_num ASC"). | |||||
FindAndCount(&m); err != nil { | |||||
return nil, count, zhios_order_relate_logx.Warn(err) | |||||
} | |||||
return m, count, nil | |||||
} | |||||
// OneCirclesPublicPlatoonUserRelationFindByParams 通过传入的参数查询数据(多条) | |||||
func OneCirclesPublicPlatoonUserRelationFindByParams(Db *xorm.Engine, params map[string]interface{}) (*[]model.OneCirclesPublicPlatoonUserRelation, error) { | |||||
var m []model.OneCirclesPublicPlatoonUserRelation | |||||
if params["value"] == nil { | |||||
return nil, errors.New("参数有误") | |||||
} | |||||
if params["key"] == nil { | |||||
//查询全部数据 | |||||
err := Db.Find(&m) | |||||
if err != nil { | |||||
return nil, zhios_order_relate_logx.Error(err) | |||||
} | |||||
return &m, nil | |||||
} else { | |||||
if reflect.TypeOf(params["value"]).Kind() == reflect.Slice { | |||||
//指定In查询 | |||||
if err := Db.In(zhios_order_relate_utils.AnyToString(params["key"]), params["value"]).Find(&m); err != nil { | |||||
return nil, zhios_order_relate_logx.Warn(err) | |||||
} | |||||
return &m, nil | |||||
} else { | |||||
var query = fmt.Sprintf("%s =?", params["key"]) | |||||
err := Db.Where(query, params["value"]).Find(&m) | |||||
if err != nil { | |||||
return nil, zhios_order_relate_logx.Error(err) | |||||
} | |||||
return &m, nil | |||||
} | |||||
} | |||||
} | |||||
func OneCirclesPublicPlatoonUserRelationFindRecommends(Db *xorm.Engine) ([]model.OneCirclesPublicPlatoonUserRelation, error) { | |||||
var m []model.OneCirclesPublicPlatoonUserRelation | |||||
var query = fmt.Sprintf("recommend_uid > 0") | |||||
err := Db.Where(query).Find(&m) | |||||
if err != nil { | |||||
return nil, zhios_order_relate_logx.Error(err) | |||||
} | |||||
return m, nil | |||||
} | |||||
func OneCirclesPublicPlatoonUserRelationFindByParamsByPage(Db *xorm.Engine, params map[string]interface{}, page, pageSize int) (*[]model.OneCirclesPublicPlatoonUserRelation, error) { | |||||
var m []model.OneCirclesPublicPlatoonUserRelation | |||||
if params["value"] == nil { | |||||
return nil, errors.New("参数有误") | |||||
} | |||||
if page == 0 && pageSize == 0 { | |||||
page = 1 | |||||
pageSize = 10 | |||||
} | |||||
if params["key"] == nil { | |||||
//查询全部数据 | |||||
err := Db.Limit(pageSize, (page-1)*pageSize).Find(&m) | |||||
if err != nil { | |||||
return nil, zhios_order_relate_logx.Error(err) | |||||
} | |||||
return &m, nil | |||||
} else { | |||||
if reflect.TypeOf(params["value"]).Kind() == reflect.Slice { | |||||
//指定In查询 | |||||
if err := Db.In(zhios_order_relate_utils.AnyToString(params["key"]), params["value"]).Limit(pageSize, (page-1)*pageSize).Find(&m); err != nil { | |||||
return nil, zhios_order_relate_logx.Warn(err) | |||||
} | |||||
return &m, nil | |||||
} else { | |||||
var query = fmt.Sprintf("%s =?", params["key"]) | |||||
err := Db.Where(query, params["value"]).Limit(pageSize, (page-1)*pageSize).Find(&m) | |||||
if err != nil { | |||||
return nil, zhios_order_relate_logx.Error(err) | |||||
} | |||||
return &m, nil | |||||
} | |||||
} | |||||
} |
@@ -31,3 +31,8 @@ func DbsUserRelate(eg *xorm.Engine, uid, level int) (*[]model.UserRelate, error) | |||||
} | } | ||||
return &userRelate, nil | return &userRelate, nil | ||||
} | } | ||||
func SumUserRelateByParentUid(eg *xorm.Engine, parentUid string) (total int64, userRelate []*model.UserRelate, err error) { | |||||
total, err = eg.Where("parent_uid = ?", parentUid).FindAndCount(&userRelate) | |||||
return | |||||
} |
@@ -0,0 +1,35 @@ | |||||
package model | |||||
import ( | |||||
"time" | |||||
) | |||||
type OneCirclesAvailableGreenEnergyPointsFlow struct { | |||||
Id int64 `json:"id" xorm:"pk autoincr BIGINT(20)"` | |||||
CoinId int `json:"coin_id" xorm:"not null comment('虚拟币id') INT(11)"` | |||||
Direction int `json:"direction" xorm:"not null default 1 comment('方向:1收入 2支出') TINYINT(255)"` | |||||
Kind int `json:"kind" xorm:"not null default 1 comment('种类(1:个人活跃积分兑换 2:结算绿色能量释放 3:签到奖励 4:账户余额兑换 5:绿色能量兑换余额 6:活跃赠送)') TINYINT(1)"` | |||||
Title string `json:"title" xorm:"not null default '' comment('标题') VARCHAR(255)"` | |||||
Amount string `json:"amount" xorm:"not null comment('变更数量') DECIMAL(28,10)"` | |||||
BeforeEcologicalApplicationValues string `json:"before_ecological_application_values" xorm:"not null default 0.0000000000 comment('变更前-生态应用区块币数量') DECIMAL(28,10)"` | |||||
AfterEcologicalApplicationValues string `json:"after_ecological_application_values" xorm:"not null default 0.0000000000 comment('变更后-生态应用区块币数量') DECIMAL(28,10)"` | |||||
BeforeTechnicalTeamValues string `json:"before_technical_team_values" xorm:"not null default 0.0000000000 comment('变更前-技术团队区块币数量') DECIMAL(28,10)"` | |||||
AfterTechnicalTeamValues string `json:"after_technical_team_values" xorm:"not null default 0.0000000000 comment('变更后-技术团队区块币数量') DECIMAL(28,10)"` | |||||
BeforeOperateTeamValues string `json:"before_operate_team_values" xorm:"not null default 0.0000000000 comment('变更前-运营团队区块币数量') DECIMAL(28,10)"` | |||||
AfterOperateTeamValues string `json:"after_operate_team_values" xorm:"not null default 0.0000000000 comment('变更后-运营团队区块币数量') DECIMAL(28,10)"` | |||||
BeforeActiveGiveawaysValues string `json:"before_active_giveaways_values" xorm:"not null default 0.0000000000 comment('变更前-活跃赠送区块币数量') DECIMAL(28,10)"` | |||||
AfterActiveGiveawaysValues string `json:"after_active_giveaways_values" xorm:"not null default 0.0000000000 comment('变更后-活跃赠送区块币数量') DECIMAL(28,10)"` | |||||
BeforeOriginalQuantityValues string `json:"before_original_quantity_values" xorm:"not null default 0.0000000000 comment('变更前-原始数量区块币数量') DECIMAL(28,10)"` | |||||
AfterOriginalQuantityValues string `json:"after_original_quantity_values" xorm:"not null default 0.0000000000 comment('变更后-原始数量区块币数量') DECIMAL(28,10)"` | |||||
BeforeMarketplaceMerchantValues string `json:"before_marketplace_merchant_values" xorm:"not null default 0.0000000000 comment('变更前-市商区块币数量') DECIMAL(28,10)"` | |||||
AfterMarketplaceMerchantValues string `json:"after_marketplace_merchant_values" xorm:"not null default 0.0000000000 comment('变更后-市商区块币数量') DECIMAL(28,10)"` | |||||
BeforeDevelopmentCommitteeValues string `json:"before_development_committee_values" xorm:"not null default 0.0000000000 comment('变更前-发展委员会区块币数量') DECIMAL(28,10)"` | |||||
AfterDevelopmentCommitteeValues string `json:"after_development_committee_values" xorm:"not null default 0.0000000000 comment('变更后-发展委员会区块币数量') DECIMAL(28,10)"` | |||||
BeforePublicWelfareAndCharityValues string `json:"before_public_welfare_and_charity_values" xorm:"not null default 0.0000000000 comment('变更前-公益慈善区块币数量') DECIMAL(28,10)"` | |||||
AfterPublicWelfareAndCharityValues string `json:"after_public_welfare_and_charity_values" xorm:"not null default 0.0000000000 comment('变更后-公益慈善区块币数量') DECIMAL(28,10)"` | |||||
BeforeStarLevelDividendsValues string `json:"before_star_level_dividends_values" xorm:"not null default 0.0000000000 comment('变更前-星级分红区块币数量') DECIMAL(28,10)"` | |||||
AfterStarLevelDividendsValues string `json:"after_star_level_dividends_values" xorm:"not null default 0.0000000000 comment('变更后-星级分红区块币数量') DECIMAL(28,10)"` | |||||
BeforeDestructionQuantityValues string `json:"before_destruction_quantity_values" xorm:"not null default 0.0000000000 comment('变更前-销毁区块币数量') DECIMAL(28,10)"` | |||||
AfterDestructionQuantityValues string `json:"after_destruction_quantity_values" xorm:"not null default 0.0000000000 comment('变更后-销毁区块币数量') DECIMAL(28,10)"` | |||||
CreateTime time.Time `json:"create_time" xorm:"default 'CURRENT_TIMESTAMP' comment('创建时间') DATETIME"` | |||||
} |
@@ -0,0 +1,37 @@ | |||||
package model | |||||
import ( | |||||
"time" | |||||
) | |||||
type OneCirclesGreenEnergyBasicSetting struct { | |||||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||||
IsOpen int `json:"is_open" xorm:"not null default 1 comment('是否开启(1:开启 0:关闭)') TINYINT(1)"` | |||||
PersonGreenEnergyCoinId int `json:"person_green_energy_coin_id" xorm:"not null default 0 comment('个人绿色能量对应虚拟币id') INT(11)"` | |||||
TeamGreenEnergyCoinId int `json:"team_green_energy_coin_id" xorm:"not null default 0 comment('团队绿色能量对应虚拟币id') INT(11)"` | |||||
TotalIssuanceAmount string `json:"total_issuance_amount" xorm:"not null comment('总发行量') DECIMAL(28,10)"` | |||||
EcologicalApplication string `json:"ecological_application" xorm:"not null comment('生态应用') DECIMAL(28,10)"` | |||||
TotalTechnologyTeam string `json:"total_technology_team" xorm:"not null comment('技术团队') DECIMAL(28,10)"` | |||||
TotalOperateTeam string `json:"total_operate_team" xorm:"not null comment('运营团队') DECIMAL(28,10)"` | |||||
TotalActiveGiveaways string `json:"total_active_giveaways" xorm:"not null comment('活跃赠送') DECIMAL(28,10)"` | |||||
OriginalQuantityNums string `json:"original_quantity_nums" xorm:"not null comment('原始数量') DECIMAL(28,10)"` | |||||
InitialPrice string `json:"initial_price" xorm:"not null comment('初始价格') DECIMAL(28,10)"` | |||||
NowPrice string `json:"now_price" xorm:"not null comment('当前价格') DECIMAL(28,10)"` | |||||
OriginalFunds string `json:"original_funds" xorm:"not null comment('原始资金') DECIMAL(28,10)"` | |||||
MarketplaceMerchantNums string `json:"marketplace_merchant_nums" xorm:"not null comment('市商数量') DECIMAL(28,10)"` | |||||
MarketplaceMerchantFunds string `json:"marketplace_merchant_funds" xorm:"not null comment('市商资金') DECIMAL(28,10)"` | |||||
DevelopmentCommittee string `json:"development_committee" xorm:"not null comment('发展委员会') DECIMAL(28,10)"` | |||||
PublicWelfareAndCharity string `json:"public_welfare_and_charity" xorm:"not null comment('公益慈善') DECIMAL(28,10)"` | |||||
StarLevelDividends string `json:"star_level_dividends" xorm:"not null comment('星级分红') DECIMAL(28,10)"` | |||||
DestructionQuantityNums string `json:"destruction_quantity_nums" xorm:"not null comment('销毁数量') DECIMAL(28,10)"` | |||||
DestructionSetting string `json:"destruction_setting" xorm:"not null comment('销毁设置') TEXT"` | |||||
IsLimitDividend int `json:"is_limit_dividend" xorm:"not null default 1 comment('是否限制分红(会员本人不活跃,没有绿色能量分红)') TINYINT(1)"` | |||||
SettlementQuantity int `json:"settlement_quantity" xorm:"not null default 0 comment('结算数量(百分比)') INT(11)"` | |||||
SignInReward string `json:"sign_in_reward" xorm:"not null comment('签到奖励') TEXT"` | |||||
TeamReward string `json:"team_reward" xorm:"not null comment('团队奖励') TEXT"` | |||||
PriceSetting string `json:"price_setting" xorm:"not null comment('价格设置') TEXT"` | |||||
WelfareOrdersLimit string `json:"welfare_orders_limit" xorm:"not null comment('福利订单抢购条件') TEXT"` | |||||
VipEquitySetting string `json:"vip_equity_setting" xorm:"not null comment('会员权益') TEXT"` | |||||
CreateAt time.Time `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` | |||||
UpdateAt time.Time `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` | |||||
} |
@@ -0,0 +1,9 @@ | |||||
package model | |||||
type OneCirclesGreenEnergySignIn struct { | |||||
Id int64 `json:"id" xorm:"pk autoincr BIGINT(20)"` | |||||
Uid int `json:"uid" xorm:"not null default 0 comment('用户id') INT(11)"` | |||||
StartTime string `json:"start_time" xorm:"not null default 'CURRENT_TIMESTAMP' comment('签到开始时间') DATETIME"` | |||||
EndTime string `json:"end_time" xorm:"not null default 'CURRENT_TIMESTAMP' comment('签到结束时间') DATETIME"` | |||||
IsCompleted int `json:"is_completed" xorm:"not null default 0 comment('是否完成(0:未完成 1:已完成)') TINYINT(1)"` | |||||
} |
@@ -0,0 +1,21 @@ | |||||
package model | |||||
type OneCirclesPublicPlatoonBasicSetting struct { | |||||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||||
IsOpen int `json:"is_open" xorm:"not null default 1 comment('是否开启(1:开启 0:关闭)') TINYINT(1)"` | |||||
ExchangeRules string `json:"exchange_rules" xorm:"not null comment('兑换规则') TEXT"` | |||||
PersonActivePointsCoinId int `json:"person_active_points_coin_id" xorm:"not null default 0 comment('个人活跃积分对应虚拟币id') INT(11)"` | |||||
TeamActivePointsCoinId int `json:"team_active_points_coin_id" xorm:"not null default 0 comment('团队活跃积分对应虚拟币id') INT(11)"` | |||||
OriginatorUid int `json:"originator_uid" xorm:"not null default 0 comment('创始人uid') INT(11)"` | |||||
SeveralTimes int `json:"several_times" xorm:"not null default 3 comment('几乘') TINYINT(3)"` | |||||
SeveralRows int `json:"several_rows" xorm:"not null default 3 comment('几排') TINYINT(3)"` | |||||
RevenueName string `json:"revenue_name" xorm:"not null default '' comment('收益名称') VARCHAR(255)"` | |||||
RewardSystem string `json:"reward_system" xorm:"not null comment('奖励机制') TEXT"` | |||||
VideoRewardIsOpen int `json:"video_reward_is_open" xorm:"not null default 1 comment('视屏奖励是否开启(1:开启 0:关闭)') TINYINT(1)"` | |||||
VideoRewardSystem string `json:"video_reward_system" xorm:"not null comment('视屏奖励机制') TEXT"` | |||||
SystemPunishReplace int `json:"system_punish_replace" xorm:"not null default 1 comment('是否位置滑落 被新用户替换 0否 1是') TINYINT(1)"` | |||||
SystemPunishReplaceValue int `json:"system_punish_replace_value" xorm:"not null default 0 comment('xx天未活跃,处罚滑落') INT(11)"` | |||||
IsSelfActiveGetTeamRevenue int `json:"is_self_active_get_team_revenue" xorm:"not null default 1 comment('会员本人没有日活,没有团队奖励(1:开启 0:关闭)') TINYINT(1)"` | |||||
CreateAt string `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` | |||||
UpdateAt string `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` | |||||
} |
@@ -0,0 +1,48 @@ | |||||
package model | |||||
type OneCirclesPublicPlatoonUserRelation struct { | |||||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||||
Uid int `json:"uid" xorm:"not null default 0 comment('用户id(若为-1,则代表等待新用户填充)') index INT(11)"` | |||||
RecommendUid int `json:"recommend_uid" xorm:"not null default 0 comment('推荐人id') INT(11)"` | |||||
FatherUid string `json:"father_uid" xorm:"not null default '' comment('父级uid(123456-563464-438384)') index VARCHAR(100)"` | |||||
FatherUid1 int `json:"father_uid1" xorm:"not null default 0 comment('父级uid_1') INT(11)"` | |||||
FatherUid2 int `json:"father_uid2" xorm:"not null default 0 comment('父级uid_2') INT(11)"` | |||||
FatherUid3 int `json:"father_uid3" xorm:"not null default 0 comment('父级uid_3') INT(11)"` | |||||
FatherUid4 int `json:"father_uid4" xorm:"not null default 0 comment('父级uid_4') INT(11)"` | |||||
FatherUid5 int `json:"father_uid5" xorm:"not null default 0 comment('父级uid_5') INT(11)"` | |||||
FatherUid6 int `json:"father_uid6" xorm:"not null default 0 comment('父级uid_6') INT(11)"` | |||||
FatherUid7 int `json:"father_uid7" xorm:"not null default 0 comment('父级uid_7') INT(11)"` | |||||
FatherUid8 int `json:"father_uid8" xorm:"not null default 0 comment('父级uid_8') INT(11)"` | |||||
Pid1 int `json:"pid1" xorm:"not null default 0 comment('父级id_1') INT(11)"` | |||||
Pid2 int `json:"pid2" xorm:"not null default 0 comment('父级id_2') INT(11)"` | |||||
Pid3 int `json:"pid3" xorm:"not null default 0 comment('父级id_3') INT(11)"` | |||||
Pid4 int `json:"pid4" xorm:"not null default 0 comment('父级id_4') INT(11)"` | |||||
Pid5 int `json:"pid5" xorm:"not null default 0 comment('父级id_5') INT(11)"` | |||||
Pid6 int `json:"pid6" xorm:"not null default 0 comment('父级id_6') INT(11)"` | |||||
Pid7 int `json:"pid7" xorm:"not null default 0 comment('父级id_7') INT(11)"` | |||||
Pid8 int `json:"pid8" xorm:"not null default 0 comment('父级id_8') INT(11)"` | |||||
Position int `json:"position" xorm:"not null default 1 comment('位置(以自己为创始人)') INT(11)"` | |||||
Position1 int `json:"position1" xorm:"not null default 0 comment('位置_1(以pid1为创始人中网的位置)') INT(11)"` | |||||
Position2 int `json:"position2" xorm:"not null default 0 comment('位置_2') INT(11)"` | |||||
Position3 int `json:"position3" xorm:"not null default 0 comment('位置_3') INT(11)"` | |||||
Position4 int `json:"position4" xorm:"not null default 0 comment('位置_4') INT(11)"` | |||||
Position5 int `json:"position5" xorm:"not null default 0 comment('位置_5') INT(11)"` | |||||
Position6 int `json:"position6" xorm:"not null default 0 comment('位置_6') INT(11)"` | |||||
Position7 int `json:"position7" xorm:"not null default 0 comment('位置_7') INT(11)"` | |||||
Position8 int `json:"position8" xorm:"not null default 0 comment('位置_8') INT(11)"` | |||||
Level int `json:"level" xorm:"not null default 1 comment('等级(以自己为创始人)') INT(11)"` | |||||
Level1 int `json:"level1" xorm:"not null default 0 comment('等级_1(以pid1为创始人中网的等级)') INT(11)"` | |||||
Level2 int `json:"level2" xorm:"not null default 0 comment('等级_2') INT(11)"` | |||||
Level3 int `json:"level3" xorm:"not null default 0 comment('等级_3') INT(11)"` | |||||
Level4 int `json:"level4" xorm:"not null default 0 comment('等级_4') INT(11)"` | |||||
Level5 int `json:"level5" xorm:"not null default 0 comment('等级_5') INT(11)"` | |||||
Level6 int `json:"level6" xorm:"not null default 0 comment('等级_6') INT(11)"` | |||||
Level7 int `json:"level7" xorm:"not null default 0 comment('等级_7') INT(11)"` | |||||
Level8 int `json:"level8" xorm:"not null default 0 comment('等级_8') INT(11)"` | |||||
LevelTotal int `json:"level_total" xorm:"not null default 1 comment('等级(整个系统)') INT(11)"` | |||||
JoinAt string `json:"join_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('加入公排时间') DATETIME"` | |||||
HasSonNum int `json:"has_son_num" xorm:"not null default 0 comment('拥有直属下级数量') TINYINT(2)"` | |||||
IsAllowPunish int `json:"is_allow_punish" xorm:"not null default 1 comment('是否允许处罚(1:允许 2:不允许)') TINYINT(1)"` | |||||
CreateAt string `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` | |||||
UpdateAt string `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` | |||||
} |
@@ -58,6 +58,11 @@ const ( | |||||
NiuBeiCoinByReleaseCouponDestroyConsumeCoinNumTitleForUserVirtualCoinFlow = "释放抵扣劵数量-消耗消费积分数量" | NiuBeiCoinByReleaseCouponDestroyConsumeCoinNumTitleForUserVirtualCoinFlow = "释放抵扣劵数量-消耗消费积分数量" | ||||
NiuBeiCoinByReleaseOptionCoinNumTitleForUserVirtualCoinFlow = "牛贝积分-释放期权积分" | NiuBeiCoinByReleaseOptionCoinNumTitleForUserVirtualCoinFlow = "牛贝积分-释放期权积分" | ||||
NiuBeiCoinByReleaseOptionDestroyConsumeCoinNumTitleForUserVirtualCoinFlow = "释放期权积分数量-消耗消费积分数量" | NiuBeiCoinByReleaseOptionDestroyConsumeCoinNumTitleForUserVirtualCoinFlow = "释放期权积分数量-消耗消费积分数量" | ||||
OneCirclesGreenEnergySignInSettlementPersonalReward = "签到个人奖励-可用绿色能量" | |||||
OneCirclesGreenEnergySignInSettlementTeamReward = "签到团队奖励-结算绿色能量" | |||||
OneCirclesWatchAdRewardPersonalActiveCoin = "观看激励视屏奖励-个人活跃积分" | |||||
OneCirclesWatchAdRewardTeamActiveCoin = "观看激励视屏奖励-团队活跃积分" | |||||
) | ) | ||||
const ( | const ( | ||||
@@ -114,6 +119,11 @@ const ( | |||||
NiuBeiCoinByReleaseOptionDestroyConsumeCoinNumTransferTypeForUserVirtualCoinFlow = 150 //释放期权积分数量-消耗消费积分数量 | NiuBeiCoinByReleaseOptionDestroyConsumeCoinNumTransferTypeForUserVirtualCoinFlow = 150 //释放期权积分数量-消耗消费积分数量 | ||||
NiuBeiCoinByExtendForUserVirtualCoinFlow = 151 //直推奖励 | NiuBeiCoinByExtendForUserVirtualCoinFlow = 151 //直推奖励 | ||||
NiuBeiCoinByTeamForUserVirtualCoinFlow = 152 //团队奖励 | NiuBeiCoinByTeamForUserVirtualCoinFlow = 152 //团队奖励 | ||||
OneCirclesGreenEnergySignInSettlementPersonalRewardForUserVirtualCoinFlow = 155 //签到个人奖励-可用绿色能量 | |||||
OneCirclesGreenEnergySignInSettlementTeamRewardForUserVirtualCoinFlow = 156 //签到团队奖励-结算绿色能量 | |||||
OneCirclesWatchAdRewardPersonalActiveCoinForUserVirtualCoinFlow = 156 //观看激励视屏奖励-个人活跃积分 | |||||
OneCirclesWatchAdRewardTeamActiveCoinForUserVirtualCoinFlow = 157 //观看激励视屏奖励-团队活跃积分 | |||||
) | ) | ||||
const DealUserCoinRequestIdPrefix = "%s:block_star_chain_deal_user_coin:%d:uid:%d" | const DealUserCoinRequestIdPrefix = "%s:block_star_chain_deal_user_coin:%d:uid:%d" | ||||
@@ -0,0 +1,6 @@ | |||||
package md | |||||
type AddOneCirclesPublicPlatoonUserRelationCommissionReq struct { | |||||
Uid string `json:"uid"` | |||||
RecommendUid string `json:"recommend_uid"` //推荐人uid | |||||
} |
@@ -0,0 +1,94 @@ | |||||
package one_circles | |||||
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" | |||||
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/md" | |||||
md2 "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/one_circles/md" | |||||
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/svc" | |||||
zhios_order_relate_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils" | |||||
"errors" | |||||
"fmt" | |||||
"github.com/shopspring/decimal" | |||||
"strconv" | |||||
"time" | |||||
"xorm.io/xorm" | |||||
) | |||||
const PessimismLockKey = "daily_settlement_block_star_chain_pessimism_lock_key" | |||||
const PessimismLockValue = "running" | |||||
// DealUserCoin 处理给用户虚拟币积分 | |||||
func DealUserCoin(session *xorm.Session, req md.DealUserCoinReq) (err error) { | |||||
if req.Amount < 0 { | |||||
req.Amount = 0 | |||||
} | |||||
//1、分布式锁阻拦 | |||||
requestIdPrefix := fmt.Sprintf(md2.DealUserCoinRequestIdPrefix, req.Mid, req.CoinId, req.Uid) | |||||
cb, err := svc.HandleDistributedLock(req.Mid, strconv.Itoa(req.Uid), requestIdPrefix) | |||||
if err != nil { | |||||
return err | |||||
} | |||||
if cb != nil { | |||||
defer cb() // 释放锁 | |||||
} | |||||
//2、计算&&组装数据 | |||||
now := time.Now() | |||||
coinAmount, err := svc.GetUserCoinAmount(session, req.Mid, req.CoinId, req.Uid) | |||||
if err != nil { | |||||
return err | |||||
} | |||||
coinAmountValue := decimal.NewFromFloat(zhios_order_relate_utils.StrToFloat64(coinAmount)) | |||||
amountValue := decimal.NewFromFloat(req.Amount).RoundFloor(8) | |||||
var userVirtualCoinFlow model.UserVirtualCoinFlow | |||||
userVirtualCoinFlow.CoinId = req.CoinId | |||||
userVirtualCoinFlow.Title = req.Title | |||||
userVirtualCoinFlow.TransferType = req.TransferType | |||||
userVirtualCoinFlow.Uid = req.Uid | |||||
userVirtualCoinFlow.ToUid = req.ToUid | |||||
userVirtualCoinFlow.OrdId = req.OrdId | |||||
userVirtualCoinFlow.BeforeAmout = coinAmount | |||||
userVirtualCoinFlow.Amout = amountValue.String() | |||||
userVirtualCoinFlow.CreateTime = now | |||||
if req.Kind == "add" { | |||||
userVirtualCoinFlow.Direction = 1 | |||||
userVirtualCoinFlow.AfterAmout = coinAmountValue.Add(amountValue).RoundFloor(8).String() | |||||
} else if req.Kind == "sub" { | |||||
userVirtualCoinFlow.Direction = 2 | |||||
userVirtualCoinFlow.AfterAmout = coinAmountValue.Sub(amountValue).RoundFloor(8).String() | |||||
} else { | |||||
err = errors.New("错误的kind类型") | |||||
return err | |||||
} | |||||
if zhios_order_relate_utils.StrToFloat64(userVirtualCoinFlow.AfterAmout) < 0 { | |||||
var coin model.VirtualCoin | |||||
_, err = session.Where("id = ?", req.CoinId).Get(&coin) | |||||
if err != nil { | |||||
return err | |||||
} | |||||
zhios_order_relate_utils.FilePutContents("virtual_coin_not", zhios_order_relate_utils.SerializeStr(map[string]interface{}{ | |||||
"uid": userVirtualCoinFlow.Uid, | |||||
"amount": userVirtualCoinFlow.Amout, | |||||
"before_amount": userVirtualCoinFlow.BeforeAmout, | |||||
"after_amount": userVirtualCoinFlow.AfterAmout, | |||||
"coin_id": userVirtualCoinFlow.CoinId, | |||||
})) | |||||
return errors.New("用户" + zhios_order_relate_utils.IntToStr(userVirtualCoinFlow.Uid) + "的" + coin.Name + "不足") | |||||
} | |||||
//3、插入 `user_virtual_coin_flow` 记录 | |||||
_, err = db.UserVirtualCoinFlowInsert(session, &userVirtualCoinFlow) | |||||
if err != nil { | |||||
return err | |||||
} | |||||
//4、修改 `user_virtual_amount`的amount值 && 及缓存 | |||||
err = svc.SetCacheUserVirtualAmount(session, req.Mid, userVirtualCoinFlow.AfterAmout, req.CoinId, req.Uid, true) | |||||
if err != nil { | |||||
return err | |||||
} | |||||
return nil | |||||
} |
@@ -0,0 +1,29 @@ | |||||
package enum | |||||
// 可用绿色能量流水-种类 | |||||
type OneCirclesAvailableGreenEnergyPointsFlowKind int | |||||
const ( | |||||
PersonalActivePointRedemption OneCirclesAvailableGreenEnergyPointsFlowKind = iota | |||||
SettlementOfGreenEnergyRelease | |||||
SignInReward | |||||
AccountBalanceExchange | |||||
GreenEnergyExchangeBalance | |||||
) | |||||
func (kind OneCirclesAvailableGreenEnergyPointsFlowKind) String() string { | |||||
switch kind { | |||||
case PersonalActivePointRedemption: | |||||
return "个人活跃积分兑换" | |||||
case SettlementOfGreenEnergyRelease: | |||||
return "结算绿色能量释放" | |||||
case SignInReward: | |||||
return "签到奖励" | |||||
case AccountBalanceExchange: | |||||
return "账户余额兑换" | |||||
case GreenEnergyExchangeBalance: | |||||
return "绿色能量兑换余额" | |||||
default: | |||||
return "未知状态" | |||||
} | |||||
} |
@@ -0,0 +1,30 @@ | |||||
package md | |||||
type VipEquitySettingStruct struct { | |||||
VipLevelId string `json:"vip_level_id"` //会员等级id | |||||
ExchangeAccountBalanceFee string `json:"exchange_account_balance_fee"` //兑换余额手续费 | |||||
DividendRatio string `json:"dividend_ratio"` //分红比例 | |||||
} | |||||
type TeamRewardSettingStruct struct { | |||||
RewardDecrementValue string `json:"reward_decrement_value"` //递减百分比 | |||||
RewardEndValue string `json:"reward_end_value"` //奖励结束值 | |||||
MemberSelfIsOpenGetTeamReward string `json:"member_self_is_open_get_team_reward"` //会员是否活跃得到团队奖励 | |||||
OneRoundDuration string `json:"one_round_duration"` //一轮持续时间 | |||||
} | |||||
type SignInRewardStruct struct { | |||||
VipMemberStartNums string `json:"vip_member_start_nums"` //会员起始数量 | |||||
VipMemberEndNums string `json:"vip_member_end_nums"` //会员结束数量 | |||||
RewardValue string `json:"reward_value"` //奖励值 | |||||
} | |||||
type DestructionSettingStruct struct { | |||||
DestructionQuantity string `json:"destruction_quantity"` //销毁百分比 | |||||
PublicWelfareAndCharity string `json:"public_welfare_and_charity"` //公益慈善百分比 | |||||
DevelopmentCommittee string `json:"development_committee"` //发展委员会百分比 | |||||
StarLevelDividends string `json:"star_level_dividends"` //星级分红百分比 | |||||
MarketplaceMerchant string `json:"marketplace_merchant"` //市商数量百分比 | |||||
} | |||||
const DealUserCoinRequestIdPrefix = "%s:one_circles_green_energy_deal_user_coin:%d:uid:%d" |
@@ -0,0 +1,14 @@ | |||||
package md | |||||
type VideoRewardSystemStruct struct { | |||||
RewardValue string `json:"reward_value"` //奖励X个活跃积分 | |||||
RewardTotalNum string `json:"reward_total_num"` //一共X个奖励视屏 | |||||
IntervalMinutes string `json:"interval_minutes"` //间隔X分钟 | |||||
EachRoundHour string `json:"each_round_hour"` //每一轮X个小时 | |||||
} | |||||
type RewardSystemStruct struct { | |||||
Level int `json:"level"` //圈层 | |||||
RewardCondition string `json:"reward_condition"` //奖励条件 | |||||
RewardValue string `json:"reward_value"` //奖励值 | |||||
} |
@@ -0,0 +1,76 @@ | |||||
package one_circles | |||||
import ( | |||||
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db" | |||||
md2 "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/one_circles/md" | |||||
"encoding/json" | |||||
"errors" | |||||
"github.com/shopspring/decimal" | |||||
"xorm.io/xorm" | |||||
) | |||||
// CalcPriceIncreaseFormula 计算涨价公式(【用户资金 ÷(用户资金+原始资金)÷ 原始数量】 = 用户获得绿色能量个数) | |||||
func CalcPriceIncreaseFormula(engine *xorm.Engine, userAmountValue string) (err error, values, nowPriceValue, afterPriceValue string) { | |||||
//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 := originalQuantityNums.Mul(nowPrice) //原始资金 | |||||
afterPrice := (userAmount.Add(originalQuantityFunds)).Div(originalQuantityNums).Truncate(8) //涨价后的价格 | |||||
values = userAmount.Div(afterPrice).Truncate(8).String() //用户得到绿色能量个数 | |||||
nowPriceValue = nowPrice.String() | |||||
afterPriceValue = afterPrice.String() | |||||
return | |||||
} | |||||
// CalcPriceReductionFormula 计算降价公式(【用户需兑换绿能色量数量*{原始资金÷(用户需兑换绿色数量+原始数量}*(1 - 扣比例50% ~ 23%) = 用户获得绿色能量个数) | |||||
func CalcPriceReductionFormula(engine *xorm.Engine, userExchangeNumsValue string, levelId string) (err error, values, greenEnergy, greenEnergyFee, nowPriceValue, afterPriceValue string) { | |||||
//1、查找 `one_circles_green_energy_basic_setting` 基础设置 | |||||
oneCirclesGreenEnergyBasicSetting, err := db.OneCirclesGreenEnergyBasicSettingGetOneByParams(engine, map[string]interface{}{ | |||||
"key": "is_open", | |||||
"value": 1, | |||||
}) | |||||
if err != nil { | |||||
return | |||||
} | |||||
var vipEquitySetting []*md2.VipEquitySettingStruct | |||||
err = json.Unmarshal([]byte(oneCirclesGreenEnergyBasicSetting.VipEquitySetting), &vipEquitySetting) | |||||
if err != nil { | |||||
return | |||||
} | |||||
var exchangeAccountBalanceFeeValue string | |||||
for _, v := range vipEquitySetting { | |||||
if v.VipLevelId == levelId { | |||||
exchangeAccountBalanceFeeValue = v.ExchangeAccountBalanceFee | |||||
} | |||||
} | |||||
if exchangeAccountBalanceFeeValue == "" { | |||||
err = errors.New("未查询到当前会员等级兑换余额手续费") | |||||
return | |||||
} | |||||
decimalRate := decimal.NewFromInt(100) //百分比 | |||||
exchangeAccountBalanceFee, _ := decimal.NewFromString(exchangeAccountBalanceFeeValue) //兑换手续费 | |||||
userExchangeNums, _ := decimal.NewFromString(userExchangeNumsValue) //用户兑换绿色能量 | |||||
originalQuantityNums, _ := decimal.NewFromString(oneCirclesGreenEnergyBasicSetting.OriginalQuantityNums) //原始数量 | |||||
nowPrice, _ := decimal.NewFromString(oneCirclesGreenEnergyBasicSetting.NowPrice) //当前价格 | |||||
originalQuantityFunds := originalQuantityNums.Mul(nowPrice) //原始资金 | |||||
afterPrice := originalQuantityFunds.Div(userExchangeNums.Add(originalQuantityNums)) //降价后的价格 | |||||
greenEnergyValues := userExchangeNums.Mul(afterPrice) //绿色能量个数 | |||||
greenEnergyFeeValues := greenEnergyValues.Mul(exchangeAccountBalanceFee.Div(decimalRate)) //绿色能量个数扣除手续费 | |||||
values = greenEnergyValues.Sub(greenEnergyFeeValues).Truncate(8).String() //用户得到绿色能量个数 | |||||
greenEnergy = greenEnergyValues.Truncate(8).String() | |||||
greenEnergyFee = greenEnergyFeeValues.Truncate(8).String() | |||||
nowPriceValue = nowPrice.String() | |||||
afterPriceValue = afterPrice.String() | |||||
return | |||||
} |
@@ -0,0 +1,202 @@ | |||||
package one_circles | |||||
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" | |||||
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/one_circles/enum" | |||||
md2 "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/one_circles/md" | |||||
"encoding/json" | |||||
"github.com/shopspring/decimal" | |||||
"time" | |||||
"xorm.io/xorm" | |||||
) | |||||
func DealAvailableGreenEnergyCoin(session *xorm.Session, kind int, amount float64, title string, chain *model.OneCirclesGreenEnergyBasicSetting) error { | |||||
amountValue := decimal.NewFromFloat(amount) | |||||
now := time.Now() | |||||
var oneCirclesAvailableGreenEnergyPointsFlow model.OneCirclesAvailableGreenEnergyPointsFlow | |||||
oneCirclesAvailableGreenEnergyPointsFlow.CoinId = chain.PersonGreenEnergyCoinId | |||||
oneCirclesAvailableGreenEnergyPointsFlow.Kind = kind | |||||
oneCirclesAvailableGreenEnergyPointsFlow.Title = title | |||||
oneCirclesAvailableGreenEnergyPointsFlow.Amount = amountValue.RoundFloor(8).String() | |||||
oneCirclesAvailableGreenEnergyPointsFlow.CreateTime = now | |||||
switch kind { | |||||
case int(enum.PersonalActivePointRedemption): //个人活跃积分兑换 | |||||
beforeOriginalQuantity, _ := decimal.NewFromString(chain.OriginalQuantityNums) | |||||
oneCirclesAvailableGreenEnergyPointsFlow.Direction = 1 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeEcologicalApplicationValues = chain.EcologicalApplication //生态应用 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterEcologicalApplicationValues = chain.EcologicalApplication | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeTechnicalTeamValues = chain.TotalTechnologyTeam //技术团队 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterTechnicalTeamValues = chain.TotalTechnologyTeam | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeOperateTeamValues = chain.TotalOperateTeam //运营团队 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterOperateTeamValues = chain.TotalOperateTeam | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeActiveGiveawaysValues = chain.TotalActiveGiveaways //活跃赠送 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterActiveGiveawaysValues = chain.TotalActiveGiveaways | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeOriginalQuantityValues = chain.OriginalQuantityNums //原始数量 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterOriginalQuantityValues = beforeOriginalQuantity.Sub(amountValue).RoundFloor(8).String() | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeMarketplaceMerchantValues = chain.MarketplaceMerchantNums //市商数量 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterMarketplaceMerchantValues = chain.MarketplaceMerchantNums | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeDevelopmentCommitteeValues = chain.DevelopmentCommittee //发展委员会 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterDevelopmentCommitteeValues = chain.DevelopmentCommittee | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforePublicWelfareAndCharityValues = chain.PublicWelfareAndCharity //公益慈善 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterPublicWelfareAndCharityValues = chain.PublicWelfareAndCharity | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeStarLevelDividendsValues = chain.StarLevelDividends //星级分红 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterStarLevelDividendsValues = chain.StarLevelDividends | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeDestructionQuantityValues = chain.DestructionQuantityNums //销毁数量 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterDestructionQuantityValues = chain.DestructionQuantityNums | |||||
break | |||||
case int(enum.SettlementOfGreenEnergyRelease): //结算绿色能量释放 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.Direction = 1 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeEcologicalApplicationValues = chain.EcologicalApplication //生态应用 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterEcologicalApplicationValues = chain.EcologicalApplication | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeTechnicalTeamValues = chain.TotalTechnologyTeam //技术团队 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterTechnicalTeamValues = chain.TotalTechnologyTeam | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeOperateTeamValues = chain.TotalOperateTeam //运营团队 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterOperateTeamValues = chain.TotalOperateTeam | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeActiveGiveawaysValues = chain.TotalActiveGiveaways //活跃赠送 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterActiveGiveawaysValues = chain.TotalActiveGiveaways | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeOriginalQuantityValues = chain.OriginalQuantityNums //原始数量 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterOriginalQuantityValues = chain.OriginalQuantityNums | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeMarketplaceMerchantValues = chain.MarketplaceMerchantNums //市商数量 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterMarketplaceMerchantValues = chain.MarketplaceMerchantNums | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeDevelopmentCommitteeValues = chain.DevelopmentCommittee //发展委员会 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterDevelopmentCommitteeValues = chain.DevelopmentCommittee | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforePublicWelfareAndCharityValues = chain.PublicWelfareAndCharity //公益慈善 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterPublicWelfareAndCharityValues = chain.PublicWelfareAndCharity | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeStarLevelDividendsValues = chain.StarLevelDividends //星级分红 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterStarLevelDividendsValues = chain.StarLevelDividends | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeDestructionQuantityValues = chain.DestructionQuantityNums //销毁数量 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterDestructionQuantityValues = chain.DestructionQuantityNums | |||||
break | |||||
case int(enum.SignInReward): //签到奖励 | |||||
beforeTotalActiveGiveaways, _ := decimal.NewFromString(chain.TotalActiveGiveaways) | |||||
oneCirclesAvailableGreenEnergyPointsFlow.Direction = 1 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeEcologicalApplicationValues = chain.EcologicalApplication //生态应用 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterEcologicalApplicationValues = chain.EcologicalApplication | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeTechnicalTeamValues = chain.TotalTechnologyTeam //技术团队 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterTechnicalTeamValues = chain.TotalTechnologyTeam | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeOperateTeamValues = chain.TotalOperateTeam //运营团队 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterOperateTeamValues = chain.TotalOperateTeam | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeActiveGiveawaysValues = chain.TotalActiveGiveaways //活跃赠送 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterActiveGiveawaysValues = beforeTotalActiveGiveaways.Sub(amountValue).RoundFloor(8).String() | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeOriginalQuantityValues = chain.OriginalQuantityNums //原始数量 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterOriginalQuantityValues = chain.OriginalQuantityNums | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeMarketplaceMerchantValues = chain.MarketplaceMerchantNums //市商数量 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterMarketplaceMerchantValues = chain.MarketplaceMerchantNums | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeDevelopmentCommitteeValues = chain.DevelopmentCommittee //发展委员会 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterDevelopmentCommitteeValues = chain.DevelopmentCommittee | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforePublicWelfareAndCharityValues = chain.PublicWelfareAndCharity //公益慈善 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterPublicWelfareAndCharityValues = chain.PublicWelfareAndCharity | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeStarLevelDividendsValues = chain.StarLevelDividends //星级分红 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterStarLevelDividendsValues = chain.StarLevelDividends | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeDestructionQuantityValues = chain.DestructionQuantityNums //销毁数量 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterDestructionQuantityValues = chain.DestructionQuantityNums | |||||
break | |||||
case int(enum.AccountBalanceExchange): //账户余额兑换 | |||||
beforeOriginalQuantity, _ := decimal.NewFromString(chain.OriginalQuantityNums) | |||||
oneCirclesAvailableGreenEnergyPointsFlow.Direction = 1 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeEcologicalApplicationValues = chain.EcologicalApplication //生态应用 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterEcologicalApplicationValues = chain.EcologicalApplication | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeTechnicalTeamValues = chain.TotalTechnologyTeam //技术团队 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterTechnicalTeamValues = chain.TotalTechnologyTeam | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeOperateTeamValues = chain.TotalOperateTeam //运营团队 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterOperateTeamValues = chain.TotalOperateTeam | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeActiveGiveawaysValues = chain.TotalActiveGiveaways //活跃赠送 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterActiveGiveawaysValues = chain.TotalActiveGiveaways | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeOriginalQuantityValues = chain.OriginalQuantityNums //原始数量 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterOriginalQuantityValues = beforeOriginalQuantity.Sub(amountValue).RoundFloor(8).String() | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeMarketplaceMerchantValues = chain.MarketplaceMerchantNums //市商数量 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterMarketplaceMerchantValues = chain.MarketplaceMerchantNums | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeDevelopmentCommitteeValues = chain.DevelopmentCommittee //发展委员会 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterDevelopmentCommitteeValues = chain.DevelopmentCommittee | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforePublicWelfareAndCharityValues = chain.PublicWelfareAndCharity //公益慈善 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterPublicWelfareAndCharityValues = chain.PublicWelfareAndCharity | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeStarLevelDividendsValues = chain.StarLevelDividends //星级分红 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterStarLevelDividendsValues = chain.StarLevelDividends | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeDestructionQuantityValues = chain.DestructionQuantityNums //销毁数量 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterDestructionQuantityValues = chain.DestructionQuantityNums | |||||
break | |||||
case int(enum.GreenEnergyExchangeBalance): //绿色能量兑换余额 | |||||
var destructionSetting *md2.DestructionSettingStruct | |||||
err := json.Unmarshal([]byte(chain.DestructionSetting), &destructionSetting) | |||||
if err != nil { | |||||
return err | |||||
} | |||||
decimalRate := decimal.NewFromInt(100) //百分比 | |||||
marketplaceMerchantNums, _ := decimal.NewFromString(chain.MarketplaceMerchantNums) | |||||
marketplaceMerchant, _ := decimal.NewFromString(destructionSetting.MarketplaceMerchant) //市商数量百分比 | |||||
afterMarketplaceMerchantValues := marketplaceMerchantNums.Add(amountValue.Mul(marketplaceMerchant.Div(decimalRate))).RoundFloor(8).String() | |||||
developmentCommitteeNums, _ := decimal.NewFromString(chain.DevelopmentCommittee) | |||||
developmentCommittee, _ := decimal.NewFromString(destructionSetting.DevelopmentCommittee) //发展委员会百分比 | |||||
afterDevelopmentCommitteeValues := developmentCommitteeNums.Add(amountValue.Mul(developmentCommittee.Div(decimalRate))).RoundFloor(8).String() | |||||
publicWelfareAndCharityNums, _ := decimal.NewFromString(chain.PublicWelfareAndCharity) | |||||
publicWelfareAndCharity, _ := decimal.NewFromString(destructionSetting.PublicWelfareAndCharity) //公益慈善百分比 | |||||
afterPublicWelfareAndCharityValues := publicWelfareAndCharityNums.Add(amountValue.Mul(publicWelfareAndCharity.Div(decimalRate))).RoundFloor(8).String() | |||||
starLevelDividendsNums, _ := decimal.NewFromString(chain.StarLevelDividends) | |||||
starLevelDividends, _ := decimal.NewFromString(destructionSetting.StarLevelDividends) //星级分红百分比 | |||||
afterStarLevelDividendsValues := starLevelDividendsNums.Add(amountValue.Mul(starLevelDividends.Div(decimalRate))).RoundFloor(8).String() | |||||
destructionQuantityNums, _ := decimal.NewFromString(chain.DestructionQuantityNums) | |||||
destructionQuantity, _ := decimal.NewFromString(destructionSetting.DestructionQuantity) //销毁百分比 | |||||
afterDestructionQuantityValues := destructionQuantityNums.Add(amountValue.Mul(destructionQuantity.Div(decimalRate))).RoundFloor(8).String() | |||||
oneCirclesAvailableGreenEnergyPointsFlow.Direction = 1 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeEcologicalApplicationValues = chain.EcologicalApplication //生态应用 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterEcologicalApplicationValues = chain.EcologicalApplication | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeTechnicalTeamValues = chain.TotalTechnologyTeam //技术团队 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterTechnicalTeamValues = chain.TotalTechnologyTeam | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeOperateTeamValues = chain.TotalOperateTeam //运营团队 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterOperateTeamValues = chain.TotalOperateTeam | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeActiveGiveawaysValues = chain.TotalActiveGiveaways //活跃赠送 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterActiveGiveawaysValues = chain.TotalActiveGiveaways | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeOriginalQuantityValues = chain.OriginalQuantityNums //原始数量 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterOriginalQuantityValues = chain.OriginalQuantityNums | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeMarketplaceMerchantValues = chain.MarketplaceMerchantNums //市商数量 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterMarketplaceMerchantValues = afterMarketplaceMerchantValues | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeDevelopmentCommitteeValues = chain.DevelopmentCommittee //发展委员会 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterDevelopmentCommitteeValues = afterDevelopmentCommitteeValues | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforePublicWelfareAndCharityValues = chain.PublicWelfareAndCharity //公益慈善 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterPublicWelfareAndCharityValues = afterPublicWelfareAndCharityValues | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeStarLevelDividendsValues = chain.StarLevelDividends //星级分红 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterStarLevelDividendsValues = afterStarLevelDividendsValues | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeDestructionQuantityValues = chain.DestructionQuantityNums //销毁数量 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterDestructionQuantityValues = afterDestructionQuantityValues | |||||
break | |||||
} | |||||
chain.EcologicalApplication = oneCirclesAvailableGreenEnergyPointsFlow.AfterEcologicalApplicationValues //生态应用 | |||||
chain.TotalTechnologyTeam = oneCirclesAvailableGreenEnergyPointsFlow.AfterTechnicalTeamValues //技术团队 | |||||
chain.TotalOperateTeam = oneCirclesAvailableGreenEnergyPointsFlow.AfterOperateTeamValues //运营团队 | |||||
chain.TotalActiveGiveaways = oneCirclesAvailableGreenEnergyPointsFlow.AfterActiveGiveawaysValues //活跃赠送 | |||||
chain.OriginalQuantityNums = oneCirclesAvailableGreenEnergyPointsFlow.AfterOriginalQuantityValues //原始数量 | |||||
chain.MarketplaceMerchantNums = oneCirclesAvailableGreenEnergyPointsFlow.AfterMarketplaceMerchantValues //市商数量 | |||||
chain.DevelopmentCommittee = oneCirclesAvailableGreenEnergyPointsFlow.AfterDevelopmentCommitteeValues //发展委员会 | |||||
chain.PublicWelfareAndCharity = oneCirclesAvailableGreenEnergyPointsFlow.AfterPublicWelfareAndCharityValues //公益慈善 | |||||
chain.StarLevelDividends = oneCirclesAvailableGreenEnergyPointsFlow.AfterStarLevelDividendsValues //星级分红 | |||||
chain.StarLevelDividends = oneCirclesAvailableGreenEnergyPointsFlow.AfterStarLevelDividendsValues //星级分红 | |||||
chain.DestructionQuantityNums = oneCirclesAvailableGreenEnergyPointsFlow.AfterDestructionQuantityValues //销毁数量 | |||||
nowPrice, _ := decimal.NewFromString(chain.NowPrice) | |||||
originalQuantityNums, _ := decimal.NewFromString(chain.OriginalQuantityNums) | |||||
originalFunds := originalQuantityNums.Mul(nowPrice).RoundFloor(8).String() | |||||
chain.OriginalFunds = originalFunds //原始资金 | |||||
marketplaceMerchantNums, _ := decimal.NewFromString(chain.MarketplaceMerchantNums) | |||||
marketplaceMerchantFunds := marketplaceMerchantNums.Mul(nowPrice).RoundFloor(8).String() | |||||
chain.MarketplaceMerchantFunds = marketplaceMerchantFunds //市商资金 | |||||
//更新 `one_circles_green_energy_basic_setting` 表 | |||||
_, err := db.OneCirclesGreenEnergyBasicSettingUpdate(session, chain.Id, chain) | |||||
if err != nil { | |||||
return err | |||||
} | |||||
//插入 `one_circles_available_green_energy_points_flow` 记录 | |||||
_, err = db.OneCirclesAvailableGreenEnergyPointsFlowInsert(session, &oneCirclesAvailableGreenEnergyPointsFlow) | |||||
if err != nil { | |||||
return err | |||||
} | |||||
return nil | |||||
} |
@@ -0,0 +1,14 @@ | |||||
package one_circles | |||||
import ( | |||||
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/md" | |||||
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils/cache" | |||||
) | |||||
func Init(redisAddr string) (err error) { | |||||
if redisAddr != "" { | |||||
cache.NewRedis(redisAddr) | |||||
} | |||||
_, err = cache.SelectDb(md.RedisDataBase) | |||||
return | |||||
} |
@@ -0,0 +1,146 @@ | |||||
package one_circles | |||||
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" | |||||
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/md" | |||||
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" | |||||
"fmt" | |||||
"strings" | |||||
"time" | |||||
"xorm.io/xorm" | |||||
) | |||||
// SettlementPublicGiveActivityCoin 计算观看激励视屏得到活跃积分 | |||||
func SettlementPublicGiveActivityCoin(engine *xorm.Engine, masterId string, uid int) (err error) { | |||||
//1、查找 `one_circles_public_platoon_basic_setting` 基础设置 | |||||
oneCirclesPublicPlatoonBasicSetting, err := db.OneCirclesPublicPlatoonBasicSettingGetOneByParams(engine, map[string]interface{}{ | |||||
"key": "is_open", | |||||
"value": 1, | |||||
}) | |||||
if err != nil { | |||||
return | |||||
} | |||||
if oneCirclesPublicPlatoonBasicSetting.VideoRewardIsOpen == 1 { | |||||
var videoRewardSystem *md2.VideoRewardSystemStruct | |||||
err = json.Unmarshal([]byte(oneCirclesPublicPlatoonBasicSetting.VideoRewardSystem), &videoRewardSystem) | |||||
if err != nil { | |||||
return | |||||
} | |||||
if videoRewardSystem.RewardValue == "" || videoRewardSystem.RewardTotalNum == "" || videoRewardSystem.IntervalMinutes == "" || videoRewardSystem.EachRoundHour == "" { | |||||
err = errors.New("视屏奖励机制设置未完全!") | |||||
return | |||||
} | |||||
var rewardSystem []*md2.RewardSystemStruct | |||||
err = json.Unmarshal([]byte(oneCirclesPublicPlatoonBasicSetting.RewardSystem), &rewardSystem) | |||||
if err != nil { | |||||
return | |||||
} | |||||
if len(rewardSystem) == 0 { | |||||
err = errors.New("未设置奖励机制!") | |||||
return | |||||
} | |||||
rewardValue := zhios_order_relate_utils.StrToFloat64(videoRewardSystem.RewardValue) //奖励多少个活跃积分 | |||||
var rewardSystemMap = map[int]*md2.RewardSystemStruct{} | |||||
for _, v := range rewardSystem { | |||||
rewardSystemMap[v.Level] = v | |||||
} | |||||
oneCirclesPublicPlatoonUserRelation, err1 := db.OneCirclesPublicPlatoonUserRelationGetOneByParams(engine, map[string]interface{}{ | |||||
"key": "uid", | |||||
"value": uid, | |||||
}) | |||||
if err1 != nil { | |||||
return | |||||
} | |||||
var rewardFather []struct { | |||||
Uid int `json:"uid"` //用户id | |||||
RewardValue float64 `json:"reward_value"` //奖励值 | |||||
} | |||||
fatherUids := strings.Split(oneCirclesPublicPlatoonUserRelation.FatherUid, "-") | |||||
for k, fatherUid := range fatherUids { | |||||
fatherReward := rewardSystemMap[k+1] | |||||
//判断是否满足奖励条件 | |||||
userCount, _, err2 := db.SumUserRelateByParentUid(engine, fatherUid) | |||||
if err2 != nil { | |||||
return err2 | |||||
} | |||||
if userCount >= zhios_order_relate_utils.StrToInt64(fatherReward.RewardCondition) { | |||||
fatherRewardValue := rewardValue * (zhios_order_relate_utils.StrToFloat64(fatherReward.RewardValue) / 100) | |||||
rewardFather = append(rewardFather, struct { | |||||
Uid int `json:"uid"` //用户id | |||||
RewardValue float64 `json:"reward_value"` //奖励值 | |||||
}{ | |||||
Uid: zhios_order_relate_utils.StrToInt(fatherUid), | |||||
RewardValue: fatherRewardValue, | |||||
}) | |||||
} | |||||
} | |||||
session := engine.NewSession() | |||||
//给相应的用户加上"个人"活跃积分 | |||||
err = DealUserCoin(session, md.DealUserCoinReq{ | |||||
Kind: "add", | |||||
Mid: masterId, | |||||
Title: md.OneCirclesWatchAdRewardPersonalActiveCoin, | |||||
TransferType: md.OneCirclesWatchAdRewardPersonalActiveCoinForUserVirtualCoinFlow, | |||||
OrdId: "", | |||||
CoinId: oneCirclesPublicPlatoonBasicSetting.PersonActivePointsCoinId, | |||||
Uid: uid, | |||||
Amount: rewardValue, | |||||
}) | |||||
if err != nil { | |||||
_ = session.Rollback() | |||||
fmt.Println("err:::::2222", err) | |||||
return err | |||||
} | |||||
//给相应的用户加上"团队"活跃积分 | |||||
for _, vv := range rewardFather { | |||||
err = DealUserCoin(session, md.DealUserCoinReq{ | |||||
Kind: "add", | |||||
Mid: masterId, | |||||
Title: md.OneCirclesWatchAdRewardTeamActiveCoin, | |||||
TransferType: md.OneCirclesWatchAdRewardTeamActiveCoinForUserVirtualCoinFlow, | |||||
OrdId: "", | |||||
CoinId: oneCirclesPublicPlatoonBasicSetting.TeamActivePointsCoinId, | |||||
Uid: vv.Uid, | |||||
Amount: vv.RewardValue, | |||||
}) | |||||
if err != nil { | |||||
_ = session.Rollback() | |||||
fmt.Println("err:::::2222", err) | |||||
return err | |||||
} | |||||
} | |||||
err = session.Commit() | |||||
if err != nil { | |||||
_ = session.Rollback() | |||||
return errors.New("事务提交失败") | |||||
} | |||||
} | |||||
return | |||||
} | |||||
// CalcUserContinuousDailyActivityDays 计算用户连续活跃天数 | |||||
func CalcUserContinuousDailyActivityDays(engine *xorm.Engine, masterId string, uid int, startDate string, endDate string) (err error, days int, isContinuousDailyActivity bool) { | |||||
var list []model.OneCirclesGreenEnergySignIn | |||||
err = engine.Where("start_time <= ?", startDate).And("uid =?", uid).Find(&list) | |||||
if err != nil { | |||||
fmt.Println("err:::::1111", err) | |||||
return | |||||
} | |||||
days = len(list) | |||||
startAt, err := time.ParseInLocation("2006-01-02", startDate, time.Local) //起始时间 | |||||
endAt, err := time.ParseInLocation("2006-01-02", endDate, time.Local) //起始时间 | |||||
diffDays := zhios_order_relate_utils.GetDiffDays(endAt, startAt) //相差天数 | |||||
if days == diffDays { | |||||
isContinuousDailyActivity = true | |||||
} | |||||
return | |||||
} |
@@ -0,0 +1,139 @@ | |||||
package one_circles | |||||
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" | |||||
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/md" | |||||
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/one_circles/enum" | |||||
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" | |||||
"fmt" | |||||
"time" | |||||
"xorm.io/xorm" | |||||
) | |||||
// SettlementSignInGreenEnergy 计算签到得到绿色能量 | |||||
func SettlementSignInGreenEnergy(engine *xorm.Engine, masterId string) (err error) { | |||||
//1、查找 `one_circles_green_energy_basic_setting` 基础设置 | |||||
oneCirclesGreenEnergyBasicSetting, err := db.OneCirclesGreenEnergyBasicSettingGetOneByParams(engine, map[string]interface{}{ | |||||
"key": "is_open", | |||||
"value": 1, | |||||
}) | |||||
if err != nil { | |||||
return | |||||
} | |||||
var teamRewardSetting *md2.TeamRewardSettingStruct | |||||
err = json.Unmarshal([]byte(oneCirclesGreenEnergyBasicSetting.VipEquitySetting), &teamRewardSetting) | |||||
if err != nil { | |||||
return | |||||
} | |||||
if teamRewardSetting.RewardDecrementValue == "" || teamRewardSetting.RewardEndValue == "" || teamRewardSetting.MemberSelfIsOpenGetTeamReward == "" || teamRewardSetting.OneRoundDuration == "" { | |||||
err = errors.New("团队奖励设置未完全!") | |||||
return | |||||
} | |||||
var oneRoundDuration = zhios_order_relate_utils.StrToInt(teamRewardSetting.OneRoundDuration) | |||||
var rewardDecrement = zhios_order_relate_utils.StrToFloat64(teamRewardSetting.RewardDecrementValue) / 100 //递减百分比 | |||||
var rewardEndValue = zhios_order_relate_utils.StrToFloat64(teamRewardSetting.RewardEndValue) //奖励结束值 | |||||
fmt.Println("rewardDecrement>>>>>>>>>>>>", rewardDecrement) | |||||
fmt.Println("rewardEndValue>>>>>>>>>>>>", rewardEndValue) | |||||
var signInRewards []*md2.SignInRewardStruct | |||||
err = json.Unmarshal([]byte(oneCirclesGreenEnergyBasicSetting.VipEquitySetting), &signInRewards) | |||||
if err != nil { | |||||
return | |||||
} | |||||
if len(signInRewards) == 0 { | |||||
err = errors.New("未设置签到奖励!") | |||||
return | |||||
} | |||||
//2、统计全网用户数 | |||||
sqlStr := "SELECT COUNT(*) AS total FROM USER " | |||||
nativeString, _ := db.QueryNativeString(engine, sqlStr) | |||||
userCount := zhios_order_relate_utils.StrToInt64(nativeString[0]["total"]) | |||||
var rewardValue string | |||||
for _, v := range signInRewards { | |||||
if zhios_order_relate_utils.StrToInt64(v.VipMemberEndNums) <= userCount && userCount <= zhios_order_relate_utils.StrToInt64(v.VipMemberStartNums) { | |||||
rewardValue = zhios_order_relate_utils.Float64ToStrPrec8(zhios_order_relate_utils.StrToFloat64(v.RewardValue) * float64(oneRoundDuration) * 60 * 60) | |||||
} | |||||
} | |||||
//3、统计签到结束的用户数据 | |||||
now := time.Now() | |||||
startTime := now.Add(-time.Hour * time.Duration(oneRoundDuration)).Format("2006-01-02 15:04:05") | |||||
var list []model.OneCirclesGreenEnergySignIn | |||||
err = engine.Where("start_time <= ?", startTime).And("is_completed =?", 0).Find(&list) | |||||
if err != nil { | |||||
fmt.Println("err:::::1111", err) | |||||
return | |||||
} | |||||
session := engine.NewSession() | |||||
var reduceTotalGreenEnergy float64 | |||||
for _, v := range list { | |||||
//4.2给相应的用户加上个人的绿色积分(可用数量) | |||||
err = DealUserCoin(session, md.DealUserCoinReq{ | |||||
Kind: "add", | |||||
Mid: masterId, | |||||
Title: md.OneCirclesGreenEnergySignInSettlementPersonalReward, | |||||
TransferType: md.OneCirclesGreenEnergySignInSettlementPersonalRewardForUserVirtualCoinFlow, | |||||
OrdId: "", | |||||
CoinId: oneCirclesGreenEnergyBasicSetting.PersonGreenEnergyCoinId, | |||||
Uid: v.Uid, | |||||
Amount: zhios_order_relate_utils.StrToFloat64(rewardValue), | |||||
}) | |||||
if err != nil { | |||||
_ = session.Rollback() | |||||
fmt.Println("err:::::2222", err) | |||||
return err | |||||
} | |||||
reduceTotalGreenEnergy += zhios_order_relate_utils.StrToFloat64(rewardValue) | |||||
//4.2给相应的上级用户加上团队奖励的绿色积分(结算数量) | |||||
relates, err1 := db.DbsUserRelate(engine, v.Uid, 0) | |||||
if err1 != nil { | |||||
_ = session.Rollback() | |||||
fmt.Println("err:::::3333", err1) | |||||
return err1 | |||||
} | |||||
var parentRewardValue = zhios_order_relate_utils.StrToFloat64(rewardValue) | |||||
for _, relate := range *relates { | |||||
if parentRewardValue <= rewardEndValue { | |||||
break | |||||
} | |||||
parentRewardValue = parentRewardValue * rewardDecrement | |||||
err = DealUserCoin(session, md.DealUserCoinReq{ | |||||
Kind: "add", | |||||
Mid: masterId, | |||||
Title: md.OneCirclesGreenEnergySignInSettlementTeamReward, | |||||
TransferType: md.OneCirclesGreenEnergySignInSettlementTeamRewardForUserVirtualCoinFlow, | |||||
OrdId: "", | |||||
CoinId: oneCirclesGreenEnergyBasicSetting.TeamGreenEnergyCoinId, | |||||
Uid: relate.Uid, | |||||
Amount: parentRewardValue, | |||||
}) | |||||
if err != nil { | |||||
_ = session.Rollback() | |||||
fmt.Println("err:::::44444", err) | |||||
return err | |||||
} | |||||
reduceTotalGreenEnergy += parentRewardValue | |||||
} | |||||
} | |||||
//5、减少“活跃赠送” 中的绿色能量 | |||||
err = DealAvailableGreenEnergyCoin(session, int(enum.SignInReward), reduceTotalGreenEnergy, enum.SignInReward.String(), oneCirclesGreenEnergyBasicSetting) | |||||
if err != nil { | |||||
_ = session.Rollback() | |||||
fmt.Println("err:::::55555", err) | |||||
return err | |||||
} | |||||
err = session.Commit() | |||||
if err != nil { | |||||
_ = session.Rollback() | |||||
return errors.New("事务提交失败") | |||||
} | |||||
return | |||||
} |
@@ -0,0 +1,661 @@ | |||||
package rule | |||||
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" | |||||
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/md" | |||||
zhios_order_relate_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils" | |||||
"errors" | |||||
"fmt" | |||||
"math" | |||||
"strconv" | |||||
"strings" | |||||
"time" | |||||
"xorm.io/xorm" | |||||
) | |||||
// AddOneCirclesPublicPlatoonUserRelationCommission 新增公排用户关系记录 | |||||
func AddOneCirclesPublicPlatoonUserRelationCommission(engine *xorm.Engine, AddOneCirclesPublicPlatoonUserRelationCommissionReqList []*md.AddOneCirclesPublicPlatoonUserRelationCommissionReq) (map[string]*model.OneCirclesPublicPlatoonUserRelation, error) { | |||||
var resp = map[string]*model.OneCirclesPublicPlatoonUserRelation{} | |||||
//查找 `one_circles_public_platoon_basic_setting` 基础设置 | |||||
oneCirclesPublicPlatoonBasicSetting, err := db.OneCirclesPublicPlatoonBasicSettingGetOneByParams(engine, map[string]interface{}{ | |||||
"key": "is_open", | |||||
"value": 1, | |||||
}) | |||||
if err != nil { | |||||
return nil, err | |||||
} | |||||
if oneCirclesPublicPlatoonBasicSetting == nil { | |||||
return nil, errors.New("公排制度未开启") | |||||
} | |||||
for _, param := range AddOneCirclesPublicPlatoonUserRelationCommissionReqList { | |||||
//1、判断是否有推荐人 | |||||
if param.RecommendUid != "" { | |||||
//2、有推荐人 | |||||
//判断是否有uid为-1 (代表等待新用户填充) 的记录 | |||||
oneCirclesPublicPlatoonUserRelation, err1 := db.OneCirclesPublicPlatoonUserRelationGetOneByPid(engine, param.RecommendUid, map[string]interface{}{ | |||||
"key": "uid", | |||||
"value": -1, | |||||
}) | |||||
if err1 != nil { | |||||
return nil, err1 | |||||
} | |||||
if oneCirclesPublicPlatoonUserRelation != nil { | |||||
now := time.Now() | |||||
oldUid := oneCirclesPublicPlatoonUserRelation.Uid | |||||
oneCirclesPublicPlatoonUserRelation.Uid = zhios_order_relate_utils.StrToInt(param.Uid) | |||||
oneCirclesPublicPlatoonUserRelation.RecommendUid = zhios_order_relate_utils.StrToInt(param.RecommendUid) | |||||
oneCirclesPublicPlatoonUserRelation.CreateAt = now.Format("2006-01-02 15:04:05") | |||||
oneCirclesPublicPlatoonUserRelation.UpdateAt = now.Format("2006-01-02 15:04:05") | |||||
oneCirclesPublicPlatoonUserRelation.JoinAt = now.Format("2006-01-02 15:04:05") | |||||
updateAffected, err2 := db.OneCirclesPublicPlatoonUserRelationUpdate(engine.NewSession(), oneCirclesPublicPlatoonUserRelation.Id, oneCirclesPublicPlatoonUserRelation) | |||||
if err2 != nil { | |||||
return nil, err2 | |||||
} | |||||
if updateAffected == 0 { | |||||
err = errors.New("更新 one_circles_public_platoon_user_relation 记录失败") | |||||
return nil, err | |||||
} else { | |||||
for n := 1; n <= 9; n++ { | |||||
str := "father_uid" + strconv.Itoa(n) | |||||
sql := fmt.Sprintf("UPDATE `one_circles_public_platoon_user_relation` SET %s=%s where %s=%s", str, param.Uid, str, strconv.Itoa(oldUid)) | |||||
fmt.Println(">>>>>>>sql>>>>>>>", sql) | |||||
_, err = engine.Exec(sql) | |||||
if err != nil { | |||||
return nil, err | |||||
} | |||||
} | |||||
resp[param.Uid] = oneCirclesPublicPlatoonUserRelation | |||||
} | |||||
continue | |||||
} | |||||
res, err := OneCirclesPublicPlatoon(engine, zhios_order_relate_utils.StrToInt(param.Uid), zhios_order_relate_utils.StrToInt(param.RecommendUid), *oneCirclesPublicPlatoonBasicSetting) | |||||
if err != nil { | |||||
return nil, err | |||||
} | |||||
resp[param.Uid] = &res | |||||
} | |||||
} | |||||
return resp, nil | |||||
} | |||||
/* | |||||
公排方法 | |||||
TODO 相关公式: | |||||
1: 每个等级的起始值(1+5^0+5^1+5^2+...+5^x-2), 每个等级的结束值(`5^0+5^1+5^2+...+5^x-1) | |||||
2: 根据position查找父级position { (position-1)/5 } | |||||
3: 根据position查找等级level {position-5^0-5^1-5^2-...-5^x 是否 <0 ? => x+1 } | |||||
4: 根据最新自增`id` 逆向推导 position {levelFirstPosition + (position-1)%5} | |||||
*/ | |||||
func OneCirclesPublicPlatoon(engine *xorm.Engine, uid, recommendUid int, oneCirclesPublicPlatoonBasicSetting model.OneCirclesPublicPlatoonBasicSetting) (model.OneCirclesPublicPlatoonUserRelation, error) { | |||||
var standardSmallPublicPlatoonRelation md.StandardSmallPublicPlatoonRelation | |||||
var oneCirclesPublicPlatoonUserRelation model.OneCirclesPublicPlatoonUserRelation | |||||
var fatherUid int | |||||
//1、 查找当前 one_circles_public_platoon_user_relation 中 recommendUid 的记录 | |||||
m, err := db.OneCirclesPublicPlatoonUserRelationGetOneByParams(engine, map[string]interface{}{ | |||||
"key": "uid", | |||||
"value": recommendUid, | |||||
}) | |||||
if err != nil { | |||||
return model.OneCirclesPublicPlatoonUserRelation{}, err | |||||
} | |||||
//2、 查找当前 one_circles_public_platoon_user_relation 中 recommendUid 所有的子记录 | |||||
oneCirclesPublicPlatoonUserRelations, err := db.OneCirclesPublicPlatoonUserRelationFindByPid(engine, m.Uid, "father_uid1", "position1") | |||||
if err != nil { | |||||
return model.OneCirclesPublicPlatoonUserRelation{}, err | |||||
} | |||||
if len(oneCirclesPublicPlatoonUserRelations) == 0 { | |||||
fatherUid = m.Uid | |||||
//证明是第一个 | |||||
standardSmallPublicPlatoonRelation.FatherUid1 = m.Uid | |||||
standardSmallPublicPlatoonRelation.FatherUid2 = m.FatherUid1 | |||||
standardSmallPublicPlatoonRelation.FatherUid3 = m.FatherUid2 | |||||
standardSmallPublicPlatoonRelation.FatherUid4 = m.FatherUid3 | |||||
standardSmallPublicPlatoonRelation.FatherUid5 = m.FatherUid4 | |||||
standardSmallPublicPlatoonRelation.FatherUid6 = m.FatherUid5 | |||||
standardSmallPublicPlatoonRelation.FatherUid7 = m.FatherUid6 | |||||
standardSmallPublicPlatoonRelation.FatherUid8 = m.FatherUid7 | |||||
standardSmallPublicPlatoonRelation.FatherUid9 = m.FatherUid8 | |||||
standardSmallPublicPlatoonRelation.Pid1 = m.Position | |||||
standardSmallPublicPlatoonRelation.Pid2 = m.Position1 | |||||
standardSmallPublicPlatoonRelation.Pid3 = m.Position2 | |||||
standardSmallPublicPlatoonRelation.Pid4 = m.Position3 | |||||
standardSmallPublicPlatoonRelation.Pid5 = m.Position4 | |||||
standardSmallPublicPlatoonRelation.Pid6 = m.Position5 | |||||
standardSmallPublicPlatoonRelation.Pid7 = m.Position6 | |||||
standardSmallPublicPlatoonRelation.Pid8 = m.Position7 | |||||
standardSmallPublicPlatoonRelation.Pid9 = m.Position8 | |||||
standardSmallPublicPlatoonRelation.Position1 = oneCirclesSmallSearchPositionFirstSonPosition(m.Position, oneCirclesPublicPlatoonBasicSetting.SeveralTimes) | |||||
standardSmallPublicPlatoonRelation.Position2 = oneCirclesSmallReverseDeductionPositionByFather(m.Position1, m.Level1, oneCirclesPublicPlatoonBasicSetting.SeveralTimes, 0) | |||||
standardSmallPublicPlatoonRelation.Position3 = oneCirclesSmallReverseDeductionPositionByFather(m.Position2, m.Level2, oneCirclesPublicPlatoonBasicSetting.SeveralTimes, 0) | |||||
standardSmallPublicPlatoonRelation.Position4 = oneCirclesSmallReverseDeductionPositionByFather(m.Position3, m.Level3, oneCirclesPublicPlatoonBasicSetting.SeveralTimes, 0) | |||||
standardSmallPublicPlatoonRelation.Position5 = oneCirclesSmallReverseDeductionPositionByFather(m.Position4, m.Level4, oneCirclesPublicPlatoonBasicSetting.SeveralTimes, 0) | |||||
standardSmallPublicPlatoonRelation.Position6 = oneCirclesSmallReverseDeductionPositionByFather(m.Position5, m.Level5, oneCirclesPublicPlatoonBasicSetting.SeveralTimes, 0) | |||||
standardSmallPublicPlatoonRelation.Position7 = oneCirclesSmallReverseDeductionPositionByFather(m.Position6, m.Level6, oneCirclesPublicPlatoonBasicSetting.SeveralTimes, 0) | |||||
standardSmallPublicPlatoonRelation.Position8 = oneCirclesSmallReverseDeductionPositionByFather(m.Position7, m.Level7, oneCirclesPublicPlatoonBasicSetting.SeveralTimes, 0) | |||||
standardSmallPublicPlatoonRelation.Position9 = oneCirclesSmallReverseDeductionPositionByFather(m.Position8, m.Level8, oneCirclesPublicPlatoonBasicSetting.SeveralTimes, 0) | |||||
if m.Level1 == 0 { | |||||
m.Level1-- | |||||
} | |||||
if m.Level2 == 0 { | |||||
m.Level2-- | |||||
} | |||||
if m.Level3 == 0 { | |||||
m.Level3-- | |||||
} | |||||
if m.Level4 == 0 { | |||||
m.Level4-- | |||||
} | |||||
if m.Level5 == 0 { | |||||
m.Level5-- | |||||
} | |||||
if m.Level6 == 0 { | |||||
m.Level6-- | |||||
} | |||||
if m.Level7 == 0 { | |||||
m.Level7-- | |||||
} | |||||
if m.Level8 == 0 { | |||||
m.Level8-- | |||||
} | |||||
standardSmallPublicPlatoonRelation.Level1 = m.Level + 1 | |||||
standardSmallPublicPlatoonRelation.Level2 = m.Level1 + 1 | |||||
standardSmallPublicPlatoonRelation.Level3 = m.Level2 + 1 | |||||
standardSmallPublicPlatoonRelation.Level4 = m.Level3 + 1 | |||||
standardSmallPublicPlatoonRelation.Level5 = m.Level4 + 1 | |||||
standardSmallPublicPlatoonRelation.Level6 = m.Level5 + 1 | |||||
standardSmallPublicPlatoonRelation.Level7 = m.Level6 + 1 | |||||
standardSmallPublicPlatoonRelation.Level8 = m.Level7 + 1 | |||||
standardSmallPublicPlatoonRelation.Level9 = m.Level8 + 1 | |||||
standardSmallPublicPlatoonRelation.LevelTotal = m.LevelTotal + 1 | |||||
} else { | |||||
//TODO::判断直属下级是否排满 | |||||
if len(oneCirclesPublicPlatoonUserRelations) >= oneCirclesPublicPlatoonBasicSetting.SeveralTimes { | |||||
var fatherLevel float64 | |||||
smallMakeSearchLevel(&m.Position, float64(oneCirclesPublicPlatoonBasicSetting.SeveralTimes), &fatherLevel) | |||||
var times = 0 | |||||
data, father, err := oneCirclesSmallFindSuitablePosition(engine, &m.Position, float64(oneCirclesPublicPlatoonBasicSetting.SeveralTimes), m.Uid, int(fatherLevel), ×) | |||||
if err != nil { | |||||
return model.OneCirclesPublicPlatoonUserRelation{}, err | |||||
} | |||||
fatherUid = father | |||||
standardSmallPublicPlatoonRelation = data | |||||
} else { | |||||
fatherUid = m.Uid | |||||
standardSmallPublicPlatoonRelation.FatherUid1 = oneCirclesPublicPlatoonUserRelations[0].FatherUid1 | |||||
standardSmallPublicPlatoonRelation.FatherUid2 = oneCirclesPublicPlatoonUserRelations[0].FatherUid2 | |||||
standardSmallPublicPlatoonRelation.FatherUid3 = oneCirclesPublicPlatoonUserRelations[0].FatherUid3 | |||||
standardSmallPublicPlatoonRelation.FatherUid4 = oneCirclesPublicPlatoonUserRelations[0].FatherUid4 | |||||
standardSmallPublicPlatoonRelation.FatherUid5 = oneCirclesPublicPlatoonUserRelations[0].FatherUid5 | |||||
standardSmallPublicPlatoonRelation.FatherUid6 = oneCirclesPublicPlatoonUserRelations[0].FatherUid6 | |||||
standardSmallPublicPlatoonRelation.FatherUid7 = oneCirclesPublicPlatoonUserRelations[0].FatherUid7 | |||||
standardSmallPublicPlatoonRelation.FatherUid8 = oneCirclesPublicPlatoonUserRelations[0].FatherUid8 | |||||
standardSmallPublicPlatoonRelation.Pid1 = oneCirclesPublicPlatoonUserRelations[0].Pid1 | |||||
standardSmallPublicPlatoonRelation.Pid2 = oneCirclesPublicPlatoonUserRelations[0].Pid2 | |||||
standardSmallPublicPlatoonRelation.Pid3 = oneCirclesPublicPlatoonUserRelations[0].Pid3 | |||||
standardSmallPublicPlatoonRelation.Pid4 = oneCirclesPublicPlatoonUserRelations[0].Pid4 | |||||
standardSmallPublicPlatoonRelation.Pid5 = oneCirclesPublicPlatoonUserRelations[0].Pid5 | |||||
standardSmallPublicPlatoonRelation.Pid6 = oneCirclesPublicPlatoonUserRelations[0].Pid6 | |||||
standardSmallPublicPlatoonRelation.Pid7 = oneCirclesPublicPlatoonUserRelations[0].Pid7 | |||||
standardSmallPublicPlatoonRelation.Pid8 = oneCirclesPublicPlatoonUserRelations[0].Pid8 | |||||
standardSmallPublicPlatoonRelation.Position1 = oneCirclesPublicPlatoonUserRelations[0].Position1 + 1 | |||||
if oneCirclesPublicPlatoonUserRelations[0].Position2 != 0 { | |||||
standardSmallPublicPlatoonRelation.Position2 = oneCirclesPublicPlatoonUserRelations[0].Position2 + 1 | |||||
} | |||||
if oneCirclesPublicPlatoonUserRelations[0].Position3 != 0 { | |||||
standardSmallPublicPlatoonRelation.Position3 = oneCirclesPublicPlatoonUserRelations[0].Position3 + 1 | |||||
} | |||||
if oneCirclesPublicPlatoonUserRelations[0].Position4 != 0 { | |||||
standardSmallPublicPlatoonRelation.Position4 = oneCirclesPublicPlatoonUserRelations[0].Position4 + 1 | |||||
} | |||||
if oneCirclesPublicPlatoonUserRelations[0].Position5 != 0 { | |||||
standardSmallPublicPlatoonRelation.Position5 = oneCirclesPublicPlatoonUserRelations[0].Position5 + 1 | |||||
} | |||||
if oneCirclesPublicPlatoonUserRelations[0].Position6 != 0 { | |||||
standardSmallPublicPlatoonRelation.Position6 = oneCirclesPublicPlatoonUserRelations[0].Position6 + 1 | |||||
} | |||||
if oneCirclesPublicPlatoonUserRelations[0].Position7 != 0 { | |||||
standardSmallPublicPlatoonRelation.Position7 = oneCirclesPublicPlatoonUserRelations[0].Position7 + 1 | |||||
} | |||||
if oneCirclesPublicPlatoonUserRelations[0].Position8 != 0 { | |||||
standardSmallPublicPlatoonRelation.Position8 = oneCirclesPublicPlatoonUserRelations[0].Position8 + 1 | |||||
} | |||||
standardSmallPublicPlatoonRelation.Level1 = oneCirclesPublicPlatoonUserRelations[0].Level1 | |||||
standardSmallPublicPlatoonRelation.Level2 = oneCirclesPublicPlatoonUserRelations[0].Level2 | |||||
standardSmallPublicPlatoonRelation.Level3 = oneCirclesPublicPlatoonUserRelations[0].Level3 | |||||
standardSmallPublicPlatoonRelation.Level4 = oneCirclesPublicPlatoonUserRelations[0].Level4 | |||||
standardSmallPublicPlatoonRelation.Level5 = oneCirclesPublicPlatoonUserRelations[0].Level5 | |||||
standardSmallPublicPlatoonRelation.Level6 = oneCirclesPublicPlatoonUserRelations[0].Level6 | |||||
standardSmallPublicPlatoonRelation.Level7 = oneCirclesPublicPlatoonUserRelations[0].Level7 | |||||
standardSmallPublicPlatoonRelation.Level8 = oneCirclesPublicPlatoonUserRelations[0].Level8 | |||||
standardSmallPublicPlatoonRelation.LevelTotal = oneCirclesPublicPlatoonUserRelations[0].LevelTotal | |||||
} | |||||
} | |||||
//2、查找对应pid的 user_public_platoon_relation 记录 | |||||
var m1 model.OneCirclesPublicPlatoonUserRelation | |||||
if has, err := engine.Where("uid=?", fatherUid).Get(&m1); err != nil || has == false { | |||||
return oneCirclesPublicPlatoonUserRelation, err | |||||
} | |||||
var fatherUidStr string | |||||
if m1.FatherUid == "" { | |||||
//TODO::顶级 | |||||
fatherUidStr = zhios_order_relate_utils.IntToStr(m1.Id) | |||||
} else { | |||||
fatherUids := strings.Split(m1.FatherUid, "-") | |||||
if len(fatherUids) >= oneCirclesPublicPlatoonBasicSetting.SeveralRows { | |||||
fatherUidStr = zhios_order_relate_utils.IntToStr(m1.Id) + "-" + strings.Join(fatherUids[0:oneCirclesPublicPlatoonBasicSetting.SeveralRows:len(fatherUids)], "-") | |||||
} else { | |||||
fatherUidStr = zhios_order_relate_utils.IntToStr(m1.Id) + "-" + m1.FatherUid | |||||
} | |||||
} | |||||
// 3、插入 user_public_platoon_relation 记录 | |||||
now := time.Now() | |||||
oneCirclesPublicPlatoonUserRelation.Uid = uid | |||||
oneCirclesPublicPlatoonUserRelation.FatherUid = fatherUidStr | |||||
oneCirclesPublicPlatoonUserRelation.FatherUid1 = standardSmallPublicPlatoonRelation.FatherUid1 | |||||
oneCirclesPublicPlatoonUserRelation.FatherUid2 = standardSmallPublicPlatoonRelation.FatherUid2 | |||||
oneCirclesPublicPlatoonUserRelation.FatherUid3 = standardSmallPublicPlatoonRelation.FatherUid3 | |||||
oneCirclesPublicPlatoonUserRelation.FatherUid4 = standardSmallPublicPlatoonRelation.FatherUid4 | |||||
oneCirclesPublicPlatoonUserRelation.FatherUid5 = standardSmallPublicPlatoonRelation.FatherUid5 | |||||
oneCirclesPublicPlatoonUserRelation.FatherUid6 = standardSmallPublicPlatoonRelation.FatherUid6 | |||||
oneCirclesPublicPlatoonUserRelation.FatherUid7 = standardSmallPublicPlatoonRelation.FatherUid7 | |||||
oneCirclesPublicPlatoonUserRelation.FatherUid8 = standardSmallPublicPlatoonRelation.FatherUid8 | |||||
oneCirclesPublicPlatoonUserRelation.Pid1 = standardSmallPublicPlatoonRelation.Pid1 | |||||
oneCirclesPublicPlatoonUserRelation.Pid2 = standardSmallPublicPlatoonRelation.Pid2 | |||||
oneCirclesPublicPlatoonUserRelation.Pid3 = standardSmallPublicPlatoonRelation.Pid3 | |||||
oneCirclesPublicPlatoonUserRelation.Pid4 = standardSmallPublicPlatoonRelation.Pid4 | |||||
oneCirclesPublicPlatoonUserRelation.Pid5 = standardSmallPublicPlatoonRelation.Pid5 | |||||
oneCirclesPublicPlatoonUserRelation.Pid6 = standardSmallPublicPlatoonRelation.Pid6 | |||||
oneCirclesPublicPlatoonUserRelation.Pid7 = standardSmallPublicPlatoonRelation.Pid7 | |||||
oneCirclesPublicPlatoonUserRelation.Pid8 = standardSmallPublicPlatoonRelation.Pid8 | |||||
oneCirclesPublicPlatoonUserRelation.Position = 1 | |||||
oneCirclesPublicPlatoonUserRelation.Position1 = standardSmallPublicPlatoonRelation.Position1 | |||||
oneCirclesPublicPlatoonUserRelation.Position2 = standardSmallPublicPlatoonRelation.Position2 | |||||
oneCirclesPublicPlatoonUserRelation.Position3 = standardSmallPublicPlatoonRelation.Position3 | |||||
oneCirclesPublicPlatoonUserRelation.Position4 = standardSmallPublicPlatoonRelation.Position4 | |||||
oneCirclesPublicPlatoonUserRelation.Position5 = standardSmallPublicPlatoonRelation.Position5 | |||||
oneCirclesPublicPlatoonUserRelation.Position6 = standardSmallPublicPlatoonRelation.Position6 | |||||
oneCirclesPublicPlatoonUserRelation.Position7 = standardSmallPublicPlatoonRelation.Position7 | |||||
oneCirclesPublicPlatoonUserRelation.Position8 = standardSmallPublicPlatoonRelation.Position8 | |||||
oneCirclesPublicPlatoonUserRelation.Level = 1 | |||||
oneCirclesPublicPlatoonUserRelation.Level1 = standardSmallPublicPlatoonRelation.Level1 | |||||
oneCirclesPublicPlatoonUserRelation.Level2 = standardSmallPublicPlatoonRelation.Level2 | |||||
oneCirclesPublicPlatoonUserRelation.Level3 = standardSmallPublicPlatoonRelation.Level3 | |||||
oneCirclesPublicPlatoonUserRelation.Level4 = standardSmallPublicPlatoonRelation.Level4 | |||||
oneCirclesPublicPlatoonUserRelation.Level5 = standardSmallPublicPlatoonRelation.Level5 | |||||
oneCirclesPublicPlatoonUserRelation.Level6 = standardSmallPublicPlatoonRelation.Level6 | |||||
oneCirclesPublicPlatoonUserRelation.Level7 = standardSmallPublicPlatoonRelation.Level7 | |||||
oneCirclesPublicPlatoonUserRelation.Level8 = standardSmallPublicPlatoonRelation.Level8 | |||||
oneCirclesPublicPlatoonUserRelation.LevelTotal = standardSmallPublicPlatoonRelation.LevelTotal | |||||
oneCirclesPublicPlatoonUserRelation.RecommendUid = recommendUid | |||||
oneCirclesPublicPlatoonUserRelation.JoinAt = now.Format("2006-01-02 15:04:05") | |||||
oneCirclesPublicPlatoonUserRelation.CreateAt = now.Format("2006-01-02 15:04:05") | |||||
oneCirclesPublicPlatoonUserRelation.UpdateAt = now.Format("2006-01-02 15:04:05") | |||||
oneCirclesPublicPlatoonUserRelation.HasSonNum = 0 | |||||
_, err = db.OneCirclesPublicPlatoonUserRelationInsert(engine, &oneCirclesPublicPlatoonUserRelation) | |||||
if err != nil { | |||||
return model.OneCirclesPublicPlatoonUserRelation{}, err | |||||
} | |||||
// 4、改变直属父级的 has_son_num 数量 | |||||
update, err := engine.Where("uid = ?", fatherUid).SetExpr("has_son_num", "has_son_num + 1").Update(new(model.OneCirclesPublicPlatoonUserRelation)) | |||||
if err != nil { | |||||
return oneCirclesPublicPlatoonUserRelation, err | |||||
} | |||||
if update == 0 { | |||||
return oneCirclesPublicPlatoonUserRelation, errors.New("更新has_son_num数据出错") | |||||
} | |||||
return oneCirclesPublicPlatoonUserRelation, nil | |||||
} | |||||
// oneCirclesSmallReverseDeductionPosition 逆向推导 position | |||||
func oneCirclesSmallReverseDeductionPosition(calcPosition, levelFirstPosition, severalTimes int) (position int) { | |||||
remainder := (calcPosition - 1) % severalTimes | |||||
position = levelFirstPosition + remainder | |||||
return | |||||
} | |||||
func oneCirclesSmallReverseDeductionPositionByFather(fatherPosition, level, severalTimes, remainder int) (position int) { | |||||
if fatherPosition == 0 { | |||||
position = 0 | |||||
return | |||||
} | |||||
firstPosition := oneCirclesSmallGetLevelForFirstPosition(level, severalTimes) | |||||
endPosition := firstPosition + int(math.Pow(float64(severalTimes), float64(level-1))) - 1 | |||||
position = fatherPosition + (fatherPosition-firstPosition)*severalTimes + (endPosition - fatherPosition) + 1 | |||||
return | |||||
} | |||||
func oneCirclesSmallFindSuitablePosition(engine *xorm.Engine, position *int, severalTimes float64, fuid, fatherLevel int, times *int) (standardSmallPublicPlatoonRelation md.StandardSmallPublicPlatoonRelation, fatherUid int, err error) { | |||||
*times++ | |||||
positionName := "position" + zhios_order_relate_utils.IntToStr(*times) | |||||
fatherName := "father_uid" + zhios_order_relate_utils.IntToStr(*times) | |||||
firstSonPosition := oneCirclesSmallSearchPositionFirstSonPosition(*position, int(severalTimes)) | |||||
var tempLevel float64 | |||||
smallMakeSearchLevel(&firstSonPosition, severalTimes, &tempLevel) | |||||
firstSonLevel := int(tempLevel) | |||||
endSonPosition := firstSonPosition + int(math.Pow(severalTimes, float64(firstSonLevel-fatherLevel))) - 1 | |||||
list, _, err := db.OneCirclesPublicPlatoonUserRelationFindCountByPosition(engine, fuid, fatherName, positionName, int64(firstSonPosition), int64(endSonPosition)) | |||||
if err != nil { | |||||
return standardSmallPublicPlatoonRelation, fatherUid, err | |||||
} | |||||
if list[0].HasSonNum == int(severalTimes) { | |||||
//TODO::则证明该层直属下级无空位 | |||||
position = &firstSonPosition | |||||
return oneCirclesSmallFindSuitablePosition(engine, position, severalTimes, fuid, fatherLevel, times) | |||||
} else if list[0].HasSonNum == 0 { | |||||
fatherUid = list[0].Uid | |||||
//TODO::新的一层 | |||||
standardSmallPublicPlatoonRelation.FatherUid1 = list[0].Uid | |||||
standardSmallPublicPlatoonRelation.FatherUid2 = list[0].FatherUid1 | |||||
standardSmallPublicPlatoonRelation.FatherUid3 = list[0].FatherUid2 | |||||
standardSmallPublicPlatoonRelation.FatherUid4 = list[0].FatherUid3 | |||||
standardSmallPublicPlatoonRelation.FatherUid5 = list[0].FatherUid4 | |||||
standardSmallPublicPlatoonRelation.FatherUid6 = list[0].FatherUid5 | |||||
standardSmallPublicPlatoonRelation.FatherUid7 = list[0].FatherUid6 | |||||
standardSmallPublicPlatoonRelation.FatherUid8 = list[0].FatherUid7 | |||||
standardSmallPublicPlatoonRelation.FatherUid9 = list[0].FatherUid8 | |||||
standardSmallPublicPlatoonRelation.Pid1 = list[0].Position | |||||
standardSmallPublicPlatoonRelation.Pid2 = list[0].Position1 | |||||
standardSmallPublicPlatoonRelation.Pid3 = list[0].Position2 | |||||
standardSmallPublicPlatoonRelation.Pid4 = list[0].Position3 | |||||
standardSmallPublicPlatoonRelation.Pid5 = list[0].Position4 | |||||
standardSmallPublicPlatoonRelation.Pid6 = list[0].Position5 | |||||
standardSmallPublicPlatoonRelation.Pid7 = list[0].Position6 | |||||
standardSmallPublicPlatoonRelation.Pid8 = list[0].Position7 | |||||
standardSmallPublicPlatoonRelation.Pid9 = list[0].Position8 | |||||
standardSmallPublicPlatoonRelation.Position1 = oneCirclesSmallSearchPositionFirstSonPosition(list[0].Position, int(severalTimes)) | |||||
standardSmallPublicPlatoonRelation.Position2 = oneCirclesSmallReverseDeductionPositionByFather(list[0].Position1, list[0].Level1, int(severalTimes), 0) | |||||
standardSmallPublicPlatoonRelation.Position3 = oneCirclesSmallReverseDeductionPositionByFather(list[0].Position2, list[0].Level2, int(severalTimes), 0) | |||||
standardSmallPublicPlatoonRelation.Position4 = oneCirclesSmallReverseDeductionPositionByFather(list[0].Position3, list[0].Level3, int(severalTimes), 0) | |||||
standardSmallPublicPlatoonRelation.Position5 = oneCirclesSmallReverseDeductionPositionByFather(list[0].Position4, list[0].Level4, int(severalTimes), 0) | |||||
standardSmallPublicPlatoonRelation.Position6 = oneCirclesSmallReverseDeductionPositionByFather(list[0].Position5, list[0].Level5, int(severalTimes), 0) | |||||
standardSmallPublicPlatoonRelation.Position7 = oneCirclesSmallReverseDeductionPositionByFather(list[0].Position6, list[0].Level6, int(severalTimes), 0) | |||||
standardSmallPublicPlatoonRelation.Position8 = oneCirclesSmallReverseDeductionPositionByFather(list[0].Position7, list[0].Level7, int(severalTimes), 0) | |||||
standardSmallPublicPlatoonRelation.Position9 = oneCirclesSmallReverseDeductionPositionByFather(list[0].Position8, list[0].Level8, int(severalTimes), 0) | |||||
if list[0].Level1 == 0 { | |||||
list[0].Level1-- | |||||
} | |||||
if list[0].Level2 == 0 { | |||||
list[0].Level2-- | |||||
} | |||||
if list[0].Level3 == 0 { | |||||
list[0].Level3-- | |||||
} | |||||
if list[0].Level4 == 0 { | |||||
list[0].Level4-- | |||||
} | |||||
if list[0].Level5 == 0 { | |||||
list[0].Level5-- | |||||
} | |||||
if list[0].Level6 == 0 { | |||||
list[0].Level6-- | |||||
} | |||||
if list[0].Level7 == 0 { | |||||
list[0].Level7-- | |||||
} | |||||
if list[0].Level8 == 0 { | |||||
list[0].Level8-- | |||||
} | |||||
standardSmallPublicPlatoonRelation.Level1 = list[0].Level + 1 | |||||
standardSmallPublicPlatoonRelation.Level2 = list[0].Level1 + 1 | |||||
standardSmallPublicPlatoonRelation.Level3 = list[0].Level2 + 1 | |||||
standardSmallPublicPlatoonRelation.Level4 = list[0].Level3 + 1 | |||||
standardSmallPublicPlatoonRelation.Level5 = list[0].Level4 + 1 | |||||
standardSmallPublicPlatoonRelation.Level6 = list[0].Level5 + 1 | |||||
standardSmallPublicPlatoonRelation.Level7 = list[0].Level6 + 1 | |||||
standardSmallPublicPlatoonRelation.Level8 = list[0].Level7 + 1 | |||||
standardSmallPublicPlatoonRelation.Level9 = list[0].Level8 + 1 | |||||
standardSmallPublicPlatoonRelation.LevelTotal = list[0].LevelTotal + 1 | |||||
} else { | |||||
fatherUid = list[0].Uid | |||||
_, _, _, _, getPositionName, _, _, _ := oneCirclesGetPosition(list[0], *times+1) | |||||
//oneCirclesPublicPlatoonUserRelations, err := db.OneCirclesPublicPlatoonUserRelationFindByPid(engine, m.Position, m.Uid, "pid1", "father_uid1", "position1") | |||||
oneCirclesPublicPlatoonUserRelations, err := db.OneCirclesPublicPlatoonUserRelationFindByPid(engine, list[0].Uid, "father_uid1", getPositionName) | |||||
if err != nil { | |||||
return standardSmallPublicPlatoonRelation, fatherUid, err | |||||
} | |||||
if oneCirclesPublicPlatoonUserRelations[0].Position2 == 0 { | |||||
oneCirclesPublicPlatoonUserRelations[0].Position2 = -1 | |||||
} | |||||
if oneCirclesPublicPlatoonUserRelations[0].Position3 == 0 { | |||||
standardSmallPublicPlatoonRelation.Position3 = -1 | |||||
} | |||||
if oneCirclesPublicPlatoonUserRelations[0].Position4 == 0 { | |||||
standardSmallPublicPlatoonRelation.Position4 = -1 | |||||
} | |||||
if oneCirclesPublicPlatoonUserRelations[0].Position5 == 0 { | |||||
standardSmallPublicPlatoonRelation.Position5 = -1 | |||||
} | |||||
if oneCirclesPublicPlatoonUserRelations[0].Position6 == 0 { | |||||
standardSmallPublicPlatoonRelation.Position6 = -1 | |||||
} | |||||
if oneCirclesPublicPlatoonUserRelations[0].Position7 == 0 { | |||||
standardSmallPublicPlatoonRelation.Position7 = -1 | |||||
} | |||||
if oneCirclesPublicPlatoonUserRelations[0].Position8 == 0 { | |||||
standardSmallPublicPlatoonRelation.Position8 = -1 | |||||
} | |||||
standardSmallPublicPlatoonRelation = md.StandardSmallPublicPlatoonRelation{ | |||||
FatherUid1: oneCirclesPublicPlatoonUserRelations[0].FatherUid1, | |||||
FatherUid2: oneCirclesPublicPlatoonUserRelations[0].FatherUid2, | |||||
FatherUid3: oneCirclesPublicPlatoonUserRelations[0].FatherUid3, | |||||
FatherUid4: oneCirclesPublicPlatoonUserRelations[0].FatherUid4, | |||||
FatherUid5: oneCirclesPublicPlatoonUserRelations[0].FatherUid5, | |||||
FatherUid6: oneCirclesPublicPlatoonUserRelations[0].FatherUid6, | |||||
FatherUid7: oneCirclesPublicPlatoonUserRelations[0].FatherUid7, | |||||
FatherUid8: oneCirclesPublicPlatoonUserRelations[0].FatherUid8, | |||||
Pid1: oneCirclesPublicPlatoonUserRelations[0].Pid1, | |||||
Pid2: oneCirclesPublicPlatoonUserRelations[0].Pid2, | |||||
Pid3: oneCirclesPublicPlatoonUserRelations[0].Pid3, | |||||
Pid4: oneCirclesPublicPlatoonUserRelations[0].Pid4, | |||||
Pid5: oneCirclesPublicPlatoonUserRelations[0].Pid5, | |||||
Pid6: oneCirclesPublicPlatoonUserRelations[0].Pid6, | |||||
Pid7: oneCirclesPublicPlatoonUserRelations[0].Pid7, | |||||
Pid8: oneCirclesPublicPlatoonUserRelations[0].Pid8, | |||||
Position1: oneCirclesPublicPlatoonUserRelations[0].Position1 + 1, | |||||
Position2: oneCirclesPublicPlatoonUserRelations[0].Position2 + 1, | |||||
Position3: oneCirclesPublicPlatoonUserRelations[0].Position3 + 1, | |||||
Position4: oneCirclesPublicPlatoonUserRelations[0].Position4 + 1, | |||||
Position5: oneCirclesPublicPlatoonUserRelations[0].Position5 + 1, | |||||
Position6: oneCirclesPublicPlatoonUserRelations[0].Position6 + 1, | |||||
Position7: oneCirclesPublicPlatoonUserRelations[0].Position7 + 1, | |||||
Position8: oneCirclesPublicPlatoonUserRelations[0].Position8 + 1, | |||||
Level1: oneCirclesPublicPlatoonUserRelations[0].Level1, | |||||
Level2: oneCirclesPublicPlatoonUserRelations[0].Level2, | |||||
Level3: oneCirclesPublicPlatoonUserRelations[0].Level3, | |||||
Level4: oneCirclesPublicPlatoonUserRelations[0].Level4, | |||||
Level5: oneCirclesPublicPlatoonUserRelations[0].Level5, | |||||
Level6: oneCirclesPublicPlatoonUserRelations[0].Level6, | |||||
Level7: oneCirclesPublicPlatoonUserRelations[0].Level7, | |||||
Level8: oneCirclesPublicPlatoonUserRelations[0].Level8, | |||||
LevelTotal: oneCirclesPublicPlatoonUserRelations[0].LevelTotal, | |||||
} | |||||
return standardSmallPublicPlatoonRelation, fatherUid, nil | |||||
} | |||||
return | |||||
} | |||||
func oneCirclesGetPosition(m model.OneCirclesPublicPlatoonUserRelation, times int) (position, pid, level, fatherUid int, positionName, pidName, levelName, fatherUidName string) { | |||||
if times == 1 { | |||||
position = m.Position1 | |||||
positionName = "position1" | |||||
pid = m.Pid1 | |||||
pidName = "pid1" | |||||
level = m.Level1 | |||||
levelName = "level1" | |||||
fatherUid = m.FatherUid1 | |||||
fatherUidName = "father_uid1" | |||||
} | |||||
if times == 2 { | |||||
position = m.Position2 | |||||
positionName = "position2" | |||||
pid = m.Pid2 | |||||
pidName = "pid2" | |||||
level = m.Level2 | |||||
levelName = "level2" | |||||
fatherUid = m.FatherUid2 | |||||
fatherUidName = "father_uid2" | |||||
} | |||||
if times == 3 { | |||||
position = m.Position3 | |||||
positionName = "position3" | |||||
pid = m.Pid3 | |||||
pidName = "pid3" | |||||
level = m.Level3 | |||||
levelName = "level3" | |||||
fatherUid = m.FatherUid3 | |||||
fatherUidName = "father_uid3" | |||||
} | |||||
if times == 4 { | |||||
position = m.Position4 | |||||
positionName = "position4" | |||||
pid = m.Pid4 | |||||
pidName = "pid4" | |||||
level = m.Level4 | |||||
levelName = "level4" | |||||
fatherUid = m.FatherUid4 | |||||
fatherUidName = "father_uid4" | |||||
} | |||||
if times == 5 { | |||||
position = m.Position5 | |||||
positionName = "position5" | |||||
pid = m.Pid5 | |||||
pidName = "pid5" | |||||
level = m.Level5 | |||||
levelName = "level5" | |||||
fatherUid = m.FatherUid5 | |||||
fatherUidName = "father_uid5" | |||||
} | |||||
if times == 6 { | |||||
position = m.Position6 | |||||
positionName = "position6" | |||||
pid = m.Pid6 | |||||
pidName = "pid6" | |||||
level = m.Level6 | |||||
levelName = "level6" | |||||
fatherUid = m.FatherUid6 | |||||
fatherUidName = "father_uid6" | |||||
} | |||||
if times == 7 { | |||||
position = m.Position7 | |||||
positionName = "position7" | |||||
pid = m.Pid7 | |||||
pidName = "pid7" | |||||
level = m.Level7 | |||||
levelName = "level7" | |||||
fatherUid = m.FatherUid7 | |||||
fatherUidName = "father_uid7" | |||||
} | |||||
if times == 8 { | |||||
position = m.Position8 | |||||
positionName = "position8" | |||||
pid = m.Pid8 | |||||
pidName = "pid8" | |||||
level = m.Level8 | |||||
levelName = "level8" | |||||
fatherUid = m.FatherUid8 | |||||
fatherUidName = "father_uid8" | |||||
} | |||||
return | |||||
} | |||||
// oneCirclesSmallGetLevelForFirstPosition 返回当前等级的起始值 | |||||
func oneCirclesSmallGetLevelForFirstPosition(level, severalTimes int) (position int) { | |||||
position = position + 1 | |||||
for n := 0; n <= (level - 2); n++ { | |||||
position += int(math.Pow(float64(severalTimes), float64(n))) | |||||
} | |||||
return | |||||
} | |||||
//递归查找等级 | |||||
func oneCirclesSmallMakeSearchLevel(position *int, rows float64, times *float64) (level int) { | |||||
difference := *position - int(math.Pow(rows, *times)) | |||||
*times++ | |||||
if difference <= 0 { | |||||
return int(*times) | |||||
} else { | |||||
position = &difference | |||||
return oneCirclesSmallMakeSearchLevel(position, rows, times) | |||||
} | |||||
} | |||||
//查找归属父级id | |||||
func oneCirclesSmallMakeSearchPid(position int, row int) (pid int) { | |||||
divisionValue := (position - 1) / row | |||||
if divisionValue == 0 { | |||||
pid = 1 | |||||
return | |||||
} else { | |||||
if (divisionValue*row + 1) == position { | |||||
pid = divisionValue | |||||
return | |||||
} else { | |||||
pid = divisionValue + 1 | |||||
return | |||||
} | |||||
} | |||||
} | |||||
//查找当前位置下的第一个子集位置 | |||||
func oneCirclesSmallSearchPositionFirstSonPosition(position int, times int) (sonPosition int) { | |||||
sonPosition = (position * times) - (times - 2) | |||||
return | |||||
} | |||||
//查找当前位位置相当于父级的等级 | |||||
func oneCirclesSmallSearchPositionSonForLevel(fatherUid string, fatherPosition int) (level int) { | |||||
fatherUids := strings.Split(fatherUid, "-") | |||||
for key, item := range fatherUids { | |||||
if item == strconv.Itoa(fatherPosition) { | |||||
level = key + 1 | |||||
break | |||||
} | |||||
} | |||||
return | |||||
} | |||||
// OneCirclesSmallFindWaitForDealUsers 查询待处理的用户 | |||||
func OneCirclesSmallFindWaitForDealUsers(engine *xorm.Engine, page, pageSize int) (err error, resp []int) { | |||||
now := time.Now().Format("2006-01-02") | |||||
lists, err := db.OneCirclesPublicPlatoonUserRelationFindByParamsByPage(engine, map[string]interface{}{ | |||||
"key": "wait_for_settlement_date", | |||||
"value": now, | |||||
}, page, pageSize) | |||||
if err != nil { | |||||
return | |||||
} | |||||
for _, list := range *lists { | |||||
resp = append(resp, list.Uid) | |||||
} | |||||
return | |||||
} |
@@ -290,6 +290,9 @@ func Float64ToStrPrec4(f float64) string { | |||||
func Float64ToStrPrec10(f float64) string { | func Float64ToStrPrec10(f float64) string { | ||||
return strconv.FormatFloat(f, 'f', 10, 64) | return strconv.FormatFloat(f, 'f', 10, 64) | ||||
} | } | ||||
func Float64ToStrPrec8(f float64) string { | |||||
return strconv.FormatFloat(f, 'f', 8, 64) | |||||
} | |||||
func Float64ToStrPrec6(f float64) string { | func Float64ToStrPrec6(f float64) string { | ||||
return strconv.FormatFloat(f, 'f', 6, 64) | return strconv.FormatFloat(f, 'f', 6, 64) | ||||