|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Product; |
|
4
|
|
|
|
|
5
|
|
|
use App\Http\Controllers\Controller; |
|
6
|
|
|
use App\Model\Payment\Currency; |
|
7
|
|
|
use App\Model\Payment\Plan; |
|
8
|
|
|
use App\Model\Payment\Tax; |
|
9
|
|
|
use App\Model\Payment\TaxClass; |
|
10
|
|
|
use App\Model\Payment\TaxProductRelation; |
|
11
|
|
|
use App\Model\Product\Price; |
|
12
|
|
|
use App\Model\Product\Product; |
|
13
|
|
|
use App\Model\Product\ProductGroup; |
|
14
|
|
|
use App\Model\Product\Subscription; |
|
15
|
|
|
use App\Model\Product\Type; |
|
16
|
|
|
use Illuminate\Http\Request; |
|
17
|
|
|
|
|
18
|
|
|
class ProductController extends Controller { |
|
19
|
|
|
|
|
20
|
|
|
public $product; |
|
21
|
|
|
public $price; |
|
22
|
|
|
public $type; |
|
23
|
|
|
public $subscription; |
|
24
|
|
|
public $currency; |
|
25
|
|
|
public $group; |
|
26
|
|
|
public $plan; |
|
27
|
|
|
public $tax; |
|
28
|
|
|
public $tax_relation; |
|
29
|
|
|
public $tax_class; |
|
30
|
|
|
|
|
31
|
|
|
public function __construct() { |
|
32
|
|
|
$this->middleware('auth'); |
|
33
|
|
|
$this->middleware('admin', ['except' => ['userDownload']]); |
|
34
|
|
|
|
|
35
|
|
|
$product = new Product(); |
|
36
|
|
|
$this->product = $product; |
|
37
|
|
|
|
|
38
|
|
|
$price = new Price(); |
|
39
|
|
|
$this->price = $price; |
|
40
|
|
|
|
|
41
|
|
|
$type = new Type(); |
|
42
|
|
|
$this->type = $type; |
|
43
|
|
|
|
|
44
|
|
|
$subscription = new Subscription(); |
|
45
|
|
|
$this->subscription = $subscription; |
|
46
|
|
|
|
|
47
|
|
|
$currency = new Currency(); |
|
48
|
|
|
$this->currency = $currency; |
|
49
|
|
|
|
|
50
|
|
|
$group = new ProductGroup(); |
|
51
|
|
|
$this->group = $group; |
|
52
|
|
|
|
|
53
|
|
|
$plan = new Plan(); |
|
54
|
|
|
$this->plan = $plan; |
|
55
|
|
|
|
|
56
|
|
|
$tax = new Tax(); |
|
57
|
|
|
$this->tax = $tax; |
|
58
|
|
|
|
|
59
|
|
|
$tax_relation = new TaxProductRelation(); |
|
60
|
|
|
$this->tax_relation = $tax_relation; |
|
61
|
|
|
|
|
62
|
|
|
$tax_class = new TaxClass(); |
|
63
|
|
|
$this->tax_class = $tax_class; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Display a listing of the resource. |
|
68
|
|
|
* |
|
69
|
|
|
* @return Response |
|
70
|
|
|
*/ |
|
71
|
|
|
public function index() { |
|
72
|
|
|
try { |
|
73
|
|
|
return view('themes.default1.product.product.index'); |
|
74
|
|
|
} catch (\Exception $e) { |
|
75
|
|
|
return redirect('/')->with('fails', $e->getMessage()); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function GetProducts() { |
|
80
|
|
|
|
|
81
|
|
|
// try { |
|
82
|
|
|
return \Datatable::collection($this->product->select('id', 'name', 'type', 'group')->where('id', '!=', 1)->get()) |
|
83
|
|
|
->addColumn('#', function ($model) { |
|
84
|
|
|
return "<input type='checkbox' value=" . $model->id . ' name=select[] id=check>'; |
|
85
|
|
|
}) |
|
86
|
|
|
->addColumn('name', function ($model) { |
|
87
|
|
|
return ucfirst($model->name); |
|
88
|
|
|
}) |
|
89
|
|
View Code Duplication |
->addColumn('type', function ($model) { |
|
90
|
|
|
//dd($model->type()); |
|
91
|
|
|
if ($this->type->where('id', $model->type)->first()) { |
|
92
|
|
|
return $this->type->where('id', $model->type)->first()->name; |
|
93
|
|
|
} else { |
|
94
|
|
|
return 'Not available'; |
|
95
|
|
|
} |
|
96
|
|
|
}) |
|
97
|
|
|
->addColumn('group', function ($model) { |
|
98
|
|
|
//dd($model->type()); |
|
99
|
|
|
if ($this->group->where('id', $model->group)->first()) { |
|
100
|
|
|
return $this->group->where('id', $model->group)->first()->name; |
|
101
|
|
|
} else { |
|
102
|
|
|
return 'Not available'; |
|
103
|
|
|
} |
|
104
|
|
|
}) |
|
105
|
|
View Code Duplication |
->addColumn('price', function ($model) { |
|
106
|
|
|
if ($this->price->where('product_id', $model->id)->first()) { |
|
107
|
|
|
return $this->price->where('product_id', $model->id)->first()->price; |
|
108
|
|
|
} else { |
|
109
|
|
|
return 'Not available'; |
|
110
|
|
|
} |
|
111
|
|
|
}) |
|
112
|
|
View Code Duplication |
->addColumn('currency', function ($model) { |
|
113
|
|
|
if ($this->price->where('product_id', $model->id)->first()) { |
|
114
|
|
|
return $this->price->where('product_id', $model->id)->first()->currency; |
|
115
|
|
|
} else { |
|
116
|
|
|
return 'Not available'; |
|
117
|
|
|
} |
|
118
|
|
|
}) |
|
119
|
|
View Code Duplication |
->addColumn('action', function ($model) { |
|
120
|
|
|
$url = ""; |
|
121
|
|
|
if ($model->type==2) { |
|
122
|
|
|
$url = '<a href=' . url('product/download/' . $model->id) . " class='btn btn-sm btn-primary'>Download</a>"; |
|
123
|
|
|
} |
|
124
|
|
|
return '<p><a href=' . url('products/' . $model->id . '/edit') . " class='btn btn-sm btn-primary'>Edit</a> $url</p>"; |
|
125
|
|
|
}) |
|
126
|
|
|
->searchColumns('name', 'email') |
|
127
|
|
|
->orderColumns('name', 'email') |
|
128
|
|
|
->make(); |
|
129
|
|
|
// } catch (\Exception $e) { |
|
130
|
|
|
// return redirect()->back()->with('fails', $e->getMessage()); |
|
131
|
|
|
// } |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* Show the form for creating a new resource. |
|
136
|
|
|
* |
|
137
|
|
|
* @return Response |
|
138
|
|
|
*/ |
|
139
|
|
|
public function create() { |
|
140
|
|
|
try { |
|
141
|
|
|
/* |
|
142
|
|
|
* server url |
|
143
|
|
|
*/ |
|
144
|
|
|
$url = $this->GetMyUrl(); |
|
145
|
|
|
$i = $this->product->orderBy('created_at', 'desc')->first()->id + 1; |
|
146
|
|
|
$cartUrl = $url . '/pricing?id=' . $i; |
|
147
|
|
|
$type = $this->type->lists('name', 'id')->toArray(); |
|
148
|
|
|
$subscription = $this->plan->lists('name', 'id')->toArray(); |
|
149
|
|
|
$currency = $this->currency->lists('name', 'code')->toArray(); |
|
150
|
|
|
$group = $this->group->lists('name', 'id')->toArray(); |
|
151
|
|
|
$products = $this->product->lists('name', 'id')->toArray(); |
|
152
|
|
|
$taxes = $this->tax_class->lists('name', 'id')->toArray(); |
|
153
|
|
|
|
|
154
|
|
|
return view('themes.default1.product.product.create', compact('subscription', 'type', 'currency', 'group', 'cartUrl', 'products', 'taxes')); |
|
155
|
|
|
} catch (\Exception $e) { |
|
156
|
|
|
return redirect()->back()->with('fails', $e->getMessage()); |
|
157
|
|
|
} |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* Store a newly created resource in storage. |
|
162
|
|
|
* |
|
163
|
|
|
* @return Response |
|
164
|
|
|
*/ |
|
165
|
|
|
public function store(Request $request) { |
|
166
|
|
|
$input = $request->all(); |
|
167
|
|
|
//dd($input); |
|
168
|
|
|
$v = \Validator::make($input, [ |
|
169
|
|
|
'name' => 'required', |
|
170
|
|
|
'type' => 'required', |
|
171
|
|
|
'group' => 'required', |
|
172
|
|
|
'subscription' => 'required', |
|
173
|
|
|
'currency.*' => 'required', |
|
174
|
|
|
'price.*' => 'required', |
|
175
|
|
|
]); |
|
176
|
|
View Code Duplication |
$v->sometimes(['file', 'image', 'version'], 'required', function ($input) { |
|
177
|
|
|
return $input->type == 2 && $input->github_owner == '' && $input->github_repository == ''; |
|
178
|
|
|
}); |
|
179
|
|
|
|
|
180
|
|
View Code Duplication |
$v->sometimes(['github_owner', 'github_repository'], 'required', function ($input) { |
|
181
|
|
|
return $input->type == 2 && $input->file == '' && $input->image == ''; |
|
182
|
|
|
}); |
|
183
|
|
|
if ($v->fails()) { |
|
184
|
|
|
return redirect()->back()->with('errors', $v->errors()); |
|
185
|
|
|
//dd(); |
|
186
|
|
|
} |
|
187
|
|
|
try { |
|
188
|
|
View Code Duplication |
if ($request->hasFile('image')) { |
|
189
|
|
|
$image = $request->file('image')->getClientOriginalName(); |
|
190
|
|
|
$imagedestinationPath = 'dist/product/images'; |
|
191
|
|
|
$request->file('image')->move($imagedestinationPath, $image); |
|
192
|
|
|
$this->product->image = $image; |
|
|
|
|
|
|
193
|
|
|
} |
|
194
|
|
View Code Duplication |
if ($request->hasFile('file')) { |
|
195
|
|
|
$file = $request->file('file')->getClientOriginalName(); |
|
196
|
|
|
$filedestinationPath = storage_path() . '/products'; |
|
197
|
|
|
$request->file('file')->move($filedestinationPath, $file); |
|
198
|
|
|
$this->product->file = $file; |
|
|
|
|
|
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
//dd($request->input('currency')); |
|
202
|
|
|
|
|
203
|
|
|
$product = $this->product; |
|
204
|
|
|
$product->fill($request->except('image', 'file'))->save(); |
|
205
|
|
|
|
|
206
|
|
|
$this->updateVersionFromGithub($product->id); |
|
207
|
|
|
|
|
208
|
|
|
$product_id = $product->id; |
|
|
|
|
|
|
209
|
|
|
$subscription = $request->input('subscription'); |
|
210
|
|
|
$price = $request->input('price'); |
|
211
|
|
|
$sales_price = $request->input('sales_price'); |
|
212
|
|
|
$currencies = $request->input('currency'); |
|
213
|
|
|
|
|
214
|
|
View Code Duplication |
foreach ($currencies as $key => $currency) { |
|
|
|
|
|
|
215
|
|
|
$this->price->create(['product_id' => $product_id, 'currency' => $currency, 'subscription' => $subscription, 'price' => $price[$key], 'sales_price' => $sales_price[$key]]); |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
//add tax class to tax_product_relation table |
|
219
|
|
|
$taxes = $request->input('tax'); |
|
220
|
|
|
if ($taxes) { |
|
221
|
|
|
$this->tax_relation->create(['product_id' => $product_id, 'tax_class_id' => $taxes]); |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
return redirect()->back()->with('success', \Lang::get('message.saved-successfully')); |
|
225
|
|
|
} catch (\Exception $e) { |
|
226
|
|
|
return redirect()->back()->with('fails', $e->getMessage()); |
|
227
|
|
|
} |
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
/** |
|
231
|
|
|
* Display the specified resource. |
|
232
|
|
|
* |
|
233
|
|
|
* @param int $id |
|
234
|
|
|
* |
|
235
|
|
|
* @return Response |
|
236
|
|
|
*/ |
|
237
|
|
|
public function show($id) { |
|
238
|
|
|
// |
|
239
|
|
|
} |
|
240
|
|
|
|
|
241
|
|
|
/** |
|
242
|
|
|
* Show the form for editing the specified resource. |
|
243
|
|
|
* |
|
244
|
|
|
* @param int $id |
|
245
|
|
|
* |
|
246
|
|
|
* @return Response |
|
247
|
|
|
*/ |
|
248
|
|
|
public function edit($id) { |
|
249
|
|
|
try { |
|
250
|
|
|
$type = $this->type->lists('name', 'id')->toArray(); |
|
251
|
|
|
$subscription = $this->plan->lists('name', 'id')->toArray(); |
|
252
|
|
|
$currency = $this->currency->lists('name', 'code')->toArray(); |
|
253
|
|
|
$group = $this->group->lists('name', 'id')->toArray(); |
|
254
|
|
|
$products = $this->product->lists('name', 'id')->toArray(); |
|
255
|
|
|
$url = $this->GetMyUrl(); |
|
256
|
|
|
$cartUrl = $url . '/cart?id=' . $id; |
|
257
|
|
|
$product = $this->product->where('id', $id)->first(); |
|
258
|
|
|
$price = $this->price->where('product_id', $product->id); |
|
259
|
|
|
foreach ($currency as $key => $value) { |
|
260
|
|
|
if ($this->price->where('product_id', $product->id)->where('currency', $key)->first()) { |
|
261
|
|
|
$regular[$key] = $this->price->where('product_id', $product->id)->where('currency', $key)->first()->price; |
|
|
|
|
|
|
262
|
|
|
$sales[$key] = $this->price->where('product_id', $product->id)->where('currency', $key)->first()->sales_price; |
|
|
|
|
|
|
263
|
|
|
} else { |
|
264
|
|
|
$regular[$key] = ''; |
|
|
|
|
|
|
265
|
|
|
$sales[$key] = ''; |
|
|
|
|
|
|
266
|
|
|
} |
|
267
|
|
|
} |
|
268
|
|
|
//dd($regular); |
|
269
|
|
|
//dd($this->tax_class); |
|
270
|
|
|
$taxes = $this->tax_class->lists('name', 'id')->toArray(); |
|
271
|
|
|
//dd($taxes); |
|
272
|
|
|
$saved_taxes = $this->tax_relation->where('product_id', $id)->get(); |
|
273
|
|
|
// dd($saved_taxes); |
|
274
|
|
|
return view('themes.default1.product.product.edit', compact('product', 'type', 'subscription', 'currency', 'group', 'price', 'cartUrl', 'products', 'regular', 'sales', 'taxes', 'saved_taxes')); |
|
275
|
|
|
} catch (\Exception $e) { |
|
276
|
|
|
return redirect()->back()->with('fails', $e->getMessage()); |
|
277
|
|
|
} |
|
278
|
|
|
} |
|
279
|
|
|
|
|
280
|
|
|
/** |
|
281
|
|
|
* Update the specified resource in storage. |
|
282
|
|
|
* |
|
283
|
|
|
* @param int $id |
|
284
|
|
|
* |
|
285
|
|
|
* @return Response |
|
286
|
|
|
*/ |
|
287
|
|
|
public function update($id, Request $request) { |
|
288
|
|
|
$input = $request->all(); |
|
289
|
|
|
//dd($input); |
|
290
|
|
|
$v = \Validator::make($input, [ |
|
291
|
|
|
'name' => 'required', |
|
292
|
|
|
'type' => 'required', |
|
293
|
|
|
'group' => 'required', |
|
294
|
|
|
'subscription' => 'required', |
|
295
|
|
|
'currency.*' => 'required', |
|
296
|
|
|
'price.*' => 'required', |
|
297
|
|
|
]); |
|
298
|
|
View Code Duplication |
$v->sometimes(['file', 'image', 'version'], 'required', function ($input) { |
|
299
|
|
|
return $input->type == 2 && $input->github_owner == '' && $input->github_repository == ''; |
|
300
|
|
|
}); |
|
301
|
|
|
|
|
302
|
|
View Code Duplication |
$v->sometimes(['github_owner', 'github_repository'], 'required', function ($input) { |
|
303
|
|
|
return $input->type == 2 && $input->file == '' && $input->image == ''; |
|
304
|
|
|
}); |
|
305
|
|
|
if ($v->fails()) { |
|
306
|
|
|
return redirect()->back()->with('errors', $v->errors()); |
|
307
|
|
|
//dd(); |
|
308
|
|
|
} |
|
309
|
|
|
try { |
|
310
|
|
|
$product = $this->product->where('id', $id)->first(); |
|
311
|
|
View Code Duplication |
if ($request->hasFile('image')) { |
|
312
|
|
|
$image = $request->file('image')->getClientOriginalName(); |
|
313
|
|
|
$imagedestinationPath = 'dist/product/images'; |
|
314
|
|
|
$request->file('image')->move($imagedestinationPath, $image); |
|
315
|
|
|
$product->image = $image; |
|
316
|
|
|
} |
|
317
|
|
View Code Duplication |
if ($request->hasFile('file')) { |
|
318
|
|
|
$file = $request->file('file')->getClientOriginalName(); |
|
319
|
|
|
$filedestinationPath = storage_path() . '/products'; |
|
320
|
|
|
$request->file('file')->move($filedestinationPath, $file); |
|
321
|
|
|
$product->file = $file; |
|
322
|
|
|
} |
|
323
|
|
|
$product->fill($request->except('image', 'file'))->save(); |
|
324
|
|
|
$this->updateVersionFromGithub($product->id); |
|
325
|
|
|
$product_id = $product->id; |
|
326
|
|
|
$subscription = $request->input('subscription'); |
|
327
|
|
|
$cost = $request->input('price'); |
|
328
|
|
|
$sales_price = $request->input('sales_price'); |
|
329
|
|
|
$currencies = $request->input('currency'); |
|
330
|
|
|
|
|
331
|
|
|
$prices = $this->price->where('product_id', $product->id)->get(); |
|
332
|
|
|
foreach ($prices as $price) { |
|
333
|
|
|
$price->delete(); |
|
334
|
|
|
} |
|
335
|
|
|
|
|
336
|
|
View Code Duplication |
foreach ($currencies as $key => $currency) { |
|
|
|
|
|
|
337
|
|
|
$this->price->create(['product_id' => $product_id, 'currency' => $currency, 'subscription' => $subscription, 'price' => $cost[$key], 'sales_price' => $sales_price[$key]]); |
|
338
|
|
|
} |
|
339
|
|
|
//add tax class to tax_product_relation table |
|
340
|
|
|
$taxes = $request->input('tax'); |
|
341
|
|
|
//dd($taxes); |
|
342
|
|
|
if ($taxes) { |
|
343
|
|
|
$saved_taxes = $this->tax_relation->where('product_id', $product_id)->first(); |
|
344
|
|
|
if ($saved_taxes) { |
|
345
|
|
|
$saved_taxes->tax_class_id = $taxes; |
|
346
|
|
|
$saved_taxes->save(); |
|
347
|
|
|
} else { |
|
348
|
|
|
$this->tax_relation->create(['product_id' => $product_id, 'tax_class_id' => $taxes]); |
|
349
|
|
|
} |
|
350
|
|
|
} |
|
351
|
|
|
|
|
352
|
|
|
return redirect()->back()->with('success', \Lang::get('message.updated-successfully')); |
|
353
|
|
|
} catch (\Exception $e) { |
|
354
|
|
|
dd($e); |
|
355
|
|
|
|
|
356
|
|
|
return redirect()->back()->with('fails', $e->getMessage()); |
|
357
|
|
|
} |
|
358
|
|
|
} |
|
359
|
|
|
|
|
360
|
|
|
/** |
|
361
|
|
|
* Remove the specified resource from storage. |
|
362
|
|
|
* |
|
363
|
|
|
* @param int $id |
|
|
|
|
|
|
364
|
|
|
* |
|
365
|
|
|
* @return Response |
|
366
|
|
|
*/ |
|
367
|
|
View Code Duplication |
public function destroy(Request $request) { |
|
368
|
|
|
try { |
|
369
|
|
|
$ids = $request->input('select'); |
|
370
|
|
|
if (!empty($ids)) { |
|
371
|
|
|
foreach ($ids as $id) { |
|
|
|
|
|
|
372
|
|
|
if ($id != 1) { |
|
373
|
|
|
$product = $this->product->where('id', $id)->first(); |
|
374
|
|
|
if ($product) { |
|
375
|
|
|
$product->delete(); |
|
376
|
|
|
} else { |
|
377
|
|
|
echo "<div class='alert alert-danger alert-dismissable'> |
|
378
|
|
|
<i class='fa fa-ban'></i> |
|
379
|
|
|
<b>" . \Lang::get('message.alert') . '!</b> ' . \Lang::get('message.failed') . ' |
|
380
|
|
|
<button type=button class=close data-dismiss=alert aria-hidden=true>×</button> |
|
381
|
|
|
' . \Lang::get('message.no-record') . ' |
|
382
|
|
|
</div>'; |
|
383
|
|
|
//echo \Lang::get('message.no-record') . ' [id=>' . $id . ']'; |
|
384
|
|
|
} |
|
385
|
|
|
echo "<div class='alert alert-success alert-dismissable'> |
|
386
|
|
|
<i class='fa fa-ban'></i> |
|
387
|
|
|
<b>" . \Lang::get('message.alert') . '!</b> ' . \Lang::get('message.success') . ' |
|
388
|
|
|
<button type=button class=close data-dismiss=alert aria-hidden=true>×</button> |
|
389
|
|
|
' . \Lang::get('message.deleted-successfully') . ' |
|
390
|
|
|
</div>'; |
|
391
|
|
|
} else { |
|
392
|
|
|
echo "<div class='alert alert-danger alert-dismissable'> |
|
393
|
|
|
<i class='fa fa-ban'></i> |
|
394
|
|
|
<b>" . \Lang::get('message.alert') . '!</b> ' . \Lang::get('message.failed') . ' |
|
395
|
|
|
<button type=button class=close data-dismiss=alert aria-hidden=true>×</button> |
|
396
|
|
|
' . \Lang::get('message.can-not-delete-default') . ' |
|
397
|
|
|
</div>'; |
|
398
|
|
|
} |
|
399
|
|
|
} |
|
400
|
|
|
} else { |
|
401
|
|
|
echo "<div class='alert alert-danger alert-dismissable'> |
|
402
|
|
|
<i class='fa fa-ban'></i> |
|
403
|
|
|
<b>" . \Lang::get('message.alert') . '!</b> ' . \Lang::get('message.failed') . ' |
|
404
|
|
|
<button type=button class=close data-dismiss=alert aria-hidden=true>×</button> |
|
405
|
|
|
' . \Lang::get('message.select-a-row') . ' |
|
406
|
|
|
</div>'; |
|
407
|
|
|
//echo \Lang::get('message.select-a-row'); |
|
408
|
|
|
} |
|
409
|
|
|
} catch (\Exception $e) { |
|
410
|
|
|
echo "<div class='alert alert-danger alert-dismissable'> |
|
411
|
|
|
<i class='fa fa-ban'></i> |
|
412
|
|
|
<b>" . \Lang::get('message.alert') . '!</b> ' . \Lang::get('message.failed') . ' |
|
413
|
|
|
<button type=button class=close data-dismiss=alert aria-hidden=true>×</button> |
|
414
|
|
|
' . $e->getMessage() . ' |
|
415
|
|
|
</div>'; |
|
416
|
|
|
} |
|
417
|
|
|
} |
|
418
|
|
|
|
|
419
|
|
|
public function GetMyUrl() { |
|
420
|
|
|
$server = new Request(); |
|
|
|
|
|
|
421
|
|
|
$url = $_SERVER['REQUEST_URI']; |
|
422
|
|
|
$server = parse_url($url); |
|
423
|
|
|
$server['path'] = dirname($server['path']); |
|
424
|
|
|
$server = parse_url($server['path']); |
|
425
|
|
|
$server['path'] = dirname($server['path']); |
|
426
|
|
|
|
|
427
|
|
|
$server = 'http://' . $_SERVER['HTTP_HOST'] . $server['path']; |
|
428
|
|
|
|
|
429
|
|
|
return $server; |
|
430
|
|
|
} |
|
431
|
|
|
|
|
432
|
|
|
public function downloadProduct($id) { |
|
433
|
|
|
try { |
|
434
|
|
|
$product = $this->product->findOrFail($id); |
|
435
|
|
|
//dd($product); |
|
436
|
|
|
$type = $product->type; |
|
437
|
|
|
$owner = $product->github_owner; |
|
438
|
|
|
$repository = $product->github_repository; |
|
439
|
|
|
$file = $product->file; |
|
440
|
|
|
|
|
441
|
|
|
if ($type == 2) { |
|
442
|
|
|
if ($owner && $repository) { |
|
443
|
|
|
//dd($repository); |
|
444
|
|
|
$github_controller = new \App\Http\Controllers\Github\GithubController(); |
|
445
|
|
|
$relese = $github_controller->listRepositories($owner, $repository); |
|
446
|
|
|
|
|
447
|
|
|
return $relese; |
|
448
|
|
|
} elseif ($file) { |
|
449
|
|
|
$relese = storage_path() . '/products/' . $file; |
|
450
|
|
|
|
|
451
|
|
|
return $relese; |
|
452
|
|
|
} |
|
453
|
|
|
} |
|
454
|
|
|
} catch (\Exception $e) { |
|
455
|
|
|
return redirect()->back()->with('fails', $e->getMessage()); |
|
456
|
|
|
} |
|
457
|
|
|
} |
|
458
|
|
|
|
|
459
|
|
|
public function adminDownload($id){ |
|
460
|
|
|
try{ |
|
461
|
|
|
$release = $this->downloadProduct($id); |
|
462
|
|
|
header("Location: $release"); |
|
463
|
|
|
exit; |
|
464
|
|
|
} catch (\Exception $e) { |
|
465
|
|
|
return redirect()->back()->with('fails', $e->getMessage()); |
|
466
|
|
|
} |
|
467
|
|
|
} |
|
468
|
|
|
|
|
469
|
|
|
public function userDownload($userid, $invoice_number) { |
|
470
|
|
|
try { |
|
471
|
|
|
if (\Auth::user()->role != 'admin') { |
|
472
|
|
|
if (\Auth::user()->id != $userid) { |
|
473
|
|
|
throw new \Exception('This user has no permission for this action'); |
|
474
|
|
|
} |
|
475
|
|
|
} |
|
476
|
|
|
$user = new \App\User(); |
|
477
|
|
|
$user = $user->findOrFail($userid); |
|
478
|
|
|
$invoice = new \App\Model\Order\Invoice(); |
|
479
|
|
|
$invoice = $invoice->where('number', $invoice_number)->first(); |
|
480
|
|
|
if ($user && $invoice) { |
|
481
|
|
|
if ($user->active == 1) { |
|
482
|
|
|
$invoice_item = new \App\Model\Order\InvoiceItem(); |
|
483
|
|
|
$item = $invoice_item->where('invoice_id', $invoice->id)->first(); |
|
484
|
|
|
$product_id = $this->product->where('name', $item->product_name)->first()->id; |
|
485
|
|
|
$release = $this->downloadProduct($product_id); |
|
486
|
|
|
return view('themes.default1.front.download', compact('release', 'form')); |
|
487
|
|
|
} else { |
|
488
|
|
|
return redirect('auth/login')->with('fails', \Lang::get('activate-your-account')); |
|
489
|
|
|
} |
|
490
|
|
|
} else { |
|
491
|
|
|
return redirect('auth/login')->with('fails', \Lang::get('please-purcahse-a-product')); |
|
492
|
|
|
} |
|
493
|
|
|
} catch (\Exception $ex) { |
|
494
|
|
|
return redirect('auth/login')->with('fails',$ex->getMessage()); |
|
495
|
|
|
} |
|
496
|
|
|
} |
|
497
|
|
|
|
|
498
|
|
|
public function getPrice(Request $request) { |
|
499
|
|
|
try { |
|
500
|
|
|
$id = $request->input('product'); |
|
501
|
|
|
$userid = $request->input('user'); |
|
502
|
|
|
$user = new \App\User(); |
|
503
|
|
|
$user = $user->find($userid); |
|
504
|
|
|
$currency = $user->currency; |
|
505
|
|
|
//dd($currency); |
|
506
|
|
|
$product = $this->product->findOrFail($id); |
|
507
|
|
|
$price = $product |
|
508
|
|
|
->price() |
|
509
|
|
|
->where('product_id', $id) |
|
510
|
|
|
->where('currency', $currency) |
|
511
|
|
|
->first() |
|
512
|
|
|
->sales_price; |
|
513
|
|
|
if (!$price) { |
|
514
|
|
|
$price = $product |
|
515
|
|
|
->price() |
|
516
|
|
|
->where('product_id', $id) |
|
517
|
|
|
->where('currency', $currency) |
|
518
|
|
|
->first() |
|
519
|
|
|
->price; |
|
520
|
|
|
} |
|
521
|
|
|
$field = $this->getProductField($id) . $this->getProductQtyCheck($id); |
|
522
|
|
|
$result = ['price' => $price, 'field' => $field]; |
|
523
|
|
|
|
|
524
|
|
|
return response()->json($result); |
|
525
|
|
|
} catch (\Exception $ex) { |
|
526
|
|
|
$result = ['price' => $ex->getMessage()]; |
|
527
|
|
|
|
|
528
|
|
|
return response()->json($result); |
|
529
|
|
|
} |
|
530
|
|
|
} |
|
531
|
|
|
|
|
532
|
|
|
public function updateVersionFromGithub($productid) { |
|
533
|
|
|
try { |
|
534
|
|
|
if (\Input::has('github_owner') && \Input::has('github_repository')) { |
|
535
|
|
|
$owner = \Input::get('github_owner'); |
|
536
|
|
|
$repo = \Input::get('github_repository'); |
|
537
|
|
|
$product = $this->product->find($productid); |
|
538
|
|
|
$github_controller = new \App\Http\Controllers\Github\GithubController(); |
|
539
|
|
|
$version = $github_controller->findVersion($owner, $repo); |
|
540
|
|
|
$product->version = $version; |
|
541
|
|
|
$product->save(); |
|
542
|
|
|
} |
|
543
|
|
|
} catch (\Exception $ex) { |
|
544
|
|
|
throw new \Exception($ex->getMessage()); |
|
545
|
|
|
} |
|
546
|
|
|
} |
|
547
|
|
|
|
|
548
|
|
|
public function getProductField($productid) { |
|
549
|
|
|
try { |
|
550
|
|
|
$product = $this->product->find($productid); |
|
551
|
|
|
if ($product) { |
|
552
|
|
|
if ($product->require_domain == 1) { |
|
553
|
|
|
return "<div class='col-md-4 form-group'> |
|
554
|
|
|
<label class='required'>" . \Lang::get('message.domain') . "</label> |
|
555
|
|
|
<input type='text' name='domain' class='form-control' id='domain' placeholder='http://example.com'> |
|
556
|
|
|
</div>"; |
|
557
|
|
|
} |
|
558
|
|
|
} |
|
559
|
|
|
} catch (\Exception $ex) { |
|
560
|
|
|
return $ex->getMessage(); |
|
561
|
|
|
} |
|
562
|
|
|
} |
|
563
|
|
|
|
|
564
|
|
|
public function getProductQtyCheck($productid) { |
|
565
|
|
|
try { |
|
566
|
|
|
$check = self::checkMultiProduct($productid); |
|
567
|
|
|
if ($check == true) { |
|
568
|
|
|
return "<div class='col-md-4 form-group'> |
|
569
|
|
|
<label class='required'>" . \Lang::get('message.quantity') . "</label> |
|
570
|
|
|
<input type='text' name='quantity' class='form-control' id='quantity' value='1'> |
|
571
|
|
|
</div>"; |
|
572
|
|
|
} |
|
573
|
|
|
} catch (\Exception $ex) { |
|
574
|
|
|
return $ex->getMessage(); |
|
575
|
|
|
} |
|
576
|
|
|
} |
|
577
|
|
|
|
|
578
|
|
|
public static function checkMultiProduct($productid) { |
|
579
|
|
|
try { |
|
580
|
|
|
$product = new Product(); |
|
581
|
|
|
$product = $product->find($productid); |
|
582
|
|
|
if ($product) { |
|
583
|
|
|
if ($product->multiple_qty == 1) { |
|
584
|
|
|
return true; |
|
585
|
|
|
} |
|
586
|
|
|
} |
|
587
|
|
|
|
|
588
|
|
|
return false; |
|
589
|
|
|
} catch (Exception $ex) { |
|
|
|
|
|
|
590
|
|
|
|
|
591
|
|
|
} |
|
592
|
|
|
} |
|
593
|
|
|
|
|
594
|
|
|
} |
|
595
|
|
|
|
Since your code implements the magic setter
_set, this function will be called for any write access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.