initializeBackend($request); if ($response !== null) { return $response; } $row = MallConfig::order('id', 'asc')->find(); if (!$row) { $now = time(); MallConfig::create([ 'return_ratio' => floatval(env('PLAYX_RETURN_RATIO', '0.1')), 'unlock_ratio' => floatval(env('PLAYX_UNLOCK_RATIO', '0.1')), 'points_to_cash_ratio' => floatval(env('PLAYX_POINTS_TO_CASH_RATIO', '0.1')), 'create_time' => $now, 'update_time' => $now, ]); $row = MallConfig::order('id', 'asc')->find(); } return $this->success('', [ 'row' => $row ? $row->toArray() : [], 'remark' => get_route_remark(), ]); } public function save(Request $request): Response { $response = $this->initializeBackend($request); if ($response !== null) { return $response; } $data = $request->post(); if (empty($data) || !is_array($data)) { return $this->error(__('Parameter %s can not be empty', [''])); } $return = $data['return_ratio'] ?? null; $unlock = $data['unlock_ratio'] ?? null; $cash = $data['points_to_cash_ratio'] ?? null; if (!is_numeric($return) || !is_numeric($unlock) || !is_numeric($cash)) { return $this->error(__('Parameter error')); } $returnF = floatval($return); $unlockF = floatval($unlock); $cashF = floatval($cash); if ($returnF < 0 || $unlockF < 0 || $cashF < 0) { return $this->error(__('Parameter error')); } $row = MallConfig::order('id', 'asc')->find(); if (!$row) { $now = time(); MallConfig::create([ 'return_ratio' => $returnF, 'unlock_ratio' => $unlockF, 'points_to_cash_ratio' => $cashF, 'create_time' => $now, 'update_time' => $now, ]); } else { $row->return_ratio = $returnF; $row->unlock_ratio = $unlockF; $row->points_to_cash_ratio = $cashF; $row->save(); } MallPlayxRatios::forget(); return $this->success(__('The current page configuration item was updated successfully')); } }