Commit fef9454f authored by 姚书霞's avatar 姚书霞 🐘

代码优化

parents 7a95cd5a 440117d7
......@@ -22,7 +22,7 @@ use backend\components\v1\authorizationFilter;
* ),
* @OA\Server(
* description="Api server",
* url="/yaoshuxia/shopback",
* url="/guoyongzhi/weiShopNew",
* ),
* @OA\SecurityScheme(
* securityScheme="Authorization",
......@@ -60,7 +60,7 @@ class BaseController extends ActiveController
public $serializer = [
'class' => 'yii\rest\Serializer',
'collectionEnvelope' => 'data',
'preserveKeys'=>true,
'preserveKeys' => true,
];
public function behaviors()
{
......
......@@ -6,7 +6,7 @@ use Yii;
use backend\controllers\v1\BaseController;
use backend\helpers\Func;
use yii\web\BadRequestHttpException;
use yii\web\ServerErrorHttpException;
use yii\web\HttpException;
use app\models\v1\rbacuser\ShopRbacRoleAccess;
class AuthorityRoleController extends BaseController
......@@ -116,7 +116,6 @@ class AuthorityRoleController extends BaseController
if ($model->save()) {
Yii::$app->getResponse()->setStatusCode(201);
} elseif (!$model->hasErrors()) {
// throw new ServerErrorHttpException('Failed to create the object for unknown reason.');
throw new HttpException(500, '添加失败');
}
return $model;
......@@ -163,7 +162,6 @@ class AuthorityRoleController extends BaseController
$model->setAttributes(Yii::$app->getRequest()->post());
if ($model->save() === false && !$model->hasErrors()) {
// throw new ServerErrorHttpException('Failed to update the object for unknown reason.');
throw new HttpException(500, '修改失败');
}
Yii::$app->getResponse()->setStatusCode(202);
......
......@@ -12,7 +12,6 @@ use app\models\v1\transport\ShopTransportType;
use app\models\v1\branch\ShopBranchService;
use yii\web\BadRequestHttpException;
use backend\helpers\Func;
use yii\web\ServerErrorHttpException;
use yidas\phpSpreadsheet\Helper;
use yii\data\ActiveDataProvider;
use app\models\v1\rbacuser\ShopRbacUser;
......@@ -60,7 +59,6 @@ class BranchController extends BaseController
$rbac = new ShopRbacUser();
$userGuid = Yii::$app->user->identity->GUID;
$userinfo = $rbac->getRbacUserInfo($userGuid);
// print_r($userinfo);die();
$where_branch = '';
//是否是 分公司管理员 是的话只显示所管理门店的数据
if ($userinfo['ROLE_ID'] == USER_ROLE_REGION_ADMIN) {
......@@ -79,7 +77,7 @@ class BranchController extends BaseController
if ($model->validate()) {
//所有输入数据都有效 all inputs are valid
$info = $model->BranchInfo($params);
$info = $model->branchInfo($params);
if (!$list = $info->getModels()) {
throw new BadRequestHttpException('未找到符合的门店列表信息');
}
......@@ -117,16 +115,16 @@ class BranchController extends BaseController
if ($model->validate()) {
//所有输入数据都有效 all inputs are valid
$info = $model->BranchDetail($params['GUID']);
$info = $model->branchDetail($params['GUID']);
if (!$list = $info->getModels()) {
throw new BadRequestHttpException('未找到符合的门店列表信息');
}
//获取门店服务类目关系信息
$branchServiceRelation = $branchService->BranchSeviceRelation($params['GUID']);
$branchServiceRelation = $branchService->branchSeviceRelation($params['GUID']);
//获取门店服务类目名称
if ($branchServiceRelation) {
foreach ($branchServiceRelation as $k => $v) {
$branchSType = $branchServiceType->BranchServiceInfo('', '', $v['SERVICE_TYPE_GUID']);
$branchSType = $branchServiceType->branchServiceInfo('', '', $v['SERVICE_TYPE_GUID']);
$branchSerType = $branchSType->getModels();
//获取服务类目信息
if ($branchSerType) {
......@@ -212,7 +210,7 @@ class BranchController extends BaseController
if (isset($param['BRANCH_SERVICE_TYPE']) && !empty($param['BRANCH_SERVICE_TYPE'])) {
$ShopBranchService->scenario = 'create'; //创建的场景
//删除门店原有服务类目
$ShopBranchService->BranchServiceDel($branch_guid);
$ShopBranchService->branchServiceDel($branch_guid);
$BST = $param['BRANCH_SERVICE_TYPE'];
//判断门店服务类目类型
if (is_string($BST)) {
......@@ -252,7 +250,6 @@ class BranchController extends BaseController
$model = new $this->modelClass();
$model->scenario = 'create'; //创建的场景
$other_param = array(
//'GUID'=>Func::create_guid(),
'GUID' => $branch_guid,
'ORG_GUID' => Yii::$app->user->identity->ORG_GUID,
'UPDATE_TIME' => date('Y-m-d H:i:s', time()),
......@@ -265,7 +262,6 @@ class BranchController extends BaseController
if ($model->save()) {
Yii::$app->getResponse()->setStatusCode(201);
} elseif (!$model->hasErrors()) {
// throw new ServerErrorHttpException('Failed to create the object for unknown reason.');
throw new HttpException(500, '添加失败');
}
return $model;
......@@ -292,7 +288,7 @@ class BranchController extends BaseController
public function actionBranchServices()
{
$model = new BranchServiceType();
$info = $model->BranchServiceInfoAll();
$info = $model->branchServiceInfoAll();
if (!$info) {
throw new BadRequestHttpException('未找到符合的门店服务类目信息');
}
......@@ -317,9 +313,9 @@ class BranchController extends BaseController
public function actionBranchTransportType()
{
$model = new ShopTransportType;
$info = $model->BranchTransportInfo();
$info = $model->branchTransportInfo();
if (!$info) {
throw new BadRequestHttpException('未找到符合的门店门店配送方式');
throw new BadRequestHttpException('未找到符合的门店配送方式');
}
return new ActiveDataProvider([
'models' => $info,
......@@ -501,7 +497,7 @@ class BranchController extends BaseController
if (isset($BRANCH_SERVICE_TYPE) && !empty($BRANCH_SERVICE_TYPE)) {
$ShopBranchService->scenario = 'create'; //创建的场景
//删除门店原有服务类目
$ShopBranchService->BranchServiceDel($branch_guid);
$ShopBranchService->branchServiceDel($branch_guid);
//判断门店服务类目类型
if (is_string($BRANCH_SERVICE_TYPE)) {
$BST_arr = explode(',', $BRANCH_SERVICE_TYPE);
......@@ -547,7 +543,6 @@ class BranchController extends BaseController
$model->setAttributes(Yii::$app->getRequest()->post());
if ($model->save() === false && !$model->hasErrors()) {
// throw new ServerErrorHttpException('Failed to update the object for unknown reason.');
throw new HttpException(500, '修改失败');
}
Yii::$app->getResponse()->setStatusCode(202);
......@@ -582,7 +577,6 @@ class BranchController extends BaseController
if (!$branchservice) {
throw new BadRequestHttpException('没有找到要删除的记录');
} else if ($branchservice->delete() === false) {
// throw new ServerErrorHttpException('Failed to delete the object for unknown reason.');
throw new HttpException(500, '删除失败');
}
......@@ -795,7 +789,7 @@ class BranchController extends BaseController
$string = substr($string, 0, strlen($string) - 1);
$_branchModel->TRANSPORT_TYPE = (string) $string;
$_servicModel = clone $servicModel;
$_servicModel->BranchServiceDel($_branchModel->GUID);
$_servicModel->branchServiceDel($_branchModel->GUID);
$serviceCode = explode(',', $_branchModel->SERVICE_TYPE_CODE);
$serviceArr = [];
foreach ($serviceCode as $servValue) {
......@@ -1028,7 +1022,7 @@ class BranchController extends BaseController
$model = new $this->modelClass();
$guid = Yii::$app->request->getQueryParam('guid');
$info = $model->BranchDetail($guid);
$info = $model->branchDetail($guid);
if (!$info->getModels()) {
throw new BadRequestHttpException('未找到符合的DC信息');
}
......@@ -1104,7 +1098,6 @@ class BranchController extends BaseController
$model->setAttributes($other_param);
$model->setAttributes(Yii::$app->getRequest()->post());
if ($model->save() === false && !$model->hasErrors()) {
// throw new ServerErrorHttpException('Failed to update the object for unknown reason.');
throw new HttpException(500, '修改失败');
}
return $model;
......
......@@ -9,10 +9,7 @@ use backend\helpers\Func;
use backend\helpers\UploadFiles;
use yidas\phpSpreadsheet\Helper;
use yii\web\HttpException;
use yii\web\ServerErrorHttpException;
use yii\web\UploadedFile;
use app\models\v1\branch\BranchServiceType;
use app\models\v1\rbacuser\ShopRbacUser;
class BranchServiceTypeController extends BaseController
......@@ -52,7 +49,7 @@ class BranchServiceTypeController extends BaseController
//所有输入数据都有效 all inputs are valid
$code = $model->CODE;
$name = $model->NAME;
$info = $model->BranchServiceInfo($code, $name);
$info = $model->branchServiceInfo($code, $name);
if (!$info->getModels()) {
throw new BadRequestHttpException('未找到符合的门店服务类目信息');
}
......@@ -91,7 +88,7 @@ class BranchServiceTypeController extends BaseController
if ($model->validate()) {
//所有输入数据都有效 all inputs are valid
$code = $model->CODE;
$info = $model->BranchServiceInfo($code, '');
$info = $model->branchServiceInfo($code, '');
if (!$info->getModels()) {
throw new BadRequestHttpException('未找到符合的门店服务类目信息');
}
......@@ -145,7 +142,6 @@ class BranchServiceTypeController extends BaseController
if ($model->save()) {
Yii::$app->getResponse()->setStatusCode(201);
} elseif (!$model->hasErrors()) {
// throw new ServerErrorHttpException('Failed to create the object for unknown reason.');
throw new HttpException(500, '添加失败');
}
return $model;
......@@ -186,7 +182,6 @@ class BranchServiceTypeController extends BaseController
$model->setAttributes(Yii::$app->getRequest()->post());
if ($model->save() === false && !$model->hasErrors()) {
// throw new ServerErrorHttpException('Failed to update the object for unknown reason.');
throw new HttpException(500, '修改失败');
}
Yii::$app->getResponse()->setStatusCode(202);
......@@ -221,7 +216,6 @@ class BranchServiceTypeController extends BaseController
if (!$branchservice) {
throw new BadRequestHttpException('没有找到要删除的记录');
} else if ($branchservice->delete() === false) {
// throw new ServerErrorHttpException('Failed to delete the object for unknown reason.');
throw new HttpException(500, '删除失败');
}
......@@ -334,7 +328,7 @@ class BranchServiceTypeController extends BaseController
throw new HttpException(422, json_encode($model->errors));
}
$list = $model->BranchServiceExport($params);
$list = $model->branchServiceExport($params);
if (!$list) {
throw new BadRequestHttpException('未找到符合条件的数据');
}
......
......@@ -383,7 +383,7 @@ class ImportGoodsInfoController extends BaseController
$value[5] = preg_replace("/,/", ",", $value[5]);
$transportType = explode(',', $value[5]);
//获取配送方式信息
$getTransportTypeInfo = $transportModel->BranchTransportInfo($transportType);
$getTransportTypeInfo = $transportModel->branchTransportInfo($transportType);
if ($getTransportTypeInfo) {
$transportGuid = array_column($getTransportTypeInfo, 'GUID');
$transportGuid_str = implode(',', $transportGuid);
......@@ -734,7 +734,7 @@ class ImportGoodsInfoController extends BaseController
$value[3] = preg_replace("/,/", ",", $value[3]);
$transportType = explode(',', $value[3]);
//获取配送方式信息
$getTransportTypeInfo = $transportModel->BranchTransportInfo($transportType);
$getTransportTypeInfo = $transportModel->branchTransportInfo($transportType);
if ($getTransportTypeInfo) {
$transportGuid = array_column($getTransportTypeInfo, 'GUID');
$transportGuid_str = implode(',', $transportGuid);
......
......@@ -10,7 +10,7 @@ use yii\web\BadRequestHttpException;
class UserComplainController extends BaseController
{
public $modelClass = 'app\models\v1\shopuser\UserComplain';
/**
* @OA\Get(
* path="/backend/web/v1/shopuser/user-complains/user-complain",
......@@ -33,15 +33,15 @@ class UserComplainController extends BaseController
if ($model->validate()) {
//所有输入数据都有效 all inputs are valid
$phone = $model->TS_PHONE;
$info = $model->UserComplainInfo($phone);
$info = $model->userComplainInfo($phone);
if (!$info->getModels()) {
throw new BadRequestHttpException('未找到符合的留言信息');
}
return $info;
} else {
//验证失败:$errors 是一个包含错误信息的数组
$errors = $model->errors;
return $errors;
Yii::$app->response->statusCode = 422;
return $model->errors;
}
}
}
......@@ -10,7 +10,7 @@ use yii\web\BadRequestHttpException;
class UserDepartmentController extends BaseController
{
public $modelClass = 'app\models\v1\shopuser\UserDepartment';
/**
* @OA\Get(
* path="/backend/web/v1/shopuser/user-departments/department",
......@@ -36,15 +36,15 @@ class UserDepartmentController extends BaseController
//所有输入数据都有效 all inputs are valid
$code = $model->CODE;
$name = $model->NAME;
$info = $model->DepartmentInfo($code, $name);
$info = $model->departmentInfo($code, $name);
if (!$info->getModels()) {
throw new BadRequestHttpException('未找到符合的部门信息');
}
return $info;
} else {
//验证失败:$errors 是一个包含错误信息的数组
$errors = $model->errors;
return $errors;
Yii::$app->response->statusCode = 422;
return $model->errors;
}
}
}
......@@ -77,7 +77,7 @@ class O2oDeliveryController extends BaseController
->andFilterWhere(['scds.SETTING_TYPE'=>O2O_FLAG])//设定为o2o配送
->andFilterWhere(['or',['sb.CODE'=>$model->BRANCH_INFO],['like','sb.NAME',$model->BRANCH_INFO]])
->andFilterWhere(['sb.GUID'=>$branchGuid])
->orFilterWhere(['sb.PARENTGUID'=>$parentBranchGuid])
->orFilterWhere(['sb.PARENT_GUID'=>$parentBranchGuid])
->asArray()->all();
return new ArrayDataProvider(
[
......
......@@ -6,11 +6,9 @@ use Yii;
use backend\controllers\v1\BaseController;
use app\models\v1\branch\ShopCityDistributionRegion;
use yii\web\BadRequestHttpException;
use yii\web\ServerErrorHttpException;
use yii\web\UploadedFile;
use backend\helpers\UploadFiles;
use yidas\phpSpreadsheet\Helper;
use backend\helpers\Func;
use yii\web\HttpException;
use app\models\v1\rbacuser\ShopRbacUser;
use app\models\v1\branch\ShopBranch;
......@@ -135,7 +133,6 @@ class TransportInitialPriceController extends BaseController
$model->setAttributes($param);
if ($model->save() === false && !$model->hasErrors()) {
// throw new ServerErrorHttpException('Failed to update the object for unknown reason.');
throw new HttpException(500, '修改失败');
}
Yii::$app->getResponse()->setStatusCode(202);
......@@ -208,8 +205,8 @@ class TransportInitialPriceController extends BaseController
// if ($userinfo['ROLE_ID'] == USER_ROLE_REGION_ADMIN) {
// //如果是省级,查询出该门店是否是该省级下的
// $branchModel = new ShopBranch();
// $isbrancharr = $branchModel->GetBranch($CS_BRANCH_GUID, $userinfo['BRANCH_GUID']);
// // $isbrancharr = $branchModel->GetBranch(003, 003);
// $isbrancharr = $branchModel->getBranch($CS_BRANCH_GUID, $userinfo['BRANCH_GUID']);
// // $isbrancharr = $branchModel->getBranch(003, 003);
// if (!$isbrancharr) {
// continue;
// }
......
......@@ -61,7 +61,7 @@ class BranchServiceType extends BaseModel
];
}
//门店-门店服务类目信息
public function BranchServiceInfo($code, $name, $guid = '')
public function branchServiceInfo($code, $name, $guid = '')
{
$query = static::find()->select('GUID,NAME,CODE,THEME_COLOR,DESCRIPTION,CREATE_TIME');
......@@ -81,13 +81,13 @@ class BranchServiceType extends BaseModel
[
'query' => $query->asArray(),
'pagination' => [
'pageSize' => 15,
'pageSize' => PAGE_SIZE,
]
]
);
}
//门店-门店服务类目信息 全部
public function BranchServiceInfoAll()
public function branchServiceInfoAll()
{
$query = static::find()->select('GUID,NAME,CODE,THEME_COLOR,DESCRIPTION,CREATE_TIME')
->all();
......@@ -95,7 +95,7 @@ class BranchServiceType extends BaseModel
return $query;
}
//门店服务类目导出
public function BranchServiceExport($params)
public function branchServiceExport($params)
{
$query = static::find()->select('GUID,NAME,CODE,THEME_COLOR,DESCRIPTION,CREATE_TIME');
......
......@@ -276,7 +276,7 @@ class ShopBranch extends BaseModel
* @params array $params 查询参数数组
* @return array|null 返回查询结果
*/
public function BranchInfo($params)
public function branchInfo($params)
{
$query = static::find()->alias('sb')
->select("sb.GUID,sb.NAME,sb.CONTACT_NAME,sb.PARENT_GUID,sb.CODE,sb.ADDRESS,sb.PHONE,sb.LAT,
......@@ -349,7 +349,7 @@ class ShopBranch extends BaseModel
* @params array $params 查询参数数组
* @return array|null 返回查询结果
*/
public function BranchDetail($GUID)
public function branchDetail($GUID)
{
$query = static::find()
->select('GUID,NAME,CODE,LICENCE_IMAGE_PATH,RECIVER_PROVINCE,RECIVER_CITY,RECIVER_REGION,ADDRESS,PARENT_GUID,
......@@ -363,7 +363,7 @@ class ShopBranch extends BaseModel
]);
}
//获取门店(权限下的)
public function GetBranch($GUID, $SUPPROVINCE_GUID)
public function getBranch($GUID, $SUPPROVINCE_GUID)
{
$query = static::find()
->select('GUID,SUPPROVINCE_GUID')
......
......@@ -53,13 +53,13 @@ class ShopBranchService extends BaseModel
];
}
//删除门店原有服务类目
public function BranchServiceDel($b_guid)
public function branchServiceDel($b_guid)
{
$branchService = static::deleteAll(['BRANCH_GUID' => $b_guid]);
return $branchService;
}
//获取门店服务类目关系
public function BranchSeviceRelation($b_guid)
public function branchSeviceRelation($b_guid)
{
$branchService = static::find()
->select('GUID,BRANCH_GUID,SERVICE_TYPE_GUID')
......
......@@ -77,7 +77,7 @@ class UserComplain extends BaseModel
];
}
//用户留言信息
public function UserComplainInfo($phone)
public function userComplainInfo($phone)
{
$query = static::find()
->from('shop_user_complain suc')
......@@ -90,7 +90,7 @@ class UserComplain extends BaseModel
[
'query' => $query->asArray(),
'pagination' => [
'pageSize' => 15,
'pageSize' => PAGE_SIZE,
]
]
);
......
......@@ -57,11 +57,9 @@ class UserDepartment extends BaseModel
];
}
//用户-部门信息
public function DepartmentInfo($code, $name)
public function departmentInfo($code, $name)
{
//$org_guid = 2;
$query = static::find()->select('GUID,NAME,CODE,COMPANY,SUB_COMPANY,UPDATE_TIME');
//->where(['ORG_GUID' => $org_guid]);
if (isset($name) && !empty($name)) {
$query->andWhere(['like', 'NAME', $name]);
......@@ -74,7 +72,7 @@ class UserDepartment extends BaseModel
[
'query' => $query->asArray(),
'pagination' => [
'pageSize' => 15,
'pageSize' => PAGE_SIZE,
]
]
);
......
......@@ -72,7 +72,7 @@ class ShopTransportType extends BaseModel
];
}
//门店-配送方式信息
public function BranchTransportInfo($name = '')
public function branchTransportInfo($name = '')
{
return $query = static::find()
->select('GUID,NAME')
......
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