public function add(Request $request)
 {
     $user = \Session::get('user');
     if (!$user->can('项目签约')) {
         abort(401);
     }
     $sub = SubProduct::find($request->input('product_id'));
     $client = Client::find($request->input('client_id'));
     $project = new Project();
     $project->product()->associate($sub);
     $project->client()->associate($client);
     $project->vip = (bool) ($request->input('vip') == 'on');
     $project->signed_status = $request->input('signed_status');
     $project->ref_no = $request->input('ref_no');
     $project->name = $request->input('name');
     $project->seller = $request->input('seller');
     $project->contact_user = $request->input('contact_user');
     $signed_time = $request->input('signed_time');
     if (!$signed_time) {
         $signed_time = null;
     } else {
         $signed_time = \Carbon\Carbon::createFromFormat('Y/m/d', $signed_time)->format('Y-m-d H:i:s');
     }
     $project->signed_time = $signed_time;
     // 签约时间
     $service_unit = $request->input('service_unit');
     $service_value = $request->input('service_value');
     # 维保时间
     $project->service_unit = $service_unit;
     $project->service_value = $service_value;
     $project->description = $request->input('description');
     if ($project->save()) {
         foreach ($sub->modules as $module) {
             $project->modules()->save($module);
         }
         foreach ($sub->params as $param) {
             $project->params()->save($param, ['value' => $param->pivot->value]);
         }
         Clog::add($project, '签约项目');
         Clog::add($project->client, '签约项目', [$project->name], Clog::LEVEL_WARNING);
         \Log::notice(strtr('客户项目签约: 用户(%name[%id]) 签约了项目: (%project_name[%project_id]), 客户: (%client_name[%client_id], 子产品: (%product_name[%product_id])', ['%name' => $user->name, '%id' => $user->id, '%project_name' => $project->name, '%project_id' => $project->id, '%client_name' => $client->name, '%client_id' => $client->id, '%product_name' => $sub->name, '%product_id' => $sub->id]));
         return redirect(route('project.profile', ['id' => $project->id]))->with('message_content', '签约成功!')->with('message_type', 'info');
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  ModuleRequest $request
  * @param  Project $project
  * @return \Illuminate\Http\Response
  */
 public function store(ModuleRequest $request, Project $project)
 {
     $module = new Module($request->all());
     $project->modules()->save($module);
     return redirect()->route('project.show', [$project]);
 }