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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
81
app/Repositories/UserPromotionRepository.php
Normal file
81
app/Repositories/UserPromotionRepository.php
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Services\Util;
|
||||
use App\Models\PromotionUser;
|
||||
use App\Models\PromotionAdmin;
|
||||
use App\Models\PromotionUserProduct;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\Models\PromotionAdminProduct;
|
||||
|
||||
class UserPromotionRepository extends BaseRepository {
|
||||
|
||||
|
||||
public function __construct(PromotionUser $model){
|
||||
|
||||
$this->model = $model;
|
||||
}
|
||||
|
||||
public function update($id, $data)
|
||||
{
|
||||
|
||||
$data['active'] = isset($data['active']) ? 1 : 0;
|
||||
$data['pick_up'] = isset($data['pick_up']) ? 1 : 0;
|
||||
$data['url'] = Util::sanitize($data['user_promotion_url'], true, false, true, true);
|
||||
|
||||
$this->model = $this->getById($id);
|
||||
$this->model->fill($data);
|
||||
$this->model->save();
|
||||
|
||||
$this->updateProducts($id, $data);
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
public function updateProducts($id, $data){
|
||||
|
||||
$this->model = $this->getById($id);
|
||||
if(isset($data['products_qty'])){
|
||||
foreach($data['products_qty'] as $pa_id => $qty){
|
||||
$PromotionAdminProduct = PromotionAdminProduct::findOrFail($pa_id);
|
||||
$PromotionUserProduct = $PromotionAdminProduct->getPromotionUserProducts($this->model);
|
||||
|
||||
if(isset($data['products_user'][$pa_id]) && $data['products_user'][$pa_id] > 0 && $PromotionUserProduct){
|
||||
$PromotionUserProduct->fill([
|
||||
'open_items' => intval($qty),
|
||||
'active' => isset($data['products_active'][$pa_id]) ? 1 : 0,
|
||||
]);
|
||||
$PromotionUserProduct->save();
|
||||
}else{
|
||||
$user_product = PromotionUserProduct::create([
|
||||
'promotion_admin_id' => $PromotionAdminProduct->promotion_admin_id,
|
||||
'promotion_user_id' => $this->model->id,
|
||||
'promotion_admin_product_id' => $PromotionAdminProduct->id,
|
||||
'product_id' => $PromotionAdminProduct->product_id,
|
||||
'open_items' => intval($qty),
|
||||
'active' => isset($data['products_active'][$pa_id]) ? 1 : 0,
|
||||
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
public function create($data){
|
||||
|
||||
if(isset($data['promotion_admin_id'])){
|
||||
$PromotionAdmin = PromotionAdmin::findOrFail($data['promotion_admin_id']);
|
||||
$this->model = PromotionUser::create([
|
||||
'promotion_admin_id' => $PromotionAdmin->id,
|
||||
'user_id' => Auth::user()->id,
|
||||
]);
|
||||
return $this->model;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue