예제 #1
0
파일: invoice.php 프로젝트: vNative/vnative
 public static function exists($uid, $start = null, $end = null)
 {
     $uid = Db::convertType($uid);
     $dateQuery = Utils::dateQuery($start, $end);
     $inv_exist = self::first(['$or' => [["user_id" => $uid, "start" => ['$lte' => $dateQuery['start'], '$lte' => $dateQuery['end']], "end" => ['$gte' => $dateQuery['start'], '$gte' => $dateQuery['end']]], ["user_id" => $uid, "start" => Db::dateQuery($start, $end), "end" => ['$gte' => $dateQuery['start'], '$gte' => $dateQuery['end']]], ["user_id" => $uid, "start" => ['$lte' => $dateQuery['start'], '$lte' => $dateQuery['end']], "end" => Db::dateQuery($start, $end)], ["user_id" => $uid, "start" => Db::dateQuery($start, $end), "end" => Db::dateQuery($start, $end)]]]);
     return $inv_exist;
 }
예제 #2
0
파일: account.php 프로젝트: vNative/vnative
 /**
  * @before _secure
  */
 public function manage()
 {
     $this->seo(array("title" => "Manage Account"));
     $view = $this->getActionView();
     $users = User::all(['type' => Db::convertType('admin|adm|afm', 'regex'), "org_id" => $this->org->_id]);
     $view->set('users', $users);
 }
예제 #3
0
파일: contest.php 프로젝트: vNative/vnative
 public static function exists($oid, $opts = [])
 {
     $oid = Db::convertType($oid);
     $dateQuery = Utils::dateQuery($opts);
     $multiple = $opts['multiple'] ?? false;
     if ($multiple) {
         $query = "all";
     } else {
         $query = "first";
     }
     $inv_exist = self::$query(['$or' => [["org_id" => $oid, "start" => ['$lte' => $dateQuery['start'], '$lte' => $dateQuery['end']], "end" => ['$gte' => $dateQuery['start'], '$gte' => $dateQuery['end']]], ["org_id" => $oid, "start" => Db::dateQuery($start, $end), "end" => ['$gte' => $dateQuery['start'], '$gte' => $dateQuery['end']]], ["org_id" => $oid, "start" => ['$lte' => $dateQuery['start'], '$lte' => $dateQuery['end']], "end" => Db::dateQuery($start, $end)], ["org_id" => $oid, "start" => Db::dateQuery($start, $end), "end" => Db::dateQuery($start, $end)]]]);
     return $inv_exist;
 }
예제 #4
0
파일: user.php 프로젝트: vNative/vnative
 public static function customFields($user, $org)
 {
     $afields = \Meta::search('customField', $org);
     if (count($afields) > 0) {
         $meta = $user->meta ?? [];
         $extraFields = [];
         foreach ($afields as $value) {
             $key = $value['name'];
             $type = $value['type'];
             $message = $value['label'] . " is required!!";
             switch ($type) {
                 case 'file':
                     $v = Utils::media($key, 'upload', ['extension' => 'jpe?g|gif|bmp|png|tif|pdf']);
                     if (!$v) {
                         $message = "Please Upload a valid image or pdf file";
                     }
                     break;
                 case 'text':
                     $v = RequestMethods::post($key);
                     break;
                 case 'date':
                     $d = RequestMethods::post($key, date('Y-m-d'));
                     $v = Db::convertType($d, 'date');
                     break;
                 default:
                     $v = '';
                     break;
             }
             if (!$v && $value['required']) {
                 return ["message" => $message, "success" => false];
             }
             $extraFields[$key] = $v;
         }
         $meta['afields'] = $extraFields;
         $user->meta = $meta;
     }
     $user->save();
     return ["success" => true];
 }
예제 #5
0
 /**
  * @before _admin
  */
 public function manage()
 {
     $this->seo(array("title" => "Manage"));
     $view = $this->getActionView();
     $page = RM::get("page", 1);
     $limit = RM::get("limit", 30);
     $query = ["type = ?" => "advertiser", "org_id = ?" => $this->org->_id];
     $property = RM::get("property", "live");
     $value = RM::get("value", 0);
     if (in_array($property, ["live", "id"])) {
         $query["{$property} = ?"] = $value;
     } else {
         if (in_array($property, ["email", "name", "phone"])) {
             $query["{$property} = ?"] = Db::convertType($value, 'regex');
         }
     }
     $advertisers = \User::all($query, ['_id', 'name', 'live', 'email', 'created'], 'created', 'desc');
     $count = \User::count($query);
     $active = \User::count(["type = ?" => "advertiser", "org_id = ?" => $this->org->_id, "live = ?" => 1]);
     $inactive = \User::count(["type = ?" => "advertiser", "org_id = ?" => $this->org->_id, "live = ?" => 0]);
     $view->set("advertisers", $advertisers)->set("property", $property)->set("value", $value)->set("active", $active)->set("inactive", $inactive)->set("count", $count)->set("limit", $limit)->set("page", $page);
 }
예제 #6
0
파일: report.php 프로젝트: vNative/vnative
 protected function _reports($table)
 {
     $view = $this->getActionView();
     $fields = Shared\Services\User::fields($table);
     $table = "\\{$table}";
     $ads = \Ad::all(['org_id' => $this->org->_id], ['_id', 'title'], 'created', 'desc');
     $affs = \User::all(['org_id' => $this->org->_id, 'type = ?' => 'publisher'], ['_id', 'name']);
     $adIds = array_keys($ads);
     $pIds = array_keys($affs);
     $searchData = $this->_searchQuery($fields, $adIds, $pIds);
     $query = $searchData['query'];
     $searching = $searchData['searching'];
     $adIds = Db::convertType($adIds);
     $pIds = Db::convertType($pIds);
     $query['adid'] = ['$in' => $adIds];
     $query['pid'] = ['$in' => $pIds];
     $query['created'] = Db::dateQuery($this->start, $this->end);
     $records = $table::all($query, [], 'created', 'desc', $this->limit, $this->page);
     $count = $table::count($query);
     $view->set(['clicks' => $records, 'fields' => $fields, 'count' => $count, 'ads' => $ads, 'query' => $searching, 'affs' => $affs]);
 }
예제 #7
0
 public static function total($dq = [], $user = null, $fields = [])
 {
     $name = __CLASS__;
     if (count($fields) === 0) {
         $fields = ['clicks', 'conversions', 'impressions', 'revenue'];
     }
     $project = ['user_id' => 1, '_id' => 0];
     $group = ['_id' => '$user_id'];
     foreach ($fields as $f) {
         $project[$f] = 1;
         $group[$f] = ['$sum' => '$' . $f];
     }
     $match = ['created' => Db::dateQuery($dq['start'], $dq['end'])];
     if (is_array($user)) {
         $keys = ArrayMethods::arrayKeys($user, '_id');
         $match['user_id'] = ['$in' => Db::convertType($keys)];
     } else {
         $match['user_id'] = Db::convertType($user->_id);
     }
     $records = Db::collection($name)->aggregate([['$match' => $match], ['$project' => $project], ['$group' => $group]]);
     $result = [];
     foreach ($records as $r) {
         $obj = Utils::toArray($r);
         $add = [];
         foreach ($fields as $f) {
             $add[$f] = $obj[$f];
         }
         ArrayMethods::add($add, $result);
     }
     return $result;
 }
예제 #8
0
 public static function performance($id, $extra = [])
 {
     $stats = [];
     $start = $end = date('Y-m-d');
     $match = ['adid' => Db::convertType($id), 'is_bot' => false];
     $user_id = $extra['pid'] ?? null;
     if ($user_id) {
         $match["pid"] = Db::convertType($user_id);
     }
     if (isset($extra['start']) && isset($extra['end'])) {
         $start = $extra['start'];
         $end = $extra['end'];
     }
     $diff = date_diff(date_create($start), date_create($end));
     $dateWise = $extra['meta'] ?? true;
     // by default datewise query
     if ($dateWise) {
         for ($i = 0; $i <= $diff->format("%a"); $i++) {
             $date = date('Y-m-d', strtotime($start . " +{$i} day"));
             $stats[$date] = ['clicks' => 0, 'meta' => []];
             $match['created'] = Db::dateQuery($date, $date);
             $records = self::_perfQuery($match, $extra);
             self::_getStats($records, $stats, $date);
         }
     } else {
         $match['created'] = Db::dateQuery($start, $end);
         $stats[$start] = ['clicks' => 0, 'meta' => []];
         $records = self::_perfQuery($match, $extra);
         self::_getStats($records, $stats, $start);
     }
     $records = self::earning($stats, $id, $user_id);
     $total = Performance::calTotal($records);
     return ['stats' => $records, 'total' => $total];
 }
