first commit

This commit is contained in:
kizzroyal
2022-02-16 14:01:00 +07:00
commit f876f79060
294 changed files with 92083 additions and 0 deletions

View File

@@ -0,0 +1,156 @@
<?php
namespace App\Console\Commands;
use App\Http\Repositories\AttendanceSessionRepository;
use App\Models\AttendanceSession;
use App\Models\AttendanceSetting;
use App\Models\LichSuChoiMomo;
use App\Models\Setting;
use App\Models\UserAttendanceSession;
use App\Traits\PhoneNumber;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
class HandleBotAttendanceSession extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'command:handle-bot-attendance-session';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* @var \App\Http\Repositories\AttendanceSessionRepository
*/
protected $attendanceSessionRepository;
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
$this->attendanceSessionRepository = new AttendanceSessionRepository();
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
var_dump("Bat dau xu ly luc: ".Carbon::now()->toTimeString());
$isTurnOn = $this->attendanceSessionRepository->checkTurOnAttendance();
if ($isTurnOn) {
$config = $this->attendanceSessionRepository->getAttendanceSetting();
$startTime = isset($config['start_time']) ? Carbon::parse($config['start_time']) : Carbon::parse(TIME_START_ATTENDANCE);
$endTime = isset($config['end_time']) ? Carbon::parse($config['end_time']) : Carbon::parse(TIME_END_ATTENDANCE);
$timeEach = $config['time_each'];
$now = Carbon::now();
if ($now->between($startTime, $endTime)) {
try {
$attendanceSetting = $this->attendanceSessionRepository->getAttendanceSetting();
$attendanceSessionCurrent = AttendanceSession::where('date', Carbon::today()->toDateString())
->orderBy('created_at', "DESC")
// ->where('status', STATUS_ACTIVE)
->first();
$usersAttendance = $this->attendanceSessionRepository->getUsersAttendanceSession($attendanceSessionCurrent);
$phoneUserAttendance = $usersAttendance->pluck('phone')->toArray();
$botRate = $attendanceSetting['bot_rate'] ?? 10;
$bots = $this->attendanceSessionRepository->getRandomBotsAttendance($botRate,
$phoneUserAttendance);
$randomNumberTakeBot = random_int(10, 40);
$phoneBots = collect($bots)
->take(round(($randomNumberTakeBot / 100) * count($bots)))
->pluck("phone")
->toArray();
$countBot = count(collect($bots));
$botHandled = [];
sleep(3);
$realtimeSecond = $this->attendanceSessionRepository->getSecondsRealtime();
$timeRun = $realtimeSecond;
for ($i = 0; $i <= $timeRun; $i++) {
$realtimeSecond = $this->attendanceSessionRepository->getSecondsRealtime();
if (count($botHandled) == count($bots) || $realtimeSecond < 1) {
return Command::SUCCESS;
}
if ($countBot < 50) {
$numberBotInsert = random_int(0, 3);
} else {
$numberBotInsert = random_int(0, 5);
}
Log::warning("BOT INSERT: ".$numberBotInsert);
$botsHandling = collect($phoneBots)->take($numberBotInsert)->toArray();
foreach ($botsHandling as $index => $phoneBot) {
DB::table('users_attendance_session')->insert([
'phone' => $phoneBot,
'session_id' => $attendanceSessionCurrent->id,
'created_at' => Carbon::now(),
'updated_at' => Carbon::now(),
]);
unset($phoneBots[array_search($phoneBot, $phoneBots)]);
}
$botHandled = array_merge($botHandled, $botsHandling);
$sleepWithTimeEach = $this->getSleepSecondByTimeEach($timeEach);
$maxSleep = $realtimeSecond < $sleepWithTimeEach[1] ? $realtimeSecond - 1 : $sleepWithTimeEach[1];
$minSleep = $maxSleep < $sleepWithTimeEach[0] ? 1 : $sleepWithTimeEach[0];
var_dump($minSleep, $maxSleep, $realtimeSecond);
$sleepInt = random_int($minSleep, $maxSleep);
var_dump("sleep:".$sleepInt);
sleep($sleepInt);
// } else {
// sleep(random_int(1, 3));
// }
}
var_dump("Xu ly xong luc: ".Carbon::now()->toTimeString());
return Command::SUCCESS;
} catch (\Throwable $throwable) {
Log::info($throwable);
}
}
}
}
private function getSleepSecondByTimeEach($timeEach)
{
switch ($timeEach) {
case 60:
default;
return [2, 5];
case 180:
return [5, 10];
case 300:
return [10, 30];
case 600:
return [15, 75];
case 900:
return [15, 90];
case 1200:
return [15, 120];
case 1800:
return [60, 180];
case 3600:
return [60, 360];
case 21600:
return [120, 600];
case 86400:
return [600, 3600];
}
}
}

View File

@@ -0,0 +1,221 @@
<?php
namespace App\Console\Commands;
use App\Http\Repositories\AttendanceSessionRepository;
use App\Models\AccountMomo;
use App\Models\AttendanceSetting;
use App\Models\LichSuChoiMomo;
use App\Models\Setting;
use App\Traits\PhoneNumber;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Queue\Listener;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
class HandleUserWinAttendanceSession extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'command:handle-user-win-attendance-session';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* @var \App\Http\Repositories\AttendanceSessionRepository
*/
protected $attendanceSessionRepository;
/**
* @var \App\Traits\PhoneNumber
*/
protected $convertPhoneNumber;
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
$this->attendanceSessionRepository = new AttendanceSessionRepository();
$this->convertPhoneNumber = new PhoneNumber();
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
var_dump("Bat dau xu ly luc: ".Carbon::now()->toTimeString());
// Log::info("Bat dau xu ly luc: ".Carbon::now()->toTimeString());
try {
$isTurnOn = $this->attendanceSessionRepository->checkTurOnAttendance();
if ($isTurnOn) {
$realtimeSecond = $this->attendanceSessionRepository->getSecondsRealtime();
$timeRun = $realtimeSecond;
for ($i = 0; $i < $timeRun; $i++) {
$realtimeSecond = $this->attendanceSessionRepository->getSecondsRealtime();
// Log::info("Chay :".$realtimeSecond);
if ($realtimeSecond > 1) {
sleep(1);
// $realtimeSecond--;
continue;
} else {
$config = $this->attendanceSessionRepository->getAttendanceSetting();
$startTime = isset($config['start_time']) ? Carbon::parse($config['start_time']) : Carbon::parse(TIME_START_ATTENDANCE);
$endTime = isset($config['end_time']) ? Carbon::parse($config['end_time']) : Carbon::parse(TIME_END_ATTENDANCE);
// Log::info("Chay :".$realtimeSecond);
$now = Carbon::now();
if ($now->between($startTime, $endTime)) {
$currentAttendanceSession = $this->attendanceSessionRepository->getCurrentAttendanceSession();
$usersAttendance = $this->attendanceSessionRepository->getUsersAttendanceSession($currentAttendanceSession);
// Log::info("Count users: ".count($usersAttendance));
if (count($usersAttendance) == 0) {
return Command::SUCCESS;
}
$this->attendanceSessionRepository->createNewAttendanceSession($currentAttendanceSession);
$randomInt = random_int(1, 10);
$billCode = 'AUTO-'.bin2hex(random_bytes(3)).time().'-CLUB';
$amount = random_int($config['money_min'] ?? MONEY_MIN_WIN_ATTENDANCE,
$config['money_max'] ?? MONEY_MAX_WIN_ATTENDANCE);
$winRate = isset($config['win_rate']) ? $config['win_rate'] / 10 : ATTENDANCE_WIN_RATE_DEFAULT;
$usersAttendance = $usersAttendance->transform(function($userAtten) {
$userAtten->phone = $this->convertPhoneNumber->convert($userAtten->phone);
return $userAtten;
});
if ($randomInt > $winRate) {
$phoneWin = $this->handleBotWin($usersAttendance);
} else {
$phoneWin = $this->handleUserWin($usersAttendance, $billCode,
$amount);
}
Log::info($phoneWin);
$currentAttendanceSession->update([
'phone' => $phoneWin,
'amount' => $amount,
'bill_code' => $billCode,
]);
break;
}
}
}
}
Log::info("DONE!!!");
var_dump("Xu ly xong luc: ".Carbon::now()->toTimeString());
return Command::SUCCESS;
} catch (\Throwable $throwable) {
Log::info($throwable);
}
}
/**
* @return mixed
*/
public function getUserLichSuMomo()
{
return LichSuChoiMomo::where('created_at', '>=', Carbon::today())->get();
}
/**
* @param $usersAttendance
* @param string $billCode
* @param int $amount
*
* @return mixed|null
* @throws \Exception
*/
private function handleUserWin($usersAttendance, string $billCode, int $amount)
{
$usersMomo = $this->getUserLichSuMomo();
$usersMomo = $usersMomo->transform(function($user) {
$user->phone = $this->convertPhoneNumber->convert($user->sdt);
return $user;
});
$usersMomoPhone = $usersMomo->pluck('phone')->unique()->toArray();
$usersAttendance = $usersAttendance->filter(function($userAttendance) use (
$usersMomoPhone
) {
return in_array($userAttendance->phone, $usersMomoPhone);
});
$phoneUsersAttendance = $usersAttendance->pluck('phone')->toArray();
$countPhoneUsersAttendance = count($phoneUsersAttendance) > 0 ? count($phoneUsersAttendance) - 1 : 0;
$phoneWin = $phoneUsersAttendance[random_int(0,
$countPhoneUsersAttendance)] ?? null;
if (is_null($phoneWin)) {
$phoneWin = $this->handleBotWin($usersAttendance);
} else {
$phoneGet = $this->getPhoneAccountMomo();
// Log::info("set phone win");
$attendanceSetting = AttendanceSetting::first();
$setPhoneWin = $attendanceSetting->setphonewin;
if($setPhoneWin != null || $setPhoneWin != ''){
$phoneWin = $setPhoneWin;
AttendanceSetting::first()->update(['setphonewin' => null]);
}
// Log::info("end phone win");
DB::table('lich_su_choi_momos')->insert([
'sdt' => $phoneWin,
'sdt_get' => $phoneGet,
'magiaodich' => $billCode,
'tiencuoc' => 0,
'tiennhan' => $amount,
'trochoi' => "DIEM DANH",
'noidung' => "DD",
'ketqua' => 1,
'status' => STATUS_LSMOMO_CHUA_THANH_TOAN,
'created_at' => Carbon::now(),
'updated_at' => Carbon::now(),
]);
}
return $phoneWin;
}
/**
* @param $usersAttendance
*
* @return int|mixed
* @throws \Exception
*/
public function handleBotWin($usersAttendance)
{
$phoneBots = $this->attendanceSessionRepository->getPhoneAttendanceSessionBots();
$phonesUserAttendance = $usersAttendance->pluck('phone')->toArray();
$phoneBotsWin = array_values(array_intersect($phoneBots, $phonesUserAttendance));
if (count($phoneBotsWin) > 0) {
$phoneBotWin = $phoneBotsWin[random_int(0, count($phoneBotsWin) - 1)];
} else {
$phoneBotWin = $phoneBots[random_int(0, count($phoneBots) - 1)];
}
return $phoneBotWin;
}
/**
* @return mixed
*/
private function getPhoneAccountMomo()
{
$cache = Cache::get('cache_get_sdt_account_momo');
if (!is_null($cache)) {
return $cache;
}
$account = AccountMomo::where('status', '1')->first();
$phone = $account->sdt;
Cache::put('cache_get_sdt_account_momo', $phone, Carbon::now()->addMinutes(10));
return $phone;
}
}

