9
This commit is contained in:
+19
-127
@@ -236,26 +236,29 @@ if (!function_exists('abort')) {
|
||||
if (!function_exists('idEncode')) {
|
||||
function idEncode($id = '')
|
||||
{
|
||||
return \isszz\hashids\facade\Hashids::mode('bilibili')->encode($id);
|
||||
if($id<=100234){return $id.'';}
|
||||
return id_encode($id);
|
||||
}
|
||||
}
|
||||
if (!function_exists('idDecode')) {
|
||||
function idDecode($id = '')
|
||||
{
|
||||
return \isszz\hashids\facade\Hashids::mode('bilibili')->decode($id);
|
||||
$_id= intval($id);
|
||||
if($_id == $id){return $id;}
|
||||
return id_decode($id);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 生成可逆的邀请码(8位,含校验位)
|
||||
* @param int $user_id 用户ID(需≥1000)
|
||||
* @param int $id 用户ID(需≥1000)
|
||||
* @return string 大写字母+数字组合
|
||||
*/
|
||||
|
||||
if (!function_exists('base62Encode')) {
|
||||
function base62Encode(int $user_id,$secret='your_secret_salt'): string {
|
||||
function base62Encode(int $id,$secret='your_secret_salt'): string {
|
||||
// 添加校验位(防止篡改)
|
||||
$hash = crc32($user_id . $secret) % 1000;
|
||||
$code_num = $user_id * 1000 + $hash;
|
||||
$hash = crc32($id . $secret) % 1000;
|
||||
$code_num = $id * 1000 + $hash;
|
||||
|
||||
// Base62 编码(0-9A-Za-z)
|
||||
$base62 = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
||||
@@ -271,7 +274,7 @@ if (!function_exists('base62Encode')) {
|
||||
}
|
||||
/**
|
||||
* 从邀请码解析用户ID
|
||||
* @return int|false 成功返回user_id,失败返回false
|
||||
* @return int|false 成功返回id,失败返回false
|
||||
*/
|
||||
if (!function_exists('base62Decode')) {
|
||||
function base62Decode(string $code,$secret='your_secret_salt'): int|false {
|
||||
@@ -286,15 +289,15 @@ if (!function_exists('base62Decode')) {
|
||||
}
|
||||
|
||||
// 分离校验位
|
||||
$user_id = (int)($code_num / 1000);
|
||||
$id = (int)($code_num / 1000);
|
||||
$hash = $code_num % 1000;
|
||||
|
||||
// 校验
|
||||
if (crc32($user_id . $secret) % 1000 != $hash) {
|
||||
if (crc32($id . $secret) % 1000 != $hash) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $user_id;
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -660,26 +663,6 @@ if (!function_exists('parent_info')) {
|
||||
return $info;
|
||||
}
|
||||
}
|
||||
if (!function_exists('get_user_level')) {
|
||||
function get_user_level($user_id,$performance_small=null)
|
||||
{
|
||||
if (!$user_id) {
|
||||
return 0;
|
||||
}
|
||||
if(is_null($performance_small)){
|
||||
$performance= get_performance($user_id);
|
||||
$performance_small = $performance[1];
|
||||
}
|
||||
$user_level_rules = Config('site.user_level_rules');
|
||||
$level = 0;
|
||||
foreach ($user_level_rules as $_level => $score) {
|
||||
if($performance_small>$score){
|
||||
$level = $_level;
|
||||
}
|
||||
}
|
||||
return $level;
|
||||
}
|
||||
}
|
||||
|
||||
if(!function_exists('datetime')){
|
||||
function datetime($timestamp=0,$format='Y-m-d H:i:s'){
|
||||
@@ -700,20 +683,6 @@ if(!function_exists('datetime')){
|
||||
return $timestamp;
|
||||
}
|
||||
}
|
||||
if(!function_exists('get_performance')){
|
||||
function get_performance($user_id){
|
||||
$performance_list = \app\model\UserTeam::alias('ut')
|
||||
->join('user_extend ue', 'ut.descendant_id = ue.user_id')
|
||||
->where('ut.ancestor_id', $user_id)
|
||||
->order('ue.sales desc')->column('ue.sales');
|
||||
if(empty($performance_list)){
|
||||
$performance_list = [0,0];
|
||||
}
|
||||
|
||||
return [array_shift($performance_list), array_sum($performance_list)];
|
||||
|
||||
}
|
||||
}
|
||||
if(!function_exists('log_alert')){
|
||||
function log_alert($data='',$channel='default'){
|
||||
if(!is_string($data)){
|
||||
@@ -743,84 +712,6 @@ if(!function_exists('enum_dir')){
|
||||
return $list ;
|
||||
}
|
||||
}
|
||||
if(!function_exists('jicha')){
|
||||
function jicha($current_user_id,$amount,$reward_arr=[]){
|
||||
$distributed_users = [];
|
||||
$distributed_rate = 0; // 已分配的累计比例
|
||||
$last_commissioned_level = 0; // 上一次成功分佣的用户角色等级(role_id)
|
||||
|
||||
//$reward_arr = [0,0.02,0.04,0.06,0.08,0.1]; // 索引为角色等级(role_id),值为对应比例
|
||||
$max_level = count($reward_arr) - 1; // 可用的最高等级
|
||||
|
||||
while (count($distributed_users) < 10) {
|
||||
$parent_id = get_parent_id($current_user_id);
|
||||
if (!$parent_id) {
|
||||
// cp(sprintf("用户ID:%s\t级别:%s\t父级:%s\t%s\t%s\n\n",
|
||||
// $parent_id.'',
|
||||
// '-',
|
||||
// '-',
|
||||
// "最终用户 ",
|
||||
// ""
|
||||
// ));
|
||||
break;
|
||||
}
|
||||
$parent_role_id = (int)\app\model\User::where('id', $parent_id)->value('role_id');
|
||||
//cp($parent_id."\t".$parent_role_id."\t".$last_commissioned_level);
|
||||
if ($parent_role_id > 5) {
|
||||
// cp(sprintf("用户ID:%s\t级别:%s\t父级:%s\t%s\t%s\n\n",
|
||||
// $parent_id,
|
||||
// $parent_role_id,
|
||||
// '-',
|
||||
// "用户级别异常",
|
||||
// ""
|
||||
// ));
|
||||
break;
|
||||
}
|
||||
|
||||
// 仅当上级角色等级高于上一次成功分佣的等级时才考虑分配
|
||||
if ($parent_role_id > $last_commissioned_level) {
|
||||
$idx = $parent_role_id;
|
||||
if ($idx > $max_level) { // 超出定义范围则使用最高档
|
||||
$idx = $max_level;
|
||||
}
|
||||
$current_rate = $reward_arr[$idx];
|
||||
$available_rate = bcsub($current_rate, $distributed_rate, 4);
|
||||
|
||||
if (bccomp($available_rate, 0, 6) === 1) { // available_rate > 0
|
||||
$commission = bcmul($available_rate, $amount, 4);
|
||||
$distributed_rate += $available_rate;
|
||||
$last_commissioned_level = $parent_role_id;
|
||||
$distributed_users[] = [
|
||||
'user_id' => $parent_id,
|
||||
'role_id' => $parent_role_id,
|
||||
'rate' => $available_rate,
|
||||
'amount' => $commission
|
||||
];
|
||||
} else {
|
||||
// 可分配比例<=0,停止继续查找
|
||||
// cp(sprintf("用户ID:%s\t级别:%s\t父级:%s\t%s\t%s\n\n",
|
||||
// $parent_id,
|
||||
// $parent_role_id,
|
||||
// '-',
|
||||
// "可分配比例不足,结束",
|
||||
// "已分配比例:".$distributed_rate
|
||||
// ));
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// cp(sprintf("用户ID:%s\t级别:%s\t父级:%s\t%s\t%s\n\n",
|
||||
// $parent_id,
|
||||
// $parent_role_id,
|
||||
// '-',
|
||||
// "用户等级不够高",
|
||||
// "最后分佣等级:".$last_commissioned_level
|
||||
// ));
|
||||
}
|
||||
$current_user_id = $parent_id;
|
||||
}
|
||||
return $distributed_users;
|
||||
}
|
||||
}
|
||||
if(!function_exists('generateShortUniqueID')){
|
||||
function generateShortUniqueID($length = 8) {
|
||||
// 生成指定长度的随机字节,转为 Base64 编码并去除不必要字符
|
||||
@@ -836,14 +727,15 @@ if(!function_exists('get_user_rights')){
|
||||
// 'max_group_join_count' => 999999999999,
|
||||
// 'max_gourp_create_count' => 999999999999
|
||||
// ];
|
||||
$user_id = idDecode($user_id);
|
||||
$key = 'user_rights_'.$user_id;
|
||||
$result = cache($key);
|
||||
if(!$result){
|
||||
log_alert(\think\facade\Db::name('user_role')->alias('ur')
|
||||
->join('user u','ur.id = u.role_id')
|
||||
->where('u.id',$user_id)
|
||||
->field('ur.name,ur.max_send_msg_count,ur.max_friend_count,ur.max_group_join_count,ur.max_gourp_create_count')
|
||||
->buildSql());
|
||||
// log_alert(\think\facade\Db::name('user_role')->alias('ur')
|
||||
// ->join('user u','ur.id = u.role_id')
|
||||
// ->where('u.id',$user_id)
|
||||
// ->field('ur.name,ur.max_send_msg_count,ur.max_friend_count,ur.max_group_join_count,ur.max_gourp_create_count')
|
||||
// ->buildSql());
|
||||
$result = \think\facade\Db::name('user_role')->alias('ur')
|
||||
->join('user u','ur.id = u.role_id')
|
||||
->where('u.id',$user_id)
|
||||
|
||||
Reference in New Issue
Block a user