1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Hideyo\Ecommerce\Framework\Services\PaymentMethod; |
4
|
|
|
|
5
|
|
|
use Validator; |
6
|
|
|
use File; |
7
|
|
|
use Hideyo\Ecommerce\Framework\Services\PaymentMethod\Entity\PaymentMethodRepository; |
8
|
|
|
use Hideyo\Ecommerce\Framework\Services\BaseService; |
9
|
|
|
|
10
|
|
|
class PaymentMethodService extends BaseService |
11
|
|
|
{ |
12
|
|
|
public function __construct(PaymentMethodRepository $paymentMethod) |
13
|
|
|
{ |
14
|
|
|
$this->repo = $paymentMethod; |
|
|
|
|
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
public function selectOneByShopIdAndId($shopId, $paymentMethodId) |
18
|
|
|
{ |
19
|
|
|
$result = $this->repo->selectOneByShopIdAndId($shopId, $paymentMethodId); |
20
|
|
|
|
21
|
|
|
if ($result->isEmpty()) { |
22
|
|
|
return false; |
23
|
|
|
} |
24
|
|
|
return $result->first(); |
25
|
|
|
|
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* The validation rules for the model. |
30
|
|
|
* |
31
|
|
|
* @param integer $paymentMethodId id attribute model |
32
|
|
|
* @return array |
33
|
|
|
*/ |
34
|
|
|
private function rules($paymentMethodId = false) |
35
|
|
|
{ |
36
|
|
|
$rules = array( |
37
|
|
|
'title' => 'required|between:4,65|unique_with:'.$this->repo->getModel()->getTable().', shop_id', |
38
|
|
|
'price' => 'numeric|required' |
39
|
|
|
); |
40
|
|
|
|
41
|
|
|
if ($paymentMethodId) { |
|
|
|
|
42
|
|
|
$rules['title'] = $rules['title'].','.$paymentMethodId.' = id'; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
return $rules; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function create(array $attributes) |
49
|
|
|
{ |
50
|
|
|
$attributes['shop_id'] = auth('hideyobackend')->user()->selected_shop_id; |
|
|
|
|
51
|
|
|
$validator = Validator::make($attributes, $this->rules()); |
52
|
|
|
|
53
|
|
|
if ($validator->fails()) { |
54
|
|
|
return $validator; |
55
|
|
|
} |
56
|
|
|
$attributes['modified_by_user_id'] = auth('hideyobackend')->user()->id; |
|
|
|
|
57
|
|
|
return $this->updateOrAddModel($this->repo->getModel(), $attributes); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function updateById(array $attributes, $paymentMethodId) |
61
|
|
|
{ |
62
|
|
|
$model = $this->find($paymentMethodId); |
63
|
|
|
$attributes['shop_id'] = auth('hideyobackend')->user()->selected_shop_id; |
|
|
|
|
64
|
|
|
$attributes['modified_by_user_id'] = auth('hideyobackend')->user()->id; |
|
|
|
|
65
|
|
|
$validator = Validator::make($attributes, $this->rules($paymentMethodId)); |
66
|
|
|
|
67
|
|
|
if ($validator->fails()) { |
68
|
|
|
return $validator; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
return $this->updateOrAddModel($model, $attributes); |
72
|
|
|
} |
73
|
|
|
} |