Beispiel #1
0
 /**
  * Display my invitations
  *
  * @return Response
  */
 public function invitations($user_id = null)
 {
     $result = \App\Models\UserInvitationLog::userid($user_id)->orderby('created_at', 'desc');
     $count = count($result->get());
     if (Input::has('skip')) {
         $skip = Input::get('skip');
         $result = $result->skip($skip);
     }
     if (Input::has('take')) {
         $take = Input::get('take');
         $result = $result->take($take);
     }
     $result = $result->get()->toArray();
     return new JSend('success', (array) ['count' => $count, 'data' => $result]);
 }
 public static function boot()
 {
     parent::boot();
     UserInvitationLog::observe(new UserInvitationLogObserver());
 }
Beispiel #3
0
 /**
  * Register customer
  *
  * @return Response
  */
 public function signup()
 {
     if (!Input::has('customer')) {
         return new JSend('error', (array) Input::all(), 'Tidak ada data customer.');
     }
     $customer = Input::get('customer');
     $errors = new MessageBag();
     DB::beginTransaction();
     //1. Validate User Parameter
     if (is_null($customer['id'])) {
         $is_new = true;
     } else {
         $is_new = false;
     }
     $customer_rules = ['name' => 'required|max:255', 'email' => 'required|max:255|unique:users,email,' . (!is_null($customer['id']) ? $customer['id'] : ''), 'password' => 'max:255', 'sso_id' => '', 'sso_media' => 'in:facebook', 'sso_data' => '', 'gender' => 'in:male,female', 'role' => 'required|in:customer', 'date_of_birth' => 'date_format:"Y-m-d H:i:s"'];
     //1a. Get original data
     $customer_data = \App\Models\Customer::findornew($customer['id']);
     //1b. Validate Basic Customer Parameter
     $validator = Validator::make($customer, $customer_rules);
     if (!$validator->passes()) {
         $errors->add('Customer', $validator->errors());
     } else {
         //if validator passed, save customer
         $customer_data = $customer_data->fill($customer);
         if (!$customer_data->save()) {
             $errors->add('Customer', $customer_data->getError());
         }
     }
     //2. check invitation
     if (!$errors->count() && isset($customer['reference_code'])) {
         $referral_data = \App\Models\Referral::code($customer['reference_code'])->first();
         if (!$referral_data) {
             $errors->add('Redeem', 'Link tidak valid. Silahkan mendaftar dengan menu biasa.');
         } elseif ($referral_data->quota <= 0) {
             $errors->add('Redeem', 'Quota referral sudah habis.');
         } else {
             $store = \App\Models\StoreSetting::type('voucher_point_expired')->Ondate('now')->first();
             if ($store) {
                 $expired_at = new Carbon($store->value);
             } else {
                 $expired_at = new Carbon('+ 3 months');
             }
             //if validator passed, save referral
             $point = ['user_id' => $customer_data['id'], 'reference_id' => $referral_data['user_id'], 'reference_type' => 'App\\Models\\User', 'expired_at' => $expired_at->format('Y-m-d H:i:s')];
             $point_data = new \App\Models\PointLog();
             $point_data->fill($point);
             if (!$point_data->save()) {
                 $errors->add('Redeem', $point_data->getError());
             }
         }
     }
     if (!$errors->count() && isset($referral_data)) {
         $invitation = \App\Models\UserInvitationLog::email($customer_data['email'])->userid($referral_data['user_id'])->first();
         if ($invitation) {
             $invitation->is_used = true;
             if (!$invitation->save()) {
                 $errors->add('Invitation', $invitation->getError());
             }
         }
     }
     if ($errors->count()) {
         DB::rollback();
         return new JSend('error', (array) Input::all(), $errors);
     }
     DB::commit();
     $final_customer = \App\Models\Customer::id($customer_data['id'])->first()->toArray();
     return new JSend('success', (array) $final_customer);
 }