Esempio n. 1
0
 public static function statSceneDay($date)
 {
     U::W(__METHOD__ . " BEGIN");
     $tableName = MSceneDay::tableName();
     $ghs = MGh::find()->all();
     foreach ($ghs as $gh) {
         foreach ($gh->staffs as $staff) {
             if ($staff->scene_id != 0) {
                 $score = MAccessLog::getScoreByRange($gh->gh_id, $staff->scene_id, $date, $date);
                 if ($score != 0) {
                     Yii::$app->db->createCommand("INSERT INTO {$tableName} (gh_id,create_date,scene_id,score) VALUES (:gh_id,:create_date,:scene_id,:score)", [':gh_id' => $gh->gh_id, ':create_date' => $date, ':scene_id' => $staff->scene_id, ':score' => $score])->execute();
                 }
             }
         }
         // for the fan without anyboby's recommend
         $staff = new MStaff();
         $staff->scene_id = 0;
         $score = MAccessLog::getScoreByRange($gh->gh_id, $staff->scene_id, $date, $date);
         if ($score != 0) {
             Yii::$app->db->createCommand("INSERT INTO {$tableName} (gh_id,create_date,scene_id,score) VALUES (:gh_id,:create_date,:scene_id,:score)", [':gh_id' => $gh->gh_id, ':create_date' => $date, ':scene_id' => $staff->scene_id, ':score' => $score])->execute();
         }
     }
     U::W(__METHOD__ . " END");
     return;
     /*
      $tableName = MAccessLog::tableName();
      $n = Yii::$app->db->createCommand("DELETE FROM $tableName WHERE create_time < DATE_SUB(NOW(), INTERVAL 90 day)")->execute();
      U::W("DELETE $tableName, $n");
     
      $tableName = MAccessLogAll::tableName();
      $n = Yii::$app->db->createCommand("DELETE FROM $tableName WHERE create_time < DATE_SUB(NOW(), INTERVAL 180 day)")->execute();
      U::W("DELETE $tableName, $n");
     */
 }