2 커밋 f48fbdb280 ... 5e9367374b

작성자 SHA1 메시지 날짜
  aiden 5e9367374b Merge branch 'main' of s.long.bid:liu/merchant_admin 3 달 전
  aiden a3327ae7d3 取消格式化金额 3 달 전
4개의 변경된 파일141개의 추가작업 그리고 9개의 파일을 삭제
  1. 35 0
      app/common.php
  2. 9 9
      app/common/CommonUtils.php
  3. 24 0
      app/model/UserIdAssignModel.php
  4. 73 0
      app/worker/AutoAssignUserId.php

+ 35 - 0
app/common.php

@@ -4,6 +4,8 @@ require_once "common/GameGameConfig.php";
 
 use Firebase\JWT\JWT;
 use Firebase\JWT\Key;
+use think\facade\Db;
+use app\model\UserIdAssignModel;
 
 /// 加密密钥
 $GLOBALS['token_key_secret'] = "z.1i8L?Ld+ovuA4r%4YZrz?w1Y%-NYvlrJ=TqV$[W[5=B#C[=l2gHV8gJ,DhZc";
@@ -309,4 +311,37 @@ if(!function_exists('batchGetIpLocation')){
             return $results;
         }
     }
+}
+
+/**
+ * 分配用户id
+ */
+if(!function_exists('assignUserId')) {
+    function assignUserId(): int|false
+    {
+        $data = [
+            'status' => 1,
+            'user_id' => Db::raw('LAST_INSERT_ID(user_id)'),
+        ];
+
+        try {
+            $affectedRows = UserIdAssignModel::where('status', 0)->limit(1)->update($data);
+
+            if ($affectedRows > 0) {
+                $result = Db::query('SELECT LAST_INSERT_ID()');
+
+                if (!empty($result) && isset($result[0])) {
+                    $assignedId = array_values($result[0])[0] ?? null;
+
+                    if ($assignedId !== null) {
+                        return (int)$assignedId;
+                    }
+                }
+            }
+        } catch (Throwable $e) {
+            return 0;
+        }
+
+        return 0;
+    }
 }

+ 9 - 9
app/common/CommonUtils.php

@@ -35,15 +35,15 @@ class CommonUtils
 
     // 转换 分数 * 10000 or / 10000
     public static function convertBalance($balance = 0, $isTenThousandfold = true) {
-        $balance = (float)$balance;
-        // 分数小数点 * 10000;
-        // $GLOBALS['balanceTenThousandfold'] = 10000;
-        $balanceTenThousandfold = 10000;
-        if ($isTenThousandfold) {
-            $balance = bcmul($balance, $balanceTenThousandfold);
-        } else {
-            $balance = bcdiv($balance, $balanceTenThousandfold, 4);
-        }
+        // $balance = (float)$balance;
+        // // 分数小数点 * 10000;
+        // // $GLOBALS['balanceTenThousandfold'] = 10000;
+        // $balanceTenThousandfold = 10000;
+        // if ($isTenThousandfold) {
+        //     $balance = bcmul($balance, $balanceTenThousandfold);
+        // } else {
+        //     $balance = bcdiv($balance, $balanceTenThousandfold, 4);
+        // }
         return (float)$balance;
     }
 

+ 24 - 0
app/model/UserIdAssignModel.php

@@ -0,0 +1,24 @@
+<?php
+
+namespace app\model;
+
+use think\facade\Db;
+use think\Model;
+
+class UserIdAssignModel extends Model
+{
+    // 设置表名
+    protected $name = 'user_assign_uid';
+
+    // 设置主键
+    protected $pk = 'user_id';
+
+    // 设置自动时间戳
+    protected $autoWriteTimestamp = true;
+
+    // 设置字段类型
+    protected $type = [
+        'user_id' => 'int',
+        'status' => 'int',
+    ];
+}

+ 73 - 0
app/worker/AutoAssignUserId.php

@@ -0,0 +1,73 @@
+<?php
+/**
+ * 生成待分配使用用户id
+ */
+require __DIR__ . '/../../vendor/autoload.php';
+
+use think\App;
+use app\model\UserIdAssignModel;
+use app\model\UserModel;
+
+$app = App::getInstance();
+$app->initialize();
+
+// 可使用的用户id范围
+$userIdRange = [10000, 99999];
+
+$offset = $userIdRange[0];
+$limit = $userIdRange[1];
+
+for ($i = $offset; $i < $limit; $i += 5000)
+{
+    $tempRange = range($i, $i + 5000);
+    echo $i . " " . ($i + 5000) . "\n";
+
+    // 打乱数组
+    shuffle($tempRange);
+    $availableUids = [];
+    if (!empty($tempRange))
+    {
+        foreach ($tempRange as $key => $val)
+        {
+            $isFilter = false;
+            if (preg_match('/(1{4}|2{4}|3{4}|4{4}|5{4}|6{4}|7{4}|8{4}|9{4}|0{4})/', $val, $matches))
+            {
+                // 带4A以上的
+                $isFilter = true;
+            }
+            elseif (preg_match('/(12345|98765)/', $val, $matches))
+            {
+                // 5连顺的
+                $isFilter = true;
+            }
+
+            // id已经注册过
+            if (UserModel::where([['user_id', '=', $val]])->find())
+            {
+                $isFilter = true;
+            }
+
+            if (!$isFilter)
+            {
+                $availableUids[] = ['user_id' => $val];
+            }
+
+            if ($key % 1000 === 0)
+            {
+                if (!empty($availableUids))
+                {
+                    UserIdAssignModel::insertAll($availableUids);
+                    echo "添加" . count($availableUids) . "\n";
+                    $availableUids = [];
+                }
+            }
+        }
+
+        if ($availableUids)
+        {
+            UserIdAssignModel::insertAll($availableUids);
+            echo "添加" . count($availableUids) . "\n";
+        }
+        unset($availableUids);
+    }
+}