<?php

declare(strict_types=1);

namespace app\common\model;

use app\common\model\traits\TimestampInteger;
use support\think\Model;

class MallPointsLog extends Model
{
    use TimestampInteger;

    protected string $table = 'mall_points_log';
    protected string $pk = 'id';
    protected bool $autoWriteTimestamp = true;
    protected bool $updateTime = false;

    /**
     * 展示备注：兼容历史数据未替换的 %s 占位符
     */
    public function getMemoAttr($value, $row): string
    {
        $memo = strval($value ?? '');
        if ($memo === '' || !str_contains($memo, '%s')) {
            return $memo;
        }
        $points = abs(intval(is_array($row) ? ($row['score_value'] ?? 0) : ($row->score_value ?? 0)));

        return sprintf($memo, $points);
    }
}
