Promotion Backend v1
This commit is contained in:
parent
0ed47d3553
commit
f0da981737
43 changed files with 2765 additions and 45 deletions
62
app/Repositories/AdminPromotionRepository.php
Normal file
62
app/Repositories/AdminPromotionRepository.php
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
<?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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue