===== PART 9/12 ===== t = $this->Links->Statistics->find() ->where([ 'Statistics.user_id' => $link->user_id, 'Statistics.reason' => 1, 'Statistics.created BETWEEN :startOfDay AND :endOfDay', ]) ->bind(':startOfDay', $startOfDay, 'datetime') ->bind(':endOfDay', $endOfDay, 'datetime') ->count(); if ($daily_count >= $views_daily_limit) { // Update link hits $this->updateLinkHits($link); $this->addNormalStatisticEntry($link, $ad_type, $data, $cookie['ip'], 16); $content = [ 'status' => 'success', //'message' => 'Go without Earn, reached the daily limit', 'message' => '', 'url' => $link->url, ]; return $content; } } $views_monthly_limit = (int)$link_user_plan->views_monthly_limit; if ($views_monthly_limit > 0) { $time_zone = get_option('timezone', 'UTC'); // Convert to UTC for database query $startOfMonth = Time::now($time_zone)->startOfMonth()->i18nFormat('yyyy-MM-dd HH:mm:ss', 'UTC', 'en'); $endOfMonth = Time::now($time_zone)->endOfMonth()->i18nFormat('yyyy-MM-dd HH:mm:ss', 'UTC', 'en'); $monthly_count = $this->Links->Statistics->find() ->where([ 'Statistics.user_id' => $link->user_id, 'Statistics.reason' => 1, 'Statistics.created BETWEEN :startOfMonth AND :endOfMonth', ]) ->bind(':startOfMonth', $startOfMonth, 'datetime') ->bind(':endOfMonth', $endOfMonth, 'datetime') ->count(); if ($monthly_count >= $views_monthly_limit) { // Update link hits $this->updateLinkHits($link); $this->addNormalStatisticEntry($link, $ad_type, $data, $cookie['ip'], 17); $content = [ 'status' => 'success', //'message' => 'Go without Earn, reached the monthly limit', 'message' => '', 'url' => $link->url, ]; return $content; } } /** * Check for unique visit within last 24 hour */ $time_zone = get_option('timezone', 'UTC'); // Convert to UTC for database query $startOfToday = Time::now($time_zone)->startOfDay()->i18nFormat('yyyy-MM-dd HH:mm:ss', 'UTC', 'en'); $endOfToday = Time::now($time_zone)->endOfDay()->i18nFormat('yyyy-MM-dd HH:mm:ss', 'UTC', 'en'); $unique_where = [ 'Statistics.ip' => $cookie['ip'], 'Statistics.publisher_earn >' => 0, 'Statistics.created BETWEEN :startOfToday AND :endOfToday', ]; if ($data['mode'] === 'campaign') { if (get_option('unique_visitor_per', 'campaign') == 'campaign') { $unique_where['Statistics.campaign_id'] = $data['ci']; } } $statistics = $this->Links->Statistics->find() ->where($unique_where) ->bind(':startOfToday', $startOfToday, 'datetime') ->bind(':endOfToday', $endOfToday, 'datetime') ->count(); if ($statistics >= get_option('paid_views_day', 1)) { // Update link hits $this->updateLinkHits($link); $this->addNormalStatisticEntry($link, $ad_type, $data, $cookie['ip'], 7); $content = [ 'status' => 'success', //'message' => 'Go without Earn because Not unique.', 'message' => '', 'url' => $link->url, ]; return $content; } /** * Add statistic record */ $owner_earn = 0; if ($data['mode'] === 'campaign') { $owner_earn = ($data['advertiser_price'] - $data['publisher_price']) / 1000; } $publisher_earn = $data['publisher_price'] / 1000; if (!empty($link_user_plan->cpm_fixed)) { $publisher_earn = $link_user_plan->cpm_fixed / 1000; } $user_update = $this->Links->Users->find()->where(['Users.id' => $link->user_id])->first(); $publisher_user_earnings = true; if ($this->Auth->user()) { if (get_user_plan($this->Auth->user('id'))->disable_ads) { $publisher_user_earnings = false; } } if ($publisher_user_earnings) { $user_update->publisher_earnings = price_database_format($user_update->publisher_earnings + $publisher_earn); $this->Links->Users->save($user_update); } $referral_id = $referral_earn = 0; $enable_referrals = (bool)get_option('enable_referrals', 1); if ($enable_referrals && $publisher_user_earnings && !empty($user_update->referred_by)) { $user_referred_by = $this->Links->Users->find() ->where([ 'Users.id' => $user_update->referred_by, 'Users.status' => 1, 'Users.disable_earnings' => 0, ]) ->first(); if ($user_referred_by) { $plan_referral = true; if (!get_user_plan($user_referred_by->id)->referral) { $plan_referral = false; } if (!(float)get_user_plan($user_referred_by->id)->referral_percentage) { $plan_referral = false; } if ($plan_referral) { $referral_percentage = ((float)get_user_plan($user_referred_by->id)->referral_percentage) / 100; $referral_value = $publisher_earn * $referral_percentage;