本文整理汇总了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);
}