response(['success' => true, 'license' => [ 'key' => alexr_get_setting('license_key'), //'activated' => alexr_get_setting('license_activated'), 'activation' => alexr_get_setting('license_activation'), 'addons' => alexr_get_setting('license_addons', ''), 'addons_tenants' => alexr_get_setting('license_addons_tenants', ''), 'license_code_check' => alexr_get_setting('license_code_check', ''), 'tenants_addons' => $this->getPaidAddonsForRestaurants(), 'tenants_addons_licenses' => $this->getPaidAddonsLicensesForRestaurants() ]]); } public function getPaidAddonsForRestaurants(){ $restaurants = Restaurant::get(); $addons = []; foreach ($restaurants as $restaurant) { $addons['tenant-' . $restaurant->id] = $restaurant->getPaidAddons(); } return $addons; } public function getPaidAddonsLicensesForRestaurants(){ $restaurants = Restaurant::get(); $addons = []; foreach ($restaurants as $restaurant) { $addons['tenant-' . $restaurant->id] = $restaurant->getPaidLicenses(); } return $addons; } public function getRestaurants(Request $request) { $restaurants = Restaurant::get(); // All restaurants with their licensing status (needed for reconciliation in the dashboard) $restaurants_status = $restaurants->map( function($restaurant) { $status = in_array($restaurant->status, Restaurant::statuses()) ? $restaurant->status : Restaurant::STATUS_LIVE; return [ 'id' => intval($restaurant->id), 'status' => $status ]; })->toArray(); $restaurants_status = array_values($restaurants_status); // Manageable restaurants = not archived (live + demo) $restaurants_id = array_values(array_map(function($r){ return $r['id']; }, array_filter($restaurants_status, function($r){ return $r['status'] !== Restaurant::STATUS_ARCHIVED; }))); return $this->response([ 'success' => true, 'restaurants_id' => $restaurants_id, 'restaurants_status' => $restaurants_status ]); } public function update(Request $request) { $license_key = $request->license_key; //ray('##'.$license_key.'##'); //if ($license_key == null) { ray('License key is null');} $license_activation = $request->license_activation; $license_addons = $request->license_addons; $license_addons_tenants = $request->license_addons_tenants; if ($license_key && is_string($license_key) && strlen($license_key) >= 9) { //ray('License key exists'); alexr_save_setting('license_key', $license_key); } else { // No borro la licencia por si ha habido un fallo en el cliente // y ha puesto la licencia a NULL y por eso se desactiva sola //ray('License key does not exists'); //alexr_save_setting('license_key', ''); } alexr_save_setting('license_code_check', $request->license_code_check); if ($license_activation) { alexr_save_setting('license_activation', $license_activation); } else { alexr_delete_setting('license_activation'); } if ($license_addons) { alexr_save_setting('license_addons', $license_addons); } else { alexr_delete_setting('license_addons'); } if ($license_addons_tenants) { alexr_save_setting('license_addons_tenants', $license_addons_tenants); } else { alexr_delete_setting('license_addons_tenants'); } return $this->response(['success' => true, 'message' => __eva('Saved!')]); } public function getErrors(Request $request) { return $this->response([ 'success' => true, 'list' => alexr_get_setting('license_list')]); } public function saveErrors(Request $request) { $list = $request->license_list; alexr_save_setting('license_list', $list); return $this->response(['success' => true]); } public function deactivateTenantsLicensesAddons(Request $request){ $addons = $request->addons; //ray($addons); /* array:1 [▼ "tenant-3" => "addon_whatsapp, addon_sms" ] */ if (is_array($addons)) { foreach($addons as $tenant_id => $slugs_string){ $id = str_replace('tenant-', '', $tenant_id); $addon = Addon::where('restaurant_id', $id)->first(); if ($addon) { $config = $addon->config; $slugs = array_map('trim', explode(',', $slugs_string)); $new_config = $config; foreach ($new_config['addons'] as &$item) { if (in_array($item['slug'], $slugs)) { $item['status'] = Addon::STATUS_INACTIVE; } } unset($item); $addon->config = $new_config; $addon->save(); } } } return $this->response(['success' => true]); } }