<?php namespace Content\Lib;
use Dever;
use Place;
class Info
{
    # 获取字段
    public function getCol()
    {
        return 'id,name,info,pic,price,cdate';
    }

    # 获取基本信息
    public function getInfo($info)
    {
        return $info;
    }

    public function submit($info, $type = 'price', $state = false)
    {
        $result = $info[$type];
        $password = Dever::input('password');
        if ($password) {
            if ($info['password'] && $password == $info['password']) {
                $result['status'] = 1;
            } else {
                Dever::error('密码输入错误');
            }
        }
        if ($result['status'] == 1) {
            if (isset($id)) {
                $result['value'] = Dever::db('value', 'content')->find(array('info_id' => $info['id'], 'id' => $id));
            } else {
                $result['value'] = Dever::db('value', 'content')->select(array('info_id' => $info['id']));
                if ($result['value']) {
                    $param['p'] = Dever::input('p');
                    $param['t'] = Dever::input('t');
                    foreach ($result['value'] as &$v) {
                        if ($v['file']) {
                            $param['g'] = \Dever\Helper\Secure::encode($v['id']);
                            $v['file'] = Dever::url('place/down.act', $param);
                        }
                    }
                }
            }
        } elseif ($result['status'] == 2) {
            $result['id'] = $info['id'];
            $result['name'] = $info['name'];
            $result['button'] = '购买';
        } elseif ($result['status'] == 3) {
            $result['text'] = '专享内容，升级会员可下载';
        }
        return $result;
    }
}