138 lines
3.1 KiB
PHP
Executable File
138 lines
3.1 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Rooyesh\Wallet\models\Wallet;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Tymon\JWTAuth\Contracts\JWTSubject;
|
|
|
|
|
|
class Customer extends Authenticatable implements JWTSubject
|
|
{
|
|
use HasFactory,SoftDeletes,Selector;
|
|
protected $fillable = [
|
|
'fname',
|
|
'lname',
|
|
'name',
|
|
'active',
|
|
'finger_print',
|
|
'mobile',
|
|
'email',
|
|
'avatar_id',
|
|
'last_seen_at',
|
|
'default_address_id',
|
|
'sts',
|
|
'total_transaction',
|
|
'token_sms',
|
|
'password',
|
|
'orders_count',
|
|
'birth_date',
|
|
'shop_name',
|
|
'phone_number',
|
|
'code',
|
|
'city',
|
|
'province',
|
|
'n_code',
|
|
'is_archive',
|
|
'gram',
|
|
'trade_active',//آیا امکان معامله دارد؟
|
|
'type',
|
|
'referral_id',
|
|
'referral_to_id',
|
|
'credential_id',
|
|
'moshtari_code',
|
|
|
|
];
|
|
/**
|
|
* The attributes that should be hidden for arrays.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $hidden = [
|
|
'password',
|
|
'token_sms',
|
|
];
|
|
/**
|
|
* The attributes that should be cast to native types.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $casts = [
|
|
"active" => "boolean",
|
|
"gold" => "float",
|
|
"is_archive" => "boolean",
|
|
"finger_print" => "boolean",
|
|
];
|
|
static $TYPE = [
|
|
1=>'همکار',
|
|
2=>'خانگی',
|
|
3=>'سرمایه گذار'
|
|
];
|
|
static $TYPES = [
|
|
1=>'همکار',
|
|
2=>'خانگی',
|
|
3=>'سرمایه گذار'
|
|
];
|
|
public function setNameAttribute($value = null)
|
|
{
|
|
$fname = $this->attributes['fname'] ?? '';
|
|
$lname = $this->attributes['lname'] ?? '';
|
|
|
|
$this->attributes['name'] = trim("$fname $lname");
|
|
}
|
|
|
|
|
|
public function wallet()
|
|
{
|
|
return $this->hasMany(Wallet::class ,'owner')->with(['fund','product'])->select(['cash', 'fund_id','product_id','gold', 'owner']);
|
|
}
|
|
public function user()
|
|
{
|
|
return $this->belongsTo(User::class)->select(['id','name']);
|
|
}
|
|
public function referral()
|
|
{
|
|
return $this->belongsTo(Customer::class, 'referral_to_id', 'referral_id');
|
|
}
|
|
|
|
// hash password
|
|
public function setPasswordAttribute($value){
|
|
$this->attributes['password'] = Hash::make($value);
|
|
}
|
|
|
|
public function getJWTIdentifier()
|
|
{
|
|
return $this->getKey();
|
|
}
|
|
|
|
public function getJWTCustomClaims()
|
|
{
|
|
return [];
|
|
}
|
|
|
|
public function tahesab()
|
|
{
|
|
return $this->hasMany(Tahesab::class, 'customer_id', 'id');
|
|
}
|
|
|
|
public function customer_settings()
|
|
{
|
|
return $this->hasMany(CustomersSetting::class, 'agent_id');
|
|
}
|
|
|
|
public function package()
|
|
{
|
|
return $this->belongsTo(Package::class);
|
|
}
|
|
|
|
public function agent()
|
|
{
|
|
return $this->belongsTo(Customer::class, 'agent_id');
|
|
}
|
|
|
|
}
|