client api

This commit is contained in:
pbao9
2026-02-11 10:08:39 +07:00
parent 458ad0a4cb
commit d59b2a0840
27 changed files with 4369 additions and 28 deletions
+63 -7
View File
@@ -2,19 +2,28 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Laravel\Sanctum\HasApiTokens;
class Customer extends Authenticatable
{
use HasFactory, HasApiTokens;
use HasFactory, HasApiTokens, HasUuids;
protected $table = 'customer';
protected $table = 'customers';
/**
* Chỉ định cột sẽ nhận UUID.
* Mặc định HasUuids dùng cột 'id', mình đổi sang 'uuid'.
*/
public function uniqueIds()
{
return ['uuid'];
}
protected $fillable = [
'firstname',
'lastname',
'fullname',
'avatar',
'address',
'state',
@@ -28,15 +37,26 @@ class Customer extends Authenticatable
'email_hash',
'email_marketing',
'receive_deposit',
'cccd',
'front_cccd',
'back_cccd',
'identity_number',
'front_identity_number',
'back_identity_number',
'password',
'credit',
'total',
'remember_token',
'status',
'gender',
'province_code',
'ward_code',
];
/**
* Appends for API
*/
protected $appends = [
'first_name',
'last_name',
'point',
];
/**
@@ -163,4 +183,40 @@ class Customer extends Authenticatable
{
return (bool) $this->receive_deposit;
}
public function getPointAttribute()
{
return (string) floor($this->total / 100);
}
public function getCmndBeforeAttribute()
{
return $this->front_identity_number ?? '';
}
public function getCmndAfterAttribute()
{
return $this->back_identity_number ?? '';
}
public function getCmndAttribute()
{
return $this->identity_number;
}
public function getOffMailMarketingAttribute()
{
return $this->email_marketing;
}
public function province()
{
return $this->belongsTo(Province::class, 'province_code', 'code');
}
public function ward()
{
return $this->belongsTo(Ward::class, 'ward_code', 'code');
}
}
+78
View File
@@ -0,0 +1,78 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Province extends Model
{
use HasFactory;
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'provinces';
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = false;
/**
* The primary key for the model.
*
* @var string
*/
protected $primaryKey = 'code';
/**
* The "type" of the primary key ID.
*
* @var string
*/
protected $keyType = 'string';
/**
* Indicates if the IDs are auto-incrementing.
*
* @var bool
*/
public $incrementing = false;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'code',
'name',
'name_en',
'full_name',
'full_name_en',
'code_name',
'administrative_unit_id',
];
/**
* Get the administrative unit that owns the province.
*/
public function administrativeUnit()
{
return $this->belongsTo(AdministrativeUnit::class, 'administrative_unit_id');
}
/**
* Get the wards for the province.
*/
public function wards()
{
return $this->hasMany(Ward::class, 'province_code', 'code');
}
}
+79
View File
@@ -0,0 +1,79 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Ward extends Model
{
use HasFactory;
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'wards';
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = false;
/**
* The primary key for the model.
*
* @var string
*/
protected $primaryKey = 'code';
/**
* The "type" of the primary key ID.
*
* @var string
*/
protected $keyType = 'string';
/**
* Indicates if the IDs are auto-incrementing.
*
* @var bool
*/
public $incrementing = false;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'code',
'name',
'name_en',
'full_name',
'full_name_en',
'code_name',
'province_code',
'administrative_unit_id',
];
/**
* Get the province that owns the ward.
*/
public function province()
{
return $this->belongsTo(Province::class, 'province_code', 'code');
}
/**
* Get the administrative unit that owns the ward.
*/
public function administrativeUnit()
{
return $this->belongsTo(AdministrativeUnit::class, 'administrative_unit_id');
}
}