colly_wyx
2018-03-30 5b00b28782f2c773aa9b63ac61584b70a366526c
更新
8 files added
2 files modified
890 ■■■■■ changed files
application/library/FileUpload.php 239 ●●●●● patch | view | raw | blame | history
application/library/Service/Ad.php 71 ●●●●● patch | view | raw | blame | history
application/library/Service/Daily.php 52 ●●●●● patch | view | raw | blame | history
application/library/Service/User.php 2 ●●● patch | view | raw | blame | history
application/models/Ad.php 7 ●●●●● patch | view | raw | blame | history
application/models/Hourly.php 7 ●●●●● patch | view | raw | blame | history
application/modules/Ad/controllers/Ad.php 142 ●●●●● patch | view | raw | blame | history
application/modules/Ad/views/ad/add.phtml 102 ●●●●● patch | view | raw | blame | history
application/modules/Ad/views/ad/edit.phtml 104 ●●●●● patch | view | raw | blame | history
application/modules/Ad/views/ad/index.phtml 164 ●●●●● patch | view | raw | blame | history
application/library/FileUpload.php
New file
@@ -0,0 +1,239 @@
<?php
  /**
    file: fileupload.class.php 文件上传类FileUpload
    本类的实例对象用于处理上传文件,可以上传一个文件,也可同时处理多个文件上传
  */
class FileUpload {
    private $path = "./uploads";          //上传文件保存的路径
    private $allowtype = array('jpg','gif','png'); //设置限制上传文件的类型
    private $maxsize = 1000000;           //限制文件上传大小(字节)
    private $israndname = true;           //设置是否随机重命名文件, false不随机
    private $originName;              //源文件名
    private $tmpFileName;              //临时文件名
    private $fileType;               //文件类型(文件后缀)
    private $fileSize;               //文件大小
    private $newFileName;              //新文件名
    private $errorNum = 0;             //错误号
    private $errorMess="";             //错误报告消息
    /**
     * 用于设置成员属性($path, $allowtype,$maxsize, $israndname)
     * 可以通过连贯操作一次设置多个属性值
     *@param  string $key  成员属性名(不区分大小写)
     *@param  mixed  $val  为成员属性设置的值
     *@return  object     返回自己对象$this,可以用于连贯操作
     */
    function set($key, $val){
      $key = strtolower($key);
      if( array_key_exists( $key, get_class_vars(get_class($this) ) ) ){
        $this->setOption($key, $val);
      }
      return $this;
    }
    /**
     * 调用该方法上传文件
     * @param  string $fileFile  上传文件的表单名称
     * @return bool        如果上传成功返回数true
     */
    function upload($fileField) {
      $return = true;
      /* 检查文件路径是滞合法 */
      if( !$this->checkFilePath() ) {
        $this->errorMess = $this->getError();
        return false;
      }
      /* 将文件上传的信息取出赋给变量 */
      $name = $_FILES[$fileField]['name']; //上传文件的文件名 'Chrysanthemum.jpg'
      $tmp_name = $_FILES[$fileField]['tmp_name']; //服务器端临时文件存放路径 'D:\wamp\tmp\php71E6.tmp'
      $size = $_FILES[$fileField]['size']; //上传文件的大小 879394   858 KB (879,394 字节)
      $error = $_FILES[$fileField]['error']; //错误信息 0
      /* 如果是多个文件上传则$file["name"]会是一个数组 */
      if(is_Array($name)){
        $errors=array();
        /*多个文件上传则循环处理 , 这个循环只有检查上传文件的作用,并没有真正上传 */
        for($i = 0; $i < count($name); $i++){
          /*设置文件信息 */
          if($this->setFiles($name[$i],$tmp_name[$i],$size[$i],$error[$i] )) {
            if(!$this->checkFileSize() || !$this->checkFileType()){
              $errors[] = $this->getError();
              $return=false;
            }
          }else{
            $errors[] = $this->getError();
            $return=false;
          }
          /* 如果有问题,则重新初使化属性 */
          if(!$return)
            $this->setFiles();
        }
        if($return){
          /* 存放所有上传后文件名的变量数组 */
          $fileNames = array();
          /* 如果上传的多个文件都是合法的,则通过循环向服务器上传文件 */
          for($i = 0; $i < count($name); $i++){
            if($this->setFiles($name[$i], $tmp_name[$i], $size[$i], $error[$i] )) {
              $this->setNewFileName();
              if(!$this->copyFile()){
                $errors[] = $this->getError();
                $return = false;
              }
              $fileNames[] = $this->newFileName;
            }
          }
          $this->newFileName = $fileNames;
        }
        $this->errorMess = $errors;
        return $return;
      /*上传单个文件处理方法*/
      } else {
        /* 设置文件信息 */
        if($this->setFiles($name,$tmp_name,$size,$error)) {
          /* 上传之前先检查一下大小和类型 */
          if($this->checkFileSize() && $this->checkFileType()){
            /* 为上传文件设置新文件名 */
            $this->setNewFileName();
            /* 上传文件  返回0为成功, 小于0都为错误 */
            if($this->copyFile()){
              return true;
            }else{
              $return=false;
            }
          }else{
            $return=false;
          }
        } else {
          $return=false;
        }
        //如果$return为false, 则出错,将错误信息保存在属性errorMess中
        if(!$return)
          $this->errorMess=$this->getError();
        return $return;
      }
    }
    /**
     * 获取上传后的文件名称
     * @param  void   没有参数
     * @return string 上传后,新文件的名称, 如果是多文件上传返回数组
     */
    public function getFileName(){
      return $this->newFileName;
    }
    /**
     * 上传失败后,调用该方法则返回,上传出错信息
     * @param  void   没有参数
     * @return string  返回上传文件出错的信息报告,如果是多文件上传返回数组
     */
    public function getErrorMsg(){
      return $this->errorMess;
    }
    /* 设置上传出错信息 */
    private function getError() {
      $str = "上传文件<font color='red'>{$this->originName}</font>时出错 : ";
      switch ($this->errorNum) {
        case 4: $str .= "没有文件被上传"; break;
        case 3: $str .= "文件只有部分被上传"; break;
        case 2: $str .= "上传文件的大小超过了HTML表单中MAX_FILE_SIZE选项指定的值"; break;
        case 1: $str .= "上传的文件超过了php.ini中upload_max_filesize选项限制的值"; break;
        case -1: $str .= "未允许类型"; break;
        case -2: $str .= "文件过大,上传的文件不能超过{$this->maxsize}个字节"; break;
        case -3: $str .= "上传失败"; break;
        case -4: $str .= "建立存放上传文件目录失败,请重新指定上传目录"; break;
        case -5: $str .= "必须指定上传文件的路径"; break;
        default: $str .= "未知错误";
      }
      return $str.'<br>';
    }
    /* 设置和$_FILES有关的内容 */
    private function setFiles($name="", $tmp_name="", $size=0, $error=0) {
      $this->setOption('errorNum', $error);
      if($error)
        return false;
      $this->setOption('originName', $name);
      $this->setOption('tmpFileName',$tmp_name);
      $aryStr = explode(".", $name);
      $this->setOption('fileType', strtolower($aryStr[count($aryStr)-1]));
      $this->setOption('fileSize', $size);
      return true;
    }
    /* 为单个成员属性设置值 */
    private function setOption($key, $val) {
      $this->$key = $val;
    }
    /* 设置上传后的文件名称 */
    private function setNewFileName() {
      if ($this->israndname) {
        $this->setOption('newFileName', $this->proRandName());
      } else{
        $this->setOption('newFileName', $this->originName);
      }
    }
    /* 检查上传的文件是否是合法的类型 */
    private function checkFileType() {
      if (in_array(strtolower($this->fileType), $this->allowtype)) {
        return true;
      }else {
        $this->setOption('errorNum', -1);
        return false;
      }
    }
    /* 检查上传的文件是否是允许的大小 */
    private function checkFileSize() {
      if ($this->fileSize > $this->maxsize) {
        $this->setOption('errorNum', -2);
        return false;
      }else{
        return true;
      }
    }
    /* 检查是否有存放上传文件的目录 */
    private function checkFilePath() {
      if(empty($this->path)){
        $this->setOption('errorNum', -5);
        return false;
      }
      if (!file_exists($this->path) || !is_writable($this->path)) {
        if (!@mkdir($this->path, 0755)) {
          $this->setOption('errorNum', -4);
          return false;
        }
      }
      return true;
    }
    /* 设置随机文件名 */
    private function proRandName() {
      $fileName = date('YmdHis')."_".rand(1000,9999);
      return $fileName.'.'.$this->fileType;
    }
    /* 复制上传文件到指定的位置 */
    private function copyFile() {
      if(!$this->errorNum) {
        $path = rtrim($this->path, '/').'/';
        $path .= $this->newFileName;
        if (@move_uploaded_file($this->tmpFileName, $path)) {
          return true;
        }else{
          $this->setOption('errorNum', -3);
          return false;
        }
      } else {
        return false;
      }
    }
  }
application/library/Service/Ad.php
New file
@@ -0,0 +1,71 @@
<?php
/**
 * 广告服务类
 */
class Service_Ad{
    public function __construct(){
        $this->ad_model = new AdModel();
    }
    /**
     * 获取所有广告
     * @param  array   $query  [description]
     * @param  array   $fields [description]
     * @param  array   $sort   [description]
     * @param  integer $limit  [description]
     * @param  integer $skip   [description]
     * @return [type]          [description]
     */
    public function getAdList($query=array(),$fields=array(),$sort=array(),$limit=0,$skip=0){
        return $this->ad_model->getList($query, $fields, $sort, $limit, $skip);
    }
    /**
     * 获取广告数量
     * @return [type] [description]
     */
    public function getAdTotal($query=array(),$limit=0,$skip=0){
        return $this->ad_model->count($query, $limit, $skip);
    }
    /**
     * 获取某个广告的信息
     * @param  array  $query [description]
     * @param  array  $field [description]
     * @return [type]        [description]
     */
    public function getAdInfo($query = array(), $field = array()){
        return $this->ad_model->get($query, $field);
    }
    /**
     * 添加广告
     * @param [type] $data [description]
     */
    public function add($data){
        return $this->ad_model->add($data);
    }
    /**
     * 修改广告
     * @param  [type] $data  [description]
     * @param  [type] $query [description]
     * @return [type]        [description]
     */
    public function update($data, $query){
        return $this->ad_model->update($data, $query);
    }
    /**
     * 删除广告
     * @param  [type] $query [description]
     * @return [type]        [description]
     */
    public function delete($query){
        return $this->ad_model->delete($query);
    }
}
application/library/Service/Daily.php
@@ -4,6 +4,7 @@
    public function __construct(){
        $this->daily_model = new DailyModel();
        $this->hourly_model = new HourlyModel();
    }
    public function summary($day){
@@ -25,14 +26,63 @@
            $time = date('Y-m-d H:i:s');
            foreach ($datas as $data) {
                $param['user_id'] = $data['user_id'];
                $param['day_avg'] = substr($data['day_avg'], 0, 5);
                $param['day_avg'] = floatval(substr($data['day_avg'], 0, 5));
                $param['date'] = $day;
                $param['create_time'] = $time;
                $this->daily_model->add($param);
                unset($param);
                for($i = 1; $i <= 8; $i ++){
                    if($i == 1){
                        $start_hour = '00:00:00';
                        $end_hour = '02:59:59';
                    }
                    elseif($i == 8){
                        $start_hour = '21:00:00';
                        $end_hour = '23:59:59';
                    }
                    else{
                        $hour = ($i - 1)*3;
                        $start_hour = $hour.':00:00';
                        $end_hour = ($hour + 2).':59:59';
                        if($hour < 10 ){
                            $start_hour = '0'.$start_hour;
                        }
                        if($hour + 2 < 10){
                            $end_hour = '0'.$end_hour;
                        }
                    }
                    $hourly_datas = $data_model->aggregate(
                        array(
                            array(
                                '$match' => array('create_time' => array('$gte' => $day.' '.$start_hour, '$lte' => $day.' '.$end_hour))
                            ),
                            array(
                                '$group' => array('_id' => '$user_id', 'avg' => array('$avg' => '$value'))
                            ),
                            array(
                                '$project' => array('_id' => 0, 'user_id' => '$_id', 'avg' => 1)
                            )
                        )
                    );
                    if($hourly_datas){
                        foreach ($hourly_datas as $hourly_data) {
                            $param['user_id'] = $hourly_data['user_id'];
                            $param['hour_avg'] = floatval(substr($hourly_data['avg'], 0, 5));
                            $param['date'] = $day;
                            $param['start_hour'] = $start_hour;
                            $param['end_hour'] = $end_hour;
                            $param['time_level'] = $i;
                            $param['create_time'] = $time;
                            $this->hourly_model->add($param);
                            unset($param);
                        }
                    }
                }
            }
            $dailyLog_service = new Service_DailyLog();
            $dailyLog_service->addLog($day);
            return true;
        }
        else{
application/library/Service/User.php
@@ -98,4 +98,4 @@
         }
         return false;
     }
}
}
application/models/Ad.php
New file
@@ -0,0 +1,7 @@
<?php
class AdModel extends System_Model_Base{
    public $table = "ad";
}
application/models/Hourly.php
New file
@@ -0,0 +1,7 @@
<?php
class HourlyModel extends System_Model_Base{
    public $table = "data_hourly";
}
application/modules/Ad/controllers/Ad.php
New file
@@ -0,0 +1,142 @@
<?php
class AdController extends System_Controller_Admin{
    public function init(){
        parent::init();
        $this->ad_service = new Service_Ad();
    }
    /**
     * 广告列表
     */
    public function IndexAction(){
        if($this->getRequest()->isXmlHttpRequest()){
            $total = $this->ad_service->getAdTotal();
            $data['draw'] = !empty($_REQUEST['draw'])?$_REQUEST['draw']:1;
            $data['start'] = !empty($_REQUEST['start'])?$_REQUEST['start']:0;
            $data['length'] = !empty($_REQUEST['length'])?$_REQUEST['length']:10;
            $data['recordsTotal'] = $total;
            $data['recordsFiltered'] = $total;
            $data['data'] = $this->ad_service->getAdList(array(), array(), array(), $data['length'], $data['start']);
            exit($this->sendToDataTable($data));
        }
    }
    /**
     * 添加广告
     */
    public function AddAction(){
        if($this->getRequest()->isXmlHttpRequest()){
            $data['name'] = $this->getRequest()->getPost('name');
            if(FileUpload::upload('logo')){
            }
            $data['is_publish'] = $this->getRequest()->getPost('is_publish');
            $data['content'] = $this->getRequest()->getPost('content');
            $data['create_time'] = date('Y-m-d H:i:s');
             if($this->ad_service->add($data)){
                exit($this->showSuccess('广告添加成功', true));
            }
            else{
                exit($this->showError($this->user_service->error, 400, true));
            }
        }
        $role_service = new service_Role();
        $roles = $role_service->getRoleList();
        $this->getView()->assign('roles', $roles);
    }
    /**
     * 修改用户
     */
    public function EditAction($id){
        $user = $this->user_service->getUserInfo(array('_id' => $id));
        if($user){
            if($this->getRequest()->isXmlHttpRequest()){
                $data['nickname'] = $this->post('nickname');
                $password = $this->post('password');
                if(!empty($password))
                $data['password'] = md5(md5($password).$user['encrypt']);
                $data['refresh_frequency'] = $this->post('refresh_frequency');
                $data['is_open_upload'] = $this->post('is_open_upload');
                $data['video'] = $this->post('video');
                $data['role'] = $this->post('role');
                $data['edit_time'] = time();
                $data['is_lock'] = $this->post('is_lock');
                if($this->user_service->update($data, array('_id' => $id))){
                    exit($this->showSuccess('用户修改成功', true));
                }
                else{
                    exit($this->showError($this->user_service->error, 400, true));
                }
            }
            $role_service = new Service_Role();
            $roles = $role_service->getRoleList();
            $this->getView()->assign(array('user' => $user, 'roles' => $roles));
        }
        else{
            $this->redirect('/error/show/type/no_data');
        }
    }
    /**
     * 修改我的信息
     */
    public function MyAction(){
        $user_id = $this->session['user']['user_id'];
        $user = $this->user_service->getUserInfo(array('_id' => $user_id));
        if($user){
            if($this->getRequest()->isXmlHttpRequest()){
                $data['nickname'] = $this->post('nickname');
                $password = $this->post('password');
                if(!empty($password))
                $data['password'] = md5(md5($password).$user['encrypt']);
                $data['refresh_frequency'] = $this->post('refresh_frequency');
                $data['is_open_upload'] = $this->post('is_open_upload');
                $data['video'] = $this->post('video');
                $data['edit_time'] = time();
                if($this->user_service->update($data, array('_id' => $user_id))){
                    exit($this->showSuccess('用户修改成功', true));
                }
                else{
                    exit($this->showError($this->user_service->error, 400, true));
                }
            }
            $role_service = new Service_Role();
            $roles = $role_service->getRoleList();
            $this->getView()->assign(array('user' => $user, 'roles' => $roles));
        }
        else{
            $this->redirect('/error/show/type/no_data');
        }
    }
    /**
     * 验证手机号码是否存在
     */
    public function CheckPhoneAction(){
        $phone = $this->post('phone');
        $result = $this->_checkPhone($phone);
        if($this->isAjax()){
            exit($this->send(array('valid' => $result)));
        }
        else{
            return $result;
        }
    }
    /**
     * 验证号码是否存在
     * @param  [type] $phone [description]
     * @return [type]        [description]
     */
    public function _checkPhone($phone){
        $user = $this->user_service->getUserInfo(array('phone' => $phone));
        if($user)
            return false;
        else
            return true;
    }
}
application/modules/Ad/views/ad/add.phtml
New file
@@ -0,0 +1,102 @@
    <section class="content-header">
      <h1>
        广告管理
      </h1>
      <ol class="breadcrumb">
        <li><a href="/admin/index/index"><i class="fa fa-dashboard"></i> 平台首台</a></li>
        <li><a href="/role/role/list">广告管理</a></li>
        <li class="active">添加广告</li>
      </ol>
    </section>
    <!-- Main content -->
    <section class="content">
        <div class="box-body pad">
          <!-- general form elements -->
          <div class="box box-primary">
            <div class="box-header with-border">
              <h3 class="box-title">添加广告</h3>
            </div>
            <!-- /.box-header -->
            <!-- form start -->
            <form role="form" id="validateform">
              <div class="box-body">
                <div class="form-group">
                  <label >广告名称</label>
                  <input type="text" class="form-control" id="name" name="name" placeholder="用户组名">
                </div>
                <div class="form-group">
                  <label >用户组描述</label>
                  <textarea class="form-control" id="description" name="description"></textarea>
                </div>
                <div class="form-group">
                  <label >用户组权限</label>
                  <?php
                   $first_modules = array();
                   $second_modules = array();
                   $third_modules = array();
                   foreach ($modules as $key => $module){
                      if($module['level'] == 1){
                        $first_modules[] = $module;
                      }
                      elseif($module['level'] == 2){
                        $second_modules[] = $module;
                      }
                      elseif($module['level'] == 3){
                        $third_modules[] = $module;
                      }
                      unset($modules[$key]);
                   }
                  ?>
                  <?php foreach ($first_modules as  $f_module):?>
                    <div class="checkbox">
                      <label>
                         <input type="checkbox" class="minimal module" id="actions" name="actions[]" value="<?php echo $f_module['_id'];?>">
                         <?php echo $f_module['name'];?>
                      </label>
                    <?php foreach ($second_modules as  $s_module):?>
                      <?php if($s_module['parent'] == $f_module['_id']):?>
                      <div class="checkbox">
                      &nbsp; &nbsp;&nbsp; &nbsp;└
                        <label>
                        <input type="checkbox" class="minimal module" id="actions" name="actions[]" value="<?php echo $s_module['_id'];?>" >
                         <?php echo $s_module['name'];?>
                        </label>
                      <?php foreach ($third_modules as $t_module):?>
                        <?php if($t_module['parent'] == $s_module['_id']):?>
                        <div class="checkbox">
                        &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;└
                          <label>
                          <input type="checkbox" class="minimal module" id="actions" name="actions[]" value="<?php echo $t_module['_id'];?>" >
                           <?php echo $t_module['name'];?>
                          </label>
                        </div>
                        <?php endif;?>
                      <?php endforeach;?>
                      </div>
                      <?php endif;?>
                    <?php endforeach;?>
                    </div>
                  <?php endforeach;?>
                </div>
              </div>
              <!-- /.box-body -->
              <div class="box-footer">
                <button type="submit" class="btn btn-primary" id="dosubmit">保存</button>
              </div>
            </form>
          </div>
    </div>
  </section>
  <script src="/themes/AdminLTE/bootstrap/js/bootstrapValidator.min.js"></script>
<script type="text/javascript">
  var SITE_URL = '<?php echo Yaf_Registry::get('var')['site_url']; ?>';
</script>
<script src="/static/<?php echo $route['module']?>/<?php echo $route['controller']?>/js/<?php echo $route['action']?>.js"></script>
application/modules/Ad/views/ad/edit.phtml
New file
@@ -0,0 +1,104 @@
    <section class="content-header">
      <h1>
        用户组管理
      </h1>
      <ol class="breadcrumb">
        <li><a href="/admin/index/index"><i class="fa fa-dashboard"></i> 平台首台</a></li>
        <li><a href="/role/role/list">用户组管理</a></li>
        <li class="active">修改用户组</li>
      </ol>
    </section>
    <!-- Main content -->
    <section class="content">
        <div class="box-body pad">
          <!-- general form elements -->
          <div class="box box-primary">
            <div class="box-header with-border">
              <h3 class="box-title">修改用户组</h3>
            </div>
            <!-- /.box-header -->
            <!-- form start -->
            <form role="form" id="validateform">
              <div class="box-body">
                <div class="form-group">
                  <label >用户组名</label>
                  <input type="text" class="form-control" id="name" name="name" placeholder="用户组名" value="<?php echo $role['name']?>">
                </div>
                <div class="form-group">
                  <label >用户组描述</label>
                  <textarea class="form-control" id="description" name="description"><?php echo $role['description']?></textarea>
                </div>
                <div class="form-group">
                  <label >用户组权限</label>
                  <?php
                   $role_auth = explode(',', $role['modules']);
                   $first_modules = array();
                   $second_modules = array();
                   $third_modules = array();
                   foreach ($modules as $key => $module){
                      if($module['level'] == 1){
                        $first_modules[] = $module;
                      }
                      elseif($module['level'] == 2){
                        $second_modules[] = $module;
                      }
                      elseif($module['level'] == 3){
                        $third_modules[] = $module;
                      }
                      unset($modules[$key]);
                   }
                  ?>
                  <?php foreach ($first_modules as  $f_module):?>
                    <div class="checkbox">
                      <label>
                         <input type="checkbox" <?php echo in_array($f_module['_id'], $role_auth)?"checked":"";?> class="minimal module" id="actions" name="actions[]" value="<?php echo $f_module['_id'];?>">
                         <?php echo $f_module['name'];?>
                      </label>
                    <?php foreach ($second_modules as  $s_module):?>
                      <?php if($s_module['parent'] == $f_module['_id']):?>
                      <div class="checkbox">
                      &nbsp; &nbsp;&nbsp; &nbsp;└
                        <label>
                        <input type="checkbox" <?php echo in_array($s_module['_id'], $role_auth)?"checked":"";?> class="minimal module" id="actions" name="actions[]" value="<?php echo $s_module['_id'];?>" >
                         <?php echo $s_module['name'];?>
                        </label>
                      <?php foreach ($third_modules as $t_module):?>
                        <?php if($t_module['parent'] == $s_module['_id']):?>
                        <div class="checkbox">
                        &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;└
                          <label>
                          <input type="checkbox" <?php echo in_array($t_module['_id'], $role_auth)?"checked":"";?> class="minimal module" id="actions" name="actions[]" value="<?php echo $t_module['_id'];?>" >
                           <?php echo $t_module['name'];?>
                          </label>
                        </div>
                        <?php endif;?>
                      <?php endforeach;?>
                      </div>
                      <?php endif;?>
                    <?php endforeach;?>
                    </div>
                  <?php endforeach;?>
                </div>
              </div>
              <!-- /.box-body -->
              <div class="box-footer">
                <button type="submit" class="btn btn-primary" id="dosubmit">保存</button>
              </div>
            </form>
          </div>
    </div>
  </section>
  <script src="/themes/AdminLTE/bootstrap/js/bootstrapValidator.min.js"></script>
