Commit e8a4b09a authored by shajiaiming's avatar shajiaiming

新接口moudle

parent 28a28fc1
...@@ -30,54 +30,6 @@ class BaseController extends Controller ...@@ -30,54 +30,6 @@ class BaseController extends Controller
} }
} }
public function behaviors()
{
$request_controller = Yii::$app->controller->id;
$request_action = Yii::$app->controller->action->id;
$interceptor_global = array_unique(Yii::$app->params['interceptor']['global']);
$interceptor_default = array_unique(Yii::$app->params['interceptor']['default']);
$interceptor_mapping = isset(Yii::$app->params['interceptor'][$request_controller]) ? array_unique(Yii::$app->params['interceptor'][$request_controller]) : null;
$controller_enable = $interceptor_mapping ?? false;
$behaviors = [];
$final_interceptor = array_keys(array_flip(array_merge($interceptor_global, $interceptor_default)));
if ($controller_enable) {
$interceptor_map = $interceptor_mapping['interceptors'];
if ($interceptor_map) {
$switch = array_shift($interceptor_map);
if (false == $switch) {
$deny_interceptor = $interceptor_map;
$final_interceptor = array_diff($interceptor_default, $deny_interceptor);
} else {
$final_interceptor = array_unique($interceptor_map);
}
}
$action_mapping = $interceptor_mapping['actions'] ?? false;
if ($action_mapping) { //指定方法使用哪些拦截器
foreach ($action_mapping as $val) {
$action_id = array_shift($val); //拦截器配置文件中的action
$interceptor_map = $val[0];
$switch = array_shift($interceptor_map); //拦截器配置文件中action对应的拦截开关
if ($action_id == $request_action) {
if (false == $switch) {
$final_interceptor = array_unique(array_merge($interceptor_map, $interceptor_global));
$final_interceptor = array_diff($interceptor_default, array_diff($final_interceptor, $interceptor_global));
} else {
$final_interceptor = array_unique($interceptor_map);
}
}
}
}
}
foreach ($final_interceptor as $key => $item) {
$behaviors[$key] = [
'class' => $item,
];
}
return $behaviors;
}
public function fzmCrossHeader() public function fzmCrossHeader()
{ {
$this->lang = \Yii::$app->request->headers->get('lang') ?? 'zh-CN'; $this->lang = \Yii::$app->request->headers->get('lang') ?? 'zh-CN';
......
...@@ -18,8 +18,12 @@ class LoginStatusAuthInterceptor extends ActionFilter ...@@ -18,8 +18,12 @@ class LoginStatusAuthInterceptor extends ActionFilter
{ {
public function beforeAction($action) public function beforeAction($action)
{ {
$request_class = get_class($action->controller);
$request_action = $action->id;
if(strpos($request_class, 'UserController') !== false && strpos($request_action, 'login') !== false){
return true;
}
$token_string = Yii::$app->request->headers->get('Token'); $token_string = Yii::$app->request->headers->get('Token');
if(false == $token_string){ if(false == $token_string){
$message = 'platform auth error'; $message = 'platform auth error';
$code = '40004'; $code = '40004';
......
...@@ -23,7 +23,9 @@ class UserAuthInterceptor extends ActionFilter ...@@ -23,7 +23,9 @@ class UserAuthInterceptor extends ActionFilter
$request_class = get_class($action->controller); $request_class = get_class($action->controller);
$request_action = $action->id; $request_action = $action->id;
if(strpos($request_class, 'UserController') !== false && strpos($request_action, 'login') !== false){
return true;
}
$token_string = Yii::$app->request->headers->get('Token'); $token_string = Yii::$app->request->headers->get('Token');
$model = new Admin(); $model = new Admin();
$user = $model->loginByAccessToken($token_string,''); $user = $model->loginByAccessToken($token_string,'');
...@@ -44,10 +46,11 @@ class UserAuthInterceptor extends ActionFilter ...@@ -44,10 +46,11 @@ class UserAuthInterceptor extends ActionFilter
goto doEnd; goto doEnd;
} }
$auth_type_map = Yii::$app->params['user_auth'][$user_auth_map]; $auth_type_map = Yii::$app->params['user_auth'][$user_auth_map];
#$auth_type_map = array_unique($auth_type_map); $auth_type_map = array_unique($auth_type_map, SORT_REGULAR);
#var_dump($auth_type_map);exit;
$switch = false; $switch = false;
foreach ($auth_type_map as $key => $auth_type){ foreach ($auth_type_map as $key => $auth_type){
if(empty($auth_type)) continue;
if($request_class == $auth_type['class']){ if($request_class == $auth_type['class']){
$action_map = $auth_type['actions']; $action_map = $auth_type['actions'];
$switch = true; $switch = true;
......
<?php
namespace backend\assets;
use yii\web\AssetBundle;
/**
* Main backend application asset bundle.
*/
class AppAsset extends AssetBundle
{
public $sourcePath = '@common/metronic';
public $css = [];
public $js = [];
public $depends = [
'backend\assets\IeAsset',
'backend\assets\CoreAsset',
'backend\assets\LayoutAsset',
];
/**
* 定义按需加载JS方法,注意加载顺序在最后
* @param $view \yii\web\View
* @param $jsFile string
*/
public static function addScript($view, $jsFile)
{
$view->registerJsFile(
$jsFile,
[
AppAsset::className(),
'depends' => 'backend\assets\AppAsset'
]
);
}
/**
* 定义按需加载css方法,注意加载顺序在最后
* @param $view \yii\web\View
* @param $cssFile string
*/
public static function addCss($view, $cssFile)
{
$view->registerCssFile(
$cssFile,
[
AppAsset::className(),
'depends' => 'backend\assets\AppAsset'
]
);
}
}
<?php
namespace backend\assets;
use yii\web\AssetBundle;
/**
* Class CoreAsset
* @package backend\assets
*/
class CoreAsset extends AssetBundle
{
public $sourcePath = '@common/metronic';
public $css = [
'global/plugins/font-awesome/css/font-awesome.min.css',
'global/plugins/simple-line-icons/simple-line-icons.min.css',
'global/plugins/bootstrap/css/bootstrap.min.css',
'other/css/style.css?2018.0510',
];
public $js = [
// 'global/plugins/bootstrap/js/bootstrap.min.js',
//'global/plugins/js.cookie.min.js',
// 'global/scripts/app.min.js',
];
public $depends = [
'backend\assets\JqueryAsset',
//'yii\web\YiiAsset',
//'yii\grid\GridViewAsset'
];
}
<?php
namespace backend\assets;
use yii\web\AssetBundle;
/**
* Class IeAsset
* @package backend\assets
*/
class IeAsset extends AssetBundle
{
public $sourcePath = '@common/metronic';
public $css = [
];
public $js = [
'global/plugins/respond.min.js',
'global/plugins/excanvas.min.js',
];
public $jsOptions = ['condition' => 'lt IE9'];
public $depends = [
//'yii\web\YiiAsset',
//'yii\grid\GridViewAsset'
];
}
<?php
namespace backend\assets;
use yii\web\AssetBundle;
/**
* Class JqueryAsset
* @package backend\assets
*/
class JqueryAsset extends AssetBundle
{
public $sourcePath = '@common/metronic';
public $css = [
'global/plugins/layui/css/layui.css',
];
public $js = [
'global/plugins/jquery.min.js',
'global/plugins/layui/layui.all.js',
];
public $depends = [];
public $jsOptions = [
'position' => \yii\web\View::POS_HEAD,
];
}
<?php
namespace backend\assets;
use yii\web\AssetBundle;
/**
* Class LayoutAsset
* @package backend\assets
*/
class LayoutAsset extends AssetBundle
{
public $sourcePath = '@common/metronic';
public $css = [
'global/css/components-md.min.css',
//'global/css/components-rounded.min.css',
//'global/css/plugins-md.min.css',
'global/css/plugins.min.css',
'layouts/layout3/css/layout.min.css',
'layouts/layout3/css/themes/blue-hoki.min.css'
];
public $js = [
// 'layouts/layout3/scripts/layout.min.js',
// 'other/js/common.js?01101'
];
public $jsOptions = [
'position' => \yii\web\View::POS_END,
];
}
<?php
namespace backend\assets;
use yii\web\AssetBundle;
/**
* Class LoginAsset
* @package backend\assets
*/
class LoginAsset extends AssetBundle
{
public $sourcePath = '@common/metronic';
public $css = [
'global/plugins/uniform/css/uniform.default.css',
'global/css/components-rounded.min.css',
'global/css/plugins.min.css',
'pages/css/login-4.min.css',
];
public $js = [
'global/plugins/jquery-validation/js/jquery.validate.min.js',
'global/plugins/jquery-validation/js/additional-methods.min.js',
'global/plugins/backstretch/jquery.backstretch.min.js',
'global/plugins/uniform/jquery.uniform.min.js',
'pages/scripts/login-4.js',
];
public $depends = [
'backend\assets\CoreAsset',
];
}
<?php
namespace backend\assets;
use yii\web\AssetBundle;
/**
* Class TableAsset
* @package backend\assets
*/
class TableAsset extends AssetBundle
{
public $sourcePath = '@common/metronic';
public $css = [
];
public $js = [
'global/plugins/bootstrap-table/bootstrap-table.min.js',
// 'global/plugins/bootstrap-table/bootstrap-table-fixed-columns.js',
];
public $depends = [
'backend\assets\JqueryAsset'
];
public $jsOptions = [
'position' => \yii\web\View::POS_END,
];
}
<?php
/**
* Created By Sublime Text 3
*
* @date 2018-09-07 17:31:23
* @author rlgy <rlgyzhcn@qq.com>
*/
namespace backend\assets;
use yii\web\AssetBundle;
use yii\web\View;
class TableZhAsset extends AssetBundle
{
public $sourcePath = '@backend/web/js';
public $js = [
'bootstrap-table-zh-CN.js',
];
public $jsOptions = [
'position' => View::POS_END,
];
}
<?php
namespace backend\assets;
use yii\web\AssetBundle;
/**
* 树形插件
* Class TreeAsset
* @package backend\assets
*/
class TreeAsset extends AssetBundle
{
public $sourcePath = '@common/metronic';
public $css = [
'global/plugins/jstree/dist/themes/default/style.min.css',
];
public $js = [
'global/plugins/jstree/dist/jstree.min.js',
];
}
<?php
/**
* Created By Sublime Text 3
*
* @date 2018-09-07 17:31:23
* @authors rlgy <rlgyzhcn@qq.com>
*/
namespace backend\assets\app;
use yii\web\AssetBundle;
use yii\web\View;
class IndexAsset extends AssetBundle
{
public $sourcePath = '@backend/web/js/app';
public $js = [
'index.js',
];
public $jsOptions = [
'position' => View::POS_END,
];
}
<?php
/**
* Created by PhpStorm.
* User: ZCY
* Date: 2018/11/1
* Time: 17:31
*/
namespace backend\assets\applicateRank;
use yii\web\AssetBundle;
use yii\web\View;
class IndexAsset extends AssetBundle
{
public $sourcePath = '@backend/web/js/applicate-rank';
public $js = [
'index.js',
];
public $jsOptions = [
'position' => View::POS_END,
];
}
\ No newline at end of file
<?php
/**
* Created By Sublime Text 3
*
* @authors rlgy <rlgyzhcn@qq.com>
* @date 2018-09-07 17:41:04
*/
namespace backend\assets\coin;
use yii\web\AssetBundle;
use yii\web\View;
class IndexAsset extends AssetBundle
{
public $sourcePath = '@backend/web/js/coin';
public $js = [
'index.js',
];
public $jsOptions = [
'position' => View::POS_END,
];
}
\ No newline at end of file
<?php
/**
* Created By Sublime Text 3
*
* @date 2018-09-07 17:31:23
* @authors rlgy <rlgyzhcn@qq.com>
*/
namespace backend\assets\coinPublish;
use yii\web\AssetBundle;
use yii\web\View;
class IndexAsset extends AssetBundle
{
public $sourcePath = '@backend/web/js/coin-publish';
public $js = [
'list.js',
];
public $jsOptions = [
'position' => View::POS_END,
];
}
<?php
/**
* Created By Sublime Text 3
*
* @date 2018-09-07 17:31:23
* @authors rlgy <rlgyzhcn@qq.com>
*/
namespace backend\assets\coinPublishRule;
use yii\web\AssetBundle;
use yii\web\View;
class IndexAsset extends AssetBundle
{
public $sourcePath = '@backend/web/js/coin-publish-rule';
public $js = [
'index.js',
];
public $jsOptions = [
'position' => View::POS_END,
];
}
<?php
/**
* Created By Sublime Text 3
*
* @date 2018-09-07 17:31:23
* @authors rlgy <rlgyzhcn@qq.com>
*/
namespace backend\assets\coinPublishRule;
use yii\web\AssetBundle;
use yii\web\View;
class ListAsset extends AssetBundle
{
public $sourcePath = '@backend/web/js/coin-publish-rule';
public $js = [
'list.js',
];
public $jsOptions = [
'position' => View::POS_END,
];
}
<?php
/**
* Created By Sublime Text 3
*
* @date 2018-09-07 17:31:23
* @authors rlgy <rlgyzhcn@qq.com>
*/
namespace backend\assets\coinReleaseCheck;
use yii\web\AssetBundle;
use yii\web\View;
class IndexAsset extends AssetBundle
{
public $sourcePath = '@backend/web/js/coin-release-check';
public $js = [
'index.js',
];
public $jsOptions = [
'position' => View::POS_END,
];
}
<?php
/**
* Created By Sublime Text 3
*
* @date 2018-09-07 17:31:23
* @authors rlgy <rlgyzhcn@qq.com>
*/
namespace backend\assets\coinReleaseMember;
use yii\web\AssetBundle;
use yii\web\View;
class IndexAsset extends AssetBundle
{
public $sourcePath = '@backend/web/js/coin-release-member';
public $js = [
'list.js',
];
public $jsOptions = [
'position' => View::POS_END,
];
}
<?php
namespace backend\assets\coinTransfer;
use yii\web\AssetBundle;
use yii\web\View;
class IndexAsset extends AssetBundle
{
public $sourcePath = '@backend/web/js/coin-transfer';
public $js = [
'list.js',
];
public $jsOptions = [
'position' => View::POS_END,
];
}
<?php
/**
* Created By Sublime Text 3
*
* @date 2018-09-07 17:31:23
* @authors rlgy <rlgyzhcn@qq.com>
*/
namespace backend\assets\investment;
use yii\web\AssetBundle;
use yii\web\View;
class IndexAsset extends AssetBundle
{
public $sourcePath = '@backend/web/js/investment';
public $js = [
'index.js',
];
public $jsOptions = [
'position' => View::POS_END,
];
}
<?php
/**
* Created By Sublime Text 3
*
* @date 2018-09-07 17:31:23
* @authors rlgy <rlgyzhcn@qq.com>
*/
namespace backend\assets\investmentType;
use yii\web\AssetBundle;
use yii\web\View;
class IndexAsset extends AssetBundle
{
public $sourcePath = '@backend/web/js/investment-type';
public $js = [
'index.js',
];
public $jsOptions = [
'position' => View::POS_END,
];
}
<?php
/**
* Created By Sublime Text 3
*
* @date 2018-09-07 17:31:23
* @authors rlgy <rlgyzhcn@qq.com>
*/
namespace backend\assets\site;
use yii\web\AssetBundle;
use yii\web\View;
class IndexAsset extends AssetBundle
{
public $sourcePath = '@backend/web/js/site';
public $js = [
'index.js',
];
public $depends = [
'backend\assets\TableAsset',
'backend\assets\TableZhAsset',
];
public $jsOptions = [
'position' => View::POS_END,
];
}
<?php
namespace wallet\base;
class BaseConstant
{
const ERROR = 'error';
const MSG = 'msg';
const MESSAGE = 'message';
const CODE = 'code';
const VAL = 'val';
const DATA = 'data';
const OK = 'ok';
const FINALTAG = 'finaltag';
}
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-5-31
* Time: 上午10:29
*/
namespace wallet\base;
use Yii;
use yii\helpers\Url;
use yii\web\Response;
use yii\base\Controller;
use yii\base\InlineAction;
use yii\web\BadRequestHttpException;
class BaseController extends Controller
{
public function behaviors()
{
$request_controller = Yii::$app->controller->id;
$request_action = Yii::$app->controller->action->id;
$interceptor_global = array_unique(Yii::$app->params['interceptor']['global']);
$interceptor_default = array_unique(Yii::$app->params['interceptor']['default']);
$interceptor_mapping = isset(Yii::$app->params['interceptor'][$request_controller]) ? array_unique(Yii::$app->params['interceptor'][$request_controller]) : null;
$controller_enable = $interceptor_mapping ?? false;
$behaviors = [];
$final_interceptor = array_keys(array_flip(array_merge($interceptor_global, $interceptor_default)));
if ($controller_enable) {
$interceptor_map = $interceptor_mapping['interceptors'];
if ($interceptor_map) {
$switch = array_shift($interceptor_map);
if (false == $switch) {
$deny_interceptor = $interceptor_map;
$final_interceptor = array_diff($interceptor_default, $deny_interceptor);
} else {
$final_interceptor = array_unique($interceptor_map);
}
}
$action_mapping = $interceptor_mapping['actions'] ?? false;
if ($action_mapping) { //指定方法使用哪些拦截器
foreach ($action_mapping as $val) {
$action_id = array_shift($val); //拦截器配置文件中的action
$interceptor_map = $val[0];
$switch = array_shift($interceptor_map); //拦截器配置文件中action对应的拦截开关
if ($action_id == $request_action) {
if (false == $switch) {
$final_interceptor = array_unique(array_merge($interceptor_map, $interceptor_global));
$final_interceptor = array_diff($interceptor_default, array_diff($final_interceptor, $interceptor_global));
} else {
$final_interceptor = array_unique($interceptor_map);
}
}
}
}
}
foreach ($final_interceptor as $key => $item) {
$behaviors[$key] = [
'class' => $item,
];
}
return $behaviors;
}
/**
* @var bool whether to enable CSRF validation for the actions in this controller.
* CSRF validation is enabled only when both this property and [[\yii\web\Request::enableCsrfValidation]] are true.
*/
public $enableCsrfValidation = true;
/**
* @var array the parameters bound to the current action.
*/
public $actionParams = [];
/**
* Renders a view in response to an AJAX request.
*
* This method is similar to [[renderPartial()]] except that it will inject into
* the rendering result with JS/CSS scripts and files which are registered with the view.
* For this reason, you should use this method instead of [[renderPartial()]] to render
* a view to respond to an AJAX request.
*
* @param string $view the view name. Please refer to [[render()]] on how to specify a view name.
* @param array $params the parameters (name-value pairs) that should be made available in the view.
* @return string the rendering result.
*/
public function renderAjax($view, $params = [])
{
return $this->getView()->renderAjax($view, $params, $this);
}
/**
* Send data formatted as JSON.
*
* This method is a shortcut for sending data formatted as JSON. It will return
* the [[Application::getResponse()|response]] application component after configuring
* the [[Response::$format|format]] and setting the [[Response::$data|data]] that should
* be formatted. A common usage will be:
*
* ```php
* return $this->asJson($data);
* ```
*
* @param mixed $data the data that should be formatted.
* @return Response a response that is configured to send `$data` formatted as JSON.
* @since 2.0.11
* @see Response::$format
* @see Response::FORMAT_JSON
* @see JsonResponseFormatter
*/
public function asJson($data)
{
$response = Yii::$app->getResponse();
$response->format = Response::FORMAT_JSON;
$response->data = $data;
return $response;
}
/**
* Send data formatted as XML.
*
* This method is a shortcut for sending data formatted as XML. It will return
* the [[Application::getResponse()|response]] application component after configuring
* the [[Response::$format|format]] and setting the [[Response::$data|data]] that should
* be formatted. A common usage will be:
*
* ```php
* return $this->asXml($data);
* ```
*
* @param mixed $data the data that should be formatted.
* @return Response a response that is configured to send `$data` formatted as XML.
* @since 2.0.11
* @see Response::$format
* @see Response::FORMAT_XML
* @see XmlResponseFormatter
*/
public function asXml($data)
{
$response = Yii::$app->getResponse();
$response->format = Response::FORMAT_XML;
$response->data = $data;
return $response;
}
/**
* Binds the parameters to the action.
* This method is invoked by [[\yii\base\Action]] when it begins to run with the given parameters.
* This method will check the parameter names that the action requires and return
* the provided parameters according to the requirement. If there is any missing parameter,
* an exception will be thrown.
* @param \yii\base\Action $action the action to be bound with parameters
* @param array $params the parameters to be bound to the action
* @return array the valid parameters that the action can run with.
* @throws BadRequestHttpException if there are missing or invalid parameters.
*/
public function bindActionParams($action, $params)
{
if ($action instanceof InlineAction) {
$method = new \ReflectionMethod($this, $action->actionMethod);
} else {
$method = new \ReflectionMethod($action, 'run');
}
$args = [];
$missing = [];
$actionParams = [];
foreach ($method->getParameters() as $param) {
$name = $param->getName();
if (array_key_exists($name, $params)) {
if ($param->isArray()) {
$args[] = $actionParams[$name] = (array)$params[$name];
} elseif (!is_array($params[$name])) {
$args[] = $actionParams[$name] = $params[$name];
} else {
throw new BadRequestHttpException(Yii::t('yii', 'Invalid data received for parameter "{param}".', [
'param' => $name,
]));
}
unset($params[$name]);
} elseif ($param->isDefaultValueAvailable()) {
$args[] = $actionParams[$name] = $param->getDefaultValue();
} else {
$missing[] = $name;
}
}
if (!empty($missing)) {
throw new BadRequestHttpException(Yii::t('yii', 'Missing required parameters: {params}', [
'params' => implode(', ', $missing),
]));
}
$this->actionParams = $actionParams;
return $args;
}
/**
* {@inheritdoc}
*/
public function beforeAction($action)
{
if (parent::beforeAction($action)) {
if ($this->enableCsrfValidation && Yii::$app->getErrorHandler()->exception === null && !Yii::$app->getRequest()->validateCsrfToken()) {
throw new BadRequestHttpException(Yii::t('yii', 'Unable to verify your data submission.'));
}
return true;
}
return false;
}
/**
* Redirects the browser to the specified URL.
* This method is a shortcut to [[Response::redirect()]].
*
* You can use it in an action by returning the [[Response]] directly:
*
* ```php
* // stop executing this action and redirect to login page
* return $this->redirect(['login']);
* ```
*
* @param string|array $url the URL to be redirected to. This can be in one of the following formats:
*
* - a string representing a URL (e.g. "http://example.com")
* - a string representing a URL alias (e.g. "@example.com")
* - an array in the format of `[$route, ...name-value pairs...]` (e.g. `['site/index', 'ref' => 1]`)
* [[Url::to()]] will be used to convert the array into a URL.
*
* Any relative URL that starts with a single forward slash "/" will be converted
* into an absolute one by prepending it with the host info of the current request.
*
* @param int $statusCode the HTTP status code. Defaults to 302.
* See <https://tools.ietf.org/html/rfc2616#section-10>
* for details about HTTP status code
* @return Response the current response object
*/
public function redirect($url, $statusCode = 302)
{
return Yii::$app->getResponse()->redirect(Url::to($url), $statusCode);
}
/**
* Redirects the browser to the home page.
*
* You can use this method in an action by returning the [[Response]] directly:
*
* ```php
* // stop executing this action and redirect to home page
* return $this->goHome();
* ```
*
* @return Response the current response object
*/
public function goHome()
{
return Yii::$app->getResponse()->redirect(Yii::$app->getHomeUrl());
}
/**
* Redirects the browser to the last visited page.
*
* You can use this method in an action by returning the [[Response]] directly:
*
* ```php
* // stop executing this action and redirect to last visited page
* return $this->goBack();
* ```
*
* For this function to work you have to [[User::setReturnUrl()|set the return URL]] in appropriate places before.
*
* @param string|array $defaultUrl the default return URL in case it was not set previously.
* If this is null and the return URL was not set previously, [[Application::homeUrl]] will be redirected to.
* Please refer to [[User::setReturnUrl()]] on accepted format of the URL.
* @return Response the current response object
* @see User::getReturnUrl()
*/
public function goBack($defaultUrl = null)
{
return Yii::$app->getResponse()->redirect(Yii::$app->getUser()->getReturnUrl($defaultUrl));
}
/**
* Refreshes the current page.
* This method is a shortcut to [[Response::refresh()]].
*
* You can use it in an action by returning the [[Response]] directly:
*
* ```php
* // stop executing this action and refresh the current page
* return $this->refresh();
* ```
*
* @param string $anchor the anchor that should be appended to the redirection URL.
* Defaults to empty. Make sure the anchor starts with '#' if you want to specify it.
* @return Response the response object itself
*/
public function refresh($anchor = '')
{
return Yii::$app->getResponse()->redirect(Yii::$app->getRequest()->getUrl() . $anchor);
}
protected function initParams($p = [], $fields = [], $isFilter = false)
{
$params = [];
if (!empty($fields)) {
foreach ($fields as $key => $value) {
if (isset($p[$value]) && (!empty($p[$value]) || $p[$value] == 0)) {
$params[$value] = $p[$value];
} else {
if (!$isFilter) $params[$value] = null;
}
}
}
return $params;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-5-31
* Time: 下午1:28
*/
namespace wallet\base;
use yii\web\Response;
class BaseResponse extends Response
{
public function send()
{
//错误处理
$excpetion = \Yii::$app->errorHandler->exception;
if ($excpetion !== null) {
$this->data = [
'code' => $excpetion->getCode(),
'msg' => $excpetion->getMessage(),
'line' => $excpetion->getLine(),
'file' => $excpetion->getFile(),
];
}
//TODO 在这里对数据进行format,这样控制器中可以直接return一个array,保存到数据域data中即可,eg:['code'=>0,'data'=>$data]
$data = \Yii::$app->response->data;
if (empty($data)) {
$return['code'] = 1;
$return['msg'] = '数据为空';
} elseif (is_array($data) && !isset($data['code'])) {
$return['code'] = 0;
$return['count'] = count($data);
$return['data'] = $data;
} else {
$return = $data;
}
if (YII_ENV_DEV) {
#$return['time'] = \Yii::$app->controller->end - \Yii::$app->controller->start;
}
\Yii::$app->response->data = $return;
parent::send();
}
}
\ No newline at end of file
<?php
namespace wallet\base;
use yii\helpers\Html;
use yii\web\Response;
class ResponseMsg
{
public $is_support_jsonp = false;
public $header_list = [];
private static $default_header_list = [];
public function __construct()
{
// if ('cli' !== php_sapi_name()){
// $this->header_list = self::$default_header_list;
// $this->fzmCrossHeader();
// }
}
public function fzmCrossHeader()
{
$allow_list = \Yii::$app->params['allow_options_domain']['common'];
$origin = \Yii::$app->request->headers->get('Origin');
if (!in_array($origin, $allow_list)) {
$origin = implode(',', $allow_list);
}
$this->header('Access-Control-Allow-Origin', $origin);
$this->header('Access-Control-Allow-Methods', 'POST,GET,OPTIONS');
$this->header('Access-Control-Allow-Credentials', 'true');
$this->header('Access-Control-Allow-Headers', 'Authorization,FZM-REQUEST-OS,FZM-USER-IP,FZM-REQUEST-UUID,Content-Type,Content-Length');
}
public static function setDefaultHeader($default_header_list)
{
foreach ($default_header_list as $key => $header) {
self::$default_header_list[$key] = $header;
}
}
public static function getDefaultHeader()
{
return self::$default_header_list;
}
public function arrSuccess($data = BaseConstant::OK, $code = 200)
{
return [BaseConstant::ERROR => false, BaseConstant::MESSAGE => $data, BaseConstant::CODE => $code];
}
public function arrFail($data, $code = -1)
{
return [BaseConstant::ERROR => true, BaseConstant::MESSAGE => $data, BaseConstant::CODE => $code];
}
/**
* 失败返回接口
* @param string $msg
* @param int $code
* @return string
*/
public function jsonError($msg = '', $code = -1)
{
if (empty($msg)) {
$msg = 'unknown error';
}
$view = [
BaseConstant::CODE => $code,
BaseConstant::MESSAGE => $msg,
];
$json = json_encode($view);
return $this->dumpJsonData($json);
}
/**
* 成功返回接口
* @param string $msg
* @param int $code
* @return string
*/
public function jsonSuccess($data = '', $code = 200)
{
$view = [
BaseConstant::CODE => $code,
BaseConstant::MESSAGE => BaseConstant::OK,
BaseConstant::DATA => $data
];
$json = json_encode($view);
return $this->dumpJsonData($json);
}
/**
* 直接处理接口数据
* @param $ret
*/
public function dealRet($ret)
{
if (true === $ret[BaseConstant::ERROR]) {
$this->jsonError($ret[BaseConstant::MESSAGE] ? : 'unknown error');
} else {
$this->jsonSuccess($ret[BaseConstant::MESSAGE] ? : BaseConstant::OK);
}
}
/**
* 根据是否为JSONP做特殊处理输出
* @param $json
* @return string
*/
public function dumpJsonData($json)
{
$callback = '';
if (true === $this->is_support_jsonp) {
if (!$this->isDebug()) {
$this->header('Content-type', 'application/javascript');
}
$callback_key = 'jsonpcallback';
$callback = $_GET[$callback_key];
if ($callback) {
$callback = Html::encode($callback_key);
$json = $callback . '(' . $json . ')';
}
}
if (!$callback && !$this->isDebug()) {
$this->header('Content-type', 'application/json');
}
return $json;
}
/**
* @param $json_str
* @param string $callback_key
* @return string
*/
public function printByJson($json_str, $callback_key = '')
{
$callback = '';
if ($callback_key) {
$callback = $_GET[$callback_key] ?? '';
}
if ($callback) {
$callback = Html::encode($callback_key);
if (!$this->isDebug()) {
$this->header('Content-type', 'application/javascript');
}
return $callback . '(' . $json_str . ')';
} else {
if (!$this->isDebug()) {
$this->header('Content-type', 'application/json');
}
return $json_str;
}
}
/**
* @param $arr
* @param string $callback_key
* @return string
*/
public function printByArr($arr, $callback_key = '')
{
$callback = '';
if ($callback_key) {
$callback = $_GET[$callback_key] ?? '';
}
if ($callback) {
$callback = Html::encode($callback_key);
if (!$this->isDebug()) {
$this->header('Content-type', 'application/javascript');
}
return $callback . '(' . json_encode($arr) . ')';
} else {
if (!$this->isDebug()) {
$this->header('Content-type', 'application/json');
}
return json_encode($arr);
}
}
public function printOldFail($code, $code_msg, $detail_code, $detail_msg, $callback_key = '')
{
$this->fzmCrossHeader();
$callback = '';
if ($callback_key) {
$callback = $_GET[$callback_key] ?? '';
}
$arr = ['code' => $code, 'error' => $code_msg, 'ecode' => $detail_code, 'message' => $detail_msg, 'data' => []];
if ($callback) {
$callback = Html::encode($callback_key);
if (!$this->isDebug()) {
$this->header('Content-type', 'application/javascript');
}
return $callback . '(' . json_encode($arr) . ')';
} else {
if (!$this->isDebug()) {
$this->header('Content-type', 'application/json');
}
return json_encode($arr);
}
}
/**
* @param $success_data
* @param string $callback_key
* @return string
*/
public function printOldSuccess($success_data, $callback_key = '')
{
$this->fzmCrossHeader();
$callback = '';
if ($callback_key) {
$callback = $_GET[$callback_key] ?? '';
}
$arr = ['code' => 200, 'ecode' => 200, 'error' => 'OK', 'message' => 'OK', 'data' => $success_data];
if ($callback) {
$callback = Html::encode($callback_key);
if (!$this->isDebug()) {
$this->header('Content-type', 'application/javascript');
}
return $callback . '(' . json_encode($arr) . ')';
} else {
if (!$this->isDebug()) {
$this->header('Content-type', 'application/json');
}
return json_encode($arr);
}
}
/**
* 解决xdebug cookie设置不了的问题
*/
private function isDebug()
{
if (defined('SERVICE_ENV') && (SERVICE_ENV === 'test' || SERVICE_ENV === 'local') && isset($_GET['debug'])) {
return true;
}
return false;
}
public function header($key, $value)
{
$this->header_list[$key] = $value;
}
public function getHeaders()
{
return $this->header_list;
}
public function withHeaders($header_arr)
{
\Yii::$app->response->format = \yii\web\Response::FORMAT_RAW;
foreach ($header_arr as $key => $val) {
\Yii::$app->response->headers->add($key, $val);
}
return $this;
}
public function withContent($content)
{
return $content;
}
}
namespace: backend\tests
actor: Tester
paths:
tests: tests
log: tests/_output
data: tests/_data
helpers: tests/_support
settings:
bootstrap: _bootstrap.php
colors: true
memory_limit: 1024M
modules:
config:
Yii2:
configFile: 'config/test-local.php'
main-local.php
params-local.php
\ No newline at end of file
<?php
$params = array_merge(
require __DIR__ . '/../../common/config/params.php',
require __DIR__ . '/../../common/config/params-local.php',
require __DIR__ . '/params.php',
require __DIR__ . '/params-local.php'
);
return [
'id' => 'app-backend',
'basePath' => dirname(__DIR__),
'timeZone' => 'Etc/GMT-8',
'controllerNamespace' => 'backend\controllers',
'bootstrap' => ['log'],
'defaultRoute' => 'site/index',
'layout' => 'main',
'modules' => [],
'components' => [
'request' => [
'class' => 'common\core\Request',
'baseUrl' => '/admin',
'cookieValidationKey' => 'Yr4XDePew55tutE3CVZ7vBUqVO3iorN6',
//'csrfParam' => '_csrf-backend',
],
'session' => [
'name' => 'manage-backend',
],
'errorHandler' => [
'errorAction' => 'public/error',
],
'urlManager' => [
'class' => 'common\core\UrlManager',
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
],
]
],
'params' => $params,
];
<?php
return [
'adminEmail' => 'admin@example.com',
/* 后台错误页面模板 */
'action_error' => '@backend/views/public/error.php', // 默认错误跳转对应的模板文件
'action_success' => '@backend/views/public/success.php', // 默认成功跳转对应的模板文件
];
<?php
namespace wallet\controllers;
use common\models\psources\CoinPlatformWithHold;
use common\service\chain33\Chain33Service;
use Yii;
use wallet\base\BaseController;
use yii\data\Pagination;
class MonitorController extends BaseController
{
/**
* landing
* @return array
* @throws \yii\base\Exception
* @throws \yii\base\InvalidConfigException
*/
public function actionList()
{
$msg = 'ok';
$code = 0;
$page = Yii::$app->request->get('page', 1);
$query = CoinPlatformWithHold::find()->select('id, platform, address')->asArray();
$count = $query->count();
if( 0 == $count ) {
$msg = '数据不存在';
$code = -1;
$data = null;
goto doEnd;
}
$models = $query->offset(($page - 1) * 10)->limit(10)->asArray()->all();
$countQuery = clone $query;
$pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => '10']);
$address = [];
foreach ($models as $model){
$address[] = $model['address'];
}
$service = new Chain33Service();
$execer = 'coins';
$result = $service->getBalance($address, $execer);
if(0 != $result['code']){
$msg = $result['msg'];
$code = -1;
goto doEnd;
}
$result_balance = $result['result'];
$balance_arr = [];
foreach ($result_balance as $key => $val){
$balance_arr[$val['addr']] = $val;
}
foreach ($models as &$model){
$model['balance'] = $balance_arr[$model['address']]['balance'];
}
$data = [
'list' => $models,
'page' => [
'pageCount' => $pages->pageCount,
'pageSize' => 20,
'currentPage' => $page,
]
];
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
}
\ No newline at end of file
<?php <?php
namespace api\controllers; namespace wallet\controllers;
use Yii; use Yii;
use common\models\Admin; use common\models\Admin;
use common\models\LoginForm; use common\models\LoginForm;
use api\base\BaseController; use wallet\base\BaseController;
class UserController extends BaseController class UserController extends BaseController
{ {
......
<?php
namespace wallet\controllers;
use Yii;
use common\models\Admin;
use wallet\base\BaseController;
use common\models\psources\CoinPlatform;
class WalletController extends BaseController
{
/**
* landing
* @return array
* @throws \yii\base\Exception
* @throws \yii\base\InvalidConfigException
*/
public function actionList()
{
$platforms = CoinPlatform::find()->asArray()->all();
return $platforms;
}
/**
* 用户同步
*/
public function actionUserSync()
{
$header = Yii::$app->request->headers;
$platform_id = $header['platform_id'] ?? 17;
$post = Yii::$app->request->post();
$data = [
'bind_uid' => $post['bind_uid'],
'username' => $post['username'],
'salt' => Yii::$app->security->generateRandomString(),
'password' => Yii::$app->security->generatePasswordHash('123456'),
'reg_time' => time(),
'reg_ip' => ip2long('127.0.0.1'),
'last_login_time' => 0,
'last_login_ip' => ip2long('127.0.0.1'),
'update_time' => 0,
'status' => 1,
'platform_id' => $platform_id
];
// $password = Yii::$app->security->generatePasswordHash('123456');
// $salt = Yii::$app->security->generateRandomString();
// $reg_time = time();
// $reg_ip = ip2long('127.0.0.1');
// $last_login_time = 0;
// $last_login_ip = ip2long('127.0.0.1');
// $update_time = 0;
// $status = 1;
// $additional = [$password, $salt, $reg_time, $reg_ip, $last_login_time, $last_login_ip, $update_time, $status];
$role = Yii::$app->request->post('role', 'GHPwallet');
$model = new Admin();
if($model->load($data, '') && $model->save()) {
$auth = Yii::$app->authManager;
$role = $auth->getRole($role);
$auth->assign($role, $model->uid);
exit;
} else {
var_dump($model->errors);exit;
}
}
/**
* 用户注册
*/
public function actionCreate()
{
}
/**
* 重置密码
*/
public function actionResetPassword()
{
}
/**
* 获取用户基本信息
* @return array
*/
public function actionView()
{
}
/*
* 更改密码
* @return array
*/
public function actionUpdatePassword()
{
}
}
\ No newline at end of file
*
!.gitignore
\ No newline at end of file
<?php
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'test');
defined('YII_APP_BASE_PATH') or define('YII_APP_BASE_PATH', __DIR__.'/../../');
require_once YII_APP_BASE_PATH . '/vendor/autoload.php';
require_once YII_APP_BASE_PATH . '/vendor/yiisoft/yii2/Yii.php';
require_once YII_APP_BASE_PATH . '/common/config/bootstrap.php';
require_once __DIR__ . '/../config/bootstrap.php';
<?php
return [
[
'username' => 'erau',
'auth_key' => 'tUu1qHcde0diwUol3xeI-18MuHkkprQI',
// password_0
'password_hash' => '$2y$13$nJ1WDlBaGcbCdbNC5.5l4.sgy.OMEKCqtDQOdQ2OWpgiKRWYyzzne',
'password_reset_token' => 'RkD_Jw0_8HEedzLk7MM-ZKEFfYR7VbMr_1392559490',
'created_at' => '1392559490',
'updated_at' => '1392559490',
'email' => 'sfriesen@jenkins.info',
],
];
<?php
namespace backend\tests;
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
*
* @SuppressWarnings(PHPMD)
*/
class FunctionalTester extends \Codeception\Actor
{
use _generated\FunctionalTesterActions;
/**
* Define custom actions here
*/
}
<?php
namespace backend\tests;
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
*
* @SuppressWarnings(PHPMD)
*/
class UnitTester extends \Codeception\Actor
{
use _generated\UnitTesterActions;
/**
* Define custom actions here
*/
}
class_name: FunctionalTester
modules:
enabled:
- Yii2
<?php
namespace backend\tests\functional;
use backend\tests\FunctionalTester;
use common\fixtures\UserFixture;
/**
* Class LoginCest
*/
class LoginCest
{
/**
* Load fixtures before db transaction begin
* Called in _before()
* @see \Codeception\Module\Yii2::_before()
* @see \Codeception\Module\Yii2::loadFixtures()
* @return array
*/
public function _fixtures()
{
return [
'user' => [
'class' => UserFixture::className(),
'dataFile' => codecept_data_dir() . 'login_data.php'
]
];
}
/**
* @param FunctionalTester $I
*/
public function loginUser(FunctionalTester $I)
{
$I->amOnPage('/site/login');
$I->fillField('Username', 'erau');
$I->fillField('Password', 'password_0');
$I->click('login-button');
$I->see('Logout (erau)', 'form button[type=submit]');
$I->dontSeeLink('Login');
$I->dontSeeLink('Signup');
}
}
<?php
/**
* Here you can initialize variables via \Codeception\Util\Fixtures class
* to store data in global array and use it in Cests.
*
* ```php
* // Here _bootstrap.php
* \Codeception\Util\Fixtures::add('user1', ['name' => 'davert']);
* ```
*
* In Cests
*
* ```php
* \Codeception\Util\Fixtures::get('user1');
* ```
*/
\ No newline at end of file
class_name: UnitTester
<?php
/**
* Here you can initialize variables via \Codeception\Util\Fixtures class
* to store data in global array and use it in Tests.
*
* ```php
* // Here _bootstrap.php
* \Codeception\Util\Fixtures::add('user1', ['name' => 'davert']);
* ```
*
* In Tests
*
* ```php
* \Codeception\Util\Fixtures::get('user1');
* ```
*/
/index-test.php
/robots.txt
/upload
\ No newline at end of file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-5-3
* Time: 下午12:53
*/
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');
require __DIR__ . '/../../vendor/autoload.php';
require __DIR__ . '/../../vendor/yiisoft/yii2/Yii.php';
require __DIR__ . '/../../common/config/bootstrap.php';
$config = yii\helpers\ArrayHelper::merge(
require __DIR__ . '/../../common/config/main.php',
require __DIR__ . '/../../common/config/main-local.php',
require __DIR__ . '/../config/main.php',
require __DIR__ . '/../config/main-local.php'
);
(new yii\web\Application($config))->run();
\ No newline at end of file
/**
* 自定义刷新提示
*/
var whenShowLoading=null;
var showMyLoading=function () {
if (typeof(layer) === 'object' && whenShowLoading === null) {
whenShowLoading = layer.load(2, {shade: false});
}
return true;
};
var hideMyLoading=function () {
if (typeof(layer) === 'object' && whenShowLoading !== null) {
layer.close(whenShowLoading);
whenShowLoading = null;
}
return true;
};
/**
* Bootstrap Table Chinese translation
*/
(function ($) {
'use strict';
$.fn.bootstrapTable.locales['zh-CN'] = {
contentType: "application/x-www-form-urlencoded",
striped: true, //设置为 true 会有隔行变色效果
cache: false, //设置为 false 禁用 AJAX 数据缓存
silent: true, //静默刷新方式 refresh {silent: true}
dataType: "json", //服务器返回的数据类型
queryParamsType:'', //queryParams {pageSize, pageNumber, searchText, sortName, sortOrder}
undefinedText: '', //当数据为 undefined 时显示的字符
sidePagination: "server", //服务器分页
pagination: true, //设置为 true 会在表格底部显示分页条
paginationLoop: false, //设置为 true 启用分页条无限循环的功能
/*fixedColumns: true,
fixedNumber: 2,*/
paginationPreText: '上一页',
paginationNextText: '下一页',
ajaxOptions: function () {
if (typeof(request_token) === 'string') {
return {
headers: {"Authorization": 'Bearer ' + request_token}
};
} else {
return {};
}
},
formatLoadingMessage: function () {
return '';
},
formatRecordsPerPage: function (pageNumber) {
return '';//'每页显示 ' + pageNumber + ' 条记录';
},
formatShowingRows: function (pageFrom, pageTo, totalRows) {
return '<span style="font-size: 11px">第 <b>'+pageFrom+'</b>-<b>'+pageTo+'</b> 条,共 <b>'+totalRows+'</b> 条数据. </span>';
//return '显示第 ' + pageFrom + ' 到第 ' + pageTo + ' 条记录,总共 ' + totalRows + ' 条记录';
},
formatSearch: function () {
return '搜索';
},
formatNoMatches: function () {
return '<span style="color: #9e9e9e">没有找到匹配的记录</span>';
},
formatPaginationSwitch: function () {
return '隐藏/显示分页';
},
formatRefresh: function () {
return '刷新';
},
formatToggle: function () {
return '切换';
},
formatColumns: function () {
return '列';
},
formatExport: function () {
return '导出';
},
formatClearFilters: function () {
return '清空过滤';
},
onLoadSuccess: function () {
return hideMyLoading();
},
onLoadError: function () {
return hideMyLoading();
},
onRefresh: function () {
return showMyLoading();
},
onPageChange: function () {
return showMyLoading();
}
};
$.extend($.fn.bootstrapTable.defaults, $.fn.bootstrapTable.locales['zh-CN']);
})(jQuery);
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment