Commit 4d70f3f1 authored by 张晓林's avatar 张晓林

Merge branch 'development' of http://gitlab-ebiz.yiyao365.cn/newshop/newshopback into development

parents 5901030f 5e165b84
...@@ -17,6 +17,7 @@ return [ ...@@ -17,6 +17,7 @@ return [
'v1/shopuser/user-department', 'v1/shopuser/user-department',
'v1/shopuser/shop-user', 'v1/shopuser/shop-user',
'v1/shopuser/user-complain', 'v1/shopuser/user-complain',
'v1/branch/branch-service-type',
'v1/shopuser/shop-user-list', 'v1/shopuser/shop-user-list',
], ],
'extraPatterns'=>[ 'extraPatterns'=>[
...@@ -33,6 +34,10 @@ return [ ...@@ -33,6 +34,10 @@ return [
'POST,OPTIONS add' => 'add', 'POST,OPTIONS add' => 'add',
'DELETE,OPTIONS del' => 'del', 'DELETE,OPTIONS del' => 'del',
'GET,OPTIONS branch-score-list' => 'branch-score-list', 'GET,OPTIONS branch-score-list' => 'branch-score-list',
'GET,OPTIONS branch-service-list' => 'branch-service-list',
'POST,OPTIONS add-branch-service' => 'add-branch-service',
'PUT,OPTIONS revise-branch-service' => 'revise-branch-service',
'DELETE,OPTIONS del-branch-service' => 'del-branch-service',
'GET,OPTIONS user-list' => 'user-list', 'GET,OPTIONS user-list' => 'user-list',
'GET,OPTIONS user-detail'=>'user-detail', 'GET,OPTIONS user-detail'=>'user-detail',
'GET,OPTIONS user-update'=>'user-update', 'GET,OPTIONS user-update'=>'user-update',
......
<?php
namespace backend\controllers\v1\branch;
use Yii;
use backend\controllers\v1\BaseController;
use yii\web\BadRequestHttpException;
use app\models\v1\branch\BranchServiceType;
use backend\helpers\Func;
class BranchServiceTypeController extends BaseController
{
public $modelClass='app\models\v1\branch\BranchServiceType';
/**
* @OA\Get(
* path="/backend/web/v1/branch/branch-service-types/branch-service-list",
* tags={"门店&DC"},
* description="门店服务类目列表",
* summary="门店服务类目列表(孙磊)",
* operationId="Department",
* @OA\Parameter(name="code",in="query",description="门店服务类目编号",@OA\Schema(type="string")),
* @OA\Parameter(name="name",in="query",description="门店服务类目名称",@OA\Schema(type="string")),
* @OA\Response(response="200",description="OK。一切正常"),
* security={{"Authorization": {}}}
* )
*/
public function actionBranchServiceList()
{
$model=new $this->modelClass();
//用户输入数据赋值到模型属性
$model->CODE = Yii::$app->request->get('code');
$model->NAME = Yii::$app->request->get('name');
if ($model->validate()) {
//所有输入数据都有效 all inputs are valid
$code = $model->CODE;
$name = $model->NAME;
$info = $model->BranchServiceInfo($code,$name);
if (!$info->getModels()) {
throw new BadRequestHttpException('未找到符合的门店服务类目信息');
}
return $info;
} else {
//验证失败:$errors 是一个包含错误信息的数组
$errors = $model->errors;
return $errors;
}
}
/**
* @OA\POST(
* path="/backend/web/v1/branch/branch-service-types/add-branch-service",
* tags={"门店&DC"},
* summary="添加门店服务类目接口(孙磊)",
* description="添加门店服务类目接口",
* @OA\RequestBody(
* required=true,
* @OA\MediaType(
* mediaType="application/x-www-form-urlencoded",
* @OA\Schema(
* type="object",
* @OA\Property(property="CODE",description="服务类目编号",type="string"),
* @OA\Property(property="NAME",description="服务类目名称,最长20字",type="string"),
* @OA\Property(property="DESCRIPTION",description="服务类目描述",type="string"),
* @OA\Property(property="THEME_COLOR",description="主题颜色",type="string"),
* )
* )
* ),
* @OA\Response(response=200,description="success"),
* security={{"Authorization": {}}}
* )
*/
public function actionAddBranchService()
{
$model = new $this->modelClass();
$model->scenario = 'create';//创建的场景
// $datetime = new \DateTime;
// $create_time = $datetime->format('Y-m-d H:i:s');
$create_time = date('Y-m-d H:i:s',time());
$other_param = array(
'GUID'=>Func::create_guid(),
'ORG_GUID'=>Yii::$app->user->identity->ORG_GUID,
'CREATE_TIME'=>$create_time,
);
$model->setAttributes($other_param);
$model->setAttributes(Yii::$app->getRequest()->post());
if ($model->save()) {
Yii::$app->getResponse()->setStatusCode(201);
} elseif (!$model->hasErrors()) {
throw new ServerErrorHttpException('Failed to create the object for unknown reason.');
}
return $model;
}
/**
* @OA\PUT(
* path="/backend/web/v1/branch/branch-service-types/revise-branch-service",
* tags={"门店&DC"},
* summary="修改门店服务类目接口(孙磊)",
* description="修改门店服务类目接口",
* @OA\RequestBody(
* required=true,
* @OA\MediaType(
* mediaType="application/x-www-form-urlencoded",
* @OA\Schema(
* type="object",
* @OA\Property(property="GUID",description="要修改的服务类目GUID",type="string"),
* @OA\Property(property="CODE",description="服务类目编号",type="string"),
* @OA\Property(property="NAME",description="服务类目名称,最长20字",type="string"),
* @OA\Property(property="DESCRIPTION",description="服务类目描述",type="string"),
* @OA\Property(property="THEME_COLOR",description="主题颜色",type="string"),
* )
* )
* ),
* @OA\Response(response=200,description="成功时返回access-token"),
* security={{"Authorization": {}}}
* )
*/
public function actionReviseBranchService()
{
$guid = Yii::$app->getRequest()->post('GUID');
$model = $this->modelClass::findOne($guid);
if(!$model){
throw new BadRequestHttpException('没有找到要修改的记录');
}
$model->scenario = 'update';//创建的场景
$model->setAttributes(Yii::$app->getRequest()->post());
if ($model->save() === false && !$model->hasErrors()) {
throw new ServerErrorHttpException('Failed to update the object for unknown reason.');
}
return $model;
}
/**
* @OA\DELETE(
* path="/backend/web/v1/branch/branch-service-types/del-branch-service",
* tags={"门店&DC"},
* summary="删除门店服务类目接口(孙磊)",
* description="删除门店服务类目接口",
* @OA\RequestBody(
* required=true,
* @OA\MediaType(
* mediaType="application/x-www-form-urlencoded",
* @OA\Schema(
* type="object",
* @OA\Property(property="GUID",description="要删除的门店服务类目GUID",type="string"),
* )
* )
* ),
* @OA\Response(response=204,description="门店服务类目删除成功"),
* security={{"Authorization": {}}}
* )
*/
public function actionDelBranchService()
{
$guid = Yii::$app->getRequest()->post('GUID');
$model = new $this->modelClass();
$branchservice = $model::findOne($guid);
if(!$branchservice){
throw new BadRequestHttpException('没有找到要删除的记录');
}else if ($branchservice->delete() === false) {
throw new ServerErrorHttpException('Failed to delete the object for unknown reason.');
}
Yii::$app->getResponse()->setStatusCode(204);
return $branchservice;
}
}
<?php
namespace app\models\v1\branch;
use Yii;
use app\models\v1\BaseModel;
use yii\data\ActiveDataProvider;
/**
* This is the model class for table "shop_branch_service_type".
*
* @property string $GUID
* @property string $ORG_GUID 组织机构号
* @property string $CODE 服务类目编号
* @property string $NAME 服务类目名称
* @property string $THEME_COLOR 主题颜色
* @property string $DESCRIPTION 服务类目描述
* @property string $CREATE_TIME 创建时间
*/
class BranchServiceType extends BaseModel
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'shop_branch_service_type';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['GUID'], 'required','on'=>['create','update']],
[['CREATE_TIME'], 'safe'],
[['GUID', 'ORG_GUID', 'CODE', 'NAME'], 'string', 'max' => 50],
[['THEME_COLOR', 'DESCRIPTION'], 'string', 'max' => 255],
[['GUID'], 'unique'],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'GUID' => 'Guid',
'ORG_GUID' => 'Org Guid',
'CODE' => 'Code',
'NAME' => 'Name',
'THEME_COLOR' => 'Theme Color',
'DESCRIPTION' => 'Description',
'CREATE_TIME' => 'Create Time',
];
}
//门店-门店服务类目信息
public function BranchServiceInfo($code,$name)
{
$query = static::find()->select('GUID,NAME,CODE,THEME_COLOR,DESCRIPTION,CREATE_TIME');
if (isset($name) && !empty($name)) {
$query->andWhere(['like', 'NAME', $name]);
}
if (isset($code) && !empty($code)) {
$query->andWhere(['like', 'CODE', $code]);
}
return new ActiveDataProvider(
[
'query' => $query->asArray(),
'pagination' => [
'pageSize' => 15,
]
]
);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment