示例#1
0
文件: user.php 项目: sandakinhs/iCRM3
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     session_start();
     $data = $request->all();
     $count = App\User::where('user_name', $data['user_name'])->count();
     if ($count != 0) {
         return 0;
     } else {
         $data['user_owner'] = $_SESSION['user_id'];
         $data['user_password'] = md5($data['user_password']);
         $userid = App\User::create($data)->id;
         $log = new Log();
         $log->add_log("users", $userid, "insert");
         // add a log
         foreach ($_SESSION['groups'] as $group_name) {
             $group_d = App\group::where('group_name', $group_name)->first();
             $group_pri = App\privilege::where('group_id', $group_d->group_id)->first();
             $data_pri = ['user_id' => $userid, 'group_id' => $group_d->group_id, 'call_log' => $group_pri->call_log, 'contact' => $group_pri->contact, 'account' => $group_pri->account, 'user' => $group_pri->user, 'group' => $group_pri->group, 'sales' => $group_pri->sales, 'ticket' => $group_pri->ticket];
             App\user_group::create($data_pri);
         }
         return redirect('user');
     }
 }
示例#2
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     session_start();
     $loguser = $_SESSION['user_id'];
     $data = $request->all();
     $data['group_modified_by'] = $loguser;
     App\group::find($id)->update($data);
     $log = new Log();
     $log->add_log("groups", $id, "update");
     // add a log
     $calllog = NULL;
     if (isset($_POST['calllog_view'])) {
         if (isset($_POST['calllog_add'])) {
             $calllog = $calllog + $_POST['calllog_add'];
         }
         if (isset($_POST['calllog_edit'])) {
             $calllog = $calllog + $_POST['calllog_edit'];
         }
         if (isset($_POST['calllog_delete'])) {
             $calllog = $calllog + $_POST['calllog_delete'];
         }
         if ($calllog == NULL) {
             $calllog = 8;
         }
     }
     $data_pri['call_log'] = $calllog;
     $contact = NULL;
     if (isset($_POST['contact_view'])) {
         if (isset($_POST['contact_add'])) {
             $contact = $contact + $_POST['contact_add'];
         }
         if (isset($_POST['contact_edit'])) {
             $contact = $contact + $_POST['contact_edit'];
         }
         if (isset($_POST['contact_delete'])) {
             $contact = $contact + $_POST['contact_delete'];
         }
         if ($contact == NULL) {
             $contact = 8;
         }
     }
     $data_pri['contact'] = $contact;
     $account = NULL;
     if (isset($_POST['account_view'])) {
         if (isset($_POST['account_add'])) {
             $account = $account + $_POST['account_add'];
         }
         if (isset($_POST['account_edit'])) {
             $account = $account + $_POST['account_edit'];
         }
         if (isset($_POST['account_delete'])) {
             $account = $account + $_POST['account_delete'];
         }
         if ($account == NULL) {
             $account = 8;
         }
     }
     $data_pri['account'] = $account;
     $sales = NULL;
     if (isset($_POST['sales_view'])) {
         if (isset($_POST['sales_add'])) {
             $sales = $sales + $_POST['sales_add'];
         }
         if (isset($_POST['sales_edit'])) {
             $sales = $sales + $_POST['sales_edit'];
         }
         if (isset($_POST['sales_delete'])) {
             $sales = $sales + $_POST['sales_delete'];
         }
         if ($sales == NULL) {
             $sales = 8;
         }
     }
     $data_pri['sales'] = $sales;
     $user = NULL;
     if (isset($_POST['user_view'])) {
         if (isset($_POST['user_add'])) {
             $user = $user + $_POST['user_add'];
         }
         if (isset($_POST['user_edit'])) {
             $user = $user + $_POST['user_edit'];
         }
         if (isset($_POST['user_delete'])) {
             $user = $user + $_POST['user_delete'];
         }
         if ($user == NULL) {
             $user = 8;
         }
     }
     $data_pri['user'] = $user;
     $ticket = NULL;
     if (isset($_POST['ticket_view'])) {
         if (isset($_POST['ticket_add'])) {
             $ticket = $ticket + $_POST['ticket_add'];
         }
         if (isset($_POST['ticket_edit'])) {
             $ticket = $ticket + $_POST['ticket_edit'];
         }
         if (isset($_POST['ticket_delete'])) {
             $ticket = $ticket + $_POST['ticket_delete'];
         }
         if ($ticket == NULL) {
             $ticket = 8;
         }
     }
     $data_pri['ticket'] = $ticket;
     $group = NULL;
     // if(isset($_POST['group_view'])){
     // 	if(isset($_POST['group_add'])){
     // 	$group=$group+$_POST['group_add'];
     // 	}
     // 	if(isset($_POST['group_edit'])){
     // 	$group=$group+$_POST['group_edit'];
     // 	}
     // 	if(isset($_POST['group_delete'])){
     // 	$group=$group+$_POST['group_delete'];
     // 	}
     // 	if($group==NULL){
     //  	$group=8;
     //  	}
     // }
     $data_pri['group'] = $group;
     App\privilege::where('group_id', $id)->first()->update($data_pri);
     return redirect('group');
 }