Files
datahub/backend/app/Model/OrderItem.php
T

75 lines
2.8 KiB
PHP
Raw Normal View History

2025-12-12 13:15:02 +08:00
<?php
declare(strict_types=1);
namespace App\Model;
/**
* @property int $id 主键
* @property int $company_id 公司 ID 与 Tools 保持一致
* @property int $platform_id 平台 ID 与 Tools 保持一致
* @property int $store_id 店铺 ID 与 Tools 保持一致
* @property int $order_id 父订单 ID
* @property string $platform_order_id 平台父订单 ID
* @property string $sub_order_id 平台子订单 ID,部分平台有,如 Tmall
* @property int $sub_order_type_id 平台子订单 类型 id,标记字段
* @property int $product_id 商品 ID 与 Tools 保持一致
* @property string $platform_product_id 平台商品 ID 与 Tools 保持一致
* @property string $product_sku 商品 SKU 编码, 客户提供的内部商品编码
* @property string $product_barcode 商品 条形码 GTIN 等
* @property string $unit_price 单件价格
* @property int $quantity 商品子项总数量
* @property string $discount 订单子项总的折扣金额
* @property string $total 总金额 = 单价X数量 - 折扣
2026-02-05 08:53:07 +08:00
* @property \Carbon\Carbon $created_date 订单创建时间(与父订单 created_date 一致,hypertable 分区键)
* @property array|null $ext 扩展字段
2026-01-29 15:53:41 +08:00
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
2025-12-12 13:15:02 +08:00
* @mixin \App_Model_OrderItem
*/
class OrderItem extends Model
{
/**
* The table associated with the model.
*/
protected ?string $table = 'order_items';
/**
* The attributes that are mass assignable.
*/
2026-01-29 15:53:41 +08:00
protected array $fillable = ['id', 'company_id', 'platform_id', 'store_id', 'order_id', 'platform_order_id', 'sub_order_id', 'sub_order_type_id', 'product_id', 'platform_product_id', 'product_sku', 'product_barcode', 'unit_price', 'quantity', 'discount', 'total', 'created_date', 'ext', 'created_at', 'updated_at'];
2025-12-12 13:15:02 +08:00
/**
* The attributes that should be cast to native types.
*/
2026-02-05 08:53:07 +08:00
protected array $casts = [
'id' => 'integer',
'company_id' => 'integer',
'platform_id' => 'integer',
'store_id' => 'integer',
'order_id' => 'integer',
'sub_order_type_id' => 'integer',
'product_id' => 'integer',
'quantity' => 'integer',
'created_date' => 'datetime',
'ext' => 'json',
'created_at' => 'datetime',
'updated_at' => 'datetime',
];
2025-12-12 13:15:02 +08:00
/**
2026-01-29 15:53:41 +08:00
* 获取父订单(基于 hypertable 分区键查询)
*
* @return Order|null
2025-12-12 13:15:02 +08:00
*/
2026-01-29 15:53:41 +08:00
public function getParentOrder(): ?Order
2025-12-12 13:15:02 +08:00
{
2026-01-29 15:53:41 +08:00
return Order::query()
->where('platform_id', $this->platform_id)
->where('store_id', $this->store_id)
->where('platform_order_id', $this->platform_order_id)
->where('created_date', $this->created_date)
->first();
2025-12-12 13:15:02 +08:00
}
}