TmcController.php 898 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace app\controllers;
  3. use Yii;
  4. use app\models\entity\Tmc;
  5. /** Created by Anton on 17.02.2020. */
  6. class TmcController extends MainController
  7. {
  8. public function beforeAction($action)
  9. {
  10. parent::beforeAction($action);
  11. // $key = Yii::$app->request->headers->get('uuid-key');
  12. // $this->checkAuth($key);
  13. \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
  14. return true;
  15. }
  16. public function actionGive()
  17. {
  18. $userId = Yii::$app->request->post('userId');
  19. $tmc = Tmc::findOne(['employee' => $userId]);
  20. if (!$tmc) {
  21. $result = ['error' => 'Устройство не найдено'];
  22. } else {
  23. $result = ['success' => $tmc->characteristic];
  24. }
  25. $buf = pack("Cl", null, $result);
  26. echo base64_encode($buf);
  27. }
  28. }