开启多线程 异步判断ws账户是否在线 ws在线时间折换成积分

This commit is contained in:
lingling 2025-02-16 19:34:37 +08:00
parent b2079e5cbb
commit 9f6e98cd74
18 changed files with 1041 additions and 28 deletions

View File

@ -0,0 +1,80 @@
<?php
namespace App\Utils\API;
use GuzzleHttp\Client;
/**
* 第三方api发送上号请求
*/
class SendCode
{
/**
* 发送验证码
*/
public static function send_code($phone)
{
$client = new Client(); // 创建 Guzzle 客户端
// 请求数据
$data = [
"token" => "druid_6aa47680-56e6-423f-866d-e190700725fd",
"phoneNumber" => $phone,
"business" => 0,
];
// 发送 POST 请求
$response = $client->post('https://dx1.rocketgo.vip/ex-api/biz/api/merchant/scanCode', [
'json' => $data, // 以 JSON 格式发送数据
]);
// 获取响应体内容
$body = $response->getBody();
$responseData = json_decode($body, true); // 如果返回的是 JSON 格式,解析它
return $responseData;
}
/**
* 获取验证码
*/
public static function get_code($phone)
{
$client = new Client(); // 创建 Guzzle 客户端
// 请求数据
$data = [
"token" => "druid_6aa47680-56e6-423f-866d-e190700725fd",
"phoneNumber" => $phone,
];
// 发送 POST 请求
$response = $client->post('https://dx1.rocketgo.vip/ex-api/biz/api/merchant/getScanCode', [
'json' => $data, // 以 JSON 格式发送数据
]);
// 获取响应体内容
$body = $response->getBody();
$responseData = json_decode($body, true); // 如果返回的是 JSON 格式,解析它
return $responseData;
}
/**
* 检测是否在线
* https://apifox.com/apidoc/shared-c08671dd-4e9d-44dd-a2a1-ec4b8316a81f
* 0 在线 1不在线
*/
public static function get_ws_status($phone)
{
$client = new Client(); // 创建 Guzzle 客户端
$url = "https://dx1.rocketgo.vip/ex-api/biz/api/wsStatus?wsNumber=" . $phone . "&token=druid_6aa47680-56e6-423f-866d-e190700725fd";
// 发送 POST 请求
$response = $client->get("$url");
$body = $response->getBody();
$responseData = json_decode($body, true); // 如果返回的是 JSON 格式,解析它
if($responseData['code']==0){
return $responseData['status'];
}
return -1;
}
}

View File

@ -54,6 +54,21 @@ class CommonController
/**
* @Apidoc\Title("1.0 消息根据type 判断类型")
* @Apidoc\Url("api/common/messageList")
* 3是首页弹窗 1是消息中心
* {
"data": [
{
"id": 2,
"title": "Announcement",
"content": "<p><img src=\"https://112233job.com/uploads/20250120/039faa1fb225ef5814a325218f2e00ee.jpg\" data-filename=\"filename\" style=\"width: 277.516px; height: 275.69px;\"><br></p>",
"status": 1,
"createtime": 1737370611,
"updatetime": 0,
"status_text": "Status 1"
}
],
"total": 0
}
* @Apidoc\Method("POST")
*/
public function messageList(Request $request){

View File

@ -0,0 +1,52 @@
<?php
namespace app\controller\api;
use support\Request;
use App\Utils\ApiResponseApp;
use App\model\User;
use App\dao\UserRewardDao;
use hg\apidoc\annotation as Apidoc;
use support\Db;
/**
* @Apidoc\Title("用户收益控制器?")
*/
class Money_logController
{
protected $noNeedLogin = [];
/**
* @Apidoc\Title("1.0 获取用户收益列表")
* time 0全部时间1今天2昨天3最近七天 需要分页page: 1 size: 20
* @Apidoc\Url("api/money_log/lists")
* @Apidoc\Method("POST")
*/
public function lists(Request $request)
{
$user_id = $request->data['id'];
$status = $request->post('status');
$time = $request->post('time');
return ApiResponseApp::success(UserRewardDao::search($user_id, $status, $time));
}
/**
* @Apidoc\Title("1.0 消息根据type 判断类型")
* @Apidoc\Url("api/common/messageList")
* @Apidoc\Method("POST")
*/
public function messageList(Request $request)
{
$type = $request->get('type');
/**
* 返回轮播图
*/
if ($type == 5) {
}
}
}

View File

@ -57,6 +57,7 @@ class SignController
*/
public function sign(Request $request)
{
//TODO 这里业务逻辑不清晰不懂
//这里需要根据 业务逻辑判断 能不能签到
$user_id=$request->data['id'];

View File

@ -0,0 +1,177 @@
<?php
namespace app\controller\api;
use app\model\User;
use support\Request;
use App\Utils\ApiResponse;
use App\model\Carousel;
use App\model\Project;
use App\model\ProjectDetailed;
use App\model\ProjectRegister;
use App\model\Carouselad;
use app\model\GetLodeLog;
use app\model\UserPhone;
use App\model\VipLevel;
use App\Utils\API\SendCode;
use App\Utils\ApiResponseApp;
use Tinywan\Jwt\JwtToken;
use GuzzleHttp\Client;
use hg\apidoc\annotation as Apidoc;
use support\Db;
/**
* @Apidoc\Title("任务控制器")
*/
class TaskController
{
/**
* @Apidoc\Title("1.0 查询当前用户积分")
* @Apidoc\Url("api/task/index")
* @Apidoc\Method("POST")
*/
public function index(Request $request)
{
$user_id = $request->data['id'];
$user = User::find($user_id);
//挂机总时长 单位秒
$res['time'] = 500;
//今天积分=0;
$res['today_money'] = 0;
//昨天积分
$res['yesterday_money'] = 0;
return ApiResponseApp::success($res);
}
/**
* @Apidoc\Title("1.0 发送验证码 ")
* @Apidoc\Url("api/task/send_code")
* @Apidoc\Method("POST")
* 这里是加密无法获得数据结构除非逆向分析
*/
public function send_code(Request $request)
{
$user_id = $request->data['id'];
return ApiResponseApp::success([]);
}
/**
* @Apidoc\Title("1.0 获取验证码")
* @Apidoc\Url("api/task/send_code")
* @Apidoc\Method("POST")
*/
public function get_code(Request $request)
{
$phone = $request->post('phone');
$GetLodeLog = GetLodeLog::where('phone', $phone)->where('status', 0)->count();
// var_dump($GetLodeLog);
if ($GetLodeLog == 0) {
// var_dump('第一次进来');
$res = SendCode::send_code($phone);
$GetLodeLog = new GetLodeLog();
$GetLodeLog->phone = $phone;
$GetLodeLog->status = 0;
$GetLodeLog->save();
} else {
$res = SendCode::get_code($phone);
var_dump($res);
if ($res['status'] == 1 && $res['scanCode'] != null) {
$GetLodeLog = GetLodeLog::where('phone', $phone)->where('status', 0)->first();
$GetLodeLog->status = 1;
$GetLodeLog->delete();
$user_id = $request->data['id'];
if (UserPhone::where('phone', $phone)->count() == 0) {
$UserPhone = new UserPhone();
$UserPhone->phone = $phone;
$UserPhone->user_id = $user_id;
$UserPhone->score = 0;
$UserPhone->status = 0;
$UserPhone->time = 0;
$UserPhone->save();
}
return ApiResponseApp::success(['code' => $res['scanCode']]);
}
}
return ApiResponseApp::success([]);
}
/**
* @Apidoc\Title("1.0 返回用户ws号在线状态")
* @Apidoc\Url("api/task/phone_list")
* @Apidoc\Method("POST")
*/
public static function phone_list(Request $request)
{
$user_id = $request->data['id'];
$user = User::find($user_id);
$user_phones = UserPhone::where('user_id', $user_id)->get();
$res = [];
foreach ($user_phones as $key => $value) {
$data = [
'id' => $value->id,
'username' => $user->username,
'user_id' => $value->user_id,
//ws手机号
'phone' => $value->phone,
//积分
'score' => $value->score,
//当前在线状态 1在线0不在线
'status' => $value->status,
//创建时间
'createtime' => 1739275956,
//最后在线时间?
'last_time' => 1739564458,
//应该是在线时间单位 秒
'time' => $value->time,
'back_times' => 80,
'updatetime' => 1739564458,
'login_success' => 1,
'priority' => 0,
//备注
'remark' => $value->remark,
'proxy' => '154.200.10.132:6051',
'smscode' => '12345678',
'smsstatus' => null,
'send_count' => 8,
'del' => 0,
'send_time' => 0,
'today_count' => 0,
'last_sent_time' => 1739564482,
'uu_id' => $user->invite_code,
'quhao' => '',
'proxy_id' => 10782,
'device_name' => 'HK4-10264D',
//任务状态?
'task_status' => 1,
'status_text' => 'Status 1',
'last_time_text' => '2025-02-15 04:20:58',
'hang_up_time_text' => ''
];
$res[] = $data;
}
return ApiResponseApp::success($res);
}
/**
* @Apidoc\Title("1.0 设置用户ws号码备注名")
* @Apidoc\Url("api/task/edit_phone")
* @Apidoc\Method("POST")
*/
public static function edit_phone(Request $request)
{
// phone: 601160880622
// remark: 4
$phone = $request->post('phone');
$remark = $request->post('remark');
$user_id = $request->data['id'];
$user_phones = UserPhone::where('user_id', $user_id)->where('phone', $phone)->first();
$user_phones->remark = $remark;
$user_phones->save();
return ApiResponseApp::success([]);
}
}

View File

@ -75,11 +75,13 @@ class UserController
return ApiResponseApp::error([], "账号已存在");
}
$f_id = 0;
$ff_id =0;
if (!empty($invitation)) {
if (User::where('invite_code', $invitation)->count() == 0) {
return ApiResponseApp::error([], "代理不存在");
} else {
$f_id = User::where('invite_code', $invitation)->first('id');
$ff_id = User::where('f_id', $$f_id)->first('id');
}
}
$user = new User();
@ -89,6 +91,7 @@ class UserController
}
$user->join_ip = $request->getRealIp($safe_mode = true);
$user->f_id = $f_id;
$user->ff_id = $ff_id;
$user->invite_code = Random::str_random(5);
$user->password = password_hash($password, PASSWORD_DEFAULT);
$user->save();

