Created
September 26, 2019 14:26
-
-
Save er361/a280cd7b6b8f75abe0bdc819167d1049 to your computer and use it in GitHub Desktop.
Бэк-енд приложения попутка
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ClientController extends Controller | |
{ | |
public function getClients(Request $request, $type) | |
{ | |
$ids = json_decode($request->post('ids')); | |
$delete = ClientModel::where(['status' => false, 'direction' => $type]) | |
->whereIn('id', $ids) | |
->pluck('id')->toArray(); | |
$new = ClientModel::where(['status' => true, 'direction' => $type]) | |
->whereNotIn('id', $ids) | |
->get(); | |
if (count($delete) || count($new)) | |
return ['status' => true, 'delete' => $delete, 'new' => $new]; | |
else | |
return ['status' => false]; | |
} | |
public function changeType($type) | |
{ | |
$models = ClientModel::where(['status' => true, 'direction' => $type]) | |
->get(); | |
if ($models->count() > 0) | |
return ['status' => true, 'clients' => $models]; | |
return ['status' => false]; | |
} | |
public function getDrivers() | |
{ | |
$driverIds = DriverModel::where(['status' => true]) | |
->pluck('id') | |
->toArray(); | |
if (count($driverIds)) | |
return ['status' => true, 'driver_ids' => $driverIds]; | |
} | |
public function addCounter(Request $request,$call, $wtsapp) | |
{ | |
$type = $request->post("type"); | |
$init_id = $request->post("client_phone"); | |
$target_id = $request->post("target_id"); | |
$counterModel = new CounterModel(); | |
$counterModel->type = $type; | |
$counterModel->driver_phone = $init_id; | |
$counterModel->target_id = $target_id; | |
if ($call == 1) | |
$counterModel->call += 1; | |
if ($wtsapp == 1) | |
$counterModel->wtsapp += 1; | |
$counterModel->save(); | |
} | |
public function saveDest(Request $request) | |
{ | |
$modelJson = $request->post("model"); | |
$model = json_decode($modelJson, true); | |
$clientModel = new ClientModel(); | |
$clientModel->fill($model); | |
$clientModel->dest = json_encode($model['dest']); | |
try { | |
$clientModel->saveOrFail(); | |
} catch (\Throwable $e) { | |
return ['status' => false, 'message' => $e->getMessage()]; | |
} | |
$modelDb = ClientModel::whereId($clientModel->id)->first(); | |
return ['status' => true, 'model' => $modelDb]; | |
} | |
public function hasPoint($id) | |
{ | |
try { | |
ClientModel::where(['status' => true])->findOrFail($id); | |
return ['status' => true]; | |
} catch (ModelNotFoundException $exception) { | |
return ['status' => false, 'message' => $exception->getMessage()]; | |
} | |
} | |
public function cancel($id) | |
{ | |
try{ | |
$model = ClientModel::whereId($id)->firstOrFail(); | |
$model->status = false; | |
$model->save(); | |
return ['status' => true]; | |
}catch (ModelNotFoundException $exception){ | |
return ['status' => false, 'message' => $exception->getMessage()]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment