回筐、账单完成

This commit is contained in:
liu
2026-08-14 01:19:47 +08:00
parent e35c951a59
commit bf8ac68391
39 changed files with 1392 additions and 963 deletions
+34
View File
@@ -15,6 +15,17 @@ class BillModel extends Model
{
use HasFactory;
/** 支付状态:未支付 */
public const int STATUS_UNPAID = 0;
/** 支付状态:已支付 */
public const int STATUS_PAID = 1;
/** 支付状态中文名 */
public const array STATUS_NAMES = [
self::STATUS_UNPAID => '未支付',
self::STATUS_PAID => '已支付',
];
protected $table = 'bill';
protected $primaryKey = 'id';
@@ -31,6 +42,10 @@ class BillModel extends Model
'tray_price',
'added_amount',
'total_amount',
'status',
'paid_at',
'pay_remark',
'paid_operator_id',
'operator_id',
'remark',
];
@@ -47,6 +62,9 @@ class BillModel extends Model
'tray_price' => 'decimal:2',
'added_amount' => 'decimal:2',
'total_amount' => 'decimal:2',
'status' => 'integer',
'paid_at' => 'datetime:Y-m-d H:i:s',
'paid_operator_id' => 'integer',
'operator_id' => 'integer',
'created_at' => 'datetime:Y-m-d H:i:s',
];
@@ -75,6 +93,14 @@ class BillModel extends Model
return $this->belongsTo(SysUserModel::class, 'operator_id', 'id');
}
/**
* 收款操作人(后台系统用户,线下收款登记)
*/
public function paidOperator(): BelongsTo
{
return $this->belongsTo(SysUserModel::class, 'paid_operator_id', 'id');
}
/**
* 本账单关联的门店订单
*/
@@ -82,4 +108,12 @@ class BillModel extends Model
{
return $this->hasMany(StoreOrderModel::class, 'bill_id', 'id');
}
/**
* 本账单关联的门店订单明细
*/
public function items(): HasMany
{
return $this->hasMany(StoreOrderItemModel::class, 'bill_id', 'id');
}
}
+76
View File
@@ -0,0 +1,76 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Modules\SystemUser\Models\SysUserModel;
/**
* 门店回筐记录模型(压筐=生成账单时自动写入并累加门店待回;回筐=门店退回手动登记并扣减待回)
*/
class ContainerReturnModel extends Model
{
use HasFactory;
/** 类型:压筐(账单生成压出,系统写入只读) */
public const int TYPE_PRESS = 1;
/** 类型:回筐(门店退回,后台手动登记) */
public const int TYPE_RETURN = 2;
/** 类型中文名 */
public const array TYPE_NAMES = [
self::TYPE_PRESS => '压筐',
self::TYPE_RETURN => '回筐',
];
protected $table = 'container_return';
protected $primaryKey = 'id';
protected $fillable = [
'store_id',
'bill_id',
'type',
'box_num',
'tray_num',
'return_date',
'operator_id',
'remark',
];
protected $casts = [
'store_id' => 'integer',
'bill_id' => 'integer',
'type' => 'integer',
'box_num' => 'integer',
'tray_num' => 'integer',
'return_date' => 'date:Y-m-d',
'operator_id' => 'integer',
'created_at' => 'datetime:Y-m-d H:i:s',
];
/**
* 所属门店(含软删除门店,保证历史记录可见)
*/
public function store(): BelongsTo
{
return $this->belongsTo(StoreModel::class, 'store_id', 'id')->withTrashed();
}
/**
* 关联账单(压筐记录)
*/
public function bill(): BelongsTo
{
return $this->belongsTo(BillModel::class, 'bill_id', 'id');
}
/**
* 操作人(后台系统用户)
*/
public function operator(): BelongsTo
{
return $this->belongsTo(SysUserModel::class, 'operator_id', 'id');
}
}
-78
View File
@@ -1,78 +0,0 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* 门店对账单明细模型(快照商品名/单价/数量/金额)
*/
class StatementItemModel extends Model
{
/** 未对账 */
public const NOT_RECONCILED = 0;
/** 已对账 */
public const RECONCILED = 1;
protected $table = 'statement_item';
protected $primaryKey = 'id';
protected $fillable = [
'statement_id',
'order_id',
'order_item_id',
'product_id',
'product_name',
'price',
'quantity',
'weight',
'amount',
'is_reconciled',
'store_remark',
];
protected $casts = [
'statement_id' => 'integer',
'order_id' => 'integer',
'order_item_id' => 'integer',
'product_id' => 'integer',
'price' => 'decimal:2',
'quantity' => 'decimal:2',
'weight' => 'decimal:3',
'amount' => 'decimal:2',
'is_reconciled' => 'integer',
];
/**
* 所属对账单
*/
public function statement(): BelongsTo
{
return $this->belongsTo(StatementModel::class, 'statement_id', 'id');
}
/**
* 来源订单
*/
public function order(): BelongsTo
{
return $this->belongsTo(StoreOrderModel::class, 'order_id', 'id');
}
/**
* 来源订单明细
*/
public function orderItem(): BelongsTo
{
return $this->belongsTo(StoreOrderItemModel::class, 'order_item_id', 'id');
}
/**
* 对账商品
*/
public function product(): BelongsTo
{
return $this->belongsTo(ProductModel::class, 'product_id', 'id');
}
}
-65
View File
@@ -1,65 +0,0 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
/**
* 门店对账单模型(门店自助生成,快照回款周期:settlement_date = period_end + payment_cycle_days
*/
class StatementModel extends Model
{
/** 状态:待对账 */
public const STATUS_PENDING = 0;
/** 状态:已对账 */
public const STATUS_RECONCILED = 1;
/** 状态:已结算 */
public const STATUS_SETTLED = 2;
protected $table = 'statement';
protected $primaryKey = 'id';
protected $fillable = [
'statement_no',
'store_id',
'period_start',
'period_end',
'total_amount',
'payment_cycle_days',
'settlement_date',
'status',
'reconciled_at',
'settled_at',
'remark',
];
protected $casts = [
'store_id' => 'integer',
'period_start' => 'date:Y-m-d',
'period_end' => 'date:Y-m-d',
'total_amount' => 'decimal:2',
'payment_cycle_days' => 'integer',
'settlement_date' => 'date:Y-m-d',
'status' => 'integer',
'reconciled_at' => 'datetime',
'settled_at' => 'datetime',
];
/**
* 所属门店
*/
public function store(): BelongsTo
{
return $this->belongsTo(StoreModel::class, 'store_id', 'id');
}
/**
* 对账单明细
*/
public function items(): HasMany
{
return $this->hasMany(StatementItemModel::class, 'statement_id', 'id');
}
}
+5 -3
View File
@@ -38,6 +38,8 @@ class StoreModel extends Model
protected $casts = [
'level_id' => 'integer',
'payment_cycle_days' => 'integer',
'pending_box_num' => 'integer',
'pending_tray_num' => 'integer',
'status' => 'integer',
];
@@ -66,10 +68,10 @@ class StoreModel extends Model
}
/**
* 门店账单
* 门店账单(采购单完成后按门店生成)
*/
public function statements(): HasMany
public function bills(): HasMany
{
return $this->hasMany(StatementModel::class, 'store_id', 'id');
return $this->hasMany(BillModel::class, 'store_id', 'id');
}
}
+2
View File
@@ -21,6 +21,7 @@ class StoreOrderItemModel extends Model
protected $fillable = [
'order_id',
'purchase_id',
'bill_id',
'store_id',
'product_id',
'category_id',
@@ -42,6 +43,7 @@ class StoreOrderItemModel extends Model
protected $casts = [
'order_id' => 'integer',
'purchase_id' => 'integer',
'bill_id' => 'integer',
'store_id' => 'integer',
'product_id' => 'integer',
'category_id' => 'integer',
-1
View File
@@ -57,7 +57,6 @@ class StoreOrderModel extends Model
protected $casts = [
'store_id' => 'integer',
'purchase_id' => 'integer',
'statement_id' => 'integer',
'bill_id' => 'integer',
'order_date' => 'date:Y-m-d',
'total_quantity' => 'integer',