1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Hideyo\Ecommerce\Framework\Services\Client\Entity; |
4
|
|
|
|
5
|
|
|
use Hideyo\Ecommerce\Framework\Services\Client\Entity\Client; |
6
|
|
|
use Hideyo\Ecommerce\Framework\Services\Client\Entity\ClientAddressRepository; |
7
|
|
|
use Hideyo\Ecommerce\Framework\Services\BaseRepository; |
8
|
|
|
|
9
|
|
|
class ClientRepository extends BaseRepository |
10
|
|
|
{ |
11
|
|
|
protected $model; |
12
|
|
|
|
13
|
|
|
public function __construct(Client $model, ClientAddressRepository $clientAddress) |
14
|
|
|
{ |
15
|
|
|
$this->model = $model; |
16
|
|
|
$this->clientAddress = $clientAddress; |
|
|
|
|
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function selectAll() |
20
|
|
|
{ |
21
|
|
|
return $this->model->where('shop_id', auth('hideyobackend')->user()->selected_shop_id)->get(); |
|
|
|
|
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function selectAllByBillClientAddress() |
25
|
|
|
{ |
26
|
|
|
return $this->model->selectRaw('CONCAT(client_address.firstname, " ", client_address.lastname) as fullname, client_address.*, client.id') |
27
|
|
|
->leftJoin('client_address', 'client.bill_client_address_id', '=', 'client_address.id')->where('shop_id', auth('hideyobackend')->user()->selected_shop_id) |
|
|
|
|
28
|
|
|
->get(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function findByEmail($email, $shopId) |
32
|
|
|
{ |
33
|
|
|
return $this->model->where('shop_id', $shopId)->where('email', '=', $email)->get()->first(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function checkEmailByShopIdAndNoAccountCreated($email, $shopId) { |
37
|
|
|
return $this->model->where('shop_id', $shopId)->whereNotNull('account_created')->where('email', '=', $email)->get()->first(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function checkEmailByShopId($email, $shopId) |
41
|
|
|
{ |
42
|
|
|
return $this->model->where('shop_id', $shopId)->where('email', '=', $email)->get()->first(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function validateRegisterNoAccount(array $attributes, $shopId) |
46
|
|
|
{ |
47
|
|
|
$client = $this->model->where('shop_id', $shopId)->where('email', '=', $attributes['email'])->get()->first(); |
48
|
|
|
|
49
|
|
|
if ($client) { |
50
|
|
|
return false; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
return true; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function selectOneByShopIdAndId($shopId, $clientId) |
57
|
|
|
{ |
58
|
|
|
return $this->model->with(array('clientAddress', 'clientDeliveryAddress', 'clientBillAddress'))->where('shop_id', $shopId)->where('active', 1)->where('id', '=', $clientId)->first(); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function selectOneById($clientId) |
62
|
|
|
{ |
63
|
|
|
return $this->model->with(array('clientAddress', 'clientDeliveryAddress', 'clientBillAddress'))->where('shop_id', auth('hideyobackend')->user()->selected_shop_id)->where('active', 1)->where('id', '=', $clientId)->first(); |
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function getClientByConfirmationCode($shopId, $email, $confirmationCode) |
67
|
|
|
{ |
68
|
|
|
return $this->model->where('shop_id', $shopId)->where('email', '=', $email)->where('confirmation_code', '=', $confirmationCode)->get()->first(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function validateConfirmationCodeByConfirmationCodeAndEmail($confirmationCode, $email, $shopId) |
72
|
|
|
{ |
73
|
|
|
return $this->model |
74
|
|
|
->where('shop_id', $shopId) |
75
|
|
|
->where('email', '=', $email) |
76
|
|
|
->whereNotNull('account_created') |
77
|
|
|
->where('confirmation_code', '=', $confirmationCode) |
78
|
|
|
->get()->first(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function validateConfirmationCodeByConfirmationCodeAndNewEmail($confirmationCode, $newEmail, $shopId) |
82
|
|
|
{ |
83
|
|
|
return $this->model |
84
|
|
|
->where('shop_id', $shopId) |
85
|
|
|
->where('new_email', '=', $newEmail) |
86
|
|
|
->whereNotNull('account_created') |
87
|
|
|
->where('confirmation_code', '=', $confirmationCode) |
88
|
|
|
->get()->first(); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function selectAllExport() |
92
|
|
|
{ |
93
|
|
|
return $this->model->with(array('clientAddress', 'clientDeliveryAddress', 'clientBillAddress'))->whereNotNull('account_created')->where('active', 1)->where('shop_id', auth('hideyobackend')->user()->selected_shop_id)->get(); |
|
|
|
|
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function editAddress($shopId, $clientId, $addressId, $attributes) |
97
|
|
|
{ |
98
|
|
|
return $this->clientAddress->updateByIdAndShopId($shopId, $attributes, $clientId, $addressId); |
|
|
|
|
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|