fastadmin操作审核功能

单个审核

buttons:[{
  name: 'adopt',
  text: '通过审核',
  title: '通过',
  classname: 'btn btn-xs btn-info btn-view btn-ajax',
  icon: 'fa fa-check',
  url: 'drama/repertory/adopt',        //修改自己对应的控制器
  visible: function (row) {
    if (row['auditing'] == 0) {
      return true;
    } else {
      return false;
    }
  },
  refresh: true
}]

控制器方法中:

public function adopt($ids)
{
  if ($ids != null) {
    $result = db('drama_repertory')->where('id', $ids)->update(['auditing' => 1]);
    $this->success('', '操作成功', $result);
  }
}

批量审核

当前所选控制器下的view中index.html

 {:__('批量审核')}
 {:__('批量反审')}

与控制器同名的js文件中,位置如下

var table = $('#table');
//一键审批
$(document).on("click", ".btn-approve", function () {        //.btn-approve要与前端中按钮的名称相同,否则监听不到
  var data = table.bootstrapTable('getSelections');
  var ids = [];
  if (data.length === 0) {
    Toastr.error("请选择操作信息");
    return;
  }
  for (var i = 0; i < data.length; i++) {
    ids[i] = data[i]['id']
  }
  Layer.confirm(
    '确认选中'+ids.length+'条审批吗?',
    {icon: 3, title: __('Warning'), offset: '40%', shadeClose: true},
    function (index) {
      Layer.close(index);
      Backend.api.ajax({
        //url: "lgwy/attrchg/approve?ids=" + JSON.stringify(ids),
        //方法一:传参方式,后台需要转换变成数组
        /*url: "lgwy/attrchg/approve?ids=" + (ids),
                data: {}*/
        //方法二:传参方式,直接是数组传递给后台
        url: "drama/repertory/approve",
        data: {ids:ids}
      }, function(data, ret){//成功的回调
        if (ret.code === 1) {
          table.bootstrapTable('refresh');
          Layer.close(index);
        } else {
          Layer.close(index);
          Toastr.error(ret.msg);
        }
      }, function(data, ret){//失败的回调
        console.log(ret);
        // Toastr.error(ret.msg);
        Layer.close(index);
      });
    }
  );
});

控制器下文件

public function approve($ids)
{
    //$arr=explode( ' , ' ,$ids);//接受参数转变成数组
    foreach ($ids as $k => $v) {
        $res = $this->model->where('id', $v)->value('auditing');
        if (!$res) {
            $this->model->where('id', $v)->update(['auditing' => '1']);
        }
    }
    $this->success();
}


 

你可能感兴趣的:(PHP开发中难点记录,php)