订单详情

This commit is contained in:
liu
2026-08-11 23:26:34 +08:00
parent 5d26f04ba2
commit ce958d690f
10 changed files with 996 additions and 70 deletions
+47 -1
View File
@@ -2,12 +2,14 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* 门店订单明细模型(快照下单时的商品名/规格/等级价,历史单据不受调价影响)
* 门店订单明细模型(下单时快照商品档案:品名/规格/单位/供应商/图文/成本价 + 等级单价,
* 商品调价或档案变更不影响历史单据)
*/
class StoreOrderItemModel extends Model
{
@@ -20,12 +22,19 @@ class StoreOrderItemModel extends Model
'order_id',
'store_id',
'product_id',
'category_id',
'supplier_id',
'product_name',
'product_spec',
'unit',
'price',
'image_ids',
'content',
'shelf_life',
'quantity',
'weight',
'amount',
'cost_price',
'remark',
];
@@ -33,12 +42,33 @@ class StoreOrderItemModel extends Model
'order_id' => 'integer',
'store_id' => 'integer',
'product_id' => 'integer',
'category_id' => 'integer',
'supplier_id' => 'integer',
'price' => 'decimal:2',
'shelf_life' => 'integer',
'quantity' => 'integer',
'weight' => 'decimal:3',
'amount' => 'decimal:2',
'cost_price' => 'decimal:2',
];
/**
* 成本价属商业敏感数据,默认不随 toArray 输出(防止泄漏到小程序端);
* 后台管理接口需在查询结果上调用 makeVisible('cost_price') 恢复。
*/
protected $hidden = ['cost_price'];
/**
* 商品图片ID(逗号分隔字符串 ↔ 数组)
*/
public function imageIds(): Attribute
{
return Attribute::make(
get: fn ($value) => $value === '' || $value === null ? [] : explode(',', (string) $value),
set: fn ($value) => is_array($value) ? implode(',', $value) : $value,
);
}
/**
* 所属订单
*/
@@ -62,4 +92,20 @@ class StoreOrderItemModel extends Model
{
return $this->belongsTo(ProductModel::class, 'product_id', 'id');
}
/**
* 快照供应商
*/
public function supplier(): BelongsTo
{
return $this->belongsTo(SupplierModel::class, 'supplier_id', 'id');
}
/**
* 快照商品分类
*/
public function category(): BelongsTo
{
return $this->belongsTo(ProductCategoryModel::class, 'category_id', 'id');
}
}