<script type="text/javascript">
  var SITE_URL = '<?php echo Yaf_Registry::get('var')['site_url']; ?>';
  var ID = '<?php echo $role['_id'];?>';
</script>
<script src="/static/<?php echo $route['module']?>/<?php echo $route['controller']?>/js/<?php echo $route['action']?>.js"></script>
application/modules/Ad/views/ad/index.phtml
New file
@@ -0,0 +1,164 @@
    <link rel="stylesheet" href="/themes/AdminLTE/plugins/datatables/dataTables.bootstrap.css">
    <section class="content-header">
      <h1>
        广告管理
      </h1>
      <ol class="breadcrumb">
        <li><a href="/admin/index/index"><i class="fa fa-dashboard"></i> 平台首页</a></li>
        <li><a href="/article/manager/list">广告管理</a></li>
        <li class="active">广告列表</li>
      </ol>
    </section>
     <!-- Main content -->
    <section class="content">
      <div class="row">
        <div class="col-xs-12">
          <div class="box">
            <div class="box-header">
              <h3 class="box-title">广告列表</h3>
            </div>
            <!-- /.box-header -->
            <div class="box-body">
              <table id="table_list" class="table table-bordered table-hover">
                <thead>
                  <tr>
                    <th>广告logo</th>
                    <th>广告名称</th>
                    <th>是否启用</th>
                    <th>创建时间</th>
                    <th>优先级</th>
                    <th>操作</th>
                  </tr>
                </thead>
              </table>
            </div>
            <!-- /.box-body -->
          </div>
          <!-- /.box -->
        </section>