46
app/Console/Kernel.php Normal file
View File

@@ -0,0 +1,46 @@
<?php
namespace App\Console;
use App\Console\Commands\HandleBotAttendanceSession;
use App\Console\Commands\HandleUserWinAttendanceSession;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
HandleUserWinAttendanceSession::class,
HandleBotAttendanceSession::class
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('command:handle-bot-attendance-session')->everyMinute()->withoutOverlapping();
$schedule->command('command:handle-user-win-attendance-session')->everyMinute()->withoutOverlapping();
}
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace App\Exceptions;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable;
class Handler extends ExceptionHandler
{
/**
* A list of the exception types that are not reported.
*
* @var array
*/
protected $dontReport = [
//
];
/**
* A list of the inputs that are never flashed for validation exceptions.
*
* @var array
*/
protected $dontFlash = [
'current_password',
'password',
'password_confirmation',
];
/**
* Register the exception handling callbacks for the application.
*
* @return void
*/
public function register()
{
$this->reportable(function (Throwable $e) {
//
});
}
}

View File

@@ -0,0 +1,117 @@
<?php
namespace App\Http\Controllers;
use App\Http\Repositories\AccountMomoRepository;
use App\Models\AccountLevelMoney;
use App\Models\AccountMomo;
use Carbon\Carbon;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Session;
use stdClass;
class AccountLevelMoneyController extends Controller
{
public function __construct()
{
}
//
public function index()
{
$GetSetting = new stdClass;
$accountMomoRepo = new AccountMomoRepository();
$accounts = $accountMomoRepo->getListAccountMomosLevels();
$accountsMomo = $accountMomoRepo->getListAccountMomos(true);
$GetSetting->namepage = 'Quản lý hạn mức SĐT';
$GetSetting->title = 'Quản lý hạn mức SĐT';
$GetSetting->description = 'Quản lý hạn mức SĐT';
$GetSetting->description = 'Tạo mới';
$titleModal = 'Tạo mới';
$types = Config::get('constant.list_game');
return view('AdminPage.AccountLevelMoney.index',
compact('GetSetting', 'titleModal', 'accounts', 'accountsMomo', 'types'));
}
public function store()
{
$data = request()->all();
$paramKeys = ['sdt', 'type', 'min', 'max'];
if (!$this->validateParameterKeys($paramKeys, $data)) {
return $this->responseMissingParameters();
}
if (!is_numeric($data['min']) || !is_numeric($data['max']) || !is_numeric($data['sdt'])) {
return $this->responseError($data, "Dữ liệu gửi lên không hợp lệ");
}
if ((int)($data['min']) >= (int)$data['max']) {
return $this->responseError($data, "Giá trị min phải nhỏ hơn giá trị max");
}
AccountLevelMoney::create($data);
Cache::forget('cache_list_account_momos_active');
Session::flash('message', 'Lưu dữ liệu thành công');
return $this->responseSuccess();
}
public function edit()
{
$data = request()->all();
$paramKeys = ['id'];
if (!$this->validateParameterKeys($paramKeys, $data)) {
return $this->responseMissingParameters();
}
$account = AccountLevelMoney::where('id', $data['id'])->first();
if (is_null($account)) {
return $this->responseMissingParameters();
}
$accountMomoRepo = new AccountMomoRepository();
$accountsMomo = $accountMomoRepo->getListAccountMomos();
$types = Config::get('constant.list_game');
$titleModal = "Cập nhật";
return view('AdminPage.AccountLevelMoney.form_template',
compact('account', 'titleModal', 'accountsMomo', 'types'));
}
public function update()
{
$data = request()->all();
$paramKeys = ['id', 'sdt', 'type', 'min', 'max'];
if (!$this->validateParameterKeys($paramKeys, $data)) {
return $this->responseMissingParameters();
}
if (!is_numeric($data['min']) || !is_numeric($data['max']) || !is_numeric($data['sdt'])) {
return $this->responseError($data, "Dữ liệu gửi lên không hợp lệ");
}
if ((int)($data['min']) >= (int)$data['max']) {
return $this->responseError($data, "Giá trị min phải nhỏ hơn giá trị max");
}
$account = AccountLevelMoney::where('id', $data['id'])->update($data);
if (!$account) {
return $this->responseMissingParameters();
}
$account = AccountLevelMoney::where('id', $data['id'])->first();
Cache::forget('cache_list_account_momos_active');
return view('AdminPage.AccountLevelMoney.row', compact('account'));
}
public function delete()
{
$data = request()->all();
$paramKeys = ['id'];
if (!$this->validateParameterKeys($paramKeys, $data)) {
return $this->responseMissingParameters();
}
$account = AccountLevelMoney::where('id', $data['id'])->update(['status' => STATUS_DE_ACTIVE]);
if (is_null($account)) {
return $this->responseMissingParameters();
}
Cache::forget('cache_list_account_momos_active');
return $this->responseSuccess();
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,54 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
public function validateParameterKeys($paramKeys, $data)
{
$validate = true;
foreach ($paramKeys as $key) {
if (!isset($data[$key])) {
$validate = false;
break;
}
}
return $validate;
}
public function responseMissingParameters()
{
return [
'status' => 2,
'message' => 'Thiếu dữ liệu gửi lên',
];
}
public function responseSuccess($data = [], $message = "")
{
return [
'status' => 1,
'message' => $message,
'data' => $data,
];
}
public function responseError($data = [], $message = "")
{
return [
'status' => 2,
'message' => $message,
'data' => $data,
];
}
}

View File

@@ -0,0 +1,465 @@
<?php
namespace App\Http\Controllers;
use App\Http\Repositories\AccountMomoRepository;
use App\Http\Repositories\AttendanceDateRepository;
use App\Http\Repositories\AttendanceSessionRepository;
use App\Traits\PhoneNumber;
use Illuminate\Http\Request;
use App\Models\Setting;
use App\Models\ChanLe;
use App\Models\TaiXiu;
use App\Models\ChanLe2;
use App\Models\Gap3;
use App\Models\Tong3So;
use App\Models\X1Phan3;
use App\Models\AccountMomo;
use App\Models\LichSuChoiMomo;
use App\Models\SettingPhanThuongTop;
use Illuminate\Http\Response;
use Illuminate\Support\Carbon;
use App\Models\NoHuu;
use App\Models\LichSuChoiNoHu;
use App\Models\LichSuBank;
use App\Models\TopTuan;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Log;
use Cache;
class HomeController extends Controller
{
//index
protected $attendanceSessionRepository;
protected $attendanceDateRepository;
protected $accountMomoRepo;
public function __construct()
{
$this->attendanceSessionRepository = new AttendanceSessionRepository();
$this->attendanceDateRepository = new AttendanceDateRepository();
$this->accountMomoRepo = new AccountMomoRepository();
}
public function index()
{
//Lịch sử chơi Momo
if (Cache::has('indexData')) {
return view(
'HomePage.home',
Cache::get('indexData')
);
}
//Setting
$Setting = new Setting;
$GetSetting = $Setting->first();
$GetSetting->namepage = 'Trang chủ';
// $accountMomosGroupTypes = $this->accountMomoRepo->getListAccountMomosGroupType();
//Bảo trì
//Chẵn lẻ
[
$Setting_ChanLe,
$Setting_TaiXiu,
$Setting_ChanLe2,
$Setting_Gap3,
$Setting_Tong3So,
$Setting_1Phan3,
] = $this->getSetingGame();
$UserTopTuan = [];
//Phần thưởng tuần
$SettingPhanThuongTop = new SettingPhanThuongTop;
$GetSettingPhanThuongTop = $SettingPhanThuongTop->get();
//Setting nổ hũ
$NoHuu = new NoHuu;
$Setting_NoHu = $NoHuu->first();
//Thông báo nổ hũ
$LichSuChoiNoHu = new LichSuChoiNoHu;
$GetLichSuChoiNoHu = $LichSuChoiNoHu->where([
'status' => 3,
'ketqua' => 1,
])->get();
$GetLichSuChoiNoHus = [];
$dem = 0;
foreach ($GetLichSuChoiNoHu as $row) {
$GetLichSuChoiNoHus[$dem] = $row;
$GetLichSuChoiNoHus[$dem]['sdt2'] = substr($row['sdt'], 0, 6).'******';
$GetLichSuChoiNoHus[$dem]['tiennhan2'] = $row['tiennhan'] + $Setting_NoHu->tienmacdinh;
$dem++;
}
$secondRealTime = $this->attendanceSessionRepository->getSecondsRealtime();
$dataAttendanceSession = $this->attendanceSessionRepository->getDataAttendanceSession();
$attendanceSessionCurrent = $dataAttendanceSession['current'];
$listSessionsPast = $dataAttendanceSession['sessions_past'];
$phoneWinLatest = $dataAttendanceSession['phone_win_latest'];
$usersAttendance = $this->attendanceSessionRepository->getUsersAttendanceSession($attendanceSessionCurrent);
$totalAmount = $this->attendanceSessionRepository->getTotalAmountAttendanceSession();
$countUsersAttendance = count($usersAttendance);
$listUserAttendance = $usersAttendance->take(10);
$checkCanAttendance = $this->attendanceSessionRepository->checkTurOnAttendance();
$checkCanAttendanceDate = $this->attendanceDateRepository->checkTurOnAttendanceDate();
$setting = $this->attendanceSessionRepository->getAttendanceSetting();
$timeEach = $setting['time_each'] ?? TIME_EACH_ATTENDANCE_SESSION;
$startTime = isset($setting['start_time']) ? Carbon::parse($setting['start_time']) : Carbon::parse(TIME_START_ATTENDANCE);
$endTime = isset($setting['end_time']) ? Carbon::parse($setting['end_time']) : Carbon::parse(TIME_END_ATTENDANCE);
$now = Carbon::now();
$canAttendance = $now->between($startTime, $endTime) && $checkCanAttendance;
$configAttendanceDate = $this->attendanceDateRepository->getMocchoi();
//View
$data = view(
'HomePage.home',
compact(
'GetSetting',
// 'accountMomosGroupTypes',
'Setting_ChanLe',
'Setting_TaiXiu',
'Setting_ChanLe2',
'Setting_Gap3',
'Setting_Tong3So',
'Setting_1Phan3',
'UserTopTuan',
'GetSettingPhanThuongTop',
'GetLichSuChoiNoHus',
'attendanceSessionCurrent',
'secondRealTime',
'listSessionsPast',
'countUsersAttendance',
'phoneWinLatest',
'usersAttendance',
'listUserAttendance',
'canAttendance',
'totalAmount',
'checkCanAttendance',
'setting',
'timeEach',
'checkCanAttendanceDate',
'configAttendanceDate',
)
);
Cache::put('indexData', compact(
'GetSetting',
// 'accountMomosGroupTypes',
'Setting_ChanLe',
'Setting_TaiXiu',
'Setting_ChanLe2',
'Setting_Gap3',
'Setting_Tong3So',
'Setting_1Phan3',
'UserTopTuan',
'GetSettingPhanThuongTop',
'GetLichSuChoiNoHus',
'attendanceSessionCurrent',
'secondRealTime',
'listSessionsPast',
'countUsersAttendance',
'phoneWinLatest',
'usersAttendance',
'listUserAttendance',
'canAttendance',
'totalAmount',
'checkCanAttendance',
'setting',
'timeEach',
'checkCanAttendanceDate',
'configAttendanceDate',
), TIME_CACHE_LOAD_DATA + 30);
return $data;
}
public function realTimeAttendance(Request $request)
{
$timeLast = $request->all();
$updateCache = $timeLast % 20 == 0;
$secondsRealtime = $this->attendanceSessionRepository->getSecondsRealtime($updateCache);
$dataAttendanceSession = $this->attendanceSessionRepository->getDataAttendanceSession();
$attendanceSessionCurrent = $dataAttendanceSession['current'];
$phoneWinLatest = $dataAttendanceSession['phone_win_latest'];
$listSessionsPast = $dataAttendanceSession['sessions_past'];
$usersAttendance = $this->attendanceSessionRepository->getUsersAttendanceSession($attendanceSessionCurrent);
$countUsersAttendance = count($usersAttendance);
$usersAttendance = $usersAttendance->transform(function($user) {
$user->phone = $user->getPhone();
return $user;
});
$phoneUsersAttendance = $usersAttendance->pluck('phone')->toArray();
$totalAmount = $this->attendanceSessionRepository->getTotalAmountAttendanceSession();
$phonesAttendance = view('HomePage.phone_user_attendance', compact('phoneUsersAttendance'))->render();
$viewListSessionPast = view('HomePage.table_sessions_attendance', compact('listSessionsPast'))->render();
return json_encode([
'session_current_code' => $attendanceSessionCurrent->id,
'phone_win_latest' => $phoneWinLatest,
'count_users_attendance' => $countUsersAttendance,
'phones_attendance' => $phonesAttendance,
'total_amount' => number_format($totalAmount),
'view_list_session_past' => $viewListSessionPast,
'second_realtime' => $secondsRealtime,
], true);
}
public function attendanceSession(Request $request)
{
$data = $request->all();
if (!isset($data['phone'])) {
return response(['status' => 2, 'message' => "Có lỗi xảy ra vui lòng thử lại"]);
}
if (!is_numeric($data['phone']) || !$this->isDigits($data['phone'])) {
return response(['status' => 2, 'message' => "Số điện thoại sai định dạng. Vui lòng kiểm tra lại"]);
}
$startTime = Carbon::parse(TIME_START_ATTENDANCE);
$endTime = Carbon::parse(TIME_END_ATTENDANCE);
$now = Carbon::now();
if (!$now->between($startTime, $endTime)) {
return response(['status' => 2, 'message' => "Thời gian bắt đầu điểm danh từ 7h sáng đến 11h hằng ngày!"]);
}
if ($this->checkPhoneHasAttendanceSessionCurrent($data['phone'])) {
return response(['status' => 2, 'message' => "Số điện thoại của bạn đã điểm danh trong phiên này!"]);
}
$this->attendanceSessionRepository->insertUsersAttendanceSession($data);
return "SUCCESS";
}
public function attendanceDate(Request $request)
{
$data = $request->all();
if (!isset($data['phone'])) {
return response(['status' => 2, 'message' => "Có lỗi xảy ra vui lòng thử lại"]);
}
if (!$this->attendanceDateRepository->checkTurOnAttendanceDate()) {
return response(['status' => 2, 'message' => "Hệ thống đang bảo trì"]);
}
$data = $this->attendanceDateRepository->handleAttendanceDate($data);
return $data;
}
private function checkPhoneHasAttendanceSessionCurrent($phone)
{
$recordsOfPhone = $this->attendanceSessionRepository->queryUsersAttendanceByPhone($phone);
return count($recordsOfPhone) > 0;
}
public function isDigits(string $s, int $minDigits = 9, int $maxDigits = 14): bool
{
return preg_match('/^[0-9]{'.$minDigits.','.$maxDigits.'}\z/', $s);
}
public function getDataAfterLoad()
{
//Lịch sử chơi Momo
if (Cache::has('AllData')) {
return Cache::get('AllData');
}
//Lịch sử chơi Momo
$LichSuChoiMomo = new LichSuChoiMomo;
$LichSuChoiMomoToDay = $LichSuChoiMomo->whereDate('created_at', Carbon::today())->where([
'ketqua' => 1,
'status' => 3,
])->orderBy('id', 'desc')->get();
$accountMomosGroupTypes = $this->accountMomoRepo->getListAccountMomosWithAccountLevel();
$accountMomosGroupTypesAllGames = collect();
if (!is_null($accountMomosGroupTypes->get(CONFIG_ALL_GAME)) && count($accountMomosGroupTypes->get(CONFIG_ALL_GAME)) > 0) {
$accountMomosGroupTypesAllGames = $accountMomosGroupTypes->get(CONFIG_ALL_GAME);
}
$ListLichSuChoiMomo = $LichSuChoiMomoToDay->take(5);
$ListAccounts = $this->getTrangthaiMomo();
$UserTopTuan = $this->getTopTuan($LichSuChoiMomo);
//$UserTopTuan=[];
[
$Setting_ChanLe,
$Setting_TaiXiu,
$Setting_ChanLe2,
$Setting_Gap3,
$Setting_Tong3So,
$Setting_1Phan3,
] = $this->getSetingGame();
$viewLichSuThang = view('HomePage.table_lich_su_thang', compact('ListLichSuChoiMomo'))->render();
$viewUserTopTuan = view('HomePage.top_tuan', compact('UserTopTuan'))->render();
$viewTrangthaiMomo = view('HomePage.table_trang_thai_momo', compact('ListAccounts'))->render();
$viewTaleAccount = [];
$types = Config::get('constant.list_game');
foreach ($types as $type => $label) {
if (!view()->exists('HomePage.table_account_'.$type)) {
continue;
}
$viewTaleAccount[$type] = view('HomePage.table_account_'.$type,
compact('accountMomosGroupTypes', 'accountMomosGroupTypesAllGames'))->render();
}
$data=[
'lich_su_thang' => $viewLichSuThang,
'view_table_account' => $viewTaleAccount,
'view_table_trang_thai_momo' => $viewTrangthaiMomo,
'view_top_tuan' => $viewUserTopTuan,
'tiencuoc_'.CONFIG_CHAN_LE => $Setting_ChanLe['tile'],
'tiencuoc_'.CONFIG_TAI_XIU => $Setting_TaiXiu['tile'],
'tiencuoc_'.CONFIG_CHAN_LE_TAI_XIU_2 => $Setting_ChanLe2['tile'],
'tiencuoc_'.CONFIG_1_PHAN_3 => $Setting_1Phan3['tile'],
'tiencuoc_'.CONFIG_GAP_3.'_1' => $Setting_Gap3['tile1'],
'tiencuoc_'.CONFIG_GAP_3.'_2' => $Setting_Gap3['tile2'],
'tiencuoc_'.CONFIG_GAP_3.'_3' => $Setting_Gap3['tile3'],
'tiencuoc_'.CONFIG_TONG_3_SO.'_1' => $Setting_Tong3So['tile1'],
'tiencuoc_'.CONFIG_TONG_3_SO.'_2' => $Setting_Tong3So['tile2'],
'tiencuoc_'.CONFIG_TONG_3_SO.'_3' => $Setting_Tong3So['tile3'],
];
// set cache tồn tại trong 30s
Cache::put('AllData', $data, TIME_CACHE_LOAD_DATA);
return $data;
}
public function getPhone($phone)
{
$middle_string = "";
$length = strlen($phone);
if ($length < 3) {
return $length == 1 ? "*" : "*".substr($phone, -1);
} else {
$part_size = floor($length / 3);
$middle_part_size = $length - ($part_size * 2);
for ($i = 0; $i < $middle_part_size; $i++) {
$middle_string .= "*";
}
return substr($phone, 0, $part_size).$middle_string.substr($phone, -$part_size);
}
}
/**
* @param \App\Models\AccountMomo $AccountMomo
*
* @return array
*/
private function getSetingGame(): array
{
$AccountMomo = new AccountMomo;
$ChanLe = new ChanLe;
$Setting_ChanLe = $ChanLe->first();
$Setting_ChanLe->sdt2 = $AccountMomo->GetListAccountID($Setting_ChanLe->sdt);
$Setting_ChanLe = $Setting_ChanLe->toArray();
//Tài xỉu
$TaiXiu = new TaiXiu;
$Setting_TaiXiu = $TaiXiu->first();
$Setting_TaiXiu->sdt2 = $AccountMomo->GetListAccountID($Setting_TaiXiu->sdt);
$Setting_TaiXiu = $Setting_TaiXiu->toArray();
//Chẵn lẻ 2
$ChanLe2 = new ChanLe2;
$Setting_ChanLe2 = $ChanLe2->first();
$Setting_ChanLe2->sdt2 = $AccountMomo->GetListAccountID($Setting_ChanLe2->sdt);
$Setting_ChanLe2 = $Setting_ChanLe2->toArray();
//Gấp 3
$Gap3 = new Gap3;
$Setting_Gap3 = $Gap3->first();
$Setting_Gap3->sdt2 = $AccountMomo->GetListAccountID($Setting_Gap3->sdt);
$Setting_Gap3 = $Setting_Gap3->toArray();
//Tổng 3 Số
$Tong3So = new Tong3So;
$Setting_Tong3So = $Tong3So->first();
$Setting_Tong3So->sdt2 = $AccountMomo->GetListAccountID($Setting_Tong3So->sdt);
$Setting_Tong3So = $Setting_Tong3So->toArray();
//1 Phần 3
$X1Phan3 = new X1Phan3;
$Setting_1Phan3 = $X1Phan3->first();
$Setting_1Phan3->sdt2 = $AccountMomo->GetListAccountID($Setting_1Phan3->sdt);
$Setting_1Phan3 = $Setting_1Phan3->toArray();
return [
$Setting_ChanLe,
$Setting_TaiXiu,
$Setting_ChanLe2,
$Setting_Gap3,
$Setting_Tong3So,
$Setting_1Phan3,
];
}
/**
* @param \App\Models\LichSuChoiMomo $LichSuChoiMomo
*
* @return mixed
*/
private function getTopTuan(LichSuChoiMomo $LichSuChoiMomo)
{
$topTuan= new TopTuan;
$UserTopTuan=[];
$getTopTuan = $topTuan->whereBetween('created_at',
[Carbon::today()->startOfWeek(), Carbon::today()->endOfWeek()])
->orderBy('tongtientuan', 'desc')->limit(5)->get();
foreach($getTopTuan as $row){
$UserTopTuan[$this->getPhone($row->sdt)] = $row->tongtientuan;
}
return $UserTopTuan;
// $lichSuChoiMomoTuan = $LichSuChoiMomo->whereBetween('created_at',
// [Carbon::today()->startOfWeek(), Carbon::today()->endOfWeek()])
// // ->where('ketqua', 1)
// ->where('status', 3)
// ->get();
// $UserTopTuan = $lichSuChoiMomoTuan->map(function($lichSu) {
// $phoneConvert = new PhoneNumber();
// $lichSu->sdt = $phoneConvert->convert($lichSu->sdt, true);
// $lichSu->sdt = $this->getPhone($lichSu->sdt);
// return $lichSu;
// })->groupBy('sdt')->map(function($lichSuPhone) {
// return $lichSuPhone->sum('tiencuoc');
// })->sortByDesc(function($tiencuoc) {
// return $tiencuoc;
// })->take(5)->toArray();
// return $UserTopTuan;
}
/**
* @return \Illuminate\Support\Collection
*/
private function getTrangthaiMomo(): \Illuminate\Support\Collection
{
//Trạng thái MOMO
$ListAccounts = $this->accountMomoRepo->getListAccountMomosWithAccountLevel(false);
return $ListAccounts->map(function($account) {
$account['status_class'] = "success";
$account['status_text'] = "hoạt động";
return $account;
});
// $LichSuBank = new LichSuBank;
// $accounts = collect($this->accountMomoRepo->getListAccountMomos());
// $LichSuBanks = $LichSuBank->whereDate('created_at', Carbon::today())->get();
// $ListAccounts = collect($accounts)->map(function($account) use (
// $LichSuChoiMomoToDay,
// $LichSuBanks
// ) {
// $GetLichSuChoiMomo = $LichSuChoiMomoToDay->where('sdt_get', $account['sdt']);
// $getLichSuBank = $LichSuBanks->where('sdtbank', $account['sdt']);
// $responseLichSuBank = $getLichSuBank->pluck('response')->toArray();
// $countbank = 0;
// foreach ($responseLichSuBank as $response) {
// $j = json_decode($response, true);
// if (isset($j['status']) && $j['status'] == 200) {
// $countbank++;
// }
// }
// $account['sent_money'] = $GetLichSuChoiMomo->sum('tiennhan');
// $account['status_class'] = "success";
// $account['status_text'] = "hoạt động";
// $account['countbank'] = $countbank;
//
// return $account;
// })->take(5);
return $ListAccounts;
}
}

View File

@@ -0,0 +1,77 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\NoHuu;
use App\Models\LichSuChoiNoHu;
use App\Models\AccountMomo;
class NoHuController extends Controller
{
//
public function Get_Hu(request $request){
//Setting nổ hũ
$NoHuu = new NoHuu;
$Setting_NoHu = $NoHuu->first();
$LichSuChoiNoHu = new LichSuChoiNoHu;
$GetLichSuChoiNoHu = $LichSuChoiNoHu->where([
'status' => 3,
])->get();
$tongtien = $Setting_NoHu->tienmacdinh;
foreach ($GetLichSuChoiNoHu as $row) {
$tongtien = $tongtien + $row->tienvaohu;
$tongtien = $tongtien - $row->tiennhan;
}
return response()->json([
'tongtien' => $tongtien,
]);
}
public function Load_Hu(request $request){
//Setting nổ hũ
$NoHuu = new NoHuu;
$Setting_NoHu = $NoHuu->first();
$LichSuChoiNoHu = new LichSuChoiNoHu;
$GetLichSuChoiNoHu = $LichSuChoiNoHu->where([
'status' => 3,
])->get();
$tongtien = $Setting_NoHu->tienmacdinh;
foreach ($GetLichSuChoiNoHu as $row) {
$tongtien = $tongtien + $row->tienvaohu;
$tongtien = $tongtien - $row->tiennhan;
}
//
$AccountMomo = new AccountMomo;
$GetAccountMomo = $AccountMomo->where([
'status' => 1,
])->get();
$GetAccountMomos = [];
$dem = 0;
foreach ($GetAccountMomo as $row) {
$GetAccountMomos[$dem]['sdt'] = $row->sdt;
$dem ++;
}
$sotienchuyen = $Setting_NoHu->tiencuoc;
//
return response()->json([
'tongtien' => $tongtien,
'tongtien_format' => number_format($tongtien),
'list_sdt' => $GetAccountMomos,
'sotienchuyen' => $sotienchuyen,
]);
}
}

67
app/Http/Kernel.php Normal file
View File

@@ -0,0 +1,67 @@
<?php
namespace App\Http;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel
{
/**
* The application's global HTTP middleware stack.
*
* These middleware are run during every request to your application.
*
* @var array
*/
protected $middleware = [
// \App\Http\Middleware\TrustHosts::class,
\App\Http\Middleware\TrustProxies::class,
\Fruitcake\Cors\HandleCors::class,
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
];
/**
* The application's route middleware groups.
*
* @var array
*/
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
// \Illuminate\Session\Middleware\AuthenticateSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
'api' => [
'throttle:api',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
];
/**
* The application's route middleware.
*
* These middleware may be assigned to groups or used individually.
*
* @var array
*/
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
'maintenance_system' => \App\Http\Middleware\MaintenanceSystem::class,
];
}

