/
proc
/
thread-self
/
root
/
home
/
henzagold
/
server
/
app
/
Http
/
Controllers
/
Api
/
File Upload :
llllll
Current File: //proc/thread-self/root/home/henzagold/server/app/Http/Controllers/Api/CustomOrderController.php
<?php namespace App\Http\Controllers\Api; use App\DB\Te\TableEngine; use App\Http\Controllers\Controller; use App\Models\Major\Cash; use App\Models\Category; use App\Models\ConfigStatic; use App\Models\CustomOrder; use App\Models\CustomOrderLog; use App\Models\Customer; use http\Client\Curl\User; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Support\Arr; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Log; use Morilog\Jalali\Jalalian; use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException; class CustomOrderController extends Controller { // Get all custom orders public function getCustomOrders(Request $request): JsonResponse { $orders = CustomOrder::with(['customer','CustomOrderLog','file'])->where('customer_id',auth()->id()); TableEngine::create($orders, $request->all()) ->initSearch([]) ->select([ '*' ])->export($orders); return response()->json($orders); } public function getCustomOrdersAdmin(Request $request): JsonResponse { $orders = CustomOrder::with(['customer','CustomOrderLog','file']); TableEngine::create($orders, $request->all()) ->initSearch([]) ->select([ '*' ])->export($orders); return response()->json($orders); } // Get single custom order public function getCustomOrder($id): JsonResponse { $order = CustomOrder::with(['customer','CustomOrderLog','file'])->find($id); if (!$order) { return response()->json(['message' => 'Order not found'], 404); } return response()->json($order); } public function editCustomOrder(Request $request, $id): JsonResponse { $validatedData = $request->validate([ 'file_id' => 'nullable|integer', 'city_id' => 'nullable|integer', 'weight' => 'nullable|numeric', 'color' => 'nullable|string', 'size' => 'string', 'sum' => 'nullable|numeric', 'color_stone' => 'nullable|string', 'color_mina' => 'nullable|string', 'workshop_id' => 'nullable|integer', 'sts' => 'nullable', ]); $order = CustomOrder::find($id); if (!$order) { return response()->json(['message' => 'Order not found'], 404); } if (!$order->workshop_id && $request->has('workshop_id')) { $order->sts = 2; $order->save(); } $originalValues = $order->getOriginal(); $order->fill($validatedData); $order->save(); $changes = $order->getChanges(); if (!empty($changes)) { CustomOrderLog::create([ 'custom_order_id' => $order->id, 'changes' => ([ 'old' => array_intersect_key($originalValues, $changes), 'new' => $changes ]), 'ip_address' => $request->ip(), 'description' => $request->description, ]); } return response()->json($order); } public function creatCustomOrder(Request $request): JsonResponse { $validatedData = $request->validate([ 'file_id' => 'nullable|integer', 'city_id' => 'nullable|integer', 'weight' => 'nullable|numeric', 'color' => 'required|string', 'size' => 'string', 'sum' => 'required|numeric', 'color_stone' => 'nullable|string', 'color_mina' => 'nullable|string', ]); $validatedData['sts'] = 1; $validatedData['customer_id'] = auth()->id(); $order = CustomOrder::create($validatedData); return response()->json([ 'message' => 'Order created successfully', 'data' => $order ], 201); } // Update existing custom order public function updateCustomOrder(Request $request, $id): JsonResponse { $order = CustomOrder::find($id); if (!$order) { return response()->json(['message' => 'Order not found'], 404); } $validatedData = $request->validate([ 'customer_id' => 'sometimes|integer', 'file_id' => 'sometimes|integer', 'city_id' => 'sometimes|integer', 'weight' => 'sometimes|numeric', 'color' => 'sometimes|string', 'size' => 'sometimes|string', 'sum' => 'sometimes|numeric', 'color_stone' => 'sometimes|string', 'color_mina' => 'sometimes|string', 'sts' => 'sometimes|integer' ]); $order->update($validatedData); return response()->json([ 'message' => 'Order updated successfully', 'data' => $order ]); } // Delete custom order public function deleteCustomOrder($id): JsonResponse { $order = CustomOrder::find($id); if (!$order) { return response()->json(['message' => 'Order not found'], 404); } $order->delete(); return response()->json(['message' => 'Order deleted successfully']); } }
Copyright ©2k19 -
Hexid
|
Tex7ure