예제 #9
0
파일: user.php 프로젝트: vNative/vnative
 public function delete()
 {
     $deleteList = ['Link', 'Platform', 'Ad', 'Performance', 'Invoice', 'Adaccess'];
     $query = ['user_id' => $this->_id];
     $delete = false;
     switch ($this->_type) {
         case 'publisher':
             $clicks = Click::count(['pid' => $this->_id]);
             if ($clicks !== 0) {
                 return false;
             }
             $delete = true;
             $this->removeFields();
             break;
         case 'advertiser':
             $ads = Ad::all(['user_id' => $this->_id], ['_id']);
             if (count($ads) === 0) {
                 $delete = true;
             } else {
                 $in = array_keys($ads);
                 $in = Db::convertType($in, 'id');
                 $clickCount = Click::count(['adid' => ['$in' => $in]]);
                 if ($clickCount === 0) {
                     Commission::deleteAll(['ad_id' => ['$in' => $in]]);
                     $delete = true;
                 }
             }
             break;
     }
     if ($delete) {
         parent::delete();
         foreach ($deleteList as $table) {
             $table::deleteAll($query);
         }
     }
     return $delete;
 }
예제 #10
0
 /**
  * @before _secure
  */
 public function manage()
 {
     $this->seo(['title' => 'Campaign: List', 'description' => 'Manage campaigns']);
     $view = $this->getActionView();
     $campaigns = [];
     $page = RM::get("page", 1);
     $limit = RM::get("limit", 10);
     $property = RM::get("property");
     $value = RM::get("value");
     switch (RM::get("sort")) {
         case 'trending':
             $start = RM::get("start", date("Y-m-d", strtotime('now')));
             $end = RM::get("end", date("Y-m-d", strtotime('now')));
             $q = ['start' => $start, 'end' => $end];
             $view->set($q);
             // Only find the ads for this organizations
             $allAds = \Ad::all(['org_id' => $this->org->_id], ['_id']);
             $in = Db::convertType(array_keys($allAds));
             $clickCol = Db::collection('Click');
             $match = ['created' => Db::dateQuery($start, $end), 'is_bot' => false, 'adid' => ['$in' => $in]];
             $records = $clickCol->aggregate([['$match' => $match], ['$project' => ['adid' => 1, '_id' => 0]], ['$group' => ['_id' => '$adid', 'count' => ['$sum' => 1]]], ['$sort' => ['count' => -1]], ['$limit' => (int) $limit]]);
             foreach ($records as $r) {
                 $arr = Utils::toArray($r);
                 $id = Utils::getMongoID($arr['_id']);
                 $campaigns[] = Ad::first(["id = ?" => $id]);
             }
             $count = $limit;
             break;
         default:
             $query = ["org_id = ?" => $this->org->id];
             if (in_array($property, ["user_id", "live", "id"])) {
                 $query[$property] = $value;
             } else {
                 if (in_array($property, ["url", "title"])) {
                     $query[$property] = Utils::mongoRegex(preg_quote($value));
                 }
             }
             $campaigns = \Ad::all($query, [], 'created', 'desc', $limit, $page);
             $count = \Ad::count($query);
             break;
     }
     $categories = \Category::all(['org_id' => $this->org->_id], ['_id', 'name']);
     $active = \Ad::count(["org_id = ?" => $this->org->id, "live = ?" => 1]);
     $inactive = \Ad::count(["org_id = ?" => $this->org->id, "live = ?" => 0]);
     $view->set("campaigns", $campaigns)->set("count", $count)->set("active", $active)->set("inactive", $inactive)->set("limit", $limit)->set("page", $page)->set("property", $property)->set("value", $value)->set("categories", $categories);
 }
예제 #11
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));
 }