<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
public function index(){
R("Login/index");
$goods = M('goods')->select();
$this->assign('goods',$goods);
$this->display();
}
public function me(){
R("Login/index");
$user = M("user"); // 实例化User对象
$where = array('userid'=>session('userid'));
$result = $user->where($where)->find();
$this->assign('id',$result['id']);
$this->assign('name',$result['nickname']);
$this->assign('url',$result['headimgurl']);
$this->display();
}
public function fabu(){
// R("Login/index");
$this->display();
}
function addgoods(){
// R("Login/index");
$this->upload();die;
// dump($_FILES);die;
$data['name'] = I('name');
$data['phone'] = I('phone');
$data['address'] = I('address');
$data['type'] = I('type');
$data['cate'] = I('cate');
$data['textarea'] = I('textarea');
$data['userid'] = S('user_id');
$data['create_time'] = date("y-m-d",time());
if(empty(I('name'))||empty(I('phone'))||empty(I('type'))||empty(I('address')||empty(I('cate'))||empty(I('textarea')))){
redirect('fabu.html');
}else{
$goods = M("goods"); // 实例化User对象
$where = array('userid'=>S('user_id'));
@header("Content-Type:text/html;charset=utf-8");
if($goods->where($where)->count()<1){
$result=$goods->add($data);
if($result){
$this->show_msg('添加数据成功!','index.html');
}
}else{
if($goods->where(array('userid'=>S('user_id'),'type'=>'1'))){
$result=$goods->add($data);
if($result){
$this->show_msg('添加数据成功!','index.html');
}
}else{
$this->show_msg('普通用户只能发布一条信息,如果想再发,请联系客服升级成VIP','ewm.html');
}
}
}
}
public function mypublish(){
$goods = M("goods"); // 实例化User对象
$where = array('userid'=>S('user_id'));
$result = $goods->where($where)->select();
$this->assign('goods',$result);
$this->display();
}
public function delmygoods(){
$goods = M("goods"); // 实例化User对象
$where = array('userid'=>S('user_id'),'id'=>I('goodsid'));
$result = $goods->where($where)->delete();
$this->show_msg('删除成功','../../me.html');
}
public function ewm(){
$this->display();
}
public function upload(){
$upload = new \Think\Upload();// 实例化上传类
$upload->maxSize = 3145728 ;// 设置附件上传大小
$upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
$upload->rootPath = './upload/'; // 设置附件上传根目录
$upload->savePath = ''; // 设置附件上传(子)目录
// 上传文件
$info = $upload->upload();
if(!$info) {// 上传错误提示错误信息
$this->error($upload->getError());
}else{// 上传成功 获取上传文件信息
foreach($info as $file){
echo $file['savepath'].$file['savename'].",";
}
}
}
public function show_msg($msg, $url){
@header("Content-Type:text/html;charset=utf-8");
echo '<script type="text/javascript">';
echo 'alert("'.$msg.'");';
if(!empty($url)){
echo 'location.href = "'.$url.'"';
}else{
echo 'history.go(-1);';
}
echo '</script>';
exit;
}
}
评论0
最新资源