API work
This commit is contained in:
parent
32595ab5a1
commit
13fb2cfe98
70 changed files with 3614 additions and 401 deletions
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Mail\MailCheckout;
|
||||
use App\Models\Country;
|
||||
use App\Models\Product;
|
||||
use App\Models\ShippingCountry;
|
||||
|
|
@ -12,6 +13,7 @@ use App\Services\CustomerPriority;
|
|||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use PHPUnit\Framework\Constraint\Count;
|
||||
use Yard;
|
||||
|
||||
|
|
@ -34,7 +36,6 @@ class ShoppingUserController extends Controller
|
|||
*/
|
||||
public function status(Request $request)
|
||||
{
|
||||
//$this->member_id = auth()->user()->m_sponsor;
|
||||
|
||||
$request->validate([
|
||||
'wp_order_numbers' => 'required',
|
||||
|
|
@ -55,17 +56,18 @@ class ShoppingUserController extends Controller
|
|||
'time' => Carbon::now()->toDateTimeString()
|
||||
], 400);
|
||||
}
|
||||
|
||||
$status = [];
|
||||
//TODO Status
|
||||
foreach ($wp_order_numbers as $wp_order_number){
|
||||
$shopping_user = ShoppingUser::where('wp_order_number', '=', $wp_order_number)->first();
|
||||
$status[] = [
|
||||
'wp_order_number' => $wp_order_number,
|
||||
'user' => $shopping_user ? true : false,
|
||||
'order' => ($shopping_user && $shopping_user->shopping_order) ? true : false,
|
||||
'status' => 'free',
|
||||
'status' => $shopping_user ? $shopping_user->getAPIShippedType() : false,
|
||||
];
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $status,
|
||||
|
|
@ -74,6 +76,112 @@ class ShoppingUserController extends Controller
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* wp_order_number [1234]
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function cancel(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'wp_order_number' => 'required|int',
|
||||
]);
|
||||
$shopping_user = ShoppingUser::where('wp_order_number', '=', $request->wp_order_number)->first();
|
||||
if (!$shopping_user) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Entry with wp_order_number ' . $request->wp_order_number . ' not found',
|
||||
'order' => false,
|
||||
'status' => false,
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
], 400);
|
||||
}
|
||||
if(!$shopping_user->shopping_order){
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Entry with wp_order_number ' . $request->wp_order_number . ' has no order',
|
||||
'order' => false,
|
||||
'status' => $shopping_user->getAPIShippedType(),
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
], 400);
|
||||
}
|
||||
if($shopping_user->shopping_order->shipped > 0){
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Entry with wp_order_number ' . $request->wp_order_number . ' can not cancel',
|
||||
'order' => true,
|
||||
'status' => $shopping_user->getAPIShippedType(),
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
], 400);
|
||||
}
|
||||
|
||||
$shopping_user->shopping_order->shipped = 10;
|
||||
$shopping_user->shopping_order->save();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Entry with wp_order_number ' . $request->wp_order_number . ' is cancel',
|
||||
'order' => true,
|
||||
'status' => $shopping_user->getAPIShippedType(),
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
], 200);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* wp_order_number [1234]
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function open(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'wp_order_number' => 'required|int',
|
||||
]);
|
||||
$shopping_user = ShoppingUser::where('wp_order_number', '=', $request->wp_order_number)->first();
|
||||
if (!$shopping_user) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Entry with wp_order_number ' . $request->wp_order_number . ' not found',
|
||||
'order' => false,
|
||||
'status' => false,
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
], 400);
|
||||
}
|
||||
if(!$shopping_user->shopping_order){
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Entry with wp_order_number ' . $request->wp_order_number . ' has no order',
|
||||
'order' => false,
|
||||
'status' => $shopping_user->getAPIShippedType(),
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
], 400);
|
||||
}
|
||||
if($shopping_user->shopping_order->shipped !== 10){
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Entry with wp_order_number ' . $request->wp_order_number . ' can not open',
|
||||
'order' => true,
|
||||
'status' => $shopping_user->getAPIShippedType(),
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
], 400);
|
||||
}
|
||||
|
||||
$shopping_user->shopping_order->shipped = 0;
|
||||
$shopping_user->shopping_order->save();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Entry with wp_order_number ' . $request->wp_order_number . ' is open',
|
||||
'order' => true,
|
||||
'status' => $shopping_user->getAPIShippedType(),
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
], 200);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* wp_order_numbers [1234, 1234]
|
||||
|
|
@ -110,16 +218,13 @@ class ShoppingUserController extends Controller
|
|||
$user = $this->prepareForShow($shopping_user);
|
||||
$order = $this->prepareForShowOrder($shopping_user->shopping_order);
|
||||
}
|
||||
//TODO Status
|
||||
|
||||
$data[] = [
|
||||
'wp_order_number' => $wp_order_number,
|
||||
'user' => $user,
|
||||
'order' => $order,
|
||||
'customer_number' => $shopping_user ? $shopping_user->number : false,
|
||||
'member_email' => ($shopping_user && $shopping_user->member) ? $shopping_user->member->email : false,
|
||||
'status' => 'free',
|
||||
];
|
||||
'status' => $shopping_user ? $shopping_user->getAPIShippedType() : false, ];
|
||||
}
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
|
|
@ -153,6 +258,8 @@ class ShoppingUserController extends Controller
|
|||
$data['member_id'] = $this->member_id ;
|
||||
$data['number'] = ShoppingUser::max('number') + 1;
|
||||
$data['mode'] = $request->mode ? $request->mode : 'live';
|
||||
$data['is_from'] = 'extern';
|
||||
$data['is_for'] = 'ot';
|
||||
|
||||
$shopping_user = ShoppingUser::create($data);
|
||||
|
||||
|
|
@ -198,7 +305,7 @@ class ShoppingUserController extends Controller
|
|||
$priority = CustomerPriority::checkChangeOne($shopping_user, $data, true);
|
||||
$updated = $shopping_user->fill($data)->save();
|
||||
\App\Services\Shop::newUserOrder($shopping_user->number);
|
||||
//TODO Status
|
||||
|
||||
if ($updated){
|
||||
$user = $this->prepareForShow($shopping_user);
|
||||
$order = $this->prepareForShowOrder($shopping_user->shopping_order);
|
||||
|
|
@ -211,7 +318,7 @@ class ShoppingUserController extends Controller
|
|||
'customer_priority' => $priority,
|
||||
'customer_number' => $shopping_user ? $shopping_user->number : false,
|
||||
'member_email' => ($shopping_user && $shopping_user->member) ? $shopping_user->member->email : false,
|
||||
'status' => 'free',
|
||||
'status' => $shopping_user ? $shopping_user->getAPIShippedType() : false,
|
||||
],
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
], 200);
|
||||
|
|
@ -254,9 +361,16 @@ class ShoppingUserController extends Controller
|
|||
}
|
||||
|
||||
$wp_invoice_path = isset($request->wp_invoice_path) ? $request->wp_invoice_path : null;
|
||||
$wp_order = $this->prepareOrder($wp_order, $shopping_user, $wp_invoice_path);
|
||||
$wp_advertising = isset($request->wp_advertising) ? $request->wp_advertising : '';
|
||||
$wp_incentives = isset($request->wp_incentives) ? $request->wp_incentives : '';
|
||||
|
||||
$wp_notice = [
|
||||
'wp_advertising' => $wp_advertising,
|
||||
'wp_incentives' => $wp_incentives,
|
||||
];
|
||||
|
||||
$wp_order = $this->prepareOrder($wp_order, $shopping_user, $wp_invoice_path, $wp_notice);
|
||||
|
||||
//TODO Status
|
||||
if ($wp_order){
|
||||
$user = $this->prepareForShow($shopping_user);
|
||||
$order = $this->prepareForShowOrder($shopping_user->shopping_order);
|
||||
|
|
@ -265,12 +379,14 @@ class ShoppingUserController extends Controller
|
|||
'data' => [
|
||||
'wp_order_number' => $shopping_user->wp_order_number,
|
||||
'wp_invoice_path' => $wp_invoice_path,
|
||||
'wp_advertising' => $wp_advertising,
|
||||
'wp_incentives' => $wp_incentives,
|
||||
'wp_order' => $wp_order,
|
||||
'user' => $user,
|
||||
'order' => $order,
|
||||
'customer_number' => $shopping_user->number,
|
||||
'member_email' => $shopping_user->member->email,
|
||||
'status' => 'free',
|
||||
'status' => $shopping_user->getAPIShippedType(),
|
||||
],
|
||||
'time' => Carbon::now()->toDateTimeString()
|
||||
], 200);
|
||||
|
|
@ -458,7 +574,7 @@ class ShoppingUserController extends Controller
|
|||
return $ret;
|
||||
}
|
||||
|
||||
private function prepareOrder($wp_shopping_order, $shopping_user, $wp_invoice_path){
|
||||
private function prepareOrder($wp_shopping_order, $shopping_user, $wp_invoice_path, $wp_notice){
|
||||
Yard::instance('shopping')->destroy();
|
||||
$ret = [];
|
||||
|
||||
|
|
@ -489,14 +605,16 @@ class ShoppingUserController extends Controller
|
|||
if($ShippingCountry){
|
||||
Yard::instance('shopping')->setShippingCountryWithPrice($ShippingCountry->id);
|
||||
}
|
||||
$shopping_order = $this->makeShoppingOrder($shopping_user, $wp_invoice_path);
|
||||
$shopping_order = $this->makeShoppingOrder($shopping_user, $wp_invoice_path, $wp_notice);
|
||||
$this->orderStatusSendMail($shopping_order);
|
||||
|
||||
$shopping_user->shopping_order = $shopping_order;
|
||||
Yard::instance('shopping')->destroy();
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
private function makeShoppingOrder($shopping_user, $wp_invoice_path){
|
||||
private function makeShoppingOrder($shopping_user, $wp_invoice_path, $wp_notice){
|
||||
|
||||
$data = [
|
||||
'shopping_user_id' => $shopping_user->id,
|
||||
|
|
@ -505,15 +623,18 @@ class ShoppingUserController extends Controller
|
|||
'user_shop_id' => auth()->user()->user_sponsor->shop->id,
|
||||
'member_id' => $shopping_user->member_id,
|
||||
'total' => Yard::instance('shopping')->total(2, '.', ''),
|
||||
'subtotal' => Yard::instance('shopping')->subtotal(2, '.', ''),
|
||||
'shipping' => Yard::instance('shopping')->shipping(2, '.', ','),
|
||||
'subtotal' => Yard::instance('shopping')->subtotalWithShipping(2, '.', ''),
|
||||
//'tax_rate' => Yard::getTaxRate(),
|
||||
'shipping_net' => Yard::instance('shopping')->shippingNet(2, '.', ''),
|
||||
'subtotal_ws' => Yard::instance('shopping')->subtotalWithShipping(2, '.', ''),
|
||||
'tax' => Yard::instance('shopping')->taxWithShipping(2, '.', ''),
|
||||
'total_shipping' => Yard::instance('shopping')->totalWithShipping(2, '.', ''),
|
||||
'points' => Yard::instance('shopping')->points(),
|
||||
'weight' => Yard::instance('shopping')->weight(),
|
||||
'paid' => true,
|
||||
'txaction' => 'extern',
|
||||
'wp_invoice_path' => $wp_invoice_path,
|
||||
'wp_notice' => $wp_notice,
|
||||
'mode' => $shopping_user->mode,
|
||||
];
|
||||
$shopping_order = $shopping_user->shopping_order;
|
||||
|
|
@ -534,6 +655,7 @@ class ShoppingUserController extends Controller
|
|||
'product_id' => $item->id,
|
||||
'qty' => $item->qty,
|
||||
'price' => $item->price,
|
||||
'price_net' => Yard::instance('shopping')->rowPriceNet($item, 3, '.', ''),
|
||||
'tax_rate' => $item->taxRate,
|
||||
'slug' => $item->options->slug,
|
||||
])->save();
|
||||
|
|
@ -552,11 +674,27 @@ class ShoppingUserController extends Controller
|
|||
'product_id' => $item->id,
|
||||
'qty' => $item->qty,
|
||||
'price' => $item->price,
|
||||
'price_net' => Yard::instance('shopping')->rowPriceNet($item, 3, '.', ''),
|
||||
'tax_rate' => $item->taxRate,
|
||||
'slug' => $item->options->slug
|
||||
]);
|
||||
}
|
||||
|
||||
return $shopping_order;
|
||||
}
|
||||
|
||||
|
||||
public function orderStatusSendMail(ShoppingOrder $shopping_order){
|
||||
|
||||
$bcc = [];
|
||||
$user_mail = $shopping_order->shopping_user->member->email;
|
||||
if($shopping_order->mode === 'dev'){
|
||||
$bcc[] = config('app.checkout_test_mail');
|
||||
}else{
|
||||
$bcc[] = config('app.checkout_mail');
|
||||
}
|
||||
|
||||
Mail::to($user_mail)->bcc($bcc)->send(new MailCheckout($shopping_order->txaction, $shopping_order, null, false, $shopping_order->mode));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -65,6 +65,18 @@ class ProductController extends Controller
|
|||
$rules = array(
|
||||
'name' => 'required',
|
||||
);
|
||||
/*if(isset($data['number']) && $data['number'] != ""){
|
||||
$rules['number'] = 'int';
|
||||
}*/
|
||||
if(isset($data['wp_number'])){
|
||||
if($data['id'] !== "new"){
|
||||
$model = Product::findOrFail($data['id']);
|
||||
$rules['wp_number'] = 'unique:products,wp_number,'.$model->id;
|
||||
}else{
|
||||
$rules['wp_number'] = 'unique:products,wp_number';
|
||||
|
||||
}
|
||||
}
|
||||
$validator = Validator::make(Request::all(), $rules);
|
||||
|
||||
if($data['id'] === "new"){
|
||||
|
|
@ -72,8 +84,12 @@ class ProductController extends Controller
|
|||
}else{
|
||||
$model = Product::findOrFail($data['id']);
|
||||
}
|
||||
$country_for_prices = Country::where('own_eur', '=', true)->orWhere('currency', '=', true)->get();
|
||||
|
||||
$data = [
|
||||
'product' => $model,
|
||||
'country_for_prices' => $country_for_prices,
|
||||
|
||||
];
|
||||
|
||||
if ($validator->fails()) {
|
||||
|
|
|
|||
|
|
@ -31,8 +31,14 @@ class SalesController extends Controller
|
|||
|
||||
public function usersDetail($id)
|
||||
{
|
||||
$ShoppingOrder = ShoppingOrder::find($id);
|
||||
if($ShoppingOrder->shipped === 0){
|
||||
$ShoppingOrder->shipped = 1;
|
||||
$ShoppingOrder->save();
|
||||
}
|
||||
|
||||
$data = [
|
||||
'shopping_order' => ShoppingOrder::find($id),
|
||||
'shopping_order' => $ShoppingOrder,
|
||||
'isAdmin' => true,
|
||||
'isView' => 'sales_user',
|
||||
];
|
||||
|
|
@ -126,8 +132,13 @@ class SalesController extends Controller
|
|||
|
||||
public function customersDetail($id)
|
||||
{
|
||||
$ShoppingOrder = ShoppingOrder::find($id);
|
||||
if($ShoppingOrder->shipped === 0){
|
||||
$ShoppingOrder->shipped = 1;
|
||||
$ShoppingOrder->save();
|
||||
}
|
||||
$data = [
|
||||
'shopping_order' => ShoppingOrder::find($id),
|
||||
'shopping_order' => $ShoppingOrder,
|
||||
'isAdmin' => true,
|
||||
'isView' => 'sales_customer',
|
||||
];
|
||||
|
|
|
|||
|
|
@ -82,11 +82,11 @@ class ContactController extends Controller
|
|||
}
|
||||
|
||||
|
||||
$checkout_mail = config('app.contact_mail');
|
||||
$contact_mail = config('app.contact_mail');
|
||||
if($user_shop){
|
||||
Mail::to($contact['email'])->bcc([$user_shop->user->email, $checkout_mail])->send(new MailContact($contact));
|
||||
Mail::to($contact['email'])->bcc([$user_shop->user->email, $contact_mail])->send(new MailContact($contact));
|
||||
}else{
|
||||
Mail::to($contact['email'])->bcc($checkout_mail)->send(new MailContact($contact));
|
||||
Mail::to($contact['email'])->bcc($contact_mail)->send(new MailContact($contact));
|
||||
}
|
||||
|
||||
$data = [
|
||||
|
|
|
|||
|
|
@ -32,26 +32,31 @@ class MailCheckout extends Mailable
|
|||
|
||||
if($this->txaction === 'paid'){
|
||||
$this->subject = __('email.checkout_subject_paid')." ";
|
||||
$this->subject .= "mivita.care";
|
||||
}elseif($this->txaction === 'extern'){
|
||||
$this->subject = __('email.checkout_subject_extern').": ";
|
||||
$this->subject .= $shopping_order->member->account->m_first_name." ".$shopping_order->member->account->m_last_name." - ";
|
||||
$this->subject .= $shopping_order->shopping_user->billing_firstname." ".$shopping_order->shopping_user->billing_lastname;
|
||||
}else{
|
||||
$this->subject = __('email.checkout_subject')." ";
|
||||
$this->subject .= "mivita.care";
|
||||
}
|
||||
|
||||
/*if($shopping_order->user_shop){
|
||||
$this->subject .= $shopping_order->user_shop->slug.".";
|
||||
}*/
|
||||
$this->subject .= "mivita.care";
|
||||
}
|
||||
|
||||
|
||||
public function build()
|
||||
{
|
||||
$salutation = __('email.salutation').",";
|
||||
$salutation = __('email.hello').",";
|
||||
|
||||
if($this->shopping_order->shopping_user){
|
||||
if($this->txaction !== 'extern' && $this->shopping_order->shopping_user){
|
||||
$salutation = __('email.hello')." ".$this->shopping_order->shopping_user->billing_firstname.",";
|
||||
//make Adresse
|
||||
}
|
||||
if($this->txaction === 'paid'){
|
||||
if($this->txaction === 'paid' || $this->txaction === 'extern'){
|
||||
return $this->view('emails.checkout')->with([
|
||||
'salutation' => $salutation,
|
||||
'copy1line' => __('email.checkout_copy1line'),
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ class ShippingPrice extends Model
|
|||
$this->attributes['factor'] = $value ? Util::reFormatNumber($value) : null;
|
||||
}
|
||||
|
||||
public function setTaxAttribute($value)
|
||||
public function setTaxRateAttribute($value)
|
||||
{
|
||||
$this->attributes['tax_rate'] = $value ? Util::reFormatNumber($value) : null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -107,28 +107,41 @@ class ShoppingOrder extends Model
|
|||
'paid',
|
||||
'txaction',
|
||||
'wp_invoice_path',
|
||||
'wp_notice',
|
||||
'mode',
|
||||
'shipped',
|
||||
'tracking'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'wp_notice' => 'array',
|
||||
];
|
||||
|
||||
public static $shippedTypes = [
|
||||
0 => 'offen',
|
||||
1 => 'versendet',
|
||||
2 => 'abgeschlossen',
|
||||
4 => 'In Bearbeitung',
|
||||
1 => 'in Bearbeitung',
|
||||
2 => 'versendet',
|
||||
3 => 'abgeschlossen',
|
||||
10 => 'storniert'
|
||||
];
|
||||
|
||||
50 => 'storiniert'
|
||||
public static $apiShippedTypes = [
|
||||
0 => 'open', //(Fullfilment durch Händler)',
|
||||
1 => 'process', //(Fullfilment durch MIVITA: nicht Versand)
|
||||
2 => 'sent', //(Fullfilment durch MIVITA: Versand erfolgt)'
|
||||
3 => 'close', //(Fullfilment durch MIVITA: Versand erfolgt)',
|
||||
10 => 'cancel'
|
||||
];
|
||||
|
||||
public static $shippedColors = [
|
||||
0 => 'warning',
|
||||
1 => 'success',
|
||||
1 => 'info',
|
||||
2 => 'success',
|
||||
4 => 'info',
|
||||
50 => 'danger',
|
||||
3 => 'secondary',
|
||||
10 => 'danger',
|
||||
];
|
||||
|
||||
|
||||
public function shopping_user()
|
||||
{
|
||||
return $this->belongsTo('App\Models\ShoppingUser','shopping_user_id');
|
||||
|
|
@ -205,6 +218,10 @@ class ShoppingOrder extends Model
|
|||
return isset(self::$shippedTypes[$this->shipped]) ? self::$shippedTypes[$this->shipped] : "";
|
||||
}
|
||||
|
||||
public function getAPIShippedType(){
|
||||
return isset(self::$apiShippedTypes[$this->shipped]) ? self::$apiShippedTypes[$this->shipped] : "free";
|
||||
}
|
||||
|
||||
public function getShippedColor(){
|
||||
return isset(self::$shippedColors[$this->shipped]) ? self::$shippedColors[$this->shipped] : "default";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -176,6 +176,8 @@ class ShoppingUser extends Model
|
|||
'wp_order_number' => 'int',
|
||||
];
|
||||
|
||||
|
||||
|
||||
//can null
|
||||
public function member()
|
||||
{
|
||||
|
|
@ -243,4 +245,11 @@ class ShoppingUser extends Model
|
|||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAPIShippedType() {
|
||||
if($this->shopping_order){
|
||||
return $this->shopping_order->getAPIShippedType();
|
||||
}
|
||||
return "free";
|
||||
}
|
||||
}
|
||||
|
|
@ -138,6 +138,7 @@ class ProductRepository extends BaseRepository {
|
|||
{
|
||||
$this->model = $model->replicate();
|
||||
$this->model->name = "Kopie: ".$this->model->name;
|
||||
$this->model->wp_number = null;
|
||||
$this->model->save();
|
||||
|
||||
//categories
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue