Ejemplo n.º 1
0
 public function actionIndex()
 {
     if (Yii::app()->user->isGuest) {
         $this->redirect('site/login');
     } else {
         $average = 0;
         $today_total = 0;
         $date = date('Y-m-d H:i:s', strtotime('-1 week'));
         $user_data = array();
         $app_id = Yii::app()->request->getParam('app_id', false);
         $criteria = new CDbCriteria();
         if ($app_id) {
             $criteria->condition = 'app_id =:app_id and ctime >=:date';
             $criteria->params = array(':app_id' => $app_id, ':date' => $date . ' 00:00:00');
         } else {
             $criteria->condition = 'ctime >=:date';
             $criteria->params = array(':date' => $date . ' 00:00:00');
         }
         $total = DreamDeviceUuid::model()->count($criteria);
         $criteria->select = 'count(*) as device_id,app_id,DATE(ctime) as ctime';
         $criteria->group = 'DATE(ctime)';
         $details = DreamDeviceUuid::model()->findAll($criteria);
         foreach ($details as $key => $detail) {
             $user_data[$key][] = strtotime($detail->ctime . 'UTC') * 1000;
             $user_data[$key][] = $detail->device_id;
             if ($key + 1 == count($details)) {
                 $today_total = $detail->device_id;
             }
         }
         $average = round($total / 7);
         $this->render('index', array('total' => $total, 'app_id' => $app_id, 'user_data' => $user_data, 'average' => $average, 'today_total' => $today_total));
     }
 }
Ejemplo n.º 2
0
 public static function getBaiduAd($uuid, $imei, $ad_list)
 {
     if (!$imei) {
         if ($uuid) {
             $user_info = DreamDeviceUuid::model()->find('uuid =:uuid', array(':uuid' => $uuid));
             if ($user_info) {
                 $device_id = $user_info->device_id;
                 $device_info = DreamDevice::model()->find('id =:id', array(':id' => $device_id));
                 $imei = isset($device_info->imei) ? $device_info->imei : false;
             }
         }
     }
     if ($imei) {
         $host = 'http://m.baidu.com/api?';
         $api_key = 'cea6fbb9e862233e3dbe6fcc6cad3bcf';
         $param = array();
         $param['action'] = 'board';
         $param['from'] = '1014104g';
         $param['token'] = 'wifi_check';
         $param['api_key'] = $api_key;
         $param['imei'] = $imei;
         $param['type'] = 'app';
         $param['id'] = 2;
         $param['pn'] = 0;
         $param['rn'] = 60;
         $param['apilevel'] = 19;
         $param['dpi'] = '720_1280';
         $param['format'] = 'json';
         $snoopy = new Snoopy();
         $snoopy->fetch($host . http_build_query($param));
         $ad_info = json_decode($snoopy->results, true);
         if ($ad_info) {
             $num = count($ad_list);
             foreach ($ad_info['result']['apps'] as $value) {
                 if ($value['sname'] != '百度手机卫士') {
                     $download = $value['download_url'];
                     if (strpos($download, 'source+MBUADP')) {
                         $screen_shots = explode(';', $value['screenshot']);
                         $ad_list[$num]['app_name'] = $value['sname'];
                         $ad_list[$num]['type'] = 'baidu';
                         $brief = $value['manual_brief'] ? $value['manual_brief'] : $value['sname'];
                         $ad_list[$num]['title'] = $brief;
                         $ad_list[$num]['content'] = $value['manual_short_brief'] ? $value['manual_short_brief'] : $brief;
                         $ad_list[$num]['package_name'] = $value['package'];
                         $ad_list[$num]['icon_url'] = $value['icon'];
                         $ad_list[$num]['cover_url'] = $screen_shots[0];
                         $ad_list[$num]['download_url'] = $value['download_url'] . '&imei=' . $imei . '&api_key=' . $api_key;
                         $num++;
                     }
                 }
             }
         }
         shuffle($ad_list);
     }
     return $ad_list;
 }
Ejemplo n.º 3
0
 public function run()
 {
     Yii::trace(get_class($this) . '.run()');
     $controller = parent::run();
     $json = isset($this->request->json) ? $this->request->json : false;
     $app_code = isset($this->request->appCode) ? $this->request->appCode : false;
     if ($json && $app_code) {
         $uuid = false;
         $sn = isset($json->sn) ? $json->sn : false;
         $imei = isset($json->imei) ? $json->imei : false;
         $imei2 = isset($json->imei2) ? $json->imei2 : false;
         $wifimac = isset($json->wifimac) ? $json->wifimac : false;
         if ($sn || $imei || $imei2 || $wifimac) {
             $criteria = new CDbCriteria();
             $criteria->condition = 'sn =:sn and imei =:imei and imei2 =:imei2 and wifimac =:wifimac';
             $criteria->params = array(':sn' => $sn, ':imei' => $imei, ':imei2' => $imei2, ':wifimac' => $wifimac);
             $device_info = DreamDevice::model()->find($criteria);
             if ($device_info) {
                 $uuid_info = DreamDeviceUuid::model()->find('device_id =:device_id', array(':device_id' => $device_info->id));
                 if ($uuid_info) {
                     $uuid = $uuid_info->uuid;
                 } else {
                     $uuid = DreamDeviceUuid::model()->createUuid($app_code, $device_info->id);
                 }
             } else {
                 $device_info = new DreamDevice();
                 $device_info->sn = $sn;
                 $device_info->imei = $imei;
                 $device_info->imei2 = $imei2;
                 $device_info->wifimac = $wifimac;
                 $device_info->setIsNewRecord(true);
                 if ($device_info->save(false)) {
                     $uuid = DreamDeviceUuid::model()->createUuid($app_code, $device_info->id);
                 }
             }
             if ($uuid) {
                 return $this->response->uuid = $uuid;
             } else {
                 return $this->response->code = 404;
             }
         }
     }
     return $this->response->code = 500;
 }