<?php

namespace Journal\Src;

use Dever;

class Api
{
	public function data()
	{
		return Dever::db('journal/info')->state();
	}

	public function ding($data)
    {
        if (isset($data['num_add_ding']) && isset($data['num_ratio_ding'])) {

            if ($data['buy'] == 1 && !$data['num_ding']) {
                $stat = Dever::db('stat/journal')->getNumByJournal(array('journal_id' => $data['id']));
                if (!$stat) {
                    $stat['buy_num'] = 0;
                }

                if (!$stat['buy_num']) {
                    $stat['buy_num'] = 0;
                }
                $data['num_ding'] = $stat['buy_num'];
            }
            
            $data['num_ding'] = $data['num_ding'] + $data['num_up'];
            $data['buy_num'] = $data['num_ding'];
            $data['num_ding'] = round(($data['num_ding']+$data['num_add_ding'])*$data['num_ratio_ding']);
        }

        return $data;
    }
}