public function postActivate(Request $request)
 {
     $validator = \Validator::make($request->all(), ['indexCode' => 'required|exists:mysql_old.member,pid', 'username' => 'required', 'phoneNumber' => 'required', 'name1' => 'required', 'phoneNumber1' => 'required', 'name2' => 'required', 'phoneNumber2' => 'required']);
     if ($validator->fails()) {
         return response()->json(['success' => false, 'error_message' => $validator->errors()->getMessages()]);
     }
     $pid = $request->input('indexCode');
     $uname = $request->input('username');
     $phone = $request->input('phoneNumber');
     $emergency_contact = $request->input('name1');
     $emergency_contact2 = $request->input('name2');
     $emergency_phone = $request->input('phoneNumber1');
     $emergency_phone2 = $request->input('phoneNumber2');
     $member = Member::where('pid', $pid)->first();
     $member->status = 0;
     $member->uname = $uname;
     $member->phone = $phone;
     $member->rphone1 = $emergency_phone;
     $member->rphone2 = $emergency_phone2;
     $member->save();
     $relative = Relative::where('mid', $member->id)->where('main', 1)->first();
     if (!$relative) {
         $relative = new Relative();
     }
     $relative->name = $emergency_contact;
     $relative->phone = $emergency_phone;
     $relative->mid = $member->id;
     $relative->main = 1;
     $relative->save();
     $relative = Relative::where('mid', $member->id)->where('main', 0)->first();
     if (!$relative) {
         $relative = new Relative();
     }
     $relative->name = $emergency_contact2;
     $relative->phone = $emergency_phone2;
     $relative->mid = $member->id;
     $relative->main = 0;
     $relative->save();
     return response()->json(['success' => true]);
 }
Пример #2
0
 public function postMultipleCreate(Request $request)
 {
     $excel = $request->file('watch');
     $target = $excel->move(storage_path(), 'test.xslt');
     \Excel::load($target, function ($reader) {
         $array = $reader->get()->toArray();
         $result = [];
         foreach ($array as $item) {
             if ($item[0]) {
                 $result[] = $item[0];
             }
         }
         foreach ($result as $item) {
             if ($member = Member::where('pid', intval($item))->first()) {
                 $member->fid = \Auth::user()->id;
                 $member->uname = \Auth::user()->contact_name;
                 $relative = Relative::where('mid', $member->id)->where('main', 1)->first();
                 if (!$relative) {
                     $relative = new Relative();
                 }
                 $relative->name = \Auth::user()->contact_name;
                 $relative->phone = \Auth::user()->contact_phone;
                 $relative->mid = $member->id;
                 $relative->main = 1;
                 $relative->save();
                 $member->save();
             }
         }
     });
     if (\Auth::user()->user_type == 0) {
         $items = Member::paginate(10);
     } else {
         $items = Member::where('fid', '=', \Auth::user()->id)->paginate(10);
     }
     return view('watch.index')->with(['success' => true, 'items' => $items]);
 }