/** * Method Name :Store * Insert data to User Table and consequencesly insert to Account, Carries and Downline table * * */ public function store(UserRegRequest $request, User $user) { $uplineUser = User::where('username', $request->upline_id)->first(); $referrarUser = User::where('username', $request->referrar_id)->first(); $uplineId = $uplineUser->id; $requestValue = $request->placement; // return $request->full_name . "++". preg_replace('/\s+/', '', strtolower($request->username)); // $username = $address = $request->address1 . "," . $request->address2; // return $user->insert([['username' => preg_replace('/\\s+/', '', strtolower($request->username)), 'full_name' => $request->full_name, 'gender' => $request->gender, 'email' => $request->email, 'password' => bcrypt($request->password), 'remember_token' => $request->_token, 'address' => $address, 'phone_number' => $request->phone_number, 'country' => $request->country, 'account_no' => 555210, 'referrar_id' => $referrarUser->id, 'upline_id' => $uplineUser->id, 'pin' => rand(1, 99999999), 'signup_date' => Carbon::now(), 'last_login_time' => Carbon::now()]]); $lastRegUser = $user->where('username', preg_replace('/\\s+/', '', strtolower($request->username)))->first(); $role = Role::where('id', 3)->first(); $lastRegUser->assign($role); Account::insert(['balance' => 0, 'roi_balance' => 0, 'user_id' => $lastRegUser->id, 'acc_type' => '0']); Carry::insert(['user_id' => $lastRegUser->id, 'left_carry' => 0, 'right_carry' => 0, 'matching_qualify' => 0]); Downline::insert(['user_id' => $lastRegUser->id, 'left_member_id' => 0, 'right_member_id' => 0]); /*Downline::where('user_id', $uplineUser->id) ->update(['right_member_id' => $request->placement]);*/ /*return $downLineTable = Downline::where('user_id', $uplineId)->first(); if($downLineTable->left_member_id == 0 && $request->placement != 'right'){ Downline::where('user_id', $uplineUser->id) ->update(['left_member_id' => $lastRegUser->id]); } else { Downline::where('user_id', $uplineUser->id) ->update(['right_member_id' => $lastRegUser->id]); } */ $position = preg_replace('/\\s+/', '', strtolower($requestValue)) . "_member_id"; Downline::where('user_id', $uplineUser->id)->update([$position => $lastRegUser->id]); return redirect()->back(); }
public function updateMatchingQualify() { $results = DB::table('carries')->join('transactions', function ($join) { $join->on('carries.user_id', '=', 'transactions.user_id')->where('transactions.purpose', '=', 12); })->get(); foreach ($results as $result) { if ($result->left_carry != 0 || $result->right_carry != 0 && $result->matching_qualify != 1) { Carry::where('user_id', $result->user_id)->update(['matching_qualify' => 1]); } } }