Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
newShopBack
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
newshop
newShopBack
Commits
cadc77de
Commit
cadc77de
authored
Nov 08, 2019
by
姚书霞
🐘
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改
parent
a28ad944
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
115 additions
and
8 deletions
+115
-8
main.php
backend/config/main.php
+1
-1
ShopUserMembergradeController.php
...controllers/v1/shopuser/ShopUserMembergradeController.php
+79
-5
Func.php
backend/helpers/Func.php
+14
-0
ShopUserMembergrade.php
backend/models/v1/shopuser/ShopUserMembergrade.php
+21
-2
No files found.
backend/config/main.php
View file @
cadc77de
...
...
@@ -53,7 +53,7 @@ return [
'swagger'
,
'v1/shop/branch/branch'
,
'v1/rbacuser/rbac-user'
,
'v1/shopuser/shop-user-membergrade'
,
'v1/shopuser/shop-user-membergrade'
],
'extraPatterns'
=>
[
'GET,OPTIONS test'
=>
'test'
,
...
...
backend/controllers/v1/shopuser/ShopUserMembergradeController.php
View file @
cadc77de
...
...
@@ -4,6 +4,7 @@ namespace backend\controllers\v1\shopuser;
use
Yii
;
use
backend\controllers\v1\BaseController
;
use
backend\helpers\Func
;
class
ShopUserMembergradeController
extends
BaseController
{
...
...
@@ -18,8 +19,10 @@ class ShopUserMembergradeController extends BaseController
{
$actions
=
parent
::
actions
();
// 禁用 "delete" 和 "create" 动作
//unset($actions['delete'], $actions['create']);
// 重写 "create" 动作
unset
(
$actions
[
'create'
],
$actions
[
'update'
],
$actions
[
'view'
]
);
// 使用 "prepareDataProvider()" 方法自定义数据 provider
// $actions['index']['prepareDataProvider'] = [$this, 'prepareDataProvider'];
...
...
@@ -45,8 +48,8 @@ class ShopUserMembergradeController extends BaseController
* security={{"Authorization": {}}}
* )
*/
//重
定义 index下面的prepareDataProvider方法
// public function
prepareDataProvider
()
//重
写index
// public function
actionIndex
()
// {
// }
...
...
@@ -74,4 +77,75 @@ class ShopUserMembergradeController extends BaseController
* security={{"Authorization": {}}}
* )
*/
public
function
actionCreate
()
{
$model
=
new
$this
->
modelClass
();
$model
->
scenario
=
'create'
;
//创建的场景
$other_param
=
array
(
'GUID'
=>
Func
::
create_guid
(),
'ORG_GUID'
=>
'100'
,
//todo 公共变量
);
$model
->
setAttributes
(
$other_param
);
$model
->
setAttributes
(
Yii
::
$app
->
getRequest
()
->
post
());
// $model->attributes = $other_param;
// print_r($model);die;
if
(
$model
->
save
())
{
$response
=
Yii
::
$app
->
getResponse
();
$response
->
setStatusCode
(
200
);
}
elseif
(
!
$model
->
hasErrors
())
{
throw
new
ServerErrorHttpException
(
'Failed to create the object for unknown reason.'
);
}
return
1
;
}
/**
* @OA\POST(
* path="/backend/web/v1/shopuser/shop-user-membergrades/123",
* tags={"用户&员工接口"},
* summary="添加用户组接口",
* description="添加用户组接口",
* @OA\RequestBody(
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(
* @OA\Property(property="NAME",type="string"),
* @OA\Property(property="IS_DEFAULT",type="string"),
* @OA\Property(property="GRADE_PERCENT",type="float"),
* @OA\Property(property="IS_SETRANGE",type="string"),
* @OA\Property(property="MONEY_POINT_SRATE",type="float"),
* example={"NAME":"用户组A", "IS_DEFAULT": "1","GRADE_PERCENT": 2.22,"IS_SETRANGE": "0","MONEY_POINT_SRATE":23.1},
* )
* )
* ),
* @OA\Response(response=200,description="成功时返回access-token"),
* security={{"Authorization": {}}}
* )
*/
public
function
actionUpdate
()
{
echo
2
;
die
;
$model
=
new
$this
->
modelClass
();
$model
->
scenario
=
'create'
;
//创建的场景
$other_param
=
array
(
'GUID'
=>
Func
::
create_guid
(),
'ORG_GUID'
=>
'100'
,
//todo 公共变量
);
$model
->
setAttributes
(
$other_param
);
$model
->
setAttributes
(
Yii
::
$app
->
getRequest
()
->
post
());
// $model->attributes = $other_param;
// print_r($model);die;
if
(
$model
->
save
())
{
$response
=
Yii
::
$app
->
getResponse
();
$response
->
setStatusCode
(
200
);
}
elseif
(
!
$model
->
hasErrors
())
{
throw
new
ServerErrorHttpException
(
'Failed to create the object for unknown reason.'
);
}
return
1
;
}
}
\ No newline at end of file
backend/helpers/Func.php
0 → 100644
View file @
cadc77de
<?php
namespace
backend\helpers
;
class
Func
{
public
static
function
create_guid
()
{
if
(
function_exists
(
'com_create_guid'
)
===
true
)
{
return
trim
(
com_create_guid
(),
'{}'
);
}
return
sprintf
(
'%04X%04X-%04X-%04X-%04X-%04X%04X%04X'
,
mt_rand
(
0
,
65535
),
mt_rand
(
0
,
65535
),
mt_rand
(
0
,
65535
),
mt_rand
(
16384
,
20479
),
mt_rand
(
32768
,
49151
),
mt_rand
(
0
,
65535
),
mt_rand
(
0
,
65535
),
mt_rand
(
0
,
65535
));
}
}
backend/models/v1/shopuser/ShopUserMembergrade.php
View file @
cadc77de
...
...
@@ -21,6 +21,9 @@ use yii\db\Expression;
*/
class
ShopUserMembergrade
extends
BaseModel
{
// const SCENARIO_CREATE = 'create';
// const SCENARIO_UPDATE = 'update';
/**
* {@inheritdoc}
*/
...
...
@@ -30,6 +33,7 @@ class ShopUserMembergrade extends BaseModel
}
/**
* 自动完成 创建时间和更新时间
* {@inheritdoc}
*/
public
function
behaviors
()
...
...
@@ -48,6 +52,19 @@ class ShopUserMembergrade extends BaseModel
}
/**
* 场景值的重写
* {@inheritdoc}
*/
// public function scenarios()
// {
// return [
// self::SCENARIO_CREATE => ['a', 'aw'],
// self::SCENARIO_UPDATE => ['username', 'email', 'password'],
// ];
// }
/**
* 验证
* {@inheritdoc}
*/
public
function
rules
()
...
...
@@ -59,7 +76,9 @@ class ShopUserMembergrade extends BaseModel
[[
'IS_DEFAULT'
],
'boolean'
],
[[
'IS_SETRANGE'
],
'in'
,
'range'
=>
[
0
,
1
,
2
]],
[[
'NAME'
],
'string'
,
'max'
=>
20
],
[[
'GUID'
],
'unique'
],
[[
'GUID'
],
'required'
,
'on'
=>
'update'
],
[[
'GUID'
],
'safe'
,
'on'
=>
'create'
],
[[
'ORG_GUID'
],
'safe'
],
];
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment