|
@@ -0,0 +1,210 @@
|
|
|
+<?php
|
|
|
+namespace App\Http\Controllers;
|
|
|
+use App\Repositories\ConfigPickupNodeRepository;
|
|
|
+use Illuminate\Http\Request;
|
|
|
+use App\Transformers\PickupNodeTransformer;
|
|
|
+use Illuminate\Support\Facades\Validator;
|
|
|
+use League\Fractal\Resource\Collection;
|
|
|
+use League\Fractal\Manager;
|
|
|
+use Illuminate\Validation\Rule;
|
|
|
+use League\Fractal\Pagination\IlluminatePaginatorAdapter;
|
|
|
+/**
|
|
|
+ * Created by PhpStorm.
|
|
|
+ * User: qinyaer
|
|
|
+ * Date: 2019/4/24
|
|
|
+ * Time: 上午10:51
|
|
|
+ */
|
|
|
+
|
|
|
+class ConfigPickupNodeController extends BaseController
|
|
|
+{
|
|
|
+ public function __construct(ConfigPickupNodeRepository $configPickupNodeRepository)
|
|
|
+ {
|
|
|
+ $this->configPickupNodeRepository = $configPickupNodeRepository;
|
|
|
+ }
|
|
|
+
|
|
|
+ //自提点列表
|
|
|
+ public function index(Request $request)
|
|
|
+ {
|
|
|
+ $ConfigPickupNode = $this->configPickupNodeRepository->index($request->all());
|
|
|
+
|
|
|
+ if (count($ConfigPickupNode)>0) {
|
|
|
+
|
|
|
+ foreach ($ConfigPickupNode as $k => $v) {
|
|
|
+
|
|
|
+ $ConfigPickupNode[$k]->pickup_group_name = $v->getGroupNameAttribute();//自提点分组名称
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $fractal = new Manager();
|
|
|
+ $resource = new Collection($ConfigPickupNode, new PickupNodeTransformer());
|
|
|
+ $resource->setPaginator(new IlluminatePaginatorAdapter($ConfigPickupNode));
|
|
|
+ $data = $fractal->createData($resource)->toArray();
|
|
|
+ $data['extra'] = [
|
|
|
+ 'filters' => [
|
|
|
+ 'id',
|
|
|
+ 'name',
|
|
|
+ 'city_id',
|
|
|
+ 'status'
|
|
|
+ ],
|
|
|
+ 'columns' => [
|
|
|
+ 'id',
|
|
|
+ 'city_id',
|
|
|
+ 'city_name',
|
|
|
+ 'name',
|
|
|
+ 'address',
|
|
|
+ 'work_time',
|
|
|
+ 'manager_name',
|
|
|
+ 'manager_mobile',
|
|
|
+ 'receive_type',
|
|
|
+ 'longitude',
|
|
|
+ 'latitude',
|
|
|
+ 'store_ids',
|
|
|
+ 'pickup_group_id',
|
|
|
+ 'pickup_group_name',
|
|
|
+ 'status',
|
|
|
+ 'created_at',
|
|
|
+ 'pickup_code',
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //新建自提点
|
|
|
+ public function create(Request $request)
|
|
|
+ {
|
|
|
+ $validator = Validator::make($request->all(), [
|
|
|
+ 'name' => 'required',
|
|
|
+// '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}$/'],
|
|
|
+ 'manager_mobile' => 'required',
|
|
|
+ 'address' => 'required',
|
|
|
+ 'pickup_group_id' => 'required',
|
|
|
+ 'city_id' => 'required',
|
|
|
+ 'city_name' => 'required|string',
|
|
|
+ 'longitude' => 'required',
|
|
|
+ 'latitude' => 'required',
|
|
|
+ 'pickup_code' => 'required',
|
|
|
+ 'work_time' => 'required',
|
|
|
+ 'store_ids' => 'required',
|
|
|
+ 'receive_type' => ['required', Rule::in(0,1)],
|
|
|
+ ]);
|
|
|
+ if ($validator->fails()) {
|
|
|
+ return $this->response->error($validator->errors()->first(), 500);
|
|
|
+ }
|
|
|
+ return $this->configPickupNodeRepository->create($request->all());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //编辑自提点
|
|
|
+ public function edit(Request $request)
|
|
|
+ {
|
|
|
+ $validator = Validator::make($request->all(), [
|
|
|
+ 'id' => 'required|exists:config_pickup_node',
|
|
|
+ 'name' => 'required|string',
|
|
|
+ 'manager_mobile' => 'required',
|
|
|
+ 'address' => 'required|string|max:200',
|
|
|
+ 'pickup_group_id' => 'required|integer',
|
|
|
+ 'city_id' => 'required',
|
|
|
+ 'city_name' => 'required|string',
|
|
|
+ 'longitude' => 'required',
|
|
|
+ 'latitude' => 'required',
|
|
|
+ 'pickup_code' => 'required',
|
|
|
+ 'work_time' => 'required',
|
|
|
+ 'store_ids' => 'required',
|
|
|
+ 'receive_type' => ['required', Rule::in(0,1)],
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if ($validator->fails()) {
|
|
|
+ return $this->response->error($validator->errors()->first(), 500);
|
|
|
+ }
|
|
|
+ return $this->configPickupNodeRepository->edit($request->all());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //查看某自提点
|
|
|
+ public function view(Request $request)
|
|
|
+ {
|
|
|
+ $all = $request->all();
|
|
|
+ $validator = Validator::make($all, [
|
|
|
+ 'id' => 'required|integer',
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if($validator->fails()) {
|
|
|
+
|
|
|
+ return $this->response->error($validator->errors()->first(), 500);
|
|
|
+ }
|
|
|
+ $getPickup = $this->configPickupNodeRepository->index($request->all());
|
|
|
+
|
|
|
+ if (count($getPickup)>0) {
|
|
|
+ foreach ($getPickup as $k => $v) {
|
|
|
+
|
|
|
+ $getPickup[$k]->receive_type = $v->receive_type == 0 ? '信任交付' : '手动确认接货';
|
|
|
+
|
|
|
+ $getPickup[$k]->status = $v->status == 0 ? '禁用' : '启用';
|
|
|
+
|
|
|
+ $getPickup[$k]->store_ids = $v->getStoreNameAttribute();//储存方式名称
|
|
|
+ $getPickup[$k]->pickup_group_id = $v->getGroupNameAttribute();//自提点分组名称
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!$getPickup){
|
|
|
+
|
|
|
+ return $this->response->error($validator->errors()->first(), 500);
|
|
|
+ }
|
|
|
+
|
|
|
+ $fractal = new Manager();
|
|
|
+ $resource = new Collection($getPickup, new PickupNodeTransformer());
|
|
|
+ $resource->setPaginator(new IlluminatePaginatorAdapter($getPickup));
|
|
|
+ $data = $fractal->createData($resource)->toArray();
|
|
|
+ $data['extra'] = [
|
|
|
+ 'filters' => [
|
|
|
+ 'id'
|
|
|
+ ],
|
|
|
+ 'columns' => [
|
|
|
+ 'id',
|
|
|
+ 'city_id',
|
|
|
+ 'city_name',
|
|
|
+ 'name',
|
|
|
+ 'address',
|
|
|
+ 'work_time',
|
|
|
+ 'manager_name',
|
|
|
+ 'manager_mobile',
|
|
|
+ 'receive_type',
|
|
|
+ 'longitude',
|
|
|
+ 'latitude',
|
|
|
+ 'store_ids',
|
|
|
+ 'pickup_group_id',
|
|
|
+ 'status',
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+ return $data;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //接货
|
|
|
+ public function pickupGoods(Request $request)
|
|
|
+ {
|
|
|
+ $validator = Validator::make($request->all(), [
|
|
|
+ 'id' => 'required|exists:config_pickup_node'
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if($validator->fails()) {
|
|
|
+ return $this->response->error($validator->errors()->first(), 500);
|
|
|
+ }
|
|
|
+ return $this->configPickupNodeRepository->pickupGoods($request->all());
|
|
|
+ }
|
|
|
+
|
|
|
+ //给货
|
|
|
+ public function deliver_goods(Request $request)
|
|
|
+ {
|
|
|
+ $validator = Validator::make($request->all(), [
|
|
|
+ 'id' => 'required|exists:config_pickup_node'
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if($validator->fails()) {
|
|
|
+ return $this->response->error($validator->errors()->first(), 500);
|
|
|
+ }
|
|
|
+ return $this->configPickupNodeRepository->deliver_goods($request->all());
|
|
|
+
|
|
|
+ }
|
|
|
+}
|