Compare commits
11 Commits
b7d32a74e7
...
5da86322b7
Author | SHA1 | Date |
---|---|---|
|
5da86322b7 | |
|
d4a9b3990c | |
|
ac6ea86eec | |
|
8e7b2b3245 | |
|
f4b1d6946f | |
|
97bb4fcd8d | |
|
4944cbe488 | |
|
7604a5f491 | |
|
9f0b4cfeeb | |
|
ee28a0bd76 | |
|
06ea9ca773 |
app
Utils/API
controller/api
process
|
@ -6,6 +6,7 @@ use GuzzleHttp\Client;
|
|||
|
||||
/**
|
||||
* 第三方api转账
|
||||
* 已经废弃
|
||||
*/
|
||||
class Payment
|
||||
{
|
||||
|
|
|
@ -6,7 +6,7 @@ use GuzzleHttp\Client;
|
|||
use support\Log;
|
||||
|
||||
/**
|
||||
* 第三方 小火箭api
|
||||
* 第三方 前端 小火箭api
|
||||
* 网址
|
||||
* https://dx1.rocketgo.vip/setting/account/account
|
||||
*/
|
||||
|
@ -15,35 +15,136 @@ class Rocketgo
|
|||
/**
|
||||
* TOKEN
|
||||
*/
|
||||
protected static $token="eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6IjFlMTRlZWQ3LTEyODUtNGFjNi1hMzFhLTFlNWQ5OTEzMTJhYSJ9.BJgOhw1VKX1i9VfYKLIzF1zXUZMi4idO9Sb-p6p_rMKJanmt4is9slky7SqvSEXqhJ6USMGs2wqMY3tYJrH-hw";
|
||||
protected static $baseurl="https://dx1.rocketgo.vip";
|
||||
/**
|
||||
* 获取base64图形验证码
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function get_captchaImage()
|
||||
{
|
||||
$client = new Client(); // 创建 Guzzle 客户端
|
||||
// 请求数据
|
||||
// 发送 POST 请求
|
||||
$response = $client->get("self::1baseurl/prod-api1/captchaImage");
|
||||
protected static $token = null;
|
||||
|
||||
// 获取响应体内容
|
||||
$body = $response->getBody();
|
||||
$responseData = json_decode($body, true); // 如果返回的是 JSON 格式,解析它
|
||||
return $responseData;
|
||||
}
|
||||
//login发送参数
|
||||
// {
|
||||
// "username": "h102067452",
|
||||
// "password": "yBQnfuBShGl1MTBN",
|
||||
// "code": "23",
|
||||
// "uuid": "9cbe6a9037dc47cf80c9f2a23c0672a5"
|
||||
// }
|
||||
public static function login($username,$password,$code,$uuid)
|
||||
protected static $baseurl = "https://dx1.rocketgo.vip"; // URL前缀
|
||||
|
||||
// 单例复用 http 客户端
|
||||
protected static $client = null;
|
||||
|
||||
/**
|
||||
* 获取 Guzzle 客户端
|
||||
* 用于复用 客户端常驻内存
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
protected static function get_client()
|
||||
{
|
||||
$client = new Client(); // 创建 Guzzle 客户端
|
||||
if (self::$client == null) {
|
||||
self::$client = new Client([
|
||||
'curl' => [
|
||||
CURLOPT_FRESH_CONNECT => false,
|
||||
CURLOPT_FORBID_REUSE => false,
|
||||
],
|
||||
'headers' => [
|
||||
'Connection' => 'keep-alive',
|
||||
],
|
||||
]);
|
||||
}
|
||||
return self::$client;
|
||||
}
|
||||
// /**
|
||||
// * 获取 token
|
||||
// * 用于复用 客户端常驻内存
|
||||
// *
|
||||
// * @return object
|
||||
// */
|
||||
// protected static function get_token()
|
||||
// {
|
||||
// if (self::$token == null) {
|
||||
// self::$token =
|
||||
// }
|
||||
// return self::$token;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 获取 base64 图形验证码
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected static function get_captchaImage()
|
||||
{
|
||||
$client = self::get_client(); // 创建 Guzzle 客户端
|
||||
|
||||
// 发送 GET 请求
|
||||
try {
|
||||
$response = $client->get("https://dx1.rocketgo.vip/prod-api3/captchaImage");
|
||||
|
||||
// 获取响应体内容
|
||||
$body = $response->getBody();
|
||||
$responseData = json_decode($body, true);
|
||||
|
||||
if ($responseData['code'] == 200) {
|
||||
return $responseData;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error("请求验证码失败: " . $e->getMessage());
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取第三方 API 可识别成功的验证码
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected static function get_captchaImage_available()
|
||||
{
|
||||
$captchaImage = self::get_captchaImage();
|
||||
|
||||
if ($captchaImage == -1) {
|
||||
Log::error("请求验证码失败: " . json_encode($captchaImage));
|
||||
return -1;
|
||||
}
|
||||
|
||||
$uuid = $captchaImage['uuid'];
|
||||
$img = $captchaImage['img'];
|
||||
|
||||
// 调用验证码识别接口
|
||||
$code = Verification::get_captchaImage($img)['data'];
|
||||
|
||||
|
||||
if ($code == -1) {
|
||||
Log::error("调用接口验证码识别失败: ");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 验证验证码是否是2位数字
|
||||
if (preg_match('/^\d{2}$/', $code)) {
|
||||
return [
|
||||
'code' => $code,
|
||||
'uuid' => $uuid
|
||||
];
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录方法
|
||||
*
|
||||
* @param string $username
|
||||
* @param string $password
|
||||
* @return array
|
||||
*/
|
||||
public static function login($username, $password)
|
||||
{
|
||||
$code = "";
|
||||
$uuid = "";
|
||||
|
||||
// 获取有效验证码并循环尝试直到成功
|
||||
while (true) {
|
||||
$captchaImage = self::get_captchaImage_available();
|
||||
if ($captchaImage != -1) {
|
||||
$code = $captchaImage['code'];
|
||||
$uuid = $captchaImage['uuid'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$client = self::get_client(); // 创建 Guzzle 客户端
|
||||
|
||||
// 请求数据
|
||||
$data = [
|
||||
"username" => $username,
|
||||
|
@ -51,25 +152,226 @@ class Rocketgo
|
|||
"code" => $code,
|
||||
"uuid" => $uuid,
|
||||
];
|
||||
// 发送 POST 请求
|
||||
$response = $client->post("self::1baseurl/prod-api1/login", [
|
||||
'json' => $data, // 以 JSON 格式发送数据
|
||||
]);
|
||||
// 获取响应体内容
|
||||
$body = $response->getBody();
|
||||
$responseData = json_decode($body, true); // 如果返回的是 JSON 格式,解析它
|
||||
return $responseData;
|
||||
}
|
||||
public static function account_list()
|
||||
{
|
||||
$client = new Client(); // 创建 Guzzle 客户端
|
||||
// 请求数据
|
||||
// 发送 POST 请求
|
||||
$response = $client->get("self::1baseurl/prod-api1/biz/account/list?pageNum=1&pageSize=1000&accountStatus=1&sendCount=0");
|
||||
|
||||
// 获取响应体内容
|
||||
$body = $response->getBody();
|
||||
$responseData = json_decode($body, true); // 如果返回的是 JSON 格式,解析它
|
||||
return $responseData;
|
||||
try {
|
||||
// 发送 POST 请求
|
||||
$response = $client->post("https://dx1.rocketgo.vip/prod-api3/login", [
|
||||
'json' => $data, // 以 JSON 格式发送数据
|
||||
]);
|
||||
|
||||
// 获取响应体内容
|
||||
$body = $response->getBody();
|
||||
$responseData = json_decode($body, true);
|
||||
if ($responseData['code'] == 200) {
|
||||
self::$token = $responseData['token'];
|
||||
return $responseData['token'];
|
||||
}else{
|
||||
Log::error("登录失败 未知错误: " . json_encode($responseData));
|
||||
}
|
||||
// return $responseData;
|
||||
} catch (\Exception $e) {
|
||||
Log::error("登录失败: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected static function get_token()
|
||||
{
|
||||
return self::$token;
|
||||
}
|
||||
protected static function set_token($token)
|
||||
{
|
||||
self::$token = $token;
|
||||
}
|
||||
/**
|
||||
* 测试token是否有效
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function test_login()
|
||||
{
|
||||
$client = self::get_client(); // 创建 Guzzle 客户端
|
||||
try {
|
||||
// 发送 GET 请求
|
||||
$response = $client->get("https://dx1.rocketgo.vip/prod-api2/biz/account/getLoginUserInfo", [
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer ' . self::$token,
|
||||
'Accept' => 'application/json', // 设置其他头信息
|
||||
]
|
||||
]);
|
||||
|
||||
// 获取响应体内容
|
||||
$body = $response->getBody();
|
||||
$responseData = json_decode($body, true);
|
||||
// var_dump($responseData);
|
||||
if(!empty($responseData['code'])){
|
||||
if ($responseData['code'] == 401) {
|
||||
Log::info("登录过期需要重新登录");
|
||||
self::login('h102067452', 'yBQnfuBShGl1MTBN');
|
||||
}
|
||||
}else{
|
||||
Log::info("登录没有过期可以继续使用token");
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error("检测登录是否过期失败: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取账号列表(分页)
|
||||
*
|
||||
* @param int $pageSize 每页数据量,默认为 1000
|
||||
* @return array
|
||||
* logged 1 在线 0不在线
|
||||
* failedReason 失败类型 正常为空
|
||||
* username ws号码
|
||||
*/
|
||||
public static function account_list($pageSize = 1000)
|
||||
{
|
||||
$client = self::get_client(); // 创建 Guzzle 客户端
|
||||
$allData = []; // 用来存储所有分页的数据
|
||||
$pageNum = 1; // 从第一页开始
|
||||
|
||||
try {
|
||||
// 首次请求,获取 total 数据量
|
||||
$response = $client->get(self::$baseurl . "/prod-api2/biz/account/list", [
|
||||
'query' => [
|
||||
'pageNum' => $pageNum,
|
||||
'pageSize' => $pageSize,
|
||||
'sendCount' => 0,
|
||||
'isAll' => 1,
|
||||
],
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer ' . self::$token,
|
||||
'Accept' => 'application/json', // 设置其他头信息
|
||||
]
|
||||
]);
|
||||
|
||||
// 获取响应体内容
|
||||
$body = $response->getBody();
|
||||
$responseData = json_decode($body, true);
|
||||
|
||||
// 检查响应是否成功
|
||||
if ($responseData['code'] == 200) {
|
||||
$total = $responseData['total']; // 获取总数据量
|
||||
$totalPages = ceil($total / $pageSize); // 计算总页数
|
||||
|
||||
// 合并第一页数据
|
||||
$allData = array_merge($allData, $responseData['rows']);
|
||||
|
||||
// 循环获取其他页的数据
|
||||
for ($pageNum = 2; $pageNum <= $totalPages; $pageNum++) {
|
||||
$response = $client->get(self::$baseurl . "/prod-api2/biz/account/list", [
|
||||
'query' => [
|
||||
'pageNum' => $pageNum,
|
||||
'pageSize' => $pageSize,
|
||||
'sendCount' => 0,
|
||||
'isAll' => 1,
|
||||
],
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer ' . self::$token,
|
||||
'Accept' => 'application/json',
|
||||
]
|
||||
]);
|
||||
|
||||
// 获取响应体内容
|
||||
$body = $response->getBody();
|
||||
$responseData = json_decode($body, true);
|
||||
|
||||
if ($responseData['code'] == 200) {
|
||||
// 合并当前页的数据
|
||||
$allData = array_merge($allData, $responseData['rows']);
|
||||
} else {
|
||||
Log::error("获取账号列表失败,错误信息: " . $responseData['msg']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Log::error("获取账号列表失败,错误信息: " . $responseData['msg']);
|
||||
}
|
||||
|
||||
return $allData; // 返回所有数据
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error("获取账号列表失败: " . $e->getMessage());
|
||||
return []; // 返回空数组,表示请求失败
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取仓库账号列表(分页)
|
||||
*
|
||||
* @param int $pageSize 每页数据量,默认为 1000
|
||||
* @return array
|
||||
*/
|
||||
public static function account_storehouse_list($pageSize = 1000)
|
||||
{
|
||||
$client = self::get_client(); // 创建 Guzzle 客户端
|
||||
$allData = []; // 用来存储所有分页的数据
|
||||
$pageNum = 1; // 当前页数从 1 开始
|
||||
|
||||
try {
|
||||
// 发送初始请求,获取 total 数据量
|
||||
$response = $client->get(self::$baseurl . "/prod-api2/biz/account/list", [
|
||||
'query' => [
|
||||
'pageNum' => $pageNum,
|
||||
'pageSize' => $pageSize,
|
||||
'accountType' => 2, // 只查询仓库类型的账号
|
||||
'isAll' => 1, // 查询所有账号
|
||||
],
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer ' . self::$token,
|
||||
'Accept' => 'application/json', // 设置其他头信息
|
||||
]
|
||||
]);
|
||||
|
||||
// 获取响应体内容
|
||||
$body = $response->getBody();
|
||||
$responseData = json_decode($body, true);
|
||||
|
||||
// 检查响应是否成功
|
||||
if ($responseData['code'] == 200) {
|
||||
$total = $responseData['total']; // 获取总数据量
|
||||
$totalPages = ceil($total / $pageSize); // 计算总页数
|
||||
|
||||
// 循环获取分页数据
|
||||
for ($pageNum = 1; $pageNum <= $totalPages; $pageNum++) {
|
||||
// 发送 GET 请求,带上分页参数
|
||||
$response = $client->get(self::$baseurl . "/prod-api2/biz/account/list", [
|
||||
'query' => [
|
||||
'pageNum' => $pageNum,
|
||||
'pageSize' => $pageSize,
|
||||
'accountType' => 2,
|
||||
'isAll' => 1,
|
||||
],
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer ' . self::$token,
|
||||
'Accept' => 'application/json', // 设置其他头信息
|
||||
]
|
||||
]);
|
||||
|
||||
// 获取响应体内容
|
||||
$body = $response->getBody();
|
||||
$responseData = json_decode($body, true);
|
||||
|
||||
// 检查响应是否成功
|
||||
if ($responseData['code'] == 200) {
|
||||
$allData = array_merge($allData, $responseData['rows']); // 合并当前页的数据
|
||||
} else {
|
||||
Log::error("获取仓库账号列表失败,错误信息: " . $responseData['msg']);
|
||||
break; // 如果请求失败,退出循环
|
||||
}
|
||||
}
|
||||
|
||||
return $allData; // 返回所有数据
|
||||
} else {
|
||||
Log::error("获取仓库账号列表失败,错误信息: " . $responseData['msg']);
|
||||
return []; // 返回空数组,表示请求失败
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error("获取仓库账号列表失败: " . $e->getMessage());
|
||||
return []; // 返回空数组,表示请求失败
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
|
||||
namespace App\Utils\API;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use support\Log;
|
||||
|
||||
/**
|
||||
* 验证码识别类
|
||||
* 官网 https://www.jfbym.com/
|
||||
*/
|
||||
class Verification
|
||||
{
|
||||
/**
|
||||
* token
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $token = "WAUjOgpcS6KUtvIc1C4Uf0M1SICxtDC9beFetiCp9hk";
|
||||
/**
|
||||
* 接口请求url
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $baseurl = "http://api.jfbym.com/api/YmServer/customApi";
|
||||
/**
|
||||
* 识别类型
|
||||
* 10110 4位纯数字
|
||||
* 10103 加强版
|
||||
* @var string
|
||||
*/
|
||||
protected static $type = "10110";
|
||||
//单例复用http客户端
|
||||
protected static $client = null;
|
||||
/**
|
||||
* 获取 Guzzle 客户端
|
||||
* 用于复用 客户端常驻内存
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
protected static function get_client()
|
||||
{
|
||||
if (self::$client == null) {
|
||||
self::$client = new Client([
|
||||
'curl' => [
|
||||
CURLOPT_FRESH_CONNECT => false,
|
||||
CURLOPT_FORBID_REUSE => false,
|
||||
],
|
||||
'headers' => [
|
||||
'Connection' => 'keep-alive',
|
||||
],
|
||||
]);
|
||||
}
|
||||
return self::$client;
|
||||
}
|
||||
/**
|
||||
* 获取验证码图片 识别结果
|
||||
*
|
||||
* @param string $image 待识别图的base64字符串
|
||||
* @return int 识别结果 -1 识别失败
|
||||
*/
|
||||
public static function get_captchaImage($image)
|
||||
{
|
||||
$client = self::get_client(); // 创建 Guzzle 客户端
|
||||
$data = [
|
||||
"token" => self::$token,
|
||||
"type" => self::$type,
|
||||
"image" => $image,
|
||||
];
|
||||
// 发送 POST 请求
|
||||
$response = $client->post(self::$baseurl, [
|
||||
'json' => $data, // 以 JSON 格式发送数据
|
||||
]);
|
||||
// 获取响应体内容
|
||||
$body = $response->getBody();
|
||||
$responseData = json_decode($body, true); // 如果返回的是 JSON 格式,解析它
|
||||
if ($responseData['code'] == 10000) {
|
||||
return $responseData['data'];
|
||||
} else {
|
||||
Log::error("验证码识别失败: " ."code:". $responseData['code']);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -64,6 +64,9 @@ class SignController
|
|||
if(!UserPhoneLogDao::getOnlineTimeByPhoneTodayId($user_id)){
|
||||
return ApiResponseApp::error([],'挂机时长没有超过6小时,暂不能签到');
|
||||
}
|
||||
if(SignDao::search_Sign_today($user_id)==1){
|
||||
return ApiResponseApp::error([],'今天已经签到');
|
||||
}
|
||||
SignDao::Sign($user_id);
|
||||
return ApiResponseApp::success([]);
|
||||
}
|
||||
|
|
|
@ -150,13 +150,13 @@ class TaskController
|
|||
$UserPhone->save();
|
||||
} else {
|
||||
// 本地已存在手机号,更新用户信息
|
||||
// $UserPhone->user_id = $user_id;
|
||||
// $UserPhone->score = 0;
|
||||
// $UserPhone->status = 1;
|
||||
// $UserPhone->time = 0;
|
||||
// $UserPhone->last_time = time();
|
||||
// $UserPhone->save();
|
||||
$GetLodeLog->delete();
|
||||
$UserPhone->user_id = $user_id;
|
||||
$UserPhone->score = 0;
|
||||
$UserPhone->status = 1;
|
||||
$UserPhone->time = 0;
|
||||
$UserPhone->last_time = time();
|
||||
$UserPhone->save();
|
||||
$GetLodeLog->delete();
|
||||
return ApiResponseApp::error([], '您已登陆');
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ use app\model\ExchangeRate;
|
|||
use app\model\Userbank;
|
||||
|
||||
use support\Request;
|
||||
use App\Utils\API\Payment;
|
||||
use App\Utils\API\PaymentNew;
|
||||
use App\Utils\ApiResponse;
|
||||
use App\Utils\ApiResponseApp;
|
||||
|
|
|
@ -9,6 +9,8 @@ use app\dao\UserRewardDao;
|
|||
use support\Log;
|
||||
use Workerman\Crontab\Crontab;
|
||||
use GuzzleHttp\Client;
|
||||
use App\Utils\API\Rocketgo;
|
||||
|
||||
/**
|
||||
* 查询用户是否在线类
|
||||
*/
|
||||
|
@ -16,59 +18,140 @@ class Task2
|
|||
{
|
||||
public function onWorkerStart()
|
||||
{
|
||||
// 每5秒执行一次
|
||||
// 每小时执行一次
|
||||
new Crontab('0 */1 * * * *', function () {
|
||||
$phones = UserPhone::where('created_at', '<', \Carbon\Carbon::now()->subMinutes(10))->where('status','!=',2)->get();
|
||||
$start_time = time();
|
||||
foreach ($phones as $key => $value) {
|
||||
|
||||
try {
|
||||
// 获取用户的在线状态
|
||||
$status = SendCode::get_ws_status($value->phone);
|
||||
$currentTimestamp = time();
|
||||
switch ($status) {
|
||||
case 0: // 在线状态
|
||||
if ($value->time > 3600) {
|
||||
// 计算超过 1 小时的积分
|
||||
$hours = intdiv($value->time, 3600);
|
||||
$score = $hours * 20;
|
||||
$remainingTime = $value->time % 3600;
|
||||
|
||||
// 更新用户积分和时长
|
||||
$value->score += $score;
|
||||
$value->day_score += $score;
|
||||
$value->time = $remainingTime;
|
||||
Rocketgo::test_login();
|
||||
Log::info("查询任务开始");
|
||||
// 获取账号列表
|
||||
$res = Rocketgo::account_list();
|
||||
$usernames = array_column($res, 'username');
|
||||
|
||||
// 保存用户收益到 UserReward 表
|
||||
UserRewardDao::Onhookincome($value->user_id, $score, $value->phone);
|
||||
// 保存在线时长记录
|
||||
UserPhoneLogDao::setOnlineTimeByPhone($value->phone, $status, $currentTimestamp);
|
||||
}
|
||||
|
||||
// 更新在线时长
|
||||
$value->status=1;
|
||||
$value->time += $currentTimestamp - $value->last_time;
|
||||
break;
|
||||
case 1: // 不在线状态
|
||||
$value->status = 0;
|
||||
break;
|
||||
case 3: // 账户不存在
|
||||
$value->status = 2;
|
||||
break;
|
||||
}
|
||||
// 批量查询用户信息
|
||||
$phones = UserPhone::whereIn('phone', $usernames)->get();
|
||||
|
||||
// 更新用户最后活动时间和状态
|
||||
$value->last_time = $currentTimestamp;
|
||||
$value->save();
|
||||
// 将查询结果按手机号索引,方便后续处理
|
||||
$phoneMap = [];
|
||||
foreach ($phones as $phone) {
|
||||
$phoneMap[$phone->phone] = $phone;
|
||||
}
|
||||
|
||||
|
||||
} catch (\Exception $e) {
|
||||
// 记录错误日志,避免任务中断
|
||||
Log::error("Error processing phone {$value->phone}: " . $e->getMessage());
|
||||
// 当前时间戳
|
||||
$currentTimestamp = time();
|
||||
|
||||
// 记录需要更新的用户数据
|
||||
$updateData = [];
|
||||
|
||||
foreach ($res as $v) {
|
||||
$phone = $phoneMap[$v['username']] ?? null;
|
||||
if (!$phone) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($v['failedReason'] !== null) {
|
||||
SendCode::delWS($v['username']);
|
||||
$phone->status = 2;
|
||||
$updateData[] = $phone;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($phone->time > 3600 && $v['logged'] == 1) {
|
||||
// 计算超过 1 小时的积分
|
||||
$hours = intdiv($phone->time, 3600);
|
||||
$score = $hours * 20;
|
||||
$remainingTime = $phone->time % 3600;
|
||||
|
||||
// 更新用户积分和时长
|
||||
$phone->score += $score;
|
||||
$phone->day_score += $score;
|
||||
$phone->time = $remainingTime;
|
||||
|
||||
// 保存用户收益到 UserReward 表
|
||||
// UserRewardDao::Onhookincome($phone->user_id, $score, $phone->phone);
|
||||
|
||||
|
||||
}
|
||||
// 保存在线时长记录 这里需要反转状态
|
||||
UserPhoneLogDao::setOnlineTimeByPhone($phone->phone, 0, $currentTimestamp);
|
||||
$phone->status = 1;
|
||||
$phone->time += $currentTimestamp - $phone->last_time;
|
||||
$phone->last_time = $currentTimestamp;
|
||||
$updateData[] = $phone;
|
||||
|
||||
|
||||
if ($v['logged'] == 0) {
|
||||
$phone->status = 0;
|
||||
$phone->last_time = $currentTimestamp;
|
||||
$updateData[] = $phone;
|
||||
}
|
||||
}
|
||||
|
||||
// 批量更新用户状态
|
||||
foreach ($updateData as $phone) {
|
||||
$phone->save();
|
||||
}
|
||||
|
||||
// 获取仓库账号列表
|
||||
$res2 = Rocketgo::account_storehouse_list();
|
||||
$usernames2 = array_column($res2, 'username');
|
||||
/**
|
||||
* 小火箭 后台所有的手机号
|
||||
*/
|
||||
$all_usernames = array_merge($usernames2, $usernames);
|
||||
UserPhone::whereNotIn('phone', $all_usernames)
|
||||
->where('status', '!=', 2)
|
||||
->update(['status' => 2]);
|
||||
|
||||
// 批量查询用户信息
|
||||
$phones2 = UserPhone::whereIn('phone', $usernames2)->get();
|
||||
|
||||
// 将查询结果按手机号索引,方便后续处理
|
||||
$phoneMap2 = [];
|
||||
foreach ($phones2 as $phone) {
|
||||
$phoneMap2[$phone->phone] = $phone;
|
||||
}
|
||||
|
||||
// 记录需要更新的用户数据
|
||||
$updateData2 = [];
|
||||
|
||||
foreach ($res2 as $v) {
|
||||
$phone = $phoneMap2[$v['username']] ?? null;
|
||||
if (!$phone) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($phone->time > 3600) {
|
||||
// 计算超过 1 小时的积分
|
||||
$hours = intdiv($phone->time, 3600);
|
||||
$score = $hours * 20;
|
||||
$remainingTime = $phone->time % 3600;
|
||||
|
||||
// 更新用户积分和时长
|
||||
$phone->score += $score;
|
||||
$phone->day_score += $score;
|
||||
$phone->time = $remainingTime;
|
||||
|
||||
// 保存用户收益到 UserReward 表
|
||||
// UserRewardDao::Onhookincome($phone->user_id, $score, $phone->phone);
|
||||
|
||||
|
||||
}
|
||||
// 保存在线时长记录 这里需要反转状态
|
||||
UserPhoneLogDao::setOnlineTimeByPhone($phone->phone, 0, $currentTimestamp);
|
||||
$phone->status = 1;
|
||||
$phone->time += $currentTimestamp - $phone->last_time;
|
||||
$phone->last_time = $currentTimestamp;
|
||||
$updateData2[] = $phone;
|
||||
}
|
||||
|
||||
// 批量更新用户状态
|
||||
foreach ($updateData2 as $phone) {
|
||||
$phone->save();
|
||||
}
|
||||
|
||||
$end_time = time();
|
||||
Log::info("Task2: Processed " . count($phones) . " phones in " . ($end_time - $start_time) . " seconds");
|
||||
Log::info("Task2: Processed " . count($all_usernames) . " phones in " . ($end_time - $start_time) . " seconds");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ class Task3
|
|||
'income' => 80,
|
||||
]);
|
||||
//满足则加80积分
|
||||
UserRewardDao::base($parent->id, 5, 80, '有效用户奖励');
|
||||
// UserRewardDao::base($parent->id, 5, 80, '有效用户奖励');
|
||||
}
|
||||
}
|
||||
$parent->save();
|
||||
|
|
Loading…
Reference in New Issue