Пример #1
0
function update_referal_signup($user_id)
{
    try {
        if ($user_id != '-') {
            $user = User::find($user_id);
            if (isset($user->id)) {
                $month = date('m');
                $year = date('Y');
                $referral = Referral::where('user_id', '=', $user_id)->where(DB::raw('month(created_at)'), '=', $month)->where(DB::raw('year(created_at)'), '=', $year)->first();
                if (!isset($referral->id)) {
                    $referral = new Referral();
                    $referral->user_id = $user_id;
                }
                $referral->total_signup = $referral->total_signup + 1;
                if ($referral->proposal_gained <= 30) {
                    $proposal = 5;
                    $referral->proposal_gained = $referral->proposal_gained + $proposal;
                    $account = Account::where('user_id', '=', $user_id)->first();
                    $account->monthly_proposal_limit = $account->monthly_proposal_limit + $proposal;
                    $account->save();
                }
                $referral->save();
            }
        }
    } catch (Exception $e) {
    }
}
 public function savecontractor()
 {
     $refer_id = $_POST['refer_id'];
     $cont = new Contractors();
     $cont->Name = $_POST['company_name'];
     $cont->ContactName = $_POST['your_name'];
     $cont->Phone = $_POST['company_phone'];
     $cont->Fax = $_POST['company_fax'];
     $cont->Address1 = $_POST['company_address'];
     $cont->City = $_POST['city'];
     $cont->State = $_POST['state'];
     $cont->Zip = $_POST['zip_code'];
     $cont->Email = $_POST['email'];
     $cont->Username = $_POST['username'];
     $cont->Password = $_POST['password'];
     $cont->Website = $_POST['website'];
     $cont->AboutBusiness = $_POST['about_business'];
     $cont->ProjectTypeId = $_POST['projecttype'];
     $cont->Services = $_POST['primary_services'];
     $cont->insert();
     Yii::app()->Ini->savetovnoc($_POST['email']);
     $identity = new UserIdentity($_POST['email'], $_POST['password'], 'contractor');
     //$identity=new UserIdentity('*****@*****.**','school30','contractors');
     if ($identity->authenticate()) {
         Yii::app()->user->login($identity);
         $owner_id = Yii::app()->user->getId();
         Yii::app()->Ini->savetoaffiliate($owner_id, 'contractor');
         Yii::app()->Ini->savetocampaign($_POST['email'], $_POST['company_name']);
         if ($refer_id != '') {
             $rcont = Contractors::model()->findByPk($refer_id);
             if (count($rcont) > 0) {
                 $t = ContractorTeam::model()->findByAttributes(array('contractor_id' => $rcont->ContractorId, 'invited_id' => $owner_id));
                 if (count($t) == 0) {
                     $team = new ContractorTeam();
                     $team->contractor_id = $rcont->ContractorId;
                     $team->invited_id = $owner_id;
                     $team->confirmed = 1;
                     $team->save();
                     $team2 = new ContractorTeam();
                     $team2->contractor_id = $owner_id;
                     $team2->invited_id = $rcont->ContractorId;
                     $team2->confirmed = 1;
                     $team2->save();
                 }
             }
             $ref = new Referral();
             $ref->userid = $owner_id;
             $ref->user_type = 'contractor';
             $ref->referred_by = $refer_id;
             $ref->referred_by_type = 'contractor';
             $ref->save();
         }
         $status = array('status' => true);
     } else {
         $status = false;
         $status = array('status' => false, 'error_message' => $identity->errorMessage);
     }
     $this->renderJSON($status);
 }
Пример #3
0
 public function testIsReferred()
 {
     //Insert into referral table
     $referral = new Referral();
     $referral->status = Referral::REFERRED_IN;
     $referral->facility_id = 1;
     $referral->person = "Gentrix";
     $referral->contacts = "Saville Row : London";
     $referral->user_id = 1;
     $specimen = Specimen::find(1);
     $referral->save();
     $specimen->referral_id = $referral->id;
     $specimen->save();
     $this->assertEquals($specimen->isReferred(), true);
 }
        		$curl_handle = curl_init();
        		curl_setopt($curl_handle, CURLOPT_URL, $api_url);
        		curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 10);
        		curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
        		curl_setopt($curl_handle, CURLOPT_POST, 1);
        		curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $data);
        		$response = curl_exec($curl_handle);
        		curl_close($curl_handle);  */
    }
    //save sub uuid -> short_code/email combo
    //save empty as well
    $r = new Referral();
    $r->uuid = $uuid;
    $r->email = $email;
    $r->short_code = $referrer;
    $r->save();
    return View::make('recurly.confirm')->with('response', $response);
});
Route::post('recurly-notification', array('before' => 'postnotification', function () {
    $o = Option::find('1');
    //need to handle
    $post_xml = file_get_contents("php://input");
    $notification = new Recurly_PushNotification($post_xml);
    $raw = new RawNotification();
    $raw->type = $notification->type;
    $raw->xml = $post_xml;
    $raw->save();
    if ($notification->type == 'successful_payment_notification') {
        //check if need to have sent commission event
        if ($notification->transaction->subscription_id != '' && $notification->transaction->subscription_id != null) {
            $r = Referral::where('uuid', '=', $notification->transaction->subscription_id)->first();
Пример #5
0
 /**
  * Refer action
  *
  * @return View
  */
 public function referAction()
 {
     //Validate
     $rules = array('referral-status' => 'required', 'facility_id' => 'required|non_zero_key', 'person', 'contacts');
     $validator = Validator::make(Input::all(), $rules);
     $specimenId = Input::get('specimen_id');
     if ($validator->fails()) {
         return Redirect::route('test.refer', array($specimenId))->withInput()->withErrors($validator);
     }
     //Insert into referral table
     $referral = new Referral();
     $referral->status = Input::get('referral-status');
     $referral->facility_id = Input::get('facility_id');
     $referral->person = Input::get('person');
     $referral->contacts = Input::get('contacts');
     $referral->user_id = Auth::user()->id;
     //Update specimen referral status
     $specimen = Specimen::find($specimenId);
     DB::transaction(function () use($referral, $specimen) {
         $referral->save();
         $specimen->referral_id = $referral->id;
         $specimen->save();
     });
     //Start test
     Input::merge(array('id' => $specimen->test->id));
     //Add the testID to the Input
     $this->start();
     //Return view
     $url = Session::get('SOURCE_URL');
     return Redirect::to($url)->with('message', trans('messages.specimen-successful-refer'))->with('activeTest', array($specimen->test->id));
 }
 public function saveproject($post)
 {
     $indicator = $post['indicator'];
     $status = true;
     $return['indicator'] = $indicator;
     if ($indicator == 2) {
         if (Homeowners::model()->countByAttributes(array('email' => $post['homeown_email'])) == 0) {
             if (Homeowners::model()->countByAttributes(array('username' => $post['howeown_pname'])) == 0) {
                 $password = Yii::app()->Ini->generate_password();
                 $huser = new Homeowners();
                 $huser->firstname = $post['homeown_fname'];
                 $huser->lastname = $post['homeown_lname'];
                 $huser->email = $post['homeown_email'];
                 $huser->phone_number = $post['homeown_phone'];
                 $huser->username = $post['howeown_pname'];
                 $huser->password = $password;
                 if ($huser->save()) {
                     Yii::app()->Ini->savetovnoc($post['homeown_email']);
                     $owner_id = Yii::app()->db->getLastInsertId();
                     Yii::app()->Ini->savetoaffiliate($owner_id, 'homeowner');
                     Yii::app()->Ini->savetocampaign($huser->email, $huser->firstname . ' ' . $huser->lastname);
                     $this->SendMailAfterSignUp($owner_id);
                     $refer_id = $post['refer_id'];
                     if ($refer_id != '') {
                         $ref = new Referral();
                         $ref->userid = $owner_id;
                         $ref->user_type = 'homeowner';
                         $ref->referred_by = $refer_id;
                         $ref->referred_by_type = 'contractor';
                         $ref->save();
                     }
                 } else {
                     $status = false;
                     $return['message'] = $huser->getErrors();
                 }
             } else {
                 $status = false;
                 $return['message'] = "Username already exists.";
             }
         } else {
             $status = false;
             $return['message'] = "Email already exists.";
         }
     } elseif ($indicator == 3) {
         $status = true;
         $owner_id = Yii::app()->user->getId();
     } else {
         $identity = new UserIdentity($post['home_loginEmail'], $post['home_loginPassword'], 'homeowner');
         if ($identity->authenticate()) {
             Yii::app()->user->login($identity);
             $owner_id = Yii::app()->user->getId();
         } else {
             $status = false;
             $return['message'] = $identity->errorMessage;
         }
     }
     if ($status) {
         //saving to project
         $proj = new Projects();
         $proj->project_type_id = $post['projecttype'];
         $proj->description = $post['projectdesc'];
         $proj->start_date = $post['projectstart'];
         $proj->status_for_project = $post['projectstatus'];
         $proj->time_frame = $post['projecttimeframe'];
         $proj->owned_property = $post['won_pro'];
         $proj->address = $post['projectaddress'];
         $proj->state_id = $post['projectstate'];
         $proj->city = $post['city'];
         $proj->zipcode = $post['zip_code'];
         $proj->budget = $post['projectbudget'];
         $proj->homeowner_id = $owner_id;
         if ($proj->save()) {
             $proj_id = Yii::app()->db->getLastInsertId();
             $this->SendMailAfterProject($proj_id);
             Yii::app()->Ini->renovationapi($proj_id);
             if ($indicator == 3) {
                 $return['message'] = $this->renderPartial('successpost', array(), true);
             } else {
                 if ($indicator == 2) {
                     //echo $password;
                     //echo $post['homeown_email'];
                     //$return['message'] = $this->renderPartial('success', array(), true);
                     $return['projectid'] = $proj_id;
                     $identity = new UserIdentity($post['homeown_email'], $password, 'homeowner');
                     if ($identity->authenticate()) {
                         Yii::app()->user->login($identity);
                         $owner_id = Yii::app()->user->getId();
                         $return['message'] = $this->renderPartial('success', array(), true);
                     } else {
                         $status = false;
                         $return['message'] = $identity->errorMessage;
                     }
                 } else {
                     $return['message'] = $this->renderPartial('success', array(), true);
                 }
             }
         } else {
             $status = false;
             $return['message'] = $proj->getErrors();
         }
     }
     $return['status'] = $status;
     $this->renderJSON($return, $status);
 }