]> _ Git - cubeextranet.git/commitdiff
#563
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Fri, 2 Sep 2016 08:56:29 +0000 (08:56 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Fri, 2 Sep 2016 08:56:29 +0000 (08:56 +0000)
inc/ws/Controlleur/class.ws.maintenance.php

index 015a33fd0ab33669551c3a3e73e9afbdd5a9d45f..99d28d3cceb48686b0aaa9032ef3d836ffd8a619 100644 (file)
@@ -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 '<pre>' . print_r($res, true) . '</pre>';
+       }
+
 }