123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- <?php
- namespace App\Http\Controllers;
- use App\Models\ConfigCityManagement;
- use App\Transformers\CityTransformer;
- use Illuminate\Http\Request;
- use App\Http\ApiHelper;
- use Illuminate\Support\Facades\Validator;
- /**
- * Created by PhpStorm.
- * User: qinyaer
- * Date: 2019/4/23
- * Time: 下午3:56
- */
- class ConfigCityManagementController extends Controller
- {
- /**
- * @api {get} /city/lists 城市管理列表
- * @apiVersion 0.1
- * @apiName ConfigCityManagement lists
- * @apiGroup ConfigCityManagement
- * @apiPermission none
- * @apiSuccessExample 成功响应:
- {
- "data": [],
- "extra": {
- "filters": [
- "筛选字段1",
- "筛选字段2"
- ],
- "columns": [
- "列表显示数据字段1",
- "列表显示数据字段2"
- ]
- },
- "meta": {
- "pagination": {}
- }
- }
- */
- public function lists()
- {
- $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[$k]->status = '启用';
- }else{
- $cityList[$k]->status = '禁用';
- }
- }
- }
- 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": {}
- }
- }
- */
- public function edit(Request $request)
- {
- $data = $request->all();
- $data['id'] = $request->input('id');
- $cityManagement = ConfigCityManagement::where('id',$data['id'])->first();
- if (!$cityManagement) {
- 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()) {
- 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->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"
- }
- }
- */
- 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));
- }
- return $this->response->array(ApiHelper::success('Success.', 200, array('id' => $id)));
- }
- }
|