Browse Source

feat: 增加api模块

antshop
iron 5 years ago
parent
commit
5499f17f70
  1. 26
      api/assets/AppAsset.php
  2. 4
      api/config/.gitignore
  3. 1
      api/config/bootstrap.php
  4. 51
      api/config/main.php
  5. 3
      api/config/params.php
  6. 22
      api/controllers/SiteController.php
  7. 59
      api/controllers/TestController.php
  8. 2
      api/runtime/.gitignore
  9. 27
      api/views/site/error.php
  10. 5
      api/web/.gitignore
  11. 2
      api/web/assets/.gitignore
  12. 120
      api/web/css/site.css
  13. BIN
      api/web/favicon.ico
  14. 19
      backend/views/layouts/sidebar.php
  15. 1
      common/config/bootstrap.php
  16. 0
      datadictionary.md

26
api/assets/AppAsset.php

@ -0,0 +1,26 @@
<?php
namespace backend\assets;
use yii\web\AssetBundle;
/**
* Main backend application asset bundle.
*/
class AppAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
'css/site.css',
];
public $js = [
'js/common.js'
];
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap4\BootstrapAsset',
'yii\bootstrap4\BootstrapPluginAsset',
'iron\web\AdminlteAsset',
];
}

4
api/config/.gitignore

@ -0,0 +1,4 @@
codeception-local.php
main-local.php
params-local.php
test-local.php

1
api/config/bootstrap.php

@ -0,0 +1 @@
<?php

51
api/config/main.php

@ -0,0 +1,51 @@
<?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' => 'api',
'basePath' => dirname(__DIR__),
'controllerNamespace' => 'api\controllers',
'bootstrap' => ['log'],
'modules' => [],
'components' => [
'request' => [
'parsers' => [
'application/json' => 'yii\web\JsonParser',
],
'csrfParam' => '_csrf-backend',
],
'user' => [
'identityClass' => 'common\models\User',
'enableAutoLogin' => true,
'identityCookie' => ['name' => '_identity-backend', 'httpOnly' => true],
],
'session' => [
// this is the name of the session cookie used for login on the app
'name' => 'advanced-api',
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => true,
'enableStrictParsing' => false,
'rules' => [
['class' => 'yii\rest\UrlRule', 'controller' => 'test'],
],
],
],
'params' => $params,
];

3
api/config/params.php

@ -0,0 +1,3 @@
<?php
return [
];

22
api/controllers/SiteController.php

@ -0,0 +1,22 @@
<?php
namespace api\controllers;
use yii\web\Controller;
/**
* Created by PhpStorm.
* User: iron
* Date: 2018/5/25
* Time: 16:42
*/
class SiteController extends Controller
{
public function actions() {
return [
'error' => [
'class' => 'yii\web\ErrorAction',
],
];
}
}

59
api/controllers/TestController.php

@ -0,0 +1,59 @@
<?php
/*
* The MIT License
*
* Copyright 2019 Blobt.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
namespace api\controllers;
/**
* @author iron
* @email weiriron@gmail.com
*/
use common\models\ars\Goods;
use common\models\searchs\GoodsSearch;
use yii\data\ActiveDataProvider;
use yii\db\ActiveRecord;
use yii\rest\ActiveController;
use yii\web\NotFoundHttpException;
class TestController extends ActiveController
{
public $modelClass = 'common\models\ars\Goods';
public function actions()
{
$action = parent::actions();
unset($action['index']);
return$action;
}
public function actionIndex()
{
return new ActiveDataProvider([
'query' => Goods::find(),
'pagination' => [
'pageSize' => 1,
],
]);
}
}

2
api/runtime/.gitignore

@ -0,0 +1,2 @@
*
!.gitignore

27
api/views/site/error.php

@ -0,0 +1,27 @@
<?php
/* @var $this yii\web\View */
/* @var $name string */
/* @var $message string */
/* @var $exception Exception */
use yii\helpers\Html;
$this->title = $name;
?>
<div class="site-error">
<h1><?= Html::encode($this->title) ?></h1>
<div class="alert alert-danger">
<?= nl2br(Html::encode($message)) ?>
</div>
<p>
The above error occurred while the Web server was processing your request.
</p>
<p>
Please contact us if you think this is a server error. Thank you.
</p>
</div>

5
api/web/.gitignore

@ -0,0 +1,5 @@
/index.php
/index-test.php
/robots.txt
uploads

2
api/web/assets/.gitignore

@ -0,0 +1,2 @@
*
!.gitignore

120
api/web/css/site.css

@ -0,0 +1,120 @@
html,
body {
height: 100%;
}
.wrap {
min-height: 100%;
height: auto;
margin: 0 auto -60px;
padding: 0 0 60px;
}
.wrap > .container {
padding: 70px 15px 20px;
}
.footer {
height: 60px;
background-color: #f5f5f5;
border-top: 1px solid #ddd;
padding-top: 20px;
}
.jumbotron {
text-align: center;
background-color: transparent;
}
.jumbotron .btn {
font-size: 21px;
padding: 14px 24px;
}
.not-set {
color: #c55;
font-style: italic;
}
/* add sorting icons to gridview sort links */
a.asc:after, a.desc:after {
position: relative;
top: 1px;
display: inline-block;
font-family: 'Glyphicons Halflings';
font-style: normal;
font-weight: normal;
line-height: 1;
padding-left: 5px;
}
a.asc:after {
content: /*"\e113"*/ "\e151";
}
a.desc:after {
content: /*"\e114"*/ "\e152";
}
.sort-numerical a.asc:after {
content: "\e153";
}
.sort-numerical a.desc:after {
content: "\e154";
}
.sort-ordinal a.asc:after {
content: "\e155";
}
.sort-ordinal a.desc:after {
content: "\e156";
}
.grid-view td {
white-space: nowrap;
}
.grid-view .filters input,
.grid-view .filters select {
min-width: 50px;
}
.hint-block {
display: block;
margin-top: 5px;
color: #999;
}
.error-summary {
color: #a94442;
background: #fdf7f7;
border-left: 3px solid #eed3d7;
padding: 10px 20px;
margin: 0 0 15px 0;
}
/* align the logout "link" (button in forms) of the navbar */
.nav li > form > button.logout {
padding: 15px;
border: none;
}
@media(max-width:767px) {
.nav li > form > button.logout {
display:block;
text-align: left;
width: 100%;
padding: 10px 15px;
}
}
.nav > li > form > button.logout:focus,
.nav > li > form > button.logout:hover {
text-decoration: none;
}
.nav > li > form > button.logout:focus {
outline: none;
}

BIN
api/web/favicon.ico

19
backend/views/layouts/sidebar.php

@ -15,22 +15,21 @@ use iron\widgets\Menu;
echo Menu::widget([ echo Menu::widget([
'items' => [ 'items' => [
// ['label' => 'MAIN NAVIGATION', 'is_header' => true], // ['label' => 'MAIN NAVIGATION', 'is_header' => true],
['label' => '商城管理', 'url' => '#', 'icon' => 'far fa-store', 'items' => [
['label' => '运营数据', 'url' => ['site/index', 'tag' => 'new']],
['label' => '基础配置', 'url' => ['config/index', 'tag' => 'new']],
['label' => '商城管理', 'url' => '#', 'icon' => 'fa-store', 'items' => [
['label' => '运营数据', 'url' => ['site/index']],
['label' => '基础配置', 'url' => ['config/index']],
] ]
], ],
['label' => '商品管理', 'url' => '#', 'icon' => 'far fa-archive', 'items' => [
['label' => '商品分类', 'url' => ['category/index', 'tag' => 'new']],
['label' => '商品列表', 'url' => ['goods/index']],
['label' => '属性管理', 'url' => ['attribute/index']],
['label' => '商品管理', 'url' => '#', 'icon' => 'fa-archive', 'items' => [
['label' => '商品分类', 'url' => ['/category']],
['label' => '商品列表', 'url' => ['/goods']],
['label' => '属性管理', 'url' => ['/attribute']],
] ]
], ],
['label' => '订单管理', 'url' => '#', 'icon' => 'far fa-list-alt', 'items' => [
['label' => '订单列表', 'url' => ['order/index', 'tag' => 'new']],
['label' => '订单管理', 'url' => '#', 'icon' => 'fa-list-alt', 'items' => [
['label' => '订单列表', 'url' => ['order/index']],
] ]
], ],
] ]
]); ]);
?> ?>

1
common/config/bootstrap.php

@ -2,3 +2,4 @@
Yii::setAlias('@common', dirname(__DIR__)); Yii::setAlias('@common', dirname(__DIR__));
Yii::setAlias('@console', dirname(dirname(__DIR__)) . '/console'); Yii::setAlias('@console', dirname(dirname(__DIR__)) . '/console');
Yii::setAlias('@backend', dirname(dirname(__DIR__)) . '/backend'); Yii::setAlias('@backend', dirname(dirname(__DIR__)) . '/backend');
Yii::setAlias('@api', dirname(dirname(__DIR__)) . '/api');

0
datadictionary.md

Loading…
Cancel
Save