113 行
3.4 KiB
PHP
可执行文件
113 行
3.4 KiB
PHP
可执行文件
<?php
|
|
namespace Super\Controller;
|
|
use Think\Controller;
|
|
|
|
class TemplateController extends SubBaseController
|
|
{
|
|
public function index()
|
|
{
|
|
$user = session('super_userinfo');
|
|
//$templateid = M('retail_admin')->where(array('id'=>$user['id']))->getField('templateid');
|
|
$templateinfo = M('retail_template')->where(array('status'=>1))->select();
|
|
if($templateinfo)
|
|
{
|
|
foreach ($templateinfo as $key=>&$val)
|
|
{
|
|
$val['img'] = C('myhttp').$val['img'];
|
|
}
|
|
}
|
|
//$this->assign('templateid',$templateid);
|
|
$this->assign('templateinfo',$templateinfo);
|
|
$this->display();
|
|
}
|
|
public function addtemplate()
|
|
{
|
|
$templateid = I('get.id');
|
|
if($templateid)
|
|
{
|
|
$templateinfo = M('retail_template')->where(array('id'=>$templateid))->find();
|
|
$this->assign('templateinfo',$templateinfo);
|
|
}
|
|
$this->display();
|
|
}
|
|
public function addact()
|
|
{
|
|
if(IS_POST)
|
|
{
|
|
$data = I('post.');
|
|
if($data['id'])
|
|
{
|
|
//修改
|
|
$add = M('retail_template')->where(array('id'=>$data['id']))->save($data);
|
|
}else
|
|
{
|
|
$data['addtime'] = time();
|
|
$add = M('retail_template')->add($data);
|
|
}
|
|
if($add)
|
|
{
|
|
$res['status'] = 1;
|
|
$res['msg'] = '操作成功';
|
|
}else
|
|
{
|
|
$res['status'] = 0;
|
|
$res['msg'] = '操作失败';
|
|
}
|
|
$this->ajaxReturn($res);
|
|
}
|
|
}
|
|
public function upload()
|
|
{
|
|
$upload = new \Think\Upload (); // 实例化上传类
|
|
$upload->maxSize = 5242880 / 2; // 设置附件上传大小5M/5
|
|
$upload->exts = array(
|
|
'jpg',
|
|
'png',
|
|
'jpeg',
|
|
); // 设置附件上传类型
|
|
$upload->rootPath = 'Uploads'; // 设置附件上传根目录
|
|
$upload->savePath = '/template/'; // 设置附件上传(子)目录
|
|
$upload->saveName = array(
|
|
'uniqid',
|
|
array('', true)
|
|
);
|
|
// 上传文件
|
|
$info = $upload->upload();
|
|
if (!empty($info['file']['savename'])) {
|
|
$path = "/" . $upload->rootPath . $info['file']['savepath'] . $info['file']['savename'];
|
|
$rt['status'] = 1;
|
|
$rt['path'] = $path;
|
|
}else{
|
|
$rt['status'] = 0;
|
|
$rt['msg'] = '图片上传失败';
|
|
}
|
|
$this->ajaxReturn($rt);
|
|
}
|
|
//删除模板
|
|
public function deletemplate()
|
|
{
|
|
if(IS_POST)
|
|
{
|
|
$id = I('post.id');
|
|
$find = M('retail_admin')->where(array('templateid'=>$id))->find();
|
|
if($find)
|
|
{
|
|
$res['status'] = 0;
|
|
$res['msg'] = '已有合伙人使用,拒绝删除';
|
|
}else
|
|
{
|
|
$del = M('retail_template')->where(array('id'=>$id))->delete();
|
|
if($del)
|
|
{
|
|
$res['status'] = 1;
|
|
$res['msg'] = '操作成功';
|
|
}else
|
|
{
|
|
$res['status'] = 0;
|
|
$res['msg'] = '操作失败';
|
|
}
|
|
}
|
|
$this->ajaxReturn($res);
|
|
}
|
|
}
|
|
} |