BaseController.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace wechat\modules\cp\controllers;
  3. use yii\web\Controller;
  4. class BaseController extends Controller
  5. {
  6. public $layout = false;
  7. /**
  8. * json 输出方法
  9. * @param int $code api code 码 0 失败 1 正常
  10. * @param array $data 输出信息
  11. * @param string $msg 提示语
  12. * @return Response
  13. */
  14. public function outJson($code = 0, $data = [], $msg = '')
  15. {
  16. $data = [
  17. 'code' => $code,
  18. 'message' => $msg,
  19. 'data' => $data,
  20. 'timestamp' => time(),
  21. ];
  22. return $this->asJson($data);
  23. }
  24. /**
  25. * 弹窗提醒
  26. * @param $message
  27. * @param string $url
  28. * @param bool $isAlert
  29. * @param string $title
  30. */
  31. public function alertMsg($message, $url='', $isAlert=true, $title='提示')
  32. {
  33. echo '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>',$title,'</title></head><body>';
  34. echo '<script type="text/javascript">';
  35. echo $isAlert?'alert("'.$message.'");':'';
  36. echo $url==''?'history.back();':'location.href="'.$url.'";';
  37. echo '</script>';
  38. echo '</body></html>';
  39. exit();
  40. }
  41. }