| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 | <?phpnamespace app\common\model;use app\common\exception\CatchException;use app\common\model\Good;use app\common\service\StockService;/** *  * @property int $good_id 物品ID * @property int $repo_id 仓库ID * @property number $num 数量,正数增加,负数减少 * @property int $type 类型,1入库,2出库 * @property string $transit_status 在途状态:"TRANSIT" 在途/借出 “COMPLETED” 完成/结束 ""/"NONE" 非在途/借出 * @property number $transit_received 在途到达/归还数量 * @property number $transit_lost 在途遗失数 */class IoDetail extends Base{    protected $schema = [        'id'     => 'int',       // id        'good_id'        => 'int',       // 物品ID        'repo_id'        => 'int',       // 仓库ID        'create_time'    => 'datetime',  // 创建时间        'update_time'    => 'datetime',  // 更新时间        'delete_time'    => 'datetime',  // 删除时间        'num'    => 'float',     // 数量,正数增加,负数减少        'date'   => 'date',      // 出入库日期        'type'   => 'tinyint',   // 类型,1入库,2出库        'remark'         => 'varchar',   // 备注        'io_id'  => 'int',       // 出入库订单ID        'transit_status'         => 'varchar',   // 在途状态:"TRANSIT" 在途/借出 “COMPLETED” 完成/结束 ""/"NONE" 非在途/借出        '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);    }}
 |