View File

@@ -0,0 +1,21 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Auth\Middleware\Authenticate as Middleware;
class Authenticate extends Middleware
{
/**
* Get the path the user should be redirected to when they are not authenticated.
*
* @param \Illuminate\Http\Request $request
* @return string|null
*/
protected function redirectTo($request)
{
if (! $request->expectsJson()) {
return route('login');
}
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
class EncryptCookies extends Middleware
{
/**
* The names of the cookies that should not be encrypted.
*
* @var array
*/
protected $except = [
//
];
}

View File

@@ -0,0 +1,26 @@
<?php
namespace App\Http\Middleware;
use App\Http\Repositories\AttendanceSessionRepository;
use Closure;
use Illuminate\Auth\Middleware\Authenticate as Middleware;
class MaintenanceSystem extends Middleware
{
/**
* Get the path the user should be redirected to when they are not authenticated.
*
* @param \Illuminate\Http\Request $request
* @return string|null
*/
public function handle($request, Closure $next)
{
$repo = new AttendanceSessionRepository();
$config = $repo->getSettingWebsite();
if ($config['baotri'] == 1){
return redirect(route('bao_tri'));
}
return $next($request);
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance as Middleware;
class PreventRequestsDuringMaintenance extends Middleware
{
/**
* The URIs that should be reachable while maintenance mode is enabled.
*
* @var array
*/
protected $except = [
//
];
}

View File

@@ -0,0 +1,32 @@
<?php
namespace App\Http\Middleware;
use App\Providers\RouteServiceProvider;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class RedirectIfAuthenticated
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string|null ...$guards
* @return mixed
*/
public function handle(Request $request, Closure $next, ...$guards)
{
$guards = empty($guards) ? [null] : $guards;
foreach ($guards as $guard) {
if (Auth::guard($guard)->check()) {
return redirect()->route('admin_home');
}
}
return $next($request);
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\TrimStrings as Middleware;
class TrimStrings extends Middleware
{
/**
* The names of the attributes that should not be trimmed.
*
* @var array
*/
protected $except = [
'current_password',
'password',
'password_confirmation',
];
}

View File

@@ -0,0 +1,20 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Http\Middleware\TrustHosts as Middleware;
class TrustHosts extends Middleware
{
/**
* Get the host patterns that should be trusted.
*
* @return array
*/
public function hosts()
{
return [
$this->allSubdomainsOfApplicationUrl(),
];
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace App\Http\Middleware;
use Fideloper\Proxy\TrustProxies as Middleware;
use Illuminate\Http\Request;
class TrustProxies extends Middleware
{
/**
* The trusted proxies for this application.
*
* @var array|string|null
*/
protected $proxies;
/**
* The headers that should be used to detect proxies.
*
* @var int
*/
protected $headers = Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_HOST | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO | Request::HEADER_X_FORWARDED_AWS_ELB;
}

View File

@@ -0,0 +1,17 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
class VerifyCsrfToken extends Middleware
{
/**
* The URIs that should be excluded from CSRF verification.
*
* @var array
*/
protected $except = [
//
];
}

View File

@@ -0,0 +1,114 @@
<?php
/**
*File name : AccountMomoRepository.php / Date: 1/4/2022 - 8:55 PM
*Code Owner: Thanhnt/ Email: Thanhnt@omt.com.vn/ Phone: 0384428234
*/
namespace App\Http\Repositories;
use App\Models\AccountLevelMoney;
use App\Models\AccountMomo;
use App\Models\LichSuBank;
use App\Models\LichSuChoiMomo;
use Carbon\Carbon;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
class AccountMomoRepository
{
public function getListAccountMomosLevels()
{
$cache = Cache::get('cache_list_account_momos_active');
$cache = null;
if (!is_null($cache)) {
return $cache;
}
$listAccountMomos = $this->getListAccountMomos(true, [STATUS_ACTIVE, STATUS_MAINTENANCE]);
$levelAccounts = AccountLevelMoney::where('status', STATUS_ACTIVE)->get()->map(function($account) use (
$listAccountMomos
) {
$accountMomo = collect($listAccountMomos)->where('sdt', $account->sdt)->first();
$account->game = $account->getGameAttribute();
if (!is_null($accountMomo)) {
if ($accountMomo['status'] == STATUS_MAINTENANCE) {
$account->text_status = "Bảo trì";
$account->class_status = "warning";
} else {
$account->text_status = "Hoạt động";
$account->class_status = "success";
}
} else {
$account->notExist = "true";
}
return $account;
})->filter(function($account) {
return !isset($account->notExist);
})->toArray();
Cache::put('cache_list_account_momos_active', $levelAccounts, Carbon::now()->addMinutes(60));
return $levelAccounts;
}
public function getListAccountMomos($forCreate = false, $status = [STATUS_ACTIVE])
{
$phones = [];
if (!$forCreate) {
$accountListMomoLevel = $this->getListAccountMomosLevels();
$phones = collect($accountListMomoLevel)->pluck('sdt')->toArray();
}
$query = AccountMomo::whereIn('status', $status);
$query = !$forCreate ? $query->whereIn('sdt', $phones)->limit(5) : $query;
return $query->get()->unique('sdt')->toArray();
}
public function getListAccountMomosWithAccountLevel($groupByType = true)
{
$accounts = collect($this->getListAccountMomosLevels());
$phones = $accounts->pluck('sdt')->unique()->toArray();
$LichSuBank = new LichSuBank;
$LichSuBanks = $LichSuBank->whereDate('created_at', \Illuminate\Support\Carbon::today())->get();
$sumTienCuocPhones = [];
foreach ($phones as $index => $phone) {
$sumTienCuocPhones[] = [
'phone' => $phone,
'sum' => DB::table('lich_su_choi_momos')
->whereDate('created_at', Carbon::today())
->where('ketqua', 1)
->where('sdt_get', $phone)
->sum('tiennhan'),
];
}
$accountMomos = AccountMomo::whereIn('sdt', $phones)
->where('status', STATUS_ACTIVE)
->get();
$phonesAccountMomo = $accountMomos->pluck('sdt')->toArray();
$accounts = $accounts->map(function($account) use ($sumTienCuocPhones, $LichSuBanks, $accountMomos) {
$sumTienCuocPhone = collect($sumTienCuocPhones)->where('phone', $account['sdt'])->first();
$accountMomo = $accountMomos->where('sdt', $account['sdt'])->first();
$account['sumTienCuoc'] = is_null($sumTienCuocPhone) ? 0 : $sumTienCuocPhone['sum'];
$account['gioihan'] = is_null($accountMomo) ? 0 : $accountMomo['gioihan'];
$getLichSuBank = $LichSuBanks->where('sdtbank', $account['sdt']);
$countbank = 0;
$responseLichSuBank = $getLichSuBank->pluck('response')->toArray();
foreach ($responseLichSuBank as $response) {
$j = json_decode($response, true);
if (isset($j['status']) && $j['status'] == 200) {
$countbank++;
}
}
$account['countbank'] = $countbank;
$account['color_min'] = $account['min'] > CONFIG_COMPARE_TIEN_CUOC_MIN ? "blue" : "";
$account['color_max'] = $account['max'] > CONFIG_COMPARE_TIEN_CUOC_MIN ? "blue" : "";
$account['color_tiencuoc'] = $account['sumTienCuoc'] > CONFIG_MAX_SUM_TIEN_CUOC ? "red" : "green";
$account['color_countbank'] = $countbank > CONFIG_MAX_COUNT_BANK ? "red" : "green";
return $account;
})->filter(function($account) use ($phonesAccountMomo) {
return in_array($account['sdt'], $phonesAccountMomo);
})->take(5)->sortBy('min');
return $groupByType ? $accounts->groupBy('type')->map(function($accountList) {
return $accountList->unique('sdt');
}) : $accounts;
}
}

View File

@@ -0,0 +1,204 @@
<?php
/**
*File name : AttendanceSessionRepository.php / Date: 10/26/2021 - 9:39 PM
*/
namespace App\Http\Repositories;
use App\Models\AccountMomo;
use App\Models\AttendanceDateSetting;
use App\Models\AttendanceSession;
use App\Models\AttendanceSetting;
use App\Models\LichSuChoiAttendanceDate;
use App\Models\LichSuChoiMomo;
use App\Models\Setting;
use App\Models\UserAttendanceSession;
use App\Traits\PhoneNumber;
use Carbon\Carbon;
use Illuminate\Config\Repository;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\DB;
class AttendanceDateRepository extends Repository
{
public function __construct()
{
}
public function getMocchoi()
{
return AttendanceDateSetting::orderBy('mocchoi')->get()->toArray();
}
public function checkTurOnAttendanceDate()
{
$attendanceRepo = new AttendanceSessionRepository();
$setting = $attendanceRepo->getSettingWebsite();
if (isset($setting['baotri']) && $setting['baotri'] == 1) {
return false;
}
if (!isset($setting['on_diemdanh_ngay'])) {
return true;
}
return $setting['on_diemdanh_ngay'] == TURN_ON_SETTING;
}
public function handleAttendanceDate($data)
{
$attendanceDateRepo = new AttendanceDateRepository();
$phone = (new PhoneNumber)->convert($data['phone']);
$phoneOld = (new PhoneNumber)->convert($data['phone'], true);
$phonesAccount = AccountMomo::where('sdt', $phone)->orWhere('sdt', $phoneOld)->get();
$date = Carbon::today()->toDateString();
$lichSuMomosOfPhone = LichSuChoiMomo::where('sdt', $phone)
->where('created_at', '>=', $date)
->orWhere(function($query) use ($phoneOld, $date) {
$query->where('sdt', $phoneOld)
->where('created_at', '>=', $date);
})
->get();
if (count($lichSuMomosOfPhone) == 0 && count($phonesAccount) == 0) {
return $this->responseResult("Oh !! Số điện thoại này chưa chơi game nào, hãy kiểm tra lại");
}
$mocchois = $attendanceDateRepo->getMocchoi();
$mocchoiFirst = collect($mocchois)->first();
if (count($mocchois) == 0) {
return $this->responseResult("Hệ thống đang bảo trì vui lòng thử lại sau!");
}
$sumTien = $lichSuMomosOfPhone->sum('tiencuoc');
$lichsuChoi = $this->getLichSuChoiDiemDanhNgay($date, $phone, $phoneOld);
if (count($lichsuChoi) == 0) {
if ($sumTien < $mocchoiFirst['mocchoi']) {
return $this->responseResult("Oh !! . Nay bạn đã chơi hết: ".number_format($sumTien)." VNĐ. Bạn chưa đủ mốc tiền để nhận thưởng trong ngày hôm nay. Cố gắng chơi thêm nhé!!!");
}
$mocSumTien = collect($mocchois)->where('mocchoi', "<=", $sumTien)->last();
if (is_null($mocSumTien)) {
return $this->responseResult("Hệ thống đang bảo trì vui lòng thử lại sau!");
}
$tiennhan = $mocSumTien['tiennhan'];
$this->insertPhoneToTableLichSu($phoneOld, $mocSumTien['mocchoi'], $tiennhan);
} else {
$mocDaChoiMax = array_key_last($lichsuChoi);
$mocSumTien = collect($mocchois)->where('mocchoi', "<=", $sumTien)->last();
// $mocTiepTheo = collect($mocchois)->where('mocchoi', ">", $mocDaChoiMax)->first();
if (is_null($mocSumTien) || $this->mocchoiIsMax(collect($mocchois)->last(), $mocDaChoiMax)) {
return $this->responseResult("Bạn đã nhận thưởng hết trong ngày hôm nay. Vui lòng quay lại trò chơi vào ngày mai!!!");
}
if ($mocDaChoiMax)
// $mocSumTien['mocchoi'] == $mocDaChoiMax
$mocDatTiepTheo = $mocSumTien['mocchoi'];
if ($mocDaChoiMax == $mocDatTiepTheo){
return $this->responseResult("Oh !! . Nay bạn đã chơi hết: ".number_format($sumTien)." VNĐ. Bạn chưa đủ mốc tiền tiếp theo để nhận thưởng thêm trong hôm nay. Cố gắng Pang thêm nhé!!!");
}
if ($sumTien >= $mocDatTiepTheo) {
$tiennhan = $mocSumTien['tiennhan'];
$this->insertPhoneToTableLichSu($phoneOld, $mocDatTiepTheo, $tiennhan);
} else {
return $this->responseResult("Oh !! . Nay bạn đã chơi hết: ".number_format($sumTien)." VNĐ. Bạn chưa đủ mốc tiền tiếp theo để nhận thưởng thêm trong hôm nay. Cố gắng Pang thêm nhé!!!");
}
}
return $this->responseResult("Oh!! Chúc mừng bạn đã nhận được ".number_format($tiennhan)." VNĐ ĐỚP ÍT THÔI!!");
}
private function getPhoneAccountMomo()
{
$cache = Cache::get('cache_get_sdt_account_momo');
if (!is_null($cache)) {
return $cache;
}
$account = AccountMomo::orderBy('status')->first();
$phone = $account->sdt;
Cache::put('cache_get_sdt_account_momo', $phone, Carbon::now()->addMinutes(10));
return $phone;
}
private function insertPhoneToTableLichSu($phone, $mocchoi, $tienNhan)
{
$phoneGet = $this->getPhoneAccountMomo();
$billCode = 'Nghiệm vụ ngày '.bin2hex(random_bytes(3)).time();
$this->insertToLichSuMoMo($phone, $tienNhan, $phoneGet, $billCode);
$this->insertToLichSuDiemDanhNgay($phone, $mocchoi, $tienNhan, $phoneGet, $billCode);
}
/**
* @param $phone
* @param $tienNhan
*
* @throws \Exception
*/
private function insertToLichSuMoMo($phone, $tienNhan, $phoneGet, $billCode)
{
return DB::table('lich_su_choi_momos')->insert([
'sdt' => $phone,
'sdt_get' => $phoneGet,
'magiaodich' => $billCode,
'tiencuoc' => 0,
'tiennhan' => $tienNhan,
'trochoi' => "Nghiệm vụ ngày",
'noidung' => "NVN",
'ketqua' => 1,
'status' => STATUS_LSMOMO_TAM_THOI,
'created_at' => Carbon::now(),
'updated_at' => Carbon::now(),
]);
}
private function insertToLichSuDiemDanhNgay($phone, $mocchoi, $tienNhan, $phoneGet, $billCode)
{
return DB::table('lich_su_attendance_date')->insert([
'date' => Carbon::today()->toDateString(),
'phone' => $phone,
'mocchoi' => $mocchoi,
'tiennhan' => $tienNhan,
'sdt_get' => $phoneGet,
'magiaodich' => $billCode,
'created_at' => Carbon::now(),
'updated_at' => Carbon::now(),
]);
}
/**
* @return array
*/
private function responseResult($message): array
{
return [
'status' => 2,
'message' => $message,
];
}
/**
* @param string $date
* @param array $phone
*
* @return mixed
*/
private function getLichSuChoiDiemDanhNgay($date, $phone, $phoneOld)
{
$lichsuChoi = LichSuChoiAttendanceDate::whereDate('date', $date)
->where('phone', $phone)
->orWhere(function($query) use ($phoneOld, $date) {
$query->where('phone', $phoneOld)
->whereDate('date', $date);
})
->orderBy("mocchoi")
->get()
->pluck('tiennhan', 'mocchoi')
->toArray();
return $lichsuChoi;
}
public function mocchoiIsMax($mocchoiMax, $mocchoiCheck)
{
return $mocchoiMax['mocchoi'] == $mocchoiCheck;
}
}

View File

@@ -0,0 +1,239 @@
<?php
/**
*File name : AttendanceSessionRepository.php / Date: 10/26/2021 - 9:39 PM
*/
namespace App\Http\Repositories;
use App\Models\AttendanceSession;
use App\Models\AttendanceSetting;
use App\Models\Setting;
use App\Models\UserAttendanceSession;
use Carbon\Carbon;
use Illuminate\Config\Repository;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\DB;
class AttendanceSessionRepository extends Repository
{
public function __construct()
{
}
public function getSecondsRealtime($updateCache = false)
{
$now = Carbon::now();
$hour = $now->hour;
$setting = $this->getAttendanceSetting();
$timeEach = (int)$setting['time_each'];
$timeStart = $this->getTimeStartByConfigTimeEach($timeEach, $hour, $now);
// $minute = (int)floor($now->minute / 10) * 3;
// $timeStart = Carbon::parse($hour.":".$minute);
// $abc = $now->minute - $now->minute%3;
// dd($hour.":".$abc, $hour.":".(int)floor($now->minute / 10) * 10);
$realTimeSeconds = $timeEach - (int)($now->timestamp - $timeStart->timestamp);
if ($realTimeSeconds <= 1 || $updateCache) {
$this->forgetCacheDatAttendanceSession();
}
return $realTimeSeconds;
}
private function getTimeStartByConfigTimeEach($timeEach, $hour, Carbon $now)
{
switch ($timeEach) {
case 60:
default;
return Carbon::parse($hour.":".$now->minute);
case 180:
$minute = $now->minute - $now->minute % 3;
return Carbon::parse($hour.":".$minute);
case 300:
$minute = $now->minute - $now->minute % 5;
return Carbon::parse($hour.":".$minute);
case 600:
$minute = (int)floor($now->minute / 10) * 10;
return Carbon::parse($hour.":".$minute);
case 900:
$minute = $now->minute - $now->minute % 15;
return Carbon::parse($hour.":".$minute);
case 1200:
$minute = $now->minute - $now->minute % 20;
return Carbon::parse($hour.":".$minute);
case 1800:
$minute = $now->minute - $now->minute % 30;
return Carbon::parse($hour.":".$minute);
case 3600:
return $now->startOfHour();
case 21600:
$hour = $hour - $hour % 6;
return Carbon::parse($hour.":00");
case 86400:
return Carbon::today();
}
}
public function getDataAttendanceSession()
{
$cache = Cache::get('cache_data_attendance_session');
$cache = null;
if (!is_null($cache)) {
return $cache;
}
return $this->updateCacheDataAttendanceSession();
}
public function getCurrentAttendanceSession()
{
return $this->getDataAttendanceSession()['current'];
}
public function getTotalAmountAttendanceSession()
{
$cache = Cache::get('cache_total_amount_attendance_session');
if (!is_null($cache)) {
return $cache;
}
$totalAmount = DB::table('attendance_session')->sum('amount');
Cache::put('cache_total_amount_attendance_session', $totalAmount,
Carbon::now()->addSeconds($this->getSecondsRealtime()));
return $totalAmount;
}
public function getUsersAttendanceSession($attendanceSessionCurrent = null)
{
$attendanceSessionCurrent = !is_null($attendanceSessionCurrent) ? $attendanceSessionCurrent : $this->getDataAttendanceSession()['current'];
return $attendanceSessionCurrent->usersAttendanceSession()->get();
}
public function insertUsersAttendanceSession($data)
{
$attendanceSessionCurrent = $this->getDataAttendanceSession()['current'];
return UserAttendanceSession::create([
'session_id' => $attendanceSessionCurrent->id,
'phone' => $data['phone'],
]);
}
public function queryUsersAttendanceByPhone($phone)
{
$attendanceSessionCurrent = $this->getDataAttendanceSession()['current'];
return UserAttendanceSession::where('phone', $phone)->where('session_id', $attendanceSessionCurrent->id)->get();
}
public function createNewAttendanceSession($currentAttendanceSession)
{
$currentAttendanceSession->update(['status' => STATUS_DE_ACTIVE]);
$attendanceSession = AttendanceSession::create([
'date' => Carbon::today()->toDateString(),
'status' => STATUS_ACTIVE,
]);
$this->forgetCacheDatAttendanceSession();
return $attendanceSession;
}
public function getPhoneAttendanceSessionBots()
{
$cache = Cache::get('cache_phone_attendance_session_bots');
if (!is_null($cache)) {
return $cache;
}
$phones = collect(DB::table('attendance_session_bots')->select('phone')->get());
$phones = $phones->pluck('phone')->toArray();
Cache::put('cache_phone_attendance_session_bots', $phones, Carbon::now()->addDay());
return $phones;
}
public function getRandomBotsAttendance($botRate = 10, $phoneUserAttendance = [])
{
$totalBot = count(DB::table('attendance_session_bots')->get());
return DB::table('attendance_session_bots')
->whereNotIn('phone', $phoneUserAttendance)
->orderBy(DB::raw('RAND()'))
->take(round(($botRate / 100) * $totalBot))
->get();
}
public function checkTurOnAttendance()
{
$setting = $this->getSettingWebsite();
if (isset($setting['baotri']) && $setting['baotri'] == 1) {
return false;
}
if (!isset($setting['on_diemdanh'])) {
return true;
}
return $setting['on_diemdanh'] == TURN_ON_SETTING;
}
public function getSettingWebsite()
{
$cache = Cache::get('cache_website_setting');
$cache = null;
if (!is_null($cache)) {
return $cache;
}
$setting = Setting::first()->toArray();
Cache::put('cache_website_setting', $setting, Carbon::now()->addDay());
return $setting;
}
/**
* @return array
*/
public function updateCacheDataAttendanceSession()
{
$records = AttendanceSession::where('date', Carbon::today()->toDateString())
->orderBy('created_at', 'DESC')
->with(['usersAttendanceSession'])
->get();
if (count($records) == 0) {
return [
'current' => AttendanceSession::create(['date' => Carbon::today()->toDateString()]),
'phone_win_latest' => "*",
'sessions_past' => collect(),
];
}
$current = $records->where('status', STATUS_ACTIVE)->last();
$current = is_null($current) ? $records->last() : $current;
$sessionsPast = $records->except($current->id)->take(5);
$result = [
'current' => $current,
'phone_win_latest' => count($sessionsPast) > 0 ? $sessionsPast->first()->getPhone() : "*",
'sessions_past' => count($sessionsPast) > 0 ? $sessionsPast : collect(),
];
Cache::put('cache_data_attendance_session', $result, Carbon::now()->addSeconds($this->getSecondsRealtime()));
return $result;
}
public function forgetCacheDatAttendanceSession()
{
Cache::forget('cache_data_attendance_session');
Cache::forget('cache_total_amount_attendance_session');
}
public function getAttendanceSetting()
{
$cache = Cache::get('cache_attendance_setting');
if (!is_null($cache)) {
return $cache;
}
$attendance = AttendanceSetting::first();
$config = !is_null($attendance) ? AttendanceSetting::first()->toArray() : AttendanceSetting::create([
'win_rate' => 10,
'start_time' => TIME_START_ATTENDANCE,
'end_time' => TIME_END_ATTENDANCE,
'money_min' => MONEY_MIN_WIN_ATTENDANCE,
'money_max' => MONEY_MAX_WIN_ATTENDANCE,
'time_each' => TIME_EACH_ATTENDANCE_SESSION,
])->toArray();
Cache::put('cache_attendance_setting', $config, Carbon::now()->addDay());
return $config;
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class AdminSettingGameRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
//
'min' => 'required|integer',
'max' => 'required|integer',
'sdt' => 'required',
'tile' => 'required',
];
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class AdminSettingGameRequest2 extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
//
'min' => 'required|integer',
'max' => 'required|integer',
'sdt' => 'required',
'tile1' => 'required',
'tile2' => 'required',
'tile3' => 'required',
];
}
}

View File

@@ -0,0 +1,33 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class AdminSettingGameRequest3 extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
//
'tiencuoc' => 'required|integer',
'tienmacdinh' => 'required|integer',
'ptvaohu' => 'required|integer',
];
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class ChangePasswordAdminRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
//
'old_password' => 'required',
'password' => 'required|string|min:6|confirmed',
];
}
}

View File

@@ -0,0 +1,31 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class CronMomoRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
//
'account_id' => 'integer|min:1|required',
];
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class LoginAdminRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
//
'email' => 'required|email',
'password' => 'required',
];
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Config;
class AccountLevelMoney extends Model
{
use HasFactory;
protected $table = "account_level_money";
protected $fillable = [
'sdt',
'type',
'min',
'max',
];
public function getGameAttribute()
{
$games = Config::get('constant.list_game');
return $games[$this->type] ?? '';
}
}

