|
@@ -6,6 +6,7 @@ use App\Enums\ProjectStatus;
|
|
|
use App\Enums\TechnicianStatus;
|
|
|
use App\Models\MemberUser;
|
|
|
use App\Models\Project;
|
|
|
+use App\Models\SettingGroup;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
@@ -156,21 +157,63 @@ class ProjectService
|
|
|
->first();
|
|
|
abort_if(! $coachProject, 404, '未开通该项目');
|
|
|
|
|
|
- // TODO:取值范围待定(从配置表中获取)
|
|
|
+ // 获取全局项目设置分组
|
|
|
+ $projectSettingGroup = SettingGroup::where('code', 'project')->first();
|
|
|
+ abort_if(! $projectSettingGroup, 404, '项目设置分组不存在');
|
|
|
|
|
|
- // 验证服务距离的合理范围
|
|
|
- if (isset($data['service_distance']) && $data['service_distance'] > 0) {
|
|
|
- abort_if($data['service_distance'] > 50, 422, '服务距离不能超过50公里');
|
|
|
+ // 获取项目设置中代金卷、交通费、顾客性别设置
|
|
|
+ $projectSettingItems = $projectSettingGroup->items()->where('code', 'voucher')->orWhere('code', 'traffic_fee')->orWhere('code', 'gender')->get();
|
|
|
+
|
|
|
+ // 检查代金卷金额是否存在,并且是否大于0
|
|
|
+ if (isset($data['voucher']) && $data['voucher'] > 0) {
|
|
|
+ $voucherSettingItem = $projectSettingItems->where('code', 'voucher')->first();
|
|
|
+ abort_if(! $voucherSettingItem, 404, '代金卷设置不存在');
|
|
|
+
|
|
|
+ // 从项目设置中验证代金卷金额的合理范围
|
|
|
+ abort_if($data['voucher'] > $voucherSettingItem->max_value, 422, '代金卷金额不能超过'.$voucherSettingItem->max_value.'元');
|
|
|
+
|
|
|
+ // 更新技师折扣金额配置
|
|
|
+ $user->coach->settingValues()->updateOrCreate(
|
|
|
+ ['item_id' => $projectSettingItems->where('code', 'voucher')->first()->id],
|
|
|
+ ['value' => $data['voucher']],
|
|
|
+ ['object_type' => $coachProject::class],
|
|
|
+ ['object_id' => $coachProject->id],
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
- // 更新项目设置
|
|
|
- $coachProject->update([
|
|
|
- 'discount_amount' => $data['discount_amount'] ?? $coachProject->discount_amount,
|
|
|
- 'service_gender' => $data['service_gender'] ?? $coachProject->service_gender,
|
|
|
- 'service_distance' => $data['service_distance'] ?? $coachProject->service_distance,
|
|
|
- 'traffic_fee_type' => $data['traffic_fee_type'] ?? $coachProject->traffic_fee_type,
|
|
|
- 'traffic_fee' => $data['traffic_fee'] ?? $coachProject->traffic_fee,
|
|
|
- ]);
|
|
|
+ // 检查路费设置是否存在,并且是否大于0
|
|
|
+ if (isset($data['traffic_fee']) && $data['traffic_fee'] >= 0) {
|
|
|
+ $trafficFeeSettingItem = $projectSettingItems->where('code', 'traffic_fee')->first();
|
|
|
+ abort_if(! $trafficFeeSettingItem, 404, '路费设置不存在');
|
|
|
+
|
|
|
+ // 从项目设置中验证交通费类型的合理范围
|
|
|
+ abort_if($data['traffic_fee'] > $trafficFeeSettingItem->max_value, 422, '交通费类型不能超过'.$trafficFeeSettingItem->max_value.'元');
|
|
|
+
|
|
|
+ // 更新技师路费配置
|
|
|
+ $user->coach->settingValues()->updateOrCreate(
|
|
|
+ ['item_id' => $projectSettingItems->where('code', 'traffic_fee')->first()->id],
|
|
|
+ ['value' => $data['traffic_fee']],
|
|
|
+ ['object_type' => $coachProject::class],
|
|
|
+ ['object_id' => $coachProject->id],
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查顾客性别设置是否存在,并且是否大于0
|
|
|
+ if (isset($data['gender']) && $data['gender'] >= 0) {
|
|
|
+ $customerGenderSettingItem = $projectSettingItems->where('code', 'gender')->first();
|
|
|
+ abort_if(! $customerGenderSettingItem, 404, '顾客性别设置不存在');
|
|
|
+
|
|
|
+ // 从项目设置中验证顾客性别设置的合理范围
|
|
|
+ abort_if($data['gender'] > $customerGenderSettingItem->max_value, 422, '顾客性别设置不能超过'.$customerGenderSettingItem->max_value.'元');
|
|
|
+
|
|
|
+ // 更新技师顾客性别设置
|
|
|
+ $user->coach->settingValues()->updateOrCreate(
|
|
|
+ ['item_id' => $projectSettingItems->where('code', 'gender')->first()->id],
|
|
|
+ ['value' => $data['gender']],
|
|
|
+ ['object_type' => $coachProject::class],
|
|
|
+ ['object_id' => $coachProject->id],
|
|
|
+ );
|
|
|
+ }
|
|
|
|
|
|
// 记录日志
|
|
|
Log::info('技师项目设置更新成功', [
|
|
@@ -182,14 +225,8 @@ class ProjectService
|
|
|
|
|
|
return [
|
|
|
'message' => '项目设置更新成功',
|
|
|
- 'project_id' => $coachProject->project_id,
|
|
|
- 'settings' => [
|
|
|
- 'discount_amount' => $coachProject->discount_amount,
|
|
|
- 'service_gender' => $coachProject->service_gender,
|
|
|
- 'service_distance' => $coachProject->service_distance,
|
|
|
- 'traffic_fee_type' => $coachProject->traffic_fee_type,
|
|
|
- 'traffic_fee' => $coachProject->traffic_fee,
|
|
|
- ],
|
|
|
+ 'coach_id' => $user->coach->id,
|
|
|
+ 'settings' => $data,
|
|
|
];
|
|
|
|
|
|
} catch (\Exception $e) {
|