<?php namespace Place_order\Lib\Source;
use Dever;
use Place;
class Log
{
    public function up($type, $type_id, $order_id, $desc)
    {
        $update['type'] = $type;
        $update['type_id'] = $type_id;
        $update['order_id'] = $order_id;
        $update['desc'] = $desc;
        Dever::db('source_log', 'place_order')->insert($update);
    }

    # 获取日志信息
    public function getList($order_id)
    {
        $log = Dever::db('source_log', 'place_order')->select(array('order_id' => $order_id));
        if ($log) {
            foreach ($log as &$v) {
                $v = $this->getInfo($v);
            }
        }
        return $log;
    }

    # 获取日志信息
    public function getInfo($info)
    {
        if ($info['type'] == 1) {
            $user = Dever::db('info', 'place_user')->find($info['type_id']);
        } elseif ($info['type'] == 2) {
            $user = Dever::db('user', 'sector')->find($info['type_id']);
        } elseif ($info['type'] == 3) {
            $user = Dever::db('supplier', 'place')->find($info['type_id']);
        } else {
            $user['name'] = $user['mobile'] = '-';
        }
        $info['type'] = Dever::db('source_log', 'place_order')->value('type', $info);
        $info['name'] = $user['name'];
        $info['mobile'] = $user['mobile'];
        $info['cdate_str'] = date('Y-m-d H:i:s', $info['cdate']);
        return $info;
    }
}