<script>
  $(function () {
    var config = {
      "dom": 'l<"#toolbar">frtip',
      /*
       * 默认为false
       * 当表格在处理的时候(比如排序操作)是否显示“处理中...”
       * 当表格的数据中的数据过多以至于对其中的记录进行排序时会消耗足以被察觉的时间的时候,该选项会有些用处
       */
         "processing":true,
      /*
        * 默认为true
        * 是否允许终端用户从一个选择列表中选择分页的页数,页数为10,25,50和100,需要分页组件bPaginate的支持
        */
        "lengthChange":false,
        "serverSide":true,
        "autoWidth": true,
        "language":{
          "lengthMenu": "每页显示 _MENU_ 条",
          "emptyTable": "没有任何数据记录",
          "processing": "正在载入数据...",
          "search": "搜索 _INPUT_",
          "info": "显示 _START_ 至 _END_ 项结果,共 _TOTAL_ 项",
          "zeroRecords": "暂时没有任何数据记录",
          "sInfoEmpty": "",
          "paginate": {
            "first": "首页",
            "previous": "上一页",
            "next": "下一页",
            "last": "尾页"
          },
        },
        "ajax":{
          "url": "/ad/ad/index",
          "type":"POST",
        },
        "columns":[
          {
            "data":"name",
            "orderable":false
          },
          {
            "data":"category",
            "orderable":false
          },
          {
            "data":"is_publish",
            "orderable":false
          },
          {
            "data":"create_time",
            "orderable":false
          },
          {
            "data":null,
            "orderable":false
          },
        ],
        "columnDefs": [
          {
            "targets":1,
            "searchable":false,
          },
          {
            "targets":2,
            "searchable":false,
            "render":function(data, type, row, meta){
              if(data == 0) {
                return "已关闭";
              }
              else{
                return "已开启";
              }
            }
          },
          {
            "targets":4,
            "searchable":false,
            "render":function(data, type, row, meta){
              return '<a class="btn btn-primary" href="/<?php echo $route['module']?>/<?php echo $route['controller']?>/edit/id/'+row['_id']+'">编辑</a>&nbsp;&nbsp;&nbsp;&nbsp;<a class="btn btn-danger del" data-id="'+row['_id']+'" data-target="/<?php echo $route['module']?>/<?php echo $route['controller']?>/del">删除</a>'
            }
          }
        ],
        "initComplete": function(){
          $("#toolbar").css("width", "100px").css("display", "inline").css("margin-left", "10px");
          $("#toolbar").append('<a id="build"  class="btn btn-success" data-toggle="modal" data-target="" href="/<?php echo $route['module']?>/<?php echo $route['controller']?>/add"> <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>添加 <a> ');
          $(".del").bind('click', function(){
            if(confirm('您确定要删除这条信息?')){
              $.ajax({
                type: "POST",
                url: $(this).data('target'),
                data:  {id:$(this).data('id')},
                success:function(response){
                  var dataObj=jQuery.parseJSON(response);
                  if(dataObj.code == 200)
                  {
                    $.scojs_message('删除成功', $.scojs_message.TYPE_OK);
                    setTimeout(function(){window.location.href = "/<?php echo $route['module']?>/<?php echo $route['controller']?>/<?php echo $route['action']?>";}, 600);
                  }else
                  {
                    $.scojs_message(dataObj.content, $.scojs_message.TYPE_ERROR);
                  }
                },
                error: function (request, status, error) {
                  $.scojs_message(request.responseText, $.scojs_message.TYPE_ERROR);
                }
              });
            }
            else{
              return false;
            }
          });
        }
    }
    $("#table_list").DataTable(config);
  });
</script>