245 lines
8.3 KiB
PHP
245 lines
8.3 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use Response;
|
|
use Schema;
|
|
use Hash;
|
|
use App\Libraries\ListHelper;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use App\Contracts\PhotoSliderResourceInterface;
|
|
use App\PhotoSlider;
|
|
use App\Promotions;
|
|
use App\Helpers\HttpStatusCode;
|
|
use App\Helpers\CurrentUserHelper;
|
|
use App\Libraries\UuidHelper;
|
|
use App\Libraries\S3;
|
|
|
|
class PhotoSliderService implements PhotoSliderResourceInterface
|
|
{
|
|
|
|
public $photoSlider;
|
|
|
|
public $photoslider_id;
|
|
|
|
public function listing($params)
|
|
{
|
|
|
|
$pagination = ListHelper::validatePagination($params['page_size'],$params['page']);
|
|
$list = PhotoSlider::with('promotion')
|
|
->where('is_active','=',1);
|
|
|
|
if($params['search'] != null)
|
|
{
|
|
$list->where(function($query) use ($params){
|
|
$query->where('title', 'LIKE', '%'.$params['search'].'%');
|
|
});
|
|
}
|
|
|
|
$sorting = $params['sorting'];
|
|
if(count($sorting) > 0)
|
|
{
|
|
$list = $list->orderBy($sorting['field'],$sorting['sort_order']);
|
|
}
|
|
|
|
if($pagination == true)
|
|
return $list->paginate($params['page_size']);
|
|
else
|
|
return $list->get();
|
|
|
|
}
|
|
|
|
public function store(Request $request)
|
|
{
|
|
$currentUser = CurrentUserHelper::get_currentAdmin();
|
|
$this->photoSlider = new PhotoSlider;
|
|
|
|
|
|
$promotion = $request->get('promotion_uuid') != '' ? Promotions::wherePromotionUuid($request->get('promotion_uuid'))->first() : null;
|
|
|
|
$s3 = new S3;
|
|
|
|
if(is_file($request->image))
|
|
$filePath = $s3->upload($request->file('image'),'photoSlider');
|
|
else
|
|
$filePath = $s3->remove_public_path($request->image);
|
|
|
|
$uuid = new UuidHelper;
|
|
$this->photoSlider->photoslider_uuid = $uuid->generate_uuid1();
|
|
$this->photoSlider->promotion_id = ($promotion ? $promotion->promotion_id : 0);
|
|
$this->photoSlider->title = $request->get('title');
|
|
$this->photoSlider->description = $request->get('description');
|
|
$this->photoSlider->date_start = $request->get('date_start');
|
|
$this->photoSlider->date_end = $request->get('date_end');
|
|
$this->photoSlider->image = $filePath;
|
|
$this->photoSlider->created_by = $currentUser->admin_id;
|
|
|
|
if ($this->photoSlider->save())
|
|
{
|
|
return $this->photoSlider->photoslider_id;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public function getByField($field,$value)
|
|
{
|
|
$this->photoSlider = PhotoSlider::where($field,$value);
|
|
return $this->photoSlider->get();
|
|
}
|
|
|
|
public function update($request,$uuid)
|
|
{
|
|
$currentUser = CurrentUserHelper::get_currentAdmin();
|
|
$this->photoSlider = PhotoSlider::where('photoslider_uuid',$uuid)->first();
|
|
|
|
|
|
if($this->photoSlider)
|
|
{
|
|
$promotion = $request->get('promotion_uuid') != '' ? Promotions::wherePromotionUuid($request->get('promotion_uuid'))->first() : null;
|
|
|
|
$this->photoSlider->promotion_id = ($promotion ? $promotion->promotion_id : 0);
|
|
$this->photoSlider->title = $request->get('title');
|
|
$this->photoSlider->description = $request->get('description');
|
|
$this->photoSlider->date_start = $request->get('date_start');
|
|
$this->photoSlider->date_end = $request->get('date_end');
|
|
$this->photoSlider->updated_by = $currentUser->admin_id;
|
|
|
|
if($request->has('image'))
|
|
{
|
|
$s3 = new S3;
|
|
|
|
if(is_file($request->image))
|
|
{
|
|
$filePath = $s3->upload($request->file('image'),'photoSlider');
|
|
$this->photoSlider->image = $filePath;
|
|
}
|
|
else
|
|
$this->photoSlider->image = $s3->remove_public_path($request->image);
|
|
}
|
|
|
|
if ($this->photoSlider->save())
|
|
{
|
|
return $this->photoSlider;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public function delete($uuid)
|
|
{
|
|
$currentUser = CurrentUserHelper::get_currentAdmin();
|
|
|
|
if(is_array($uuid))
|
|
{
|
|
$this->photoSlider = PhotoSlider::whereIn('photoslider_uuid',$uuid)
|
|
->update([
|
|
'is_active' => 0,
|
|
'updated_by' => $currentUser->admin_id
|
|
]);
|
|
|
|
if($this->photoSlider)
|
|
return true;
|
|
else
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
$this->photoSlider = PhotoSlider::where('photoslider_uuid',$uuid)->first();
|
|
$this->photoSlider->is_active = 0;
|
|
$this->photoSlider->updated_by = $currentUser->admin_id;
|
|
|
|
if ($this->photoSlider->save())
|
|
return true;
|
|
else
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public function getDetailsWhereIn($field,$value,$relationship = null)
|
|
{
|
|
if($relationship)
|
|
{
|
|
$details = PhotoSlider::with($relationship)
|
|
->whereIn($field,$value)->get();
|
|
}
|
|
else
|
|
{
|
|
$details = PhotoSlider::whereIn($field,$value)->get();
|
|
}
|
|
|
|
return $details->toArray();
|
|
}
|
|
|
|
public function count()
|
|
{
|
|
return PhotoSlider::where('is_active',1)->count();
|
|
}
|
|
|
|
public function getPhotoSlider()
|
|
{
|
|
$date_now = date('Y-m-d H:i:s');
|
|
|
|
$photoslider = PhotoSlider::select(
|
|
"photo_slider.photoslider_id as photoslider_id_oder",
|
|
"promotion_id as promotion_uuid",
|
|
"photo_slider.description",
|
|
"promotion_id as is_toppromotion",
|
|
"promotion_id as is_gps",
|
|
"promotion_id as promo_type",
|
|
"photo_slider.promotion_id as promotion_id",
|
|
"photo_slider.title as title",
|
|
"promotion_id as promotion_date_start",
|
|
"promotion_id as promotion_date_end",
|
|
"photo_slider.image as image",
|
|
"photo_slider.date_start as date_start",
|
|
"photo_slider.date_end",
|
|
"photo_slider.photoslider_id",
|
|
"photo_slider.photoslider_uuid",
|
|
"photo_slider.created_at as created_at",
|
|
"promotion_id as promotion_title",
|
|
"promotion_id as promotion_description",
|
|
"promotion_id as promotion_image")
|
|
->where('photo_slider.promotion_id', '=', 0)
|
|
->where('photo_slider.date_start', '<=', $date_now)
|
|
->where('photo_slider.date_end', '>=', $date_now)
|
|
->where('photo_slider.is_active','=',1)
|
|
->orderBy('date_start','asc')
|
|
->orderBy('created_at','asc');
|
|
|
|
$getPromo = PhotoSlider::select(
|
|
"photo_slider.photoslider_id as photoslider_id_oder",
|
|
"promotions.promotion_uuid",
|
|
"promotions.description",
|
|
"promotions.is_toppromotion",
|
|
"promotions.is_gps",
|
|
"promotions.promo_type",
|
|
"promotions.promotion_id as promotion_id",
|
|
"promotions.title",
|
|
"promotions.date_start as promotion_date_start",
|
|
"promotions.date_end as promotion_date_end",
|
|
"photo_slider.image as image",
|
|
"photo_slider.date_start as date_start",
|
|
"photo_slider.date_end",
|
|
"photo_slider.photoslider_id",
|
|
"photo_slider.photoslider_uuid",
|
|
"photo_slider.created_at as created_at",
|
|
"promotions.title as promotion_title",
|
|
"promotions.description as promotion_description",
|
|
"promotions.image as promotion_image"
|
|
)
|
|
->join('promotions', 'promotions.promotion_id', '=', 'photo_slider.promotion_id')
|
|
->where('photo_slider.date_start', '<=', $date_now)
|
|
->where('photo_slider.date_end', '>=', $date_now)
|
|
->where('photo_slider.is_active','=',1)
|
|
->union($photoslider);
|
|
// return $getPromo->orderBy('photoslider_id_oder','asc')->limit(5)->get();
|
|
return $getPromo->orderBy('date_start','asc')->orderBy('created_at','asc')->limit(5)->get();
|
|
}
|
|
}
|