webman/app/controller/api/TaskController.php

225 lines
7.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\controller\api;
use app\dao\UserDao;
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\model\PhoneLog;
use App\Utils\API\SendCode;
use App\Utils\ApiResponseApp;
use App\dao\UserRewardDao;
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'];
//挂机总时长 单位秒
$res['time'] = UserDao::Totalduration($user_id);
//今天积分=0;
$res['today_money'] = UserDao::today_task_income($user_id);
//昨天积分
$res['yesterday_money'] = UserDao::today_task_income_old($user_id);
return ApiResponseApp::success($res);
}
/**
* @Apidoc\Title("1.0 发送验证码 ")
* @Apidoc\Url("api/task/send_code")
* @Apidoc\Method("POST")
*
*/
public function send_code(Request $request)
{
$phone = $request->post('phone');
$res = SendCode::send_code($phone);
if ($res['code'] == 3) {
return ApiResponseApp::error([], '您已登陆');
}
if ($res['code'] == 0) {
//删除以前未登录成功的日志
$GetLodeLog = GetLodeLog::where('phone', $phone)->delete();
$GetLodeLog = new GetLodeLog();
$GetLodeLog->phone = $phone;
$GetLodeLog->status = 0;
$GetLodeLog->save();
}
return ApiResponseApp::success([]);
}
/**
* @Apidoc\Title("1.0 获取验证码")
* @Apidoc\Url("api/task/send_code")
* @Apidoc\Method("POST")
*/
public function get_code(Request $request)
{
$user_id = $request->data['id'];
$phone = $request->post('phone');
// 获取对应手机号的加载日志
$GetLodeLog = GetLodeLog::where('phone', $phone)->first();
if(is_null($GetLodeLog)){
//应该是不会出现没获取验证码就getcode
// return ApiResponseApp::error([],'请发送验证码');
return ApiResponseApp::success([]);
}
// 如果状态是 0表示验证码未使用直接返回成功
if ($GetLodeLog->status == 0) {
return ApiResponseApp::success([]);
}
// 如果状态是 1表示验证码已使用更新状态为 2 并返回验证码
if ($GetLodeLog->status == 1) {
$GetLodeLog->status = 2;
$GetLodeLog->save();
return ApiResponseApp::success(['code' => $GetLodeLog->code]);
}
// 状态为 2表示正在等待上号检查上号状态
if ($GetLodeLog->status == 2) {
$ws_build_status = SendCode::get_ws_status($phone);
// 如果上号成功
if ($ws_build_status == 0) {
// 查询本地是否存在该手机号
$UserPhone = UserPhone::where('phone', $phone)->first();
// 如果手机号不在本地数据库中,说明是全新手机号
if (is_null($UserPhone)) {
// 如果该用户没有关联手机号,首次关联赠送积分
if (UserPhone::where('user_id', $user_id)->count() == 0) {
UserRewardDao::base($user_id, 4, 50, '首次关联手机号送50积分');
$UserPhone = new UserPhone();
$UserPhone->phone = $phone;
$UserPhone->user_id = $user_id;
$UserPhone->score = 0;
$UserPhone->status = 1;
$UserPhone->time = 0;
$UserPhone->last_time = time();
$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();
}
return ApiResponseApp::success([]);
}
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([]);
}
}