62 lines
No EOL
1.5 KiB
PHP
62 lines
No EOL
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories;
|
|
|
|
use App\Models\PromotionAdmin;
|
|
use App\Models\PromotionAdminProduct;
|
|
|
|
class AdminPromotionRepository extends BaseRepository {
|
|
|
|
|
|
public function __construct(PromotionAdmin $model){
|
|
|
|
$this->model = $model;
|
|
}
|
|
|
|
public function update($id, $data)
|
|
{
|
|
|
|
$data['active'] = isset($data['active']) ? 1 : 0;
|
|
$data['shop'] = isset($data['shop']) ? 1 : 0;
|
|
|
|
if($id == 0 || $id === 'new'){
|
|
$this->model = PromotionAdmin::create($data);
|
|
}
|
|
else{
|
|
$this->model = $this->getById($id);
|
|
$this->model->fill($data);
|
|
$this->model->save();
|
|
}
|
|
|
|
return $this->model;
|
|
}
|
|
public function updateProduct($id, $data){
|
|
$this->model = $this->getById($id);
|
|
|
|
$data['own_price'] = isset($data['own_price']) ? 1 : 0;
|
|
$data['calcu_commission'] = isset($data['calcu_commission']) ? 1 : 0;
|
|
$data['shipping'] = isset($data['shipping']) ? 1 : 0;
|
|
$data['active'] = isset($data['active']) ? 1 : 0;
|
|
|
|
if($data['id'] === 'new'){
|
|
$data['promotion_admin_id'] = $this->model->id;
|
|
$product = PromotionAdminProduct::create($data);
|
|
}
|
|
else{
|
|
$product = PromotionAdminProduct::findOrFail($data['id']);
|
|
$product->fill($data);
|
|
$product->save();
|
|
}
|
|
|
|
|
|
|
|
return $this->model;
|
|
}
|
|
|
|
public function create($data){
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
} |