API Shopping Order backend
This commit is contained in:
parent
7a040c3e19
commit
d01b4bd560
24 changed files with 1584 additions and 34 deletions
83
app/Repositories/ShopApiRepository.php
Normal file
83
app/Repositories/ShopApiRepository.php
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Services\ShopApiOrderCart;
|
||||
|
||||
class ShopApiRepository extends BaseRepository {
|
||||
|
||||
private $shopApiOrderCart;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
//$this->model = $model;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function order($data)
|
||||
{
|
||||
$this->shopApiOrderCart = new ShopApiOrderCart();
|
||||
$this->performOrderActionList($data, 0);
|
||||
return $this->shopApiOrderCart;
|
||||
}
|
||||
|
||||
public function remove($data){
|
||||
$this->performActionList($data, 5);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public function reset($data){
|
||||
$this->performActionList($data, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkout($data){
|
||||
$this->shopApiOrderCart = new ShopApiOrderCart();
|
||||
$this->performOrderCheckoutList($data, 1);
|
||||
return $this->shopApiOrderCart;
|
||||
}
|
||||
|
||||
private function performActionList($data, $status){
|
||||
if(isset($data['api_action_list'])){
|
||||
foreach($data['api_action_list'] as $orderItemId=>$v){
|
||||
$ShoppingOrder = ShoppingOrder::findOrFail($orderItemId);
|
||||
$ShoppingOrder->api_status = $status;
|
||||
$ShoppingOrder->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function performOrderActionList($data, $status){
|
||||
if(isset($data['api_action_list'])){
|
||||
foreach($data['api_action_list'] as $orderItemId=>$v){
|
||||
$ShoppingOrder = ShoppingOrder::findOrFail($orderItemId);
|
||||
$this->shopApiOrderCart->add($ShoppingOrder);
|
||||
$ShoppingOrder->api_status = $status; //<- no status change is the show list
|
||||
$ShoppingOrder->save();
|
||||
}
|
||||
$this->shopApiOrderCart->calculate();
|
||||
return $this->shopApiOrderCart;
|
||||
}
|
||||
}
|
||||
|
||||
private function performOrderCheckoutList($data, $status){
|
||||
if(isset($data['api_action_list'])){
|
||||
foreach($data['api_action_list'] as $k=>$orderItemId){
|
||||
$ShoppingOrder = ShoppingOrder::findOrFail($orderItemId);
|
||||
$this->shopApiOrderCart->add($ShoppingOrder);
|
||||
$ShoppingOrder->api_status = $status;
|
||||
$ShoppingOrder->save();
|
||||
}
|
||||
$this->shopApiOrderCart->calculate();
|
||||
$this->shopApiOrderCart->store();
|
||||
|
||||
return $this->shopApiOrderCart;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue