IoDetail.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace app\common\model;
  3. use app\common\exception\CatchException;
  4. use app\common\model\Good;
  5. use app\common\service\StockService;
  6. /**
  7. *
  8. * @property int $good_id 物品ID
  9. * @property int $repo_id 仓库ID
  10. * @property number $num 数量,正数增加,负数减少
  11. * @property int $type 类型,1入库,2出库
  12. * @property string $transit_status 在途状态:"TRANSIT" 在途/借出 “COMPLETED” 完成/结束 ""/"NONE" 非在途/借出
  13. * @property number $transit_received 在途到达/归还数量
  14. * @property number $transit_lost 在途遗失数
  15. */
  16. class IoDetail extends Base
  17. {
  18. protected $schema = [
  19. 'id' => 'int', // id
  20. 'good_id' => 'int', // 物品ID
  21. 'repo_id' => 'int', // 仓库ID
  22. 'create_time' => 'datetime', // 创建时间
  23. 'update_time' => 'datetime', // 更新时间
  24. 'delete_time' => 'datetime', // 删除时间
  25. 'num' => 'float', // 数量,正数增加,负数减少
  26. 'date' => 'date', // 出入库日期
  27. 'type' => 'tinyint', // 类型,1入库,2出库
  28. 'remark' => 'varchar', // 备注
  29. 'io_id' => 'int', // 出入库订单ID
  30. 'transit_status' => 'varchar', // 在途状态:"TRANSIT" 在途/借出 “COMPLETED” 完成/结束 ""/"NONE" 非在途/借出
  31. 'transit_received' => 'float', // 在途到达/归还数量
  32. 'transit_lost' => 'float', // 在途遗失数
  33. ];
  34. /**
  35. * 入库
  36. */
  37. const TYPE_IN = 1;
  38. /**
  39. * 出库
  40. */
  41. const TYPE_OUT = 2;
  42. /**
  43. * 非在途/借出
  44. */
  45. const TRANSIT_STATUS_NONE = "NONE";
  46. /**
  47. * 在途/借出
  48. */
  49. const TRANSIT_STATUS_TRANSIT = 'TRANSIT';
  50. /**
  51. * 完成/结束
  52. */
  53. const TRANSIT_STATUS_COMPLETED = 'COMPLETED';
  54. const TRANSIT_STATUS_MAP = [
  55. self::TRANSIT_STATUS_NONE => ['text' => '非在途/借出'],
  56. self::TRANSIT_STATUS_TRANSIT => ['text' => '在途/借出'],
  57. self::TRANSIT_STATUS_COMPLETED => ['text' => '非在途/借出']
  58. ];
  59. public function io()
  60. {
  61. return $this->belongsTo(Io::class);
  62. }
  63. public function repo()
  64. {
  65. return $this->belongsTo(Repo::class);
  66. }
  67. public function good()
  68. {
  69. return $this->belongsTo(Good::class);
  70. }
  71. public function getTransitStatusTextAttr($value, $data)
  72. {
  73. return self::TRANSIT_STATUS_MAP[$data['transit_status']]['text'];
  74. }
  75. public static function onAfterInsert($detail)
  76. {
  77. static $service;
  78. if (!$service) {
  79. $service = (new StockService(app()))->exceptionClass(CatchException::class);
  80. }
  81. $service->chengeStockTrans($detail->repo, $detail->good, $detail->num);
  82. }
  83. }