99 lines
3.0 KiB
PHP
Executable File
99 lines
3.0 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use Response;
|
|
use Schema;
|
|
use Hash;
|
|
use App\Libraries\ListHelper;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use App\Contracts\RatingsResourceInterface;
|
|
use App\Ratings;
|
|
use App\Helpers\HttpStatusCode;
|
|
use App\Helpers\CurrentUserHelper;
|
|
use App\Libraries\UuidHelper;
|
|
|
|
class RatingsService implements RatingsResourceInterface
|
|
{
|
|
|
|
public $rating;
|
|
|
|
|
|
public function report_stationRatings($params, $export = false)
|
|
{
|
|
|
|
$pagination = ListHelper::validatePagination($params['page_size'],$params['page']);
|
|
$list = Ratings::with(['loyaltyCard','payment','station'])
|
|
->where('ratings.is_active','=',1);
|
|
|
|
if($params['date_start'] != null && $params['date_end'] != null)
|
|
{
|
|
$list = $list->where('ratings.created_at','>=',date('Y-m-d',strtotime($params['date_start'])).' 00:00:00')
|
|
->where('ratings.created_at','<=',date('Y-m-d',strtotime($params['date_end'])).' 23:59:59');
|
|
}
|
|
|
|
|
|
if($params['search'] != null)
|
|
{
|
|
$list = $list->whereHas('loyaltyCard', function ($query) use ($params) {
|
|
$query->where('card_number', 'LIKE', '%'.$params['search'].'%');
|
|
})
|
|
->orWhereHas('payment', function ($query) use ($params) {
|
|
$query->where('item_name', 'LIKE', '%'.$params['search'].'%');
|
|
})
|
|
->orWhereHas('station', function ($query) use ($params) {
|
|
$query->where('description', 'LIKE', '%'.$params['search'].'%');
|
|
});
|
|
}
|
|
|
|
$sorting = $params['sorting'];
|
|
if(count($sorting) > 0)
|
|
{
|
|
$list = $list->sort($sorting['field'],$sorting['sort_order']);
|
|
}
|
|
|
|
if($export)
|
|
return $list->get();
|
|
else
|
|
return $list->paginate($params['page_size']);
|
|
|
|
}
|
|
|
|
public function store($data)
|
|
{
|
|
$this->rating = new Ratings();
|
|
|
|
$uuid = new UuidHelper;
|
|
$this->rating->rating_uuid = $uuid->generate_uuid1();
|
|
$this->rating->lcard_id = $data['lcard_id'];
|
|
$this->rating->station_id = $data['station_id'];
|
|
$this->rating->payment_id = $data['payment_id'];
|
|
$this->rating->rate = $data['rate'];
|
|
$this->rating->created_by = $data['lcard_id'];
|
|
|
|
if($this->rating->save())
|
|
return true;
|
|
else
|
|
return false;
|
|
}
|
|
|
|
public function update($data,$rating_id)
|
|
{
|
|
$this->rating = Ratings::where('rating_id',$rating_id)->first();
|
|
|
|
$this->rating->lcard_id = $data['lcard_id'];
|
|
$this->rating->station_id = $data['station_id'];
|
|
$this->rating->payment_id = $data['payment_id'];
|
|
$this->rating->rate = $data['rate'];
|
|
$this->rating->updated_by = $data['lcard_id'];
|
|
|
|
if($this->rating->save())
|
|
return true;
|
|
else
|
|
return false;
|
|
}
|
|
|
|
|
|
} |