当前位置: 首页>>代码示例>>PHP>>正文


PHP Ad::earning方法代码示例

本文整理汇总了PHP中Ad::earning方法的典型用法代码示例。如果您正苦于以下问题:PHP Ad::earning方法的具体用法?PHP Ad::earning怎么用?PHP Ad::earning使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Ad的用法示例。


在下文中一共展示了Ad::earning方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: earning

 public static function earning($stats = [], $adid, $user_id = null)
 {
     $records = [];
     foreach ($stats as $date => $r) {
         $commissions = [];
         $meta = $r['meta'] ?? [];
         if (array_key_exists("country", $meta)) {
             $countryWise = $meta["country"] ?? [];
             foreach ($countryWise as $country => $clicks) {
                 $extra = ['type' => 'both', 'start' => $date, 'end' => $date];
                 if ($user_id) {
                     $extra['publisher'] = \User::first(['_id' => $user_id]);
                 }
                 $comm = \Commission::campaignRate($adid, $commissions, $country, $extra);
                 $earning = \Ad::earning($comm, $clicks);
                 ArrayMethods::add($earning, $r);
             }
         }
         $records[$date] = $r;
     }
     return $records;
 }
开发者ID:vNative,项目名称:vnative,代码行数:22,代码来源:campaign.php

示例2: livePerf

 public static function livePerf($user, $s = null, $e = null)
 {
     $start = $end = date('Y-m-d');
     $type = $user->type ?? '';
     if ($s) {
         $start = $s;
     }
     if ($e) {
         $end = $e;
     }
     $perf = new \Performance();
     $match = ['is_bot' => false, 'created' => Db::dateQuery($start, $end)];
     switch ($user->type) {
         case 'publisher':
             $match['pid'] = Db::convertType($user->_id);
             break;
         case 'advertiser':
             $ads = \Ad::all(['user_id' => $user->_id], ['_id']);
             $keys = array_keys($ads);
             $match['adid'] = ['$in' => Db::convertType($keys)];
             break;
         default:
             return $perf;
     }
     $results = $commissions = [];
     $records = self::_livePerfQuery($match);
     foreach ($records as $r) {
         $obj = Utils::toArray($r);
         $adid = Utils::getMongoID($obj['_id']);
         $results[$adid] = $obj;
     }
     $comms = Db::query('Commission', ['ad_id' => ['$in' => array_keys($results)]], ['ad_id', 'rate', 'revenue', 'model', 'coverage']);
     $comms = \Click::classify($comms, 'ad_id');
     foreach ($comms as $adid => $value) {
         $value = array_map(function ($v) {
             $v["ad_id"] = Utils::getMongoID($v["ad_id"]);
             unset($v["_id"]);
             return (object) $v;
         }, Utils::toArray($value));
         $commissions[$adid] = \Commission::filter($value);
     }
     foreach ($results as $adid => $obj) {
         $comms = $commissions[$adid];
         foreach ($obj['countries'] as $value) {
             $country = $value['country'];
             $clicks = $value['count'];
             $commission = \Commission::campaignRate($adid, $comms, $country, ['type' => $type, "{$type}" => $user, 'start' => $start, 'end' => $end, 'commFetched' => true]);
             $updateData = [];
             $earning = \Ad::earning($commission, $clicks);
             AM::copy($earning, $updateData);
             $perf->update($updateData);
         }
     }
     return $perf;
 }
开发者ID:vNative,项目名称:vnative,代码行数:55,代码来源:user.php

示例3: perf

 protected function perf($clicks, $arr, $dq = [])
 {
     $perf = new Performance();
     $commissions = [];
     $classify = \Click::classify($clicks, 'adid');
     foreach ($classify as $key => $value) {
         $countryWise = \Click::classify($value, 'country');
         foreach ($countryWise as $country => $records) {
             $adClicks = count($records);
             $updateData = [];
             $extra = array_merge($arr, $dq);
             $info = \Commission::campaignRate($key, $commissions, $country, $extra);
             $earning = \Ad::earning($info, $adClicks);
             \Framework\ArrayMethods::copy($earning, $updateData);
             $perf->update($updateData);
         }
     }
     return $perf;
 }
