<?php

namespace app\models\system;

use crmeb\traits\ModelTrait;
use crmeb\basic\BaseModel;

class SystemPool extends BaseModel
{
    /**
     * 数据表主键
     * @var string
     */
    protected $pk = 'id';

    /**
     * 模型名称
     * @var string
     */
    protected $name = 'system_pool';

    use ModelTrait;


    /**
     * 记录变更
     * 
     * @amount: 变更金额
     * @admin_id: 操作员ID
     * @activity: 操作的活动
     * @result: 变更后金额
     */
    public static function incrby(float $amount, int $admin_id, string $activity, float $result)
    {
        return self::create([
            'adminid' => $admin_id,
            'activity' => $activity,
            'delta' => $amount,
            'pool' => $result,
            'add_time' => time(),
        ]);
    }

    public static function getList($page, $limit)
    {
        return self::field('adminid, activity, delta, pool, FROM_UNIXTIME(add_time,"%Y-%m-%d") as add_time')
            ->order('add_time desc')
            ->page(intval($page), intval($limit))
            ->select()->toArray();
    }
}