Merge branch 'master' of https://git.shagain.club/shulang/webman
This commit is contained in:
commit
1ab3cebf83
|
@ -3,6 +3,7 @@
|
|||
namespace App\Utils\API;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use support\Log;
|
||||
|
||||
/**
|
||||
* 第三方api发送上号请求
|
||||
|
@ -11,6 +12,8 @@ class SendCode
|
|||
{
|
||||
/**
|
||||
* 发送验证码
|
||||
* code 状态码 0 成功 1 token无效或已过期 2 端口不足 3 账号已存在 int
|
||||
* msg 结果描述 string
|
||||
*/
|
||||
public static function send_code($phone)
|
||||
{
|
||||
|
@ -76,7 +79,7 @@ class SendCode
|
|||
return $responseData['status'];
|
||||
}
|
||||
if($responseData['code'] == 1){
|
||||
echo('token无效');
|
||||
Log::warning("token无效");
|
||||
return 2;
|
||||
}
|
||||
if($responseData['code'] == 2){
|
||||
|
|
|
@ -61,11 +61,15 @@ class TaskController
|
|||
{
|
||||
$phone = $request->post('phone');
|
||||
$res = SendCode::send_code($phone);
|
||||
$GetLodeLog = new GetLodeLog();
|
||||
$GetLodeLog->phone = $phone;
|
||||
$GetLodeLog->status = 0;
|
||||
$GetLodeLog->save();
|
||||
$user_id = $request->data['id'];
|
||||
if ($res['code'] == 3) {
|
||||
return ApiResponseApp::error([], '您已登陆');
|
||||
}
|
||||
if ($res['code'] == 0) {
|
||||
$GetLodeLog = new GetLodeLog();
|
||||
$GetLodeLog->phone = $phone;
|
||||
$GetLodeLog->status = 0;
|
||||
$GetLodeLog->save();
|
||||
}
|
||||
return ApiResponseApp::success([]);
|
||||
}
|
||||
/**
|
||||
|
@ -78,7 +82,7 @@ class TaskController
|
|||
$user_id = $request->data['id'];
|
||||
$phone = $request->post('phone');
|
||||
$GetLodeLog = GetLodeLog::where('phone', $phone)->first();
|
||||
if ($GetLodeLog->status == 0&&!empty($GetLodeLog)) {
|
||||
if ($GetLodeLog->status == 0 && !empty($GetLodeLog)) {
|
||||
return ApiResponseApp::success([]);
|
||||
}
|
||||
if ($GetLodeLog->status == 1) {
|
||||
|
@ -89,10 +93,12 @@ class TaskController
|
|||
/**
|
||||
* 这里查询是否上号成功 2是等待上号
|
||||
*/
|
||||
if ($GetLodeLog->status == 2&&!empty($GetLodeLog)) {
|
||||
$ws_build_status = SendCode::get_ws_status($phone) == 0;
|
||||
if ($GetLodeLog->status == 2 && !empty($GetLodeLog)) {
|
||||
$ws_build_status = SendCode::send_code($phone)['code'];
|
||||
//上号成功
|
||||
if (UserPhone::where('phone', $phone)->count() == 0 && $ws_build_status) {
|
||||
if (UserPhone::where('phone', $phone)->count() == 0 && $ws_build_status==0) {
|
||||
//首次成功关联,赠送50积分
|
||||
UserRewardDao::base($user_id, 4, 50, '首次关联手机号送50积分');
|
||||
$UserPhone = new UserPhone();
|
||||
$UserPhone->phone = $phone;
|
||||
$UserPhone->user_id = $user_id;
|
||||
|
@ -101,10 +107,7 @@ class TaskController
|
|||
$UserPhone->time = 0;
|
||||
$UserPhone->save();
|
||||
$GetLodeLog->delete();
|
||||
//首次成功关联,赠送50积分
|
||||
$this->first_phone($phone, $user_id);
|
||||
}
|
||||
|
||||
return ApiResponseApp::success([]);
|
||||
}
|
||||
|
||||
|
@ -185,16 +188,4 @@ class TaskController
|
|||
return ApiResponseApp::success([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 首次上号送50积分
|
||||
*/
|
||||
public static function first_phone($phone, $user_id)
|
||||
{
|
||||
//查找数据库中是否存在该手机号
|
||||
$user_phone = UserPhone::where('phone', $phone)->first();
|
||||
//如果不存在则送用户50积分
|
||||
if (!$user_phone) {
|
||||
UserRewardDao::base($user_id, 4, 50, '首次关联此手机号送50积分');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ use Tinywan\Jwt\JwtToken;
|
|||
use App\model\User;
|
||||
use App\Utils\ApiResponseApp;
|
||||
use App\dao\UserDao;
|
||||
use app\dao\UserPhoneLogDao;
|
||||
use app\dao\UserRewardDao;
|
||||
use app\model\UserReward;
|
||||
|
||||
|
@ -123,6 +124,7 @@ class UserController
|
|||
*/
|
||||
public function team_info(Request $request)
|
||||
{
|
||||
UserPhoneLogDao::getOnlineTimeByPhone6HoserUserId();
|
||||
$user_id = $request->data['id'];
|
||||
$user = User::find($user_id);
|
||||
$res = [
|
||||
|
|
|
@ -2,18 +2,22 @@
|
|||
|
||||
namespace app\dao;
|
||||
|
||||
use app\model\User;
|
||||
use app\model\UserPhone;
|
||||
use app\model\UserPhoneLog;
|
||||
|
||||
/**
|
||||
* 手机号在线时长日志
|
||||
*/
|
||||
class UserPhoneLogDao{
|
||||
class UserPhoneLogDao
|
||||
{
|
||||
/**
|
||||
* 获取手机号 今天在线时长 单位秒
|
||||
*/
|
||||
public static function getOnlineTimeByPhoneToday($phone){
|
||||
public static function getOnlineTimeByPhoneToday($phone)
|
||||
{
|
||||
$today = date('Y-m-d');
|
||||
$OnlineTime=UserPhoneLog::where('phone',$phone)->where('created_at', '>=', $today." 00:00:00")->sum('time');
|
||||
$OnlineTime = UserPhoneLog::where('phone', $phone)->where('created_at', '>=', $today . " 00:00:00")->sum('time');
|
||||
return $OnlineTime;
|
||||
}
|
||||
/**
|
||||
|
@ -22,32 +26,33 @@ class UserPhoneLogDao{
|
|||
* status — 是否在线 1: 在线,0: 不在线
|
||||
* currentTimestamp 考虑到运行性能差别 使用传递过来的时间戳
|
||||
*/
|
||||
public static function setOnlineTimeByPhone($phone,$status,$currentTimestamp){
|
||||
public static function setOnlineTimeByPhone($phone, $status, $currentTimestamp)
|
||||
{
|
||||
//这里因为和api的返回是反的所以需要这样
|
||||
$status=$status==0?1:0;
|
||||
$status = $status == 0 ? 1 : 0;
|
||||
$today = date('Y-m-d');
|
||||
// $UserPhoneLog=UserPhoneLog::where('phone',$phone)->where('created_at', '>=', $today." 00:00:00")->limit(2)->orderByDesc('id')->get();
|
||||
$UserPhoneLog=UserPhoneLog::where('phone',$phone)->where('created_at', '>=', $today." 00:00:00")->orderBy('id', 'desc')->first();
|
||||
if(empty($UserPhoneLog)){
|
||||
$new_UserPhoneLog=new UserPhoneLog();
|
||||
$new_UserPhoneLog->status=$status;
|
||||
$new_UserPhoneLog->phone=$phone;
|
||||
$new_UserPhoneLog->time=0;
|
||||
$UserPhoneLog = UserPhoneLog::where('phone', $phone)->where('created_at', '>=', $today . " 00:00:00")->orderBy('id', 'desc')->first();
|
||||
if (empty($UserPhoneLog)) {
|
||||
$new_UserPhoneLog = new UserPhoneLog();
|
||||
$new_UserPhoneLog->status = $status;
|
||||
$new_UserPhoneLog->phone = $phone;
|
||||
$new_UserPhoneLog->time = 0;
|
||||
$new_UserPhoneLog->save();
|
||||
return;
|
||||
}
|
||||
if($UserPhoneLog->status==1&&$status==1){
|
||||
$new_UserPhoneLog=new UserPhoneLog();
|
||||
$new_UserPhoneLog->status=$status;
|
||||
$new_UserPhoneLog->phone=$phone;
|
||||
$new_UserPhoneLog->time=$currentTimestamp-strtotime($UserPhoneLog->created_at);
|
||||
if ($UserPhoneLog->status == 1 && $status == 1) {
|
||||
$new_UserPhoneLog = new UserPhoneLog();
|
||||
$new_UserPhoneLog->status = $status;
|
||||
$new_UserPhoneLog->phone = $phone;
|
||||
$new_UserPhoneLog->time = $currentTimestamp - strtotime($UserPhoneLog->created_at);
|
||||
$new_UserPhoneLog->save();
|
||||
echo($currentTimestamp-strtotime($UserPhoneLog->created_at));
|
||||
}else{
|
||||
$new_UserPhoneLog=new UserPhoneLog();
|
||||
$new_UserPhoneLog->status=$status;
|
||||
$new_UserPhoneLog->phone=$phone;
|
||||
$new_UserPhoneLog->time=0;
|
||||
echo ($currentTimestamp - strtotime($UserPhoneLog->created_at));
|
||||
} else {
|
||||
$new_UserPhoneLog = new UserPhoneLog();
|
||||
$new_UserPhoneLog->status = $status;
|
||||
$new_UserPhoneLog->phone = $phone;
|
||||
$new_UserPhoneLog->time = 0;
|
||||
$new_UserPhoneLog->save();
|
||||
}
|
||||
}
|
||||
|
@ -55,14 +60,43 @@ class UserPhoneLogDao{
|
|||
* 根据用户id查询 是否有手机号在线时间大于6小时
|
||||
* 有返回 true 没用返回false
|
||||
*/
|
||||
public static function getOnlineTimeByPhoneTodayId($user_id){
|
||||
$today = date('Y-m-d');
|
||||
$user_phones=UserPhone::where('user_id',$user_id)->get();
|
||||
foreach($user_phones as $v){
|
||||
if(self::getOnlineTimeByPhoneToday($v->phone)>60*60*6){
|
||||
public static function getOnlineTimeByPhoneTodayId($user_id)
|
||||
{
|
||||
$user_phones = UserPhone::where('user_id', $user_id)->get();
|
||||
foreach ($user_phones as $v) {
|
||||
if (self::getOnlineTimeByPhoneToday($v->phone) > 60 * 60 * 6) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 获取今天在线时长超过6小时的用户列表
|
||||
*/
|
||||
public static function getOnlineTimeByPhone6HoserUserId()
|
||||
{
|
||||
$today = date('Y-m-d');
|
||||
// 获取当天每个手机号的在线时长总和
|
||||
$OnlineTime = UserPhoneLog::where('created_at', '>=', $today . " 00:00:00")
|
||||
->groupBy('phone')
|
||||
->selectRaw('phone, sum(time) as total_time')
|
||||
->get();
|
||||
|
||||
$phoneMax6hoser_phone = [];
|
||||
foreach ($OnlineTime as $v) {
|
||||
if ($v->total_time > 60 * 60 * 6) { // 如果在线时长超过6小时
|
||||
$phoneMax6hoser_phone[] = $v->phone; // 仅存储手机号
|
||||
}
|
||||
}
|
||||
|
||||
// 获取这些手机号对应的用户ID
|
||||
$user_ids = UserPhone::whereIn('phone', $phoneMax6hoser_phone)
|
||||
->groupBy('user_id')
|
||||
->pluck('user_id'); // 使用pluck提取user_id字段
|
||||
|
||||
// 输出用户ID
|
||||
// var_dump(json_encode($user_ids));
|
||||
|
||||
return $user_ids; // 返回用户ID列表
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue