1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use App\Http\Requests\SaveLotRequest; |
6
|
|
|
use App\Lot; |
7
|
|
|
use App\Repositories\ImprovedSpecRepository; |
8
|
|
|
use App\Repositories\SpecPriceRepository; |
9
|
|
|
use App\Repositories\LotRepository; |
10
|
|
|
use App\Repositories\ProductsRepository; |
11
|
|
|
use App\Repositories\SubCategoriesRepository; |
12
|
|
|
use App\Repositories\MethodDeliveryPaymentRepository; |
13
|
|
|
use App\Repositories\LotDeliveryPaymentRepository; |
14
|
|
|
use App\Repositories\CurrenciesRepository; |
15
|
|
|
use App\Vendor; |
16
|
|
|
use Illuminate\Contracts\Auth\Guard; |
17
|
|
|
use Illuminate\Http\Request; |
18
|
|
|
|
19
|
|
|
use App\Http\Requests; |
20
|
|
|
|
21
|
|
|
class LotsController extends Controller |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var LotRepository |
25
|
|
|
*/ |
26
|
|
|
protected $lots; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var Guard |
30
|
|
|
*/ |
31
|
|
|
protected $auth; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var ProductsRepository |
35
|
|
|
*/ |
36
|
|
|
protected $products; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var ImprovedSpecRepository |
40
|
|
|
*/ |
41
|
|
|
protected $improvedSpecs; |
42
|
|
|
|
43
|
|
|
protected $specPrice; |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
protected $sub_category; |
47
|
|
|
|
48
|
|
|
protected $method; |
49
|
|
|
|
50
|
|
|
protected $lot_method; |
51
|
|
|
|
52
|
|
|
protected $currencies; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* LotsController constructor. |
56
|
|
|
* @param LotRepository $lotRepository |
57
|
|
|
* @param ProductsRepository $productsRepository |
58
|
|
|
* @param ImprovedSpecRepository $improvedSpecRepository |
59
|
|
|
* @param Guard $auth |
60
|
|
|
*/ |
61
|
|
View Code Duplication |
public function __construct( |
|
|
|
|
62
|
|
|
LotRepository $lotRepository, |
63
|
|
|
ProductsRepository $productsRepository, |
64
|
|
|
ImprovedSpecRepository $improvedSpecRepository, |
65
|
|
|
SpecPriceRepository $specPriceRepository, |
66
|
|
|
SubCategoriesRepository $subCategoriesRepository, |
67
|
|
|
MethodDeliveryPaymentRepository $methodDeliveryPaymentRepository, |
68
|
|
|
LotDeliveryPaymentRepository $lotDeliveryPaymentRepository, |
69
|
|
|
CurrenciesRepository $currenciesRepository, |
70
|
|
|
Guard $auth |
71
|
|
|
) { |
72
|
|
|
$this->lots = $lotRepository; |
73
|
|
|
$this->auth = $auth; |
74
|
|
|
$this->products = $productsRepository; |
75
|
|
|
$this->improvedSpecs = $improvedSpecRepository; |
76
|
|
|
$this->specPrice = $specPriceRepository; |
77
|
|
|
$this->sub_category = $subCategoriesRepository; |
78
|
|
|
$this->method = $methodDeliveryPaymentRepository; |
79
|
|
|
$this->lot_method = $lotDeliveryPaymentRepository; |
80
|
|
|
$this->currencies = $currenciesRepository; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Create lot or modify drafted for vendor. |
85
|
|
|
* |
86
|
|
|
* @param Vendor $vendor |
87
|
|
|
* @return \Illuminate\View\View |
88
|
|
|
*/ |
89
|
|
View Code Duplication |
public function create(Vendor $vendor) |
|
|
|
|
90
|
|
|
{ |
91
|
|
|
$lot = $this->lots->addLot($vendor); |
92
|
|
|
$delivery = $this->method->getPublic('delivery'); |
93
|
|
|
$payment = $this->method->getPublic('payment'); |
94
|
|
|
return view('lots.create', compact('lot','delivery','payment')); |
|
|
|
|
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param Lot $lot |
99
|
|
|
* @return \Illuminate\View\View |
100
|
|
|
*/ |
101
|
|
View Code Duplication |
public function edit(Lot $lot) |
|
|
|
|
102
|
|
|
{ |
103
|
|
|
//dd($lot->lotDeliveryPayment()); |
|
|
|
|
104
|
|
|
$delivery = $this->method->getPublic('delivery'); |
105
|
|
|
$payment = $this->method->getPublic('payment'); |
106
|
|
|
return view('lots.create', compact('lot','delivery','payment')); |
|
|
|
|
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Remove lot. |
111
|
|
|
* |
112
|
|
|
* @param Lot $lot |
113
|
|
|
* @return mixed |
114
|
|
|
*/ |
115
|
|
|
public function delete(Lot $lot) |
116
|
|
|
{ |
117
|
|
|
$this->lots->delete($lot); |
118
|
|
|
|
119
|
|
|
return redirect()->route('my_lots') |
|
|
|
|
120
|
|
|
->withStatus(sprintf('Lot %s was removed', $lot->present()->renderName())) |
|
|
|
|
121
|
|
|
->withColor('green'); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Select category. |
126
|
|
|
* |
127
|
|
|
* @param Request $request |
128
|
|
|
* @param Lot $lot |
129
|
|
|
* |
130
|
|
|
* @return string |
131
|
|
|
*/ |
132
|
|
|
/* public function selectCategory(Request $request, Lot $lot) |
|
|
|
|
133
|
|
|
{ |
134
|
|
|
if($this->lots->checkIfPossibleToChangeCategory($lot)) { |
135
|
|
|
$this->lots->changeCategory($lot, $request->get('category_id')); |
136
|
|
|
return 'true'; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
return 'false'; |
140
|
|
|
}*/ |
141
|
|
|
|
142
|
|
|
public function selectCategory(Request $request, Lot $lot) |
143
|
|
|
{ |
144
|
|
|
$sub_category = $this->sub_category->getSubCategory($request->get('category_id')); |
145
|
|
|
$this->lots->changeCategory($lot, $request->get('category_id')); |
146
|
|
|
$json = array( |
147
|
|
|
'sub_category' => $sub_category, |
148
|
|
|
'respons' => true |
149
|
|
|
); |
150
|
|
|
return response($json); |
|
|
|
|
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Load product form for lot create/edit. |
155
|
|
|
* |
156
|
|
|
* @param Request $request |
157
|
|
|
* @param Lot $lot |
158
|
|
|
* @return mixed |
159
|
|
|
*/ |
160
|
|
|
public function loadProductBlock(Request $request, Lot $lot) |
|
|
|
|
161
|
|
|
{ |
162
|
|
|
if($lot->category_id) { |
|
|
|
|
163
|
|
|
$product = $this->products->createPlain($lot); |
164
|
|
|
|
165
|
|
|
return view('lots.partials.form.product', ['product' => $product, 'lot' => $lot]); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
return 'false'; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* Load specification |
173
|
|
|
* |
174
|
|
|
* @param Request $request |
175
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
176
|
|
|
*/ |
177
|
|
|
|
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Load improved spec. |
181
|
|
|
* |
182
|
|
|
* @param Request $request |
183
|
|
|
* @return mixed |
184
|
|
|
*/ |
185
|
|
|
public function loadImprovedSpec(Request $request) |
186
|
|
|
{ |
187
|
|
|
$spec = $this->improvedSpecs->createPlain($request->get('product_id')); |
188
|
|
|
|
189
|
|
|
return view('lots.partials.form.improved_specs', [ 'spec' => $spec ]); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* @param SaveLotRequest $request |
194
|
|
|
* @param Lot $lot |
195
|
|
|
* @return mixed |
196
|
|
|
*/ |
197
|
|
|
public function saveLot(SaveLotRequest $request, Lot $lot) |
198
|
|
|
{ |
199
|
|
|
$lot = $this->lots->save($lot, $request->all()); |
200
|
|
|
return redirect()->route('edit_lot', [ $lot ]) |
|
|
|
|
201
|
|
|
->withStatus('You created lot successefully. Waiting for moderator verify it. You will be notificated!'); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
View Code Duplication |
public function updateLot(SaveLotRequest $request, Lot $lot) |
|
|
|
|
205
|
|
|
{ |
206
|
|
|
$lot = $this->lots->save($lot, $request->all()); |
207
|
|
|
$method = []; |
208
|
|
|
if ($request->input('method')) { |
209
|
|
|
$method = $request->input('method'); |
210
|
|
|
} |
211
|
|
|
$lotMethod = $this->lot_method->save($lot, $method); |
|
|
|
|
212
|
|
|
return response(array('respons'=>true)); |
|
|
|
|
213
|
|
|
|
214
|
|
|
} |
215
|
|
|
|
216
|
|
View Code Duplication |
public function publishedLot(SaveLotRequest $request, Lot $lot) |
|
|
|
|
217
|
|
|
{ |
218
|
|
|
$lot = $this->lots->save($lot, $request->all()); |
219
|
|
|
$method = []; |
220
|
|
|
if ($request->input('method')) { |
221
|
|
|
$method = $request->input('method'); |
222
|
|
|
} |
223
|
|
|
$lotMethod = $this->lot_method->save($lot, $method); |
|
|
|
|
224
|
|
|
|
225
|
|
|
return response(array('respons'=>true,'status'=>$lot->status)); |
|
|
|
|
226
|
|
|
|
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* |
231
|
|
|
*/ |
232
|
|
|
public function index() |
233
|
|
|
{ |
234
|
|
|
/* dd(Lot::all());*/ |
|
|
|
|
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* Show user's all lots; |
239
|
|
|
* |
240
|
|
|
* @return \Illuminate\View\View |
241
|
|
|
*/ |
242
|
|
|
public function myLots() |
243
|
|
|
{ |
244
|
|
|
$lots = $this->lots->userLots($this->getUser(), 5); |
245
|
|
|
return view('lots.my_lots', compact('lots')); |
|
|
|
|
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* @param Lot $lot |
250
|
|
|
* @return mixed |
251
|
|
|
*/ |
252
|
|
|
public function show(Lot $lot) |
253
|
|
|
{ |
254
|
|
|
return view('lots.show', compact('lot')); |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* Get user from Guard\Auth |
260
|
|
|
* |
261
|
|
|
* @return \Illuminate\Contracts\Auth\Authenticatable|null |
262
|
|
|
*/ |
263
|
|
|
public function getUser() |
264
|
|
|
{ |
265
|
|
|
return $this->auth->user(); |
266
|
|
|
} |
267
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.