Beispiel #1
0
 public function body_content()
 {
     $dbc = $this->connection;
     $settings = $this->config->PLUGIN_SETTINGS;
     $dbc->selectDB($settings['TargetedPromosDB']);
     $model = new DeveloperTargetsModel($dbc);
     $model->addedDate('2015-07-20', '>');
     echo '<textarea>';
     foreach ($model->find() as $obj) {
         echo $obj->card_no() . "\n";
     }
     echo '</textarea>';
 }
Beispiel #2
0
 public function run()
 {
     $settings = $this->config->PLUGIN_SETTINGS;
     $dbc = FannieDB::get($settings['TargetedPromosDB']);
     $warehouse = $settings['WarehouseDatabase'];
     $rules = new DeveloperRulesModel($dbc);
     $all_rules = $rules->find('developerRulesID', true);
     if (count($all_rules) == 0) {
         $rules->couponUPC('');
         $rules->save();
         $all_rules = $rules->find('developerRulesID', true);
     }
     $rules = $all_rules[0];
     $targets = new DeveloperTargetsModel($dbc);
     $shopping_period = new stdClass();
     $shopping_period->start = date('Ymd', strtotime($rules->examineMonths() . ' months ago'));
     $shopping_period->end = date('Ymd');
     $statusP = $dbc->prepare('
         SELECT Type,
             memType,
             staff
         FROM ' . $this->config->OP_DB . $dbc->sep() . 'custdata
         WHERE CardNo=?
             AND personNum=1
     ');
     $meminfoP = $dbc->prepare('
         SELECT card_no
         FROM ' . $this->config->OP_DB . $dbc->sep() . 'meminfo
         WHERE ads_OK = 1
             AND (zip LIKE \'55%\' OR zip LIKE \'56%\')
             AND card_no=?
     ');
     /**
       Lookup accounts with activity matching
       the developer criteria
     */
     $activityP = $dbc->prepare('
         SELECT s.card_no
         FROM ' . $warehouse . $dbc->sep() . 'sumMemSalesByDay AS s
         WHERE date_id BETWEEN ? AND ?
         GROUP BY s.card_no
         HAVING SUM(transCount) >= ?
             AND AVG(total) <= ?
             AND SUM(total) <= ?
     ');
     $args = array($shopping_period->start, $shopping_period->end, $rules->minVisits(), $rules->minVisitAvg(), $rules->examineMonths() * $rules->minMonthAvg());
     $activityR = $dbc->execute($activityP, $args);
     $def_target = new DefectorTargetsModel($dbc);
     while ($w = $dbc->fetchRow($activityR)) {
         /**
           Enforce rules about account status
         */
         $statusR = $dbc->execute($statusP, array($w['card_no']));
         if (!$statusR || $dbc->numRows($statusR) == 0) {
             continue;
         }
         $status = $dbc->fetchRow($statusR);
         if ($rules->memberOnly() && $status['Type'] != 'PC') {
             continue;
         }
         if (!$rules->includeStaff() && $status['staff']) {
             continue;
         }
         $infoP = $dbc->execute($meminfoP, array($w['card_no']));
         if (!$infoP || $dbc->numRows($infoP) == 0) {
             continue;
         }
         /**
           If the account is already in the developer
           program, check whether any coupons have been
           redeemed. If so, decrement the issued counter
           and reset the redeemed counter. Issued is not
           reset so that "issued - redeemed" should always
           represent the number of outstanding coupons.
         
           Other accounts are simply added to the program.
         */
         $targets->reset();
         $targets->card_no($w['card_no']);
         $def_target->card_no($w['card_no']);
         if (!$def_target->load()) {
             echo "Adding: " . $w['card_no'] . "\n";
             $targets->card_no($w['card_no']);
             $targets->addedDate(date('Y-m-d H:i:s'));
             $targets->save();
         }
     }
 }