View File

@ -30,18 +30,91 @@ class Vip_rewardController
/**
* @Apidoc\Title("1.0 获取vip等级赠送积分")
* @Apidoc\Url("api/vip_salary/product")
* @Apidoc\Url("api/vip_reward/product")
* @Apidoc\Method("POST")
*/
public function product(Request $request)
{
$res = VipLevel::all();
return ApiResponseApp::success($res);
$data = [
[
"id" => 1,
"name" => "1",
"user_count" => 3,
"first_amount" => 1500,
"gift_amount" => 150,
"createtime" => 0
],
[
"id" => 2,
"name" => "2",
"user_count" => 5,
"first_amount" => 4000,
"gift_amount" => 380,
"createtime" => 0
],
[
"id" => 3,
"name" => "3",
"user_count" => 10,
"first_amount" => 6000,
"gift_amount" => 580,
"createtime" => 0
],
[
"id" => 4,
"name" => "4",
"user_count" => 20,
"first_amount" => 15000,
"gift_amount" => 1080,
"createtime" => 0
],
[
"id" => 5,
"name" => "5",
"user_count" => 40,
"first_amount" => 40000,
"gift_amount" => 2080,
"createtime" => 0
],
[
"id" => 6,
"name" => "6",
"user_count" => 70,
"first_amount" => 75000,
"gift_amount" => 3800,
"createtime" => 0
],
[
"id" => 7,
"name" => "7",
"user_count" => 200,
"first_amount" => 75000,
"gift_amount" => 10800,
"createtime" => 0
],
[
"id" => 8,
"name" => "8",
"user_count" => 500,
"first_amount" => 75000,
"gift_amount" => 28000,
"createtime" => 0
],
[
"id" => 9,
"name" => "9",
"user_count" => 1000,
"first_amount" => 75000,
"gift_amount" => 58000,
"createtime" => 0
]
];
return ApiResponseApp::success($data);
}
/**
* @Apidoc\Title("1.0 查询当前用户积分")
* @Apidoc\Url("api/vip_salary/need_score")
* @Apidoc\Url("api/vip_reward/need_score")
* @Apidoc\Method("POST")
*/
public function need_score(Request $request)
@ -51,5 +124,81 @@ class Vip_rewardController
$res['score'] = $user->money;
return ApiResponseApp::success($res);
}
/**
* @Apidoc\Title("1.0 获取当前用户vip等级")
* @Apidoc\Url("api/vip_reward/user_count")
* @Apidoc\Method("POST")
*/
public function user_count(Request $request)
{
$user_id=$request->data['id'];
$user=User::find($user_id);
return ApiResponseApp::success(['user_count'=>$user->vip_id]);
}
/**
* @Apidoc\Title("1.0 获取当前用户vip等级")
* @Apidoc\Url("api/vip_reward/check_status")
* @Apidoc\Method("POST")
*/
public function check_status(Request $request)
{
$data = [
[
"vip_id" => 1,
"status" => 0,
'$userCount' => 0,
"user_count" => 3
],
[
"vip_id" => 2,
"status" => 0,
'$userCount' => 0,
"user_count" => 5
],
[
"vip_id" => 3,
"status" => 0,
'$userCount' => 0,
"user_count" => 10
],
[
"vip_id" => 4,
"status" => 0,
'$userCount' => 0,
"user_count" => 20
],
[
"vip_id" => 5,
"status" => 0,
'$userCount' => 0,
"user_count" => 40
],
[
"vip_id" => 6,
"status" => 0,
'$userCount' => 0,
"user_count" => 70
],
[
"vip_id" => 7,
"status" => 0,
'$userCount' => 0,
"user_count" => 200
],
[
"vip_id" => 8,
"status" => 0,
'$userCount' => 0,
"user_count" => 500
],
[
"vip_id" => 9,
"status" => 0,
'$userCount' => 0,
"user_count" => 1000
]
];
return ApiResponseApp::success($data);
}
}

