From a4b6abfb963b615129d0bf8c2479ef385fa4e68a Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Fri, 2 Sep 2016 08:56:29 +0000 Subject: [PATCH] #563 --- inc/ws/Controlleur/class.ws.maintenance.php | 50 +++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/inc/ws/Controlleur/class.ws.maintenance.php b/inc/ws/Controlleur/class.ws.maintenance.php index 015a33fd0..99d28d3cc 100644 --- a/inc/ws/Controlleur/class.ws.maintenance.php +++ b/inc/ws/Controlleur/class.ws.maintenance.php @@ -1025,4 +1025,54 @@ class wsMaintenance { } } + public static function syncMailchimp() { + global $core; + + set_time_limit(0); + $api = new CubeIT_Services_Mailchimp('2abe038d70806d50b23b7a37aa2f6067-us12'); + + $u = array(); + + $r = $core->con->select('SELECT * FROM utilisateurs'); + while ($r->fetch()) { + $u[$r->utilisateur_id] = $r->row(); + } + + $r = $core->con->select("SELECT * FROM entreprises_ws WHERE revendeur='Cubedesigners' AND ws_grade<=4 AND ws_grade>0"); + while ($r->fetch()) { + $e[$r->entreprise_id] = array('COUNTRY' => $r->pays, 'CONTACT' => date('d/m/Y', $r->date_creation), 'LASTACTION' => date('d/m/Y', $r->date_creation), 'COMPANY' => $r->nom, 'RESSELER' => ($r->ws_grade > 2) ? 1 : 0, 'FLUIDBOOKS' => 0, 'TURNOVER' => 0); + } + + $r = $core->con->select("SELECT * FROM entreprises_vue"); + while ($r->fetch()) { + if (isset($e[$r->entreprise_id])) { + $e[$r->entreprise_id]['TURNOVER'] = $r->ca; + } + } + + $rr = $core->con->select('SELECT COUNT(*) AS nb,MAX(`date`) AS lastdate,facturable_id FROM books_vue WHERE status >= 0 GROUP BY facturable_id'); + while ($rr->fetch()) { + $eid = $u[$rr->facturable_id]['entreprise']; + if (isset($e[$eid])) { + $e[$eid]['FLUIDBOOKS'] = $rr->nb; + $e[$eid]['LASTACTION'] = date('d/m/Y', $rr->lastdate); + } + } + + $batch = array(); + foreach ($u as $user) { + if (!isset($e[$user['entreprise']])) { + continue; + } + if (stristr($user['email'], 'extranet.cubedesigners.com')) { + continue; + } + + $batch[] = array_merge($e[$user['entreprise']], array('email' => $user['email'], 'LOCALE' => $user['lang'], 'FNAME' => $user['prenom'], 'LNAME' => $user['nom'])); + } + + $res = $api->batchSubscribe('69f69a2bb8', $batch); + echo '
' . print_r($res, true) . '
'; + } + } -- 2.39.5