| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Database\Eloquent\Model;
- class Member extends Model
- {
- use HasFactory;
- protected $fillable = [
- 'first_name',
- 'last_name',
- 'status',
- 'birth_city_id',
- 'birth_province_id',
- 'birth_nation_id',
- 'birth_date',
- 'gender',
- 'address',
- 'zip_code',
- 'fiscal_code',
- 'nation_id',
- 'province_id',
- 'city_id',
- 'phone',
- 'email',
- 'enabled',
- ];
- public function nation()
- {
- return $this->belongsTo(Nation::class);
- }
- public function province()
- {
- return $this->belongsTo(Province::class);
- }
- public function city()
- {
- return $this->belongsTo(City::class);
- }
- public function birth_nation()
- {
- return $this->belongsTo(Nation::class);
- }
- public function birth_province()
- {
- return $this->belongsTo(Province::class);
- }
- public function birth_city()
- {
- return $this->belongsTo(City::class);
- }
- public function isActive()
- {
- $ret = array('status' => false, 'date' => '');
- $cards = \App\Models\MemberCard::where('member_id', $this->id)->with('card')->orderBy('expire_date')->get();
- foreach($cards as $card)
- {
- if ($card->card->use_for_user_check)
- {
- $ret = array('status' => $card->expire_date > date("Y-m-d"), 'date' => $card->expire_date);
- }
- }
- return $ret;
- }
- public function getMoney()
- {
- $ret = 0;
- // Soldi virtuali caricati
- $records = \App\Models\Record::where('member_id', $this->id)->where('type', 'IN')->with('causal')->get();
- foreach($records as $record)
- {
- if ($record->causal->money == 1)
- {
- $ret += $record->amount;
- }
- }
- // Soldi virtuali spesi
- $records = \App\Models\Record::where('member_id', $this->id)->where('type', 'IN')->with('payment_method')->get();
- foreach($records as $record)
- {
- if ($record->payment_method->money == 1)
- {
- $ret -= $record->amount;
- }
- }
- return $ret;
- }
- }
|