Пример #1
0
 private function _getRandomApp()
 {
     $twoWeeksAgo = date('Y-m-d', strtotime("-5 day"));
     $recentApps = AppInfoList::model()->findAll('CommitTime > "' . $twoWeeksAgo . '" and Status = 0');
     $chance = array();
     $appScoreInfo = array();
     $appScore = array();
     $appRealLikeMax = 0;
     $appRealCommentMax = 0;
     $appDateMax = 0;
     $weight = array('like' => 30, 'comment' => 30, 'date' => 40);
     foreach ($recentApps as $app) {
         $appRealLike = count($this->_getLikedRealUser($app->Id));
         if ($appRealLike > $appRealLikeMax) {
             $appRealLikeMax = $appRealLike;
         }
         $appRealComment = count($this->_getCommentedUser($app->Id, 0));
         if ($appRealComment > $appRealCommentMax) {
             $appRealCommentMax = $appRealComment;
         }
         $commitDateArr = explode(' ', $app->CommitTime);
         $commitDate = $commitDateArr[0];
         $days = strtotime(date('Y-m-d')) - strtotime($commitDate) / 86400;
         if ($days < 1) {
             $dateScore = 50;
         } else {
             if ($days < 3) {
                 $dateScore = 30;
             } else {
                 if ($days < 7) {
                     $dateScore = 5;
                 } else {
                     $dateScore = 1;
                 }
             }
         }
         if ($dateScore > $appDateMax) {
             $appDateMax = $dateScore;
         }
         $app_detail = AppPushListDetail::model()->find(array('condition' => 'PushId=:PushId', 'params' => array(':PushId' => $app->PushId), 'order' => 'Date desc', 'limit' => 1));
         $appScoreInfo['app_' . $app->Id] = array('id' => $app->Id, 'like' => $appRealLike, 'comment' => $appRealComment, 'date' => $dateScore, 'dayscore' => $app_detail ? $app_detail->Score : 0);
     }
     foreach ($appScoreInfo as $key => $value) {
         $score = round(($this->_devide($value['like'], $appRealLikeMax) * $weight['like'] + $this->_devide($value['comment'], $appRealCommentMax) * $weight['comment'] + $this->_devide($value['date'], $appDateMax) * $weight['date']) * 0.7 + $value['dayscore'] * 0.3);
         if ($score > 0) {
             $chance = array_merge($chance, array_fill(count($chance), $score, $value['id']));
         }
     }
     return $chance ? AppInfoList::model()->findByPk($chance[array_rand($chance)]) : '';
 }
Пример #2
0
 /**
  *删除App操作
  * @throws THttpException
  */
 public function actionDelete()
 {
     if (!isset($_POST['id']) || empty($_POST['id'])) {
         // isset() 变量是否设置, empty() 变量是否为空
         throw new THttpException('勾选项不能为空');
     }
     $id = $_POST['id'];
     // $_POST['id'] 接收前台参数id
     if (!is_array($id)) {
         // is_array() 判断是否为数组
         $id = array($id);
     }
     try {
         foreach ($id as $row) {
             $modal_app = AppPushList::model()->findByPk($row);
             if (!$modal_app instanceof AppPushList) {
                 //instanceof 判断是否为某个对象
                 throw new THttpException('操作失败');
             }
             $modal_app->Status = '-1';
             if (!$modal_app->save()) {
                 // save() 保存所做改动
                 throw new Exception();
             }
             AppPushListDetail::model()->deleteAll('PushId=' . $row);
             //根据condition条件执行查询删除操作
             AppPushListReviews::model()->deleteAll('PushId=' . $row);
         }
         echo new ReturnInfo(RET_SUC, '删除成功');
     } catch (Exception $e) {
         throw new THttpException('操作失败');
     }
 }
Пример #3
0
 /**
  * 删除App操作
  * @throws THttpException
  */
 public function actionDelete()
 {
     if (!isset($_POST['id']) || empty($_POST['id'])) {
         throw new THttpException('勾选项不能为空');
     }
     $id = $_POST['id'];
     if (!is_array($id)) {
         $id = array($id);
     }
     try {
         foreach ($id as $row) {
             $models_app = AppPushList::model()->findByPk($row);
             if (!$models_app instanceof AppPushList) {
                 throw new THttpException('操作失败');
             }
             $models_app->Status = '-1';
             if (!$models_app->save()) {
                 throw new Exception();
             }
             AppPushListReviews::model()->deleteAll('PushId=' . $row);
             AppPushListDetail::model()->find('PushId=' . $row)->delete();
         }
         echo new ReturnInfo(RET_SUC, '删除成功');
     } catch (Exception $e) {
         throw new THttpException('操作失败');
     }
 }