2020-11-04 11:49:43 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\bo;
|
|
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
2021-02-23 18:27:03 +01:00
|
|
|
use App\Mail\CourrierArcadiaError;
|
2020-11-04 11:49:43 +01:00
|
|
|
use App\Models\Participation;
|
|
|
|
|
use App\Models\Settings;
|
|
|
|
|
use Illuminate\Http\Request;
|
2021-02-23 18:27:03 +01:00
|
|
|
use Illuminate\Support\Facades\Mail;
|
2020-11-04 11:49:43 +01:00
|
|
|
|
|
|
|
|
class WinnersListController extends Controller
|
|
|
|
|
{
|
2021-02-23 18:27:03 +01:00
|
|
|
private $apiCrm;
|
|
|
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
|
$this->apiCrm = new \LDCCRM\ApiV1(config('crm.endpoint'), config('crm.token'));
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-04 11:49:43 +01:00
|
|
|
public function index() {
|
|
|
|
|
$winnersList = Participation::where('instant_win_id', '<>', null)->get();
|
2020-11-04 13:51:22 +01:00
|
|
|
$settings = Settings::select('use_ean_codes', 'winning_proof')->first();
|
2020-11-04 11:49:43 +01:00
|
|
|
return view('bo.winners-list.index', compact('winnersList', 'settings'));
|
|
|
|
|
}
|
2020-11-20 15:18:31 +01:00
|
|
|
|
|
|
|
|
public function courrierArcadia($id) {
|
|
|
|
|
$participation = Participation::findOrFail($id);
|
|
|
|
|
|
2021-02-23 18:27:03 +01:00
|
|
|
$crmUser = $this->apiCrm->getCustomer($participation->user->crm_id);
|
|
|
|
|
if ($crmUser->status === 'NOK')
|
|
|
|
|
return back()->withErrors("Erreur lors de la récupération de l'utilisateur dans la CRM : Code : ". $crmUser->code. " Message : " . $crmUser->message);
|
|
|
|
|
|
|
|
|
|
$crmId = $participation->user->crm_id;
|
2020-11-20 15:18:31 +01:00
|
|
|
|
2021-02-23 18:27:03 +01:00
|
|
|
$crmUser = $crmUser->user;
|
2020-11-20 15:18:31 +01:00
|
|
|
|
|
|
|
|
$corps = '<arcadia>' . "\n" ;
|
|
|
|
|
$corps .= '<Commande> ' . "\n" ;
|
|
|
|
|
$corps .= "\t" . '<Num_Commande></Num_Commande>' . "\n" ;
|
|
|
|
|
$corps .= "\t" . '<Date_Commande>' . date ('d/m/Y') . '</Date_Commande>' . "\n" ;
|
|
|
|
|
$corps .= "\t" . '<Operation></Operation> ' . "\n" ;
|
|
|
|
|
$corps .= "\t" . '<Civilite></Civilite>' . "\n" ;
|
2021-02-23 18:27:03 +01:00
|
|
|
$corps .= "\t" . '<Nom><![CDATA[' .trim ($crmUser->firstname). ']]></Nom>' . "\n" ;
|
|
|
|
|
$corps .= "\t" . '<Prenom><![CDATA[' .trim ($crmUser->lastname). ']]></Prenom>' . "\n" ;
|
|
|
|
|
$corps .= "\t" . '<Adresse><![CDATA[' .trim ($crmUser->address). ']]></Adresse>' . "\n" ;
|
|
|
|
|
$corps .= "\t" . '<Adresse_Complementaire><![CDATA[' .trim ($crmUser->address2). ']]></Adresse_Complementaire>' . "\n" ;
|
|
|
|
|
$corps .= "\t" . '<CP><![CDATA[' .trim ($crmUser->postcode). ']]></CP>' . "\n" ;
|
|
|
|
|
$corps .= "\t" . '<Ville><![CDATA[' .trim ($crmUser->city). ']]></Ville>' . "\n" ;
|
2020-11-20 15:18:31 +01:00
|
|
|
$corps .= '<Ligne_de_Commande>' . "\n" ;
|
|
|
|
|
$corps .= "\t" . '<Code_Support></Code_Support> ' . "\n" ;
|
|
|
|
|
$corps .= "\t" . '<Libelle_Type_Support></Libelle_Type_Support> ' . "\n" ;
|
|
|
|
|
$corps .= "\t" . '<Quantite>1</Quantite>' . "\n" ;
|
|
|
|
|
$corps .= "\t" . '<Poids_Unitaire_Colis></Poids_Unitaire_Colis>' . "\n" ;
|
|
|
|
|
$corps .= '</Ligne_de_Commande>' . "\n" ;
|
|
|
|
|
$corps .= '</Commande> ' . "\n" ;
|
|
|
|
|
$corps .= '</arcadia>' ;
|
|
|
|
|
|
2021-02-23 18:27:03 +01:00
|
|
|
return view('bo.winners-list.arcadia', compact('participation', 'corps', 'crmId'));
|
2020-11-20 15:18:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function createCourrierArcadia(Request $request, $id) {
|
2021-02-23 18:27:03 +01:00
|
|
|
$participation = Participation::findOrFail($id);
|
|
|
|
|
$instantWin = $participation->instant_win;
|
|
|
|
|
|
|
|
|
|
if ($instantWin->prize->arcadia_operation_code !== 0 && $instantWin->prize->arcadia_support_code !== 0) {
|
|
|
|
|
|
|
|
|
|
$fields = [
|
|
|
|
|
'root' => [
|
|
|
|
|
[
|
|
|
|
|
'fieldName' => 'order_date',
|
|
|
|
|
'fieldValue' => date('d/m/Y')
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'fieldName' => 'operation',
|
|
|
|
|
'fieldValue' => $instantWin->prize->arcadia_operation_code
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
'orderLine' => [
|
|
|
|
|
[
|
|
|
|
|
'fieldName' => 'code_unique',
|
|
|
|
|
'fieldValue' => $participation->code->code_unique
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'fieldName' => 'support_code',
|
|
|
|
|
'fieldValue' => $instantWin->prize->arcadia_support_code
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'fieldName' => 'label_type_support',
|
|
|
|
|
'fieldValue' => 'Gain du lot : ' . $instantWin->prize->label_one
|
|
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
];
|
2020-11-20 15:18:31 +01:00
|
|
|
|
2021-02-23 18:27:03 +01:00
|
|
|
$settings = Settings::find(1);
|
|
|
|
|
if ($settings->use_ean_codes === 1) {
|
|
|
|
|
$fields['orderLine'][] = [
|
|
|
|
|
'fieldName' => 'code_on_pack',
|
|
|
|
|
'fieldValue' => $participation->code_ean->code
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$arcadiaMail = $this->apiCrm->ArcadiaOutgoingMail($participation->user->crm_id, $fields, 'game');
|
|
|
|
|
if ($arcadiaMail->status === 'NOK'){
|
|
|
|
|
Mail::to(config('mail.MAIL_ADMIN'))->send(new CourrierArcadiaError($participation->user));
|
|
|
|
|
return back()->withErrors("Erreur lors de l'envoi du courrier Arcadia. Code : ". $arcadiaMail->code. " Message : " . $arcadiaMail->message);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-11-20 15:18:31 +01:00
|
|
|
return back()->with('success', 'Courrier envoyé !');
|
|
|
|
|
}
|
2020-11-04 11:49:43 +01:00
|
|
|
}
|