Io.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace app\common\model;
  3. /**
  4. * 出入库
  5. *
  6. * @property string $sn 编号
  7. * @property string $date 出入库日期
  8. * @property int $type 类型,1入库,2出库
  9. * @property int $repo_id 仓库id
  10. * @property int $change_type 变更原因,1出入库,2调拔,3.盘点
  11. * @property int $revert_id 回滚id
  12. * @property array<IoDetail>|\think\Collection<IoDetail> $details 出入库明细
  13. */
  14. class Io extends Base
  15. {
  16. protected $schema = [
  17. 'id' => 'int', // id
  18. 'repo_id' => 'int', // 仓库ID
  19. 'create_time' => 'datetime', // 创建时间
  20. 'update_time' => 'datetime', // 更新时间
  21. 'delete_time' => 'datetime', // 删除时间
  22. 'date' => 'date', // 出入库日期
  23. 'type' => 'tinyint', // 类型,1入库,2出库
  24. 'remark' => 'varchar', // 备注
  25. 'sn' => 'varchar', // 订单号
  26. 'admin_id' => 'int', // 操作人ID
  27. 'change_type' => 'tinyint', // 变更原因,1出入库,2调拔,3.盘点
  28. 'source' => 'varchar',
  29. 'revert_id' => 'int' // 回滚id
  30. ];
  31. /**
  32. * 入库
  33. */
  34. const TYPE_IN = 1;
  35. /**
  36. * 出库
  37. */
  38. const TYPE_OUT = 2;
  39. /**
  40. * 出入库
  41. */
  42. const CHANGE_TYPE_IO = 1;
  43. /**
  44. * 调拨
  45. */
  46. const CHANGE_TYPE_ALLOCATION = 2;
  47. /**
  48. * 盘点
  49. */
  50. const CHANGE_TYPE_CHECK = 3;
  51. const CHANGE_TYPE_MAP = [
  52. self::CHANGE_TYPE_IO => ['text' => '出入库'],
  53. self::CHANGE_TYPE_ALLOCATION => ['text' => '调拨'],
  54. self::CHANGE_TYPE_CHECK => ['text' => '盘点']
  55. ];
  56. public function getChangeTypeTextAttr($value, $data)
  57. {
  58. $index = $data['change_type'];
  59. return isset(self::CHANGE_TYPE_MAP[$index]) ? self::CHANGE_TYPE_MAP[$index]['text'] : '未知';
  60. }
  61. public function details()
  62. {
  63. return $this->hasMany(IoDetail::class);
  64. }
  65. public function repo()
  66. {
  67. return $this->belongsTo(Repo::class);
  68. }
  69. public function revert()
  70. {
  71. return $this->belongsTo(Io::class, 'revert_id', 'id');
  72. }
  73. }