unioil-mobile-api/app/Services/LcardActionLogsService.php

105 lines
2.8 KiB
PHP

<?php
namespace App\Services;
use Response;
use Schema;
use Hash;
use Illuminate\Http\Request;
use App\Libraries\ListHelper;
use App\Contracts\LcardActionLogsInterface;
use App\Helpers\HttpStatusCode;
use App\Libraries\UuidHelper;
use App\Helpers\CurrentUserHelper;
use App\LcardActionLogs;
class LcardActionLogsService implements LcardActionLogsInterface
{
public $lcardActionLogs;
public $lactivity_id;
public $modules;
public $actions;
public function __construct()
{
$this->modules = [
'LOGIN' => 'Login',
'OTP' => 'OTP',
'PROFILE' => 'OTP',
'STATIONLOCATOR' => 'Station Locator',
'FUELTRACKER' => 'FUELTRACKER',
'TRANSACTIONS' => 'Transactions',
'RATINGS' => 'Ratings',
'PAYMENTS' => 'Payment',
'SHAREDTREATS' => 'SHAREDTREATS',
'CRONJOB' => 'CRONJOB',
'SIGNUP' => 'Sign Up',
];
$this->actions = [
'STORE' => 'store',
'UPDATE' => 'update',
'DELETE' => 'delete',
'VIEW' => 'view',
'ACTIVATE' => 'activate',
'GENERATE' => 'generate',
'EXPORT' => 'export',
'LOGIN' => 'login',
'LOGOUT' => 'logout',
'ATTEMPT' => 'attempt',
'LOCKED' => 'locked',
'SEARCH' => 'search',
'INACTIVE' => 'inactive',
];
}
public function getByField($field,$value)
{
$this->lcardActionLogs = LcardActionLogs::where($field,$value)
->orderBy('created_dt','desc');
return $this->lcardActionLogs->get();
}
public function log($id, $module, $action, $remarks = '')
{
if(isset($this->modules[$module]) && isset($this->actions[$action]))
{
$currentUser = CurrentUserHelper::get_currentMember();
$this->lcardActionLogs = new LcardActionLogs;
$this->lcardActionLogs->id = $id;
$this->lcardActionLogs->module = $this->modules[$module];
$this->lcardActionLogs->action = $this->actions[$action];
$this->lcardActionLogs->created_by = isset( $currentUser ) ? $currentUser->lcard_id : $id;
if($remarks != '')
$this->lcardActionLogs->remarks = $remarks;
if ($this->lcardActionLogs->save())
{
return true;
}
}
return false;
}
public function getByFieldWithOperator($field, $operator, $value)
{
$this->lcardActionLogs = LcardActionLogs::selectRaw('*, max(lactivity_id) as last')
->where($field,$value)
->groupBy('created_at')->orderBy('created_at','desc');
return $this->lcardActionLogs->get();
}
}