<?php
/**
 * 行为管理
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author xiaogg <xiaogg@sina.cn>
 */
 
namespace Admin\Controller;
class ActionController extends BaseController {
    /**
     * 用户行为列表
     */
    public function index(){
        $map['status']    =   array('gt', -1);//获取列表数据
        $list   =   $this->lists('Action', $map);
        int_to_string($list);
        Cookie('__forward__',$_SERVER['REQUEST_URI']);// 记录当前列表页的cookie
        $this->assign('_list', $list);
        $this->meta_title = '用户行为';
        $this->display();
    }
    /**
     * 新增行为
     */
    public function addAction(){
        $this->meta_title = '新增行为';
        $this->display('editaction');
    }
    /**
     * 编辑行为
     */
    public function editAction(){
        $id = I('get.id');
        empty($id) && $this->error('参数不能为空！');
        $data = M('Action')->field(true)->find($id);
        $this->assign($data);
        $this->meta_title = '编辑行为';
        $this->display();
    }
    /**
     * 更新行为
     */
    public function saveAction(){
        $res = D('Action')->update();
        if(!$res){
            $this->error(D('Action')->getError());
        }else{
            $this->success($res['id']?'更新成功！':'新增成功！', Cookie('__forward__'));
        }
    }
    /**
     * 行为日志列表
     */
    public function actionlog(){
        $postdata=I('param.');unset($postdata['__hash__']);
        //获取列表数据
        $map['status']    =   array('gt', -1);
        if(isset($postdata['action_id']))$map['action_id']=$postdata['action_id'];
        //if(isset($postdata['keyword']))$map['mark']=array('like',"%".$postdata['keyword']."%");
        $list   =   $this->lists('ActionLog', $map);
        int_to_string($list);
        $actionlist=M('Action')->where('status=1')->field('id,name,title')->select();
        foreach($actionlist as $v){
            $actionarr[$v['id']]=$v['title']."(".$v['name'].")";
        }
        $this->assign($postdata);
        $this->assign('actionarr', $actionarr);
        $this->assign('_list', $list);
        $this->meta_title = '行为日志';
        $this->display();
    }
    /**
     * 删除日志
     * @param mixed $ids
     */
    public function remove(){exit();
        $ids=I('ids');
        empty($ids) && $this->error('参数错误！');
        if(is_array($ids)){
            $map['id'] = array('in', $ids);
        }elseif (is_numeric($ids)){
            $map['id'] = $ids;
        }
        $res = M('ActionLog')->where($map)->delete();
        if($res !== false){
            $this->success('删除成功！');
        }else {
            $this->error('删除失败！');
        }
    }
    /**
     * 查看行为日志
     */
    public function edit($id = 0){
        // empty($id) && $this->error('参数错误！');
        $info = M('ActionLog')->field(true)->find($id);
        $this->assign('info', $info);
        $this->meta_title = '查看行为日志';
        $this->display();
    }
    /**
     * 清空日志
     */
    public function clear(){exit();
        $res = M('ActionLog')->where('1=1')->delete();
        if($res !== false){
            $this->success('日志清空成功！');
        }else {
            $this->error('日志清空失败！');
        }
    }
}
?>