12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- namespace app\common\model;
- use app\common\exception\CatchException;
- use app\common\model\Good;
- use app\common\service\StockService;
- class IoDetail extends Base
- {
- protected $schema = [
- 'id' => 'int',
- 'good_id' => 'int',
- 'repo_id' => 'int',
- 'create_time' => 'datetime',
- 'update_time' => 'datetime',
- 'delete_time' => 'datetime',
- 'num' => 'float',
- 'date' => 'date',
- 'type' => 'tinyint',
- 'remark' => 'varchar',
- 'io_id' => 'int',
- 'transit_status' => 'varchar',
- 'transit_received' => 'float',
- 'transit_lost' => 'float',
- ];
-
- const TYPE_IN = 1;
-
- const TYPE_OUT = 2;
-
- const TRANSIT_STATUS_NONE = "NONE";
-
- const TRANSIT_STATUS_TRANSIT = 'TRANSIT';
-
- const TRANSIT_STATUS_COMPLETED = 'COMPLETED';
- const TRANSIT_STATUS_MAP = [
- self::TRANSIT_STATUS_NONE => ['text' => '非在途/借出'],
- self::TRANSIT_STATUS_TRANSIT => ['text' => '在途/借出'],
- self::TRANSIT_STATUS_COMPLETED => ['text' => '非在途/借出']
- ];
- public function io()
- {
- return $this->belongsTo(Io::class);
- }
- public function repo()
- {
- return $this->belongsTo(Repo::class);
- }
- public function good()
- {
- return $this->belongsTo(Good::class);
- }
- public function getTransitStatusTextAttr($value, $data)
- {
- return self::TRANSIT_STATUS_MAP[$data['transit_status']]['text'];
- }
- public static function onAfterInsert($detail)
- {
- static $service;
- if (!$service) {
- $service = (new StockService(app()))->exceptionClass(CatchException::class);
- }
- $service->chengeStockTrans($detail->repo, $detail->good, $detail->num);
- }
- }
|