<?php

namespace Agent\Lib;

use Dever;

# 记录日志
class Level_log
{

    # 记录日志
    public function up($mid, $order_id, $old_level, $new_level, $new_sell, $sell)
    {
    	$data['mid'] = $mid;
    	$data['order_id'] = $order_id;
    	$data['old_level'] = $old_level;
    	$data['new_level'] = $new_level;
    	$data['new_sell'] = $new_sell;
    	$data['sell'] = $sell;
    	$data['order_num'] = $this->getOrderId();

    	$id = Dever::db('agent/member_level_log')->insert($data);

    	return $id;
    }

    /**
     * 生成日志订单号
     *
     * @return mixed
     */
    public function getOrderId()
    {
        $where['order_num'] = Dever::order('L');
        $state = Dever::db('agent/member_level_log')->one($where);
        if (!$state) {
            return $where['order_num'];
        } else {
            return $this->getOrderId();
        }
    }
}