public function show($id) { if (config('global.users.current.id') || config('global.managers.current.id')) { $cacheTag = ['checkouts']; $cacheKey = $id; $response = Cache::tags($cacheTag)->remember($cacheKey, 60 * 24 * 7, function () use($id) { $_model = Checkouts::select(['checkouts.id', 'code', 'total', 'payment_method', 'payment_change', 'address_address', 'address_number', 'address_neighborhood', 'address_city', 'address_state', 'address_code', 'checkouts.created_at', 'checkouts.updated_at', 'process_id', 'processes.description as process', 'processes.color as process_color'])->join('processes', 'checkouts.process_id', '=', 'processes.id')->where('checkouts.company_id', config('global.companies.current.id'))->where('checkouts.id', $id); if (!config('global.managers.current.id')) { $_model->where('user_id', config('global.users.current.id')); } if ($_model->count() > 0) { $data = $_model->first()->toArray(); $_checkout = Checkouts::find($id); $data['products'] = $_checkout->products()->get()->toArray(); $data['customer'] = $_checkout->user()->first(['id', 'name', 'lastname', 'avatar', 'confirmed'])->toArray(); return $this->dataApiToJson($data); } else { return false; } }); if (!$response) { Cache::tags($cacheTag)->forget($cacheKey); return new \Exception("Houve um erro ao localizar registro (id not found)"); } return $response; } else { return new \Exception('Token inválido! tente fazer login novamente.'); } }
public function checkouts() { $count = Checkouts::select(\DB::raw('count(id) as total'))->where('created_at', '>', Carbon::now()->subDays(30))->where('company_id', config('global.companies.current.id'))->count(); return $this->jsonResponse(['data' => $count]); }