View File

@ -27,7 +27,7 @@ class Vip_salaryController
{
protected $noNeedLogin = ['get_project', 'get_projectdetailed', 'get_mechanism_list'];
/**
* @Apidoc\Title("1.0 获取首页轮播图")
* @Apidoc\Title("1.0 获取当前用户vip等级")
* @Apidoc\Url("api/vip_salary/product")
* @Apidoc\Method("POST")
*/
@ -48,5 +48,39 @@ class Vip_salaryController
return ApiResponseApp::success($res);
}
/**
* @Apidoc\Title("1.0 获取vip等级赠送积分")
* @Apidoc\Url("api/vip_salary/check_status")
* @Apidoc\Method("POST")
*/
public function check_status(Request $request)
{
$data = [
[
"vip_id" => 1,
"status" => 0,
'$userCount' => 0,
"user_count" => 5
],
[
"vip_id" => 2,
"status" => 0,
'$userCount' => 0,
"user_count" => 100
],
[
"vip_id" => 3,
"status" => 0,
'$userCount' => 0,
"user_count" => 1000
],
[
"vip_id" => 4,
"status" => 0,
'$userCount' => 0,
"user_count" => 2000
]
];
return ApiResponseApp::success($data);
}
}

116
app/dao/UserRewardDao.php Normal file
View File

@ -0,0 +1,116 @@
<?php
namespace app\dao;
use App\model\UserReward;
use App\model\BankLog;
use app\model\User;
/**
* 用户收益明细控制类
*/
class UserRewardDao
{
/**
* 注册赠送金额
*/
public static function Register_for_free($userid)
{
self::base($userid, 4, 30, '注册赠送');
}
/**
* 挂机获得的奖励
*/
public static function Onhookincome($userid,$money)
{
self::base($userid, 6, $money, '挂机收益');
}
/**
* 加粉赏金奖励
*/
public static function bounty($userid,$money)
{
self::base($userid, 5, $money, '加粉赏金');
}
/**
* 公共函数
*/
public static function base($userid, $status, $money, $memo,$is_f_bounty=1)
{
$UserReward = new UserReward();
$user = User::find($userid);
$UserReward->user_id = $user->id;
$UserReward->username = $user->username;
$UserReward->uu_id = $user->invite_code;
$UserReward->status = $status;
$UserReward->money = $money;
$UserReward->before = $user->money;
$UserReward->after = $user->money + $money;
$UserReward->memo = $memo;
$UserReward->createtime2 = date('Y-m-d H:i:s');
$user->money = $UserReward->after;
$user->save();
$UserReward->save();
}
/**
* 父级 父父级分红
*/
public static function f_bounty($userid, $status, $money, $memo){
//父分红
$f_dividend=floor($money*0.2);
//父父分红
$ff_dividend=floor($money*0.1);
$user = User::find($userid);
if($user->f_id!=0&&$user->f_id!=0){
$f=User::find($user->f_id);
self::base($f->id, 5, $f_dividend, '加粉赏金');
$ff=User::find($user->ff_id);
self::base($ff->id, 5, $ff_dividend, '加粉赏金');
}
}
/**
* 搜索函数
*
* @param int $userid 用户ID
* @param int $status 类型
* @param int $time 时间段0: 全部时间1: 今天2: 昨天3: 最近七天)
* @return mixed 返回查询结果(可以是数组或查询对象)
*/
public static function search($userid, $status, int $time)
{
// 初始化查询对象
if ($status == 0) {
$query = UserReward::where('user_id', $userid);
} else {
$query = UserReward::where('status', $status)->where('user_id', $userid);
}
switch ($time) {
case 0:
// 全部时间:查询没有时间限制的记录
return $query->get();
case 1:
// 今天:查询今天的记录
$startOfDay = strtotime('today'); // 今天的开始时间00:00:00
return $query->where('created_at', '>=', $startOfDay)->get();
case 2:
// 昨天:查询昨天的记录
$startOfYesterday = strtotime('yesterday'); // 昨天的开始时间00:00:00
$endOfYesterday = strtotime('today') - 1; // 昨天的结束时间23:59:59
return $query->whereBetween('created_at', [$startOfYesterday, $endOfYesterday])->get();
case 3:
// 最近七天:查询过去七天的记录
$sevenDaysAgo = strtotime('-7 days'); // 七天前的时间戳
return $query->where('created_at', '>=', $sevenDaysAgo)->get();
default:
// 如果没有匹配的时间段,返回空结果或其他处理方式
return $query->get();
}
}
}

32
app/model/GetLodeLog.php Normal file
View File

@ -0,0 +1,32 @@
<?php
namespace app\model;
use support\Model;
/**
* @property integer $id ID(主键)
* @property string $phone 手机号
* @property string $code 验证码
* @property integer $status 状态 0已发送 验证码请求 1等待上号 2是已完成
*/
class GetLodeLog extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'get_code_log';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
}

55
app/model/UserPhone.php Normal file
View File

@ -0,0 +1,55 @@
<?php
namespace app\model;
use support\Model;
/**
* 用户WS信息表模型
*
* @property int $id 用户记录的唯一标识符
* @property int $user_id 用户的唯一ID标识符
* @property string $phone 用户手机号WS手机号
* @property int $score 用户积分
* @property int $status 当前在线状态1: 在线0: 不在线)
* @property int $time 用户在线时长(单位:秒)
* @property string|null $remark 用户备注信息
* @property string $created_at 创建时间
* @property string $updated_at 更新时间
* @property string $last_time 最后一次在线时间
*/
class UserPhone extends Model
{
/**
* 表名
*
* @var string
*/
protected $table = 'user_phone';
/**
* 主键
*
* @var string
*/
protected $primaryKey = 'id';
/**
* 是否自动维护时间戳字段
*
* @var bool
*/
public $timestamps = true;
/**
* 表的字段类型
* 这里我们不需要使用数据库中的每个字段的类型声明Webman 模型会自动推导出来
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();
$this->fillable = ['user_id', 'phone', 'score', 'status', 'time', 'remark'];
}
}

107
app/model/UserReward.php Normal file
View File

@ -0,0 +1,107 @@
<?php
namespace app\model;
use support\Model;
/**
* @property int $id 奖励记录的唯一标识符
* @property int $user_id 用户ID
* @property int $order_id 关联订单ID
* @property string $username 用户名(如手机号码)
* @property float $money 奖励积分
* @property float $before 操作前的积分余额
* @property float $after 操作后的积分余额
* @property string $memo 奖励类型或备注信息
* @property int $status 操作类型 1提现扣款 2人工调整 3提现返还 4注册赠送 5加粉赏金 6任务佣金
* @property string $uu_id 用户唯一标识符 这里好像是对应的用户邀请码
* @property string|null $admin_name 管理员名称(如果管理员操作)
* @property string $createtime2 创建时间的格式化日期YYYY-MM-DD HH:MM:SS
*/
class UserReward extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'user_rewards';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
/**
* 数据创建时间,自动转化为格式化的日期
*
* @return string
*/
// public function getCreatetime2Attribute()
// {
// return date('Y-m-d H:i:s', $this->createtime);
// }
/**
* 记录新增奖励
*
* @param array $data 奖励数据
* @return UserReward
*/
public static function createReward(array $data)
{
return self::create($data);
}
/**
* 更新奖励记录
*
* @param int $id 奖励记录的ID
* @param array $data 更新的数据
* @return bool
*/
public static function updateReward(int $id, array $data)
{
$reward = self::find($id);
if ($reward) {
return $reward->update($data);
}
return false;
}
/**
* 根据用户ID查询所有奖励记录
*
* @param int $userId 用户ID
* @param int $status 1提现扣款 2人工调整 3提现返还 4注册赠送 5加粉赏金 6任务佣金
* @return \support\Collection
*/
public static function getByUserId(int $userId,$status)
{
return self::where('user_id', $userId)->where('status', $status)->get();
}
/**
* 根据记录ID查询奖励记录
*
* @param int $id 奖励记录ID
* @return UserReward|null
*/
public static function getById(int $id)
{
return self::find($id);
}
/**
* 根据记录的状态查询奖励记录
*
* @param int $status 奖励记录的状态
* @return \support\Collection
*/
public static function getByStatus(int $status)
{
return self::where('status', $status)->get();
}
}

