EventlogController.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. namespace app\controllers;
  3. use app\models\Trade;
  4. use Yii;
  5. use app\models\Eventlog;
  6. use app\models\EventlogSearch;
  7. use yii\web\Controller;
  8. use yii\web\NotFoundHttpException;
  9. use yii\filters\VerbFilter;
  10. /**
  11. * EventlogController implements the CRUD actions for Eventlog model.
  12. */
  13. class EventlogController extends Controller
  14. {
  15. public function behaviors()
  16. {
  17. return [
  18. 'verbs' => [
  19. 'class' => VerbFilter::className(),
  20. 'actions' => [
  21. 'delete' => ['post'],
  22. ],
  23. ],
  24. ];
  25. }
  26. /**
  27. * Lists all Eventlog models.
  28. * @return mixed
  29. */
  30. public function init()
  31. {
  32. parent::init();
  33. if(Yii::$app->user->isGuest)
  34. {
  35. return $this->redirect('/user/login');
  36. }
  37. if(!Yii::$app->user->can("admin"))
  38. {
  39. return $this->redirect('/site/index');
  40. }
  41. }
  42. public function actionIndex()
  43. {
  44. $searchModel = new EventlogSearch();
  45. $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
  46. //print_r($dataProvider); die();
  47. return $this->render('index', [
  48. 'searchModel' => $searchModel,
  49. 'dataProvider' => $dataProvider,
  50. ]);
  51. }
  52. /**
  53. * Displays a single Eventlog model.
  54. * @param integer $id
  55. * @return mixed
  56. */
  57. public function actionView($id)
  58. {
  59. return $this->render('view', [
  60. 'model' => $this->findModel($id),
  61. ]);
  62. }
  63. /**
  64. * Creates a new Eventlog model.
  65. * If creation is successful, the browser will be redirected to the 'view' page.
  66. * @return mixed
  67. */
  68. public function actionCreate()
  69. {
  70. $model = new Eventlog();
  71. if ($model->load(Yii::$app->request->post()) && $model->save()) {
  72. return $this->redirect(['view', 'id' => $model->id]);
  73. } else {
  74. return $this->render('create', [
  75. 'model' => $model,
  76. ]);
  77. }
  78. }
  79. /**
  80. * Updates an existing Eventlog model.
  81. * If update is successful, the browser will be redirected to the 'view' page.
  82. * @param integer $id
  83. * @return mixed
  84. */
  85. public function actionUpdate($id)
  86. {
  87. $model = $this->findModel($id);
  88. if ($model->load(Yii::$app->request->post()) && $model->save()) {
  89. return $this->redirect(['view', 'id' => $model->id]);
  90. } else {
  91. return $this->render('update', [
  92. 'model' => $model,
  93. ]);
  94. }
  95. }
  96. public function actionTradelog($id,$user_id)
  97. {
  98. $query = Yii::$app->db->createCommand('SELECT * FROM trade_logs WHERE auk_id=:id AND user_id=:user_id');
  99. $query->bindValues([':id' => $id, ':user_id' => $user_id]);
  100. $result = $query->queryAll();
  101. $filename = "../uploads/temp/tradelog-".$id.$user_id.date('Ymdhis').".doc";
  102. $file = fopen($filename,'w+');
  103. foreach ($result as $item => $value)
  104. {
  105. fputs($file,$value['date']." ".$value['comment']."\n");
  106. }
  107. fclose($file);
  108. Yii::$app->response->xSendFile($filename);
  109. }
  110. /**
  111. * Deletes an existing Eventlog model.
  112. * If deletion is successful, the browser will be redirected to the 'index' page.
  113. * @param integer $id
  114. * @return mixed
  115. */
  116. public function actionDelete($id)
  117. {
  118. $this->findModel($id)->delete();
  119. return $this->redirect(['index']);
  120. }
  121. /**
  122. * Finds the Eventlog model based on its primary key value.
  123. * If the model is not found, a 404 HTTP exception will be thrown.
  124. * @param integer $id
  125. * @return Eventlog the loaded model
  126. * @throws NotFoundHttpException if the model cannot be found
  127. */
  128. protected function findModel($id)
  129. {
  130. if (($model = Eventlog::findOne($id)) !== null) {
  131. return $model;
  132. } else {
  133. throw new NotFoundHttpException('The requested page does not exist.');
  134. }
  135. }
  136. }