コード例 #1
0
 public function createUser(Request $request)
 {
     $request_data = $request->input('request');
     $request_array = json_decode($request_data, true);
     $resturant = Resturant::Where('id', '=', $request_array['resturant_id'])->firstOrFail();
     $subscription = SubscriptionPlan::Where('id', '=', $resturant->subscription_plan_id)->firstOrFail();
     $all = User::Where('resturant_id', '=', $request_array['resturant_id'])->count();
     if ($all >= $subscription->user) {
         return response()->json(["Response" => "error", "message" => "You Subscription plan doesn't allow more users"]);
     }
     $rules = array('email' => 'unique:users,email');
     $validator = \Validator::make(array('email' => $request_array['email']), $rules);
     if ($validator->fails()) {
         return response()->json(["Response" => "Error", "message" => "This Email Address is Already Registered in our system."]);
     }
     $user = new User();
     $user->email = $request_array['email'];
     $hashed_password = Hash::make($request_array['password']);
     $user->password = $hashed_password;
     $user->phone = $request_array['phone'];
     $user->fullname = $request_array['fullname'];
     $user->activation_token = str_random(32);
     $user->active = 0;
     $user->role_id = 2;
     $user->resturant_id = $request_array['resturant_id'];
     $user->save();
     $alluserlocation = $request_array['locations'];
     foreach ($alluserlocation as $location) {
         $locationId = $location['id'];
         $user_locations = new UserLocation();
         $user_locations->user_id = $user->id;
         $user_locations->location_id = $locationId;
         $user_locations->save();
     }
     $maincardactions = $request_array['mainmenu'];
     $weeklycardactions = $request_array['weeklymenu'];
     $itemsactions = $request_array['items'];
     $user_actions = new UserAction();
     $user_actions->maincard = serialize($maincardactions);
     $user_actions->weeklymenu = serialize($weeklycardactions);
     $user_actions->items = serialize($itemsactions);
     $user_actions->user_id = $user->id;
     $user_actions->save();
     \Event::fire(new registrationEmail($user));
     return response()->json(["Response" => "success", "message" => "User Successfully Created"]);
 }
コード例 #2
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request, $resturant_id)
 {
     //
     $registered_resturant = Resturant::Where('id', '=', $resturant_id)->firstOrFail();
     $subscription = SubscriptionPlan::Where('id', '=', $registered_resturant->subscription_plan_id)->firstOrFail();
     $resturant_locations = Location::Where('resturantId', '=', $resturant_id)->count();
     if ($resturant_locations == $subscription->location) {
         return response()->json(["Response" => "error", "message" => "You Subscription plan doesn't allow more locations"]);
     } else {
         $location = new Location();
         $request_data = $request->input('request');
         $request_array = json_decode($request_data, true);
         $parsed_object = $request_array['locationdetails'];
         $location->geo_location = $parsed_object['geo_location'];
         $location->radius = $parsed_object['radius'];
         $location->name = $parsed_object['name'];
         $location->address = $parsed_object['address'];
         $location->resturantId = $resturant_id;
         $location->save();
     }
     return response()->json(["Response" => "success", "message" => 'Location saved successfully']);
 }
コード例 #3
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, $franchiseId)
 {
     //
     $registered_resturant = Resturant::Where('id', '=', $id)->firstOrFail();
     $subscription = SubscriptionPlan::Where('id', '=', $registered_resturant->subscription_plan_id)->firstOrFail();
     $franchise_users = User::Where('franchise_id', '=', $franchiseId)->count();
     $all_users = User::Where('resturant_id', '=', $id)->where('franchise_id', '!=', -1)->count();
     $request_data = $request->input('request');
     $request_array = json_decode($request_data, true);
     $Location_users = $request_array['users'];
     $effective_users = $all_users - $franchise_users + sizeof($Location_users);
     if ($effective_users > $subscription->user) {
         return response()->json(["Response" => "error", "message" => "You Subscription plan doesn't allow more users"]);
     } else {
         $franchise = Franchise::Where('id', '=', $franchiseId)->firstOrFail();
         $parsed_object = $request_array['Franchise'];
         $franchise->location_id = $parsed_object['location_id'];
         $franchise->address = $parsed_object['address'];
         $franchise->phone = $parsed_object['phone'];
         $franchise->name = $parsed_object['name'];
         $franchise->save();
         $rules = array('email' => 'unique:users,username');
         foreach ($Location_users as $users) {
             $name = $users['username'];
             $validator = \Validator::make(array('email' => $name), $rules);
             if ($validator->fails()) {
                 return response()->json(["Response" => "error", "message" => 'Email Address : ' . $name . ' is Already Registered in our system.']);
             }
         }
         foreach ($Location_users as $users) {
             $isnew = array_get($users, 'isnew', 'default');
             if ($isnew != 'default') {
                 $user = new User();
                 $name = $users['username'];
                 $password = $user['password'];
                 $user->username = $name;
                 $hashed_password = Hash::make($password);
                 $user->password = $hashed_password;
                 $user->resturant_id = $id;
                 $user->franchise_id = $franchiseId;
                 $user->role_id = 2;
                 $user->active = 0;
                 $user->activation_token = str_random(32);
                 \Event::fire(new registrationEmail($user));
                 $user->save();
             } else {
                 $name = $users['username'];
                 $password = $users['password'];
                 $userId = $users['id'];
                 $user = User::Where('id', '=', $userId)->firstOrFail();
                 $user->username = $name;
                 if ($user->password != $password) {
                     $hashed_password = Hash::make($password);
                     $user->password = $password;
                 }
                 $user->save();
             }
         }
         $franchise_Users = User::Where('franchise_id', '=', $franchiseId)->get();
         foreach ($franchise_Users as $franchiseUsers) {
             $franchiseUserId = $franchiseUsers->id;
             $tobeDeleted = true;
             foreach ($Location_users as $locationUsers) {
                 $isnew = array_get($locationUsers, 'isnew', 'default');
                 if ($isnew == 'default') {
                     if ($locationUsers['id'] == $franchiseUserId) {
                         $tobeDeleted = false;
                         break;
                     }
                 } else {
                     $tobeDeleted = false;
                 }
             }
             if ($tobeDeleted) {
                 User::where('id', '=', $franchiseUserId)->delete();
             }
         }
         return response()->json(["Response" => "success", "message" => "Franchise info Updated"]);
     }
     return response()->json(["Response" => "error", "message" => "There was an error processing your request"]);
 }
コード例 #4
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)
 {
     //
     echo $id;
     $resturant = Resturant::findOrFail($id);
     $request_array = $request->input('request');
     $request_data = json_decode($request_array, true);
     if ($request_data['name']) {
         $resturant->name = $request_data['name'];
     }
     if ($request_data['phone']) {
         $resturant->phone = $request_data['phone'];
     }
     if ($request_data['address']) {
         $resturant->address = $request_data['address'];
     }
     if ($request_data['email']) {
         $resturant->email = $request_data['email'];
     }
     if ($request_data['logo']) {
         $resturant->logo = $request_data['logo'];
     }
     $resturant->save();
     return response()->json(["Response" => "success"]);
 }