Bladeren bron

城市管理对应模块

duqinya 6 jaren geleden
bovenliggende
commit
fe7c6f1b00

+ 95 - 0
app/Http/Controllers/ConfigCityManagementController.php

@@ -0,0 +1,95 @@
+<?php
+namespace App\Http\Controllers;
+use App\Models\ConfigCityManagement;
+use App\Transformers\CityTransformer;
+use Illuminate\Http\Request;
+
+/**
+ * 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)
+    {
+
+    }
+
+
+
+
+
+
+
+
+}

+ 39 - 0
app/Models/ConfigCityManagement.php

@@ -0,0 +1,39 @@
+<?php
+
+namespace App\Models;
+
+
+class ConfigCityManagement extends BaseModel
+{
+    protected  $table = 'config_city_management';
+
+    /**
+     * 可被批量赋值的字段
+     * @var array
+     */
+    protected $fillable = ['province_id','city_id','province_name','city_name','express_type'];
+
+
+    /**
+     *
+     * 快递方式:0.快递;1. 自提
+     *
+     * @return string
+     */
+    public function getExpressTypeAttribute()
+    {
+        $express_type = '';
+        switch ($this->express_type) {
+            case 0:
+                $express_type = '快递';
+                break;
+            case 1:
+                $express_type = '自提';
+                break;
+            default:
+        }
+
+        return $express_type;
+    }
+
+}

+ 23 - 0
app/Transformers/CityTransformer.php

@@ -0,0 +1,23 @@
+<?php
+
+namespace App\Transformers;
+
+use App\Models\ConfigCityManagement;
+use League\Fractal\TransformerAbstract;
+
+class CityTransformer extends TransformerAbstract
+{
+
+    public function transform(ConfigCityManagement $city)
+    {
+        return [
+            'id'  => $city['id'],
+            'province_id'  => $city['province_id'],
+            'province_name'    => $city['province_name'],
+            'city_name'    => $city['city_name'],
+            'city_id'    => $city['city_id'],
+            'express_type'    => $city['express_type'],
+            'status'    => $city['status'],
+        ];
+    }
+}