View File

@ -34,7 +34,9 @@
"vlucas/phpdotenv": "^5.6",
"hg/apidoc": "^5.2",
"hhink/webman-sms": "^1.0",
"simplehtmldom/simplehtmldom": "^2.0@RC"
"simplehtmldom/simplehtmldom": "^2.0@RC",
"guzzlehttp/guzzle": "^7.9",
"workerman/crontab": "^1.0"
},
"suggest": {
"ext-event": "For better performance. "

60
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "2f78aed5a543ee22ae1011edb7e4caa9",
"content-hash": "abda64e112867835ad0472d5a7b86c66",
"packages": [
{
"name": "cakephp/core",
@ -4869,6 +4869,62 @@
},
"time": "2023-03-28T04:01:23+00:00"
},
{
"name": "workerman/crontab",
"version": "v1.0.7",
"source": {
"type": "git",
"url": "https://github.com/walkor/crontab.git",
"reference": "74f51ca8204e8eb628e57bc0e640561d570da2cb"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/walkor/crontab/zipball/74f51ca8204e8eb628e57bc0e640561d570da2cb",
"reference": "74f51ca8204e8eb628e57bc0e640561d570da2cb",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"php": ">=7.0",
"workerman/workerman": ">=4.0.20"
},
"type": "library",
"autoload": {
"psr-4": {
"Workerman\\Crontab\\": "./src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "walkor",
"email": "walkor@workerman.net",
"homepage": "http://www.workerman.net",
"role": "Developer"
}
],
"description": "A crontab written in PHP based on workerman",
"homepage": "http://www.workerman.net",
"keywords": [
"crontab"
],
"support": {
"email": "walkor@workerman.net",
"forum": "http://wenda.workerman.net/",
"issues": "https://github.com/walkor/workerman/issues",
"source": "https://github.com/walkor/crontab",
"wiki": "http://doc.workerman.net/"
},
"time": "2025-01-15T07:20:50+00:00"
},
{
"name": "workerman/webman-framework",
"version": "v1.5.27",
@ -5018,6 +5074,6 @@
"platform": {
"php": ">=7.2"
},
"platform-dev": {},
"platform-dev": [],
"plugin-api-version": "2.6.0"
}

View File

@ -33,10 +33,10 @@ return [
'host' => '127.0.0.1',
'port' => '3306',
'database' => 'app_hd',
// 'username' => 'app_hd',
// 'password' => 'fmW4NwwXMxN8ShSM',
'username' => 'root',
'password' => '123456',
'username' => 'app_hd',
'password' => 'fmW4NwwXMxN8ShSM',
// 'username' => 'root',
// 'password' => '123456',
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_general_ci',
'prefix' => '',

View File

@ -1,4 +1,5 @@
<?php
/**
* This file is part of webman.
*
@ -51,12 +52,22 @@ return [
], glob(base_path() . '/plugin/*/app'), glob(base_path() . '/plugin/*/config'), glob(base_path() . '/plugin/*/api')),
// Files with these suffixes will be monitored
'monitorExtensions' => [
'php', 'html', 'htm', 'env'
'php',
'html',
'htm',
'env'
],
'options' => [
'enable_file_monitor' => !in_array('-d', $argv) && DIRECTORY_SEPARATOR === '/',
'enable_memory_monitor' => DIRECTORY_SEPARATOR === '/',
]
]
]
],
],
'task' => [
'handler' => process\Task::class
],
'task2' => [
'handler' => process\Task2::class
],
];

61
process/Task.php Normal file
View File

@ -0,0 +1,61 @@
<?php
namespace process;
use App\Utils\API\SendCode;
use app\model\UserPhone;
use app\dao\UserRewardDao;
use Workerman\Crontab\Crontab;
/**
* 查询用户是否在线类
*/
class Task
{
public function onWorkerStart()
{
// // 每秒钟执行一次
// new Crontab('*/1 * * * * *', function(){
// echo date('Y-m-d H:i:s')."\n";
// });
// // 每5秒执行一次
// new Crontab('*/5 * * * * *', function(){
// echo date('Y-m-d H:i:s')."\n";
// });
// // 每分钟执行一次
// new Crontab('0 */1 * * * *', function(){
// echo date('Y-m-d H:i:s')."\n";
// });
// // 每5分钟执行一次
// new Crontab('0 */5 * * * *', function(){
// echo date('Y-m-d H:i:s')."\n";
// });
// // 每分钟的第一秒执行
// new Crontab('1 * * * * *', function(){
// echo date('Y-m-d H:i:s')."\n";
// });
// // 每天的7点50执行注意这里省略了秒位
// new Crontab('50 7 * * *', function(){
// echo date('Y-m-d H:i:s')."\n";
// });
// // 每5秒执行一次
new Crontab('0 */1 * * * *', function(){
$phones=UserPhone::all();
foreach($phones as $key =>$value){
//如果大于60秒这里单位是秒就给他20个积分
if($value->time>3600){
$score =intdiv($value->time,3600)*20;
$value->score=$score;
$value->time-=intdiv($value->time,3600)*3600;
$value->save();
UserRewardDao::Onhookincome($value->user_id,$score);
}
}
});
}
}

62
process/Task2.php Normal file
View File

@ -0,0 +1,62 @@
<?php
namespace process;
use App\Utils\API\SendCode;
use app\model\UserPhone;
use app\dao\UserRewardDao;
use Workerman\Crontab\Crontab;
/**
* 查询用户是否在线类
*/
class Task2
{
public function onWorkerStart()
{
// // 每秒钟执行一次
// new Crontab('*/1 * * * * *', function(){
// echo date('Y-m-d H:i:s')."\n";
// });
// // 每5秒执行一次
// new Crontab('*/5 * * * * *', function(){
// echo date('Y-m-d H:i:s')."\n";
// });
// // 每分钟执行一次
// new Crontab('0 */1 * * * *', function(){
// echo date('Y-m-d H:i:s')."\n";
// });
// // 每5分钟执行一次
// new Crontab('0 */5 * * * *', function(){
// echo date('Y-m-d H:i:s')."\n";
// });
// // 每分钟的第一秒执行
// new Crontab('1 * * * * *', function(){
// echo date('Y-m-d H:i:s')."\n";
// });
// // 每天的7点50执行注意这里省略了秒位
// new Crontab('50 7 * * *', function(){
// echo date('Y-m-d H:i:s')."\n";
// });
// // 每5秒执行一次
new Crontab('*/1 * * * * *', function(){
$phones=UserPhone::all();
foreach($phones as $key =>$value){
// var_dump($value->last_time);
if(SendCode::get_ws_status($value->phone)==0){
$currentTimestamp = time();
var_dump($currentTimestamp-$value->last_time);
$value->time=$value->time+$currentTimestamp-$value->last_time;
$value->last_time=$currentTimestamp;
$value->status=1;
$value->save();
}
}
});
}
}