Files
xin-procurement/app/Models/StoreModel.php
T
2026-08-14 23:47:49 +08:00

77 lines
1.7 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* 门店模型(小程序下单主体)
*/
class StoreModel extends Model
{
use SoftDeletes, HasFactory;
/** 状态:停用 */
public const STATUS_DISABLED = 0;
/** 状态:正常 */
public const STATUS_NORMAL = 1;
protected $table = 'store';
protected $primaryKey = 'id';
protected $fillable = [
'name',
'code',
'level_id',
'contact',
'phone',
'address',
'payment_cycle_days',
'status',
'remark',
];
protected $casts = [
'level_id' => 'integer',
'payment_cycle_days' => 'integer',
'total_purchase_amount' => 'decimal:2',
'status' => 'integer',
];
/**
* 所属客户等级(决定商品展示价格)
*/
public function level(): BelongsTo
{
return $this->belongsTo(CustomerLevelModel::class, 'level_id', 'id');
}
/**
* 门店订单
*/
public function orders(): HasMany
{
return $this->hasMany(StoreOrderModel::class, 'store_id', 'id');
}
/**
* 绑定本门店的小程序用户
*/
public function users(): HasMany
{
return $this->hasMany(UserModel::class, 'store_id', 'id');
}
/**
* 门店账单(采购单完成后按门店生成)
*/
public function bills(): HasMany
{
return $this->hasMany(BillModel::class, 'store_id', 'id');
}
}