|
@@ -0,0 +1,284 @@
|
|
|
+<?php
|
|
|
+namespace App\Http\Controllers;
|
|
|
+use App\Http\ApiHelper;
|
|
|
+use Illuminate\Http\Request;
|
|
|
+use App\Models\ConfigPickupNode;
|
|
|
+use App\Transformers\PickupNodeTransformer;
|
|
|
+use Illuminate\Support\Facades\Validator;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by PhpStorm.
|
|
|
+ * User: qinyaer
|
|
|
+ * Date: 2019/4/24
|
|
|
+ * Time: 上午10:51
|
|
|
+ */
|
|
|
+
|
|
|
+class ConfigPickupNodeController extends BaseController
|
|
|
+{
|
|
|
+ /**
|
|
|
+ * @api {get} /pickupNode/index 自提点列表
|
|
|
+ * @apiVersion 0.1
|
|
|
+ * @apiName ConfigPickupNode index
|
|
|
+ * @apiGroup ConfigPickupNode
|
|
|
+ * @apiPermission none
|
|
|
+ * @apiSuccessExample 成功响应:
|
|
|
+
|
|
|
+ {
|
|
|
+ "data": [],
|
|
|
+ "extra": {
|
|
|
+ "filters": [
|
|
|
+ "筛选字段1",
|
|
|
+ "筛选字段2"
|
|
|
+ ],
|
|
|
+ "columns": [
|
|
|
+ "id",
|
|
|
+ "name"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ "meta": {
|
|
|
+ "pagination": {
|
|
|
+ "total": 2,
|
|
|
+ "count": 2,
|
|
|
+ "per_page": 15,
|
|
|
+ "current_page": 1,
|
|
|
+ "total_pages": 1,
|
|
|
+ "links": []
|
|
|
+ }
|
|
|
+ }
|
|
|
+ */
|
|
|
+ public function index()
|
|
|
+ {
|
|
|
+ $ConfigPickupNode = ConfigPickupNode::orderBy('id', 'desc')
|
|
|
+ ->paginate();
|
|
|
+
|
|
|
+ if (count($ConfigPickupNode)>0) {
|
|
|
+
|
|
|
+ foreach ($ConfigPickupNode as $k => $v) {
|
|
|
+ $ConfigPickupNode[$k]->receive_type = $v->receive_type == 0 ? '信任交付' : '手动确认接货';
|
|
|
+
|
|
|
+ $ConfigPickupNode[$k]->status = $v->status == 0 ? '启用' : '禁用';
|
|
|
+
|
|
|
+ $ConfigPickupNode[$k]->store_ids = $v->getStoreNameAttribute();//储存方式名称
|
|
|
+ $ConfigPickupNode[$k]->pickup_group_id = $v->getGroupNameAttribute();//自提点分组名称
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this->response->paginator($ConfigPickupNode, new PickupNodeTransformer());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @api {get} /pickupNode/add 新建自提点
|
|
|
+ * @apiVersion 0.1
|
|
|
+ * @apiName ConfigPickupNode add
|
|
|
+ * @apiGroup ConfigPickupNode
|
|
|
+ * @apiPermission none
|
|
|
+ * @apiSuccessExample 成功响应:
|
|
|
+
|
|
|
+ {
|
|
|
+ "meta": {
|
|
|
+ "message": "Success.",
|
|
|
+ "status_code": 200
|
|
|
+ }
|
|
|
+ }
|
|
|
+ */
|
|
|
+
|
|
|
+ public function add(Request $request)
|
|
|
+ {
|
|
|
+ $name = $request->input('name') ? $request->input('name') : '';
|
|
|
+ $pickup_group_id = $request->input('pickup_group_id') ? $request->input('pickup_group_id') : 0;
|
|
|
+ $city_id = $request->input('city_id') ? $request->input('city_id') : 0;
|
|
|
+ $city_name = $request->input('city_name') ? $request->input('city_name') : '';
|
|
|
+ $address = $request->input('address') ? $request->input('address') : '';
|
|
|
+ $longitude = $request->input('longitude') ? $request->input('longitude') : '';
|
|
|
+ $latitude = $request->input('latitude') ? $request->input('latitude') : '';
|
|
|
+ $pickup_code = $request->input('pickup_code') ? $request->input('pickup_code') : '';
|
|
|
+ $work_time = $request->input('work_time') ? $request->input('work_time') : '';
|
|
|
+ $manager_name = $request->input('manager_name') ? $request->input('manager_name') : '';
|
|
|
+ $manager_mobile = $request->input('manager_mobile') ? $request->input('manager_mobile') : '';
|
|
|
+ $store_ids = $request->input('store_ids') ? $request->input('store_ids') : 0;
|
|
|
+ $receive_type = $request->input('receive_type') ? $request->input('receive_type') : '';
|
|
|
+
|
|
|
+ $data = array(
|
|
|
+ 'name' => $name,
|
|
|
+ 'pickup_group_id' => $pickup_group_id,
|
|
|
+ 'city_id' => $city_id,
|
|
|
+ 'city_name' => $city_name,
|
|
|
+ 'address' => $address,
|
|
|
+ 'longitude' => $longitude,
|
|
|
+ 'latitude' => $latitude,
|
|
|
+ 'pickup_code' => $pickup_code,
|
|
|
+ 'work_time' => $work_time,
|
|
|
+ 'manager_name' => $manager_name,
|
|
|
+ 'manager_mobile' => $manager_mobile,
|
|
|
+ 'store_ids' => $store_ids,
|
|
|
+ 'receive_type' => $receive_type,
|
|
|
+ );
|
|
|
+
|
|
|
+ $rules = [
|
|
|
+ 'name' => 'required|max:20',
|
|
|
+ 'manager_mobile' => ['required', 'regex:/^1(3[0-9]|4[57]|5[0-35-9]|6[56]|7[0135678]|8[0-9]|9[89])\\d{8}$/'],
|
|
|
+ 'address' => 'required|max:200',
|
|
|
+ 'pickup_group_id' => 'required',
|
|
|
+ 'city_id' => 'required',
|
|
|
+ 'city_name' => 'required',
|
|
|
+ 'longitude' => 'required',
|
|
|
+ 'latitude' => 'required',
|
|
|
+ 'pickup_code' => 'required',
|
|
|
+ 'work_time' => 'required',
|
|
|
+ ];
|
|
|
+
|
|
|
+ $massage = [
|
|
|
+ 'name.required' => '自提点名称不能为空',
|
|
|
+ 'name.max' => '自提点名称不能超过20个字符',
|
|
|
+ 'manager_mobile.required' => '负责人电话不能为空',
|
|
|
+ 'manager_mobile.regex' => '负责人手机号格式不正确',
|
|
|
+ 'address.required' => '自提点详细地址不能为空',
|
|
|
+ 'address.max' => '自提点详细地址不能超过200个字符',
|
|
|
+ 'pickup_group_id.required' => '自提点分组ID不能为空',
|
|
|
+ 'city_id.required' => '城市不能为空',
|
|
|
+ 'city_name.required' => '城市名称不能为空',
|
|
|
+ 'longitude.required' => '经度不能为空',
|
|
|
+ 'latitude.required' => '纬度不能为空',
|
|
|
+ 'pickup_code.required' => '自提点编码不能为空',
|
|
|
+ 'work_time.required' => '自提时间不能为空',
|
|
|
+ ];
|
|
|
+ $validator = Validator::make($data, $rules, $massage);
|
|
|
+
|
|
|
+ if ($validator->fails()) {
|
|
|
+
|
|
|
+ return $this->response->array(ApiHelper::error('请求参数格式不正确!', 412));
|
|
|
+ }
|
|
|
+
|
|
|
+ $pickup_node = ConfigPickupNode::create($data);
|
|
|
+ if(!$pickup_node) {
|
|
|
+
|
|
|
+ return $this->response->array(ApiHelper::error('新建自提点失败!', 500));
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this->response->array(ApiHelper::success());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @api {get} /pickupNode/edit 编辑自提点
|
|
|
+ * @apiVersion 0.1
|
|
|
+ * @apiName ConfigPickupNode edit
|
|
|
+ * @apiGroup ConfigPickupNode
|
|
|
+ * @apiPermission none
|
|
|
+ * @apiSuccessExample 成功响应:
|
|
|
+ {
|
|
|
+ "data": [],
|
|
|
+ "extra": {
|
|
|
+ "filters": [
|
|
|
+ "筛选字段1",
|
|
|
+ "筛选字段2"
|
|
|
+ ],
|
|
|
+ "columns": [
|
|
|
+ "id",
|
|
|
+ "name"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ "meta": {
|
|
|
+ "pagination": {
|
|
|
+ "total": 2,
|
|
|
+ "count": 2,
|
|
|
+ "per_page": 15,
|
|
|
+ "current_page": 1,
|
|
|
+ "total_pages": 1,
|
|
|
+ "links": []
|
|
|
+ }
|
|
|
+ }
|
|
|
+ */
|
|
|
+
|
|
|
+ public function edit(Request $request)
|
|
|
+ {
|
|
|
+ $id = $request->input('id');
|
|
|
+ $pickup_node = ConfigPickupNode::where('id',$id)->first();
|
|
|
+
|
|
|
+ if (!$pickup_node) {
|
|
|
+
|
|
|
+ return $this->response->array(ApiHelper::error('该自提点不存在!', 402));
|
|
|
+ }
|
|
|
+
|
|
|
+ $data = $request->all();
|
|
|
+ $data['id'] = $request->input('id');
|
|
|
+
|
|
|
+ $rules = [
|
|
|
+ 'name' => 'required|max:20',
|
|
|
+ 'manager_mobile' => ['required', 'regex:/^1(3[0-9]|4[57]|5[0-35-9]|6[56]|7[0135678]|8[0-9]|9[89])\\d{8}$/'],
|
|
|
+ 'address' => 'required|max:200',
|
|
|
+ 'pickup_group_id' => 'required',
|
|
|
+ 'city_id' => 'required',
|
|
|
+ 'city_name' => 'required',
|
|
|
+ 'longitude' => 'required',
|
|
|
+ 'latitude' => 'required',
|
|
|
+ 'pickup_code' => 'required',
|
|
|
+ 'work_time' => 'required',
|
|
|
+ ];
|
|
|
+ $validator = Validator::make($data, $rules);
|
|
|
+ if ($validator->fails()) {
|
|
|
+
|
|
|
+ return $this->response->array(ApiHelper::error('请求参数格式不正确!', 412));
|
|
|
+ }
|
|
|
+ $pickup_node_update = $pickup_node->update($data);
|
|
|
+ if (!$pickup_node_update){
|
|
|
+
|
|
|
+ return $this->response->array(ApiHelper::error('修改失败,请重试!', 412));
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this->response->array(ApiHelper::success());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @api {get} /pickupNode/view 查看自提点
|
|
|
+ * @apiVersion 0.1
|
|
|
+ * @apiName ConfigPickupNode view
|
|
|
+ * @apiGroup ConfigPickupNode
|
|
|
+ * @apiPermission none
|
|
|
+ * @apiSuccessExample 成功响应:
|
|
|
+
|
|
|
+ {
|
|
|
+ "data": {
|
|
|
+ "id": 2,
|
|
|
+ "city_id": 1,
|
|
|
+ "city_name": "dd",
|
|
|
+ "name": "ff",
|
|
|
+ "address": "dd",
|
|
|
+ "work_time": "2019-04-24 11:35:00",
|
|
|
+ "manager_name": "4ed",
|
|
|
+ "manager_mobile": "555",
|
|
|
+ "receive_type": "信任交付",
|
|
|
+ "longitude": "2",
|
|
|
+ "latitude": "2",
|
|
|
+ "store_ids": "冷冻",
|
|
|
+ "status": "启用"
|
|
|
+ },
|
|
|
+ "meta": {
|
|
|
+ "message": "Success.",
|
|
|
+ "status_code": 200
|
|
|
+ }
|
|
|
+ }
|
|
|
+ */
|
|
|
+
|
|
|
+ public function view(Request $request)
|
|
|
+ {
|
|
|
+ $id = $request->input('id');
|
|
|
+ $pickup_node = ConfigPickupNode::where('id',$id)->first();
|
|
|
+ if (!$pickup_node) {
|
|
|
+
|
|
|
+ return $this->response->array(ApiHelper::error('没有找到该自提点!', 402));
|
|
|
+ }
|
|
|
+ $pickup_node->receive_type = $pickup_node->receive_type == 0 ? '信任交付':'手动确认接货';
|
|
|
+ $pickup_node->status = $pickup_node->status == 0 ? '启用':'禁用';
|
|
|
+ $pickup_node->store_ids = $pickup_node->getStoreNameAttribute();
|
|
|
+ $pickup_node->pickup_group_id = $pickup_node->getGroupNameAttribute();
|
|
|
+
|
|
|
+ return $this->response->item($pickup_node, new PickupNodeTransformer)->setMeta(ApiHelper::meta());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|