<?php

namespace Source\Lib;

use Dever;

class Manage
{
	/**
	 * 显示信息
	 *
	 * @return mixed
	 */
	public function show($id)
	{
		$info = Dever::db('source/info')->one($id);
		$link = Dever::db('source/link')->one($id);

		return '';
	}

	public function updateCode($id, $name, $param)
	{
		$cate_id = Dever::param('cate_id', $param);
		$type = Dever::param('type', $param);
		$link_id = Dever::param('link_id', $param);
		$link = Dever::db('source/link')->one($link_id);
		if (!$link) {
			$link['link'] = Dever::url('home', 'buy');
		}

		$send['cate'] = $cate_id;
    	$send['source'] = $id;
        $send['type'] = $type;
        $send['seller'] = 1;
        $key = 'jmbuybuybuyv1';
        $param = array();
        $param['p'] = Dever::encode(Dever::json_encode($send), $key);

    	$param = http_build_query($param);
    	if (strstr($link['link'], '?')) {
    		$url = $link['link'] . '&' . $param;
    	} else {
    		$url = $link['link'] . '?' . $param;
    	}
    	

    	Dever::db('source/info')->update(array('where_id' => $id, 'code' => $url));
	}
}