2020-11-04 11:49:43 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\bo;
|
|
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
use App\Models\Participation;
|
|
|
|
|
use App\Models\Settings;
|
2020-11-20 15:18:31 +01:00
|
|
|
use CPCConnection;
|
|
|
|
|
use Exception;
|
2020-11-04 11:49:43 +01:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
|
|
class WinnersListController extends Controller
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
$cpcConnect = new CPCConnection(config('crm.CRM_PLATOS_WSDL'), config('crm.WS_SERVCE_LOGIN'), config('crm.WS_SERVCE_PASSWORD'));
|
|
|
|
|
$cpcConnect->connect();
|
|
|
|
|
$crmUser = $cpcConnect->getUser($participation->user->crm_id);
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
return back()->withErrors("Erreur lors de la récupération de l'utilisateur dans la CRM : " . $e->getMessage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$crmId = $crmUser->iId;
|
|
|
|
|
$idCourrierArcadia = $participation->instant_win->prize->arcadia_mail_id;
|
|
|
|
|
|
|
|
|
|
$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" ;
|
|
|
|
|
$corps .= "\t" . '<Nom><![CDATA[' .trim ($crmUser->zNom). ']]></Nom>' . "\n" ;
|
|
|
|
|
$corps .= "\t" . '<Prenom><![CDATA[' .trim ($crmUser->zPrenom). ']]></Prenom>' . "\n" ;
|
|
|
|
|
$corps .= "\t" . '<Adresse><![CDATA[' .trim ($crmUser->zAdresse1). ']]></Adresse>' . "\n" ;
|
|
|
|
|
$corps .= "\t" . '<Adresse_Complementaire><![CDATA[' .trim ($crmUser->zAdresse2). ']]></Adresse_Complementaire>' . "\n" ;
|
|
|
|
|
$corps .= "\t" . '<CP><![CDATA[' .trim ($crmUser->zCodePostal). ']]></CP>' . "\n" ;
|
|
|
|
|
$corps .= "\t" . '<Ville><![CDATA[' .trim ($crmUser->zVille). ']]></Ville>' . "\n" ;
|
|
|
|
|
$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>' ;
|
|
|
|
|
|
|
|
|
|
return view('bo.winners-list.arcadia', compact('participation', 'corps', 'crmId', 'idCourrierArcadia'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function createCourrierArcadia(Request $request, $id) {
|
|
|
|
|
$corps = $request->corps;
|
|
|
|
|
$idCourrierArcadia = $request->id_courrier_arcadia;
|
|
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
$cpcConnect = new CPCConnection(config('crm.CRM_PLATOS_WSDL'), config('crm.WS_SERVCE_LOGIN'), config('crm.WS_SERVCE_PASSWORD'));
|
|
|
|
|
$cpcConnect->connect();
|
|
|
|
|
$cpcConnect->createOutCourrier($id, $idCourrierArcadia, $corps);
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
return back()->withErrors("Erreur lors de l'envoi du courrier Arcadia : " . $e->getMessage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return back()->with('success', 'Courrier envoyé !');
|
|
|
|
|
}
|
2020-11-04 11:49:43 +01:00
|
|
|
}
|