From 973134eaf302591e96377e237e778034e0cf04b4 Mon Sep 17 00:00:00 2001 From: Vincent BRIDIER Date: Mon, 8 Mar 2021 11:37:54 +0100 Subject: [PATCH 1/2] - Add stats brand view - Add method removeOptInCustomer --- .../Controllers/Api/v1/CustomerController.php | 38 +++++++++++++++++++ app/Models/Brand.php | 8 ++++ clients/LDCCRM_V1.php | 4 ++ resources/views/brands/index.blade.php | 4 ++ routes/api.php | 1 + 5 files changed, 55 insertions(+) diff --git a/app/Http/Controllers/Api/v1/CustomerController.php b/app/Http/Controllers/Api/v1/CustomerController.php index ef10b5b..f23c039 100644 --- a/app/Http/Controllers/Api/v1/CustomerController.php +++ b/app/Http/Controllers/Api/v1/CustomerController.php @@ -289,6 +289,11 @@ class CustomerController extends Controller if ($customer) { $customerLogin = $customer->logins()->where('brand_id', $brandId)->first(); if ($customerLogin) { + // Check if same password + if (Hash::check($password, $customerLogin->password)){ + return new StatusResource(['status' => 'KO', 'code' => 123, 'message' => 'Same password.']); + } + $customerLogin->password = Hash::make($password); $customerLogin->save(); } else { @@ -398,6 +403,39 @@ class CustomerController extends Controller } } + /** + * Remove opt-in for the customer on this brand + * @param Request $request + * @param $hashcode + */ + public function removeOptin(Request $request, $hashcode) { + // TODO : Liaison des opt-in avec MailJet + $brandId = $request->brand_id; + + $infos = CustomerInfos::where([ + ['brand_id', $brandId], + ['hashcode', $hashcode] + ])->first(); + + if ($infos) { + $infos->opt_in = 0; + + // On enregistre l'historique du changement d'optin + $optinHistory = new CustomerOptInHistory(); + $optinHistory->customer_id = $infos->customer_id; + $optinHistory->new_value = 0; + $optinHistory->brand_id = $brandId; + $optinHistory->save(); + + $infos->save(); + // "Changement effectué" + return new StatusResource(['status' => 'OK', 'message' => 'Update complete.']); + } else { + // "Ce compte n'a pas d'information liés à cette marque" + return new StatusResource(['status' => 'KO', 'code' => 122, 'message' => 'User not found.']); + } + } + public function addSingleOptin(Request $request) { $validator = Validator::make($request->all(), [ 'email' => 'required|email', diff --git a/app/Models/Brand.php b/app/Models/Brand.php index 6e7c660..5a54e33 100644 --- a/app/Models/Brand.php +++ b/app/Models/Brand.php @@ -26,4 +26,12 @@ class Brand extends Model public function single_optins() { return $this->hasMany('App\Models\SingleOptin', 'brand_id'); } + + public function getAccountsAttribute(){ + return $this->customer_infos()->count(); + } + + public function getTotalOptinsAttribute(){ + return $this->customer_infos()->where('opt_in', 1)->count() + $this->single_optins()->count(); + } } diff --git a/clients/LDCCRM_V1.php b/clients/LDCCRM_V1.php index 7499bf9..6e1959d 100644 --- a/clients/LDCCRM_V1.php +++ b/clients/LDCCRM_V1.php @@ -92,6 +92,10 @@ class ApiV1 return $this->callAPI('POST', "/customer/$id/toggle-optin"); } + public function removeOptInCustomer($hashcode){ + return $this->callAPI('POST', "/customer/$hashcode/remove-optin"); + } + public function loginCustomer($email, $password){ return $this->callAPI('POST', "/customer/login", ['email' => $email, 'password' => $password]); } diff --git a/resources/views/brands/index.blade.php b/resources/views/brands/index.blade.php index ac56f96..24965ab 100644 --- a/resources/views/brands/index.blade.php +++ b/resources/views/brands/index.blade.php @@ -8,6 +8,8 @@ + + @@ -15,6 +17,8 @@ @foreach ($brands as $brand) + + diff --git a/routes/api.php b/routes/api.php index f56474f..e3eae2d 100644 --- a/routes/api.php +++ b/routes/api.php @@ -25,6 +25,7 @@ Route::prefix('v1')->middleware(['auth:api', 'check-brand'])->group(function() { Route::post('/{id}/change-password', [CustomerController::class, 'changePassword']); Route::post('/{id}/activate', [CustomerController::class, 'activateAccount']); Route::post('/{id}/toggle-optin', [CustomerController::class, 'toggleOptin']); + Route::post('/{hashcode}/remove-optin', [CustomerController::class, 'removeOptin']); Route::post('/login', [CustomerController::class, 'authenticate']); }); // Optin simple From 199198340a4fe95e5dc959b5f65d9eb869a69039 Mon Sep 17 00:00:00 2001 From: Vincent BRIDIER Date: Fri, 12 Mar 2021 11:07:33 +0100 Subject: [PATCH 2/2] - Fix email in CustomerResource --- app/Http/Resources/CustomerResource.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Http/Resources/CustomerResource.php b/app/Http/Resources/CustomerResource.php index 2539016..3d16d2e 100644 --- a/app/Http/Resources/CustomerResource.php +++ b/app/Http/Resources/CustomerResource.php @@ -29,6 +29,7 @@ class CustomerResource extends JsonResource 'crm_id' => $this->id, 'firstname' => $infos->firstname, 'lastname' => $infos->lastname, + 'email' => $this->email, 'birth_date' => $infos->birth_date, 'address' => $infos->address, 'address2' => $infos->address2,
Nom de la marqueNombre de comptesNombre d'optins Date d'ajout en base
{{ $brand->name }}{{ $brand->accounts }}{{ $brand->total_optins }} {{ \Carbon\Carbon::parse($brand->created_at)->format('d/m/Y à H:i') }} Modifier