first commit
This commit is contained in:
114
app/Http/Repositories/AccountMomoRepository.php
Normal file
114
app/Http/Repositories/AccountMomoRepository.php
Normal 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;
|
||||
}
|
||||
|
||||
}
|
204
app/Http/Repositories/AttendanceDateRepository.php
Normal file
204
app/Http/Repositories/AttendanceDateRepository.php
Normal 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;
|
||||
}
|
||||
|
||||
}
|
239
app/Http/Repositories/AttendanceSessionRepository.php
Normal file
239
app/Http/Repositories/AttendanceSessionRepository.php
Normal 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user