AuthController.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace addons\RfDevTool\backend\controllers;
  3. use Yii;
  4. use common\helpers\ExcelHelper;
  5. use addons\RfDevTool\common\helpers\ImportHelper;
  6. /**
  7. * Class AuthController
  8. * @package addons\RfDevTool\backend\controllers
  9. * @author jianyan74 <751393839@qq.com>
  10. */
  11. class AuthController extends BaseController
  12. {
  13. /**
  14. * @return string
  15. */
  16. public function actionIndex()
  17. {
  18. if (Yii::$app->request->isPost) {
  19. try {
  20. $file = $_FILES['excelFile'];
  21. $data = ExcelHelper::import($file['tmp_name'], 2);
  22. ImportHelper::auth($data, Yii::$app->request->post('app_id'));
  23. } catch (\Exception $e) {
  24. return $this->message($e->getMessage(), $this->redirect(['index']), 'error');
  25. }
  26. return $this->message('导入成功', $this->redirect(['index']));
  27. }
  28. return $this->render('index', [
  29. ]);
  30. }
  31. /**
  32. * 下载
  33. */
  34. public function actionDownload()
  35. {
  36. $file = 'auth-default.xls';
  37. if (Yii::$app->request->get('type') == 'merchant') {
  38. $file = 'auth-merchant.xls';
  39. }
  40. $path = Yii::getAlias('@addons') . '/RfDevTool/common/file/' . $file;
  41. Yii::$app->response->sendFile($path, '权限数据_' . time() . '.xls');
  42. }
  43. }
粤ICP备19079148号