示例#1
0
 /**
  * @before _secure
  */
 public function index()
 {
     $this->seo(array("title" => "Dashboard", "description" => "Stats for your Data"));
     $view = $this->getActionView();
     $commissions = [];
     $start = RM::get("start", date("Y-m-d", strtotime('now')));
     $end = RM::get("end", date("Y-m-d", strtotime('now')));
     $today = date('Y-m-d');
     $yesterday = date('Y-m-d', strtotime("-1 day"));
     $perf = Shared\Services\User::livePerf($this->user, $today, $today);
     $yestPerf = Shared\Services\User::livePerf($this->user, $yesterday, $yesterday);
     $notifications = Notification::all(["org_id = ?" => $this->org->id, "meta = ?" => ['$in' => ['all', $this->user->_id]]], [], "created", "desc", 5, 1);
     $total = Performance::total(['start' => date("Y-m-d", strtotime('-365 day')), 'end' => date("Y-m-d", strtotime('-2 day'))], $this->user);
     $view->set("start", date("Y-m-d", strtotime('-7 day')))->set("end", date("Y-m-d", strtotime('now')))->set("notifications", $notifications)->set("total", $total)->set("yestPerf", $yestPerf)->set("performance", $perf);
 }
示例#2
0
文件: admin.php 项目: vNative/vnative
 /**
  * @before _secure
  */
 public function index()
 {
     $this->seo(array("title" => "Dashboard"));
     $view = $this->getActionView();
     $d = 1;
     $publishers = User::all(["org_id = ?" => $this->org->_id, "type = ?" => "publisher"], ["_id"]);
     $in = array_keys($publishers);
     $start = RM::get("start", date('Y-m-d', strtotime('-4 day')));
     $end = RM::get("end", date('Y-m-d', strtotime('now')));
     $dq = ['start' => date('Y-m-d', strtotime("-365 day")), 'end' => $end];
     $pubPerf = (object) Performance::total($dq, $publishers);
     $advPerf = (object) Performance::total($dq, $this->org->users('advertiser', 'users'), ['revenue']);
     $topusers = $this->widgets();
     if (array_key_exists("widgets", $this->org->meta)) {
         $d = in_array("top10ads", $this->org->meta["widgets"]) + in_array("top10pubs", $this->org->meta["widgets"]);
     }
     $view->set("start", $start)->set("end", $end)->set("d", 12 / $d)->set("topusers", $topusers)->set("links", \Link::count(['user_id' => ['$in' => $in]]))->set("platforms", \Platform::count(['user_id' => ['$in' => $in]]))->set("performance", Performance::calProfit($pubPerf, $advPerf));
 }
