Subversion Repositories SmartDukaan

Rev

Rev 17022 | Rev 17127 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
13532 anikendra 1
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * Administration Controller
5
 *
6
 * @property Administration $Administration
7
 * @property PaginatorComponent $Paginator
8
 */
9
class AdministrationController extends AppController {
10
 
11
/**
12
 * Components
13
 *
14
 * @var array
15
 */
16
	public $components = array('Paginator');
17
 
18
	public function beforeFilter() {
19
    	parent::beforeFilter();
20
    	$this->layout = 'admin';
21
    }
22
 
23
	public function dashboard(){
15077 anikendra 24
		$this->loadModel('User');
25
		//daily userbase
17023 manas 26
		$sql = "SELECT count(User.id) AS count,date(User.activation_time) AS date FROM users User WHERE datediff(now(),activation_time) <= 30 AND activated = 1 GROUP BY date(activation_time) ORDER BY User.activation_time DESC";
15077 anikendra 27
		$userbase = $this->User->query($sql);
15721 anikendra 28
		$sql = "SELECT count(Click.id) AS count,date(created) AS date FROM clicks Click WHERE datediff(now(),created) <= 30 AND extras NOT LIKE '%notification%'GROUP BY date(created) ORDER BY id DESC";
15077 anikendra 29
		$clicks = $this->User->query($sql);
30
		$this->set(compact('userbase','clicks'));
31
		$sql = "SELECT count(id) AS count,date(created) AS date FROM orders WHERE datediff(now(),created) <= 30 AND status = 'ORDER_CREATED' GROUP BY date(created) ORDER BY id DESC";
32
		$orders = $this->User->query($sql);		
15607 anikendra 33
		// $sql = "select count(id) AS count,versioncode from devices group by versioncode";
34
		$sql = "SELECT COUNT( * ) AS count, a.c AS versioncode FROM (SELECT MAX( versioncode ) c, user_id FROM devices GROUP BY user_id) a GROUP BY a.c";
15077 anikendra 35
		$devices = $this->User->query($sql);
15093 anikendra 36
		$sql = "SELECT count(distinct user_id) AS count,date(created) AS date FROM `brand_preferences` WHERE datediff(now(),created) <= 30 group by date(created) order by id desc";
15128 anikendra 37
		$preferences_set = $this->User->query($sql);		
38
		$sql = "select count(distinct user_id) AS count from brand_preferences";
39
		$usersWithBrandPreferencesSet = $this->User->query($sql);
40
		$sql = "select count(id) AS count from users";
15188 anikendra 41
		$totalUsers = $this->User->query($sql);		
16013 anikendra 42
		$sql = "SELECT DATE( created ) AS date, COUNT( DISTINCT (user_id) ) AS count FROM user_urls WHERE ( created ) > CURDATE( ) - INTERVAL 30 DAY GROUP BY date order by id desc";
16220 anikendra 43
		$activeUsers = $this->User->query($sql);		
44
		$sql = "select date(created) date, count(distinct user_id) count from (select id,user_id, created from orders union all select id,user_id, created from flipkartorders) a where date(created) > curdate() - interval 30 day group by date order by date desc";
15654 anikendra 45
		$activeBuyers = $this->User->query($sql);
16220 anikendra 46
		ksort($activeBuyers);
15670 manas 47
		$sql = "SELECT count(id) as count,date(mobile_number_last_updated) as date from users where mobile_verified=1 and datediff(now(),mobile_number_last_updated) <= 30 group by date(mobile_number_last_updated) ORDER BY date(mobile_number_last_updated) desc";
48
		$dailyVerifications = $this->User->query($sql);
16855 manas 49
		$sql="SELECT date(transaction_time) AS date,COUNT(*) AS count, (COUNT(CASE payout_description WHEN 'Approved' THEN 1 END)) as approved FROM app_transactions where datediff(now(),transaction_time) <= 30 group by date(transaction_time) order by date(transaction_time) desc";
50
		$app_transactions_clicks_approved = $this->User->query($sql);
51
		$sql="SELECT x.date,round(((x.approved/x.count)*100),2) as conversion from (SELECT date(transaction_time) AS date,COUNT(*) AS count, (COUNT(CASE payout_description WHEN 'Approved' THEN 1 END)) as approved FROM app_transactions where datediff(now(),transaction_time) <= 30 group by date(transaction_time) order by date(transaction_time) desc) as x ";
52
		$app_transactions_percentage = $this->User->query($sql);
16945 anikendra 53
		$sql="select date(at.transaction_time) AS date, at.app_name,at.app_id, count(*) AS count from  (select app_id from app_transactions where datediff(curdate(),date(transaction_time))<30 group by app_id order by count(1) desc limit 5)a join app_transactions at on a.app_id = at.app_id group by date(at.transaction_time), at.app_id order by date(at.transaction_time)";
54
		$top_five_apps = $this->User->query($sql);		
55
		if(!empty($top_five_apps)){
56
			foreach ($top_five_apps as $key => $app) {
57
				$apps[$app['at']['app_id']] = $app['at']['app_name'];
58
				$appinstalls[$app[0]['date']][$app['at']['app_id']] = $app[0]['count'];
59
			}
16855 manas 60
		}
16945 anikendra 61
		$this->set(compact('userbase','clicks','orders','devices','preferences_set','usersWithBrandPreferencesSet','totalUsers','activeUsers','activeBuyers','dailyVerifications','app_transactions_clicks_approved','app_transactions_percentage','top_five_apps','apps','appinstalls'));
62
	}
63
}