View File

@@ -0,0 +1,79 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class AccountMomo extends Model
{
use HasFactory;
protected $fillable = [
'sdt',
'password',
'token',
'status',
'gioihan',
'webapi'
];
protected $hidden = [
'password',
'token',
];
public function TextStatus($status){
if ($status == 1) {
return 'Hoạt động';
}
if ($status == 2) {
return 'Đang bảo trì';
}
}
public function ClassStatus($status){
if ($status == 1) {
return 'success';
}
if ($status == 2) {
return 'danger';
}
}
public function GetListAccountID($id){
$id='';
$AccountMomo = new AccountMomo;
$ListAccount = $AccountMomo->get();
foreach ($ListAccount as $row) {
$id=$id .$row->id.',';
}
$list_id = explode(',', $id);
$data = [];
$dem = 0;
foreach($list_id as $row){
$res = $this->where([
'id' => $row,
'status' => 1,
]);
if ($res->count() > 0) {
$response = $res->first()->sdt;
$data[$dem] = $response;
$dem++;
}
}
return $data;
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class AttendanceDateSetting extends Model
{
use HasFactory, SoftDeletes;
protected $table = "attendance_date_setting";
protected $fillable = [
'mocchoi',
'tiennhan',
];
}

View File

@@ -0,0 +1,43 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class AttendanceSession extends Model
{
use HasFactory;
protected $table = "attendance_session";
protected $fillable = [
'phone',
'date',
'amount',
'bill_code',
'status',
];
public function getPhone()
{
$middle_string = "";
$length = strlen($this->phone);
if ($length < 3) {
return $length == 1 ? "*" : "*".substr($this->phone, -1);
} else {
$part_size = floor($length / 3);
$middle_part_size = $length - ($part_size * 2);
for ($i = 0; $i < $middle_part_size; $i++) {
$middle_string .= "*";
}
return substr($this->phone, 0, $part_size).$middle_string.substr($this->phone, -$part_size);
}
}
public function usersAttendanceSession()
{
return $this->hasMany(UserAttendanceSession::class, 'session_id');
}
}

View File

@@ -0,0 +1,22 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class AttendanceSetting extends Model
{
use HasFactory;
protected $table ="attendance_settings";
protected $fillable = [
'win_rate',
'bot_rate',
'start_time',
'end_time',
'money_min',
'money_max',
'time_each',
'setphonewin'
];
}

11
app/Models/Cache.php Normal file
View File

@@ -0,0 +1,11 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Cache extends Model
{
use HasFactory;
}

18
app/Models/ChanLe.php Normal file
View File

@@ -0,0 +1,18 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class ChanLe extends Model
{
use HasFactory;
protected $fillable = [
'min',
'max',
'sdt',
'tile'
];
}

11
app/Models/ChanLe2.php Normal file
View File

@@ -0,0 +1,11 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class ChanLe2 extends Model
{
use HasFactory;
}

View File

@@ -0,0 +1,15 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class ConfigMessageMomo extends Model
{
use HasFactory;
protected $fillable = [
];
}

20
app/Models/Gap3.php Normal file
View File

@@ -0,0 +1,20 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Gap3 extends Model
{
use HasFactory;
protected $fillable = [
'min',
'max',
'sdt',
'tile1',
'tile2',
'tile3'
];
}

11
app/Models/LichSuBank.php Normal file
View File

@@ -0,0 +1,11 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class LichSuBank extends Model
{
use HasFactory;
}

View File

@@ -0,0 +1,12 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class LichSuChoiAttendanceDate extends Model
{
protected $table = "lich_su_attendance_date";
use HasFactory;
}

View File

@@ -0,0 +1,27 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class LichSuChoiMomo extends Model
{
use HasFactory;
public function getSdtHiddenAttribute()
{
$middle_string = "";
$length = strlen($this->sdt);
if ($length < 3) {
return $length == 1 ? "*" : "*".substr($this->sdt, -1);
} else {
$part_size = floor($length / 3);
$middle_part_size = $length - ($part_size * 2);
for ($i = 0; $i < $middle_part_size; $i++) {
$middle_string .= "*";
}
return substr($this->sdt, 0, $part_size).$middle_string.substr($this->sdt, -$part_size);
}
}
}

View File

@@ -0,0 +1,11 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class LichSuChoiNoHu extends Model
{
use HasFactory;
}

View File

@@ -0,0 +1,11 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class LichSuTraThuongTuan extends Model
{
use HasFactory;
}

11
app/Models/LimitCron.php Normal file
View File

@@ -0,0 +1,11 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class LimitCron extends Model
{
use HasFactory;
}

12
app/Models/MaGiaoDich.php Normal file
View File

@@ -0,0 +1,12 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class MaGiaoDich extends Model
{
protected $table = "ma_giao_dichs";
use HasFactory;
}

17
app/Models/NoHuu.php Normal file
View File

@@ -0,0 +1,17 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class NoHuu extends Model
{
use HasFactory;
protected $fillable = [
'tiencuoc',
'tienmacdinh',
'ptvaohu',
];
}

35
app/Models/Setting.php Normal file
View File

@@ -0,0 +1,35 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Setting extends Model
{
use HasFactory;
protected $fillable = [
'title',
'description',
'logo',
'linkvideoyoutube',
'zalo',
'baotri',
'script',
'color_header',
'color_footer',
'color_table',
'color_table2',
'on_chanle',
'on_taixiu',
'on_chanle2',
'on_gap3',
'on_tong3so',
'on_1phan3',
'on_nohu',
'on_trathuongtuan',
'on_diemdanh',
'on_diemdanh_ngay'
];
}

View File

@@ -0,0 +1,11 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class SettingPhanThuongTop extends Model
{
use HasFactory;
}

18
app/Models/TaiXiu.php Normal file
View File

@@ -0,0 +1,18 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class TaiXiu extends Model
{
use HasFactory;
protected $fillable = [
'min',
'max',
'sdt',
'tile'
];
}

11
app/Models/Tong3So.php Normal file
View File

@@ -0,0 +1,11 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Tong3So extends Model
{
use HasFactory;
}

12
app/Models/TopTuan.php Normal file
View File

@@ -0,0 +1,12 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class TopTuan extends Model
{
protected $table = "top_tuan";
use HasFactory;
}

43
app/Models/User.php Normal file
View File

@@ -0,0 +1,43 @@
<?php
namespace App\Models;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class User extends Authenticatable
{
use HasFactory, Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name',
'email',
'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
}

View File

@@ -0,0 +1,34 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class UserAttendanceSession extends Model
{
use HasFactory;
protected $table = "users_attendance_session";
protected $fillable = [
'session_id',
'user_id',
'phone',
'status',
];
public function getPhone()
{
$middle_string = "";
$length = strlen($this->phone);
if ($length < 3) {
return $length == 1 ? "*" : "*".substr($this->phone, -1);
} else {
$part_size = floor($length / 3);
$middle_part_size = $length - ($part_size * 2);
for ($i = 0; $i < $middle_part_size; $i++) {
$middle_string .= "*";
}
return substr($this->phone, 0, $part_size).$middle_string.substr($this->phone, -$part_size);
}
}
}

128
app/Models/WEB2M.php Normal file
View File

@@ -0,0 +1,128 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Http;
use App\Models\AccountMomo;
use App\Models\LichSuBank;
class WEB2M extends AccountMomo
{
//Lấy lịch sử giao dịch
public function GetGiaoDich($token,$webapi){
if($webapi == 1 ){
$url = "https://nguyenkhoa.dichvuapi.com/historyapimomo1h/$token";
}
else{
//$url = "https://thueapimomo.vn/HISTORYAPIMOMOVIP?token=$token&time=1";https://apiv3.web2m.com
$url = "https://apiv3.web2m.com/historyapimomo1h/$token";
}
$response = Http::get($url);
return $response->json();
}
//Chuyển tiền MOMO
public function Bank($token, $sdtnguoinhan, $password, $money, $noidung,$webapi){
//$url = "https://api.web2m.com/TRANSFERAPIMOMO/$token/$sdtnguoinhan/$password/$money/$noidung";
if($webapi == 1 ){
$url = "https://nguyenkhoa.dichvuapi.com/TRANSFERAPIMOMO/$token/$sdtnguoinhan/$password/$money/$noidung";
}
else{
//$url = "https://thueapimomo.vn/TRANSFERAPIMOMO?token=$token&phone=$sdtnguoinhan&cash=$money&comment=$noidung&passmomo=$password";
$url = "https://apiv3.web2m.com/TRANSFERAPIMOMO/$token/$sdtnguoinhan/$password/$money/$noidung";
}
$response = Http::get($url);
$AccountMomo = new AccountMomo;
$getInfoPhone = $AccountMomo->where([
'token' => $token
])->first();
$LichSuBank = new LichSuBank;
$LichSuBank->sdtbank = $getInfoPhone->sdt;
$LichSuBank->nguoinhan = $sdtnguoinhan;
$LichSuBank->sotien = $money;
$LichSuBank->noidung = $noidung;
$LichSuBank->response = json_encode($response->json() ?? []);
$LichSuBank->save();
return $response->json();
}
public function getMoney_momo($token,$webapi)
{
try {
//$result = Http::get("https://api.web2m.com/apigetsodu/$token")->json();
if($webapi == 1 ){
$result = Http::get("https://nguyenkhoa.dichvuapi.com/apigetsodu/$token")->json();
}
else{
//$result = Http::get("https://thueapimomo.vn/GETBALANCEAPIMOMO?token=$token")->json();
$result = Http::get("https://apiv3.web2m.com/apigetsodu/$token")->json();
}
//if($webapi == 1 ){
if(true){
if(isset($result['status']) && $result['status'] == 200){
return $result['SoDu'];
}else
{
return 0;
}
}
else{
if(isset($result['status']) && $result['status'] == 'success'){
return $result['balance'];
}else
{
return 0;
}
}
}
catch(Exception $e) {
return 0;
}
}
public function getName_momo($sdt, $token, $webapi)
{
try {
//$result = Http::get("https://api.web2m.com/apigetten/".$sdt."/".$token)->json();
if($webapi == 1 ){
$result = Http::get("https://nguyenkhoa.dichvuapi.com/apigetten/".$sdt."/".$token)->json();
}
else{
$result = Http::get("https://apiv3.web2m.com/apigetten/".$sdt."/".$token)->json();
// $result = Http::get("https://thueapimomo.vn/GETNAMEAPIMOMO?token=$token&phone=$sdt")->json();
}
if(isset($result['status']) && $result['status'] == 200)
{
return $result['name'];
}
else
{
if( !empty($result['msg']) ){
return $result['msg'];
} else {
return 'Có lỗi xãy ra vui lòng F5';
}
}
}
catch(Exception $e) {
return 'Có lỗi xãy ra vui lòng thử lại';
}
}
}

85
app/Models/WEB2Mbk.php Normal file
View File

@@ -0,0 +1,85 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Http;
use App\Models\AccountMomo;
use App\Models\LichSuBank;
class WEB2M extends AccountMomo
{
//Lấy lịch sử giao dịch
public function GetGiaoDich($token){
$url = "https://api.web2m.com/historyapimomo1h/$token";
$response = Http::get($url);
return $response->json();
}
//Chuyển tiền MOMO
public function Bank($token, $sdtnguoinhan, $password, $money, $noidung){
$url = "https://api.web2m.com/TRANSFERAPIMOMO/$token/$sdtnguoinhan/$password/$money/$noidung";
$response = Http::get($url);
$AccountMomo = new AccountMomo;
$getInfoPhone = $AccountMomo->where([
'token' => $token
])->first();
$LichSuBank = new LichSuBank;
$LichSuBank->sdtbank = $getInfoPhone->sdt;
$LichSuBank->nguoinhan = $sdtnguoinhan;
$LichSuBank->sotien = $money;
$LichSuBank->noidung = $noidung;
$LichSuBank->response = json_encode($response->json() ?? []);
$LichSuBank->save();
return $response->json();
}
public function getMoney_momo($token)
{
try {
$result = Http::get("https://api.web2m.com/apigetsodu/$token")->json();
if(isset($result['status']) && $result['status'] == 200)
{
return $result['SoDu'];
}
else
{
return 0;
}
}
catch(Exception $e) {
return 0;
}
}
public function getName_momo($sdt, $token)
{
try {
$result = Http::get("https://api.web2m.com/apigetten/".$sdt."/".$token)->json();
if(isset($result['status']) && $result['status'] == 200)
{
return $result['name'];
}
else
{
if( !empty($result['msg']) ){
return $result['msg'];
} else {
return 'Có lỗi xãy ra vui lòng F5';
}
}
}
catch(Exception $e) {
return 'Có lỗi xãy ra vui lòng thử lại';
}
}
}

11
app/Models/X1Phan3.php Normal file
View File

@@ -0,0 +1,11 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class X1Phan3 extends Model
{
use HasFactory;
}

View File

@@ -0,0 +1,28 @@
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
//
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace App\Providers;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Gate;
class AuthServiceProvider extends ServiceProvider
{
/**
* The policy mappings for the application.
*
* @var array
*/
protected $policies = [
// 'App\Models\Model' => 'App\Policies\ModelPolicy',
];
/**
* Register any authentication / authorization services.
*
* @return void
*/
public function boot()
{
$this->registerPolicies();
//
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Broadcast;
use Illuminate\Support\ServiceProvider;
class BroadcastServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Broadcast::routes();
require base_path('routes/channels.php');
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace App\Providers;
use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Event;
class EventServiceProvider extends ServiceProvider
{
/**
* The event listener mappings for the application.
*
* @var array
*/
protected $listen = [
Registered::class => [
SendEmailVerificationNotification::class,
],
];
/**
* Register any events for your application.
*
* @return void
*/
public function boot()
{
//
}
}

View File

@@ -0,0 +1,63 @@
<?php
namespace App\Providers;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Facades\Route;
class RouteServiceProvider extends ServiceProvider
{
/**
* The path to the "home" route for your application.
*
* This is used by Laravel authentication to redirect users after login.
*
* @var string
*/
public const HOME = '/';
/**
* The controller namespace for the application.
*
* When present, controller route declarations will automatically be prefixed with this namespace.
*
* @var string|null
*/
// protected $namespace = 'App\\Http\\Controllers';
/**
* Define your route model bindings, pattern filters, etc.
*
* @return void
*/
public function boot()
{
$this->configureRateLimiting();
$this->routes(function () {
Route::prefix('api')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/web.php'));
});
}
/**
* Configure the rate limiters for the application.
*
* @return void
*/
protected function configureRateLimiting()
{
RateLimiter::for('api', function (Request $request) {
return Limit::perMinute(60)->by(optional($request->user())->id ?: $request->ip());
});
}
}

165
app/Traits/PhoneNumber.php Normal file
View File

@@ -0,0 +1,165 @@
<?php
/**
*File name : PhoneNumber.php / Date: 10/27/2021 - 11:26 PM
*/
namespace App\Traits;
class PhoneNumber
{
//private $phonetype='CELL'; //CELL, HOME
private $arr_Prefix = [
'CELL' => [
'016966' => '03966',
'0169' => '039',
'0168' => '038',
'0167' => '037',
'0166' => '036',
'0165' => '035',
'0164' => '034',
'0163' => '033',
'0162' => '032',
'0120' => '070',
'0121' => '079',
'0122' => '077',
'0126' => '076',
'0128' => '078',
'0123' => '083',
'0124' => '084',
'0125' => '085',
'0127' => '081',
'0129' => '082',
'01992' => '059',
'01993' => '059',
'01998' => '059',
'01999' => '059',
'0186' => '056',
'0188' => '058',
],
// 'HOME' => [
// '076' => '0296',
// '064' => '0254',
// '0281' => '0209',
// '0240' => '0204',
// '0781' => '0291',
// '0241' => '0222',
// '075' => '0275',
// '056' => '0256',
// '0650' => '0274',
// '0651' => '0271',
// '062' => '0252',
// '0780' => '0290',
// '0710' => '0292',
// '026' => '0206',
// '0511' => '0236',
// '0500' => '0262',
// '0501' => '0261',
// '0230' => '0215',
// '061' => '0251',
// '067' => '0277',
// '059' => '0269',
// '0351' => '0226',
// '04' => '024',
// '039' => '0239',
// '0320' => '0220',
// '031' => '0225',
// '0711' => '0293',
// '08' => '028',
// '0321' => '0221',
// '058' => '0258',
// '077' => '0297',
// '060' => '0260',
// '0231' => '0213',
// '063' => '0263',
// '025' => '0205',
// '020' => '0214',
// '072' => '0272',
// '0350' => '0228',
// '038' => '0238',
// '030' => '0229',
// '068' => '0259',
// '057' => '0257',
// '052' => '0232',
// '0510' => '0235',
// '055' => '0255',
// '033' => '0203',
// '053' => '0233',
// '079' => '0299',
// '022' => '0212',
// '066' => '0276',
// '036' => '0227',
// '0280' => '0208',
// '037' => '0237',
// '054' => '0234',
// '073' => '0273',
// '074' => '0294',
// '027' => '0207',
// '070' => '0270',
// '029' => '0216',
// ],
];
function convert($phonenumber, $convertOld = false)
{
if (!empty($phonenumber)) {
//1. Xóa ký tự trắng
$phonenumber = str_replace(' ', '', $phonenumber);
//2. Xóa các dấu chấm phân cách
$phonenumber = str_replace('.', '', $phonenumber);
//3. Xóa các dấu gạch nối phân cách
$phonenumber = str_replace('-', '', $phonenumber);
//4. Xóa dấu mở ngoặc đơn
$phonenumber = str_replace('(', '', $phonenumber);
//5. Xóa dấu đóng ngoặc đơn
$phonenumber = str_replace(')', '', $phonenumber);
//6. Xóa dấu +
$phonenumber = str_replace('+', '', $phonenumber);
//7. Chuyển 84 đầu thành 0
if (substr($phonenumber, 0, 2) == '84') {
$phonenumber = '0'.substr($phonenumber, 2, strlen($phonenumber) - 2);
}
$dathaythe = false;
// foreach ($this->arr_Prefix['HOME'] as $key => $value) {
// //$prefixlen=strlen($key);
// dd($key);
// if (strpos($phonenumber, $key) === 0) {
// $prefix = $key;
// $prefixlen = strlen($key);
// $phone = substr($phonenumber, $prefixlen, strlen($phonenumber) - $prefixlen);
// $prefix = str_replace($key, $value, $prefix);
// $phonenumber = $prefix.$phone;
// dd($phonenumber);
// //$phonenumber=str_replace($key,$value,$phonenumber);
// $dathaythe = true;
// break;
// }
// }
if ($dathaythe == false) {
$arrayPrefix = $convertOld ? array_flip($this->arr_Prefix['CELL']) : $this->arr_Prefix['CELL'];
foreach ($arrayPrefix as $key => $value) {
//$prefixlen=strlen($key);
if (strpos($phonenumber, $key) === 0) {
$prefix = $key;
$prefixlen = strlen($key);
$phone = substr($phonenumber, $prefixlen, strlen($phonenumber) - $prefixlen);
$prefix = str_replace($key, $value, $prefix);
$phonenumber = $prefix.$phone;
//$phonenumber=str_replace($key,$value,$phonenumber);
$dathaythe = true;
break;
}
}
}
return $phonenumber;
} else {
return false;
}
}
}