|
|
@@ -3,7 +3,9 @@
|
|
|
namespace Longyi\RewardPoints\Http\Controllers\Admin;
|
|
|
|
|
|
use Illuminate\Http\JsonResponse;
|
|
|
+use Illuminate\Http\Request;
|
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
+use Longyi\RewardPoints\Repositories\RewardPointSettingRepository;
|
|
|
use Longyi\RewardPoints\Services\GrowthValueService;
|
|
|
use Longyi\RewardPoints\Models\GrowthValueCustomer;
|
|
|
use Longyi\RewardPoints\Models\GrowthValueHistory;
|
|
|
@@ -14,9 +16,10 @@ class GrowthValueController extends Controller
|
|
|
{
|
|
|
protected $growthValueService;
|
|
|
|
|
|
- public function __construct(GrowthValueService $growthValueService)
|
|
|
+ public function __construct(GrowthValueService $growthValueService,RewardPointSettingRepository $settingRepository)
|
|
|
{
|
|
|
$this->growthValueService = $growthValueService;
|
|
|
+ $this->settingRepository = $settingRepository;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -48,6 +51,81 @@ class GrowthValueController extends Controller
|
|
|
return view('rewardpoints::admin.growth-value.index', compact('customers'));
|
|
|
}
|
|
|
|
|
|
+ public function settings()
|
|
|
+ {
|
|
|
+ $groups = $this->settingRepository->getGroups();
|
|
|
+ $currentGroup = request('group', 'growth_value');
|
|
|
+ $settings = $this->settingRepository->getSettingsByGroup($currentGroup);
|
|
|
+
|
|
|
+ // 获取分组数据(包含名称和排序)
|
|
|
+ $groupData = $this->getGroupData($groups);
|
|
|
+
|
|
|
+ return view('rewardpoints::admin.growth-value.settings', compact('groups', 'currentGroup', 'settings', 'groupData'));
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 保存配置
|
|
|
+ */
|
|
|
+ public function saveSettings(Request $request)
|
|
|
+ {
|
|
|
+ $this->validate($request, [
|
|
|
+ 'settings' => 'required|array'
|
|
|
+ ]);
|
|
|
+
|
|
|
+ try {
|
|
|
+ $settings = $request->input('settings');
|
|
|
+
|
|
|
+ foreach ($settings as $code => $value) {
|
|
|
+ $this->settingRepository->setConfigValue($code, $value);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 清除缓存
|
|
|
+ cache()->forget('reward_points_settings');
|
|
|
+
|
|
|
+ session()->flash('success', '配置保存成功');
|
|
|
+
|
|
|
+ $redirectRoute = isset($this->_config['redirect']) ? $this->_config['redirect'] : 'admin.growth-value.settings';
|
|
|
+ return redirect()->route($redirectRoute, ['group' => $request->input('group', 'general')]);
|
|
|
+
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ session()->flash('error', '保存配置失败:' . $e->getMessage());
|
|
|
+ return redirect()->back()->withInput();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 获取分组数据(包含名称和排序)
|
|
|
+ */
|
|
|
+ protected function getGroupData($groups)
|
|
|
+ {
|
|
|
+ // 定义分组排序顺序
|
|
|
+ $groupOrder = [
|
|
|
+ 'general' => 1, // 通用设置
|
|
|
+ ];
|
|
|
+
|
|
|
+ $groupData = [];
|
|
|
+ foreach ($groups as $group) {
|
|
|
+ $groupData[$group] = [
|
|
|
+ 'name' => $this->getGroupName($group),
|
|
|
+ 'order' => $groupOrder[$group] ?? 99, // 如果未定义顺序,默认排在最后
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 按照排序顺序排列
|
|
|
+ uasort($groupData, function($a, $b) {
|
|
|
+ return $a['order'] <=> $b['order'];
|
|
|
+ });
|
|
|
+
|
|
|
+ return $groupData;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 获取分组名称
|
|
|
+ */
|
|
|
+ protected function getGroupName($group)
|
|
|
+ {
|
|
|
+ $names = [
|
|
|
+ 'general' => '成长值设置',
|
|
|
+ ];
|
|
|
+ return $names[$group] ?? ucfirst($group);
|
|
|
+ }
|
|
|
/**
|
|
|
* 显示某个会员的成长值详情
|
|
|
*/
|