采购单优化
This commit is contained in:
@@ -1,67 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* 采购金额分摊模型(实际采购金额按订货比例分摊到门店/单品,尾差修正保证金额守恒)
|
||||
*/
|
||||
class PurchaseAllocationModel extends Model
|
||||
{
|
||||
protected $table = 'purchase_allocation';
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
protected $fillable = [
|
||||
'purchase_item_id',
|
||||
'order_item_id',
|
||||
'store_id',
|
||||
'product_id',
|
||||
'quantity',
|
||||
'weight',
|
||||
'amount',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'purchase_item_id' => 'integer',
|
||||
'order_item_id' => 'integer',
|
||||
'store_id' => 'integer',
|
||||
'product_id' => 'integer',
|
||||
'quantity' => 'decimal:2',
|
||||
'weight' => 'decimal:3',
|
||||
'amount' => 'decimal:2',
|
||||
];
|
||||
|
||||
/**
|
||||
* 来源采购明细
|
||||
*/
|
||||
public function purchaseItem(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(PurchaseOrderItemModel::class, 'purchase_item_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 溯源订货明细
|
||||
*/
|
||||
public function orderItem(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(StoreOrderItemModel::class, 'order_item_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 分摊门店
|
||||
*/
|
||||
public function store(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(StoreModel::class, 'store_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 分摊商品
|
||||
*/
|
||||
public function product(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ProductModel::class, 'product_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* 采购单明细模型(按商品+供应商聚合,快照品名/规格;实际金额录入后用于分摊)
|
||||
*/
|
||||
class PurchaseOrderItemModel extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/** 未发送供应商 */
|
||||
public const NOT_SENT = 0;
|
||||
/** 已发送供应商 */
|
||||
public const SENT = 1;
|
||||
|
||||
protected $table = 'purchase_order_item';
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
protected $fillable = [
|
||||
'purchase_id',
|
||||
'product_id',
|
||||
'supplier_id',
|
||||
'product_name',
|
||||
'product_spec',
|
||||
'price',
|
||||
'quantity',
|
||||
'weight',
|
||||
'amount',
|
||||
'sort',
|
||||
'is_sent',
|
||||
'sent_at',
|
||||
'supplier_confirmed_at',
|
||||
'remark',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'purchase_id' => 'integer',
|
||||
'product_id' => 'integer',
|
||||
'supplier_id' => 'integer',
|
||||
'price' => 'decimal:2',
|
||||
'quantity' => 'decimal:2',
|
||||
'weight' => 'decimal:3',
|
||||
'amount' => 'decimal:2',
|
||||
'sort' => 'integer',
|
||||
'is_sent' => 'integer',
|
||||
'sent_at' => 'datetime',
|
||||
'supplier_confirmed_at' => 'datetime',
|
||||
];
|
||||
|
||||
/**
|
||||
* 所属采购单
|
||||
*/
|
||||
public function purchase(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(PurchaseOrderModel::class, 'purchase_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 采购商品
|
||||
*/
|
||||
public function product(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ProductModel::class, 'product_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 供货供应商
|
||||
*/
|
||||
public function supplier(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(SupplierModel::class, 'supplier_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 金额分摊记录(按订货比例摊到门店/单品)
|
||||
*/
|
||||
public function allocations(): HasMany
|
||||
{
|
||||
return $this->hasMany(PurchaseAllocationModel::class, 'purchase_item_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -9,18 +9,14 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Modules\SystemUser\Models\SysUserModel;
|
||||
|
||||
/**
|
||||
* 采购单模型(按门店订单汇总生成,按商品+供应商聚合)
|
||||
* 采购单模型(按门店订单汇总生成;无独立明细表,明细直接溯源订货明细 store_order_item.purchase_id)
|
||||
*/
|
||||
class PurchaseOrderModel extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/** 状态:待发送 */
|
||||
/** 状态:进行中(已生成,待完成) */
|
||||
public const STATUS_PENDING = 0;
|
||||
/** 状态:部分发送 */
|
||||
public const STATUS_PART_SENT = 1;
|
||||
/** 状态:全部发送 */
|
||||
public const STATUS_ALL_SENT = 2;
|
||||
/** 状态:已完成 */
|
||||
public const STATUS_COMPLETED = 3;
|
||||
|
||||
@@ -58,10 +54,18 @@ class PurchaseOrderModel extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* 采购明细
|
||||
* 本采购单归集的门店订货明细
|
||||
*/
|
||||
public function items(): HasMany
|
||||
public function orderItems(): HasMany
|
||||
{
|
||||
return $this->hasMany(PurchaseOrderItemModel::class, 'purchase_id', 'id')->orderBy('sort');
|
||||
return $this->hasMany(StoreOrderItemModel::class, 'purchase_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 本采购单合并的门店订单
|
||||
*/
|
||||
public function orders(): HasMany
|
||||
{
|
||||
return $this->hasMany(StoreOrderModel::class, 'purchase_id', 'id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ class ReconciliationItemModel extends Model
|
||||
protected $fillable = [
|
||||
'recon_id',
|
||||
'store_id',
|
||||
'purchase_item_id',
|
||||
'order_item_id',
|
||||
'product_id',
|
||||
'product_name',
|
||||
@@ -38,7 +37,6 @@ class ReconciliationItemModel extends Model
|
||||
protected $casts = [
|
||||
'recon_id' => 'integer',
|
||||
'store_id' => 'integer',
|
||||
'purchase_item_id' => 'integer',
|
||||
'order_item_id' => 'integer',
|
||||
'product_id' => 'integer',
|
||||
'quantity' => 'decimal:2',
|
||||
@@ -74,14 +72,6 @@ class ReconciliationItemModel extends Model
|
||||
return $this->belongsTo(ProductModel::class, 'product_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 来源采购明细
|
||||
*/
|
||||
public function purchaseItem(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(PurchaseOrderItemModel::class, 'purchase_item_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 溯源订货明细
|
||||
*/
|
||||
|
||||
@@ -20,6 +20,7 @@ class StoreOrderItemModel extends Model
|
||||
|
||||
protected $fillable = [
|
||||
'order_id',
|
||||
'purchase_id',
|
||||
'store_id',
|
||||
'product_id',
|
||||
'category_id',
|
||||
@@ -40,6 +41,7 @@ class StoreOrderItemModel extends Model
|
||||
|
||||
protected $casts = [
|
||||
'order_id' => 'integer',
|
||||
'purchase_id' => 'integer',
|
||||
'store_id' => 'integer',
|
||||
'product_id' => 'integer',
|
||||
'category_id' => 'integer',
|
||||
@@ -94,7 +96,7 @@ class StoreOrderItemModel extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* 快照供应商
|
||||
* 供应商
|
||||
*/
|
||||
public function supplier(): BelongsTo
|
||||
{
|
||||
|
||||
@@ -44,14 +44,6 @@ class SupplierModel extends Model
|
||||
return $this->hasMany(ProductModel::class, 'supplier_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 供应商的采购明细行
|
||||
*/
|
||||
public function purchaseItems(): HasMany
|
||||
{
|
||||
return $this->hasMany(PurchaseOrderItemModel::class, 'supplier_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定本供应商的小程序用户
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user