224 lines
9.1 KiB
PHP
224 lines
9.1 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Created by Reliese Model.
|
|
*/
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Services\HomepartyUserCart;
|
|
use App\User;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
/**
|
|
* Class HomepartyUser
|
|
*
|
|
* @property int $id
|
|
* @property int $homeparty_id
|
|
* @property int $auth_user_id
|
|
* @property bool $is_host
|
|
* @property string $billing_salutation
|
|
* @property string $billing_company
|
|
* @property string $billing_firstname
|
|
* @property string $billing_lastname
|
|
* @property string $billing_address
|
|
* @property string $billing_address_2
|
|
* @property string $billing_zipcode
|
|
* @property string $billing_city
|
|
* @property int $billing_country_id
|
|
* @property string $billing_phone
|
|
* @property string $billing_email
|
|
* @property bool $same_as_billing
|
|
* @property string $shipping_salutation
|
|
* @property string $shipping_company
|
|
* @property string $shipping_firstname
|
|
* @property string $shipping_lastname
|
|
* @property string $shipping_address
|
|
* @property string $shipping_address_2
|
|
* @property string $shipping_zipcode
|
|
* @property string $shipping_city
|
|
* @property int $shipping_country_id
|
|
* @property string $shipping_phone
|
|
* @property string $shipping_email
|
|
* @property bool $has_buyed
|
|
* @property bool $subscribed
|
|
* @property string $token
|
|
* @property bool $token_active
|
|
* @property string $notice
|
|
* @property string $mode
|
|
* @property Carbon $created_at
|
|
* @property Carbon $updated_at
|
|
* @property string $deleted_at
|
|
* @property Carbon $user_deleted_at
|
|
* @property User $user
|
|
* @property Country $country
|
|
* @property Homeparty $homeparty
|
|
* @package App\Models
|
|
* @property-read \App\User $auth_user
|
|
* @property-read \App\Models\Country $billing_country
|
|
* @property-read \App\Models\Country $shipping_country
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUser newModelQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUser newQuery()
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\HomepartyUser onlyTrashed()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUser query()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUser whereAuthUserId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUser whereBillingAddress($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUser whereBillingAddress2($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUser whereBillingCity($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUser whereBillingCompany($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUser whereBillingCountryId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUser whereBillingEmail($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUser whereBillingFirstname($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUser whereBillingLastname($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUser whereBillingPhone($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUser whereBillingSalutation($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUser whereBillingZipcode($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUser whereCreatedAt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUser whereDeletedAt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUser whereHasBuyed($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUser whereHomepartyId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUser whereId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUser whereIsHost($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUser whereMode($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUser whereNotice($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUser whereSameAsBilling($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUser whereShippingAddress($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUser whereShippingAddress2($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUser whereShippingCity($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUser whereShippingCompany($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUser whereShippingCountryId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUser whereShippingEmail($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUser whereShippingFirstname($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUser whereShippingLastname($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUser whereShippingPhone($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUser whereShippingSalutation($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUser whereShippingZipcode($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUser whereSubscribed($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUser whereToken($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUser whereTokenActive($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUser whereUpdatedAt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\HomepartyUser whereUserDeletedAt($value)
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\HomepartyUser withTrashed()
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\HomepartyUser withoutTrashed()
|
|
* @mixin \Eloquent
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\HomepartyUserOrderItem[] $homeparty_user_order_items
|
|
* @property-read int|null $homeparty_user_order_items_count
|
|
* @property string|null $delivery
|
|
* @property array|null $settings
|
|
* @method static \Illuminate\Database\Eloquent\Builder|HomepartyUser whereDelivery($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|HomepartyUser whereSettings($value)
|
|
*/
|
|
class HomepartyUser extends Model
|
|
{
|
|
use SoftDeletes;
|
|
|
|
protected $userCart = null;
|
|
|
|
protected $table = 'homeparty_users';
|
|
|
|
protected $casts = [
|
|
'homeparty_id' => 'int',
|
|
'auth_user_id' => 'int',
|
|
'is_host' => 'bool',
|
|
'billing_country_id' => 'int',
|
|
'same_as_billing' => 'bool',
|
|
'shipping_country_id' => 'int',
|
|
'has_buyed' => 'bool',
|
|
'subscribed' => 'bool',
|
|
'settings' => 'array',
|
|
|
|
];
|
|
|
|
protected $dates = [
|
|
'user_deleted_at'
|
|
];
|
|
|
|
|
|
protected $fillable = [
|
|
'homeparty_id',
|
|
'auth_user_id',
|
|
'is_host',
|
|
'billing_salutation',
|
|
'billing_company',
|
|
'billing_firstname',
|
|
'billing_lastname',
|
|
'billing_address',
|
|
'billing_address_2',
|
|
'billing_zipcode',
|
|
'billing_city',
|
|
'billing_country_id',
|
|
'billing_phone',
|
|
'billing_email',
|
|
'same_as_billing',
|
|
'shipping_salutation',
|
|
'shipping_company',
|
|
'shipping_firstname',
|
|
'shipping_lastname',
|
|
'shipping_address',
|
|
'shipping_address_2',
|
|
'shipping_zipcode',
|
|
'shipping_city',
|
|
'shipping_country_id',
|
|
'shipping_phone',
|
|
'shipping_email',
|
|
'has_buyed',
|
|
'subscribed',
|
|
'notice',
|
|
'mode',
|
|
'settings',
|
|
'delivery',
|
|
'user_deleted_at'
|
|
];
|
|
|
|
public function homeparty()
|
|
{
|
|
return $this->belongsTo(Homeparty::class);
|
|
}
|
|
|
|
public function auth_user()
|
|
{
|
|
return $this->belongsTo(User::class, 'auth_user_id');
|
|
}
|
|
|
|
public function billing_country()
|
|
{
|
|
return $this->belongsTo('App\Models\Country','billing_country_id');
|
|
}
|
|
|
|
public function shipping_country()
|
|
{
|
|
return $this->belongsTo('App\Models\Country','shipping_country_id');
|
|
}
|
|
|
|
public function homeparty_user_order_items(){
|
|
return $this->hasMany('App\Models\HomepartyUserOrderItem','homeparty_user_id');
|
|
|
|
}
|
|
|
|
public function isAddress(){
|
|
if($this->billing_firstname !== null && $this->billing_country_id !== null){
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public function getDelivery(){
|
|
return $this->delivery === 'direct' ? 'direct' : 'host';
|
|
}
|
|
|
|
|
|
public function getShipping(){
|
|
if($this->same_as_billing){
|
|
$country_id = $this->billing_country_id != null ? $this->billing_country_id : 1;
|
|
}else{
|
|
$country_id = $this->shipping_country_id != null ? $this->shipping_country_id : 1;
|
|
}
|
|
$shippingCountry = ShippingCountry::whereCountryId($country_id)->first();
|
|
if(!$shippingCountry){
|
|
return null;
|
|
}
|
|
return $shippingCountry->shipping;
|
|
}
|
|
}
|