<?php

namespace Admin\Model;

use Think\Model;

class PromoteGameRatioModel extends Model
{
    protected $db = 'promote_game_ratio';

    // 数据表前缀
    protected $tablePrefix = 'tab_';

    public function addLog($id)
    {
        $logSave = $this->find($id);
        if (!empty($logSave)) {
            if (empty($logSave['last_ratio_status'])) {
                $logSave['last_ratio'] = D('game')->where(array('id' => $logSave['game_id']))->getField('ratio');
                $logSave['last_ratio'] = $logSave['last_ratio'] ?? 0;
            }
            $logSave['create_time'] = $logSave['update_time'];
            unset($logSave['id']);
            unset($logSave['update_time']);
            M('promote_game_ratio_log', 'tab_')->add($logSave);
        }
    }
}