| 108 |
lars |
1 |
<?php
|
|
|
2 |
|
| 779 |
lars |
3 |
namespace App\Http\Controllers;
|
| 108 |
lars |
4 |
|
| 1337 |
lars |
5 |
use App\Http\Requests\ActionRequest;
|
| 962 |
lars |
6 |
use App\Models\WebSetting;
|
| 1337 |
lars |
7 |
use Illuminate\Contracts\Foundation\Application;
|
|
|
8 |
use Illuminate\Contracts\View\Factory;
|
|
|
9 |
use Illuminate\Contracts\View\View;
|
|
|
10 |
use Illuminate\Http\RedirectResponse;
|
| 779 |
lars |
11 |
use Illuminate\Http\Request;
|
|
|
12 |
use App\Models\OrderAddress;
|
|
|
13 |
use App\Models\OrderItem;
|
|
|
14 |
use App\Models\Order;
|
| 108 |
lars |
15 |
|
| 779 |
lars |
16 |
class OrderController extends Controller
|
|
|
17 |
{
|
|
|
18 |
//
|
| 1454 |
lars |
19 |
private int $shipAddrId;
|
|
|
20 |
private int $billAddrId;
|
|
|
21 |
private Order $order;
|
|
|
22 |
private int $orderId;
|
| 958 |
lars |
23 |
private OrderItem $orderItem;
|
| 1454 |
lars |
24 |
private array $orderItems;
|
| 958 |
lars |
25 |
|
| 1337 |
lars |
26 |
/**
|
|
|
27 |
* Display a listing of the resource.
|
|
|
28 |
*
|
|
|
29 |
*/
|
|
|
30 |
public function index(): Factory|View|Application
|
|
|
31 |
{
|
|
|
32 |
//
|
| 1377 |
lars |
33 |
$orders = Order::with( [
|
|
|
34 |
'shop',
|
|
|
35 |
'orderType',
|
|
|
36 |
'orderItem',
|
|
|
37 |
'billAddr',
|
|
|
38 |
'shipAddr'
|
|
|
39 |
] )->orderBy( "created_at", 'desc' )->paginate( 100 );
|
|
|
40 |
return view( 'admin/orders', [ "orders" => $orders, ] );
|
| 1337 |
lars |
41 |
}
|
|
|
42 |
|
| 779 |
lars |
43 |
public function create()
|
|
|
44 |
{
|
| 958 |
lars |
45 |
$this->billAddr = new OrderAddress();
|
| 787 |
lars |
46 |
if ( !( isset( $_SESSION["SHOP"]["buy"]["Persdata"]["ID"] ) && $_SESSION["SHOP"]["buy"]["Persdata"]["ID"] ) )
|
|
|
47 |
{
|
|
|
48 |
$_SESSION["SHOP"]["buy"]["Persdata"]["ID"] = 1;
|
|
|
49 |
}
|
| 958 |
lars |
50 |
$this->billAddr->user_id = $_SESSION["SHOP"]["buy"]["Persdata"]["ID"];
|
|
|
51 |
$this->billAddr->name = $_SESSION["SHOP"]["buy"]["Persdata"]["Vorname"];
|
|
|
52 |
$this->billAddr->lastname = $_SESSION["SHOP"]["buy"]["Persdata"]["Nachname"];
|
| 781 |
lars |
53 |
if ( $_SESSION["SHOP"]["buy"]["Persdata"]["Firma"] )
|
|
|
54 |
{
|
| 958 |
lars |
55 |
$this->billAddr->company = $_SESSION["SHOP"]["buy"]["Persdata"]["Firma"];
|
| 781 |
lars |
56 |
}
|
| 958 |
lars |
57 |
$this->billAddr->street = $_SESSION["SHOP"]["buy"]["Persdata"]["Strasse"];
|
|
|
58 |
$this->billAddr->houseno = $_SESSION["SHOP"]["buy"]["Persdata"]["Hausnummer"];
|
|
|
59 |
$this->billAddr->zip = $_SESSION["SHOP"]["buy"]["Persdata"]["PLZ"];
|
|
|
60 |
$this->billAddr->city = $_SESSION["SHOP"]["buy"]["Persdata"]["Ort"];
|
|
|
61 |
$this->billAddr->country_id = $_SESSION["SHOP"]["buy"]["Persdata"]["Land"];
|
|
|
62 |
$this->billAddr->phone = $_SESSION["SHOP"]["buy"]["Persdata"]["Telefon"];
|
|
|
63 |
$this->billAddr->email = $_SESSION["SHOP"]["buy"]["Persdata"]["email"];
|
|
|
64 |
$this->billAddr->save();
|
|
|
65 |
$this->billAddrId = $this->billAddr->id;
|
| 778 |
lars |
66 |
|
| 782 |
lars |
67 |
if ( $_SESSION["SHOP"]["Lieferadresse"] == "packstation" )
|
| 779 |
lars |
68 |
{
|
| 958 |
lars |
69 |
$this->shipAddr = new OrderAddress();
|
|
|
70 |
$this->shipAddr->user_id = $_SESSION["SHOP"]["buy"]["Persdata"]["ID"];
|
|
|
71 |
$this->shipAddr->name = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Vorname_pst"];
|
|
|
72 |
$this->shipAddr->lastname = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Nachname_pst"];
|
| 781 |
lars |
73 |
if ( $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Firma_pst"] )
|
|
|
74 |
{
|
| 958 |
lars |
75 |
$this->shipAddr->company = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Firma_pst"];
|
| 781 |
lars |
76 |
}
|
| 958 |
lars |
77 |
$this->shipAddr->street = $_SESSION["SHOP"]["buy"]["Persdata"]["lieferStrasse_pst"];
|
|
|
78 |
$this->shipAddr->houseno = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Hausnummer_pst"];
|
|
|
79 |
$this->shipAddr->zip = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_PLZ_pst"];
|
|
|
80 |
$this->shipAddr->city = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Ort_pst"];
|
|
|
81 |
$this->shipAddr->country_id = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Land_pst"];
|
|
|
82 |
$this->shipAddr->phone = $_SESSION["SHOP"]["buy"]["Persdata"]["Telefon"];
|
|
|
83 |
$this->shipAddr->email = $_SESSION["SHOP"]["buy"]["Persdata"]["email"];
|
|
|
84 |
$this->shipAddr->save();
|
|
|
85 |
$this->shipAddrId = $this->billAddr->id;
|
| 779 |
lars |
86 |
}
|
|
|
87 |
else
|
|
|
88 |
{
|
| 958 |
lars |
89 |
$this->shipAddr = new OrderAddress();
|
|
|
90 |
$this->shipAddr->user_id = $_SESSION["SHOP"]["buy"]["Persdata"]["ID"];
|
|
|
91 |
$this->shipAddr->name = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Vorname"];
|
| 781 |
lars |
92 |
if ( $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Firma"] )
|
|
|
93 |
{
|
| 958 |
lars |
94 |
$this->shipAddr->company = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Firma"];
|
| 781 |
lars |
95 |
}
|
| 958 |
lars |
96 |
$this->shipAddr->lastname = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Nachname"];
|
|
|
97 |
$this->shipAddr->street = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Strasse"];
|
|
|
98 |
$this->shipAddr->houseno = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Hausnummer"];
|
|
|
99 |
$this->shipAddr->zip = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_PLZ"];
|
|
|
100 |
$this->shipAddr->city = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Ort"];
|
|
|
101 |
$this->shipAddr->country_id = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Land"];
|
|
|
102 |
$this->shipAddr->phone = $_SESSION["SHOP"]["buy"]["Persdata"]["Telefon"];
|
|
|
103 |
$this->shipAddr->email = $_SESSION["SHOP"]["buy"]["Persdata"]["email"];
|
|
|
104 |
$this->shipAddr->save();
|
|
|
105 |
$this->shipAddrId = $this->billAddr->id;
|
| 779 |
lars |
106 |
}
|
| 958 |
lars |
107 |
$this->order = new Order();
|
|
|
108 |
$this->order->shop_id = $GLOBALS["INI"]["shops_ID"];
|
|
|
109 |
$this->order->user_id = $_SESSION["SHOP"]["buy"]["Persdata"]["ID"];
|
|
|
110 |
$this->order->order_type_id = 1;
|
|
|
111 |
$this->order->ship_addr_id = $this->shipAddrId;
|
|
|
112 |
$this->order->bill_addr_id = $this->billAddrId;
|
|
|
113 |
$this->order->created_by = "(Bestellung)";
|
|
|
114 |
$this->order->save();
|
|
|
115 |
$this->orderId = $this->order->id;
|
|
|
116 |
$this->orderItems = array();
|
| 779 |
lars |
117 |
foreach ( $_SESSION["SHOP"]["BASKET"]->items as $item )
|
|
|
118 |
{
|
| 958 |
lars |
119 |
$this->orderItem = new OrderItem();
|
|
|
120 |
$this->orderItem->name = $item->name;
|
|
|
121 |
$this->orderItem->item_id = $item->id;
|
|
|
122 |
$this->orderItem->price = $item->price;
|
|
|
123 |
$this->orderItem->amount = $item->menge;
|
|
|
124 |
$this->orderItem->option_input = $item->addinfo;
|
|
|
125 |
$this->orderItem->save();
|
|
|
126 |
$this->orderItems[] = $this->orderItem;
|
| 779 |
lars |
127 |
}
|
| 958 |
lars |
128 |
return $this->orderId;
|
| 779 |
lars |
129 |
}
|
| 958 |
lars |
130 |
|
|
|
131 |
public function mail()
|
|
|
132 |
{
|
| 1377 |
lars |
133 |
$webSettings = WebSetting::where( 'shop_id', '=', $this->order->shop_id )->where( 'order_type_id', '=', $this->order->order_type_id )->whereIn( 'id', [
|
|
|
134 |
11,
|
|
|
135 |
12,
|
|
|
136 |
13,
|
|
|
137 |
14,
|
|
|
138 |
17,
|
|
|
139 |
18,
|
|
|
140 |
1000,
|
|
|
141 |
] )->get();
|
| 962 |
lars |
142 |
foreach ( $webSettings as $webSetting )
|
|
|
143 |
{
|
|
|
144 |
switch ( $webSetting->id )
|
|
|
145 |
{
|
|
|
146 |
case 11:
|
|
|
147 |
$fromEmail = $webSetting->content;
|
|
|
148 |
break;
|
|
|
149 |
case 12:
|
|
|
150 |
$customerSubject = $webSetting->content;
|
|
|
151 |
break;
|
|
|
152 |
case 13:
|
|
|
153 |
$customerBody = $webSetting->content;
|
|
|
154 |
break;
|
|
|
155 |
case 14:
|
|
|
156 |
$bccAddress = $webSetting->content;
|
|
|
157 |
break;
|
|
|
158 |
case 17:
|
|
|
159 |
$shopSubject = $webSetting->content;
|
|
|
160 |
break;
|
|
|
161 |
case 18:
|
|
|
162 |
$shopBody = $webSetting->content;
|
|
|
163 |
break;
|
|
|
164 |
case 1000:
|
|
|
165 |
$template = $webSetting->content;
|
|
|
166 |
break;
|
|
|
167 |
}
|
|
|
168 |
}
|
|
|
169 |
|
| 958 |
lars |
170 |
}
|
| 1337 |
lars |
171 |
|
|
|
172 |
/**
|
|
|
173 |
* Store a newly created resource in storage.
|
|
|
174 |
*
|
|
|
175 |
* @param Request $request
|
|
|
176 |
* @return RedirectResponse
|
|
|
177 |
*/
|
|
|
178 |
public function store( Request $request ): RedirectResponse
|
|
|
179 |
{
|
|
|
180 |
//
|
|
|
181 |
$rules = [
|
|
|
182 |
'name' => 'bail|max:255',
|
|
|
183 |
];
|
|
|
184 |
$request->validate( $rules );
|
|
|
185 |
$bu = new Order();
|
|
|
186 |
$bu->update( $request->validated() );
|
|
|
187 |
return redirect( "/backend/orders" );
|
|
|
188 |
}
|
|
|
189 |
|
|
|
190 |
/**
|
|
|
191 |
* Display the specified resource.
|
|
|
192 |
*
|
|
|
193 |
* @param int $id
|
|
|
194 |
*/
|
|
|
195 |
public function show( int $id )
|
|
|
196 |
{
|
|
|
197 |
//
|
|
|
198 |
}
|
|
|
199 |
|
|
|
200 |
/**
|
|
|
201 |
* Show the form for editing the specified resource.
|
|
|
202 |
*
|
|
|
203 |
* @param int $id
|
|
|
204 |
* @return Factory|View|Application
|
|
|
205 |
*/
|
|
|
206 |
public function edit( int $id ): Factory|View|Application
|
|
|
207 |
{
|
|
|
208 |
//
|
| 1377 |
lars |
209 |
$order = Order::with( [
|
|
|
210 |
'shop',
|
|
|
211 |
'orderType',
|
|
|
212 |
'orderItem',
|
|
|
213 |
'billAddr',
|
| 1428 |
lars |
214 |
'shipAddr',
|
| 1436 |
lars |
215 |
'orderItem.item',
|
|
|
216 |
'orderItem.item.medium.medium',
|
| 1377 |
lars |
217 |
] )->find( $id );
|
|
|
218 |
$order->kk_info = unserialize( $order->kk_info );
|
| 1455 |
lars |
219 |
return view( 'admin/order', [ "order" => $order, ] );
|
| 1337 |
lars |
220 |
}
|
|
|
221 |
|
|
|
222 |
|
|
|
223 |
/**
|
|
|
224 |
* Update the specified resource in storage.
|
|
|
225 |
*
|
|
|
226 |
* @param ActionRequest $request
|
| 1454 |
lars |
227 |
* @param int $id
|
| 1337 |
lars |
228 |
* @return RedirectResponse
|
|
|
229 |
*/
|
|
|
230 |
public function update( ActionRequest $request, int $id ): RedirectResponse
|
|
|
231 |
{
|
|
|
232 |
//
|
|
|
233 |
$rules = [
|
|
|
234 |
'name' => 'bail|max:255',
|
|
|
235 |
];
|
|
|
236 |
$request->validate( $rules );
|
|
|
237 |
$bu = Order::find( $id );
|
|
|
238 |
$data = $request->validated();
|
|
|
239 |
$bu->update( $data );
|
|
|
240 |
return redirect( "/backend/orders" );
|
|
|
241 |
}
|
|
|
242 |
|
|
|
243 |
/**
|
|
|
244 |
* Remove the specified resource from storage.
|
|
|
245 |
*
|
|
|
246 |
* @param int $id
|
|
|
247 |
* @return RedirectResponse
|
|
|
248 |
*/
|
|
|
249 |
public function destroy( int $id ): RedirectResponse
|
|
|
250 |
{
|
|
|
251 |
//
|
|
|
252 |
$bu = Order::find( $id );
|
|
|
253 |
$bu->update( [ "status" => "cancelled" ] );
|
|
|
254 |
return redirect( "/backend/orders" );
|
|
|
255 |
}
|
| 779 |
lars |
256 |
}
|