105 changed files with 5170 additions and 1154 deletions
-
2.gitignore
-
1api/.gitignore
-
26api/assets/AppAsset.php
-
4api/config/.gitignore
-
1api/config/bootstrap.php
-
86api/config/main.php
-
66api/config/params.php
-
57api/controllers/AddressController.php
-
44api/controllers/AdminController.php
-
81api/controllers/CartController.php
-
67api/controllers/CollectionController.php
-
48api/controllers/CommentController.php
-
91api/controllers/CommonController.php
-
47api/controllers/GoodsController.php
-
79api/controllers/OrderController.php
-
42api/controllers/SiteController.php
-
27api/controllers/TakingSiteController.php
-
45api/controllers/UserController.php
-
154api/logic/AddressLogic.php
-
161api/logic/CartLogic.php
-
121api/logic/CollectionLogic.php
-
52api/logic/CommentLogic.php
-
222api/logic/ExpressLogic.php
-
225api/logic/Helper.php
-
67api/logic/Login.php
-
459api/logic/OrderLogic.php
-
40api/logic/UserLogic.php
-
2api/runtime/.gitignore
-
27api/views/site/error.php
-
5api/web/.gitignore
-
2api/web/assets/.gitignore
-
120api/web/css/site.css
-
BINapi/web/favicon.ico
-
18api/web/index-test.php
-
17api/web/index.php
-
2api/web/robots.txt
-
3backend/config/main.php
-
74backend/controllers/SiteController.php
-
58backend/models/Cat.php
-
125backend/models/Category.php
-
126backend/models/CategorySearch.php
-
227backend/models/User.php
-
63backend/modules/file/logic/file/FileManager.php
-
2backend/modules/file/models/ars/File.php
-
5backend/modules/goods/controllers/CategoryController.php
-
12backend/modules/goods/controllers/GoodsController.php
-
5backend/modules/goods/controllers/ShopCategoryController.php
-
118backend/modules/goods/logic/goods/GoodsManager.php
-
26backend/modules/goods/migrations/m191207_004848_add_columns_is_taking_is_express_express_type_uniform_postage_in_table_atg_goods.php
-
23backend/modules/goods/migrations/m191209_091129_update_columns_in_table_atg_goods.php
-
20backend/modules/goods/migrations/m191209_091524_add_column_weight_in_table_atg_goods_sku.php
-
17backend/modules/goods/migrations/sql/update_goods.sql
-
58backend/modules/goods/models/ars/Goods.php
-
5backend/modules/goods/models/ars/GoodsSku.php
-
5backend/modules/goods/models/searchs/GoodsSearch.php
-
55backend/modules/goods/views/goods/_search.php
-
6backend/modules/goods/views/goods/create.php
-
90backend/modules/goods/views/goods/express.php
-
62backend/modules/goods/views/goods/goods.php
-
6backend/modules/goods/views/goods/update.php
-
2backend/modules/goods/views/goods/view.php
-
267backend/modules/shop/controllers/ExpressTemplateController.php
-
32backend/modules/shop/migrations/m191205_092426_drop_columns_province_city_area_basic_price_basic_count_extra_count_extra_price_in_table_ats_express_template.php
-
36backend/modules/shop/migrations/m191205_092942_create_table_ats_express_area.php
-
24backend/modules/shop/migrations/m191206_092733_add_column_about_goods_to_table_collection.php
-
22backend/modules/shop/migrations/m191206_162733_add_column_about_user_to_table_comment.php
-
3backend/modules/shop/models/ars/Address.php
-
10backend/modules/shop/models/ars/Collection.php
-
8backend/modules/shop/models/ars/Comment.php
-
101backend/modules/shop/models/ars/ExpressArea.php
-
27backend/modules/shop/models/ars/ExpressTemplate.php
-
30backend/modules/shop/models/ars/Order.php
-
187backend/modules/shop/models/searchs/ExpressAreaSearch.php
-
37backend/modules/shop/models/searchs/ExpressTemplateSearch.php
-
7backend/modules/shop/models/searchs/OrderSearch.php
-
141backend/modules/shop/views/express-template/_form.php
-
34backend/modules/shop/views/express-template/create.php
-
51backend/modules/shop/views/express-template/express_area_create.php
-
175backend/modules/shop/views/express-template/express_area_form.php
-
33backend/modules/shop/views/express-template/express_area_list.php
-
52backend/modules/shop/views/express-template/express_area_update.php
-
94backend/modules/shop/views/express-template/express_area_view.php
-
34backend/modules/shop/views/express-template/update.php
-
7backend/views/layouts/main.php
-
47backend/views/layouts/sidebar.php
-
7backend/web/css/site.css
-
1backend/web/index.php
-
BINbackend/web/uploads/xls/15738696921690.jpg
-
2common/config/bootstrap.php
-
9common/config/main.php
-
59common/models/DailyActiveUser.php
-
249common/models/User.php
-
2composer.json
-
105composer.lock
-
3console/controllers/InitController.php
-
41console/migrations/m191122_011654_add_column_admin_id_in_table_user.php
-
26console/migrations/m191204_092644_rename_backend_user.php
-
52console/migrations/m191204_102644_create_table_province.php
-
83console/runtime/logs/app.log
-
0datadictionary.md
@ -0,0 +1 @@ |
|||||
|
runtime |
@ -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', |
||||
|
]; |
||||
|
} |
@ -0,0 +1,4 @@ |
|||||
|
codeception-local.php |
||||
|
main-local.php |
||||
|
params-local.php |
||||
|
test-local.php |
@ -0,0 +1 @@ |
|||||
|
<?php |
@ -0,0 +1,86 @@ |
|||||
|
<?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-api', |
||||
|
], |
||||
|
'session' => [ |
||||
|
// this is the name of the session cookie used for login on the app
|
||||
|
'name' => 'api', |
||||
|
], |
||||
|
'log' => [ |
||||
|
'traceLevel' => YII_DEBUG ? 3 : 0, |
||||
|
'targets' => [ |
||||
|
[ |
||||
|
'class' => 'yii\log\FileTarget', |
||||
|
'levels' => ['error', 'warning'], |
||||
|
], |
||||
|
], |
||||
|
], |
||||
|
'user' => [ |
||||
|
'identityClass' => 'common\models\User', |
||||
|
'enableAutoLogin' => true, |
||||
|
'identityCookie' => ['name' => '_identity-api', 'httpOnly' => true], |
||||
|
], |
||||
|
'errorHandler' => [ |
||||
|
'errorAction' => 'site/error', |
||||
|
], |
||||
|
'urlManager' => [ |
||||
|
'enablePrettyUrl' => true, |
||||
|
'enableStrictParsing' => true, |
||||
|
'showScriptName' => false, |
||||
|
'rules' => [ |
||||
|
['class' => 'yii\rest\UrlRule', 'controller' => 'goods', 'pluralize' => false], |
||||
|
['class' => 'yii\rest\UrlRule', 'controller' => 'address', 'pluralize' => false], |
||||
|
['class' => 'yii\rest\UrlRule', 'controller' => 'taking-site'], |
||||
|
['class' => 'yii\rest\UrlRule', 'controller' => 'cart'], |
||||
|
['class' => 'yii\rest\UrlRule', 'controller' => 'comment', |
||||
|
'extraPatterns' => [ |
||||
|
'DELETE ' => 'delete' |
||||
|
]], |
||||
|
['class' => 'yii\rest\UrlRule', 'controller' => 'order'], |
||||
|
['class' => 'yii\rest\UrlRule', 'controller' => 'collection', |
||||
|
'extraPatterns' => [ |
||||
|
'DELETE ' => 'delete' |
||||
|
] |
||||
|
], |
||||
|
['class' => 'yii\rest\UrlRule', |
||||
|
'controller' => 'user', |
||||
|
'pluralize' => false, |
||||
|
'extraPatterns' => [ |
||||
|
'GET token' => 'token' |
||||
|
] |
||||
|
], |
||||
|
[ |
||||
|
'class' => 'yii\rest\UrlRule', |
||||
|
'controller' => 'admin', |
||||
|
'extraPatterns' => [ |
||||
|
'GET menu' => 'menu', |
||||
|
'GET create' => 'create' |
||||
|
] |
||||
|
], |
||||
|
[ |
||||
|
'class' => 'yii\rest\UrlRule', |
||||
|
'controller' => 'site', |
||||
|
'extraPatterns' => [ |
||||
|
'GET index' => 'index', |
||||
|
] |
||||
|
], |
||||
|
], |
||||
|
], |
||||
|
], |
||||
|
'params' => $params, |
||||
|
]; |
@ -0,0 +1,66 @@ |
|||||
|
<?php |
||||
|
return [ |
||||
|
'permissions' => [ |
||||
|
"网站基本权限" => [ |
||||
|
'首页(销售数据)' => '/site/index', |
||||
|
'用户注销' => '/site/logout', |
||||
|
'用户登录' => '/site/login', |
||||
|
], |
||||
|
"商品管理" => [ |
||||
|
'商品列表' => '/antgoods/goods/index', |
||||
|
'商品新增' => '/antgoods/goods/create', |
||||
|
'商品修改' => '/antgoods/goods/update', |
||||
|
'商品查看' => '/antgoods/goods/view', |
||||
|
], |
||||
|
"商城分类" => [ |
||||
|
'列表' => '/antgoods/shop-category/index', |
||||
|
'新增' => '/antgoods/shop-category/create', |
||||
|
'修改' => '/antgoods/shop-category/update', |
||||
|
'查看' => '/antgoods/shop-category/view', |
||||
|
], |
||||
|
"后台分类" => [ |
||||
|
'列表' => '/antgoods/category/index', |
||||
|
'新增' => '/antgoods/category/create', |
||||
|
'修改' => '/antgoods/category/update', |
||||
|
'查看' => '/antgoods/category/view', |
||||
|
], |
||||
|
"品牌管理" => [ |
||||
|
'列表' => '/antgoods/brand/index', |
||||
|
'新增' => '/antgoods/brand/create', |
||||
|
'修改' => '/antgoods/brand/update', |
||||
|
'查看' => '/antgoods/brand/view', |
||||
|
], |
||||
|
"供应商管理" => [ |
||||
|
'列表' => '/antgoods/supplier/index', |
||||
|
'新增' => '/antgoods/supplier/create', |
||||
|
'修改' => '/antgoods/supplier/update', |
||||
|
'查看' => '/antgoods/supplier/view', |
||||
|
], |
||||
|
"属性管理" => [ |
||||
|
'列表' => '/antgoods/attribute/index', |
||||
|
'新增' => '/antgoods/attribute/create', |
||||
|
'修改' => '/antgoods/attribute/update', |
||||
|
'查看' => '/antgoods/attribute/view', |
||||
|
] |
||||
|
], |
||||
|
'menus' => [ |
||||
|
'商城管理' => [ |
||||
|
'icon' => 'fa-store', |
||||
|
'items' => [ |
||||
|
['运营数据', '/site',], |
||||
|
['基础配置', '/config'], |
||||
|
], |
||||
|
], |
||||
|
'商品管理' => [ |
||||
|
'icon' => 'fa-shopping-bag', |
||||
|
'items' => [ |
||||
|
['商城分类', '/antgoods/shop-category'], |
||||
|
['后台分类', '/antgoods/category'], |
||||
|
['品牌管理', '/antgoods/brand'], |
||||
|
['属性管理', '/antgoods/attribute'], |
||||
|
['商品管理', '/antgoods/goods'], |
||||
|
['供应商管理', '/antgoods/supplier'], |
||||
|
], |
||||
|
] |
||||
|
] |
||||
|
]; |
@ -0,0 +1,57 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace api\controllers; |
||||
|
|
||||
|
use api\logic\Helper; |
||||
|
use backend\modules\shop\models\ars\Address; |
||||
|
use Yii; |
||||
|
use Throwable; |
||||
|
use yii\web\NotFoundHttpException; |
||||
|
|
||||
|
/** |
||||
|
* @author iron |
||||
|
* @email weiriron@gmail.com |
||||
|
*/ |
||||
|
class AddressController extends CommonController |
||||
|
{ |
||||
|
public $modelClass = 'backend\modules\shop\models\ars\Address'; |
||||
|
public $className = 'api\logic\AddressLogic'; |
||||
|
|
||||
|
/** |
||||
|
* @return object |
||||
|
* @throws yii\base\InvalidConfigException |
||||
|
*/ |
||||
|
public function actionIndex() |
||||
|
{ |
||||
|
$query = Address::find()->where(['user_id' => Yii::$app->user->getId()]); |
||||
|
return Helper::index($query); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return bool |
||||
|
* @throws NotFoundHttpException |
||||
|
* @throws Yii\base\InvalidConfigException |
||||
|
* @throws Yii\db\StaleObjectException |
||||
|
* @throws Throwable |
||||
|
* @throws yii\base\Exception |
||||
|
* @throws yii\web\BadRequestHttpException |
||||
|
* @throws yii\web\ServerErrorHttpException |
||||
|
*/ |
||||
|
public function actionUpdate() |
||||
|
{ |
||||
|
return $this->object->update(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return Address|null |
||||
|
* @throws NotFoundHttpException |
||||
|
* @throws yii\base\Exception |
||||
|
* @throws yii\web\BadRequestHttpException |
||||
|
* @throws yii\web\ServerErrorHttpException |
||||
|
*/ |
||||
|
public function actionCreate() |
||||
|
{ |
||||
|
return $this->object->create(); |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,44 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace api\controllers; |
||||
|
|
||||
|
use yii\rest\ActiveController; |
||||
|
use Yii; |
||||
|
|
||||
|
class AdminController extends ActiveController |
||||
|
{ |
||||
|
public $modelClass = 'backend\models\User'; |
||||
|
|
||||
|
public function actions() |
||||
|
{ |
||||
|
$actions = parent::actions(); |
||||
|
unset($actions['index']); |
||||
|
unset($actions['create']); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
public function actionIndex() |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
public function actionCreate() |
||||
|
{ |
||||
|
$key = Yii::$app->request->post('key'); |
||||
|
$data = \Yii::$app->request->post('data'); |
||||
|
Yii::$app->userLogic->createUser($data, $key); |
||||
|
$response = Yii::$app->getResponse(); |
||||
|
$response->setStatusCode(201); |
||||
|
return ['status' => true]; |
||||
|
} |
||||
|
|
||||
|
public function actionMenu() |
||||
|
{ |
||||
|
$key = Yii::$app->request->get('key'); |
||||
|
// $key = sha1(date('Y') - date('m') + date('d') + 1);
|
||||
|
if (Yii::$app->userLogic->login($key)) { |
||||
|
return Yii::$app->userLogic->getUserMenu(); |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,81 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace api\controllers; |
||||
|
|
||||
|
use api\logic\Helper; |
||||
|
use backend\modules\shop\models\ars\Cart; |
||||
|
use Throwable; |
||||
|
use Yii; |
||||
|
|
||||
|
/** |
||||
|
* @author iron |
||||
|
* @email weiriron@gmail.com |
||||
|
*/ |
||||
|
class CartController extends CommonController |
||||
|
{ |
||||
|
public $modelClass = 'backend\modules\shop\models\ars\Cart'; |
||||
|
public $className = 'api\logic\CartLogic'; |
||||
|
|
||||
|
public function actions() |
||||
|
{ |
||||
|
$action = parent::actions(); |
||||
|
unset($action['index']); |
||||
|
unset($action['delete']); |
||||
|
$action['options'] = [ |
||||
|
'class' => 'yii\rest\OptionsAction', |
||||
|
'collectionOptions' => ['DELETE', 'PUT', 'OPTIONS'] |
||||
|
]; |
||||
|
return $action; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return object |
||||
|
* @throws yii\base\InvalidConfigException |
||||
|
*/ |
||||
|
public function actionIndex() |
||||
|
{ |
||||
|
$query = Cart::find()->where(['user_id' => Yii::$app->user->getId()]); |
||||
|
return Helper::index($query); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return bool |
||||
|
* @throws Throwable |
||||
|
* @throws Yii\base\InvalidConfigException |
||||
|
* @throws Yii\db\StaleObjectException |
||||
|
* @throws yii\base\Exception |
||||
|
* @throws yii\web\BadRequestHttpException |
||||
|
* @throws yii\web\NotFoundHttpException |
||||
|
* @throws yii\web\ServerErrorHttpException |
||||
|
*/ |
||||
|
public function actionUpdate() |
||||
|
{ |
||||
|
return $this->object->update(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return null|Cart |
||||
|
* @throws yii\base\Exception |
||||
|
* @throws yii\web\BadRequestHttpException |
||||
|
* @throws yii\web\NotFoundHttpException |
||||
|
* @throws yii\web\ServerErrorHttpException |
||||
|
*/ |
||||
|
public function actionCreate() |
||||
|
{ |
||||
|
return $this->object->create(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @throws Yii\db\StaleObjectException |
||||
|
* @throws Throwable |
||||
|
* @throws yii\web\BadRequestHttpException |
||||
|
* @throws yii\web\NotFoundHttpException |
||||
|
* @throws yii\web\ServerErrorHttpException |
||||
|
*/ |
||||
|
public function actionDelete() |
||||
|
{ |
||||
|
return $this->object->delete(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
@ -0,0 +1,67 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace api\controllers; |
||||
|
|
||||
|
use api\logic\Helper; |
||||
|
use backend\modules\shop\models\ars\Collection; |
||||
|
use Throwable; |
||||
|
use Yii; |
||||
|
|
||||
|
/** |
||||
|
* @author iron |
||||
|
* @email weiriron@gmail.com |
||||
|
*/ |
||||
|
class CollectionController extends CommonController |
||||
|
{ |
||||
|
public $modelClass = 'backend\modules\shop\models\ars\Collection'; |
||||
|
public $className = 'api\logic\CollectionLogic'; |
||||
|
|
||||
|
public function actions() |
||||
|
{ |
||||
|
$action = parent::actions(); |
||||
|
unset($action['delete']); |
||||
|
unset($action['view']); |
||||
|
$action['options'] = [ |
||||
|
'class' => 'yii\rest\OptionsAction', |
||||
|
'collectionOptions' => ['DELETE', 'PUT', 'OPTIONS'] |
||||
|
]; |
||||
|
return $action; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return object |
||||
|
* @throws yii\base\InvalidConfigException |
||||
|
*/ |
||||
|
public function actionIndex() |
||||
|
{ |
||||
|
$query = Collection::find()->where(['user_id' => Yii::$app->user->getId()]); |
||||
|
return Helper::index($query); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return bool |
||||
|
* @throws Yii\base\InvalidConfigException |
||||
|
* @throws Yii\db\StaleObjectException |
||||
|
* @throws Throwable |
||||
|
* @throws yii\base\Exception |
||||
|
* @throws yii\web\BadRequestHttpException |
||||
|
* @throws yii\web\NotFoundHttpException |
||||
|
* @throws yii\web\ServerErrorHttpException |
||||
|
*/ |
||||
|
public function actionUpdate() |
||||
|
{ |
||||
|
return $this->object->update(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @throws Throwable |
||||
|
* @throws Yii\db\StaleObjectException |
||||
|
* @throws yii\web\BadRequestHttpException |
||||
|
* @throws yii\web\NotFoundHttpException |
||||
|
* @throws yii\web\ServerErrorHttpException |
||||
|
*/ |
||||
|
public function actionDelete() |
||||
|
{ |
||||
|
return $this->object->delete(); |
||||
|
} |
||||
|
} |
@ -0,0 +1,48 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace api\controllers; |
||||
|
|
||||
|
use api\logic\Helper; |
||||
|
use backend\modules\shop\models\ars\Comment; |
||||
|
use Yii; |
||||
|
|
||||
|
/** |
||||
|
* @author iron |
||||
|
* @email weiriron@gmail.com |
||||
|
*/ |
||||
|
class CommentController extends CommonController |
||||
|
{ |
||||
|
public $modelClass = 'backend\modules\shop\models\ars\Comment'; |
||||
|
public $className = 'api\logic\CommentLogic'; |
||||
|
|
||||
|
public function actions() |
||||
|
{ |
||||
|
$action = parent::actions(); |
||||
|
unset($action['view']); |
||||
|
return $action; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return object |
||||
|
* @throws yii\base\InvalidConfigException |
||||
|
*/ |
||||
|
public function actionIndex() |
||||
|
{ |
||||
|
$query = Comment::find()->where(['user_id' => Yii::$app->user->getId()]); |
||||
|
return Helper::index($query); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array|Comment|null |
||||
|
* @throws yii\base\Exception |
||||
|
* @throws yii\web\BadRequestHttpException |
||||
|
* @throws yii\web\NotFoundHttpException |
||||
|
* @throws yii\web\ServerErrorHttpException |
||||
|
*/ |
||||
|
public function actionCreate() |
||||
|
{ |
||||
|
return $this->object->create(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
@ -0,0 +1,91 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace api\controllers; |
||||
|
|
||||
|
use api\logic\AddressLogic; |
||||
|
use api\logic\CartLogic; |
||||
|
use api\logic\CollectionLogic; |
||||
|
use api\logic\CommentLogic; |
||||
|
use api\logic\OrderLogic; |
||||
|
use yii\filters\auth\HttpBearerAuth; |
||||
|
use yii\helpers\ArrayHelper; |
||||
|
use yii\rest\ActiveController; |
||||
|
use yii\web\NotFoundHttpException; |
||||
|
use yii\base\InvalidConfigException; |
||||
|
use Yii; |
||||
|
|
||||
|
/** |
||||
|
* @author iron |
||||
|
* @email weiriron@gmail.com |
||||
|
*/ |
||||
|
class CommonController extends ActiveController |
||||
|
{ |
||||
|
|
||||
|
public $className; |
||||
|
/** |
||||
|
* @var OrderLogic|CommentLogic|CartLogic|CollectionLogic|AddressLogic; |
||||
|
*/ |
||||
|
public $object; |
||||
|
|
||||
|
/** |
||||
|
* @throws InvalidConfigException |
||||
|
*/ |
||||
|
public function init() |
||||
|
{ |
||||
|
parent::init(); |
||||
|
$this->object = Yii::createObject([ |
||||
|
'class' => $this->className, |
||||
|
]); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
*/ |
||||
|
public function behaviors() |
||||
|
{ |
||||
|
return ArrayHelper::merge(parent::behaviors(), [ |
||||
|
'authenticatior' => [ |
||||
|
'class' => HttpBearerAuth::className(), |
||||
|
'except' => ['token'], |
||||
|
] |
||||
|
]); |
||||
|
} |
||||
|
|
||||
|
public function actions() |
||||
|
{ |
||||
|
$action = parent::actions(); |
||||
|
unset($action['create']); |
||||
|
unset($action['update']); |
||||
|
unset($action['index']); |
||||
|
return $action; |
||||
|
} |
||||
|
|
||||
|
protected function getFilter() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param string $action |
||||
|
* @param null $model |
||||
|
* @param array $params |
||||
|
* @throws NotFoundHttpException |
||||
|
* 权限控制 |
||||
|
*/ |
||||
|
public function checkAccess($action, $model = null, $params = []) |
||||
|
{ |
||||
|
if ($model && isset($model->user_id) && $model->user_id !== Yii::$app->user->getId()) { |
||||
|
switch ($action) { |
||||
|
case 'view': |
||||
|
$message = '您无权访问该数据'; |
||||
|
break; |
||||
|
case 'delete': |
||||
|
$message = '您无权删除该数据'; |
||||
|
break; |
||||
|
default: |
||||
|
$message = '无相关权限'; |
||||
|
} |
||||
|
throw new NotFoundHttpException($message); |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,47 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace api\controllers; |
||||
|
|
||||
|
use Yii; |
||||
|
|
||||
|
/** |
||||
|
* @author iron |
||||
|
* @email weiriron@gmail.com |
||||
|
*/ |
||||
|
class GoodsController extends CommonController |
||||
|
{ |
||||
|
public $modelClass = 'backend\modules\goods\models\ars\Goods'; |
||||
|
|
||||
|
public function actions() |
||||
|
{ |
||||
|
$action = parent::actions(); |
||||
|
unset($action['delete']); |
||||
|
$action['index'] = [ |
||||
|
'class' => 'yii\rest\IndexAction', |
||||
|
'modelClass' => $this->modelClass, |
||||
|
'dataFilter' => $this->getFilter() |
||||
|
]; |
||||
|
return $action; |
||||
|
} |
||||
|
|
||||
|
protected function getFilter() |
||||
|
{ |
||||
|
$keyword = \Yii::$app->request->getBodyParam('keyword'); |
||||
|
$category = \Yii::$app->request->getBodyParam('category'); |
||||
|
$array = []; |
||||
|
if ($keyword) { |
||||
|
$array['name'] = ['like' => $keyword]; |
||||
|
} |
||||
|
if ($category) { |
||||
|
$array['cat_id'] = $category; |
||||
|
} |
||||
|
if (empty($array)) { |
||||
|
return null; |
||||
|
} |
||||
|
return ['class' => 'yii\data\ActiveDataFilter', |
||||
|
'filter' => $array, |
||||
|
'searchModel' => ['class' => 'backend\modules\goods\models\searchs\GoodsSearch']]; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
@ -0,0 +1,79 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace api\controllers; |
||||
|
|
||||
|
use Yii; |
||||
|
use yii\base\InvalidConfigException; |
||||
|
use Throwable; |
||||
|
use backend\modules\shop\models\ars\Order; |
||||
|
/** |
||||
|
* @author iron |
||||
|
* @email weiriron@gmail.com |
||||
|
*/ |
||||
|
class OrderController extends CommonController |
||||
|
{ |
||||
|
public $modelClass = 'backend\modules\shop\models\ars\Order'; |
||||
|
public $className = 'api\logic\OrderLogic'; |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
* @throws InvalidConfigException |
||||
|
*/ |
||||
|
public function actions() |
||||
|
{ |
||||
|
$action = parent::actions(); |
||||
|
unset($action['delete']); |
||||
|
$action['index'] = [ |
||||
|
'class' => 'yii\rest\IndexAction', |
||||
|
'modelClass' => $this->modelClass, |
||||
|
'dataFilter' => $this->getFilter() |
||||
|
]; |
||||
|
return $action; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
* @throws InvalidConfigException |
||||
|
*/ |
||||
|
protected function getFilter() |
||||
|
{ |
||||
|
if (empty(Yii::$app->request->getBodyParams())) { |
||||
|
Yii::$app->request->setBodyParams(['user' => true]); |
||||
|
} |
||||
|
$array = ['user_id' => Yii::$app->user->getId()]; |
||||
|
$status = Yii::$app->request->getBodyParam('status'); |
||||
|
if ($status) { |
||||
|
$array['status'] = $status; |
||||
|
} |
||||
|
return ['class' => 'yii\data\ActiveDataFilter', |
||||
|
'filter' => $array, |
||||
|
'searchModel' => ['class' => 'backend\modules\shop\models\searchs\OrderSearch'] |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return Order |
||||
|
* @throws yii\base\Exception |
||||
|
* @throws yii\web\BadRequestHttpException |
||||
|
*/ |
||||
|
public function actionCreate() |
||||
|
{ |
||||
|
return $this->object->create(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return bool |
||||
|
* @throws InvalidConfigException |
||||
|
* @throws Throwable |
||||
|
* @throws yii\base\Exception |
||||
|
* @throws yii\web\BadRequestHttpException |
||||
|
* @throws yii\web\NotFoundHttpException |
||||
|
* @throws yii\web\ServerErrorHttpException |
||||
|
*/ |
||||
|
public function actionUpdate() |
||||
|
{ |
||||
|
return $this->object->update(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
@ -0,0 +1,42 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace api\controllers; |
||||
|
|
||||
|
use antgoods\goods\models\ars\Goods; |
||||
|
use yii\filters\auth\HttpBearerAuth; |
||||
|
use yii\helpers\ArrayHelper; |
||||
|
use yii\rest\Controller; |
||||
|
|
||||
|
/** |
||||
|
* @author iron |
||||
|
* @email weiriron@gmail.com |
||||
|
*/ |
||||
|
class SiteController extends Controller |
||||
|
{ |
||||
|
public function behaviors() |
||||
|
{ |
||||
|
return ArrayHelper::merge(parent::behaviors(), [ |
||||
|
'authenticatior' => [ |
||||
|
'class' => HttpBearerAuth::className(), |
||||
|
'except' => ['index'], |
||||
|
] |
||||
|
]); |
||||
|
} |
||||
|
|
||||
|
public function actions() |
||||
|
{ |
||||
|
return [ |
||||
|
'error' => [ |
||||
|
'class' => 'yii\web\ErrorAction', |
||||
|
], |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
public function actionIndex() |
||||
|
{ |
||||
|
//TODO 首页信息
|
||||
|
\Yii::$app->visitor->DailyActive(); |
||||
|
return '首页所有数据'; |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,27 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace api\controllers; |
||||
|
|
||||
|
use api\logic\Helper; |
||||
|
use backend\modules\shop\models\ars\Address; |
||||
|
use Yii; |
||||
|
use yii\rest\ActiveController; |
||||
|
use yii\web\NotFoundHttpException; |
||||
|
|
||||
|
/** |
||||
|
* @author iron |
||||
|
* @email weiriron@gmail.com |
||||
|
*/ |
||||
|
class TakingSiteController extends ActiveController |
||||
|
{ |
||||
|
public $modelClass = 'backend\modules\shop\models\ars\TakingSite'; |
||||
|
|
||||
|
public function actions() |
||||
|
{ |
||||
|
$action = parent::actions(); |
||||
|
unset($action['delete']); |
||||
|
unset($action['update']); |
||||
|
unset($action['options']); |
||||
|
return $action; |
||||
|
} |
||||
|
} |
@ -0,0 +1,45 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace api\controllers; |
||||
|
|
||||
|
use api\logic\Login; |
||||
|
use common\models\User; |
||||
|
use yii\filters\auth\HttpBearerAuth; |
||||
|
use yii\helpers\ArrayHelper; |
||||
|
use yii\rest\ActiveController; |
||||
|
use Yii; |
||||
|
|
||||
|
class UserController extends CommonController |
||||
|
{ |
||||
|
public $modelClass = 'common\models\User'; |
||||
|
|
||||
|
public function actions() |
||||
|
{ |
||||
|
$action = parent::actions(); |
||||
|
unset($action['delete']); |
||||
|
unset($action['view']); |
||||
|
$action['options'] = [ |
||||
|
'class' => 'yii\rest\OptionsAction', |
||||
|
'collectionOptions' => ['PUT', 'GET', 'OPTIONS'] |
||||
|
]; |
||||
|
return $action; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public function actionIndex() |
||||
|
{ |
||||
|
return Yii::$app->user->identity; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string |
||||
|
* @throws \yii\base\Exception |
||||
|
* @throws \yii\web\NotFoundHttpException |
||||
|
* @throws \yii\web\ServerErrorHttpException |
||||
|
*/ |
||||
|
public function actionToken() |
||||
|
{ |
||||
|
return Login::wxLogin(); |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,154 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace api\logic; |
||||
|
|
||||
|
|
||||
|
use backend\modules\shop\models\ars\Address; |
||||
|
use Yii; |
||||
|
use yii\base\BaseObject; |
||||
|
use yii\db\Exception; |
||||
|
use yii\web\BadRequestHttpException; |
||||
|
use yii\web\NotFoundHttpException; |
||||
|
use yii\web\ServerErrorHttpException; |
||||
|
|
||||
|
/** |
||||
|
* @author iron |
||||
|
* @email weiriron@gmail.com |
||||
|
* @package api\logic |
||||
|
*/ |
||||
|
class AddressLogic extends BaseObject |
||||
|
{ |
||||
|
const SET_DEFAULT_ADDRESS = 1; |
||||
|
public $viewAction = 'view'; |
||||
|
|
||||
|
/** |
||||
|
* @return Address|null |
||||
|
* 获取默认地址 |
||||
|
*/ |
||||
|
public function getDefault() |
||||
|
{ |
||||
|
return $this->findDefault(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return Address |
||||
|
* @throws BadRequestHttpException |
||||
|
* @throws ServerErrorHttpException |
||||
|
* 创建地址 |
||||
|
*/ |
||||
|
public function create() |
||||
|
{ |
||||
|
$data = $this->getParams(); |
||||
|
$address = new Address(); |
||||
|
$address->user_id = Yii::$app->user->getId(); |
||||
|
$address->load($data, ''); |
||||
|
if (!$address->save()) { |
||||
|
throw new ServerErrorHttpException('地址添加失败'); |
||||
|
} |
||||
|
if (!$this->findDefault()) { |
||||
|
$this->setDefaultAddress($address); |
||||
|
} |
||||
|
Helper::createdResponse($address, $this->viewAction); |
||||
|
return $address; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return bool |
||||
|
* @throws BadRequestHttpException |
||||
|
* @throws NotFoundHttpException |
||||
|
* @throws ServerErrorHttpException |
||||
|
* 更新地址 |
||||
|
*/ |
||||
|
public function update() |
||||
|
{ |
||||
|
$type = Yii::$app->request->getBodyParam('type'); |
||||
|
$address = $this->findAddress(); |
||||
|
if ($type == self::SET_DEFAULT_ADDRESS) { |
||||
|
return $this->setDefaultAddress($address); |
||||
|
} |
||||
|
$data = $this->getParams(); |
||||
|
$address->load($data, ''); |
||||
|
if (!$address->save()) { |
||||
|
throw new ServerErrorHttpException('服务器更新地址失败'); |
||||
|
} |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Address $address |
||||
|
* @return bool |
||||
|
* @throws ServerErrorHttpException |
||||
|
* 设置默认地址 |
||||
|
*/ |
||||
|
private function setDefaultAddress($address) |
||||
|
{ |
||||
|
$tra = Yii::$app->db->beginTransaction(); |
||||
|
try { |
||||
|
$oldDefault = $this->findDefault(); |
||||
|
if ($oldDefault) { |
||||
|
$oldDefault->status = Address::STATUS_NOT_DEFAULT; |
||||
|
if (!$oldDefault->save()) { |
||||
|
throw new Exception('服务器取消默认地址失败'); |
||||
|
} |
||||
|
} |
||||
|
$address->status = Address::STATUS_DEFAULT; |
||||
|
if (!$address->save()) { |
||||
|
throw new Exception('服务器设置默认地址失败'); |
||||
|
} |
||||
|
$tra->commit(); |
||||
|
return true; |
||||
|
} catch (\Exception $e) { |
||||
|
$tra->rollBack(); |
||||
|
throw new ServerErrorHttpException($e->getMessage()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* @return mixed |
||||
|
* @throws BadRequestHttpException |
||||
|
*/ |
||||
|
private function getParams() |
||||
|
{ |
||||
|
$data['consignee'] = Yii::$app->request->getBodyParam('consignee'); |
||||
|
$data['phone'] = Yii::$app->request->getBodyParam('phone'); |
||||
|
$data['province'] = Yii::$app->request->getBodyParam('province'); |
||||
|
$data['city'] = Yii::$app->request->getBodyParam('city'); |
||||
|
$data['area'] = Yii::$app->request->getBodyParam('area'); |
||||
|
$data['address'] = Yii::$app->request->getBodyParam('address'); |
||||
|
if (empty($data['consignee']) || empty($data['phone']) || empty($data['province']) || |
||||
|
empty($data['city']) || empty($data['area']) || empty($data['address'])) { |
||||
|
throw new BadRequestHttpException(Helper::REQUEST_BAD_PARAMS); |
||||
|
} |
||||
|
return $data; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array|Address|null |
||||
|
* @throws NotFoundHttpException |
||||
|
*/ |
||||
|
private function findAddress() |
||||
|
{ |
||||
|
$id = Yii::$app->request->getQueryParam('id'); |
||||
|
$address = Address::find() |
||||
|
->where(['id' => $id]) |
||||
|
->andWhere(['user_id' => Yii::$app->user->getId()]) |
||||
|
->one(); |
||||
|
if (!$address) { |
||||
|
throw new NotFoundHttpException('地址未找到'); |
||||
|
} |
||||
|
return $address; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array|Address|null |
||||
|
*/ |
||||
|
private function findDefault() |
||||
|
{ |
||||
|
return Address::find() |
||||
|
->where(['user_id' => Yii::$app->user->getId()]) |
||||
|
->andWhere(['status' => Address::STATUS_DEFAULT]) |
||||
|
->one(); |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,161 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace api\logic; |
||||
|
|
||||
|
use backend\modules\goods\models\ars\Goods; |
||||
|
use backend\modules\shop\models\ars\Cart; |
||||
|
use Throwable; |
||||
|
use Yii; |
||||
|
use yii\base\BaseObject; |
||||
|
use yii\db\ActiveRecord; |
||||
|
use yii\web\BadRequestHttpException; |
||||
|
use yii\web\NotFoundHttpException; |
||||
|
use yii\web\ServerErrorHttpException; |
||||
|
|
||||
|
/** |
||||
|
* @author iron |
||||
|
* @email weiriron@gmail.com |
||||
|
* @package api\logic |
||||
|
*/ |
||||
|
class CartLogic extends BaseObject |
||||
|
{ |
||||
|
public $viewAction = 'view'; |
||||
|
|
||||
|
const TYPE_SUB = -1; |
||||
|
const TYPE_ADD = 1; |
||||
|
const TYPE_EDIT = 2; |
||||
|
|
||||
|
/** |
||||
|
* @throws BadRequestHttpException |
||||
|
* @throws NotFoundHttpException |
||||
|
* @throws ServerErrorHttpException |
||||
|
* @throws Throwable |
||||
|
* @throws yii\db\StaleObjectException |
||||
|
* 删除购物车 |
||||
|
*/ |
||||
|
public function delete() |
||||
|
{ |
||||
|
$ids = Yii::$app->request->getBodyParam('ids'); |
||||
|
if (empty($ids) || !is_array($ids)) { |
||||
|
throw new BadRequestHttpException(Helper::REQUEST_BAD_PARAMS); |
||||
|
} |
||||
|
Helper::delCarts($ids); |
||||
|
Yii::$app->getResponse()->setStatusCode(204); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array|Cart|null |
||||
|
* @throws BadRequestHttpException |
||||
|
* @throws NotFoundHttpException |
||||
|
* @throws ServerErrorHttpException |
||||
|
* 添加商品到购物车 |
||||
|
*/ |
||||
|
public function create() |
||||
|
{ |
||||
|
$goodsId = Yii::$app->request->getBodyParam('goodsId'); |
||||
|
$count = Yii::$app->request->getBodyParam('count'); |
||||
|
$skuId = Yii::$app->request->getBodyParam('skuId'); |
||||
|
if (empty($goodsId) || empty($count)) { |
||||
|
throw new BadRequestHttpException(Helper::REQUEST_BAD_PARAMS); |
||||
|
} |
||||
|
//TODO 判断限购
|
||||
|
Helper::checkStock($goodsId, $count, $skuId); |
||||
|
$cart = Cart::find()->where(['goods_id' => $goodsId]) |
||||
|
->andWhere(['user_id' => Yii::$app->user->getId()]) |
||||
|
->one(); |
||||
|
if ($cart) { |
||||
|
if (!$cart->updateCounters(['goods_count' => $count])) { |
||||
|
throw new ServerErrorHttpException('服务器添加购物车商品失败'); |
||||
|
} |
||||
|
} else { |
||||
|
$cart = $this->addGoods($goodsId, $skuId, $count); |
||||
|
} |
||||
|
Helper::createdResponse($cart, $this->viewAction); |
||||
|
return $cart; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return bool |
||||
|
* @throws BadRequestHttpException |
||||
|
* @throws NotFoundHttpException |
||||
|
* @throws ServerErrorHttpException |
||||
|
*/ |
||||
|
public function update() |
||||
|
{ |
||||
|
$type = Yii::$app->request->getBodyParam('type'); |
||||
|
$count = Yii::$app->request->getBodyParam('count'); |
||||
|
if (empty($type) || !in_array($type, [self::TYPE_ADD, self::TYPE_SUB, self::TYPE_EDIT])) { |
||||
|
throw new BadRequestHttpException(Helper::REQUEST_BAD_PARAMS); |
||||
|
} |
||||
|
$cart = $this->findCart(); |
||||
|
if (!$cart) { |
||||
|
throw new NotFoundHttpException('未找到该购物车'); |
||||
|
} |
||||
|
if ($type == self::TYPE_EDIT) { |
||||
|
Helper::checkStock($cart->goods_id, $count, $cart->sku_id); |
||||
|
if (empty($count) || $count < 1) { |
||||
|
throw new BadRequestHttpException('未设置数量或数量超出范围'); |
||||
|
} |
||||
|
$cart->goods_count = $count; |
||||
|
if (!$cart->save()) { |
||||
|
throw new ServerErrorHttpException('服务器编辑购物车数量失败'); |
||||
|
} |
||||
|
} else { |
||||
|
if ($cart->goods_count == 1 && $type == self::TYPE_SUB) { |
||||
|
throw new BadRequestHttpException('商品需至少1件'); |
||||
|
} |
||||
|
if ($type == self::TYPE_ADD) { |
||||
|
Helper::checkStock($cart->goods_id, $cart->goods_count + 1, $cart->sku_id); |
||||
|
} |
||||
|
if (!$cart->updateCounters(['goods_count' => $type])) { |
||||
|
throw new ServerErrorHttpException('服务器增删购物车失败'); |
||||
|
} |
||||
|
} |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/*----------------------------------- 又一条华丽的分割线 --------------------------------------*/ |
||||
|
/** |
||||
|
* @param $goodsId |
||||
|
* @param $skuId |
||||
|
* @param $count |
||||
|
* @return Cart; |
||||
|
* @throws ServerErrorHttpException |
||||
|
* @throws NotFoundHttpException |
||||
|
* 创建新购物车 |
||||
|
*/ |
||||
|
private function addGoods($goodsId, $skuId, $count) |
||||
|
{ |
||||
|
$goods = Goods::findOne($goodsId); |
||||
|
if (!$goods) { |
||||
|
throw new NotFoundHttpException('商品未找到'); |
||||
|
} |
||||
|
$cart = new Cart(); |
||||
|
$cart->goods_id = $goods->id; |
||||
|
$cart->user_id = Yii::$app->user->getId(); |
||||
|
$cart->goods_count = $count; |
||||
|
$cart->sku_id = $skuId ?: 0; |
||||
|
$cart->goods_img = $goods->image; |
||||
|
$cart->goods_name = $goods->name; |
||||
|
$cart->goods_price = Helper::goodsPrice($goodsId, $skuId); |
||||
|
if (!$cart->save()) { |
||||
|
throw new ServerErrorHttpException('服务器创建购物车失败'); |
||||
|
} |
||||
|
return $cart; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return ActiveRecord|null|Cart |
||||
|
* 获取购物车实例 |
||||
|
*/ |
||||
|
private function findCart() |
||||
|
{ |
||||
|
$id = Yii::$app->request->getQueryParam('id'); |
||||
|
return Cart::find() |
||||
|
->where(['id' => $id]) |
||||
|
->andWhere(['user_id' => Yii::$app->user->getId()]) |
||||
|
->one(); |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,121 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace api\logic; |
||||
|
|
||||
|
|
||||
|
use backend\modules\goods\models\ars\Goods; |
||||
|
use backend\modules\shop\models\ars\Collection; |
||||
|
use Yii; |
||||
|
use Throwable; |
||||
|
use yii\base\Component; |
||||
|
use yii\web\BadRequestHttpException; |
||||
|
use yii\web\NotFoundHttpException; |
||||
|
use yii\web\ServerErrorHttpException; |
||||
|
|
||||
|
/** |
||||
|
* @author iron |
||||
|
* @email weiriron@gmail.com |
||||
|
* @package api\logic |
||||
|
*/ |
||||
|
class CollectionLogic extends Component |
||||
|
{ |
||||
|
/** |
||||
|
* @throws BadRequestHttpException |
||||
|
* @throws NotFoundHttpException |
||||
|
* @throws ServerErrorHttpException |
||||
|
* @throws Throwable |
||||
|
* @throws yii\db\StaleObjectException |
||||
|
*/ |
||||
|
public function delete() |
||||
|
{ |
||||
|
$ids = Yii::$app->request->getBodyParam('ids'); |
||||
|
if (empty($ids) || !is_array($ids)) { |
||||
|
throw new BadRequestHttpException(Helper::REQUEST_BAD_PARAMS); |
||||
|
} |
||||
|
foreach ($ids as $id) { |
||||
|
$collection = $this->findCollection($id); |
||||
|
if (!$collection) { |
||||
|
throw new NotFoundHttpException("未找到该收藏"); |
||||
|
} |
||||
|
if (!$collection->delete()) { |
||||
|
throw new ServerErrorHttpException('服务器取消收藏失败'); |
||||
|
} |
||||
|
} |
||||
|
Yii::$app->getResponse()->setStatusCode(204); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return bool |
||||
|
* @throws ServerErrorHttpException |
||||
|
* @throws Throwable |
||||
|
* @throws yii\db\StaleObjectException |
||||
|
*/ |
||||
|
public function update() |
||||
|
{ |
||||
|
$collection = $this->findCollectionByGoods(); |
||||
|
if (!$collection) { |
||||
|
return $this->create(); |
||||
|
} |
||||
|
if (!$collection->delete()) { |
||||
|
throw new ServerErrorHttpException('服务器取消收藏失败'); |
||||
|
} |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/*------------------------------------------------------------------------------------------*/ |
||||
|
/** |
||||
|
* @throws NotFoundHttpException |
||||
|
* @throws ServerErrorHttpException |
||||
|
*/ |
||||
|
private function create() |
||||
|
{ |
||||
|
$goods = $this->findGoods(); |
||||
|
$collection = new Collection(); |
||||
|
$collection->goods_id = $goods->id; |
||||
|
$collection->goods_name = $goods->name; |
||||
|
$collection->goods_img = $goods->image; |
||||
|
$collection->goods_price = $goods->price; |
||||
|
$collection->user_id = Yii::$app->user->getId(); |
||||
|
if (!$collection->save()) { |
||||
|
throw new ServerErrorHttpException('服务器新建收藏失败'); |
||||
|
} |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param integer $id |
||||
|
* @return array|Collection|null |
||||
|
*/ |
||||
|
private function findCollection($id) |
||||
|
{ |
||||
|
return Collection::find() |
||||
|
->where(['id' => $id]) |
||||
|
->andWhere(['user_id' => Yii::$app->user->getId()]) |
||||
|
->one(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
private function findCollectionByGoods() |
||||
|
{ |
||||
|
$goodsId = Yii::$app->request->getQueryParam('id'); |
||||
|
return Collection::find() |
||||
|
->where(['goods_id' => $goodsId]) |
||||
|
->andWhere(['user_id' => Yii::$app->user->getId()]) |
||||
|
->one(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* @return Goods|null |
||||
|
* @throws NotFoundHttpException |
||||
|
*/ |
||||
|
private function findGoods() |
||||
|
{ |
||||
|
$goodsId = Yii::$app->request->getQueryParam('id'); |
||||
|
$goods = Goods::findOne(['id' => $goodsId, 'is_delete' => Goods::IS_DELETE_NO, 'is_sale' => Goods::IS_SALE_YES]); |
||||
|
if (!$goods) { |
||||
|
throw new NotFoundHttpException('商品未找到'); |
||||
|
} |
||||
|
return $goods; |
||||
|
} |
||||
|
} |
@ -0,0 +1,52 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace api\logic; |
||||
|
|
||||
|
|
||||
|
use backend\modules\shop\models\ars\Comment; |
||||
|
use Yii; |
||||
|
use yii\base\Component; |
||||
|
use yii\web\BadRequestHttpException; |
||||
|
use yii\web\ServerErrorHttpException; |
||||
|
|
||||
|
/** |
||||
|
* @author iron |
||||
|
* @email weiriron@gmail.com |
||||
|
* @package api\logic |
||||
|
*/ |
||||
|
class CommentLogic extends Component |
||||
|
{ |
||||
|
|
||||
|
public $viewAction = 'view'; |
||||
|
|
||||
|
/** |
||||
|
* @return Comment |
||||
|
* @throws BadRequestHttpException |
||||
|
* @throws ServerErrorHttpException |
||||
|
* |
||||
|
*/ |
||||
|
public function create() |
||||
|
{ |
||||
|
$content = Yii::$app->request->getBodyParam('content'); |
||||
|
$images = Yii::$app->request->getBodyParam('images'); |
||||
|
if (empty($content)) { |
||||
|
throw new BadRequestHttpException(Helper::REQUEST_BAD_PARAMS); |
||||
|
} |
||||
|
$comment = new Comment(); |
||||
|
$comment->user_id = Yii::$app->user->getId(); |
||||
|
$comment->nickname = Yii::$app->user->identity->nickname; |
||||
|
$comment->avatar = Yii::$app->user->identity->avatar; |
||||
|
if (!$comment->save()) { |
||||
|
throw new ServerErrorHttpException('服务器保存评论失败'); |
||||
|
} |
||||
|
if (!empty($images) && is_array($images)) { |
||||
|
foreach ($images as $image) { |
||||
|
$data = Helper::uploadImage('content/', $image); |
||||
|
Helper::saveFileMsg($data, $comment->id, 4); |
||||
|
} |
||||
|
} |
||||
|
Helper::createdResponse($comment, $this->viewAction); |
||||
|
return $comment; |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,222 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace api\logic; |
||||
|
|
||||
|
|
||||
|
use backend\modules\goods\models\ars\Goods; |
||||
|
use backend\modules\shop\models\ars\ExpressArea; |
||||
|
use backend\modules\shop\models\ars\ExpressTemplate; |
||||
|
use backend\modules\shop\models\ars\Order; |
||||
|
use backend\modules\shop\models\ars\OrderGoods; |
||||
|
use yii\base\BaseObject; |
||||
|
use yii\web\NotFoundHttpException; |
||||
|
|
||||
|
/** |
||||
|
* @author iron |
||||
|
* @email weiriron@gmail.com |
||||
|
* @package api\logic |
||||
|
*/ |
||||
|
class ExpressLogic extends BaseObject |
||||
|
{ |
||||
|
/** |
||||
|
* @var Order |
||||
|
* 订单 |
||||
|
*/ |
||||
|
public $order; |
||||
|
|
||||
|
/** |
||||
|
* @param $order |
||||
|
* @return float|int |
||||
|
* @throws NotFoundHttpException |
||||
|
* 计算运费 |
||||
|
*/ |
||||
|
public function countShippingAmount($order) |
||||
|
{ |
||||
|
$this->order = $order; |
||||
|
$allGoods = $this->findDifferentExpressTypeGoods();/*获取不同运费计算模式的商品*/ |
||||
|
$uniformPostage = $this->countGoodsExpress($allGoods['uniformPostageGoods'], Goods::EXPRESS_TYPE_UNIFORM_POSTAGE);/*计算统一运费模式下所有商品运费*/ |
||||
|
$expressTemplate = $this->countGoodsExpress($allGoods['useTemplateGoods'], Goods::EXPRESS_TYPE_EXPRESS_TEMPLATE);/*计算运费模板模式下所有商品的运费*/ |
||||
|
$amount = $uniformPostage > $expressTemplate ? $uniformPostage : $expressTemplate;/*比较两种不同运费计算模式下,取金额大的值为最终收取运费*/ |
||||
|
return $amount / 100; /*将金额单位[分]转化为[元]*/ |
||||
|
} |
||||
|
|
||||
|
/*--------------------------------------------------------------------------------------*/ |
||||
|
/** |
||||
|
* @return array |
||||
|
* @throws NotFoundHttpException |
||||
|
* 获取不同运费计算模式的商品 |
||||
|
*/ |
||||
|
private function findDifferentExpressTypeGoods() |
||||
|
{ |
||||
|
$uniformPostage = $useTemplate = []; |
||||
|
$allGoods = OrderGoods::findAll(['order_id' => $this->order->id]); |
||||
|
foreach ($allGoods as $orderGoods) { |
||||
|
$goods = Goods::findOne(['id' => $orderGoods->goods_id, 'is_sale' => Goods::IS_SALE_YES, 'is_delete' => Goods::IS_DELETE_NO]); |
||||
|
if (!$goods) { |
||||
|
throw new NotFoundHttpException('商品未找到'); |
||||
|
} |
||||
|
$goodsArr['object'] = $goods; |
||||
|
$goodsArr['count'] = $orderGoods->goods_count; |
||||
|
$goodsArr['weight'] = $orderGoods->weight; |
||||
|
if ($goods->is_express && $goods->express_type == Goods::EXPRESS_TYPE_UNIFORM_POSTAGE) { |
||||
|
$uniformPostage[] = $goodsArr; |
||||
|
} |
||||
|
if ($goods->is_express && $goods->express_type == Goods::EXPRESS_TYPE_EXPRESS_TEMPLATE) { |
||||
|
$useTemplate[] = $goodsArr; |
||||
|
} |
||||
|
} |
||||
|
return ['uniformPostageGoods' => $uniformPostage, 'useTemplateGoods' => $useTemplate]; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param $allGoods |
||||
|
* @param $type |
||||
|
* @return float|int |
||||
|
* @throws NotFoundHttpException |
||||
|
* 根据不同计费模式计算商品运费 |
||||
|
*/ |
||||
|
private function countGoodsExpress($allGoods, $type) |
||||
|
{ |
||||
|
if ($type == Goods::EXPRESS_TYPE_UNIFORM_POSTAGE) { |
||||
|
$amount = 0; |
||||
|
foreach ($allGoods as $goods) { |
||||
|
$amount = $goods['object']->uniform_postage > $amount ? $goods['object']->uniform_postage : $amount; |
||||
|
} |
||||
|
return $amount; |
||||
|
} else { |
||||
|
$extraPrice = 0; |
||||
|
$areasIds = $basicGoods = []; |
||||
|
foreach ($allGoods as $goods) { |
||||
|
$areasIds[] = $this->getAreaId($goods['object']->express_template);/*获取所有配送区域的id*/ |
||||
|
} |
||||
|
$basicId = $this->getBasicAreaId($areasIds);/*获取首重运费和对应的计费规则id*/ |
||||
|
foreach ($allGoods as $k => $goods) { |
||||
|
$res = $this->countExtraAmount($goods, $basicId);/*判断商品绑定的是否为基础模板并计算非基础模板商品的增重运费*/ |
||||
|
if (is_bool($res) && $res === true) { |
||||
|
$basicGoods[] = $allGoods[$k]; |
||||
|
continue; |
||||
|
} |
||||
|
$extraPrice += $res; |
||||
|
} |
||||
|
$basicPrice = $this->countBasicPrice($basicGoods, $basicId);/*计算基础模板商品的运费*/ |
||||
|
return $extraPrice + $basicPrice; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param $allGoods |
||||
|
* @param $areaId |
||||
|
* @return float|int |
||||
|
* @throws NotFoundHttpException |
||||
|
* 计算基础模板商品的运费价格 |
||||
|
*/ |
||||
|
private function countBasicPrice($allGoods, $areaId) |
||||
|
{ |
||||
|
$area = $this->findArea($areaId); |
||||
|
$count = $weight = 0; |
||||
|
$template = $this->findTemplate($area->express_template); |
||||
|
foreach ($allGoods as $goods) { |
||||
|
$count += $goods['count']; |
||||
|
$weight += $goods['weight']; |
||||
|
} |
||||
|
if ($template->calculation_type == ExpressTemplate::CALCULATION_TYPE_WEIGHT) { |
||||
|
$amount = $weight - $area->basic_count > 0 ? $weight - $area->basic_count : 0; |
||||
|
} else { |
||||
|
$amount = $weight - $area->basic_count > 0 ? $weight - $area->basic_count : 0; |
||||
|
} |
||||
|
return $area->basic_price + $area->extra_price * ceil($amount / $area->extra_count); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param $areaIds |
||||
|
* @return int |
||||
|
* @throws NotFoundHttpException |
||||
|
* 获取基础运费的区域id |
||||
|
*/ |
||||
|
private function getBasicAreaId($areaIds) |
||||
|
{ |
||||
|
$basePrice = $id = 0; |
||||
|
foreach ($areaIds as $areasId) { |
||||
|
$area = $this->findArea($areasId); |
||||
|
if ($area->basic_price < $basePrice) { |
||||
|
continue; |
||||
|
} |
||||
|
$basePrice = $area->basic_price; |
||||
|
$id = $areasId; |
||||
|
} |
||||
|
return $id; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param $goods |
||||
|
* @param $areaId |
||||
|
* @return bool|int |
||||
|
* @throws NotFoundHttpException |
||||
|
* 计算非使用基础运费模板的商品按增重运费计算运费 |
||||
|
*/ |
||||
|
private function countExtraAmount($goods, $areaId) |
||||
|
{ |
||||
|
$count = $goods['count']; |
||||
|
$weight = $goods['weight']; |
||||
|
$area = $this->findArea($this->getAreaId($goods['object']->express_template)); |
||||
|
$template = $this->findTemplate($goods['object']->express_template); |
||||
|
if ($area->id == $areaId) { |
||||
|
return true; |
||||
|
} |
||||
|
if ($template->calculation_type == ExpressTemplate::CALCULATION_TYPE_WEIGHT) { |
||||
|
$amount = $weight; |
||||
|
} else { |
||||
|
$amount = $count; |
||||
|
} |
||||
|
return $area->extra_price * ceil($amount / $area->extra_count); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param $templateId |
||||
|
* @return int |
||||
|
* @throws NotFoundHttpException |
||||
|
* 根据收货地址获取配送区域id |
||||
|
*/ |
||||
|
private function getAreaId($templateId) |
||||
|
{ |
||||
|
$city = $this->order->city; |
||||
|
$areas = ExpressArea::findALl(['express_template' => $templateId]); |
||||
|
foreach ($areas as $area) { |
||||
|
$allCity = explode(',', $area->city); |
||||
|
if (in_array($city, $allCity)) { |
||||
|
return $area->id; |
||||
|
} |
||||
|
} |
||||
|
throw new NotFoundHttpException('超出配送范围(未找到对应地区运费计算规则)'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param $areaId |
||||
|
* @return ExpressArea|null |
||||
|
* @throws NotFoundHttpException |
||||
|
* 获取对应区域 |
||||
|
*/ |
||||
|
private function findArea($areaId) |
||||
|
{ |
||||
|
$area = ExpressArea::findOne($areaId); |
||||
|
if (!$area) { |
||||
|
throw new NotFoundHttpException('模板地区未找到'); |
||||
|
} |
||||
|
return $area; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param $templateId |
||||
|
* @return ExpressTemplate|null |
||||
|
* @throws NotFoundHttpException |
||||
|
* 获取运费模板 |
||||
|
*/ |
||||
|
private function findTemplate($templateId) |
||||
|
{ |
||||
|
$template = ExpressTemplate::findOne($templateId); |
||||
|
if (!$template) { |
||||
|
throw new NotFoundHttpException('运费模板未找到'); |
||||
|
} |
||||
|
return $template; |
||||
|
} |
||||
|
} |
@ -0,0 +1,225 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace api\logic; |
||||
|
|
||||
|
use backend\modules\file\models\ars\File; |
||||
|
use backend\modules\goods\models\ars\Goods; |
||||
|
use backend\modules\goods\models\ars\GoodsAttr; |
||||
|
use backend\modules\goods\models\ars\GoodsSku; |
||||
|
use backend\modules\shop\models\ars\Cart; |
||||
|
use yii\data\ActiveDataProvider; |
||||
|
use yii\helpers\Url; |
||||
|
use yii\web\BadRequestHttpException; |
||||
|
use yii\web\NotFoundHttpException; |
||||
|
use Yii; |
||||
|
use yii\web\ServerErrorHttpException; |
||||
|
|
||||
|
/** |
||||
|
* @author iron |
||||
|
* @email weiriron@gmail.com |
||||
|
* Class Helper |
||||
|
* @package api\logic |
||||
|
*/ |
||||
|
class Helper |
||||
|
{ |
||||
|
const REQUEST_BAD_PARAMS = '参数缺失或包含无效参数'; |
||||
|
|
||||
|
|
||||
|
public static function timeRandomNum($digit, $Prefix = '') |
||||
|
{ |
||||
|
$max = pow(10, $digit + 1); |
||||
|
return $Prefix . date('YmdHis', time()) . rand(0, $max - 1); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param $data |
||||
|
* @param $oid |
||||
|
* @param $type |
||||
|
* @throws ServerErrorHttpException |
||||
|
*/ |
||||
|
public static function saveFileMsg($data, $oid, $type) |
||||
|
{ |
||||
|
$file = new File(); |
||||
|
$file->type = 1; |
||||
|
$file->own_type = $type; |
||||
|
$file->own_id = $oid; |
||||
|
$file->path = $data['fileName']; |
||||
|
$file->alias = $data['alias']; |
||||
|
if (!$file->save()) { |
||||
|
throw new ServerErrorHttpException('服务器保存文件失败'); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param $dirs |
||||
|
* @param $file |
||||
|
* @return array |
||||
|
* @throws ServerErrorHttpException |
||||
|
*/ |
||||
|
public static function uploadImage($dirs, $file) |
||||
|
{ |
||||
|
$savePath = Yii::getAlias('@app') . '/web/uploads'; |
||||
|
if (!is_dir($savePath)) { |
||||
|
mkdir($savePath, 0755); |
||||
|
} |
||||
|
foreach ($dirs as $dir) { |
||||
|
$savePath .= "/$dir"; |
||||
|
if (!is_dir($savePath)) { |
||||
|
mkdir($savePath, 0755); |
||||
|
} |
||||
|
} |
||||
|
$fileName = time() . rand(0, 9999) . '.' . $file->extension; |
||||
|
$path = $savePath . $fileName; |
||||
|
if (!$file->saveAs($path)) { |
||||
|
throw new ServerErrorHttpException('服务器保存图片失败'); |
||||
|
} |
||||
|
return ['fileName' => '/uploads/' . $dirs . '/' . $fileName, 'alias' => $file->baseName . $file->extension]; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param $array |
||||
|
* @return string |
||||
|
*/ |
||||
|
public static function errorMessageStr($array): string |
||||
|
{ |
||||
|
$data = []; |
||||
|
foreach ($array as $k => $v) { |
||||
|
$data[] = implode(' ', $v); |
||||
|
} |
||||
|
return implode(' ', $data); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param array $ids 购物车id 数组 |
||||
|
* @throws NotFoundHttpException |
||||
|
* @throws ServerErrorHttpException |
||||
|
* @throws \Throwable |
||||
|
* @throws \yii\db\StaleObjectException |
||||
|
*/ |
||||
|
public static function delCarts($ids) |
||||
|
{ |
||||
|
foreach ($ids as $id) { |
||||
|
$cart = Cart::find() |
||||
|
->where(['id' => $id]) |
||||
|
->andWhere(['user_id' => Yii::$app->user->getId()]) |
||||
|
->one(); |
||||
|
if (!$cart) { |
||||
|
throw new NotFoundHttpException("未找到该购物车"); |
||||
|
} |
||||
|
if (!$cart->delete()) { |
||||
|
throw new ServerErrorHttpException('服务器删除购物车失败'); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param $goodsId |
||||
|
* @param $count |
||||
|
* @param null $skuId |
||||
|
* @return bool true代表无限库存,false代表有限库存需要进行增删库存操作 |
||||
|
* 判断库存 |
||||
|
* @throws NotFoundHttpException |
||||
|
* @throws BadRequestHttpException |
||||
|
*/ |
||||
|
public static function checkStock($goodsId, $count, $skuId = null) |
||||
|
{ |
||||
|
$sku = GoodsSku::findOne($skuId); |
||||
|
$goods = Goods::findOne($goodsId); |
||||
|
if (!$goods) { |
||||
|
throw new NotFoundHttpException('商品未找到'); |
||||
|
} |
||||
|
if ($goods->stock == Goods::UNLIMITED_STOCK) { |
||||
|
return true; |
||||
|
} |
||||
|
if ($sku && $sku->stock == Goods::UNLIMITED_STOCK) { |
||||
|
return true; |
||||
|
} |
||||
|
$stock = $sku ? $sku->stock : $goods->stock; |
||||
|
if ($stock < $count) { |
||||
|
throw new BadRequestHttpException("{$goods->name}库存不足"); |
||||
|
} |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param $model |
||||
|
* @param $view |
||||
|
* post的返回头设置 |
||||
|
*/ |
||||
|
public static function createdResponse($model, $view) |
||||
|
{ |
||||
|
$response = Yii::$app->getResponse()->setStatusCode(201); |
||||
|
$id = implode(',', array_values($model->getPrimaryKey(true))); |
||||
|
$response->getHeaders()->set('Location', Url::toRoute([$view, 'id' => $id], true)); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param $goodsId |
||||
|
* @param $skuId |
||||
|
* @return int |
||||
|
* @throws NotFoundHttpException |
||||
|
* 计算商品价格 |
||||
|
*/ |
||||
|
public static function goodsPrice($goodsId, $skuId) |
||||
|
{ |
||||
|
$goods = Goods::findOne($goodsId); |
||||
|
if (!$goods) { |
||||
|
throw new NotFoundHttpException('商品未找到'); |
||||
|
} |
||||
|
$price = $goods->price; |
||||
|
$sku = GoodsSku::findOne($skuId); |
||||
|
if ($sku) { |
||||
|
$price = $sku->price; |
||||
|
} |
||||
|
return $price; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param $skuId |
||||
|
* @return string |
||||
|
* @throws NotFoundHttpException |
||||
|
* 获取拼接后的sku值 |
||||
|
*/ |
||||
|
public static function skuValue($skuId) |
||||
|
{ |
||||
|
$sku = GoodsSku::findOne($skuId); |
||||
|
if (!$sku) { |
||||
|
return ''; |
||||
|
} |
||||
|
$data = []; |
||||
|
$goodsAttr = array_filter(explode(',', $sku->goods_attr)); |
||||
|
if (empty($goodsAttr)) { |
||||
|
throw new NotFoundHttpException('sku无对应商品属性'); |
||||
|
} |
||||
|
foreach ($goodsAttr as $k => $v) { |
||||
|
$attr = GoodsAttr::findOne($v); |
||||
|
if (!$attr) { |
||||
|
throw new NotFoundHttpException('商品属性未找到'); |
||||
|
} |
||||
|
$data[] = $attr->attr_value; |
||||
|
} |
||||
|
return implode(',', $data); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param $query |
||||
|
* @return object |
||||
|
* @throws \yii\base\InvalidConfigException |
||||
|
* 获取数据 |
||||
|
*/ |
||||
|
public static function index($query) |
||||
|
{ |
||||
|
$requestParams = Yii::$app->request->getBodyParams(); |
||||
|
return Yii::createObject([ |
||||
|
'class' => ActiveDataProvider::className(), |
||||
|
'query' => $query, |
||||
|
'pagination' => [ |
||||
|
'params' => $requestParams, |
||||
|
], |
||||
|
'sort' => [ |
||||
|
'params' => $requestParams, |
||||
|
], |
||||
|
]); |
||||
|
} |
||||
|
} |
@ -0,0 +1,67 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace api\logic; |
||||
|
|
||||
|
use common\models\User; |
||||
|
use yii\base\Exception; |
||||
|
use Yii; |
||||
|
use yii\web\BadRequestHttpException; |
||||
|
use yii\web\NotFoundHttpException; |
||||
|
use yii\web\ServerErrorHttpException; |
||||
|
|
||||
|
class Login |
||||
|
{ |
||||
|
const EXPIRE_TIME = 7 * 60 * 60 * 24; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* @return string |
||||
|
* @throws Exception |
||||
|
* @throws NotFoundHttpException |
||||
|
* @throws ServerErrorHttpException |
||||
|
*/ |
||||
|
public static function wxLogin() |
||||
|
{ |
||||
|
$user = self::getWxUser(); |
||||
|
Yii::$app->user->login($user, static::EXPIRE_TIME); |
||||
|
$user->expire_at = time() + static::EXPIRE_TIME; |
||||
|
$user->access_token = Yii::$app->security->generateRandomString(); |
||||
|
if (!$user->save()) { |
||||
|
throw new ServerErrorHttpException('更新登录信息失败'); |
||||
|
} |
||||
|
return $user->access_token; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array|User|null |
||||
|
* @throws BadRequestHttpException |
||||
|
* @throws NotFoundHttpException |
||||
|
*/ |
||||
|
protected static function getWxUser() |
||||
|
{ |
||||
|
$openid = Yii::$app->request->getBodyParam('openid'); |
||||
|
if (!$openid) { |
||||
|
throw new BadRequestHttpException('缺少参数openid'); |
||||
|
} |
||||
|
$user = User::find() |
||||
|
->where(['status' => User::STATUS_ACTIVE]) |
||||
|
->andWhere(['wx_openid' => $openid]) |
||||
|
->one(); |
||||
|
if (!$user) { |
||||
|
throw new NotFoundHttpException('用户未找到'); |
||||
|
} |
||||
|
return $user; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public function miniProgramLogin() |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
protected function getMiniUser() |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,459 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace api\logic; |
||||
|
|
||||
|
use backend\modules\goods\models\ars\Goods; |
||||
|
use backend\modules\goods\models\ars\GoodsSku; |
||||
|
use backend\modules\shop\models\ars\Address; |
||||
|
use backend\modules\shop\models\ars\Cart; |
||||
|
use backend\modules\shop\models\ars\Order; |
||||
|
use backend\modules\shop\models\ars\OrderGoods; |
||||
|
use backend\modules\shop\models\ars\TakingSite; |
||||
|
use yii\base\Component; |
||||
|
use Throwable; |
||||
|
use Yii; |
||||
|
use yii\db\ActiveRecord; |
||||
|
use yii\base\Exception; |
||||
|
use yii\web\BadRequestHttpException; |
||||
|
use yii\web\NotFoundHttpException; |
||||
|
use yii\web\ServerErrorHttpException; |
||||
|
|
||||
|
/** |
||||
|
* @author iron |
||||
|
* @email weiriron@gmail.com |
||||
|
* @package api\logic |
||||
|
*/ |
||||
|
class OrderLogic extends Component |
||||
|
{ |
||||
|
public $viewAction = 'view'; |
||||
|
/*订单操作类型*/ |
||||
|
const TYPE_CONFIRM = 1; |
||||
|
const TYPE_CANCEL = 2; |
||||
|
const TYPE_TAKE = 3; |
||||
|
const TYPE_CHANGE_SHIPPING_TYPE = 4; |
||||
|
const TYPE_CHANGE_ADDRESS = 5; |
||||
|
const TYPE_CHANGE_TAKING_SITE = 6; |
||||
|
/*仓库类型*/ |
||||
|
const TYPE_ADD_STOCK = 1; |
||||
|
const TYPE_SUB_STOCK = -1; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* @return Order |
||||
|
* @throws BadRequestHttpException |
||||
|
* @throws Exception |
||||
|
* 创建订单 |
||||
|
*/ |
||||
|
public function create() |
||||
|
{ |
||||
|
//立即购物需传参数
|
||||
|
$goodsId = Yii::$app->request->getBodyParam('goodsId');/*int 商品id*/ |
||||
|
$count = Yii::$app->request->getBodyParam('count');/*int 数量*/ |
||||
|
$skuId = Yii::$app->request->getBodyParam('skuId');/*int 商品sku id*/ |
||||
|
//购物车提交订单需传参数
|
||||
|
$cartIds = Yii::$app->request->getBodyParam('cartIds');/*array 购物车商品id*/ |
||||
|
|
||||
|
if ((empty($cartIds) && empty($goodsId)) || ($goodsId && empty($count))) { |
||||
|
throw new BadRequestHttpException(Helper::REQUEST_BAD_PARAMS); |
||||
|
} |
||||
|
$tra = Yii::$app->db->beginTransaction(); |
||||
|
try { |
||||
|
$order = new Order(); |
||||
|
$order->user_id = Yii::$app->user->getId(); |
||||
|
$order->type = Order::TYPE_SHOPPING; |
||||
|
$order->order_sn = Helper::timeRandomNum(3, 'W'); |
||||
|
if (!$order->save()) { |
||||
|
throw new ServerErrorHttpException('服务器创建订单失败'); |
||||
|
} |
||||
|
if ($goodsId && $count) { |
||||
|
$this->addGoods($order->id, $goodsId, $skuId, $count);/*添加订单商品*/ |
||||
|
} else { |
||||
|
$this->addGoodsByCart($cartIds, $order->id);/*通过购物车添加订单商品*/ |
||||
|
} |
||||
|
$this->getShippingType($order); |
||||
|
$this->saveGoodsInfo($order);/*保存订单商品信息*/ |
||||
|
if (!$order->save()) { |
||||
|
throw new Exception('服务器创建订单失败'); |
||||
|
} |
||||
|
$tra->commit(); |
||||
|
Helper::createdResponse($order, $this->viewAction); |
||||
|
return $order; |
||||
|
} catch (Exception $e) { |
||||
|
$tra->rollBack(); |
||||
|
throw $e; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return bool |
||||
|
* @throws Exception |
||||
|
* @throws Throwable |
||||
|
* @throws yii\base\InvalidConfigException |
||||
|
* 根据操作类型更新订单 |
||||
|
*/ |
||||
|
public function update() |
||||
|
{ |
||||
|
$data = Yii::$app->request->getBodyParams(); |
||||
|
$type = Yii::$app->request->getBodyParam('type'); |
||||
|
$order = $this->findOrder(); |
||||
|
$tra = Yii::$app->db->beginTransaction(); |
||||
|
try { |
||||
|
switch ($type) { |
||||
|
case self::TYPE_CONFIRM : |
||||
|
$this->confirm($order, $data); |
||||
|
break; |
||||
|
case self::TYPE_CANCEL: |
||||
|
$this->cancel($order); |
||||
|
break; |
||||
|
case self::TYPE_TAKE: |
||||
|
$this->take($order); |
||||
|
break; |
||||
|
case self::TYPE_CHANGE_SHIPPING_TYPE: |
||||
|
$this->switchShippingType($order, $data); |
||||
|
break; |
||||
|
case self::TYPE_CHANGE_ADDRESS: |
||||
|
$this->changeAddress($order, $data); |
||||
|
break; |
||||
|
case self::TYPE_CHANGE_TAKING_SITE: |
||||
|
$this->changeTakingSite($order, $data); |
||||
|
break; |
||||
|
default: |
||||
|
throw new BadRequestHttpException(Helper::REQUEST_BAD_PARAMS); |
||||
|
} |
||||
|
if (!$order->save()) { |
||||
|
throw new ServerErrorHttpException('服务器更新订单失败'); |
||||
|
} |
||||
|
$tra->commit(); |
||||
|
return true; |
||||
|
} catch (Exception $e) { |
||||
|
$tra->rollBack(); |
||||
|
throw $e; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/*----------------------------------------- 华丽的分割线 -----------------------------------------*/ |
||||
|
/** |
||||
|
* @param $order |
||||
|
* @return int |
||||
|
* @throws BadRequestHttpException |
||||
|
* @throws NotFoundHttpException |
||||
|
*/ |
||||
|
private function getShippingType($order) |
||||
|
{ |
||||
|
$allOrderGoods = $this->findOrderGoods($order->id); |
||||
|
$goods = $this->findGoods($allOrderGoods[0]->goods_id); |
||||
|
if ($goods->is_express) { |
||||
|
return Order::SHIPPING_TYPE_EXPRESS; |
||||
|
} |
||||
|
if ($goods->is_taking) { |
||||
|
return Order::SHIPPING_TYPE_PICKED_UP; |
||||
|
} |
||||
|
throw new BadRequestHttpException('配送方式异常'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Order $order |
||||
|
* @param array $data |
||||
|
* @throws BadRequestHttpException |
||||
|
* @throws NotFoundHttpException |
||||
|
* 添加地址到订单 |
||||
|
*/ |
||||
|
private function changeAddress($order, $data) |
||||
|
{ |
||||
|
if (!isset($data['address_id'])) { |
||||
|
throw new BadRequestHttpException(Helper::REQUEST_BAD_PARAMS); |
||||
|
} |
||||
|
if ($order->shipping_type !== Order::SHIPPING_TYPE_EXPRESS) { |
||||
|
throw new BadRequestHttpException('配送方式异常'); |
||||
|
} |
||||
|
if ($order->status !== Order::STATUS_UNCONFIRMED) { |
||||
|
throw new BadRequestHttpException('该状态下不允许更改配送方式'); |
||||
|
} |
||||
|
$address = Address::findOne(['id' => $data['address_id'], 'user_id' => Yii::$app->user->getId()]); |
||||
|
if (!$address) { |
||||
|
throw new NotFoundHttpException('收货地址未找到'); |
||||
|
} |
||||
|
$order->consignee = $address->consignee; |
||||
|
$order->phone = $address->phone; |
||||
|
$order->city = $address->city; |
||||
|
$order->area = $address->area; |
||||
|
$order->province = $address->province; |
||||
|
$order->address = $address->address; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Order $order |
||||
|
* @param array $data |
||||
|
* @throws BadRequestHttpException |
||||
|
* @throws NotFoundHttpException |
||||
|
* 修改自提点 |
||||
|
*/ |
||||
|
private function changeTakingSite($order, $data) |
||||
|
{ |
||||
|
if (!isset($data['taking_site_id']) || empty($data['taking_site_id'])) { |
||||
|
throw new BadRequestHttpException(Helper::REQUEST_BAD_PARAMS); |
||||
|
} |
||||
|
if ($order->shipping_type !== Order::SHIPPING_TYPE_PICKED_UP) { |
||||
|
throw new BadRequestHttpException('配送方式异常'); |
||||
|
} |
||||
|
if ($order->status !== Order::STATUS_UNCONFIRMED) { |
||||
|
throw new BadRequestHttpException('该状态下不允许更改提货地址方式'); |
||||
|
} |
||||
|
$site = TakingSite::findOne($data['taking_site_id']); |
||||
|
if (!$site) { |
||||
|
throw new NotFoundHttpException('自提点未找到'); |
||||
|
} |
||||
|
$order->taking_site = $data['taking_site_id']; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* @param Order $order |
||||
|
* @param array $data |
||||
|
* @throws BadRequestHttpException |
||||
|
* 切换配送方式 |
||||
|
*/ |
||||
|
private function switchShippingType($order, $data) |
||||
|
{ |
||||
|
if (!isset($data['shipping_type']) || |
||||
|
!in_array($data['shipping_type'], [Order::SHIPPING_TYPE_PICKED_UP, Order::SHIPPING_TYPE_EXPRESS])) { |
||||
|
throw new BadRequestHttpException(Helper::REQUEST_BAD_PARAMS); |
||||
|
} |
||||
|
if ($order->status !== Order::STATUS_UNCONFIRMED) { |
||||
|
throw new BadRequestHttpException('该状态下不允许更改配送方式'); |
||||
|
} |
||||
|
|
||||
|
$order->shipping_type = $data['shipping_type']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Order $order |
||||
|
* @param array $data |
||||
|
* @throws BadRequestHttpException |
||||
|
* @throws NotFoundHttpException |
||||
|
* @throws ServerErrorHttpException |
||||
|
* @throws Throwable |
||||
|
* @throws yii\db\StaleObjectException |
||||
|
* 确定订单 |
||||
|
*/ |
||||
|
private function confirm($order, $data) |
||||
|
{ |
||||
|
if ($order->status !== Order::STATUS_UNCONFIRMED) { |
||||
|
throw new BadRequestHttpException('订单状态异常'); |
||||
|
} |
||||
|
if ($order->shipping_type === Order::SHIPPING_TYPE_PICKED_UP) { |
||||
|
if ($data['consignee'] ?? false || $data['phone'] ?? false) { |
||||
|
throw new BadRequestHttpException(Helper::REQUEST_BAD_PARAMS); |
||||
|
} |
||||
|
$order->consignee = $data['consignee']; |
||||
|
$order->phone = $data['phone']; |
||||
|
} |
||||
|
if (empty($order->consignee)) { |
||||
|
throw new BadRequestHttpException('需先填写收件人信息'); |
||||
|
} |
||||
|
if (isset($data['remarks'])) { |
||||
|
$order->remarks = $data['remarks']; |
||||
|
} |
||||
|
Helper::delCarts($this->getCartsIds($order)); //删除购物车对应商品
|
||||
|
$order->status = Order::STATUS_NONPAYMENT; |
||||
|
$this->updateStock($order, self::TYPE_SUB_STOCK); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param $order |
||||
|
* @return array |
||||
|
* 获取订单商品对应购物车商品id |
||||
|
*/ |
||||
|
private function getCartsIds($order) |
||||
|
{ |
||||
|
$allGoods = $this->findOrderGoods($order->id); |
||||
|
$ids = []; |
||||
|
foreach ($allGoods as $goods) { |
||||
|
$cart = Cart::findOne(['goods_id' => $goods->goods_id, 'user_id' => Yii::$app->user->getId()]); |
||||
|
if ($cart) { |
||||
|
$ids[] = $cart->id; |
||||
|
} |
||||
|
} |
||||
|
return $ids; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Order $order |
||||
|
* @throws BadRequestHttpException |
||||
|
* @throws NotFoundHttpException |
||||
|
* @throws ServerErrorHttpException |
||||
|
* 取消订单 |
||||
|
*/ |
||||
|
private function cancel($order) |
||||
|
{ |
||||
|
if ($order->status !== Order::STATUS_NONPAYMENT) { |
||||
|
throw new BadRequestHttpException('该状态下无法取消订单'); |
||||
|
} |
||||
|
$order->status = Order::STATUS_CANCEL; |
||||
|
$this->updateStock($order, self::TYPE_ADD_STOCK);/*更新库存*/ |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Order $order |
||||
|
* @throws BadRequestHttpException |
||||
|
* 确认收货 |
||||
|
*/ |
||||
|
private function take($order) |
||||
|
{ |
||||
|
if ($order->status !== Order::STATUS_SHIPMENT_ALL) { |
||||
|
throw new BadRequestHttpException('该状态下无法确认收货'); |
||||
|
} |
||||
|
$order->status = Order::STATUS_FINISH; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param $id |
||||
|
* @param $type |
||||
|
* @throws BadRequestHttpException |
||||
|
* @throws NotFoundHttpException |
||||
|
* @throws ServerErrorHttpException |
||||
|
* 更新库存 |
||||
|
*/ |
||||
|
private function updateStock($id, $type) |
||||
|
{ |
||||
|
$allOrderGoods = $this->findOrderGoods($id); |
||||
|
foreach ($allOrderGoods as $orderGoods) { |
||||
|
/*检查库存*/ |
||||
|
if (Helper::checkStock($orderGoods->goods_id, $orderGoods->goods_count, $orderGoods->sku_id)) { |
||||
|
return; |
||||
|
} |
||||
|
if ($orderGoods->sku_id) { |
||||
|
$goods = GoodsSku::findOne($orderGoods->sku_id); |
||||
|
} else { |
||||
|
$goods = $this->findGoods($orderGoods->goods_id); |
||||
|
} |
||||
|
if ($type) { |
||||
|
$count = $orderGoods->goods_count; |
||||
|
} else { |
||||
|
$count = -$orderGoods->goods_count; |
||||
|
} |
||||
|
if (!$goods->updateCounters(['stock' => $count])) { |
||||
|
throw new ServerErrorHttpException('更新库存失败'); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param array $cartIds 购物车商品id |
||||
|
* @param int $id 订单id |
||||
|
* @throws Exception |
||||
|
* @throws NotFoundHttpException |
||||
|
* 通过购物车添加商品 |
||||
|
*/ |
||||
|
private function addGoodsByCart($cartIds, $id) |
||||
|
{ |
||||
|
foreach ($cartIds as $cartId) { |
||||
|
$cart = Cart::findOne($cartId); |
||||
|
if (!$cart) { |
||||
|
throw new NotFoundHttpException('购物车未找到'); |
||||
|
} |
||||
|
$this->addGoods($id, $cart->goods_id, $cart->sku_id, $cart->goods_count); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Order $order |
||||
|
* 保存商品总价格和总数量信息到 |
||||
|
*/ |
||||
|
private function saveGoodsInfo($order) |
||||
|
{ |
||||
|
$orderGoods = $this->findOrderGoods($order->id); |
||||
|
foreach ($orderGoods as $goods) { |
||||
|
$order->goods_amount += $goods->price; |
||||
|
$order->goods_count += $goods->goods_count; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* @param $id |
||||
|
* @param int $goodsId |
||||
|
* @param $skuId |
||||
|
* @param $count |
||||
|
* @throws Exception |
||||
|
* @throws NotFoundHttpException |
||||
|
* 添加商品到订单 |
||||
|
*/ |
||||
|
private function addGoods($id, $goodsId, $skuId, $count) |
||||
|
{ |
||||
|
$goods = $this->findGoods($goodsId); |
||||
|
$orderGoods = new OrderGoods(); |
||||
|
$orderGoods->order_id = $id; |
||||
|
$orderGoods->goods_id = $goodsId; |
||||
|
$orderGoods->sku_id = $skuId ?: 0; |
||||
|
$orderGoods->sku_value = Helper::skuValue($skuId); |
||||
|
$orderGoods->weight = $skuId ? $this->skuWeight($skuId) : $goods->weight; |
||||
|
$orderGoods->goods_count = $count; |
||||
|
$orderGoods->goods_img = $goods->image; |
||||
|
$orderGoods->goods_name = $goods->name; |
||||
|
$orderGoods->price = Helper::goodsPrice($goodsId, $skuId); |
||||
|
Helper::checkStock($goodsId, $count, $skuId); /*检查库存*/ |
||||
|
if (!$orderGoods->save()) { |
||||
|
throw new Exception('服务器添加订单商品失败'); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param $skuId |
||||
|
* @return int |
||||
|
* @throws NotFoundHttpException |
||||
|
* 获取sku重量 |
||||
|
*/ |
||||
|
private function skuWeight($skuId) |
||||
|
{ |
||||
|
$sku = GoodsSku::findOne($skuId); |
||||
|
if (!$sku) { |
||||
|
throw new NotFoundHttpException('sku未找到'); |
||||
|
} |
||||
|
return $sku->weight; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array|Order|null |
||||
|
* 根据id获取订单 |
||||
|
*/ |
||||
|
private function findOrder() |
||||
|
{ |
||||
|
$id = Yii::$app->request->getQueryParam('id'); |
||||
|
return Order::find() |
||||
|
->where(['id' => $id]) |
||||
|
->andWhere(['user_id' => Yii::$app->user->getId()]) |
||||
|
->one(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param $id |
||||
|
* @return array|ActiveRecord[]|OrderGoods[] |
||||
|
* 根据订单 id 获取所有订单商品 |
||||
|
*/ |
||||
|
private function findOrderGoods($id) |
||||
|
{ |
||||
|
return OrderGoods::find() |
||||
|
->where(['order_id' => $id]) |
||||
|
->all(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param $goodsId |
||||
|
* @return array|Goods|null |
||||
|
* @throws NotFoundHttpException |
||||
|
*/ |
||||
|
private function findGoods($goodsId) |
||||
|
{ |
||||
|
$goods = Goods::find() |
||||
|
->where(['id' => $goodsId]) |
||||
|
->andWhere(['is_delete' => Goods::IS_DELETE_NO]) |
||||
|
->andWhere(['is_sale' => Goods::IS_SALE_YES]) |
||||
|
->one(); |
||||
|
if (!$goods) { |
||||
|
throw new NotFoundHttpException("商品[{$goodsId}]未找到"); |
||||
|
} |
||||
|
return $goods; |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,40 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace api\logic; |
||||
|
|
||||
|
use common\models\DailyActiveUser; |
||||
|
use yii\base\Component; |
||||
|
use Yii; |
||||
|
|
||||
|
/** |
||||
|
* @author iron |
||||
|
* @email weiriron@gmail.com |
||||
|
* Class CartLogic |
||||
|
* @package api\logic |
||||
|
*/ |
||||
|
class UserLogic extends Component |
||||
|
{ |
||||
|
|
||||
|
public function DailyActive() |
||||
|
{ |
||||
|
$date = date('Y-m-d', time()); |
||||
|
$DAU = DailyActiveUser::find() |
||||
|
->where(['date' => $date]) |
||||
|
->one(); |
||||
|
if ($DAU) { |
||||
|
$ids = $DAU->user_ids; |
||||
|
if (in_array(Yii::$app->user->id, $ids)) { |
||||
|
return; |
||||
|
} |
||||
|
array_push($ids, Yii::$app->user->id); |
||||
|
$DAU->user_id = $ids; |
||||
|
$DAU->count += 1; |
||||
|
} else { |
||||
|
$DAU = new DailyActiveUser(); |
||||
|
$DAU->user_ids = array(Yii::$app->user->getId()); |
||||
|
$DAU->date = $date; |
||||
|
} |
||||
|
$DAU->save(); |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,2 @@ |
|||||
|
* |
||||
|
!.gitignore |
@ -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> |
@ -0,0 +1,5 @@ |
|||||
|
/index.php |
||||
|
/index-test.php |
||||
|
/robots.txt |
||||
|
uploads |
||||
|
|
@ -0,0 +1,2 @@ |
|||||
|
* |
||||
|
!.gitignore |
@ -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; |
||||
|
} |
@ -0,0 +1,18 @@ |
|||||
|
<?php |
||||
|
|
||||
|
// NOTE: Make sure this file is not accessible when deployed to production
|
||||
|
if (!in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', '::1'])) { |
||||
|
die('You are not allowed to access this file.'); |
||||
|
} |
||||
|
|
||||
|
defined('YII_DEBUG') or define('YII_DEBUG', true); |
||||
|
defined('YII_ENV') or define('YII_ENV', 'test'); |
||||
|
|
||||
|
require __DIR__ . '/../../vendor/autoload.php'; |
||||
|
require __DIR__ . '/../../vendor/yiisoft/yii2/Yii.php'; |
||||
|
require __DIR__ . '/../../common/config/bootstrap.php'; |
||||
|
require __DIR__ . '/../config/bootstrap.php'; |
||||
|
|
||||
|
$config = require __DIR__ . '/../config/test-local.php'; |
||||
|
|
||||
|
(new yii\web\Application($config))->run(); |
@ -0,0 +1,17 @@ |
|||||
|
<?php |
||||
|
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'; |
||||
|
require __DIR__ . '/../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(); |
@ -0,0 +1,2 @@ |
|||||
|
User-agent: * |
||||
|
Disallow: / |
@ -1,58 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace backend\models; |
|
||||
|
|
||||
use Yii; |
|
||||
|
|
||||
/** |
|
||||
* This is the model class for table "cat". |
|
||||
* |
|
||||
* @property int $id |
|
||||
* @property string $cat_name |
|
||||
* @property string $icon |
|
||||
* @property int $icon_type |
|
||||
* @property string $description |
|
||||
* @property int $sort_order |
|
||||
* @property int $created_at |
|
||||
* @property int $updated_at |
|
||||
*/ |
|
||||
class Cat extends \yii\db\ActiveRecord |
|
||||
{ |
|
||||
/** |
|
||||
* {@inheritdoc} |
|
||||
*/ |
|
||||
public static function tableName() |
|
||||
{ |
|
||||
return 'cat'; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* {@inheritdoc} |
|
||||
*/ |
|
||||
public function rules() |
|
||||
{ |
|
||||
return [ |
|
||||
[['cat_name'], 'required'], |
|
||||
[['icon_type', 'sort_order', 'created_at', 'updated_at'], 'integer'], |
|
||||
[['description'], 'string'], |
|
||||
[['cat_name', 'icon'], 'string', 'max' => 64], |
|
||||
]; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* {@inheritdoc} |
|
||||
*/ |
|
||||
public function attributeLabels() |
|
||||
{ |
|
||||
return [ |
|
||||
'id' => 'ID', |
|
||||
'cat_name' => 'Cat Name', |
|
||||
'icon' => 'Icon', |
|
||||
'icon_type' => 'Icon Type', |
|
||||
'description' => 'Description', |
|
||||
'sort_order' => 'Sort Order', |
|
||||
'created_at' => 'Created At', |
|
||||
'updated_at' => 'Updated At', |
|
||||
]; |
|
||||
} |
|
||||
} |
|
@ -1,125 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace backend\models; |
|
||||
|
|
||||
use iron\wegets\Upload; |
|
||||
use Yii; |
|
||||
use yii\behaviors\TimestampBehavior; |
|
||||
|
|
||||
/** |
|
||||
* This is the model class for table "category". |
|
||||
* |
|
||||
* @property int $id |
|
||||
* @property string $cat_name |
|
||||
* @property string $icon |
|
||||
* @property int $icon_type |
|
||||
* @property string $description |
|
||||
* @property int $sort_order |
|
||||
* @property int $created_at |
|
||||
* @property int $updated_at |
|
||||
*/ |
|
||||
class Category extends \yii\db\ActiveRecord |
|
||||
{ |
|
||||
|
|
||||
const ICON_TYPE_BOOSTARAP = 1; |
|
||||
const ICON_TYPE_AWESOME = 2; |
|
||||
|
|
||||
public static $iconType = [ |
|
||||
self::ICON_TYPE_BOOSTARAP => "boostrap", |
|
||||
self::ICON_TYPE_AWESOME => "awesome" |
|
||||
]; |
|
||||
|
|
||||
/** |
|
||||
* {@inheritdoc} |
|
||||
*/ |
|
||||
public static function tableName() |
|
||||
{ |
|
||||
return 'category'; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* {@inheritdoc} |
|
||||
*/ |
|
||||
public function rules() |
|
||||
{ |
|
||||
return [ |
|
||||
[['icon_type', 'cat_name', 'created_at'], 'required'], |
|
||||
[['icon_type', 'sort_order', 'created_at', 'updated_at'], 'integer'], |
|
||||
[['description'], 'string'], |
|
||||
[['cat_name', 'icon'], 'string', 'max' => 64], |
|
||||
]; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* {@inheritdoc} |
|
||||
*/ |
|
||||
public function attributeLabels() |
|
||||
{ |
|
||||
return [ |
|
||||
'id' => 'ID', |
|
||||
'cat_name' => '类名', |
|
||||
'icon' => 'Icon', |
|
||||
'icon_type' => '图标类型', |
|
||||
'description' => '描述', |
|
||||
'sort_order' => 'Sort Order', |
|
||||
'created_at' => '添加日期', |
|
||||
'updated_at' => 'Updated At', |
|
||||
]; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* @return array |
|
||||
* 列格式 |
|
||||
*/ |
|
||||
public static function columns() |
|
||||
{ |
|
||||
return [ |
|
||||
[ |
|
||||
'class' => 'blobt\grid\CheckboxColumn', |
|
||||
'width' => '2%', |
|
||||
'align' => 'center' |
|
||||
], |
|
||||
[ |
|
||||
'attribute' => 'id', |
|
||||
'width' => '10%', |
|
||||
'align' => 'center' |
|
||||
], |
|
||||
[ |
|
||||
'attribute' => 'created_at', |
|
||||
'width' => '10%', |
|
||||
'format' => 'date' |
|
||||
], |
|
||||
[ |
|
||||
'attribute' => 'cat_name', |
|
||||
'width' => '10%', |
|
||||
], |
|
||||
[ |
|
||||
'attribute' => 'icon', |
|
||||
'width' => '10%', |
|
||||
], |
|
||||
[ |
|
||||
'attribute' => 'icon_type', |
|
||||
'width' => '10%', |
|
||||
'showConstText' => true |
|
||||
], |
|
||||
[ |
|
||||
'attribute' => 'description', |
|
||||
'enableSorting' => false, |
|
||||
'format' => 'ntext', |
|
||||
'width' => '20%', |
|
||||
], |
|
||||
[ |
|
||||
'class' => 'iron\grid\ActionColumn', |
|
||||
'align' => 'center', |
|
||||
], |
|
||||
]; |
|
||||
} |
|
||||
|
|
||||
public function behaviors() |
|
||||
{ |
|
||||
return [ |
|
||||
TimestampBehavior::className() |
|
||||
]; |
|
||||
} |
|
||||
|
|
||||
} |
|
@ -1,126 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace backend\models; |
|
||||
|
|
||||
use backend\models\Category; |
|
||||
use yii\base\Model; |
|
||||
use yii\data\ActiveDataProvider; |
|
||||
use yii\helpers\ArrayHelper; |
|
||||
|
|
||||
/** |
|
||||
* CategorySearch represents the model behind the search form of `\backend\models\Category`. |
|
||||
*/ |
|
||||
class CategorySearch extends Category |
|
||||
{ |
|
||||
/** |
|
||||
* @return array |
|
||||
* 增加创建时间查询字段 |
|
||||
*/ |
|
||||
public function attributes() |
|
||||
{ |
|
||||
return ArrayHelper::merge(['created_at_range'], parent::attributes()); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* {@inheritdoc} |
|
||||
*/ |
|
||||
public function rules() |
|
||||
{ |
|
||||
return [ |
|
||||
[['id', 'icon_type', 'sort_order', 'created_at', 'updated_at'], 'integer'], |
|
||||
[['cat_name', 'icon', 'description', 'created_at_range'], 'safe'], |
|
||||
]; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* {@inheritdoc} |
|
||||
*/ |
|
||||
public function scenarios() |
|
||||
{ |
|
||||
// bypass scenarios() implementation in the parent class
|
|
||||
return Model::scenarios(); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* @param $params |
|
||||
* @return ActiveDataProvider |
|
||||
* 不分页的所有数据 |
|
||||
*/ |
|
||||
public function allData($params) |
|
||||
{ |
|
||||
$query = Category::find(); |
|
||||
$dataProvider = new ActiveDataProvider([ |
|
||||
'query' => $query, |
|
||||
'pagination' => false, |
|
||||
'sort' => false |
|
||||
]); |
|
||||
$this->load($params); |
|
||||
return $this->filter($query, $dataProvider); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* Creates data provider instance with search query applied |
|
||||
* |
|
||||
* @param array $params |
|
||||
* |
|
||||
* @return ActiveDataProvider |
|
||||
*/ |
|
||||
public function search($params) |
|
||||
{ |
|
||||
$query = Category::find(); |
|
||||
|
|
||||
// add conditions that should always apply here
|
|
||||
|
|
||||
$dataProvider = new ActiveDataProvider([ |
|
||||
'query' => $query, |
|
||||
'pagination' => [ |
|
||||
'pageSizeLimit' => [1, 200] |
|
||||
], |
|
||||
'sort' => [ |
|
||||
'defaultOrder' => [ |
|
||||
'id' => SORT_DESC, |
|
||||
] |
|
||||
], |
|
||||
]); |
|
||||
$this->load($params); |
|
||||
return $this->filter($query, $dataProvider); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* @param $query |
|
||||
* @param $dataProvider |
|
||||
* @return ActiveDataProvider |
|
||||
* 条件筛选 |
|
||||
*/ |
|
||||
private function filter($query, $dataProvider) |
|
||||
{ |
|
||||
|
|
||||
if (!$this->validate()) { |
|
||||
// uncomment the following line if you do not want to return any records when validation fails
|
|
||||
// $query->where('0=1');
|
|
||||
return $dataProvider; |
|
||||
} |
|
||||
|
|
||||
// grid filtering conditions
|
|
||||
$query->andFilterWhere([ |
|
||||
'id' => $this->id, |
|
||||
'icon_type' => $this->icon_type, |
|
||||
'sort_order' => $this->sort_order, |
|
||||
'created_at' => $this->created_at, |
|
||||
'updated_at' => $this->updated_at, |
|
||||
]); |
|
||||
|
|
||||
$query->andFilterWhere(['like', 'cat_name', $this->cat_name]) |
|
||||
->andFilterWhere(['like', 'icon', $this->icon]) |
|
||||
->andFilterWhere(['like', 'description', $this->description]); |
|
||||
|
|
||||
if ($this->created_at_range) { |
|
||||
$arr = explode(' ~ ', $this->created_at_range); |
|
||||
$start = strtotime($arr[0]); |
|
||||
$end = strtotime($arr[1]) + 3600 * 24; |
|
||||
$query->andFilterWhere(['between', 'created_at', $start, $end]); |
|
||||
} |
|
||||
return $dataProvider; |
|
||||
} |
|
||||
|
|
||||
} |
|
@ -0,0 +1,227 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace backend\models; |
||||
|
|
||||
|
use Yii; |
||||
|
use yii\base\NotSupportedException; |
||||
|
use yii\behaviors\TimestampBehavior; |
||||
|
use yii\db\ActiveRecord; |
||||
|
use yii\web\IdentityInterface; |
||||
|
|
||||
|
/** |
||||
|
* User model |
||||
|
* |
||||
|
* @property integer $id |
||||
|
* @property string $username |
||||
|
* @property string $password_hash |
||||
|
* @property string $password_reset_token |
||||
|
* @property string $verification_token |
||||
|
* @property string $email |
||||
|
* @property string $auth_key |
||||
|
* @property integer $status |
||||
|
* @property integer $created_at |
||||
|
* @property integer $updated_at |
||||
|
* @property string $password write-only password |
||||
|
*/ |
||||
|
class User extends ActiveRecord implements IdentityInterface |
||||
|
{ |
||||
|
const STATUS_DELETED = 0; |
||||
|
const STATUS_ACTIVE = 10; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* {@inheritdoc} |
||||
|
*/ |
||||
|
public static function tableName() |
||||
|
{ |
||||
|
return '{{auth_user}}'; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* {@inheritdoc} |
||||
|
*/ |
||||
|
public function behaviors() |
||||
|
{ |
||||
|
return [ |
||||
|
[ |
||||
|
'class' => TimestampBehavior::className(), |
||||
|
'createdAtAttribute' => 'created_at', |
||||
|
'updatedAtAttribute' => 'updated_at', |
||||
|
'value' => function () { |
||||
|
return time(); |
||||
|
}, |
||||
|
], |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* {@inheritdoc} |
||||
|
*/ |
||||
|
public function rules() |
||||
|
{ |
||||
|
return [ |
||||
|
['status', 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_DELETED]], |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
public function beforeSave($insert) |
||||
|
{ |
||||
|
if ($insert) { |
||||
|
$this->email = $this->username . '@example.com'; |
||||
|
$this->generateAuthKey(); |
||||
|
$this->setPassword(Yii::$app->security->generateRandomString()); |
||||
|
} |
||||
|
return parent::beforeSave($insert); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* {@inheritdoc} |
||||
|
*/ |
||||
|
public static function findIdentity($id) |
||||
|
{ |
||||
|
return static::findOne(['id' => $id, 'status' => self::STATUS_ACTIVE]); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* {@inheritdoc} |
||||
|
*/ |
||||
|
public static function findIdentityByAccessToken($token, $type = null) |
||||
|
{ |
||||
|
throw new NotSupportedException('"findIdentityByAccessToken" is not implemented.'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Finds user by username |
||||
|
* |
||||
|
* @param string $username |
||||
|
* @return static|null |
||||
|
*/ |
||||
|
public static function findByUsername($username) |
||||
|
{ |
||||
|
return static::findOne(['username' => $username, 'status' => self::STATUS_ACTIVE]); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Finds user by password reset token |
||||
|
* |
||||
|
* @param string $token password reset token |
||||
|
* @return static|null |
||||
|
*/ |
||||
|
public static function findByPasswordResetToken($token) |
||||
|
{ |
||||
|
if (!static::isPasswordResetTokenValid($token)) { |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
return static::findOne([ |
||||
|
'password_reset_token' => $token, |
||||
|
'status' => self::STATUS_ACTIVE, |
||||
|
]); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Finds user by verification email token |
||||
|
* |
||||
|
* @param string $token verify email token |
||||
|
* @return static|null |
||||
|
*/ |
||||
|
public static function findByVerificationToken($token) |
||||
|
{ |
||||
|
return static::findOne([ |
||||
|
'verification_token' => $token, |
||||
|
'status' => self::STATUS_INACTIVE |
||||
|
]); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Finds out if password reset token is valid |
||||
|
* |
||||
|
* @param string $token password reset token |
||||
|
* @return bool |
||||
|
*/ |
||||
|
public static function isPasswordResetTokenValid($token) |
||||
|
{ |
||||
|
if (empty($token)) { |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
$timestamp = (int)substr($token, strrpos($token, '_') + 1); |
||||
|
$expire = Yii::$app->params['user.passwordResetTokenExpire']; |
||||
|
return $timestamp + $expire >= time(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* {@inheritdoc} |
||||
|
*/ |
||||
|
public function getId() |
||||
|
{ |
||||
|
return $this->getPrimaryKey(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* {@inheritdoc} |
||||
|
*/ |
||||
|
public function getAuthKey() |
||||
|
{ |
||||
|
return $this->auth_key; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* {@inheritdoc} |
||||
|
*/ |
||||
|
public function validateAuthKey($authKey) |
||||
|
{ |
||||
|
return $this->getAuthKey() === $authKey; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Validates password |
||||
|
* |
||||
|
* @param string $password password to validate |
||||
|
* @return bool if password provided is valid for current user |
||||
|
*/ |
||||
|
public function validatePassword($password) |
||||
|
{ |
||||
|
return Yii::$app->security->validatePassword($password, $this->password_hash); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Generates password hash from password and sets it to the model |
||||
|
* |
||||
|
* @param string $password |
||||
|
*/ |
||||
|
public function setPassword($password) |
||||
|
{ |
||||
|
$this->password_hash = Yii::$app->security->generatePasswordHash($password); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Generates "remember me" authentication key |
||||
|
*/ |
||||
|
public function generateAuthKey() |
||||
|
{ |
||||
|
$this->auth_key = Yii::$app->security->generateRandomString(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Generates new password reset token |
||||
|
*/ |
||||
|
public function generatePasswordResetToken() |
||||
|
{ |
||||
|
$this->password_reset_token = Yii::$app->security->generateRandomString() . '_' . time(); |
||||
|
} |
||||
|
|
||||
|
public function generateEmailVerificationToken() |
||||
|
{ |
||||
|
$this->verification_token = Yii::$app->security->generateRandomString() . '_' . time(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Removes password reset token |
||||
|
*/ |
||||
|
public function removePasswordResetToken() |
||||
|
{ |
||||
|
$this->password_reset_token = null; |
||||
|
} |
||||
|
} |
@ -0,0 +1,26 @@ |
|||||
|
<?php |
||||
|
|
||||
|
use yii\db\Migration; |
||||
|
|
||||
|
/** |
||||
|
* Class m191207_004848_add_columns_is_taking_is_express_express_type_uniform_postage_in_table_atg_goods |
||||
|
*/ |
||||
|
class m191207_004848_add_columns_is_taking_is_express_express_type_uniform_postage_in_table_atg_goods extends Migration |
||||
|
{ |
||||
|
public function up() |
||||
|
{ |
||||
|
$this->addColumn('atg_goods', 'is_taking', $this->tinyInteger(1)->defaultValue(0)->notNull()->comment('是否自提')); |
||||
|
$this->addColumn('atg_goods', 'is_express', $this->tinyInteger(1)->defaultValue(0)->notNull()->comment('是否快递发货')); |
||||
|
$this->addColumn('atg_goods', 'express_type', $this->tinyInteger(2)->defaultValue(0)->comment('快递运费方式')); |
||||
|
$this->addColumn('atg_goods', 'uniform_postage', $this->integer(20)->defaultValue(0)->comment('统一邮费')); |
||||
|
} |
||||
|
|
||||
|
public function down() |
||||
|
{ |
||||
|
$this->dropColumn('atg_goods', 'is_taking'); |
||||
|
$this->dropColumn('atg_goods', 'is_express'); |
||||
|
$this->dropColumn('atg_goods', 'express_type'); |
||||
|
$this->dropColumn('atg_goods', 'uniform_postage'); |
||||
|
return true; |
||||
|
} |
||||
|
} |
@ -0,0 +1,23 @@ |
|||||
|
<?php |
||||
|
|
||||
|
use yii\db\Migration; |
||||
|
|
||||
|
/** |
||||
|
* Class m191209_091129_update_columns_in_table_atg_goods |
||||
|
*/ |
||||
|
class m191209_091129_update_columns_in_table_atg_goods extends Migration |
||||
|
{ |
||||
|
public function up() |
||||
|
{ |
||||
|
$sql = file_get_contents(__DIR__."/sql/update_goods.sql"); |
||||
|
$this->execute($sql); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* {@inheritdoc} |
||||
|
*/ |
||||
|
public function down() |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
} |
@ -0,0 +1,20 @@ |
|||||
|
<?php |
||||
|
|
||||
|
use yii\db\Migration; |
||||
|
|
||||
|
/** |
||||
|
* Class m191209_091524_add_column_weight_in_table_atg_goods_sku |
||||
|
*/ |
||||
|
class m191209_091524_add_column_weight_in_table_atg_goods_sku extends Migration |
||||
|
{ |
||||
|
public function up() |
||||
|
{ |
||||
|
$this->addColumn('atg_goods_sku', 'weight', $this->integer(8)->defaultValue("0")->unsigned()->comment('重量')); |
||||
|
} |
||||
|
|
||||
|
public function down() |
||||
|
{ |
||||
|
$this->dropColumn('atg_goods_sku', 'weight'); |
||||
|
return true; |
||||
|
} |
||||
|
} |
@ -0,0 +1,17 @@ |
|||||
|
ALTER TABLE `atg_goods` DROP `weight`; |
||||
|
ALTER TABLE `atg_goods` DROP `length`; |
||||
|
ALTER TABLE `atg_goods` DROP `width`; |
||||
|
ALTER TABLE `atg_goods` DROP `height`; |
||||
|
ALTER TABLE `atg_goods` DROP `diameter`; |
||||
|
ALTER TABLE `atg_goods` DROP `sold_count`; |
||||
|
ALTER TABLE `atg_goods` DROP `market_price`; |
||||
|
ALTER TABLE `atg_goods` DROP `price`; |
||||
|
|
||||
|
ALTER TABLE `atg_goods` ADD COLUMN `weight` mediumint(8) UNSIGNED DEFAULT NULL COMMENT '重量'; |
||||
|
ALTER TABLE `atg_goods` ADD COLUMN `length` mediumint(8) UNSIGNED DEFAULT NULL COMMENT '长度'; |
||||
|
ALTER TABLE `atg_goods` ADD COLUMN `width` mediumint(8) UNSIGNED DEFAULT NULL COMMENT '宽度'; |
||||
|
ALTER TABLE `atg_goods` ADD COLUMN `height` mediumint(8) UNSIGNED DEFAULT NULL COMMENT '高度'; |
||||
|
ALTER TABLE `atg_goods` ADD COLUMN `diameter` mediumint(8) UNSIGNED DEFAULT NULL COMMENT '直径'; |
||||
|
ALTER TABLE `atg_goods` ADD COLUMN `sold_count` int(10) UNSIGNED DEFAULT NULL COMMENT '已售数量'; |
||||
|
ALTER TABLE `atg_goods` ADD COLUMN `market_price` int(20) UNSIGNED DEFAULT NULL COMMENT '市场价'; |
||||
|
ALTER TABLE `atg_goods` ADD COLUMN `price` int(20) UNSIGNED DEFAULT NULL COMMENT '销售价'; |
@ -0,0 +1,90 @@ |
|||||
|
<?php |
||||
|
|
||||
|
use yii\helpers\Url; |
||||
|
use blobt\widgets\Icheck; |
||||
|
use backend\modules\goods\models\ars\Goods; |
||||
|
use linyao\widgets\Select2; |
||||
|
use backend\modules\shop\models\ars\ExpressTemplate; |
||||
|
|
||||
|
/* @var $this yii\web\View */ |
||||
|
/* @var $model backend\modules\goods\models\ars\Goods */ |
||||
|
/* @var $form yii\widgets\ActiveForm */ |
||||
|
?>
|
||||
|
<?= $form->field($model, 'is_taking')->widget(Icheck::className(), ['items' => Goods::$isTaking, 'type' => 'radio']) ?>
|
||||
|
|
||||
|
<?= $form->field($model, 'is_express')->widget(Icheck::className(), ['items' => Goods::$isExpress, 'type' => 'radio']) ?>
|
||||
|
|
||||
|
<fieldset id="isExpress" style="display: <?= $model->is_express == Goods::IS_EXPRESS_NO ? 'none' : 'block' ?>"> |
||||
|
<?= $form->field($model, 'express_type')->widget(Icheck::className(), ['items' => Goods::$expressType, 'type' => 'radio']) ?>
|
||||
|
|
||||
|
<fieldset id="uniformPostage" style="display: <?= $model->express_type == Goods::EXPRESS_TYPE_UNIFORM_POSTAGE ? 'block' : 'none' ?>"> |
||||
|
<?= $form->field($model, 'uniform_postage')->textInput() ?>
|
||||
|
</fieldset> |
||||
|
|
||||
|
<fieldset id="expressTemplate" style="display: <?= $model->express_type == Goods::EXPRESS_TYPE_EXPRESS_TEMPLATE ? 'block' : 'none' ?>"> |
||||
|
<?= $form->field($model, 'express_template')->widget(Select2::className(), ["items" => ExpressTemplate::modelColumn()]) ?>
|
||||
|
</fieldset> |
||||
|
</fieldset> |
||||
|
|
||||
|
<?php |
||||
|
$js =<<<JS |
||||
|
$(document).ready(function(){ |
||||
|
if(!$("#goods-uniform_postage").val()){ |
||||
|
$("#goods-uniform_postage").val("0.00") |
||||
|
}else{ |
||||
|
$("#goods-uniform_postage").val(toFixeds($("#goods-uniform_postage").val(), 2)); |
||||
|
} |
||||
|
$("input:radio[name='Goods[is_express]']").on('ifChecked', function(event){ |
||||
|
if ($(this).val() === '1') { |
||||
|
$("#isExpress").show(); |
||||
|
} else { |
||||
|
$("#isExpress").hide(); |
||||
|
} |
||||
|
}) |
||||
|
$("input:radio[name='Goods[express_type]']").on('ifChecked', function(event){ |
||||
|
if ($(this).val() === '1') { |
||||
|
$("#uniformPostage").show(); |
||||
|
$("#expressTemplate").hide(); |
||||
|
} else { |
||||
|
$("#expressTemplate").show(); |
||||
|
$("#uniformPostage").hide(); |
||||
|
} |
||||
|
}) |
||||
|
$("#goods-uniform_postage").blur(function(){ |
||||
|
if(!$(this).val()){ |
||||
|
$(this).val("0.00") |
||||
|
} |
||||
|
if(isNaN($(this).val())){ |
||||
|
$(this).val("0.00") |
||||
|
} |
||||
|
if($(this).val().indexOf('-') != -1){ |
||||
|
$(this).val("0.00") |
||||
|
} |
||||
|
var basicPrice = $(this).val(); |
||||
|
$(this).val(toFixeds($(this).val(), 2)); |
||||
|
}) |
||||
|
//金额补全
|
||||
|
function toFixeds(val, pre) { |
||||
|
const num = parseFloat(val); |
||||
|
// eslint-disable-next-line no-restricted-globals
|
||||
|
if (isNaN(num)) { |
||||
|
return false; |
||||
|
} |
||||
|
const p = 10 ** pre; |
||||
|
const value = num * p; |
||||
|
let f = (Math.round(value) / p).toString(); |
||||
|
let rs = f.indexOf('.'); |
||||
|
if (rs < 0) { |
||||
|
rs = f.length; |
||||
|
f += '.'; |
||||
|
} |
||||
|
while (f.length <= rs + pre) { |
||||
|
f += '0'; |
||||
|
} |
||||
|
return f; |
||||
|
} |
||||
|
}) |
||||
|
JS; |
||||
|
$this->registerJs($js); |
||||
|
|
||||
|
?>
|
@ -0,0 +1,32 @@ |
|||||
|
<?php |
||||
|
|
||||
|
use yii\db\Migration; |
||||
|
|
||||
|
/** |
||||
|
* Class m191205_092426_drop_columns_province_city_area_basic_price_basic_count_extra_count_extra_price_in_table_ats_express_template |
||||
|
*/ |
||||
|
class m191205_092426_drop_columns_province_city_area_basic_price_basic_count_extra_count_extra_price_in_table_ats_express_template extends Migration |
||||
|
{ |
||||
|
public function up() |
||||
|
{ |
||||
|
$this->dropColumn('ats_express_template', 'province'); |
||||
|
$this->dropColumn('ats_express_template', 'city'); |
||||
|
$this->dropColumn('ats_express_template', 'area'); |
||||
|
$this->dropColumn('ats_express_template', 'extra_price'); |
||||
|
$this->dropColumn('ats_express_template', 'basic_price'); |
||||
|
$this->dropColumn('ats_express_template', 'basic_count'); |
||||
|
$this->dropColumn('ats_express_template', 'extra_count'); |
||||
|
} |
||||
|
|
||||
|
public function down() |
||||
|
{ |
||||
|
$this->addColumn('ats_express_template', 'province', $this->text()->comment('省份')); |
||||
|
$this->addColumn('ats_express_template', 'city', $this->text()->comment('城市')); |
||||
|
$this->addColumn('ats_express_template', 'area', $this->text()->comment('区域')); |
||||
|
$this->addColumn('ats_express_template', 'extra_price', $this->integer(20)->defaultValue(null)->comment('续重运费')); |
||||
|
$this->addColumn('ats_express_template', 'basic_price', $this->integer(20)->defaultValue(null)->comment('基本运费')); |
||||
|
$this->addColumn('ats_express_template', 'basic_count', $this->integer(20)->defaultValue(null)->comment('基本数量')); |
||||
|
$this->addColumn('ats_express_template', 'extra_count', $this->integer(20)->defaultValue(null)->comment('续重数量')); |
||||
|
return true; |
||||
|
} |
||||
|
} |
@ -0,0 +1,36 @@ |
|||||
|
<?php |
||||
|
|
||||
|
use yii\db\Migration; |
||||
|
|
||||
|
/** |
||||
|
* Class m191205_092942_create_table_ats_express_area |
||||
|
*/ |
||||
|
class m191205_092942_create_table_ats_express_area extends Migration |
||||
|
{ |
||||
|
public function up() |
||||
|
{ |
||||
|
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB COMMENT="快递区域价格表"'; |
||||
|
$this->createTable('ats_express_area', [ |
||||
|
'id' => $this->primaryKey(), |
||||
|
'province' => $this->text()->comment('省份'), |
||||
|
'city' => $this->text()->comment('城市'), |
||||
|
'area' => $this->text()->comment('区域'), |
||||
|
'express_template' => $this->integer(11)->defaultValue(null)->comment('运费模板id'), |
||||
|
'extra_price' => $this->integer(20)->defaultValue(null)->comment('续重运费'), |
||||
|
'basic_price' => $this->integer(20)->defaultValue(null)->comment('基本运费'), |
||||
|
'basic_count' => $this->integer(20)->defaultValue(null)->comment('基本数量'), |
||||
|
'extra_count' => $this->integer(20)->defaultValue(null)->comment('续重数量'), |
||||
|
'updated_at'=>$this->integer(11)->defaultValue(null)->comment('更新时间'), |
||||
|
'created_at'=>$this->integer(11)->defaultValue(null)->comment('创建时间'), |
||||
|
],$tableOptions); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* {@inheritdoc} |
||||
|
*/ |
||||
|
public function down() |
||||
|
{ |
||||
|
$this->dropTable('ats_express_area'); |
||||
|
return true; |
||||
|
} |
||||
|
} |
@ -0,0 +1,24 @@ |
|||||
|
<?php |
||||
|
|
||||
|
use yii\db\Migration; |
||||
|
|
||||
|
/** |
||||
|
* Class m191205_062533_update_columns_basic_amount_extra_amount_calculation_in_table_ats_express_template |
||||
|
*/ |
||||
|
class m191206_092733_add_column_about_goods_to_table_collection extends Migration |
||||
|
{ |
||||
|
public function up() |
||||
|
{ |
||||
|
$this->addColumn('ats_collection', 'goods_name', $this->string(120)->notNull()->defaultValue('')->comment('商品名称')); |
||||
|
$this->addColumn('ats_collection', 'goods_img', $this->integer(11)->comment('商品图片')); |
||||
|
$this->addColumn('ats_collection', 'goods_price', $this->integer(20)->notNull()->defaultValue(0)->comment('商品价格')); |
||||
|
} |
||||
|
|
||||
|
public function down() |
||||
|
{ |
||||
|
$this->dropColumn('ats_collection', 'goods_name'); |
||||
|
$this->dropColumn('ats_collection', 'goods_img'); |
||||
|
$this->dropColumn('ats_collection', 'goods_price'); |
||||
|
return true; |
||||
|
} |
||||
|
} |
@ -0,0 +1,22 @@ |
|||||
|
<?php |
||||
|
|
||||
|
use yii\db\Migration; |
||||
|
|
||||
|
/** |
||||
|
* Class m191205_062533_update_columns_basic_amount_extra_amount_calculation_in_table_ats_express_template |
||||
|
*/ |
||||
|
class m191206_162733_add_column_about_user_to_table_comment extends Migration |
||||
|
{ |
||||
|
public function up() |
||||
|
{ |
||||
|
$this->addColumn('ats_comment', 'nickname', $this->string(120)->notNull()->defaultValue('')->comment('昵称')); |
||||
|
$this->addColumn('ats_comment', 'avatar', $this->integer(11)->comment('头像')); |
||||
|
} |
||||
|
|
||||
|
public function down() |
||||
|
{ |
||||
|
$this->dropColumn('ats_comment', 'nickname'); |
||||
|
$this->dropColumn('ats_comment', 'avatar'); |
||||
|
return true; |
||||
|
} |
||||
|
} |
@ -0,0 +1,101 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace backend\modules\shop\models\ars; |
||||
|
|
||||
|
use Yii; |
||||
|
use yii\behaviors\TimestampBehavior; |
||||
|
|
||||
|
/** |
||||
|
* This is the model class for table "ats_express_area". |
||||
|
* |
||||
|
* @property int $id |
||||
|
* @property string $province 省份 |
||||
|
* @property string $city 城市 |
||||
|
* @property string $area 区域 |
||||
|
* @property int $express_template 运费模板id |
||||
|
* @property int $extra_price 续重运费 |
||||
|
* @property int $basic_price 基本运费 |
||||
|
* @property int $basic_count 基本数量 |
||||
|
* @property int $extra_count 续重数量 |
||||
|
* @property int $updated_at 更新时间 |
||||
|
* @property int $created_at 创建时间 |
||||
|
*/ |
||||
|
class ExpressArea extends \yii\db\ActiveRecord |
||||
|
{ |
||||
|
public static $formList = [ |
||||
|
1 => [ |
||||
|
"basic_count"=>"基本重量(KG)", |
||||
|
"basic_price"=>"基本运费(元)", |
||||
|
"extra_count"=>"续重重量(KG)", |
||||
|
"extra_price"=>"续重运费(元)" |
||||
|
], |
||||
|
2 => [ |
||||
|
"basic_count"=>"基本数量(件)", |
||||
|
"basic_price"=>"基本运费(元)", |
||||
|
"extra_count"=>"续重数量(件)", |
||||
|
"extra_price"=>"续重运费(元)" |
||||
|
] |
||||
|
]; |
||||
|
/** |
||||
|
* {@inheritdoc} |
||||
|
*/ |
||||
|
public static function tableName() |
||||
|
{ |
||||
|
return 'ats_express_area'; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* {@inheritdoc} |
||||
|
*/ |
||||
|
public function rules() |
||||
|
{ |
||||
|
return [ |
||||
|
[['province', 'city', 'area'], 'string'], |
||||
|
[['express_template'], 'integer'], |
||||
|
[['extra_price', 'basic_price', 'basic_count', 'extra_count'], 'safe'], |
||||
|
[['extra_price', 'basic_price', 'basic_count', 'extra_count'], 'number'], |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* {@inheritdoc} |
||||
|
*/ |
||||
|
public function attributeLabels() |
||||
|
{ |
||||
|
return [ |
||||
|
'id' => 'id', |
||||
|
'province' => '省份', |
||||
|
'city' => '城市', |
||||
|
'area' => '区域', |
||||
|
'express_template' => '运费模板id', |
||||
|
'extra_price' => '续重运费', |
||||
|
'basic_price' => '基本运费', |
||||
|
'basic_count' => '基本数量', |
||||
|
'extra_count' => '续重数量', |
||||
|
'updated_at' => '更新时间', |
||||
|
'created_at' => '创建时间', |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* @author linyao |
||||
|
* @email 602604991@qq.com |
||||
|
* @created Nov 8, 2019 |
||||
|
* |
||||
|
* 行为存储创建时间和更新时间 |
||||
|
*/ |
||||
|
public function behaviors() |
||||
|
{ |
||||
|
return [ |
||||
|
[ |
||||
|
'class' => TimestampBehavior::className(), |
||||
|
'createdAtAttribute' => 'created_at', |
||||
|
'updatedAtAttribute' => 'updated_at', |
||||
|
'value' => function() { |
||||
|
return time(); |
||||
|
}, |
||||
|
], |
||||
|
]; |
||||
|
} |
||||
|
} |
@ -0,0 +1,187 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace backend\modules\shop\models\searchs; |
||||
|
|
||||
|
use backend\modules\shop\models\ars\City; |
||||
|
use backend\modules\shop\models\ars\Province; |
||||
|
use yii\base\Model; |
||||
|
use yii\data\ActiveDataProvider; |
||||
|
use yii\helpers\ArrayHelper; |
||||
|
use backend\modules\shop\models\ars\ExpressArea; |
||||
|
use yii; |
||||
|
use yii\bootstrap4\Html; |
||||
|
|
||||
|
/** |
||||
|
* ExpressAreaSearch represents the model behind the search form of `backend\modules\shop\models\ars\ExpressArea`. |
||||
|
*/ |
||||
|
class ExpressAreaSearch extends ExpressArea |
||||
|
{ |
||||
|
/** |
||||
|
* @return array |
||||
|
* 增加创建时间查询字段 |
||||
|
*/ |
||||
|
public function attributes() |
||||
|
{ |
||||
|
return ArrayHelper::merge(['created_at_range'], parent::attributes()); |
||||
|
} |
||||
|
/** |
||||
|
* {@inheritdoc} |
||||
|
*/ |
||||
|
public function rules() |
||||
|
{ |
||||
|
return [ |
||||
|
[['id', 'express_template', 'extra_price', 'basic_price', 'basic_count', 'extra_count', 'updated_at', 'created_at'], 'integer'], |
||||
|
[['province', 'city', 'area'], 'safe'], |
||||
|
['created_at_range','safe'], |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* {@inheritdoc} |
||||
|
*/ |
||||
|
public function scenarios() |
||||
|
{ |
||||
|
// bypass scenarios() implementation in the parent class
|
||||
|
return Model::scenarios(); |
||||
|
} |
||||
|
/** |
||||
|
* @return array |
||||
|
* 列格式 |
||||
|
*/ |
||||
|
public function columns() |
||||
|
{ |
||||
|
return [ |
||||
|
[ |
||||
|
'class' => 'blobt\grid\CheckboxColumn', |
||||
|
'width' => '2%', |
||||
|
'align' => 'center' |
||||
|
], |
||||
|
'id', |
||||
|
['attribute' => 'city', |
||||
|
'value' => function ($model) { |
||||
|
$expressAreas = ExpressArea::findOne($model->id); |
||||
|
$expressAresCityIdArr = explode(',', $expressAreas->city); |
||||
|
$cities = []; |
||||
|
$provinces = Province::find()->cache(0)->all(); |
||||
|
foreach ($provinces as $k => $v) { |
||||
|
$cityId = City::find() |
||||
|
->select(['city_id']) |
||||
|
->where(['province_id' => $v->province_id]) |
||||
|
->column(); |
||||
|
if (empty(array_diff($cityId, $expressAresCityIdArr))) { |
||||
|
$cities[] = $v->name; |
||||
|
}else{ |
||||
|
foreach (\backend\modules\shop\models\ars\City::find()->andWhere(['in', 'city_id', array_diff($cityId, array_diff($cityId, $expressAresCityIdArr))])->all() as $city) { |
||||
|
$cities[] = $city->name; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
return implode(' , ', $cities); |
||||
|
}, |
||||
|
], |
||||
|
[ |
||||
|
'class' => 'iron\grid\ActionColumn', |
||||
|
'align' => 'center', |
||||
|
'config' => [ |
||||
|
[ |
||||
|
'name' => 'express-area-view', |
||||
|
'icon' => 'list', |
||||
|
'title' => '详情', |
||||
|
], |
||||
|
[ |
||||
|
'name' => 'express-area-update', |
||||
|
'icon' => 'pencil', |
||||
|
'title' => '修改' |
||||
|
], |
||||
|
[ |
||||
|
'name' => 'express-area-delete', |
||||
|
'icon' => 'trash', |
||||
|
'title' => '删除', |
||||
|
'contents' => '确定删除?' |
||||
|
] |
||||
|
], |
||||
|
], |
||||
|
]; |
||||
|
} |
||||
|
/** |
||||
|
* @param $params |
||||
|
* @return ActiveDataProvider |
||||
|
* 不分页的所有数据 |
||||
|
*/ |
||||
|
public function allData($params) |
||||
|
{ |
||||
|
$query = ExpressArea::find(); |
||||
|
$dataProvider = new ActiveDataProvider([ |
||||
|
'query' => $query, |
||||
|
'pagination' => false, |
||||
|
'sort' => false |
||||
|
]); |
||||
|
$this->load($params); |
||||
|
return $this->filter($query, $dataProvider); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Creates data provider instance with search query applied |
||||
|
* |
||||
|
* @param array $params |
||||
|
* |
||||
|
* @return ActiveDataProvider |
||||
|
*/ |
||||
|
public function search($params, $expressTemplateId) |
||||
|
{ |
||||
|
$query = ExpressArea::find()->where(['express_template' => $expressTemplateId]); |
||||
|
|
||||
|
// add conditions that should always apply here
|
||||
|
|
||||
|
$dataProvider = new ActiveDataProvider([ |
||||
|
'query' => $query, |
||||
|
'pagination' => [ |
||||
|
'pageSizeLimit' => [1, 200] |
||||
|
], |
||||
|
'sort' => [ |
||||
|
'defaultOrder' => [ |
||||
|
'id' => SORT_DESC, |
||||
|
] |
||||
|
], |
||||
|
]); |
||||
|
|
||||
|
$this->load($params); |
||||
|
return $this->filter($query, $dataProvider); |
||||
|
} |
||||
|
/** |
||||
|
* @param $query |
||||
|
* @param $dataProvider |
||||
|
* @return ActiveDataProvider |
||||
|
* 条件筛选 |
||||
|
*/ |
||||
|
private function filter($query, $dataProvider){ |
||||
|
if (!$this->validate()) { |
||||
|
// uncomment the following line if you do not want to return any records when validation fails
|
||||
|
// $query->where('0=1');
|
||||
|
return $dataProvider; |
||||
|
} |
||||
|
|
||||
|
// grid filtering conditions
|
||||
|
$query->andFilterWhere([ |
||||
|
'id' => $this->id, |
||||
|
'express_template' => $this->express_template, |
||||
|
'extra_price' => $this->extra_price, |
||||
|
'basic_price' => $this->basic_price, |
||||
|
'basic_count' => $this->basic_count, |
||||
|
'extra_count' => $this->extra_count, |
||||
|
'updated_at' => $this->updated_at, |
||||
|
'created_at' => $this->created_at, |
||||
|
]); |
||||
|
|
||||
|
$query->andFilterWhere(['like', 'province', $this->province]) |
||||
|
->andFilterWhere(['like', 'city', $this->city]) |
||||
|
->andFilterWhere(['like', 'area', $this->area]); |
||||
|
if ($this->created_at_range) { |
||||
|
$arr = explode(' ~ ', $this->created_at_range); |
||||
|
$start = strtotime($arr[0]); |
||||
|
$end = strtotime($arr[1]) + 3600 * 24; |
||||
|
$query->andFilterWhere(['between', 'created_at', $start, $end]); |
||||
|
} |
||||
|
return $dataProvider; |
||||
|
} |
||||
|
} |
@ -0,0 +1,51 @@ |
|||||
|
<?php |
||||
|
|
||||
|
use yii\bootstrap4\Html; |
||||
|
use yii\bootstrap4\ActiveForm; |
||||
|
use kartik\tabs\TabsX; |
||||
|
|
||||
|
/* @var $this yii\web\View */ |
||||
|
/* @var $model backend\modules\shop\models\ars\ExpressTemplate */ |
||||
|
|
||||
|
$this->title = '创建区域运费模板'; |
||||
|
$this->params['breadcrumbs'][] = ['label' => '运费区域模板', 'url' => ['express_area_list', ['id' => $expressTemplateModel->id]]]; |
||||
|
$this->params['breadcrumbs'][] = $this->title; |
||||
|
Yii::$app->params['bsVersion'] = '4.x'; |
||||
|
?>
|
||||
|
<div class="express-template-create"> |
||||
|
<div class="express-template-form"> |
||||
|
|
||||
|
<?php |
||||
|
$form = ActiveForm::begin(['options' => ['class' => 'container-fluid']]); |
||||
|
|
||||
|
echo TabsX::widget([ |
||||
|
'bordered' => true, |
||||
|
'items' => [ |
||||
|
[ |
||||
|
'label' => '<i class="fas fa-user"></i> 基本信息', |
||||
|
'content' => $this->render('express_area_form', [ |
||||
|
'model' => $model, |
||||
|
'form' => $form, |
||||
|
'expressTemplateModel' => $expressTemplateModel |
||||
|
]), |
||||
|
], |
||||
|
[ |
||||
|
'label' => '<i class="fas fa-globe"></i> 选择配送区域', |
||||
|
'content' => $this->render('area', ['data' => $data, 'form' => $form, 'cities' => [] |
||||
|
]), |
||||
|
], |
||||
|
], |
||||
|
'position' => TabsX::POS_ABOVE, |
||||
|
'encodeLabels' => false |
||||
|
]); |
||||
|
?>
|
||||
|
|
||||
|
<div class="form-group"> |
||||
|
<?= Html::submitButton('保存', ['class' => 'btn btn-success']) ?>
|
||||
|
<?= Html::a('返回', ['express-area-list', 'id' => $expressTemplateModel->id], ['class' => 'btn btn-info']) ?>
|
||||
|
</div> |
||||
|
|
||||
|
<?php ActiveForm::end(); ?>
|
||||
|
|
||||
|
</div> |
||||
|
</div> |
@ -0,0 +1,175 @@ |
|||||
|
<?php |
||||
|
|
||||
|
use blobt\widgets\Icheck; |
||||
|
use backend\modules\shop\models\ars\ExpressTemplate; |
||||
|
|
||||
|
/* @var $this yii\web\View */ |
||||
|
/* @var $model backend\modules\shop\models\ars\ExpressTemplate */ |
||||
|
/* @var $form yii\widgets\ActiveForm */ |
||||
|
?>
|
||||
|
|
||||
|
<?php |
||||
|
$status = Yii::$app->request->get('status'); |
||||
|
if ($status == 1) { |
||||
|
?>
|
||||
|
<div class="alert alert-warning alert-dismissible" role="alert"> |
||||
|
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span |
||||
|
aria-hidden="true">×</span></button> |
||||
|
<p style="color: #2e2e2e">必须至少选择一个城市为配送区域</p> |
||||
|
</div> |
||||
|
<?php } ?>
|
||||
|
|
||||
|
<?= $form->field($model, 'express_template')->textInput(['maxlength' => true]) ?>
|
||||
|
|
||||
|
<?= $form->field($model, 'basic_count')->textInput() ?>
|
||||
|
|
||||
|
<?= $form->field($model, 'basic_price')->textInput() ?>
|
||||
|
|
||||
|
<?= $form->field($model, 'extra_count')->textInput() ?>
|
||||
|
|
||||
|
<?= $form->field($model, 'extra_price')->textInput() ?>
|
||||
|
|
||||
|
<?php |
||||
|
$js=<<<JS |
||||
|
const formList = [//切换时,class对应的标题
|
||||
|
{ |
||||
|
"field-expressarea-basic_count":"基本重量(KG)", |
||||
|
"field-expressarea-basic_price":"基本运费(元)", |
||||
|
"field-expressarea-extra_count":"续重重量(KG)", |
||||
|
"field-expressarea-extra_price":"续重运费(元)" |
||||
|
|
||||
|
}, |
||||
|
|
||||
|
{ |
||||
|
"field-expressarea-basic_count":"基本数量(件)", |
||||
|
"field-expressarea-basic_price":"基本运费(元)", |
||||
|
"field-expressarea-extra_count":"续重数量(件)", |
||||
|
"field-expressarea-extra_price":"续重运费(元)" |
||||
|
|
||||
|
} |
||||
|
] |
||||
|
const udfVal = [//初始值
|
||||
|
[0.1,"0.00"], |
||||
|
[1,"0.00"] |
||||
|
] |
||||
|
var calType = {$expressTemplateModel->calculation_type}-1;//初始的计算方式0:计重 1:计件
|
||||
|
|
||||
|
function updateTypeChangeCalType(type){//当切换计算方式
|
||||
|
|
||||
|
$.each(formList[type],function(index,value){ //更改文字标题
|
||||
|
$("." + index).children("label").html(value) |
||||
|
}); |
||||
|
|
||||
|
$("#expressarea-basic_count").val(udfVal[type][0])//重置初始值
|
||||
|
$("#expressarea-basic_price").val(udfVal[type][1]) |
||||
|
$("#expressarea-extra_count").val(0) |
||||
|
$("#expressarea-extra_price").val(udfVal[type][1]) |
||||
|
calType = type; |
||||
|
} |
||||
|
function changeCalType(type){//当切换计算方式
|
||||
|
|
||||
|
$.each(formList[type],function(index,value){ //更改文字标题
|
||||
|
$("." + index).children("label").html(value) |
||||
|
}); |
||||
|
|
||||
|
if(!$("#expressarea-basic_count").val()){ |
||||
|
$("#expressarea-basic_count").val(udfVal[type][0])//重置初始值
|
||||
|
} |
||||
|
if(!$("#expressarea-basic_price").val()){ |
||||
|
$("#expressarea-basic_price").val(udfVal[type][1]) |
||||
|
} |
||||
|
if(!$("#expressarea-extra_count").val()){ |
||||
|
$("#expressarea-extra_count").val(0) |
||||
|
} |
||||
|
if(!$("#expressarea-extra_price").val()){ |
||||
|
$("#expressarea-extra_price").val(udfVal[type][1]) |
||||
|
} |
||||
|
calType = type; |
||||
|
} |
||||
|
//金额补全
|
||||
|
function toFixeds(val, pre) { |
||||
|
const num = parseFloat(val); |
||||
|
// eslint-disable-next-line no-restricted-globals
|
||||
|
if (isNaN(num)) { |
||||
|
return false; |
||||
|
} |
||||
|
const p = 10 ** pre; |
||||
|
const value = num * p; |
||||
|
let f = (Math.round(value) / p).toString(); |
||||
|
let rs = f.indexOf('.'); |
||||
|
if (rs < 0) { |
||||
|
rs = f.length; |
||||
|
f += '.'; |
||||
|
} |
||||
|
while (f.length <= rs + pre) { |
||||
|
f += '0'; |
||||
|
} |
||||
|
return f; |
||||
|
} |
||||
|
$(document).ready(function(){ |
||||
|
$("#expressarea-basic_count").blur(function(){ |
||||
|
if(isNaN($(this).val())){ |
||||
|
$(this).val(1) |
||||
|
} |
||||
|
if (calType == 0) { |
||||
|
if($(this).val() < 0.1){ |
||||
|
$(this).val(1) |
||||
|
} |
||||
|
var basiccount = $(this).val(); |
||||
|
$(this).val(toFixeds($(this).val(), 1)); |
||||
|
} else{ |
||||
|
if($(this).val() < 1){ |
||||
|
$(this).val(1) |
||||
|
} |
||||
|
var basiccount = $(this).val(); |
||||
|
$(this).val(Math.floor(basiccount * 1) / 1); |
||||
|
} |
||||
|
}) |
||||
|
$("#expressarea-basic_price").blur(function(){ |
||||
|
if(isNaN($(this).val())){ |
||||
|
$(this).val("0.00") |
||||
|
} |
||||
|
if($(this).val().indexOf('-') != -1){ |
||||
|
$(this).val("0.00") |
||||
|
} |
||||
|
var basicPrice = $(this).val(); |
||||
|
$(this).val(toFixeds($(this).val(), 2)); |
||||
|
}) |
||||
|
$("#expressarea-extra_count").blur(function(){ |
||||
|
if(isNaN($(this).val())){ |
||||
|
$(this).val(0) |
||||
|
} |
||||
|
if (calType == 0) { |
||||
|
if($(this).val() < 0){ |
||||
|
$(this).val(0) |
||||
|
} |
||||
|
var basiccount = $(this).val(); |
||||
|
$(this).val(toFixeds($(this).val(), 1)); |
||||
|
} else{ |
||||
|
if($(this).val() < 0){ |
||||
|
$(this).val(0) |
||||
|
} |
||||
|
var basiccount = $(this).val(); |
||||
|
$(this).val(Math.floor(basiccount * 1) / 1); |
||||
|
} |
||||
|
}) |
||||
|
$("#expressarea-extra_price").blur(function(){ |
||||
|
if(isNaN($(this).val())){ |
||||
|
$(this).val("0.00") |
||||
|
} |
||||
|
if($(this).val().indexOf('-') != -1){ |
||||
|
$(this).val("0.00") |
||||
|
} |
||||
|
var basicPrice = $(this).val(); |
||||
|
$(this).val(toFixeds($(this).val(), 2)); |
||||
|
}) |
||||
|
|
||||
|
$("input:radio[name='ExpressArea[calculation_type]']").on('ifChecked', function(event){ |
||||
|
updateTypeChangeCalType($(this).val()-1) |
||||
|
}) |
||||
|
changeCalType(calType) |
||||
|
}) |
||||
|
JS; |
||||
|
$this->registerJs($js) |
||||
|
|
||||
|
?>
|
@ -0,0 +1,33 @@ |
|||||
|
<?php |
||||
|
|
||||
|
use yii\helpers\Html; |
||||
|
use iron\grid\GridView; |
||||
|
|
||||
|
/* @var $this yii\web\View */ |
||||
|
/* @var $searchModel backend\modules\shop\models\searchs\ExpressAreaSearch */ |
||||
|
/* @var $dataProvider yii\data\ActiveDataProvider */ |
||||
|
|
||||
|
$this->title = '运费区域模板:'.$expressTemplate->name; |
||||
|
$this->params['breadcrumbs'][] = $this->title; |
||||
|
?>
|
||||
|
<div class="row"> |
||||
|
<div class="col-12"> |
||||
|
<?= GridView::widget([ |
||||
|
'dataProvider' => $dataProvider, |
||||
|
'filter' => $this->render("_search", ['model' => $searchModel]), |
||||
|
'batch' => [ |
||||
|
[ |
||||
|
"label" => "删除", |
||||
|
"url" => "express-area/deletes" |
||||
|
], |
||||
|
], |
||||
|
'columns' => $columns, |
||||
|
'batchTemplate' => '', |
||||
|
'create' => '', |
||||
|
'export' => '', |
||||
|
'content' => Html::a('创建', ['express-area-create', 'expressTemplateId' => $expressTemplate->id], ['class' => 'btn btn-default']). |
||||
|
Html::a('返回', ['index'], ['class' => 'btn btn-default']) |
||||
|
]); |
||||
|
?>
|
||||
|
</div> |
||||
|
</div> |
@ -0,0 +1,52 @@ |
|||||
|
<?php |
||||
|
|
||||
|
use yii\bootstrap4\Html; |
||||
|
use yii\bootstrap4\ActiveForm; |
||||
|
use kartik\tabs\TabsX; |
||||
|
|
||||
|
/* @var $this yii\web\View */ |
||||
|
/* @var $model backend\modules\shop\models\ars\ExpressTemplate */ |
||||
|
|
||||
|
$this->title = '编辑区域运费模板'; |
||||
|
$this->params['breadcrumbs'][] = ['label' => '运费模板', 'url' => ['index']]; |
||||
|
$this->params['breadcrumbs'][] = ['label' => '区域运费模板:'.$expressTemplateModel->name, 'url' => ['express-area-list', 'id' => $expressTemplateModel->id]]; |
||||
|
$this->params['breadcrumbs'][] = '编辑区域运费模板'; |
||||
|
Yii::$app->params['bsVersion'] = '4.x'; |
||||
|
?>
|
||||
|
<div class="express-template-update"> |
||||
|
<div class="express-template-form"> |
||||
|
|
||||
|
<?php |
||||
|
$form = ActiveForm::begin(['options' => ['class' => 'container-fluid']]); |
||||
|
|
||||
|
echo TabsX::widget([ |
||||
|
'bordered' => true, |
||||
|
'items' => [ |
||||
|
[ |
||||
|
'label' => '<i class="fas fa-user"></i> 基本信息', |
||||
|
'content' => $this->render('express_area_form', [ |
||||
|
'model' => $model, |
||||
|
'form' => $form, |
||||
|
'expressTemplateModel' => $expressTemplateModel |
||||
|
]), |
||||
|
], |
||||
|
[ |
||||
|
'label' => '<i class="fas fa-globe"></i> 选择配送区域', |
||||
|
'content' => $this->render('area', ['data' => $data, 'form' => $form, 'cities' => $cities |
||||
|
]), |
||||
|
], |
||||
|
], |
||||
|
'position' => TabsX::POS_ABOVE, |
||||
|
'encodeLabels' => false |
||||
|
]); |
||||
|
?>
|
||||
|
|
||||
|
<div class="form-group"> |
||||
|
<?= Html::submitButton('保存', ['class' => 'btn btn-success']) ?>
|
||||
|
<?= Html::a('返回', ['express-area-list', 'id' => $expressTemplateModel->id], ['class' => 'btn btn-info']) ?>
|
||||
|
</div> |
||||
|
|
||||
|
<?php ActiveForm::end(); ?>
|
||||
|
|
||||
|
</div> |
||||
|
</div> |
@ -0,0 +1,94 @@ |
|||||
|
<?php |
||||
|
|
||||
|
use backend\modules\shop\models\ars\City; |
||||
|
use backend\modules\shop\models\ars\ExpressArea; |
||||
|
use backend\modules\shop\models\ars\Province; |
||||
|
use yii\helpers\Html; |
||||
|
use yii\widgets\DetailView; |
||||
|
use backend\modules\shop\models\ars\ExpressTemplate; |
||||
|
|
||||
|
/* @var $this yii\web\View */ |
||||
|
/* @var $model backend\modules\shop\models\ars\ExpressTemplate */ |
||||
|
|
||||
|
$this->title = $model->id; |
||||
|
$this->params['breadcrumbs'][] = ['label' => '运费模板', 'url' => ['index']]; |
||||
|
$this->params['breadcrumbs'][] = ['label' => '运费区域模板:'.$expressTemplateModel->name, 'url' => ['express-area-list?id='.$expressTemplateModel->id]]; |
||||
|
$this->params['breadcrumbs'][] = $this->title; |
||||
|
\yii\web\YiiAsset::register($this); |
||||
|
?>
|
||||
|
<div class="express-template-view"> |
||||
|
|
||||
|
<p> |
||||
|
<?= Html::a('返回列表', ['express-area-list?id='.$expressTemplateModel->id], ['class' => 'btn btn-success']) ?>
|
||||
|
</p> |
||||
|
|
||||
|
<?= DetailView::widget([ |
||||
|
'model' => $model, |
||||
|
'attributes' => [ |
||||
|
'id', |
||||
|
[ |
||||
|
'attribute' => 'basic_count', |
||||
|
'label' => ExpressArea::$formList[$expressTemplateModel->calculation_type]['basic_count'], |
||||
|
'value' => function ($model) { |
||||
|
$expressTemplateModel = ExpressTemplate::findOne($model->express_template); |
||||
|
if ($expressTemplateModel->calculation_type == ExpressTemplate::CALCULATION_TYPE_WEIGHT) { |
||||
|
return $model->basic_count /= 10; |
||||
|
} else { |
||||
|
return $model->basic_count; |
||||
|
} |
||||
|
} |
||||
|
], |
||||
|
[ |
||||
|
'attribute' => 'basic_price', |
||||
|
'label' => ExpressArea::$formList[$expressTemplateModel->calculation_type]['basic_price'], |
||||
|
'value' => function ($model) { |
||||
|
return $model->basic_price /= 100; |
||||
|
} |
||||
|
], |
||||
|
[ |
||||
|
'attribute' => 'extra_count', |
||||
|
'label' => ExpressArea::$formList[$expressTemplateModel->calculation_type]['extra_count'], |
||||
|
'value' => function ($model) { |
||||
|
$expressTemplateModel = ExpressTemplate::findOne($model->express_template); |
||||
|
if ($expressTemplateModel->calculation_type == ExpressTemplate::CALCULATION_TYPE_WEIGHT) { |
||||
|
return $model->extra_count /= 10; |
||||
|
} else { |
||||
|
return $model->extra_count; |
||||
|
} |
||||
|
} |
||||
|
], |
||||
|
[ |
||||
|
'attribute' => 'extra_price', |
||||
|
'label' => ExpressArea::$formList[$expressTemplateModel->calculation_type]['extra_price'], |
||||
|
'value' => function ($model) { |
||||
|
return $model->extra_price /= 100; |
||||
|
} |
||||
|
], |
||||
|
'updated_at:datetime', |
||||
|
'created_at:datetime', |
||||
|
['attribute' => 'city', |
||||
|
'value' => function ($model) { |
||||
|
$expressAreas = ExpressArea::findOne($model->id); |
||||
|
$expressAresCityIdArr = explode(',', $expressAreas->city); |
||||
|
$cities = []; |
||||
|
$provinces = Province::find()->cache(0)->all(); |
||||
|
foreach ($provinces as $k => $v) { |
||||
|
$cityId = City::find() |
||||
|
->select(['city_id']) |
||||
|
->where(['province_id' => $v->province_id]) |
||||
|
->column(); |
||||
|
if (empty(array_diff($cityId, $expressAresCityIdArr))) { |
||||
|
$cities[] = $v->name; |
||||
|
}else{ |
||||
|
foreach (\backend\modules\shop\models\ars\City::find()->andWhere(['in', 'city_id', array_diff($cityId, array_diff($cityId, $expressAresCityIdArr))])->all() as $city) { |
||||
|
$cities[] = $city->name; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
return implode(' , ', $cities); |
||||
|
}, |
||||
|
], |
||||
|
], |
||||
|
]) ?>
|
||||
|
|
||||
|
</div> |
@ -1,47 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
use iron\widgets\Menu; |
|
||||
|
|
||||
?>
|
|
||||
<aside class="main-sidebar sidebar-dark-info elevation-4"> |
|
||||
<a href="#" class="brand-link"> |
|
||||
<img src="/img/logo.jpeg" alt="AdminLTE" class="brand-image img-circle elevation-3" |
|
||||
style="opacity: .8"> |
|
||||
<span class="brand-text font-weight-light">AdminLTE 3</span> |
|
||||
</a> |
|
||||
<!-- sidebar: style can be found in sidebar.less --> |
|
||||
<section class="sidebar"> |
|
||||
<?php |
|
||||
echo Menu::widget([ |
|
||||
'items' => [ |
|
||||
// ['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' => 'far fa-box', 'items' => [ |
|
||||
['label' => '后台商品分类', 'url' => ['/goods/category/index']], |
|
||||
['label' => '规格管理', 'url' => ['/goods/attribute/index']], |
|
||||
['label' => '前端商品分类', 'url' => ['/goods/shop-category/index']], |
|
||||
['label' => '品牌管理', 'url' => ['/goods/brand/index']], |
|
||||
['label' => '供应商管理', 'url' => ['/goods/supplier/index']], |
|
||||
['label' => '商品列表', 'url' => ['/goods/goods/index']], |
|
||||
] |
|
||||
], |
|
||||
['label' => '订单管理', 'url' => '#', 'icon' => 'far fa-list-alt', 'items' => [ |
|
||||
['label' => '订单列表', 'url' => ['/shop/order/index', 'tag' => 'new']], |
|
||||
], |
|
||||
], |
|
||||
['label' => '配送服务', 'url' => '#', 'icon' => 'far fa-shipping-fast', 'items' => [ |
|
||||
['label' => '上门自提', 'url' => ['/shop/taking-site/index']], |
|
||||
['label' => '运费模板', 'url' => ['/shop/express-template/index']], |
|
||||
] |
|
||||
], |
|
||||
|
|
||||
] |
|
||||
]); |
|
||||
?>
|
|
||||
</section> |
|
||||
<!-- /.sidebar --> |
|
||||
</aside> |
|
Before Width: 1024 | Height: 759 | Size: 159 KiB |
@ -0,0 +1,59 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace common\models; |
||||
|
/** |
||||
|
* Created by PhpStorm. |
||||
|
* User: iron |
||||
|
* Date: 19-1-15 |
||||
|
* Time: 下午7:40 |
||||
|
* |
||||
|
* @property int $admin_id 管理员id |
||||
|
* @property string $admin_name 管理员名 |
||||
|
* @property string $ip 客户端ip |
||||
|
* @property string $admin_agent 客户端版本 |
||||
|
* @property string $path 访问路径 |
||||
|
* @property string $method http方法 |
||||
|
* @property array $params 各类参数 |
||||
|
* @property int $created_at 创建时间 |
||||
|
*/ |
||||
|
|
||||
|
use yii\mongodb\ActiveRecord; |
||||
|
|
||||
|
class DailyActiveUser extends ActiveRecord |
||||
|
{ |
||||
|
/** |
||||
|
* @return string the name of the index associated with this ActiveRecord class. |
||||
|
*/ |
||||
|
public static function collectionName() |
||||
|
{ |
||||
|
return 'daily_active_user'; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array list of attribute names. |
||||
|
*/ |
||||
|
public function attributes() |
||||
|
{ |
||||
|
return ['_id', 'date', 'created_at', 'user_ids', 'count']; |
||||
|
} |
||||
|
|
||||
|
public function rules() |
||||
|
{ |
||||
|
return [ |
||||
|
['count','default','value'=>1], |
||||
|
['created_at','default','value'=>time()] |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
public function attributeLabels() |
||||
|
{ |
||||
|
return [ |
||||
|
'date' => '日期', |
||||
|
'created_at' => '创建时间', |
||||
|
'user_ids' => '用户id', |
||||
|
'count' => '数量' |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
@ -0,0 +1,41 @@ |
|||||
|
<?php |
||||
|
|
||||
|
use yii\db\Migration; |
||||
|
|
||||
|
/** |
||||
|
* Class m191122_011654_create_table_user_admin |
||||
|
*/ |
||||
|
class m191122_011654_add_column_admin_id_in_table_user extends Migration |
||||
|
{ |
||||
|
/** |
||||
|
* {@inheritdoc} |
||||
|
*/ |
||||
|
public function safeUp() |
||||
|
{ |
||||
|
$this->addColumn('user','admin_id',$this->integer(11)->notNull()->defaultValue(0)); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* {@inheritdoc} |
||||
|
*/ |
||||
|
public function safeDown() |
||||
|
{ |
||||
|
$this->dropColumn('user','admin_id'); |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/* |
||||
|
// Use up()/down() to run migration code without a transaction.
|
||||
|
public function up() |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
public function down() |
||||
|
{ |
||||
|
echo "m191122_011654_create_table_user_admin cannot be reverted.\n"; |
||||
|
|
||||
|
return false; |
||||
|
} |
||||
|
*/ |
||||
|
} |
@ -0,0 +1,26 @@ |
|||||
|
<?php |
||||
|
|
||||
|
use yii\db\Migration; |
||||
|
|
||||
|
/** |
||||
|
* Class m191111_102644_create_table_province |
||||
|
*/ |
||||
|
class m191204_092644_rename_backend_user extends Migration |
||||
|
{ |
||||
|
/** |
||||
|
* {@inheritdoc} |
||||
|
*/ |
||||
|
public function up() |
||||
|
{ |
||||
|
$sql = 'alter table user rename to auth_user '; |
||||
|
$this->execute($sql); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* {@inheritdoc} |
||||
|
*/ |
||||
|
public function down() |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
} |
@ -0,0 +1,52 @@ |
|||||
|
<?php |
||||
|
|
||||
|
use yii\db\Migration; |
||||
|
|
||||
|
/** |
||||
|
* Class m191111_102644_create_table_province |
||||
|
*/ |
||||
|
class m191204_102644_create_table_province extends Migration |
||||
|
{ |
||||
|
/** |
||||
|
* {@inheritdoc} |
||||
|
*/ |
||||
|
public function up() |
||||
|
{ |
||||
|
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB COMMENT="用户"'; |
||||
|
$this->createTable('user', [ |
||||
|
'id' => $this->primaryKey(), |
||||
|
'username'=>$this->string(255)->comment('用户名'), |
||||
|
'auth_key'=>$this->string(32)->notNull()->comment(''), |
||||
|
'password_hash'=>$this->string(255)->notNull()->comment(''), |
||||
|
'password_reset_token'=>$this->string(255)->defaultValue(null)->comment(''), |
||||
|
'name'=>$this->string(120)->comment('姓名'), |
||||
|
'sex'=>$this->integer(1)->comment('性别'), |
||||
|
'phone'=>$this->string(13)->comment('联系方式'), |
||||
|
'email'=>$this->string(255)->comment('邮箱'), |
||||
|
'role'=>$this->tinyInteger(1)->defaultValue(1)->comment('角色'), |
||||
|
'status'=>$this->tinyInteger(1)->defaultValue(1)->comment('状态'), |
||||
|
'access_token'=>$this->string(255)->comment('令牌'), |
||||
|
'expire_at'=>$this->integer(11)->comment('令牌过期时间'), |
||||
|
'nickname'=>$this->string(120)->comment('昵称'), |
||||
|
'avatar'=>$this->string(255)->comment('头像'), |
||||
|
'wx_openid'=>$this->string(32)->comment('微信openid'), |
||||
|
'mini_openid'=>$this->string(32)->comment('小程序openid'), |
||||
|
'unionid'=>$this->string(60)->comment('微信联合id'), |
||||
|
'session_key'=>$this->string(120)->comment('小程序会话秘钥'), |
||||
|
'member_code'=>$this->string(20)->comment('会员编号'), |
||||
|
'exp_point'=>$this->integer(20)->comment('经验值'), |
||||
|
'consume_point'=>$this->integer(20)->defaultValue(null)->comment('消费积分'), |
||||
|
'created_at'=>$this->integer(11)->notNull()->comment('创建时间'), |
||||
|
'updated_at'=>$this->integer(11)->notNull()->comment('更新时间'), |
||||
|
],$tableOptions); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* {@inheritdoc} |
||||
|
*/ |
||||
|
public function down() |
||||
|
{ |
||||
|
$this->dropTable("user"); |
||||
|
return true; |
||||
|
} |
||||
|
} |
83
console/runtime/logs/app.log
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
Some files were not shown because too many files changed in this diff
Write
Preview
Loading…
Cancel
Save
Reference in new issue