初始化项目
This commit is contained in:
66
app/Models/DrugStoreRelation.php
Normal file
66
app/Models/DrugStoreRelation.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\YiiModels\Store;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* App\Models\DrugStoreRelation
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $store_id 门店id
|
||||
* @property int $drug_id 药品id
|
||||
* @property string $price 销售价
|
||||
* @property int $status 状态1下架2上架
|
||||
* @property int $base_sales_volume 基础销量
|
||||
* @property int $true_sales_volume 真实销量
|
||||
* @property int $total_sales_volume 总销量
|
||||
* @property string|null $buy_price 进货(采购)价
|
||||
* @property \Illuminate\Support\Carbon|null $created_at
|
||||
* @property \Illuminate\Support\Carbon|null $updated_at
|
||||
* @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\DrugStoreRelation newModelQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\DrugStoreRelation newQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\DrugStoreRelation query()
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
class DrugStoreRelation extends BaseModel
|
||||
{
|
||||
// 状态
|
||||
public const STATUS_OFF = 1;
|
||||
public const STATUS_ON = 2;
|
||||
public const STATUS = [
|
||||
self::STATUS_OFF => '下架',
|
||||
self::STATUS_ON => '上架',
|
||||
];
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
parent::creating(function (self $model) {
|
||||
$model->total_sales_volume = $model->base_sales_volume + $model->true_sales_volume;
|
||||
});
|
||||
parent::updating(function (self $model) {
|
||||
if (
|
||||
isset($model->total_sales_volume)
|
||||
&& isset($model->base_sales_volume)
|
||||
&& isset($model->true_sales_volume)
|
||||
) {
|
||||
$model->total_sales_volume = $model->base_sales_volume + $model->true_sales_volume;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @comment 门店
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function store(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Store::class, 'store_id');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user