コード例 #1
0
 public function param_edit($id, Request $request)
 {
     $user = \Session::get('user');
     if (!$user->can('项目参数管理')) {
         abort(401);
     }
     $param_id = $request->input('param_id');
     $param = Param::find($param_id);
     $project = Project::find($id);
     $old_value = $project->params()->where('param_id', $param->id)->first()->pivot->value;
     //如果设定了需要重置,
     if ($request->input('reset') == 'on') {
         $new_value = $project->product->params()->where('param_id', $param->id)->first()->pivot->value;
         $project->params()->detach($param_id);
         $project->params()->save($param, ['value' => $new_value]);
         Clog::add($project, '重置参数', [['old' => $old_value, 'new' => $new_value, 'title' => $param->name]], Clog::LEVEL_WARNING);
     } else {
         $project->params()->detach($param_id);
         $new_value = $request->input('value');
         $project->params()->save($param, ['value' => $new_value, 'manual' => true]);
         Clog::add($project, '更新参数', [['old' => $old_value, 'new' => $new_value, 'title' => $param->name]], Clog::LEVEL_WARNING);
     }
     \Log::notice(strtr('项目参数修改: 用户(%name[%id]) 修改了项目(%project_name[%project_id]) 的参数 (%param_name[%param_id]): %old -> %new', ['%name' => $user->name, '%id' => $user->id, '%project_name' => $project->name, '%project_id' => $project->id, '%param_name' => $param->name, '%param_id' => $param->id, '%old' => $old_value, '%new' => $new_value]));
     return redirect()->back()->with('message_content', '参数修改成功!')->with('message_type', 'info')->with('tab', 'softwares');
 }
コード例 #2
0
 public function param_edit($id, Request $request)
 {
     $user = \Session::get('user');
     if (!$user->can('产品参数管理')) {
         abort(401);
     }
     $sub = SubProduct::find($id);
     $param_id = $request->input('param_id');
     $param = \App\Param::find($param_id);
     //获取子产品中该参数关联的 value
     $old_value = $sub->params()->where('param_id', $param->id)->first()->pivot->value;
     if ($request->input('reset') == 'on') {
         //获取到 product 中该参数的 value
         $value = $sub->product->params()->where('id', $param->id)->first()->value;
         $param->value = $value;
         $sub->params()->detach($param_id);
         $sub->params()->save($param, ['value' => $value]);
         \Log::notice(strtr('子产品参数修改: 用户 (%name[%id]) 修改了子产品 (%product_name[%product_id] 的参数(%param_name[%param_id]) : %old_value -> %new_value', ['%name' => $user->name, '%id' => $user->id, '%product_name' => $sub->name, '%product_id' => $sub->id, '%param_name' => $param->name, '%param_id' => $param->id, '%old_value' => $old_value, '%new_value' => $value]));
     } else {
         $value = $request->input('value');
         $sub->params()->updateExistingPivot($param_id, ['value' => $value, 'manual' => true]);
         \Log::notice(strtr('子产品参数修改: 用户 (%name[%id]) 修改了子产品 (%product_name[%product_id] 的参数(%param_name[%param_id]) : %old_value -> %new_value', ['%name' => $user->name, '%id' => $user->id, '%product_name' => $sub->name, '%product_id' => $sub->id, '%param_name' => $param->name, '%param_id' => $param->id, '%old_value' => $old_value, '%new_value' => $value]));
     }
     foreach ($sub->projects as $project) {
         $project_param = $project->params()->where('param_id', $param->id)->first();
         $old_value = $project_param->pivot->value;
         //如果为默认 (不为手动), 则修改
         if (!$project_param->pivot->manual) {
             $project->params()->updateExistingPivot($param->id, ['value' => $value]);
             \Log::notice(strtr('项目参数修改: 用户 (%name[%id]) 修改了项目 (%project_name[%project_id] 的参数(%param_name[%param_id]) : %old_value -> %new_value', ['%name' => $user->name, '%id' => $user->id, '%project_name' => $project->name, '%project_id' => $project->id, '%param_name' => $param->name, '%param_id' => $param->id, '%old_value' => $old_value, '%new_value' => $value]));
         }
     }
     return redirect()->back()->with('message_content', '参数修改成功!')->with('message_type', 'info');
 }
コード例 #3
0
 public function delete($id)
 {
     $user = \Session::get('user');
     if (!$user->can('产品参数管理')) {
         abort(401);
     }
     $param = Param::find($id);
     $param_name = $param->name;
     $param_id = $param->id;
     $param_value = $param->value;
     $product = $param->product;
     //softDelete, 删除后会 hide, 不用在其他的地方进行修改
     $param->delete();
     \Log::notice(strtr('产品参数删除: 用户 (%name[%id]) 删除了产品 (%product_name[%product_id] 的参数(%param_name[%param_id]) : %value', ['%name' => $user->name, '%id' => $user->id, '%product_name' => $product->name, '%product_id' => $product->id, '%param_name' => $param_name, '%param_id' => $param_id, '%value' => $param_value]));
     return redirect()->back()->with('message_content', '删除成功!')->with('message_type', 'info');
 }