EventlogController.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. if(Yii::$app->user->isGuest)
  33. {
  34. return $this->redirect('/user/login');
  35. }
  36. if(!Yii::$app->user->can("admin"))
  37. {
  38. return $this->redirect('/site/index');
  39. }
  40. }
  41. public function actionIndex()
  42. {
  43. $searchModel = new EventlogSearch();
  44. $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
  45. //print_r($dataProvider); die();
  46. return $this->render('index', [
  47. 'searchModel' => $searchModel,
  48. 'dataProvider' => $dataProvider,
  49. ]);
  50. }
  51. /**
  52. * Displays a single Eventlog model.
  53. * @param integer $id
  54. * @return mixed
  55. */
  56. public function actionView($id)
  57. {
  58. return $this->render('view', [
  59. 'model' => $this->findModel($id),
  60. ]);
  61. }
  62. /**
  63. * Creates a new Eventlog model.
  64. * If creation is successful, the browser will be redirected to the 'view' page.
  65. * @return mixed
  66. */
  67. public function actionCreate()
  68. {
  69. $model = new Eventlog();
  70. if ($model->load(Yii::$app->request->post()) && $model->save()) {
  71. return $this->redirect(['view', 'id' => $model->id]);
  72. } else {
  73. return $this->render('create', [
  74. 'model' => $model,
  75. ]);
  76. }
  77. }
  78. /**
  79. * Updates an existing Eventlog model.
  80. * If update is successful, the browser will be redirected to the 'view' page.
  81. * @param integer $id
  82. * @return mixed
  83. */
  84. public function actionUpdate($id)
  85. {
  86. $model = $this->findModel($id);
  87. if ($model->load(Yii::$app->request->post()) && $model->save()) {
  88. return $this->redirect(['view', 'id' => $model->id]);
  89. } else {
  90. return $this->render('update', [
  91. 'model' => $model,
  92. ]);
  93. }
  94. }
  95. public function actionTradelog($id,$user_id)
  96. {
  97. $query = Yii::$app->db->createCommand('SELECT * FROM trade_logs WHERE auk_id=:id AND user_id=:user_id');
  98. $query->bindValues([':id' => $id, ':user_id' => $user_id]);
  99. $result = $query->queryAll();
  100. $filename = "../uploads/temp/tradelog-".$id.$user_id.date('Ymdhis').".doc";
  101. $file = fopen($filename,'w+');
  102. foreach ($result as $item => $value)
  103. {
  104. fputs($file,$value['date']." ".$value['comment']."\n");
  105. }
  106. fclose($file);
  107. Yii::$app->response->xSendFile($filename);
  108. }
  109. /**
  110. * Deletes an existing Eventlog model.
  111. * If deletion is successful, the browser will be redirected to the 'index' page.
  112. * @param integer $id
  113. * @return mixed
  114. */
  115. public function actionDelete($id)
  116. {
  117. $this->findModel($id)->delete();
  118. return $this->redirect(['index']);
  119. }
  120. /**
  121. * Finds the Eventlog model based on its primary key value.
  122. * If the model is not found, a 404 HTTP exception will be thrown.
  123. * @param integer $id
  124. * @return Eventlog the loaded model
  125. * @throws NotFoundHttpException if the model cannot be found
  126. */
  127. protected function findModel($id)
  128. {
  129. if (($model = Eventlog::findOne($id)) !== null) {
  130. return $model;
  131. } else {
  132. throw new NotFoundHttpException('The requested page does not exist.');
  133. }
  134. }
  135. }