Example #1
0
 public function actionInsertFileRecord()
 {
     $file_id = '56e009bee8a711f465b7acd9';
     $user_id = '72eb5a63e3a3584271d0cfc09beaf736';
     $start_time = '2015-01-01 00:00:00';
     $end_time = '2016-03-09 00:00:00';
     for ($i = 1001; $i < 1500; $i++) {
         $date = $this->rand_time($start_time, $end_time);
         $file = new FileRecord();
         $file->f_record_id = md5($user_id . $date . $i);
         $file->f_record_type = '1';
         $file->file_id = $file_id;
         $file->user_id = $user_id;
         $file->file_name = 'testData';
         $file->extension = 'mp3';
         $file->file_type = 'audio/mp3';
         $file->file_size = 445746179;
         $file->parent_id = $user_id;
         $file->upload_date = $date;
         $file->state = '1';
         $file->save();
         $removeLog = new RemoveLog();
         $removeLog->f_record_id = $file->f_record_id;
         $removeLog->remove_date = $date;
         $removeLog->save();
     }
     echo date('Y-m-d H:i:s');
 }
Example #2
0
 public function removeLog($recordId)
 {
     $removeLog = new RemoveLog();
     $removeLog->f_record_id = $recordId;
     $removeLog->remove_date = date('Y-m-d H:i:s');
     if ($removeLog->save()) {
         return 'success';
     } else {
         return 'error';
     }
 }
Example #3
0
 public function revertFiles($files, $userId)
 {
     $tran = \Yii::$app->db->beginTransaction();
     try {
         foreach ($files as $recordId) {
             $fileRecord = FileRecord::findOne(['f_record_id' => $recordId]);
             $disk = Disk::findOne(['user_id' => $userId]);
             if ($disk->available_size < $fileRecord->file_size) {
                 $tran->rollBack();
                 return '2';
                 //空间不足
             }
             $fileRecord->state = '0';
             $fileRecord->parent_id = $userId;
             if (!$fileRecord->save()) {
                 $tran->rollBack();
                 return '1';
                 //还原错误
             }
             $disk->available_size = $disk->available_size - $fileRecord->file_size;
             if (!$disk->save()) {
                 $tran->rollBack();
                 return '1';
                 //还原错误
             }
             $removeLog = RemoveLog::findOne(['f_record_id' => $fileRecord->f_record_id]);
             if (!$removeLog->delete()) {
                 $tran->rollBack();
                 return '1';
                 //还原错误
             }
         }
         $tran->commit();
         return '0';
     } catch (Exception $e) {
         $tran->rollBack();
         return '1';
     }
 }