123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- namespace app\common\model;
- /**
- * 出入库
- *
- * @property string $sn 编号
- * @property string $date 出入库日期
- * @property int $type 类型,1入库,2出库
- * @property int $repo_id 仓库id
- * @property int $change_type 变更原因,1出入库,2调拔,3.盘点
- * @property int $revert_id 回滚id
- * @property array<IoDetail>|\think\Collection<IoDetail> $details 出入库明细
- */
- class Io extends Base
- {
- protected $schema = [
- 'id' => 'int', // id
- 'repo_id' => 'int', // 仓库ID
- 'create_time' => 'datetime', // 创建时间
- 'update_time' => 'datetime', // 更新时间
- 'delete_time' => 'datetime', // 删除时间
- 'date' => 'date', // 出入库日期
- 'type' => 'tinyint', // 类型,1入库,2出库
- 'remark' => 'varchar', // 备注
- 'sn' => 'varchar', // 订单号
- 'admin_id' => 'int', // 操作人ID
- 'change_type' => 'tinyint', // 变更原因,1出入库,2调拔,3.盘点
- 'source' => 'varchar',
- 'revert_id' => 'int' // 回滚id
- ];
- /**
- * 入库
- */
- const TYPE_IN = 1;
- /**
- * 出库
- */
- const TYPE_OUT = 2;
-
- /**
- * 出入库
- */
- const CHANGE_TYPE_IO = 1;
- /**
- * 调拨
- */
- const CHANGE_TYPE_ALLOCATION = 2;
- /**
- * 盘点
- */
- const CHANGE_TYPE_CHECK = 3;
- const CHANGE_TYPE_MAP = [
- self::CHANGE_TYPE_IO => ['text' => '出入库'],
- self::CHANGE_TYPE_ALLOCATION => ['text' => '调拨'],
- self::CHANGE_TYPE_CHECK => ['text' => '盘点']
- ];
- public function getChangeTypeTextAttr($value, $data)
- {
- $index = $data['change_type'];
- return isset(self::CHANGE_TYPE_MAP[$index]) ? self::CHANGE_TYPE_MAP[$index]['text'] : '未知';
- }
- public function details()
- {
- return $this->hasMany(IoDetail::class);
- }
- public function repo()
- {
- return $this->belongsTo(Repo::class);
- }
- public function revert()
- {
- return $this->belongsTo(Io::class, 'revert_id', 'id');
- }
- }
|