当前位置: 首页>>代码示例>>PHP>>正文


PHP Customer::findornew方法代码示例

本文整理汇总了PHP中app\models\Customer::findornew方法的典型用法代码示例。如果您正苦于以下问题:PHP Customer::findornew方法的具体用法?PHP Customer::findornew怎么用?PHP Customer::findornew使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\models\Customer的用法示例。


在下文中一共展示了Customer::findornew方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: store

 /**
  * Register customer
  *
  * @return Response
  */
 public function store($user_id = null)
 {
     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' => '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', '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());
         }
     }
     if ($errors->count()) {
         DB::rollback();
         return new JSend('error', (array) Input::all(), $errors);
     }
     DB::commit();
     $final_customer = \App\Models\Customer::id($user_id)->with(['myreferrals', 'myreferrals.user'])->first()->toArray();
     return new JSend('success', (array) $final_customer);
 }
开发者ID:ThunderID,项目名称:SHOP-API,代码行数:41,代码来源:MyController.php

示例2: signup

 /**
  * 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);
 }
开发者ID:ThunderID,项目名称:SHOP-API,代码行数:73,代码来源:AuthController.php


注:本文中的app\models\Customer::findornew方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。