loyalty_card = $loyalty_card; $this->personal_details = $personal_details; $this->format = $httpStatusCode; $this->admin_logs = $admin_logs; $this->user = $user; $this->lcard_logs = $lcard_logs; $this->system_preferences = $system_preferences; $this->otp_attempts = $otp_attempts; $this->otp_logs = $otp_logs; $this->mobile_usage = $mobile_usage; $this->mpin_codes = $mpin_codes; } /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index(Request $request) { $params = [ 'locked' => ($request->has('_locked') ? 1 : 0), 'search' => ($request->has('_search') ? $request->get('_search') : NULL), 'page_size' => ($request->has('page_size') ? $request->get('page_size') : 10), 'page' => ($request->has('page') ? $request->get('page') : 10), 'sorting' => ParameterHelper::prepareSortingParameter($request), 'filter' => [ 'is_validated' => ($request->has('status') ? $request->get('status') : null) ] ]; $list = $this->loyalty_card->listing($params); if(count($list)) { $additionals = $this->format->success("Success",[],false); $data = LoyaltyCardResource::collection($list)->additional($additionals); return $data->response()->setStatusCode(200); } else { return $this->format->success("No records found",[]); } } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { // } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { // } /** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($uuid) { $details = $this->loyalty_card->show($uuid,['personalDetails','codeVehicleOwn','codeCivilStatus','codeGender','codeCardType']); if($details) { $additionals = $this->format->success("Success",[],false); $data = (new LoyaltyCardResource($details))->additional($additionals); return $data->response()->setStatusCode(200); } else return $this->format->notFound(); } /** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { // } /** * * This function is accessed from mobile * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(MobileEditProfileFormValidation $request) { $member_details = CurrentUserHelper::get_currentMember(); // $city = $request->has('city_uuid') ? CodeCity::uuid($request->city_uuid)->first() : null; $cyware = new CywareLibrary(); $cyware->setCardNumber($member_details->card_number); $cyware->setFirstName($member_details->personalDetails->firstname); $cyware->setLastName($member_details->personalDetails->lastname); $cyware->setAddress($request->address); $cyware->setMobile('63'.$request->mobile); $cyware->setEmail($request->email); $cyware->setCivilStatusCode($request->civilstatus_code); $cyware->setGenderCode($request->gender_code); $cyware->setFuelType($request->fueltype_code); $cyware->setVehicleOwn($request->vo_code); $cyware->setCityCode($request->city); // if($city) // { // $cyware->setCityCode($city->code); // $request->merge(['city_id' => $city->city_id]); // } $cyware->state_update(); if($cyware->response['status_code'] == "200" && $cyware->response['message'] == "success") { $this->loyalty_card->update($request, $member_details->lcard_id); // $this->user->updateMember($request, $member_details->card_number); $path = $this->personal_details->update($request, $member_details->personalDetails->pd_id); $this->lcard_logs->log($member_details->lcard_id,'PROFILE','UPDATE'); if($path) { // $photo_url = str_replace('/public/index.php','',secure_url('storage/app/'.$path)); // $photo_url = str_replace('https','http',$photo_url); return $this->format->mobile_success('Profile updated',['photo' => S3::public_path($path)]); } else return $this->format->mobile_success('Profile updated',['photo' => '']); } else { return $this->format->mobile_error($cyware->response['message']); } } /** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($uuid) { } public function batch_delete(Request $request) { $lcard_uuid = $request->has('lcard_uuid') ? $request->get('lcard_uuid') : null; if($lcard_uuid) { $details_loyaltyCard = $this->loyalty_card->getDetailsWhereIn('lcard_uuid',$lcard_uuid,'personalDetails'); $pd_uuid = array(); foreach ($details_loyaltyCard as $key => $value) { $pd_uuid[] = $value['personal_details']['pd_uuid']; $this->admin_logs->log($value['lcard_id'],self::MODULE,'DELETE'); } if($this->loyalty_card->delete($lcard_uuid) && $this->personal_details->delete($pd_uuid)) { return $this->format->success("Member Successfully Deleted"); } else { return $this->format->badRequest('Something went wrong'); } } else { $data['lcard_uuid'] = 'lcard_uuid is required'; return $this->format->unprocessableEntity("Submit at least one user",$data); } } public function activate_locked($uuid) { $details = $this->loyalty_card->getByField(['lcard_uuid' => $uuid]); if($details->count()) { $details = $details[0]; if($this->loyalty_card->activate_locked($uuid)) { $adminLog = $this->admin_logs->log($details['lcard_id'],self::MODULE,'ACTIVATE'); $data['is_locked'] = false; return $this->format->success('User has been activated', $data); } } return $this->format->notFound(); } // public function direct_update(MobileEditProfileFormValidation $request) // { // $status = $this->update($request); // if($status == true) // { // return $this->format->mobile_success('Profile Details Updated', [ // 'photo' => // ]); // } // else // { // return $this->format->mobile_error($status); // } // } public function confirm_otp(Request $request) { $member_details = CurrentUserHelper::get_currentMember(); // lock after 3 attempts $numberOfAttempts = 0; $attempts = $this->loyalty_card->numberOfOTPAttempts($member_details->lcard_uuid); if(!is_null($attempts)) { $numberOfAttempts = $attempts->otpAttempts->count(); } if($numberOfAttempts >= 3) { $customer_service_email = $this->system_preferences->getByField('name','contact_email_address_mobile'); $customer_service_number = $this->system_preferences->getByField('name','contact_number_mobile'); return $this->format->mobile_error('You have entered the wrong OTP for 3 times. Your account is now locked for 24 hours and you will be logged out of the system.',[ 'code' => 1, 'email' => $customer_service_email[0]['value'], 'number' => $customer_service_number[0]['value'], ]); } else { $numberOfAttempts++; $this->otp_attempts->store($member_details->lcard_id,$request->otp); $this->lcard_logs->log($member_details->lcard_id,'OTP','ATTEMPT','Member entered otp '.$request->otp); // check if correct $otpLog = $this->otp_logs->getByField(['lcard_id' => $member_details->lcard_id, 'otp' => $request->otp]); if(count($otpLog)) { $latestOtp = $this->otp_logs->getLastLog($member_details->lcard_id); // checks if otp entered is expired and it's the latest otp created if(!StringHelper::check_time_exceeded($otpLog[0]['created_at'],'+5 minutes') || $latestOtp->otp != $request->otp) { if($numberOfAttempts >= 3) { return $this->format->mobile_error('You have entered the wrong OTP for 3 times. Your account is now locked for 24 hours, call or email customer service.',$this->lock_member($member_details)); $this->user->force_logout($member_details->card_number,2); } return $this->format->mobile_error('The OTP you have entered has already expired. Please select the Resend OTP option',['code' => 3]); } else { return $this->format->mobile_success('OTP Confirmed'); } } else { if($numberOfAttempts >= 3) { return $this->format->mobile_error('You have entered the wrong OTP for 3 times. Your account is now locked for 24 hours, call or email customer service.',$this->lock_member($member_details)); } return $this->format->mobile_error('Incorrect OTP. The OTP you have entered does not exist.',['code' => 2]); } } } private function lock_member($member_details) { $this->loyalty_card->lockMember($member_details->lcard_id,'02'); $this->lcard_logs->log($member_details->lcard_id,'OTP','LOCKED','Account is locked due to wrong OTP entered when updating the mobile phone number'); $this->mobile_usage->add_locked(); $customer_service_email = $this->system_preferences->getByField('name','contact_email_address_mobile'); $customer_service_number = $this->system_preferences->getByField('name','contact_number_mobile'); return [ 'code' => 1, 'email' => $customer_service_email[0]['value'], 'number' => $customer_service_number[0]['value'], ]; } public function myProfile() { $member_details = CurrentUserHelper::get_currentMember(); $cyware = new CywareLibrary(); $details = $this->loyalty_card->show($member_details->lcard_uuid,['personalDetails','codeVehicleOwn','codeCivilStatus','codeGender','codeCardType','codeCity','codeFuelType']); if($details) { $cyware->setCardNumber($member_details->card_number); $cyware->state_retrieve(); $additionals = $this->format->mobile_success("Success",[],false); $additionals["retrieved"] = $cyware->response["data"]; $data = (new MobileUserProfileResource($details))->additional($additionals); //return $data->response()->setStatusCode(200); //getmpin $mpin = $this->mpin_codes->getMpin($additionals["retrieved"]->customer_number); $dataResult = $this->StateRetrieve($data->response()->setStatusCode(200),$mpin); return $dataResult; // return $this->StateRetrieve($data->response()->setStatusCode(200)); } else return $this->format->notFound(); } public function validateMember(SecurityFormValidation $request) { // $member_details = CurrentUserHelper::get_currentMember(); // return $this->format->mobile_success($request->card_number,[ // 'is_valid' => 0 // ]); $cyware = new CywareLibrary(); $cyware->setCardNumber($request->get('card_number')); $cyware->state_validate(); if ($cyware->response['status_code'] == "200" && $cyware->response['data'] != null) { if($cyware->response['data']->birthdate != $request->get('birthdate')) { return $this->format->mobile_error( 'Incorrect Birthdate'); } if(strtolower($cyware->response['data']->email) != strtolower($request->get('email_address'))) { return $this->format->mobile_error( 'Incorrect Email'); } return $this->format->mobile_success('Success',[ 'is_valid' => 1 ]); } else { return $this->format->mobile_error($cyware->response['message'], ['card_number' => $cyware->response['message']]); } } public function StateRetrieve($data,$mpin){ $newData = $data->getData(); $mainData = []; $mainData["lcard_uuid"] = $newData->data->lcard_uuid; $mainData["card_number"] = $newData->data->card_number; $mainData["customer_number"] = $newData->retrieved->customer_number; $mainData["pin"] = $newData->data->pin; $mainData["birthdate"] = $newData->data->birthdate; $mainData["mobile"] = $newData->data->mobile; $mainData["email"] = $newData->data->email; $mainData["firstname"] = $newData->data->firstname; $mainData["lastname"] = $newData->data->lastname; $mainData["photo"] = $newData->data->photo; $mainData["card_type"] = $newData->data->card_type; $mainData["card_code"] = $newData->data->card_code; $mainData["card_image"] = $newData->data->card_image; $mainData["card_bg_image"] = $newData->data->card_bg_image; $mainData["card_black_label"] = $newData->data->card_black_label; $mainData["expiry_date"] = $newData->data->expiry_date; $mainData["points"] = $newData->data->points; //DATA THAT MUST GET FROM STATE RETRIEVE $mainData["middlename"] = $newData->retrieved->middle_initial; $mainData["city_name"] = $newData->retrieved->address; $mainData["address"] = $newData->retrieved->address; $mainData["civilstatus_code"] = $newData->retrieved->civil_status_code; $mainData["gender_code"] = $newData->retrieved->gender_code; $mainData["vo_code"] = $newData->retrieved->vehicle_own_code; $mainData["fueltype_code"] = $newData->retrieved->fuel_type_code; if($mpin){ $mainData["mpin"] = $mpin->mpin_code; } //$mainData['log'] = "start:".$datestart." ---- end:".$dateend; $newData->data = $mainData; return response()->json($newData); } }