本文整理匯總了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);
}
示例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);
}