@@ -0,0 +1,117 @@ | |||||
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" | |||||
) | |||||
// BatchSelectUserPublicPlatoonAmounts 批量查询数据 TODO::和下面的方法重复了,建议采用下面的 `UserPublicPlatoonAmountFindByParams` 方法 | |||||
func BatchSelectUserPublicPlatoonAmounts(Db *xorm.Engine, params map[string]interface{}) (*[]model.UserPublicPlatoonAmount, error) { | |||||
var UserPublicPlatoonAmountData []model.UserPublicPlatoonAmount | |||||
if err := Db.In(zhios_order_relate_utils.AnyToString(params["key"]), params["value"]). | |||||
Find(&UserPublicPlatoonAmountData); err != nil { | |||||
return nil, zhios_order_relate_logx.Warn(err) | |||||
} | |||||
return &UserPublicPlatoonAmountData, nil | |||||
} | |||||
// UserPublicPlatoonAmountInsert 插入单条数据 | |||||
func UserPublicPlatoonAmountInsert(Db *xorm.Engine, UserPublicPlatoonAmount *model.UserPublicPlatoonAmount) (int64, error) { | |||||
_, err := Db.InsertOne(UserPublicPlatoonAmount) | |||||
if err != nil { | |||||
return 0, err | |||||
} | |||||
return UserPublicPlatoonAmount.Id, nil | |||||
} | |||||
// BatchAddUserPublicPlatoonAmounts 批量新增数据 | |||||
func BatchAddUserPublicPlatoonAmounts(Db *xorm.Engine, UserPublicPlatoonAmountData []*model.UserPublicPlatoonAmount) (int64, error) { | |||||
affected, err := Db.Insert(UserPublicPlatoonAmountData) | |||||
if err != nil { | |||||
return 0, err | |||||
} | |||||
return affected, nil | |||||
} | |||||
func GetUserPublicPlatoonAmountCount(Db *xorm.Engine) int { | |||||
var UserPublicPlatoonAmount model.UserPublicPlatoonAmount | |||||
session := Db.Where("") | |||||
count, err := session.Count(&UserPublicPlatoonAmount) | |||||
if err != nil { | |||||
return 0 | |||||
} | |||||
return int(count) | |||||
} | |||||
// UserPublicPlatoonAmountDelete 删除记录 | |||||
func UserPublicPlatoonAmountDelete(Db *xorm.Engine, id interface{}) (int64, error) { | |||||
if reflect.TypeOf(id).Kind() == reflect.Slice { | |||||
return Db.In("id", id).Delete(model.UserPublicPlatoonAmount{}) | |||||
} else { | |||||
return Db.Where("id = ?", id).Delete(model.UserPublicPlatoonAmount{}) | |||||
} | |||||
} | |||||
// UserPublicPlatoonAmountUpdate 更新记录 | |||||
func UserPublicPlatoonAmountUpdate(session *xorm.Session, id interface{}, UserPublicPlatoonAmount *model.UserPublicPlatoonAmount, forceColums ...string) (int64, error) { | |||||
var ( | |||||
affected int64 | |||||
err error | |||||
) | |||||
if forceColums != nil { | |||||
affected, err = session.Where("id=?", id).Cols(forceColums...).Update(UserPublicPlatoonAmount) | |||||
} else { | |||||
affected, err = session.Where("id=?", id).Update(UserPublicPlatoonAmount) | |||||
} | |||||
if err != nil { | |||||
return 0, err | |||||
} | |||||
return affected, nil | |||||
} | |||||
// UserPublicPlatoonAmountGetOneByParams 通过传入的参数查询数据(单条) | |||||
func UserPublicPlatoonAmountGetOneByParams(Db *xorm.Engine, params map[string]interface{}) (*model.UserPublicPlatoonAmount, error) { | |||||
var m model.UserPublicPlatoonAmount | |||||
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 | |||||
} | |||||
// UserPublicPlatoonAmountFindByParams 通过传入的参数查询数据(多条) | |||||
func UserPublicPlatoonAmountFindByParams(Db *xorm.Engine, params map[string]interface{}) (*[]model.UserPublicPlatoonAmount, error) { | |||||
var m []model.UserPublicPlatoonAmount | |||||
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 | |||||
} | |||||
} | |||||
} |
@@ -58,15 +58,15 @@ func UserPublicPlatoonRelationDelete(Db *xorm.Engine, id interface{}) (int64, er | |||||
} | } | ||||
// UserPublicPlatoonRelationUpdate 更新记录 | // UserPublicPlatoonRelationUpdate 更新记录 | ||||
func UserPublicPlatoonRelationUpdate(Db *xorm.Engine, id interface{}, UserPublicPlatoonRelation *model.UserPublicPlatoonRelation, forceColums ...string) (int64, error) { | |||||
func UserPublicPlatoonRelationUpdate(session *xorm.Session, id interface{}, UserPublicPlatoonRelation *model.UserPublicPlatoonRelation, forceColums ...string) (int64, error) { | |||||
var ( | var ( | ||||
affected int64 | affected int64 | ||||
err error | err error | ||||
) | ) | ||||
if forceColums != nil { | if forceColums != nil { | ||||
affected, err = Db.Where("id=?", id).Cols(forceColums...).Update(UserPublicPlatoonRelation) | |||||
affected, err = session.Where("id=?", id).Cols(forceColums...).Update(UserPublicPlatoonRelation) | |||||
} else { | } else { | ||||
affected, err = Db.Where("id=?", id).Update(UserPublicPlatoonRelation) | |||||
affected, err = session.Where("id=?", id).Update(UserPublicPlatoonRelation) | |||||
} | } | ||||
if err != nil { | if err != nil { | ||||
return 0, err | return 0, err | ||||
@@ -115,3 +115,39 @@ func UserPublicPlatoonRelationFindByParams(Db *xorm.Engine, params map[string]in | |||||
} | } | ||||
} | } | ||||
func UserPublicPlatoonRelationFindByParamsByPage(Db *xorm.Engine, params map[string]interface{}, page, pageSize int) (*[]model.UserPublicPlatoonRelation, error) { | |||||
var m []model.UserPublicPlatoonRelation | |||||
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,117 @@ | |||||
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" | |||||
) | |||||
// BatchSelectUserPublicPlatoonSettlementRecordss 批量查询数据 TODO::和下面的方法重复了,建议采用下面的 `UserPublicPlatoonSettlementRecordsFindByParams` 方法 | |||||
func BatchSelectUserPublicPlatoonSettlementRecordss(Db *xorm.Engine, params map[string]interface{}) (*[]model.UserPublicPlatoonSettlementRecords, error) { | |||||
var UserPublicPlatoonSettlementRecordsData []model.UserPublicPlatoonSettlementRecords | |||||
if err := Db.In(zhios_order_relate_utils.AnyToString(params["key"]), params["value"]). | |||||
Find(&UserPublicPlatoonSettlementRecordsData); err != nil { | |||||
return nil, zhios_order_relate_logx.Warn(err) | |||||
} | |||||
return &UserPublicPlatoonSettlementRecordsData, nil | |||||
} | |||||
// UserPublicPlatoonSettlementRecordsInsert 插入单条数据 | |||||
func UserPublicPlatoonSettlementRecordsInsert(Db *xorm.Engine, UserPublicPlatoonSettlementRecords *model.UserPublicPlatoonSettlementRecords) (int64, error) { | |||||
_, err := Db.InsertOne(UserPublicPlatoonSettlementRecords) | |||||
if err != nil { | |||||
return 0, err | |||||
} | |||||
return UserPublicPlatoonSettlementRecords.Id, nil | |||||
} | |||||
// BatchAddUserPublicPlatoonSettlementRecordss 批量新增数据 | |||||
func BatchAddUserPublicPlatoonSettlementRecordss(session *xorm.Session, UserPublicPlatoonSettlementRecordsData []*model.UserPublicPlatoonSettlementRecords) (int64, error) { | |||||
affected, err := session.Insert(UserPublicPlatoonSettlementRecordsData) | |||||
if err != nil { | |||||
return 0, err | |||||
} | |||||
return affected, nil | |||||
} | |||||
func GetUserPublicPlatoonSettlementRecordsCount(Db *xorm.Engine) int { | |||||
var UserPublicPlatoonSettlementRecords model.UserPublicPlatoonSettlementRecords | |||||
session := Db.Where("") | |||||
count, err := session.Count(&UserPublicPlatoonSettlementRecords) | |||||
if err != nil { | |||||
return 0 | |||||
} | |||||
return int(count) | |||||
} | |||||
// UserPublicPlatoonSettlementRecordsDelete 删除记录 | |||||
func UserPublicPlatoonSettlementRecordsDelete(Db *xorm.Engine, id interface{}) (int64, error) { | |||||
if reflect.TypeOf(id).Kind() == reflect.Slice { | |||||
return Db.In("id", id).Delete(model.UserPublicPlatoonSettlementRecords{}) | |||||
} else { | |||||
return Db.Where("id = ?", id).Delete(model.UserPublicPlatoonSettlementRecords{}) | |||||
} | |||||
} | |||||
// UserPublicPlatoonSettlementRecordsUpdate 更新记录 | |||||
func UserPublicPlatoonSettlementRecordsUpdate(Db *xorm.Engine, id interface{}, UserPublicPlatoonSettlementRecords *model.UserPublicPlatoonSettlementRecords, forceColums ...string) (int64, error) { | |||||
var ( | |||||
affected int64 | |||||
err error | |||||
) | |||||
if forceColums != nil { | |||||
affected, err = Db.Where("id=?", id).Cols(forceColums...).Update(UserPublicPlatoonSettlementRecords) | |||||
} else { | |||||
affected, err = Db.Where("id=?", id).Update(UserPublicPlatoonSettlementRecords) | |||||
} | |||||
if err != nil { | |||||
return 0, err | |||||
} | |||||
return affected, nil | |||||
} | |||||
// UserPublicPlatoonSettlementRecordsGetOneByParams 通过传入的参数查询数据(单条) | |||||
func UserPublicPlatoonSettlementRecordsGetOneByParams(Db *xorm.Engine, params map[string]interface{}) (*model.UserPublicPlatoonSettlementRecords, error) { | |||||
var m model.UserPublicPlatoonSettlementRecords | |||||
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 | |||||
} | |||||
// UserPublicPlatoonSettlementRecordsFindByParams 通过传入的参数查询数据(多条) | |||||
func UserPublicPlatoonSettlementRecordsFindByParams(Db *xorm.Engine, params map[string]interface{}) (*[]model.UserPublicPlatoonSettlementRecords, error) { | |||||
var m []model.UserPublicPlatoonSettlementRecords | |||||
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,117 @@ | |||||
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" | |||||
) | |||||
// BatchSelectUserPublicPlatoonSystemPunishRecordss 批量查询数据 TODO::和下面的方法重复了,建议采用下面的 `UserPublicPlatoonSystemPunishRecordsFindByParams` 方法 | |||||
func BatchSelectUserPublicPlatoonSystemPunishRecordss(Db *xorm.Engine, params map[string]interface{}) (*[]model.UserPublicPlatoonSystemPunishRecords, error) { | |||||
var UserPublicPlatoonSystemPunishRecordsData []model.UserPublicPlatoonSystemPunishRecords | |||||
if err := Db.In(zhios_order_relate_utils.AnyToString(params["key"]), params["value"]). | |||||
Find(&UserPublicPlatoonSystemPunishRecordsData); err != nil { | |||||
return nil, zhios_order_relate_logx.Warn(err) | |||||
} | |||||
return &UserPublicPlatoonSystemPunishRecordsData, nil | |||||
} | |||||
// UserPublicPlatoonSystemPunishRecordsInsert 插入单条数据 | |||||
func UserPublicPlatoonSystemPunishRecordsInsert(session *xorm.Session, UserPublicPlatoonSystemPunishRecords *model.UserPublicPlatoonSystemPunishRecords) (int64, error) { | |||||
_, err := session.InsertOne(UserPublicPlatoonSystemPunishRecords) | |||||
if err != nil { | |||||
return 0, err | |||||
} | |||||
return UserPublicPlatoonSystemPunishRecords.Id, nil | |||||
} | |||||
// BatchAddUserPublicPlatoonSystemPunishRecords 批量新增数据 | |||||
func BatchAddUserPublicPlatoonSystemPunishRecords(session *xorm.Session, UserPublicPlatoonSystemPunishRecordsData []*model.UserPublicPlatoonSystemPunishRecords) (int64, error) { | |||||
affected, err := session.Insert(UserPublicPlatoonSystemPunishRecordsData) | |||||
if err != nil { | |||||
return 0, err | |||||
} | |||||
return affected, nil | |||||
} | |||||
func GetUserPublicPlatoonSystemPunishRecordsCount(Db *xorm.Engine) int { | |||||
var UserPublicPlatoonSystemPunishRecords model.UserPublicPlatoonSystemPunishRecords | |||||
session := Db.Where("") | |||||
count, err := session.Count(&UserPublicPlatoonSystemPunishRecords) | |||||
if err != nil { | |||||
return 0 | |||||
} | |||||
return int(count) | |||||
} | |||||
// UserPublicPlatoonSystemPunishRecordsDelete 删除记录 | |||||
func UserPublicPlatoonSystemPunishRecordsDelete(Db *xorm.Engine, id interface{}) (int64, error) { | |||||
if reflect.TypeOf(id).Kind() == reflect.Slice { | |||||
return Db.In("id", id).Delete(model.UserPublicPlatoonSystemPunishRecords{}) | |||||
} else { | |||||
return Db.Where("id = ?", id).Delete(model.UserPublicPlatoonSystemPunishRecords{}) | |||||
} | |||||
} | |||||
// UserPublicPlatoonSystemPunishRecordsUpdate 更新记录 | |||||
func UserPublicPlatoonSystemPunishRecordsUpdate(Db *xorm.Engine, id interface{}, UserPublicPlatoonSystemPunishRecords *model.UserPublicPlatoonSystemPunishRecords, forceColums ...string) (int64, error) { | |||||
var ( | |||||
affected int64 | |||||
err error | |||||
) | |||||
if forceColums != nil { | |||||
affected, err = Db.Where("id=?", id).Cols(forceColums...).Update(UserPublicPlatoonSystemPunishRecords) | |||||
} else { | |||||
affected, err = Db.Where("id=?", id).Update(UserPublicPlatoonSystemPunishRecords) | |||||
} | |||||
if err != nil { | |||||
return 0, err | |||||
} | |||||
return affected, nil | |||||
} | |||||
// UserPublicPlatoonSystemPunishRecordsGetOneByParams 通过传入的参数查询数据(单条) | |||||
func UserPublicPlatoonSystemPunishRecordsGetOneByParams(Db *xorm.Engine, params map[string]interface{}) (*model.UserPublicPlatoonSystemPunishRecords, error) { | |||||
var m model.UserPublicPlatoonSystemPunishRecords | |||||
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 | |||||
} | |||||
// UserPublicPlatoonSystemPunishRecordsFindByParams 通过传入的参数查询数据(多条) | |||||
func UserPublicPlatoonSystemPunishRecordsFindByParams(Db *xorm.Engine, params map[string]interface{}) (*[]model.UserPublicPlatoonSystemPunishRecords, error) { | |||||
var m []model.UserPublicPlatoonSystemPunishRecords | |||||
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,8 @@ | |||||
package model | |||||
type UserPublicPlatoonAmount struct { | |||||
Id int64 `json:"id" xorm:"pk autoincr BIGINT(20)"` | |||||
Uid int `json:"uid" xorm:"unique(idx_uid_coin_id) INT(11)"` | |||||
CoinId int `json:"coin_id" xorm:"unique(idx_uid_coin_id) INT(11)"` | |||||
Amount string `json:"amount" xorm:"DECIMAL(16,6)"` | |||||
} |
@@ -5,15 +5,17 @@ import ( | |||||
) | ) | ||||
type UserPublicPlatoonRelation struct { | type UserPublicPlatoonRelation struct { | ||||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||||
Uid int `json:"uid" xorm:"not null default 0 comment('用户id') unique INT(11)"` | |||||
FatherUid string `json:"father_uid" xorm:"not null default '' comment('父级id(123456-563464-438384)') index VARCHAR(100)"` | |||||
Pid int `json:"pid" xorm:"not null default 0 comment('父级id') INT(11)"` | |||||
RecommendUid int `json:"recommend_uid" xorm:"not null default 0 comment('推荐人id') INT(11)"` | |||||
Level int `json:"level" xorm:"not null default 1 comment('等级(整个系统)') INT(11)"` | |||||
Position int `json:"position" xorm:"not null default 1 comment('当前等级上位置') INT(11)"` | |||||
UniqueIdentifier string `json:"unique_identifier" xorm:"not null default '' comment('唯一标识符(uid-推荐人id-等级-位置)') unique CHAR(100)"` | |||||
ReturnCommissionNum int `json:"return_commission_num" xorm:"not null default 0 comment('返佣次数') INT(11)"` | |||||
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"` | |||||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||||
Uid int `json:"uid" xorm:"not null default 0 comment('用户id(若为-1,则代表等待新用户填充)') unique INT(11)"` | |||||
FatherUid string `json:"father_uid" xorm:"not null default '' comment('父级id(123456-563464-438384)') index VARCHAR(100)"` | |||||
Pid int `json:"pid" xorm:"not null default 0 comment('父级id') INT(11)"` | |||||
RecommendUid int `json:"recommend_uid" xorm:"not null default 0 comment('推荐人id') INT(11)"` | |||||
Level int `json:"level" xorm:"not null default 1 comment('等级(整个系统)') INT(11)"` | |||||
Position int `json:"position" xorm:"not null default 1 comment('位置') unique INT(11)"` | |||||
UniqueIdentifier string `json:"unique_identifier" xorm:"not null default '' comment('唯一标识符(父级id-uid-等级-位置)') unique CHAR(100)"` | |||||
ReturnCommissionNum int `json:"return_commission_num" xorm:"not null default 0 comment('返佣次数') INT(11)"` | |||||
JoinAt time.Time `json:"join_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('加入公排时间') DATETIME"` | |||||
WaitForSettlementDate string `json:"wait_for_settlement_date" xorm:"not null default '' comment('待结算时间(0000-00)') CHAR(50)"` | |||||
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,17 @@ | |||||
package model | |||||
import ( | |||||
"time" | |||||
) | |||||
type UserPublicPlatoonSettlementRecords struct { | |||||
Id int64 `json:"id" xorm:"pk autoincr BIGINT(20)"` | |||||
Uid int `json:"uid" xorm:"not null comment('用户id') index INT(11)"` | |||||
CoinId int `json:"coin_id" xorm:"not null default 0 comment('虚拟币id(0为金额)') INT(11)"` | |||||
Amount string `json:"amount" xorm:"not null default '' comment('结算金额') VARCHAR(50)"` | |||||
Title string `json:"title" xorm:"comment('标题') VARCHAR(255)"` | |||||
Date string `json:"date" xorm:"not null default '' comment('结算日期(0000-00)') VARCHAR(50)"` | |||||
Kind int `json:"kind" xorm:"not null default 1 comment('结算种类(1:转入用户余额 2:清零)') TINYINT(1)"` | |||||
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,17 @@ | |||||
package model | |||||
import ( | |||||
"time" | |||||
) | |||||
type UserPublicPlatoonSystemPunishRecords struct { | |||||
Id int64 `json:"id" xorm:"pk autoincr BIGINT(20)"` | |||||
Uid int `json:"uid" xorm:"not null comment('用户id') index INT(11)"` | |||||
OldPostion int `json:"old_postion" xorm:"not null default 0 comment('位置(旧)') INT(11)"` | |||||
NewPostion int `json:"new_postion" xorm:"not null default 0 comment('位置(新)') INT(11)"` | |||||
Date string `json:"date" xorm:"not null default '' comment('日期(0000-00)') VARCHAR(50)"` | |||||
Title string `json:"title" xorm:"not null default '' comment('标题') VARCHAR(100)"` | |||||
Reason string `json:"reason" xorm:"not null default '' comment('原因') VARCHAR(255)"` | |||||
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"` | |||||
} |
@@ -73,17 +73,29 @@ func BatchGetPublicPlatoonRelateCommissionByOrder(engine *xorm.Engine, masterId | |||||
if userPublicPlatoonRelation == nil { | if userPublicPlatoonRelation == nil { | ||||
return nil, errors.New("未查询到公排关系记录") | return nil, errors.New("未查询到公排关系记录") | ||||
} | } | ||||
fatherUids := strings.Split(userPublicPlatoonRelation.FatherUid, "-") | |||||
fatherPositions := strings.Split(userPublicPlatoonRelation.FatherUid, "-") | |||||
var fatherPosition string | |||||
userPublicPlatoonRelation.ReturnCommissionNum++ | userPublicPlatoonRelation.ReturnCommissionNum++ | ||||
remainder := (userPublicPlatoonRelation.ReturnCommissionNum) % userPublicPlatoonSetting.SeveralRows | remainder := (userPublicPlatoonRelation.ReturnCommissionNum) % userPublicPlatoonSetting.SeveralRows | ||||
if remainder == 0 { | if remainder == 0 { | ||||
nowBenefitUid = fatherUids[userPublicPlatoonSetting.SeveralRows-1] | |||||
fatherPosition = fatherPositions[userPublicPlatoonSetting.SeveralRows-1] | |||||
} else { | } else { | ||||
nowBenefitUid = fatherUids[remainder-1] | |||||
fatherPosition = fatherPositions[remainder-1] | |||||
} | } | ||||
nowBenefitUsers, err := db.UserPublicPlatoonRelationGetOneByParams(engine, map[string]interface{}{ | |||||
"key": "position", | |||||
"value": fatherPosition, | |||||
}) | |||||
if err != nil { | |||||
return nil, err | |||||
} | |||||
if nowBenefitUsers == nil { | |||||
return nil, errors.New("未查询到父级公排关系记录") | |||||
} | |||||
nowBenefitUid = zhios_order_relate_utils.AnyToString(nowBenefitUsers.Uid) | |||||
//TODO::更新 公排关系记录 中 `return_commission_num` | //TODO::更新 公排关系记录 中 `return_commission_num` | ||||
affected, err := db.UserPublicPlatoonRelationUpdate(engine, userPublicPlatoonRelation.Id, userPublicPlatoonRelation, "return_commission_num") | |||||
affected, err := db.UserPublicPlatoonRelationUpdate(engine.NewSession(), userPublicPlatoonRelation.Id, userPublicPlatoonRelation, "return_commission_num") | |||||
if err != nil { | if err != nil { | ||||
return nil, err | return nil, err | ||||
} | } | ||||
@@ -116,6 +128,28 @@ func AddPublicPlatoonRelateCommission(engine *xorm.Engine, masterId string, AddP | |||||
return nil, err | return nil, err | ||||
} | } | ||||
for _, param := range AddPublicPlatoonRelateCommissionReqList { | for _, param := range AddPublicPlatoonRelateCommissionReqList { | ||||
//TODO::判断是否有uid为-1 (代表等待新用户填充) 的记录 | |||||
userPublicPlatoonRelation, err := db.UserPublicPlatoonRelationGetOneByParams(engine, map[string]interface{}{ | |||||
"key": "uid", | |||||
"value": -1, | |||||
}) | |||||
if err != nil { | |||||
return nil, err | |||||
} | |||||
if userPublicPlatoonRelation != nil { | |||||
userPublicPlatoonRelation.Uid = zhios_order_relate_utils.StrToInt(param.Uid) | |||||
updateAffected, err := db.UserPublicPlatoonRelationUpdate(engine.NewSession(), userPublicPlatoonRelation.Id, userPublicPlatoonRelation) | |||||
if err != nil { | |||||
return nil, err | |||||
} | |||||
if updateAffected == 0 { | |||||
err = errors.New("更新 user_public_platoon_relation 记录失败") | |||||
return nil, err | |||||
} else { | |||||
resp[param.Uid] = userPublicPlatoonRelation | |||||
} | |||||
continue | |||||
} | |||||
res, err := publicPlatoon(engine, zhios_order_relate_utils.StrToInt(param.Uid), zhios_order_relate_utils.StrToInt(param.RecommendUid), *userPublicPlatoonSetting) | res, err := publicPlatoon(engine, zhios_order_relate_utils.StrToInt(param.Uid), zhios_order_relate_utils.StrToInt(param.RecommendUid), *userPublicPlatoonSetting) | ||||
if err != nil { | if err != nil { | ||||
return nil, err | return nil, err | ||||
@@ -154,9 +188,14 @@ func publicPlatoon(engine *xorm.Engine, uid, recommendUid int, userPublicPlatoon | |||||
var fatherUid string | var fatherUid string | ||||
if m1.FatherUid == "" { | if m1.FatherUid == "" { | ||||
//TODO::顶级 | //TODO::顶级 | ||||
fatherUid = zhios_order_relate_utils.IntToStr(m1.Uid) | |||||
fatherUid = zhios_order_relate_utils.IntToStr(m1.Position) | |||||
} else { | } else { | ||||
fatherUid = zhios_order_relate_utils.IntToStr(m1.Uid) + "-" + m1.FatherUid | |||||
fatherUids := strings.Split(m1.FatherUid, "-") | |||||
if len(fatherUids) > userPublicPlatoonSetting.SeveralRows { | |||||
fatherUid = zhios_order_relate_utils.IntToStr(m1.Position) + "-" + strings.Join(fatherUids[0:userPublicPlatoonSetting.SeveralRows:len(fatherUids)], "-") | |||||
} else { | |||||
fatherUid = zhios_order_relate_utils.IntToStr(m1.Position) + "-" + m1.FatherUid | |||||
} | |||||
} | } | ||||
//唯一标识符(父级id-uid-等级-位置) | //唯一标识符(父级id-uid-等级-位置) | ||||
@@ -171,6 +210,8 @@ func publicPlatoon(engine *xorm.Engine, uid, recommendUid int, userPublicPlatoon | |||||
userPublicPlatoonRelation.Level = int(level) | userPublicPlatoonRelation.Level = int(level) | ||||
userPublicPlatoonRelation.Position = position | userPublicPlatoonRelation.Position = position | ||||
userPublicPlatoonRelation.UniqueIdentifier = uniqueIdentifier | userPublicPlatoonRelation.UniqueIdentifier = uniqueIdentifier | ||||
userPublicPlatoonRelation.WaitForSettlementDate = now.AddDate(0, 0, 30).Format("2006-01-02") | |||||
userPublicPlatoonRelation.JoinAt = now | |||||
userPublicPlatoonRelation.CreateAt = now | userPublicPlatoonRelation.CreateAt = now | ||||
userPublicPlatoonRelation.UpdateAt = now | userPublicPlatoonRelation.UpdateAt = now | ||||
_, err := db.UserPublicPlatoonRelationInsert(engine, &userPublicPlatoonRelation) | _, err := db.UserPublicPlatoonRelationInsert(engine, &userPublicPlatoonRelation) | ||||
@@ -208,3 +249,174 @@ func makeSearchPid(position int, row int) (pid int) { | |||||
} | } | ||||
} | } | ||||
} | } | ||||
// FindWaitForDealUsers 查询待处理的用户 | |||||
func FindWaitForDealUsers(engine *xorm.Engine, page, pageSize int) (err error, resp []int) { | |||||
now := time.Now().Format("2006-01-02") | |||||
lists, err := db.UserPublicPlatoonRelationFindByParamsByPage(engine, map[string]interface{}{ | |||||
"wait_for_settlement_date": now, | |||||
}, page, pageSize) | |||||
if err != nil { | |||||
return | |||||
} | |||||
for _, list := range *lists { | |||||
resp = append(resp, list.Uid) | |||||
} | |||||
return | |||||
} | |||||
// UpdateWaitForSettlementDate 改变 `wait_for_settlement_date` 待结算时间 | |||||
func UpdateWaitForSettlementDate(engine *xorm.Engine, userIds []string) (err error) { | |||||
//Todo:: 将 user_public_platoon_relation 中 wait_for_settlement_date 设置为 30天后 | |||||
sql := "update user_public_platoon_amount set wait_for_settlement_date = ? where uid in (" + strings.Join(userIds, ",") + ")" | |||||
waitForSettlementDate := time.Now().AddDate(0, 0, 30).Format("2006-01-02") | |||||
_, err = engine.Exec(sql, waitForSettlementDate) | |||||
if err != nil { | |||||
return | |||||
} | |||||
return | |||||
} | |||||
// DealCommonWealthReward 处理共富奖励 | |||||
func DealCommonWealthReward(engine *xorm.Engine, uid int, isCompleteReward bool) (err error, resp []map[string]string) { | |||||
session := engine.NewSession() | |||||
defer func() { | |||||
session.Close() | |||||
if err := recover(); err != nil { | |||||
_ = zhios_order_relate_logx.Error(err) | |||||
} | |||||
}() | |||||
//1、查询出 `user_public_platoon_amount` 中相关记录 | |||||
params, err := db.UserPublicPlatoonAmountFindByParams(engine, map[string]interface{}{ | |||||
"key": "uid", | |||||
"value": uid, | |||||
}) | |||||
if err != nil { | |||||
_ = session.Rollback() | |||||
return | |||||
} | |||||
//2、完成共富奖励(插入 user_public_platoon_settlement_records 记录) && 构造返回数据 | |||||
var userPublicPlatoonSettlementRecords []*model.UserPublicPlatoonSettlementRecords | |||||
now := time.Now() | |||||
for _, param := range *params { | |||||
var userPublicPlatoonSettlementRecord = model.UserPublicPlatoonSettlementRecords{ | |||||
Uid: param.Uid, | |||||
CoinId: param.CoinId, | |||||
Amount: param.Amount, | |||||
Title: "结算共富奖励", | |||||
Date: now.AddDate(0, 0, 30).Format("2006-01-02"), | |||||
CreateAt: now, | |||||
UpdateAt: now, | |||||
} | |||||
if isCompleteReward { | |||||
userPublicPlatoonSettlementRecord.Kind = 1 | |||||
resp = append(resp, map[string]string{ | |||||
zhios_order_relate_utils.AnyToString(param.CoinId): param.Amount, | |||||
}) | |||||
} else { | |||||
userPublicPlatoonSettlementRecord.Kind = 2 | |||||
} | |||||
if zhios_order_relate_utils.StrToFloat64(userPublicPlatoonSettlementRecord.Amount) > 0 { | |||||
userPublicPlatoonSettlementRecords = append(userPublicPlatoonSettlementRecords, &userPublicPlatoonSettlementRecord) | |||||
} | |||||
} | |||||
affected, err := db.BatchAddUserPublicPlatoonSettlementRecordss(session, userPublicPlatoonSettlementRecords) | |||||
if err != nil { | |||||
_ = session.Rollback() | |||||
return | |||||
} | |||||
if affected == 0 { | |||||
err = errors.New("插入 user_public_platoon_settlement_records 记录失败") | |||||
_ = session.Rollback() | |||||
return | |||||
} | |||||
//3、将 user_public_platoon_amount 相关记录的 amount 置 0 | |||||
sql := "update user_public_platoon_amount set amount = ? where uid = ?" | |||||
_, err = session.Exec(sql, 0, uid) | |||||
if err != nil { | |||||
_ = session.Rollback() | |||||
return | |||||
} | |||||
err = session.Commit() | |||||
return | |||||
} | |||||
// DealCommonWealthPunish 处理共富处罚 | |||||
func DealCommonWealthPunish(engine *xorm.Engine, uid int, reason string) (err error, resp []map[string]string) { | |||||
session := engine.NewSession() | |||||
defer func() { | |||||
session.Close() | |||||
if err := recover(); err != nil { | |||||
_ = zhios_order_relate_logx.Error(err) | |||||
} | |||||
}() | |||||
//1、查找 `user_public_platoon_setting` 基础设置 | |||||
userPublicPlatoonSetting, err := db.UserPublicPlatoonSettingGetOneByParams(engine, map[string]interface{}{ | |||||
"key": "is_open", | |||||
"value": 1, | |||||
}) | |||||
if err != nil { | |||||
_ = session.Rollback() | |||||
return | |||||
} | |||||
//2、查询出 `user_public_platoon_relation` 中相关记录 && 将该记录的uid置为 -1 | |||||
params, err := db.UserPublicPlatoonRelationGetOneByParams(engine, map[string]interface{}{ | |||||
"key": "uid", | |||||
"value": uid, | |||||
}) | |||||
if err != nil { | |||||
_ = session.Rollback() | |||||
return | |||||
} | |||||
if params == nil { | |||||
err = errors.New("未查询到公排关系记录") | |||||
_ = session.Rollback() | |||||
} | |||||
params.Uid = -1 | |||||
updateAffected, err := db.UserPublicPlatoonRelationUpdate(session, params.Id, params) | |||||
if err != nil { | |||||
_ = session.Rollback() | |||||
return | |||||
} | |||||
if updateAffected == 0 { | |||||
err = errors.New("更新 user_public_platoon_relation 记录失败") | |||||
_ = session.Rollback() | |||||
return | |||||
} | |||||
//3、新增一条 `user_public_platoon_relation` 记录 | |||||
res, err := publicPlatoon(engine, params.Uid, params.RecommendUid, *userPublicPlatoonSetting) | |||||
if err != nil { | |||||
_ = session.Rollback() | |||||
return | |||||
} | |||||
//4、新增一条 `user_public_platoon_system_punish_records` 记录 | |||||
now := time.Now() | |||||
insertAffected, err := db.UserPublicPlatoonSystemPunishRecordsInsert(session, &model.UserPublicPlatoonSystemPunishRecords{ | |||||
Uid: params.Uid, | |||||
OldPostion: params.Position, | |||||
NewPostion: res.Position, | |||||
Date: now.AddDate(0, 0, 30).Format("2006-01-02"), | |||||
Title: "共富收益-系统处罚记录", | |||||
Reason: reason, | |||||
CreateAt: now, | |||||
UpdateAt: now, | |||||
}) | |||||
if err != nil { | |||||
_ = session.Rollback() | |||||
return | |||||
} | |||||
if insertAffected == 0 { | |||||
err = errors.New("新增 user_public_platoon_system_punish_records 记录失败") | |||||
_ = session.Rollback() | |||||
return | |||||
} | |||||
err = session.Commit() | |||||
return | |||||
} |
@@ -276,6 +276,15 @@ func Float64ToStr(f float64) string { | |||||
func Float64ToStrPrec1(f float64) string { | func Float64ToStrPrec1(f float64) string { | ||||
return strconv.FormatFloat(f, 'f', 1, 64) | return strconv.FormatFloat(f, 'f', 1, 64) | ||||
} | } | ||||
func Float64ToStrPrec4(f float64) string { | |||||
return strconv.FormatFloat(f, 'f', 4, 64) | |||||
} | |||||
func Float64ToStrPrec6(f float64) string { | |||||
return strconv.FormatFloat(f, 'f', 6, 64) | |||||
} | |||||
func Float64ToStrByPrec(f float64, prec int) string { | func Float64ToStrByPrec(f float64, prec int) string { | ||||
return strconv.FormatFloat(f, 'f', prec, 64) | return strconv.FormatFloat(f, 'f', prec, 64) | ||||
} | } | ||||