开发者ID:vNative,项目名称:vnative,代码行数:19,代码来源:auth.php

示例4: _performance

 protected function _performance($date = null)
 {
     if (!$date) {
         $date = date('Y-m-d', strtotime('-1 day'));
     }
     $date = date('Y-m-d', strtotime('-1 day'));
     // find the publishers
     $publishers = \User::all(['type = ?' => 'publisher', 'live = ?' => true], ['_id', 'email', 'meta', 'org_id']);
     $dq = ['start' => $date, 'end' => $date];
     $dateQuery = Utils::dateQuery($dq);
     $start = $dateQuery['start'];
     $end = $dateQuery['end'];
     // store AD commission info
     $commInfo = [];
     $orgs = [];
     $advPerfs = [];
     $advertisers = [];
     $adsInfo = [];
     foreach ($publishers as $p) {
         $org = \Organization::find($orgs, $p->org_id);
         // find the clicks for the publisher
         $clicks = Db::query('Click', ['pid' => $p->_id, 'is_bot' => false, 'created' => Db::dateQuery($date, $date)], ['adid', 'country', 'device', 'os', 'referer']);
         $perf = Performance::exists($p, $date);
         // classify the clicks according to AD ID
         $classify = \Click::classify($clicks, 'adid');
         $countryWise = $deviceWise = $osWise = $refWise = [];
         foreach ($classify as $key => $value) {
             $ad = \Ad::find($adsInfo, $key, ['user_id', 'url']);
             $advert = Usr::find($advertisers, $ad->user_id, ['_id', 'meta', 'email', 'org_id']);
             $advertPerf = Usr::findPerf($advPerfs, $advert, $date);
             $countries = \Click::classify($value, 'country');
             foreach ($countries as $country => $records) {
                 $updateData = [];
                 $adClicks = count($records);
                 ArrayMethods::counter($countryWise, $country, $adClicks);
                 $pComm = \Commission::campaignRate($key, $commInfo, $country, array_merge(['type' => 'both', 'publisher' => $p], $dq));
                 $earning = \Ad::earning($pComm, $adClicks);
                 ArrayMethods::copy($earning, $updateData);
                 $updateData['profit'] = $updateData['revenue'] - $updateData['payout'];
                 $updateData['revenue'] = $updateData['payout'];
                 $perf->update($updateData);
                 $aComm = \Commission::campaignRate($key, $commInfo, $country, array_merge(['type' => 'advertiser'], $dq));
                 $updateData = [];
                 $earning = \Ad::earning($aComm, $adClicks);
                 ArrayMethods::copy($earning, $updateData);
                 $advertPerf->update($updateData);
             }
             $deviceWise = Click::classifyInfo(['clicks' => $value, 'type' => 'device', 'arr' => $deviceWise]);
             $osWise = Click::classifyInfo(['clicks' => $value, 'type' => 'os', 'arr' => $osWise]);
             $refWise = Click::classifyInfo(['clicks' => $value, 'type' => 'referer', 'arr' => $refWise]);
         }
         $msg = 'Performance saved for user: ' . $p->email . ' with clicks: ' . $perf->clicks . ' impressions: ' . $perf->impressions;
         $this->log($msg);
         $splitCountry = ArrayMethods::topValues($countryWise);
         $splitCountry['rest'] = array_sum($countryWise) - array_sum($splitCountry);
         $meta = ['country' => $splitCountry, 'device' => ArrayMethods::topValues($deviceWise, count($deviceWise)), 'os' => ArrayMethods::topValues($osWise, count($osWise)), 'referer' => ArrayMethods::topValues($refWise, count($refWise))];
         $perf->meta = $meta;
         $perf->save();
     }
     foreach ($advPerfs as $key => $perf) {
         $msg = 'Saving performance for advertiser: ' . $key . ' with clicks: ' . $perf->clicks . ' earning: ' . $perf->revenue . ' impressions: ' . $perf->impressions;
         $this->log($msg);
         $perf->save();
     }
 }
开发者ID:vNative,项目名称:vnative,代码行数:65,代码来源:cron.php


注:本文中的Ad::earning方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。