67 lines
1.8 KiB
PHP
67 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Models\YiiModels\Drug;
|
|
use App\Models\YiiModels\DrugstoreDrug;
|
|
use App\Models\YiiModels\Store;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
/**
|
|
* App\Models\Cart
|
|
*
|
|
* @property int $id
|
|
* @property int $user_id 用户ID
|
|
* @property int $drug_id 药品ID
|
|
* @property int $store_id 门店ID
|
|
* @property int $qty 数量
|
|
* @property string|null $join_at 加入时间
|
|
* @property \Illuminate\Support\Carbon|null $created_at
|
|
* @property \Illuminate\Support\Carbon|null $updated_at
|
|
* @property-read \App\Models\YiiModels\Drug|null $drug 药品
|
|
* @property-read string $created_at_format 创建时间的格式化
|
|
* @property-read string $status_string 状态名称
|
|
* @property-read string $updated_at_format 更新时间的格式化
|
|
* @property-read \App\Models\YiiModels\Store|null $store 门店
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Cart newModelQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Cart newQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Cart query()
|
|
* @mixin \Eloquent
|
|
*/
|
|
class Cart extends BaseModel
|
|
{
|
|
protected $attributes = [
|
|
'qty' => 0,
|
|
];
|
|
|
|
protected static function boot()
|
|
{
|
|
parent::boot();
|
|
parent::creating(function (self $model) {
|
|
if (!isset($model->join_at) && !$model->join_at) {
|
|
$model->join_at = now();
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @comment 药品
|
|
*
|
|
* @return BelongsTo
|
|
*/
|
|
public function drug(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Drug::class, 'drug_id');
|
|
}
|
|
|
|
/**
|
|
* @comment 门店
|
|
*
|
|
* @return BelongsTo
|
|
*/
|
|
public function store(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Store::class, 'store_id');
|
|
}
|
|
}
|