'微信支付', self::METHOD_ALIPAY => '支付宝', self::METHOD_BANK => '对公汇款', ]; /** 状态:待审核 */ public const int STATUS_PENDING = 0; /** 状态:已通过 */ public const int STATUS_APPROVED = 1; /** 状态:已拒绝 */ public const int STATUS_REJECTED = 2; /** 状态中文名 */ public const array STATUS_NAMES = [ self::STATUS_PENDING => '待审核', self::STATUS_APPROVED => '已通过', self::STATUS_REJECTED => '已拒绝', ]; protected $table = 'payment'; protected $primaryKey = 'id'; protected $fillable = [ 'payment_no', 'store_id', 'amount', 'pay_method', 'voucher_ids', 'status', 'remark', 'audited_at', 'auditor_id', 'audit_remark', ]; protected $casts = [ 'store_id' => 'integer', 'amount' => 'decimal:2', 'pay_method' => 'integer', 'status' => 'integer', 'audited_at' => 'datetime:Y-m-d H:i:s', 'auditor_id' => 'integer', 'created_at' => 'datetime:Y-m-d H:i:s', ]; /** * 汇款凭证图片ID(逗号分隔字符串 ↔ 数组) */ public function voucherIds(): Attribute { return Attribute::make( get: fn ($value) => $value === '' || $value === null ? [] : explode(',', (string) $value), set: fn ($value) => is_array($value) ? implode(',', $value) : $value, ); } /** * 汇款凭证图片URL列表(保持提交顺序) * * @return string[] */ public function voucherUrls(): array { $ids = array_map('intval', $this->voucher_ids); if ($ids === []) { return []; } $urls = []; foreach (SysFileModel::query()->whereIn('id', $ids)->get() as $file) { $urls[$file->id] = $file->preview_url; } $result = []; foreach ($ids as $id) { if (isset($urls[$id])) { $result[] = $urls[$id]; } } return $result; } /** * 所属门店(含软删除门店,保证历史记录可见) */ public function store(): BelongsTo { return $this->belongsTo(StoreModel::class, 'store_id', 'id')->withTrashed(); } /** * 本支付记录合并付款的账单 */ public function bills(): HasMany { return $this->hasMany(BillModel::class, 'payment_id', 'id'); } /** * 审核人(后台系统用户) */ public function auditor(): BelongsTo { return $this->belongsTo(SysUserModel::class, 'auditor_id', 'id'); } }