...
|
...
|
@@ -13,6 +13,7 @@ use Common\Controller\AdminbaseController; |
|
|
class SuccessorController extends AdminbaseController {
|
|
|
|
|
|
protected $successor_model;
|
|
|
protected $product_model;
|
|
|
|
|
|
function _initialize() {
|
|
|
parent::_initialize();
|
...
|
...
|
@@ -26,49 +27,9 @@ class SuccessorController extends AdminbaseController { |
|
|
$this->display();
|
|
|
}
|
|
|
|
|
|
// 传承人作品列表
|
|
|
public function product(){
|
|
|
if(I('get.id',0,'intval')) {
|
|
|
$this->assign('id', I('get.id'));
|
|
|
$this->assign('product', json_decode($this->successor_model->getProduct(I('get.id'))));
|
|
|
$this->display();
|
|
|
} else {
|
|
|
$this->error("非法操作!");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 传承人作品添加
|
|
|
public function add_product_post() {
|
|
|
if (IS_POST) {
|
|
|
$id = I('post.id',0,'intval');
|
|
|
if(!$id) {
|
|
|
$this->error("参数错误");
|
|
|
}
|
|
|
$info['name'] = I('post.name');
|
|
|
$info['thumb'] = I('post.thumb');
|
|
|
$info['description'] = I('post.description');
|
|
|
$info['href'] = I('post.href');
|
|
|
if(!$info['name']) {
|
|
|
$this->error("作品名称必填");
|
|
|
}
|
|
|
if(!$info['thumb']) {
|
|
|
$this->error("作品图片必填");
|
|
|
}
|
|
|
if(!$info['description']) {
|
|
|
$this->error("作品描述必填");
|
|
|
}
|
|
|
$result=$this->exam_model->where(array('id'=>$id))->save($info);
|
|
|
if ($result) {
|
|
|
$this->success("添加成功!");
|
|
|
} else {
|
|
|
$this->error("添加失败!");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 传承人添加
|
|
|
public function add(){
|
|
|
$this->_getTermTree();
|
|
|
$this->_getProductTree();
|
|
|
$this->assign('sex', array('1'=>'男', '2'=>'女'));
|
|
|
$this->assign('level', array('国家级', '省市级', '地区及', '县级'));
|
|
|
$this->assign('region', M('Region')->select());
|
...
|
...
|
@@ -79,28 +40,17 @@ class SuccessorController extends AdminbaseController { |
|
|
// 传承人添加提交
|
|
|
public function add_post(){
|
|
|
if (IS_POST) {
|
|
|
if(empty($_POST['term'])){
|
|
|
$this->error("请至少选择一个分类!");
|
|
|
if(empty($_POST['post']['sort_id'])){
|
|
|
$this->error("请选择一个分类!");
|
|
|
}
|
|
|
if(!empty($_POST['photos_alt']) && !empty($_POST['photos_url'])){
|
|
|
foreach ($_POST['photos_url'] as $key=>$url){
|
|
|
$photourl=sp_asset_relative_url($url);
|
|
|
$_POST['smeta']['photo'][]=array("url"=>$photourl,"alt"=>$_POST['photos_alt'][$key]);
|
|
|
}
|
|
|
$successor=I("post.post");
|
|
|
$successor['content']=htmlspecialchars_decode($successor['content']);
|
|
|
$successor['ctime'] = time();
|
|
|
if(!$this->successor_model->create($successor)){
|
|
|
$this->error($this->successor_model->getError());
|
|
|
}
|
|
|
$_POST['smeta']['thumb'] = sp_asset_relative_url($_POST['smeta']['thumb']);
|
|
|
|
|
|
$_POST['post']['post_modified']=date("Y-m-d H:i:s",time());
|
|
|
$_POST['post']['post_author']=get_current_admin_id();
|
|
|
$article=I("post.post");
|
|
|
$article['smeta']=json_encode($_POST['smeta']);
|
|
|
$article['post_content']=htmlspecialchars_decode($article['post_content']);
|
|
|
$result=$this->posts_model->add($article);
|
|
|
$result=$this->successor_model->add($successor);
|
|
|
if ($result) {
|
|
|
foreach ($_POST['term'] as $mterm_id){
|
|
|
$this->term_relationships_model->add(array("term_id"=>intval($mterm_id),"object_id"=>$result));
|
|
|
}
|
|
|
|
|
|
$this->success("添加成功!");
|
|
|
} else {
|
|
|
$this->error("添加失败!");
|
...
|
...
|
@@ -113,52 +63,38 @@ class SuccessorController extends AdminbaseController { |
|
|
public function edit(){
|
|
|
$id= I("get.id",0,'intval');
|
|
|
|
|
|
$term_relationship = M('TermRelationships')->where(array("object_id"=>$id,"status"=>1))->getField("term_id",true);
|
|
|
$this->_getTermTree($term_relationship);
|
|
|
$terms=$this->terms_model->select();
|
|
|
$post=$this->posts_model->where("id=$id")->find();
|
|
|
$this->assign("post",$post);
|
|
|
$post=$this->successor_model->where("id=$id")->find();
|
|
|
$product_id = M('Product')->where(array("id"=>$post['sort_id'],"is_del"=>0))->getField("id", true);
|
|
|
$this->_getProductTree($product_id);
|
|
|
$this->assign('info',$post);
|
|
|
$this->assign("smeta",json_decode($post['smeta'],true));
|
|
|
$this->assign("terms",$terms);
|
|
|
$this->assign("term",$term_relationship);
|
|
|
$this->assign('sex', array('1'=>'男', '2'=>'女'));
|
|
|
$this->assign('level', array('国家级', '省市级', '地区及', '县级'));
|
|
|
$this->assign('region', M('Region')->select());
|
|
|
$this->assign('nation', M('Nation')->select());
|
|
|
$this->display();
|
|
|
}
|
|
|
|
|
|
// 传承人编辑提交
|
|
|
public function edit_post(){
|
|
|
if (IS_POST) {
|
|
|
if(empty($_POST['term'])){
|
|
|
if(empty($_POST['post']['sort_id'])){
|
|
|
$this->error("请至少选择一个分类!");
|
|
|
}
|
|
|
$post_id=intval($_POST['post']['id']);
|
|
|
|
|
|
$this->term_relationships_model->where(array("object_id"=>$post_id,"term_id"=>array("not in",implode(",", $_POST['term']))))->delete();
|
|
|
foreach ($_POST['term'] as $mterm_id){
|
|
|
$find_term_relationship=$this->term_relationships_model->where(array("object_id"=>$post_id,"term_id"=>$mterm_id))->count();
|
|
|
if(empty($find_term_relationship)){
|
|
|
$this->term_relationships_model->add(array("term_id"=>intval($mterm_id),"object_id"=>$post_id));
|
|
|
}else{
|
|
|
$this->term_relationships_model->where(array("object_id"=>$post_id,"term_id"=>$mterm_id))->save(array("status"=>1));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if(!empty($_POST['photos_alt']) && !empty($_POST['photos_url'])){
|
|
|
foreach ($_POST['photos_url'] as $key=>$url){
|
|
|
$photourl=sp_asset_relative_url($url);
|
|
|
$_POST['smeta']['photo'][]=array("url"=>$photourl,"alt"=>$_POST['photos_alt'][$key]);
|
|
|
}
|
|
|
$id=intval(I('post.id'));
|
|
|
|
|
|
$successor=I("post.post");
|
|
|
$successor['content']=htmlspecialchars_decode($successor['content']);
|
|
|
$successor['ctime'] = time();
|
|
|
$successor['utime'] = time();
|
|
|
if(!$this->successor_model->create($successor)){
|
|
|
$this->error($this->successor_model->getError());
|
|
|
}
|
|
|
$_POST['smeta']['thumb'] = sp_asset_relative_url($_POST['smeta']['thumb']);
|
|
|
unset($_POST['post']['post_author']);
|
|
|
$_POST['post']['post_modified']=date("Y-m-d H:i:s",time());
|
|
|
$article=I("post.post");
|
|
|
$article['smeta']=json_encode($_POST['smeta']);
|
|
|
$article['post_content']=htmlspecialchars_decode($article['post_content']);
|
|
|
$result=$this->posts_model->save($article);
|
|
|
if ($result!==false) {
|
|
|
$this->success("保存成功!");
|
|
|
$result=$this->successor_model->where(array('id'=>$id))->save($successor);
|
|
|
if ($result) {
|
|
|
$this->success("修改成功!");
|
|
|
} else {
|
|
|
$this->error("保存失败!");
|
|
|
$this->error("修改失败!");
|
|
|
}
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -201,7 +137,7 @@ class SuccessorController extends AdminbaseController { |
|
|
$page = $this->page($count, 20);
|
|
|
|
|
|
$posts = $this->successor_model
|
|
|
->field('s.*,p.name')
|
|
|
->field('s.*,p.name as pname')
|
|
|
->alias("s")
|
|
|
->join("__PRODUCT__ p ON s.sort_id = p.id")
|
|
|
->where($where)
|
...
|
...
|
@@ -215,7 +151,7 @@ class SuccessorController extends AdminbaseController { |
|
|
}
|
|
|
|
|
|
// 获取商品分类树结构
|
|
|
private function _getTermTree($term=array()){
|
|
|
private function _getProductTree($product=array()){
|
|
|
$result = $this->product_model->order(array("listorder"=>"asc"))->select();
|
|
|
|
|
|
$tree = new \Tree();
|
...
|
...
|
@@ -226,8 +162,8 @@ class SuccessorController extends AdminbaseController { |
|
|
$r['visit'] = "<a href='#'>访问</a>";
|
|
|
$r['taxonomys'] = $this->taxonomys[$r['taxonomy']];
|
|
|
$r['parentid']=$r['parent'];
|
|
|
$r['selected']=in_array($r['id'], $term)?"selected":"";
|
|
|
$r['checked'] =in_array($r['id'], $term)?"checked":"";
|
|
|
$r['selected']=in_array($r['id'], $product)?"selected":"";
|
|
|
$r['checked'] =in_array($r['id'], $product)?"checked":"";
|
|
|
$array[] = $r;
|
|
|
}
|
|
|
|
...
|
...
|
|