diff --git a/app/admin/controller/Base.php b/app/admin/controller/Base.php index e7687ed..614f079 100755 --- a/app/admin/controller/Base.php +++ b/app/admin/controller/Base.php @@ -245,4 +245,29 @@ class Base extends MyController return $data; } + /** + * 将用户UID转换为真实用户ID + * + * @param string $uid 用户UID + * @return int|string 真实用户ID + */ + protected function convertUidToUserId($uid) + { + if (empty($uid)) { + return $uid; + } + + // 检查是否为UID格式 + $user_config = getConfig('user_config'); + if (!empty($user_config) && isset($user_config['uid_type']) && $user_config['uid_type'] != 0) { + // 如果配置了非真实ID的UID类型,需要根据UID查找用户ID + $real_user_id = \app\common\model\User::where('uid', '=', $uid)->value('id'); + if ($real_user_id) { + return $real_user_id; + } + } + + return $uid; // 如果未找到或未配置,返回原值 + } + } diff --git a/app/admin/controller/Config.php b/app/admin/controller/Config.php index 1ef270d..7ce89fc 100755 --- a/app/admin/controller/Config.php +++ b/app/admin/controller/Config.php @@ -58,8 +58,10 @@ class Config extends Base public function systemconfig(Request $request) { $config = getConfig('systemconfig'); + $user_config = getConfig('user_config'); View::assign("key", "systemconfig"); View::assign("data", $config); + View::assign("user_config", $user_config); return View::fetch('Config/systemconfig'); } diff --git a/app/admin/controller/Order.php b/app/admin/controller/Order.php index d1a6e8c..acaa3c0 100755 --- a/app/admin/controller/Order.php +++ b/app/admin/controller/Order.php @@ -38,6 +38,8 @@ class Order extends Base $whe[] = ['status', '=', 0]; $whe[] = ['kd_is', '=', 1]; if ($user_id) { + // 将UID转换为用户ID + $user_id = $this->convertUidToUserId($user_id); $whe[] = ['user_id', '=', $user_id]; } if ($mobile) { @@ -85,6 +87,8 @@ class Order extends Base $whe[] = ['status', '=', 1]; $whe[] = ['kd_is', '=', 0]; if ($user_id) { + // 将UID转换为用户ID + $user_id = $this->convertUidToUserId($user_id); $whe[] = ['user_id', '=', $user_id]; } if ($mobile) { @@ -172,6 +176,8 @@ class Order extends Base $whe = array(); if ($user_id) { + // 将UID转换为用户ID + $user_id = $this->convertUidToUserId($user_id); $whe[] = ['user_id', '=', $user_id]; } if ($mobile) { @@ -237,7 +243,7 @@ class Order extends Base /** - * 订单列表 + * 发货订单 */ public function send_order() { @@ -255,6 +261,8 @@ class Order extends Base $whe[] = ['status', '>', 0]; } if ($user_id) { + // 将UID转换为用户ID + $user_id = $this->convertUidToUserId($user_id); $whe[] = ['user_id', '=', $user_id]; $whe1[] = ['user_id', '=', $user_id]; } @@ -289,9 +297,9 @@ class Order extends Base // 订单筛选条件 $data = OrderListSend::getList($whe, $field, $order, $this->page); - $all_goodslist_money_sum = OrderList::where('status', '=', 2)->where($whe1)->sum('goodslist_money'); - $whe1[] = ['user_id', 'not in', $userList]; - $all_goodslist_money_sum1 = OrderList::where('status', '=', 2)->where($whe1)->sum('goodslist_money'); + $all_goodslist_money_sum = OrderList::where('status', '=', 2)->where($whe)->sum('goodslist_money'); + $whe[] = ['user_id', 'not in', $userList]; + $all_goodslist_money_sum1 = OrderList::where('status', '=', 2)->where($whe)->sum('goodslist_money'); foreach ($data['list'] as &$value) { $user_info = User::field('nickname,headimg,mobile,istest')->where(['id' => $value['user_id']])->find(); if ($user_info) { @@ -545,6 +553,8 @@ class Order extends Base $whe = [['status', '=', 1], ['kd_is', '=', 0]]; if ($user_id) { + // 将UID转换为用户ID + $user_id = $this->convertUidToUserId($user_id); $whe[] = ['user_id', '=', $user_id]; } if ($mobile) { @@ -637,6 +647,8 @@ class Order extends Base $whe = []; if ($user_id) { + // 将UID转换为用户ID + $user_id = $this->convertUidToUserId($user_id); $whe[] = ['user_id', '=', $user_id]; } if ($mobile) { @@ -729,6 +741,8 @@ class Order extends Base $whe = [['status', '=', $status]]; } if ($user_id) { + // 将UID转换为用户ID + $user_id = $this->convertUidToUserId($user_id); $whe[] = ['user_id', '=', $user_id]; } if ($mobile) { diff --git a/app/admin/controller/User.php b/app/admin/controller/User.php index 6bfb5d1..96e5d6b 100755 --- a/app/admin/controller/User.php +++ b/app/admin/controller/User.php @@ -40,7 +40,8 @@ class User extends Base // 构建查询条件 $where = []; if (!empty($param['user_id'])) { - $where[] = ['id', '=', intval($param['user_id'])]; + $user_id = $this->convertUidToUserId($param['user_id']); + $where[] = ['id', '=', intval($user_id)]; } if (!empty($param['mobile'])) { $where[] = ['mobile', 'like', "%{$param['mobile']}%"]; @@ -62,7 +63,7 @@ class User extends Base $order = 'id desc'; $data = UserModel::getList($where, $field, $order, $this->page); foreach ($data['list'] as &$value) { - $pid_info = UserModel::field('id,nickname,headimg')->where(['id' => $value['pid']])->find(); + $pid_info = UserModel::field('id,nickname,headimg,uid')->where(['id' => $value['pid']])->find(); $value['pid_info'] = $pid_info; #关联user_account $user_account = UserAccount::where(['user_id' => $value['id']])->field('last_login_ip1,last_login_ip,ip_adcode,ip_province,ip_city')->find(); diff --git a/app/admin/view/Config/systemconfig.html b/app/admin/view/Config/systemconfig.html index d4d1bb5..2be2c28 100755 --- a/app/admin/view/Config/systemconfig.html +++ b/app/admin/view/Config/systemconfig.html @@ -1,53 +1,96 @@ {include file="Public:header2"/} +

系统设置

-
系统设置
+
盒子同步地址
-
{if isset($data.sync_address) && is_array($data.sync_address)} - {foreach $data.sync_address as $index => $address} -
-
- -
-
- -
- -
- {/foreach} - {else} -
-
- -
-
- -
- + {foreach $data.sync_address as $index => $address} +
+
+
+
+ +
+ +
+ {/foreach} + {else} +
+
+ +
+
+ +
+ +
{/if}
- + +
- + +
+
+
+ +
+
+
用户UID设置
+
+
+ +
+ +
+ + + +
+
改变生成规则后,新用户UID会发生变化,请谨慎操作,uid为空的,会在登录后显示真实ID +
+
+ +
+ +
+ +
数字ID长度推荐6位,随机字符和数字长度推荐8位
+
+
- - +
@@ -58,14 +101,14 @@
{include file="Public:footer"/} - + - + - \ No newline at end of file + + \ No newline at end of file diff --git a/app/admin/view/User/index.html b/app/admin/view/User/index.html index c4bfa8a..a2b51bd 100755 --- a/app/admin/view/User/index.html +++ b/app/admin/view/User/index.html @@ -63,7 +63,8 @@ {{d.nickname}}
@@ -75,8 +76,9 @@
{{# } else { }} diff --git a/app/api/controller/Base.php b/app/api/controller/Base.php index 361ea39..00f2a70 100755 --- a/app/api/controller/Base.php +++ b/app/api/controller/Base.php @@ -48,8 +48,155 @@ class Base extends MyController $data['msg'] = "该账户已被封号,请联系客服解封"; exit(json_encode($data, 1)); } + + // 检查用户是否有UID,如果没有则生成 + if (empty($user['uid'])) { + // 获取用户uid配置 + $user_config = getConfig('user_config'); + if (!empty($user_config) && isset($user_config['uid_type'])) { + // 生成UID + $uid = $this->generateUidForUser($user['id']); + if ($uid) { + // 更新用户UID + User::where('id', $user['id'])->update(['uid' => $uid]); + $user['uid'] = $uid; + } + } + } + return $user; } + + /** + * 为用户生成UID + * + * @param int $user_id 用户ID + * @return string 生成的UID + */ + protected function generateUidForUser($user_id) + { + // 获取用户uid配置 + $user_config = getConfig('user_config'); + if (empty($user_config) || !isset($user_config['uid_type'])) { + return (string)$user_id; // 默认使用真实ID + } + + $uid_type = (int)$user_config['uid_type']; + $uid_length = isset($user_config['uid_length']) ? (int)$user_config['uid_length'] : 6; + + // 限制长度范围 + if ($uid_length < 4) { + $uid_length = 4; + } elseif ($uid_length > 16) { + $uid_length = 16; + } + + // 根据不同类型生成UID + switch ($uid_type) { + case 0: // 真实ID + return (string)$user_id; + + case 1: // 数字ID + // 生成不以0开头的随机数字 + $max_attempts = 10; + $attempt = 0; + + while ($attempt < $max_attempts) { + // 生成随机数字 + $min = pow(10, $uid_length - 1); + $max = pow(10, $uid_length) - 1; + $uid = (string)mt_rand($min, $max); + + // 检查是否唯一 + $exists = User::where('uid', $uid)->count(); + if ($exists == 0) { + return $uid; + } + + $attempt++; + } + + // 如果多次尝试后仍无法生成唯一ID,则使用更可靠的方法 + return $this->generateUniqueNumericId($uid_length); + + case 2: // 随机字符和数字 + $length = max(8, $uid_length); // 字母数字混合至少8位 + + $max_attempts = 10; + $attempt = 0; + + while ($attempt < $max_attempts) { + // 生成随机字母数字 + $characters = '23456789ABCDEFGHJKLMNPQRSTUVWXYZ'; // 排除容易混淆的字符 + $uid = ''; + + // 确保第一个字符不是数字 + $uid .= $characters[mt_rand(8, strlen($characters) - 1)]; // 从字母开始 + + // 生成剩余字符 + for ($i = 1; $i < $length; $i++) { + $uid .= $characters[mt_rand(0, strlen($characters) - 1)]; + } + + // 检查是否唯一 + $exists = User::where('uid', $uid)->count(); + if ($exists == 0) { + return $uid; + } + + $attempt++; + } + + // 如果多次尝试后仍无法生成唯一ID,使用时间戳+随机数确保唯一性 + return $this->generateUniqueAlphaNumId($length); + + default: + return (string)$user_id; + } + } + + /** + * 生成唯一的数字ID(备用方法) + */ + private function generateUniqueNumericId($length) + { + // 使用时间微秒 + 随机数的方式保证唯一性 + $base = microtime(true) * 10000 . mt_rand(1000, 9999); + $uid = substr(preg_replace('/[^0-9]/', '', $base), 0, $length); + + // 确保不以0开头且长度正确 + while (strlen($uid) < $length || $uid[0] == '0') { + $uid = mt_rand(1, 9) . substr($uid, 1); + $uid = substr($uid, 0, $length); + } + + return $uid; + } + + /** + * 生成唯一的字母数字ID(备用方法) + */ + private function generateUniqueAlphaNumId($length) + { + // 使用时间戳 + 随机字符 + $base = time() . mt_rand(1000, 9999); + $hash = md5($base); + + // 转换为字母数字混合 + $uid = ''; + $chars = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789'; // 排除容易混淆的字符 + + // 确保第一个字符是字母 + $uid .= $chars[mt_rand(0, 25)]; // 前26个是字母 + + // 生成剩余字符 + for ($i = 1; $i < $length; $i++) { + $uid .= $chars[mt_rand(0, strlen($chars) - 1)]; + } + + return $uid; + } + /** * * 是否H5客户端 diff --git a/app/api/controller/Goods.php b/app/api/controller/Goods.php index 392357b..024f37f 100755 --- a/app/api/controller/Goods.php +++ b/app/api/controller/Goods.php @@ -1241,32 +1241,35 @@ class Goods extends Base // 获取POST的JSON数据 $input = file_get_contents('php://input'); $data = json_decode($input, true); - + if (!$data || !isset($data['goods']) || !isset($data['goodsList']) || !isset($data['async_code'])) { return $this->renderError('无效的同步数据'); } - + // 开始事务 Db::startTrans(); try { $goodsData = $data['goods']; $goodsListData = $data['goodsList']; $async_code = $data['async_code']; - + // 检查async_code是否存在 $existingGoods = Goodsmodel::where('async_code', $async_code)->find(); - + // 准备商品数据 - $goods = isset($goodsData['id']) ? unset($goodsData['id']) : $goodsData; - + $goods = $goodsData; + if (isset($goods['id'])) { + unset($goods['id']); + } + if ($existingGoods) { // 更新现有商品 $goodsId = $existingGoods->id; - + // 更新商品数据 $goods['async_date'] = date('Y-m-d H:i:s'); $existingGoods->save($goods); - + // 删除现有的商品列表数据 GoodsList::where('goods_id', $goodsId)->delete(); } else { @@ -1278,24 +1281,24 @@ class Goods extends Base $goodsModel->save($goods); $goodsId = $goodsModel->id; } - + // 处理商品列表数据 foreach ($goodsListData as $listItem) { // 处理商品列表项 if (isset($listItem['id'])) { unset($listItem['id']); } - + $listItem['goods_id'] = $goodsId; - + // 创建新的商品列表项 $goodsListModel = new GoodsList(); $goodsListModel->save($listItem); } - + // 提交事务 Db::commit(); - + return $this->renderSuccess('同步成功'); } catch (\Exception $e) { // 回滚事务 diff --git a/app/api/controller/Login.php b/app/api/controller/Login.php index ae15670..51f699a 100755 --- a/app/api/controller/Login.php +++ b/app/api/controller/Login.php @@ -18,10 +18,163 @@ class Login extends Base public function initialize() { - + parent::initialize(); // 确保调用父类初始化方法 + $config = getConfig('uploads'); + if (!$config) { + $config = []; // 确保config是一个数组 + } $this->uploader = new TencentCosUploader($config); } + /** + * 处理用户的UID + * + * @param User $user 用户对象 + */ + private function processUid($user) + { + // 如果用户已有uid,不处理 + if (!empty($user['uid'])) { + return; + } + + // 生成uid + $uid = $this->generateUid($user['id']); + if ($uid) { + // 更新用户uid + User::where('id', $user['id'])->update(['uid' => $uid]); + } + } + + /** + * 生成用户UID + * + * @param int $user_id 用户ID + * @return string 生成的UID + */ + private function generateUid($user_id) + { + // 获取用户uid配置 + $user_config = getConfig('user_config'); + if (empty($user_config) || !isset($user_config['uid_type'])) { + return (string)$user_id; // 默认使用真实ID + } + + $uid_type = (int)$user_config['uid_type']; + $uid_length = isset($user_config['uid_length']) ? (int)$user_config['uid_length'] : 6; + + // 限制长度范围 + if ($uid_length < 4) { + $uid_length = 4; + } elseif ($uid_length > 16) { + $uid_length = 16; + } + + // 根据不同类型生成UID + switch ($uid_type) { + case 0: // 真实ID + return (string)$user_id; + + case 1: // 数字ID + // 生成不以0开头的随机数字 + $max_attempts = 10; + $attempt = 0; + + while ($attempt < $max_attempts) { + // 生成随机数字 + $min = pow(10, $uid_length - 1); + $max = pow(10, $uid_length) - 1; + $uid = (string)mt_rand($min, $max); + + // 检查是否唯一 + $exists = User::where('uid', $uid)->count(); + if ($exists == 0) { + return $uid; + } + + $attempt++; + } + + // 如果多次尝试后仍无法生成唯一ID,则使用更可靠的方法 + return $this->generateUniqueNumericId($uid_length); + + case 2: // 随机字符和数字 + $length = max(8, $uid_length); // 字母数字混合至少8位 + + $max_attempts = 10; + $attempt = 0; + + while ($attempt < $max_attempts) { + // 生成随机字母数字 + $characters = '23456789ABCDEFGHJKLMNPQRSTUVWXYZ'; // 排除容易混淆的字符 + $uid = ''; + + // 确保第一个字符不是数字 + $uid .= $characters[mt_rand(8, strlen($characters) - 1)]; // 从字母开始 + + // 生成剩余字符 + for ($i = 1; $i < $length; $i++) { + $uid .= $characters[mt_rand(0, strlen($characters) - 1)]; + } + + // 检查是否唯一 + $exists = User::where('uid', $uid)->count(); + if ($exists == 0) { + return $uid; + } + + $attempt++; + } + + // 如果多次尝试后仍无法生成唯一ID,使用时间戳+随机数确保唯一性 + return $this->generateUniqueAlphaNumId($length); + + default: + return (string)$user_id; + } + } + + /** + * 生成唯一的数字ID(备用方法) + */ + private function generateUniqueNumericId($length) + { + // 使用时间微秒 + 随机数的方式保证唯一性 + $base = microtime(true) * 10000 . mt_rand(1000, 9999); + $uid = substr(preg_replace('/[^0-9]/', '', $base), 0, $length); + + // 确保不以0开头且长度正确 + while (strlen($uid) < $length || $uid[0] == '0') { + $uid = mt_rand(1, 9) . substr($uid, 1); + $uid = substr($uid, 0, $length); + } + + return $uid; + } + + /** + * 生成唯一的字母数字ID(备用方法) + */ + private function generateUniqueAlphaNumId($length) + { + // 使用时间戳 + 随机字符 + $base = time() . mt_rand(1000, 9999); + $hash = md5($base); + + // 转换为字母数字混合 + $uid = ''; + $chars = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789'; // 排除容易混淆的字符 + + // 确保第一个字符是字母 + $uid .= $chars[mt_rand(0, 25)]; // 前26个是字母 + + // 生成剩余字符 + for ($i = 1; $i < $length; $i++) { + $uid .= $chars[mt_rand(0, strlen($chars) - 1)]; + } + + return $uid; + } /** * 微信授权,登录接口 */ @@ -61,6 +214,10 @@ class Login extends Base $user->save(); } } + + // 检查并生成uid + $this->processUid($user); + #token时间戳 $time = time(); #token字符串 @@ -133,6 +290,13 @@ class Login extends Base 'click_id' => $click_id, 'unionid' => $wx_unionid, ]); + + // 生成用户uid + $uid = $this->generateUid($user_id); + if ($uid) { + User::where('id', $user_id)->update(['uid' => $uid]); + } + $time = time(); #token字符串 $token_num = getRandStr(10); diff --git a/app/api/controller/User.php b/app/api/controller/User.php index 23f9846..70a2f95 100755 --- a/app/api/controller/User.php +++ b/app/api/controller/User.php @@ -39,13 +39,13 @@ class User extends Base $this->domain = $config['Domain']; } - /** * 我的 */ public function user(Request $request) { $user = $this->getUser(); + $userinfo['ID'] = $user['id']; $userinfo['mobile_is'] = $user['mobile'] ? 1 : 0; $userinfo['nickname'] = $user['nickname']; @@ -56,9 +56,10 @@ class User extends Base $userinfo['integral'] = $user['integral']; $userinfo['score'] = $user['score']; $userinfo['vip'] = $this->vip_level($user['id'], $user['vip']); + $userinfo['uid'] = $user['uid'] ? $user['uid'] : $user['id']; $vip_imgurl = UserVip::field('imgurl')->where('id', '=', $userinfo['vip'])->value('imgurl'); $userinfo['vip_imgurl'] = $vip_imgurl ? imageUrl($vip_imgurl) : 0; - $userinfo['quan_yi_level'] = \app\common\model\User::ou_qi_level($user['ou_qi_level'], $user['ou_qi']); + $userinfo['quan_yi_level'] = Usermodel::ou_qi_level($user['ou_qi_level'], $user['ou_qi']); $userinfo['coupon'] = UserCoupon::where('user_id', '=', $user['id'])->where('status', '=', 1)->count(); $base = getConfig('base'); $userinfo['js_is_open'] = 0; @@ -193,15 +194,6 @@ class User extends Base } } - // if ($headimg) { - - // if (strpos($headimg, '/storage') !== false) { - // $str = explode('/storage', $headimg); - // $save['headimg'] = '/storage' . $str[1]; - // } else { - // $save['headimg'] = $headimg; - // } - // } $res = Usermodel::field('nickname,headimg')->where('id', '=', $user['id'])->update($save); if ($res) { return $this->renderSuccess('修改成功');