<?php

namespace app\admin\model;

use think\Model;

/**
 * PayApply
 */
class PayApply extends Model
{
    // 表名
    protected $name = 'pay_apply';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = true;

    protected static function onBeforeInsert($model)
    {
        $pk         = $model->getPk();
        $model->$pk = \app\common\library\SnowFlake::generateParticle();
    }

    public function getIdAttr($value): string
    {
        return (string)$value;
    }

    public function getPayAmountAttr($value): float
    {
        return (float)$value;
    }

    public function getImagesAttr($value): array
    {
        if ($value === '' || $value === null) return [];
        if (!is_array($value)) {
            return explode(',', $value);
        }
        return $value;
    }

    public function setImagesAttr($value): string
    {
        return is_array($value) ? implode(',', $value) : $value;
    }

    public function reqOrder()
    {
        return $this->belongsTo(\app\admin\model\ReqOrder::class, 'req_id', 'id');
    }
}