|
@@ -1,11 +1,14 @@
|
|
<?php
|
|
<?php
|
|
namespace App\Http\Controllers;
|
|
namespace App\Http\Controllers;
|
|
use App\Models\ConfigCityManagement;
|
|
use App\Models\ConfigCityManagement;
|
|
|
|
+use App\Repositories\ConfigCityManagementRepository;
|
|
use App\Transformers\CityTransformer;
|
|
use App\Transformers\CityTransformer;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Request;
|
|
use App\Http\ApiHelper;
|
|
use App\Http\ApiHelper;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Illuminate\Support\Facades\Validator;
|
|
-
|
|
|
|
|
|
+use League\Fractal\Pagination\IlluminatePaginatorAdapter;
|
|
|
|
+use League\Fractal\Resource\Collection;
|
|
|
|
+use League\Fractal\Manager;
|
|
/**
|
|
/**
|
|
* Created by PhpStorm.
|
|
* Created by PhpStorm.
|
|
* User: qinyaer
|
|
* User: qinyaer
|
|
@@ -15,134 +18,87 @@ use Illuminate\Support\Facades\Validator;
|
|
|
|
|
|
class ConfigCityManagementController extends Controller
|
|
class ConfigCityManagementController extends Controller
|
|
{
|
|
{
|
|
- /**
|
|
|
|
- * @api {get} /city/lists 城市管理列表
|
|
|
|
- * @apiVersion 0.1
|
|
|
|
- * @apiName ConfigCityManagement lists
|
|
|
|
- * @apiGroup ConfigCityManagement
|
|
|
|
- * @apiPermission none
|
|
|
|
- * @apiSuccessExample 成功响应:
|
|
|
|
|
|
+ public function __construct(ConfigCityManagementRepository $configCityManagementRepository)
|
|
{
|
|
{
|
|
- "data": [],
|
|
|
|
- "extra": {
|
|
|
|
- "filters": [
|
|
|
|
- "筛选字段1",
|
|
|
|
- "筛选字段2"
|
|
|
|
- ],
|
|
|
|
- "columns": [
|
|
|
|
- "列表显示数据字段1",
|
|
|
|
- "列表显示数据字段2"
|
|
|
|
- ]
|
|
|
|
- },
|
|
|
|
- "meta": {
|
|
|
|
- "pagination": {}
|
|
|
|
- }
|
|
|
|
|
|
+ $this->configCityManagementRepository = $configCityManagementRepository;
|
|
}
|
|
}
|
|
- */
|
|
|
|
|
|
|
|
- public function lists()
|
|
|
|
|
|
+ //城市列表
|
|
|
|
+ public function lists(Request $request)
|
|
{
|
|
{
|
|
- $cityList = ConfigCityManagement::orderBy('id', 'desc')
|
|
|
|
- ->paginate();
|
|
|
|
- if (count($cityList)>0){
|
|
|
|
- foreach ($cityList as $k=>$v){
|
|
|
|
- $cityList[$k]->express_type = $v->getExpressTypeAttribute();
|
|
|
|
- if ($v->status == 0){
|
|
|
|
|
|
+
|
|
|
|
+ $cityList = $this->configCityManagementRepository->index($request->all());
|
|
|
|
+
|
|
|
|
+ if (count($cityList) > 0) {
|
|
|
|
+ foreach ($cityList as $k => $v) {
|
|
|
|
+ if ($v->status == 0) {
|
|
$cityList[$k]->status = '启用';
|
|
$cityList[$k]->status = '启用';
|
|
- }else{
|
|
|
|
|
|
+ } else {
|
|
$cityList[$k]->status = '禁用';
|
|
$cityList[$k]->status = '禁用';
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if ($v->express_type == "0"){
|
|
|
|
+ $cityList[$k]->express_type = '快递';
|
|
|
|
+ }elseif ($v->express_type == "1"){
|
|
|
|
+ $cityList[$k]->express_type = '自提';
|
|
|
|
+ }elseif ($v->express_type === "0,1" || $v->express_type === "1,0"){
|
|
|
|
+ $cityList[$k]->express_type = '快递,自提';
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- return $this->response->paginator($cityList, new CityTransformer());
|
|
|
|
- }
|
|
|
|
|
|
|
|
- /**
|
|
|
|
- * @api {post} /city/edit 编辑城市
|
|
|
|
- * @apiVersion 0.1
|
|
|
|
- * @apiName ConfigCityManagement edit
|
|
|
|
- * @apiGroup ConfigCityManagement
|
|
|
|
- * @apiPermission none
|
|
|
|
- * @apiSuccessExample 成功响应:
|
|
|
|
- {
|
|
|
|
- "data": [],
|
|
|
|
- "extra": {
|
|
|
|
- "filters": [
|
|
|
|
- "筛选字段1",
|
|
|
|
- "筛选字段2"
|
|
|
|
- ],
|
|
|
|
- "columns": [
|
|
|
|
- "列表显示数据字段1",
|
|
|
|
- "列表显示数据字段2"
|
|
|
|
- ]
|
|
|
|
- },
|
|
|
|
- "meta": {
|
|
|
|
- "pagination": {}
|
|
|
|
- }
|
|
|
|
|
|
+ $fractal = new Manager();
|
|
|
|
+ $resource = new Collection($cityList, new CityTransformer());
|
|
|
|
+ $resource->setPaginator(new IlluminatePaginatorAdapter($cityList));
|
|
|
|
+ $data = $fractal->createData($resource)->toArray();
|
|
|
|
+ $data['extra'] = [
|
|
|
|
+ 'filters' => [
|
|
|
|
+ 'id'
|
|
|
|
+ ],
|
|
|
|
+ 'columns' => [
|
|
|
|
+ 'id',
|
|
|
|
+ 'province_id',
|
|
|
|
+ 'province_name',
|
|
|
|
+ 'city_name',
|
|
|
|
+ 'city_id',
|
|
|
|
+ 'express_type',
|
|
|
|
+ 'status',
|
|
|
|
+ ]
|
|
|
|
+ ];
|
|
|
|
+ return $data;
|
|
}
|
|
}
|
|
- */
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
+ //编辑城市
|
|
public function edit(Request $request)
|
|
public function edit(Request $request)
|
|
{
|
|
{
|
|
- $data = $request->all();
|
|
|
|
- $data['id'] = $request->input('id');
|
|
|
|
- $cityManagement = ConfigCityManagement::where('id',$data['id'])->first();
|
|
|
|
- if (!$cityManagement) {
|
|
|
|
|
|
+ $validator = Validator::make($request->all(), [
|
|
|
|
+ 'id' => 'required|exists:config_city_management',
|
|
|
|
+ 'province_name' => 'required|string|max:20',
|
|
|
|
+ 'province_id' => 'required|integer',
|
|
|
|
+ 'city_id' => 'required|integer',
|
|
|
|
+ 'city_name' => 'required|string|max:30',
|
|
|
|
+ ]);
|
|
|
|
|
|
- return $this->response->array(ApiHelper::error('该城市不存在!', 402));
|
|
|
|
- }
|
|
|
|
- $rules = [
|
|
|
|
- 'province_name' => 'required',
|
|
|
|
- 'province_id' => 'required',
|
|
|
|
- 'city_id' => 'required',
|
|
|
|
- 'city_name' => 'required',
|
|
|
|
- ];
|
|
|
|
- $validator = Validator::make($data, $rules);
|
|
|
|
if ($validator->fails()) {
|
|
if ($validator->fails()) {
|
|
|
|
|
|
- return $this->response->array(ApiHelper::error('请求参数格式不正确!', 412));
|
|
|
|
- }
|
|
|
|
- $city_management_update = $cityManagement->update($data);
|
|
|
|
- if (!$city_management_update){
|
|
|
|
-
|
|
|
|
- return $this->response->array(ApiHelper::error('修改失败,请重试!', 412));
|
|
|
|
|
|
+ return $this->response->error($validator->errors()->first(), 500);
|
|
}
|
|
}
|
|
|
|
|
|
- return $this->response->array(ApiHelper::success());
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * @api {post} /city/delete 删除城市
|
|
|
|
- * @apiVersion 0.1
|
|
|
|
- * @apiName ConfigCityManagement delete
|
|
|
|
- * @apiGroup ConfigCityManagement
|
|
|
|
- * @apiPermission none
|
|
|
|
- * @apiSuccessExample 成功响应:
|
|
|
|
-
|
|
|
|
- {
|
|
|
|
- "meta": {
|
|
|
|
- "message": "Success.",
|
|
|
|
- "status_code": 200
|
|
|
|
- },
|
|
|
|
- "data": {
|
|
|
|
- "id": "2"
|
|
|
|
- }
|
|
|
|
|
|
+ return $this->configCityManagementRepository->edit($request->all());
|
|
}
|
|
}
|
|
- */
|
|
|
|
|
|
|
|
|
|
+ //删除城市
|
|
public function delete(Request $request)
|
|
public function delete(Request $request)
|
|
{
|
|
{
|
|
- $id = $request->input('id');
|
|
|
|
- $cityManagement = ConfigCityManagement::find($id);
|
|
|
|
- if (!$cityManagement) {
|
|
|
|
- return $this->response->array(ApiHelper::error('该城市不存在!', 402));
|
|
|
|
- }
|
|
|
|
- $city_delete = $cityManagement->delete();
|
|
|
|
- if (!$city_delete) {
|
|
|
|
- return $this->response->array(ApiHelper::error('删除城市失败!', 500));
|
|
|
|
|
|
+ $validator = Validator::make($request->all(), [
|
|
|
|
+ 'id' => 'required|exists:config_city_management'
|
|
|
|
+ ]);
|
|
|
|
+ if ($validator->fails()) {
|
|
|
|
+ return $this->response->error($validator->errors()->first(), 500);
|
|
}
|
|
}
|
|
- return $this->response->array(ApiHelper::success('Success.', 200, array('id' => $id)));
|
|
|
|
|
|
+ return $this->configCityManagementRepository->delete($request->all());
|
|
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|