示例#3
0
 /**
  * @before _admin
  */
 public function info($id = null)
 {
     $this->seo(array("title" => "Publisher Edit"));
     $view = $this->getActionView();
     $publisher = User::first(["_id = ?" => $id, "type = ?" => "publisher", "org_id = ?" => $this->org->id]);
     if (!$publisher) {
         $this->_404();
     }
     $platforms = Platform::all(["user_id = ?" => $publisher->id]);
     $view->set("platforms", $platforms);
     $view->set("errors", []);
     if (RM::type() == 'POST') {
         $action = RM::post('action', '');
         switch ($action) {
             case 'account':
                 $fields = ['name', 'email', 'phone', 'country', 'currency', 'username'];
                 foreach ($fields as $f) {
                     $publisher->{$f} = RM::post($f);
                 }
                 $publisher->save();
                 $view->set('message', 'Account Info updated!!');
                 break;
             case 'password':
                 $old = RM::post('password');
                 $new = RM::post('npassword');
                 $view->set($publisher->updatePassword($old, $new));
                 break;
             case 'campaign':
                 $publisher->getMeta()['campaign'] = ['model' => RM::post('model'), 'rate' => $this->currency(RM::post('rate'))];
                 $publisher->save();
                 $view->set('message', 'Payout Info Updated!!');
                 break;
             case 'trackingDomain':
                 $tdomain = (array) RM::post('tdomain', '');
                 if ($tdomain && ArrayMethods::inArray($this->org->tdomains, $tdomain)) {
                     $publisher->getMeta()['tdomain'] = $tdomain;
                     $publisher->save();
                     $view->set('message', 'Added Tracking Domain for publisher');
                 } else {
                     $view->set('message', 'Invalid Request!!');
                 }
             case 'commadd':
             case 'commedit':
                 $comm_id = RM::post('comm_id');
                 if ($comm_id) {
                     $comm = Commission::first(['_id' => $comm_id, 'user_id' => $publisher->_id]);
                 } else {
                     $comm = new Commission(['user_id' => $publisher->_id]);
                 }
                 $comm->model = RM::post('model');
                 $comm->description = RM::post('description');
                 $comm->rate = $this->currency(RM::post('rate'));
                 $comm->coverage = RM::post('coverage', ['ALL']);
                 $comm->save();
                 $view->set('message', "Multi Country Payout Saved!!");
                 break;
         }
     }
     if (RM::type() === 'DELETE') {
         $action = RM::get("action");
         switch ($action) {
             case 'payoutdel':
                 unset($publisher->getMeta()['campaign']);
                 $publisher->save();
                 $view->set('message', 'Payout Deleted!!');
                 break;
             case 'commDel':
                 $comm = Commission::first(['_id' => RM::get("comm_id"), 'user_id' => $publisher->_id]);
                 if ($comm) {
                     $comm->delete();
                     $view->set('message', 'Payout Deleted!!');
                 } else {
                     $view->set('message', 'Invalid Request!!');
                 }
                 break;
             case 'afields':
                 $meta = $publisher->meta;
                 $publisher->removeFields();
                 unset($meta['afields']);
                 Db::updateRaw('users', ['_id' => Db::convertType($publisher->_id, 'id')], ['$set' => ['meta' => $meta]]);
                 $view->set('message', 'Data Removed!!');
                 break;
             case 'defaultDomain':
                 unset($publisher->getMeta()['tdomain']);
                 $publisher->save();
                 $view->set('message', 'Removed tracking domain!!');
                 break;
         }
     }
     $afields = Meta::search('customField', $this->org);
     $view->set('afields', $afields)->set("publisher", $publisher)->set("commissions", Commission::all(["user_id = ?" => $publisher->id]))->set("start", strftime("%Y-%m-%d", strtotime('-7 day')))->set("end", strftime("%Y-%m-%d", strtotime('now')))->set("d", Performance::total(['start' => $start ?? $publisher->created->format('Y-m-d'), 'end' => $end ?? date('Y-m-d')], $publisher));
 }
示例#4
0
文件: cron.php 项目: vNative/vnative
 protected function _parseContest($c)
 {
     // find publishers performances
     $start = $c->start->format('Y-m-d');
     $yesterday = date('Y-m-d', strtotime('-1 day'));
     // whatever may the type be but sort publisher according to clicks
     $pubClicks = [];
     $meta = $c->meta;
     if (!isset($meta['condition'])) {
         return;
     }
     $users = \User::all(['type' => 'publisher', 'org_id' => $c->org_id], ['_id', 'username']);
     foreach ($users as $u) {
         $perf = \Performance::total(['start' => $start, 'end' => $yesterday], $u);
         $key = $perf['clicks'];
         $pubClicks[$key][] = sprintf('%s', $u->_id);
     }
     krsort($pubClicks);
     $condition = $meta['condition'];
     switch ($c->type) {
         case 'topEarner':
             $count = $condition['topEarnerCount'];
             $i = 0;
             $condition['winners'] = [];
             foreach ($pubClicks as $key => $value) {
                 if ($i >= $count) {
                     break;
                     // we have total topEarners reqd.
                 }
                 foreach ($value as $v) {
                     $condition['winners'][] = $v;
                     $i++;
                     if ($i >= $count) {
                         break;
                     }
                 }
             }
             break;
         case 'clickRange':
             foreach ($pubClicks as $key => $value) {
                 // foreach clickRange check if this key is in range
                 foreach ($condition as &$cond) {
                     $winners = isset($cond['winners']) ? $cond['winners'] : [];
                     $isStart = is_numeric($cond['start']);
                     $isEnd = is_numeric($cond['end']);
                     $start = (int) $cond['start'];
                     $end = (int) $cond['end'];
                     $merge = false;
                     if ($isStart && $isEnd) {
                         if ($start <= $key && $end >= $key) {
                             $merge = true;
                         }
                     } else {
                         if ($isStart && $start <= $key) {
                             $merge = true;
                         } else {
                             if ($isEnd && $end >= $key) {
                                 $merge = true;
                             }
                         }
                     }
                     if ($merge) {
                         $winners = array_merge($winners, $value);
                         $winners = array_unique($winners);
                     }
                     $cond['winners'] = $winners;
                 }
             }
             break;
     }
     $meta['condition'] = $condition;
     $c->meta = $meta;
     $this->log('Saving contest: ' . $c->_id);
     $c->save();
 }