Пример #1
0
 public function updateUserGroupAccess($get, $post)
 {
     $user_group_id = $get['user_group_id'] ?: $post['user_group_id'];
     if (Router::isPost()) {
         $ex = Model::transaction(function () use($post, $user_group_id) {
             $con = "user_group_id = '" . addslashes($user_group_id) . "'";
             UserGroupAuth::deleteWhere(0, $con);
             $data = array();
             if ($post['act_bids']) {
                 foreach ($post['act_bids'] as $act_id) {
                     $data[] = array('user_group_id' => $user_group_id, 'action_id' => $act_id, 'type' => UserGroupAuth::TYPE_BLACK);
                 }
             }
             if ($post['act_wids']) {
                 foreach ($post['act_wids'] as $act_id) {
                     $data[] = array('user_group_id' => $user_group_id, 'action_id' => $act_id, 'type' => UserGroupAuth::TYPE_BLACK);
                 }
             }
             if ($data) {
                 UserGroupAuth::insertMany($data);
             }
         });
         return new Result(!$ex ? '操作成功' : $ex->getMessage(), !$ex, null, Router::getUrl('UserGroup'));
     }
     if (!$user_group_id) {
         $tmp = UserGroup::find()->one();
         $user_group_id = $tmp->id;
     }
     $act_list = AccessAction::find()->all(true);
     $act_ids = array_column($act_list, 'id');
     //user_group values
     $w_user_group_values = $b_user_group_values = array();
     if ($act_ids) {
         $user_group_values = UserGroupAuth::find('action_id IN ? AND user_group_id = ?', $act_ids, $user_group_id)->all(true);
         foreach ($user_group_values as $val) {
             if ($val['type'] == UserGroupAuth::TYPE_WHITE) {
                 $w_user_group_values[$val['action_id']] = $val;
             } else {
                 $b_user_group_values[$val['action_id']] = $val;
             }
         }
     }
     array_orderby($act_list, 'desc', SORT_DESC);
     $white_list = $black_list = array();
     foreach ($act_list as $act) {
         $a = $this->convertPathToArray('全部/' . $act['desc'], array($act['id'], $act['uri'], !!$w_user_group_values[$act['id']]));
         $white_list = array_merge_recursive($white_list, $a);
         $b = $this->convertPathToArray('全部/' . $act['desc'], array($act['id'], $act['uri'], !!$b_user_group_values[$act['id']]));
         $black_list = array_merge_recursive($black_list, $b);
     }
     return array('user_group_id' => $user_group_id, 'auth_list' => array($white_list, $black_list), 'user_group_list' => UserGroup::find()->all());
 }
Пример #2
0
 public function file($get)
 {
     if (Router::isPost()) {
         $file = $_FILES['file'];
         if (empty($file['name'])) {
             return new Result('请选择文件', false);
         }
         $url_prefix = Config::get('upload/url');
         $uploader = new Uploader(array('upload_dir' => Config::get('upload/path'), 'file_name_converter' => Config::get('upload/file_name_converter'), 'max_size' => Config::get('upload/max_size'), 'file_type' => Config::get('upload/file_type')));
         $result = $uploader->upload($errors);
         if ($errors) {
             return new Result(array_first($errors));
         }
         return new Result('上传成功', true, array('url' => $url_prefix . $result['file'], 'name' => $result['file'], 'value' => $result['file']));
     }
     return new Result('请选择上传文件');
 }
Пример #3
0
 public function uploadImage()
 {
     if (Router::isPost()) {
         $file = $_FILES['file'];
         if (empty($file['name'])) {
             return new Result('请选择文件', false);
         }
         $ext = $this->getFileExt($file['type']);
         if (!$ext) {
             return new Result('文件类型不符合,请重新选择文件上传', false);
         }
         $rsp = Request::postFiles(Config::get('upload/host'), array(), array('file' => $file['tmp_name']));
         $result = json_decode($rsp, true);
         if ($result['code'] == '0') {
             return new Result('图片上传成功', null, array('src' => Config::get('upload/url') . $result['data'], 'value' => $result['data']));
         }
         return new Result('图片上传失败,请稍候重试', null, $rsp);
     }
     return array('UPLOAD_PAGE_URL' => Router::getUrl('index/uploadImage'));
 }