牟新芬 4 anos atrás
pai
commit
5f1b2ab8c2

+ 142 - 0
app/model/system/Attachment.php

@@ -0,0 +1,142 @@
+<?php
+namespace app\models\system;
+
+use library\traits\ModelTrait;
+use library\basic\BaseModel;
+
+/**
+ * 文件检验model
+ * Class SystemFile
+ * @package app\models\system
+ */
+class Attachment extends BaseModel
+{
+
+    /**
+     * 数据表主键
+     * @var string
+     */
+    protected $pk = 'att_id';
+
+    /**
+     * 模型名称
+     * @var string
+     */
+    protected $name = 'attachment';
+
+    use ModelTrait;
+
+    /**
+     * TODO 添加附件记录
+     * @param $name
+     * @param $att_size
+     * @param $att_type
+     * @param $att_dir
+     * @param string $satt_dir
+     * @param int $pid
+     * @param int $imageType
+     * @param int $time
+     * @return Attachment
+     */
+    public static function attachmentAdd($name, $att_size, $att_type, $att_dir, $satt_dir = '', $pid = 0, $imageType = 1, $time = 0, $module_type = 1, $mer_id = '')
+    {
+        $data['name'] = $name;
+        $data['att_dir'] = $att_dir;
+        $data['satt_dir'] = $satt_dir;
+        $data['att_size'] = $att_size;
+        $data['att_type'] = $att_type;
+        $data['image_type'] = $imageType;
+        $data['module_type'] = $module_type;
+        $data['time'] = $time ? $time : time();
+        $data['pid'] = $pid;
+        $data['mer_id'] = $mer_id;
+        return self::create($data);
+    }
+
+    /**
+     * TODO 获取分类图
+     * @param $id
+     * @return array
+     */
+    public static function getAll($id)
+    {
+        $model = new self;
+        $where['pid'] = $id;
+        $where['module_type'] = 1;
+        $model->where($where)->order('att_id desc');
+        return $model->page($model, $where, '', 24);
+    }
+
+    /** 获取图片列表
+     * @param $where
+     * @return array
+     */
+    public static function getImageList($where)
+    {
+        $model = new self;
+        $model = $model->where('module_type', 1);
+        if (isset($where['pid']) && $where['pid']) $model = $model->where('pid', $where['pid']);
+        if (isset($where['mer_id']) && $where['mer_id'] != '') $model = $model->where('mer_id', $where['mer_id']);
+        $model = $model->page((int)$where['page'], (int)$where['limit']);
+        $model = $model->order('att_id desc,time desc');
+        $list = $model->select();
+        $list = count($list) ? $list->toArray() : [];
+        $site_url = config('app')['API_URL'];
+        foreach ($list as &$item) {
+            if ($site_url) {
+                $item['satt_dir'] = (strpos($item['satt_dir'], $site_url) !== false || strstr($item['satt_dir'], 'http') !== false) ? $item['satt_dir'] : $site_url . $item['satt_dir'];
+                $item['att_dir'] = (strpos($item['att_dir'], $site_url) !== false || strstr($item['att_dir'], 'http') !== false) ? $item['satt_dir'] : $site_url . $item['att_dir'];
+            }
+        }
+        if (isset($where['pid']) && $where['pid']) $map[] = ['pid', '=', $where['pid']];
+        $map[] = ['module_type', '=', 1];
+        if (isset($where['mer_id']) && $where['mer_id']) $map[] = ['mer_id', '=', $where['mer_id']];
+        $count = self::where($map)->count();
+        return compact('count', 'list');
+    }
+
+    /**
+     * TODO 获取单条信息
+     * @param $value
+     * @param string $field
+     * @return array
+     * @throws \think\Exception
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public static function getInfo($value, $field = 'att_id')
+    {
+        $where[$field] = $value;
+        $count = self::where($where)->count();
+        if (!$count) return false;
+        return self::where($where)->find()->toArray();
+    }
+
+    /**
+     * 清除昨日海报
+     * @return bool
+     * @throws \Exception
+     */
+    public static function emptyYesterdayAttachment()
+    {
+        self::beginTrans();
+        try {
+            $list = self::whereTime('time', 'yesterday')->where(['module_type' => 2])->column('att_dir', 'att_id');
+            foreach ($list as $att_id => $att_dir) {
+                if ($att_dir && strstr($att_dir, 'uploads') !== false) {
+                    if (strstr($att_dir, 'http') === false)
+                        @unlink(substr($att_dir, 1));
+                    else {
+                        $filedir = substr($att_dir, strpos($att_dir, 'uploads'));
+                        @unlink($filedir);
+                    }
+                }
+                self::del($att_id);
+            }
+            self::commitTrans();
+        } catch (\Exception $e) {
+            self::rollbackTrans();
+        }
+    }
+}

+ 111 - 0
app/model/system/AttachmentCategory.php

@@ -0,0 +1,111 @@
+<?php
+namespace app\models\system;
+
+use library\traits\ModelTrait;
+use library\basic\BaseModel;
+
+/**
+ * 附件目录
+ * Class SystemAttachmentCategory
+ * @package app\models\system
+ */
+class AttachmentCategory extends BaseModel
+{
+
+    /**
+     * 数据表主键
+     * @var string
+     */
+    protected $pk = 'id';
+
+    /**
+     * 模型名称
+     * @var string
+     */
+    protected $name = 'attachment_category';
+
+    use ModelTrait;
+
+    /**
+     * 添加分类
+     * @param $name
+     * @param $att_size
+     * @param $att_type
+     * @param $att_dir
+     * @param string $satt_dir
+     * @param int $pid
+     * @return AttachmentCategory|\think\Model
+     */
+    public static function Add($name,$att_size,$att_type,$att_dir,$satt_dir='',$pid = 0)
+    {
+        $data['name'] = $name;
+        $data['att_dir'] = $att_dir;
+        $data['satt_dir'] = $satt_dir;
+        $data['att_size'] = $att_size;
+        $data['att_type'] = $att_type;
+        $data['time'] = time();
+        $data['pid'] = $pid;
+        return self::create($data);
+    }
+
+    /**
+     * 获取分类图
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public static function getAll($name, $mer_id = ''){
+        $model = new self;
+        if($name) $model = $model->where('name','LIKE',"%$name%");
+        if($mer_id) $model = $model->where('mer_id', 'in', [0, $mer_id]);
+//        $count=$model->where('pid',0)->count();
+        $list=self::tidyMenuTier($model->select(),0);
+        return compact('list');
+    }
+    public static function tidyMenuTier($menusList,$pid = 0,$navList = [])
+    {
+
+        foreach ($menusList as $k=>$menu){
+            $menu = $menu->getData();
+            $menu['title']=$menu['name'];
+            if($menu['pid'] == $pid){
+                unset($menusList[$k]);
+                $menu['children'] = self::tidyMenuTier($menusList,$menu['id']);
+                if ($menu['children']) $menu['expand']=true;
+                $navList[] = $menu;
+            }
+        }
+        return $navList;
+    }
+
+    /**
+     * 获取分类下拉列表
+     * @param int $id
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public static function getCateList($id = 10000, $mer_id = ''){
+        $model = new self();
+        if($id == 0) $model = $model->where('pid',$id);
+        $model = $model->where('mer_id', 'in', [0, $mer_id]);
+        return sort_list_tier($model->select()->toArray());
+    }
+
+    /**
+     * 获取单条信息
+     * @param $att_id
+     * @return mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public static function getinfo($att_id){
+        $model = new self;
+        $where['att_id'] = $att_id;
+        return $model->where($where)->select()->toArray()[0];
+    }
+
+}

+ 136 - 0
app/system/controller/v1/Attachment.php

@@ -0,0 +1,136 @@
+<?php
+
+namespace app\system\controller\v1;
+
+use app\BaseController;
+use think\facade\Route as Url;
+use library\services\UtilService;
+use app\models\system\{
+    Attachment as AttachmentModel, AttachmentCategory as Category
+};
+use think\Request;
+use library\basic\BaseUpload as Upload;
+use library\utils\Qiniu;
+
+/**
+ * 图片管理类
+ * Class Attachment
+ * @package app\system\controller\v1
+ */
+class Attachment extends BaseController
+{
+
+    /**
+     * 显示资源列表
+     *
+     * @return \think\Response
+     */
+    public function index()
+    {
+        $where = UtilService::getMore([
+            ['page', 1],
+            ['limit', 18],
+            ['pid', 0]
+        ]);
+        return $this->success(AttachmentModel::getImageList($where));
+    }
+
+    /**
+     * 删除指定资源
+     *
+     * @param string $ids
+     * @return \think\Response
+     */
+    public function delete()
+    {
+        $request = app('request');
+        $ids = $request->post('ids');
+        $ids = explode(',', $ids);
+        if (empty($ids))
+            return $this->fail('请选择要删除的图片');
+        foreach ($ids as $v) {
+            self::deleteImg($v);
+        }
+        return $this->success('删除成功');
+    }
+
+    /**
+     * 图片管理上传图片
+     * @return \think\response\Json
+     */
+    public function upload()
+    {
+        [$pid, $file] = UtilService::getMore([
+            ['pid', 0],
+            ['file', 'file']
+        ], $this->request, true);
+        try {
+            $path = make_path('attach', 2, true);
+            $res = Upload::to($path)->validate()->move($file);
+            if ($res === false) {
+                return $this->fail(Upload::getError());
+            } else {
+                $img_url = Qiniu::updateFile('img', $path, $path);
+                $fileInfo = Upload::getUploadInfo();
+                if ($fileInfo) {
+                    AttachmentModel::attachmentAdd($fileInfo['name'], $fileInfo['size'], $fileInfo['type'], $fileInfo['dir'], $fileInfo['thumb_path'], $pid, 2, $fileInfo['time'], 1, 0);
+                }
+                return $this->success('上传成功', ['src' => $res->filePath]);
+            }
+        } catch (\Exception $e) {
+            return $this->fail($e->getMessage());
+        }
+    }
+
+    /**删除图片和数据记录
+     * @param $att_id
+     */
+    public function deleteImg($att_id)
+    {
+        $attinfo = AttachmentModel::get($att_id);
+        if ($attinfo) {
+            try {
+                Upload::delete($attinfo['name']);
+            } catch (\Throwable $e) {
+            }
+            AttachmentModel::where('att_id', $att_id)->delete();
+        }
+    }
+
+    /**
+     * 移动图片分类显示
+     */
+    public function move($images)
+    {
+        $formbuider = [];
+        $formbuider[] = Form::hidden('images', $images);
+        $formbuider[] = Form::select('pid', '选择分类')->setOptions(function () {
+            $list = Category::getCateList();
+            $options = [['value' => 0, 'label' => '所有分类']];
+            foreach ($list as $id => $cateName) {
+                $options[] = ['label' => $cateName['html'] . $cateName['name'], 'value' => $cateName['id']];
+            }
+            return $options;
+        })->filterable(1);
+        return $this->makePostForm('编辑分类', $formbuider, Url::buildUrl('/file/do_move'), 'PUT');
+    }
+
+    /**
+     * 移动图片分类操作
+     */
+    public function moveImageCate()
+    {
+        $data = Util::postMore([
+            'pid',
+            'images'
+        ]);
+        if ($data['images'] == '') return $this->fail('请选择图片');
+        if (!$data['pid']) return $this->fail('请选择分类');
+        $res = SystemAttachmentModel::where('att_id', 'in', $data['images'])->update(['pid' => $data['pid']]);
+        if ($res)
+            return $this->success('移动成功');
+        else
+            return $this->fail('移动失败!');
+    }
+
+}

+ 132 - 0
app/system/controller/v1/AttachmentCategory.php

@@ -0,0 +1,132 @@
+<?php
+
+namespace app\system\controller\v1;
+
+use app\BaseController;
+use think\Request;
+use think\facade\Route as Url;
+use library\services\{UtilService as Util,FormBuilder as Form};
+use app\models\system\{Attachment as AttachmentModel,AttachmentCategory as Category};
+
+/**
+ * 图片分类管理类
+ * Class AttachmentCategory
+ * @package app\system\controller\v1
+ */
+class AttachmentCategory extends BaseController
+{
+    /**
+     * 显示资源列表
+     *
+     * @return \think\Response
+     */
+    public function index($name='')
+    {
+        return $this->success(Category::getAll($name));
+    }
+
+    /**
+     * 显示创建资源表单页.
+     *
+     * @return \think\Response
+     */
+    public function create()
+    {
+        $id=$this->request->param('id');
+        $id=$id ?? 0;
+        $formbuider = [];
+        $formbuider[] = Form::select('pid','上级分类',(string)$id)->setOptions(function () {
+            $list = Category::getCateList(0);
+            $options =  [['value'=>0,'label'=>'所有分类']];
+            foreach ($list as $id=>$cateName){
+                $options[] = ['label'=>$cateName['html'].$cateName['name'],'value'=>$cateName['id']];
+            }
+            return $options;
+        })->filterable(1);
+        $formbuider[] = Form::input('name','分类名称');
+        return $this->makePostForm('添加分类', $formbuider, Url::buildUrl('/file/category'), 'POST');
+    }
+
+    /**
+     * 保存新建的资源
+     *
+     * @param  \think\Request  $request
+     * @return \think\Response
+     */
+    public function save(Request $request)
+    {
+        $request = app('request');
+        $post = $request->post();
+        $data['pid'] = $post['pid'];
+        $data['name'] = $post['name'];
+        $data['mer_id'] = $this->merId;
+        if(empty($post['name'] ))
+            return $this->fail('分类名称不能为空!');
+        $res = Category::create($data);
+        if($res)
+            return $this->success('添加成功');
+        else
+            return $this->fail('添加失败!');
+    }
+
+    /**
+     * 显示编辑资源表单页.
+     *
+     * @param  int  $id
+     * @return \think\Response
+     */
+    public function edit($id)
+    {
+        $Category = Category::get($id);
+        if(!$Category) return $this->fail('数据不存在!');
+        $formbuider = [];
+        $formbuider[] = Form::hidden('id',$id);
+        $formbuider[] = Form::select('pid','上级分类',(string)$Category->getData('pid'))->setOptions(function ()use($id){
+            $list = Category::getCateList();
+            $options =  [['value'=>0,'label'=>'所有分类']];
+            foreach ($list as $id=>$cateName){
+                $options[] = ['label'=>$cateName['html'].$cateName['name'],'value'=>$cateName['id']];
+            }
+            return $options;
+        })->filterable(1);
+        $formbuider[] = Form::input('name','分类名称',$Category->getData('name'));
+        return $this->makePostForm('编辑分类', $formbuider, Url::buildUrl('/file/category/'.$id), 'PUT');
+    }
+
+    /**
+     * 保存更新的资源
+     *
+     * @param  \think\Request  $request
+     * @param  int  $id
+     * @return \think\Response
+     */
+    public function update(Request $request, $id)
+    {
+        $data = Util::postMore([
+            'pid',
+            'name'
+        ]);
+        if($data['pid'] == '') return $this->fail('请选择父类');
+        if(!$data['name']) return $this->fail('请输入分类名称');
+        Category::edit($data,$id);
+        return $this->success('分类编辑成功!');
+    }
+
+    /**
+     * 删除指定资源
+     *
+     * @param  int  $id
+     * @return \think\Response
+     */
+    public function delete($id)
+    {
+        $chdcount = Category::where('pid',$id)->count();
+        if($chdcount) return $this->fail('有子栏目不能删除');
+        $chdcount = AttachmentModel::where('pid',$id)->count();
+        if($chdcount) return $this->fail('栏目内有图片不能删除');
+        if(Category::del($id))
+            return $this->success('删除成功!');
+        else
+            return $this->fail('删除失败');
+    }
+}

+ 26 - 0
app/system/route/file.php

@@ -0,0 +1,26 @@
+<?php
+
+use think\facade\Route;
+
+/**
+ * 附件相关路由
+ */
+Route::group('file', function () {
+    //附件列表
+    Route::get('file', 'v1.Attachment/index');
+    //删除图片和数据记录
+    Route::post('file/delete', 'v1.Attachment/delete');
+    //移动图片分来表单
+    Route::get('file/move', 'v1.Attachment/move');
+    //移动图片分类
+    Route::put('file/do_move', 'v1.Attachment/moveImageCate');
+    //上传图片
+    Route::post('upload/[:upload_type]', 'v1.Attachment/upload');
+    //附件分类管理资源路由
+    Route::resource('category', 'v1.AttachmentCategory');
+
+})->middleware([
+    \app\system\middleware\AllowOriginMiddleware::class,
+    \app\system\middleware\AdminAuthTokenMiddleware::class
+    // \app\adminapi\middleware\AdminCkeckRole::class
+]);

+ 3 - 3
config/database.php

@@ -23,11 +23,11 @@ return [
             // 服务器地址
             'hostname'          => env('database.hostname', '119.45.212.25'),
             // 数据库名
-            'database'          => env('database.database', 'lpw'),
+            'database'          => env('database.database', 'live'),
             // 用户名
-            'username'          => env('database.username', 'lpw'),
+            'username'          => env('database.username', 'live'),
             // 密码
-            'password'          => env('database.password', 'YRPBTMAzy885pwMt'),
+            'password'          => env('database.password', 'MJdWPeXSaWp5yWyG'),
             // 端口
             'hostport'          => env('database.hostport', '3306'),
             // 数据库连接参数

+ 3 - 3
env

@@ -6,9 +6,9 @@ DEFAULT_TIMEZONE = Asia/Shanghai
 [DATABASE]
 TYPE = mysql
 HOSTNAME = 119.45.212.25
-DATABASE = lpw
-USERNAME = lpw
-PASSWORD = "YRPBTMAzy885pwMt"
+DATABASE = live
+USERNAME = live
+PASSWORD = "MJdWPeXSaWp5yWyG"
 PREFIX = table_
 HOSTPORT = 3306
 CHARSET = utf8mb4

+ 46 - 0
library/basic/BaseStorage.php

@@ -0,0 +1,46 @@
+<?php
+
+namespace library\basic;
+
+
+/**
+ * Class BaseStorage
+ * @package crmeb\basic
+ */
+abstract class BaseStorage
+{
+    use \library\traits\ErrorTrait;
+
+    /**
+     * 驱动名称
+     * @var string
+     */
+    protected $name;
+
+    /**
+     * 驱动配置文件名
+     * @var string
+     */
+    protected $configFile;
+
+    /**
+     * BaseStorage constructor.
+     * @param string $name 驱动名
+     * @param string $configFile 驱动配置名
+     * @param array $config 其他配置
+     */
+    public function __construct(string $name, array $config = [], string $configFile = null)
+    {
+        $this->name = $name;
+        $this->configFile = $configFile;
+        $this->initialize($config);
+    }
+
+    /**
+     * 初始化
+     * @param array $config
+     * @return mixed
+     */
+    abstract protected function initialize(array $config);
+
+}

+ 209 - 0
library/basic/BaseUpload.php

@@ -0,0 +1,209 @@
+<?php
+
+namespace library\basic;
+
+use think\facade\Config;
+
+abstract class BaseUpload extends BaseStorage
+{
+
+    /**
+     * 图片信息
+     * @var array
+     */
+    protected $fileInfo;
+
+    /**
+     * 验证配置
+     * @var string
+     */
+    protected $validate;
+
+    /**
+     * 保存路径
+     * @var string
+     */
+    protected $path = '';
+
+    protected function initialize(array $config)
+    {
+        $this->fileInfo = new \StdClass();
+    }
+
+
+    /**
+     * 上传文件路径
+     * @param string $path
+     * @return $this
+     */
+    public function to(string $path)
+    {
+        $this->path = $path;
+        return $this;
+    }
+
+    /**
+     * 获取文件信息
+     * @return array
+     */
+    public function getFileInfo()
+    {
+        return $this->fileInfo;
+    }
+
+    /**
+     * 验证合法上传域名
+     * @param string $url
+     * @return string
+     */
+    protected function checkUploadUrl(string $url)
+    {
+        if ($url && strstr($url, 'http') === false) {
+            $url = 'http://' . $url;
+        }
+        return $url;
+    }
+
+    /**
+     * 获取系统配置
+     * @return mixed
+     */
+    protected function getConfig()
+    {
+        $config = Config::get($this->configFile . '.stores.' . $this->name, []);
+        if (empty($config)) {
+            $config['filesize'] = Config::get($this->configFile . '.filesize', []);
+            $config['fileExt'] = Config::get($this->configFile . '.fileExt', []);
+            $config['fileMime'] = Config::get($this->configFile . '.fileMime', []);
+        }
+        return $config;
+    }
+
+    /**
+     * 设置验证规则
+     * @param array|null $validate
+     * @return $this
+     */
+    public function validate(?array $validate = null)
+    {
+        if (is_null($validate)) {
+            $validate = $this->getConfig();
+        }
+        $this->extractValidate($validate);
+        return $this;
+    }
+
+    /**
+     * 提取上传验证
+     */
+    protected function extractValidate(array $validateArray)
+    {
+        $validate = [];
+        foreach ($validateArray as $key => $value) {
+            $validate[] = $key . ':' . (is_array($value) ? implode(',', $value) : $value);
+        }
+        $this->validate = implode('|', $validate);
+        unset($validate);
+    }
+
+    /**
+     * 提取文件名
+     * @param string $path
+     * @param string $ext
+     * @return string
+     */
+    protected function saveFileName(string $path = null, string $ext = 'jpg')
+    {
+        return ($path ? substr(md5($path), 0, 5) : '') . date('YmdHis') . rand(0, 9999) . '.' . $ext;
+    }
+
+    /**
+     * 获取文件类型和大小
+     * @param string $url
+     * @param bool $isData
+     * @return array
+     */
+    protected function getFileHeaders(string $url, $isData = true)
+    {
+        stream_context_set_default(['ssl' => ['verify_peer' => false, 'verify_peer_name' => false]]);
+        $header['size'] = 0;
+        $header['type'] = 'image/jpeg';
+        if (!$isData) {
+            return $header;
+        }
+        try {
+            $headerArray = get_headers(str_replace('\\', '/', $url), true);
+            if (!isset($headerArray['Content-Length'])) {
+                $header['size'] = 0;
+            }
+            if (!isset($headerArray['Content-Type'])) {
+                $header['type'] = 'image/jpeg';
+            }
+            if (is_array($headerArray['Content-Length']) && count($headerArray['Content-Length']) == 2) {
+                $header['size'] = $headerArray['Content-Length'][1];
+            }
+            if (is_array($headerArray['Content-Type']) && count($headerArray['Content-Type']) == 2) {
+                $header['type'] = $headerArray['Content-Type'][1];
+            }
+        } catch (\Exception $e) {
+        }
+        return $header;
+    }
+
+    /**
+     * 获取上传信息
+     * @return array
+     */
+    public function getUploadInfo()
+    {
+        if (isset($this->fileInfo->filePath)) {
+            if (strstr($this->fileInfo->filePath, 'http') === false) {
+                $url = request()->domain() . $this->fileInfo->filePath;
+            } else {
+                $url = $this->fileInfo->filePath;
+            }
+            $headers = $this->getFileHeaders($url);
+            return [
+                'name' => $this->fileInfo->fileName,
+                'size' => $headers['size'] ?? 0,
+                'type' => $headers['type'] ?? 'image/jpeg',
+                'dir' => $this->fileInfo->filePath,
+                'thumb_path' => $this->fileInfo->filePath,
+                'time' => time(),
+            ];
+        } else {
+            return [];
+        }
+    }
+
+    /**
+     * 文件上传
+     * @return mixed
+     */
+    abstract public function move(string $file = 'file');
+
+    /**
+     * 文件流上传
+     * @return mixed
+     */
+    abstract public function stream(string $fileContent, string $key = null);
+
+    /**
+     * 删除文件
+     * @return mixed
+     */
+    abstract public function delete(string $filePath);
+
+    /**
+     * 实例化上传
+     * @return mixed
+     */
+    abstract protected function app();
+
+    /**
+     * 获取上传密钥
+     * @return mixed
+     */
+    abstract public function getTempKeys();
+
+}

+ 16 - 0
library/services/FormBuilder.php

@@ -0,0 +1,16 @@
+<?php
+/**
+ *
+ * @author: xaboy<365615158@qq.com>
+ * @day: 2017/11/23
+ */
+
+namespace crmeb\services;
+
+use FormBuilder\Form;
+
+class FormBuilder extends Form
+{
+
+
+}

+ 54 - 2
library/services/UtilService.php

@@ -14,7 +14,6 @@ use library\exceptions\UtilException;
 
 class  UtilService {
 
-
     /**
      * 参数判断模型
      * @param $params   [
@@ -84,7 +83,6 @@ class  UtilService {
         return $p;
     }
 
-
     /**
      * 参数解析 | 返回
      * @param $params
@@ -122,4 +120,58 @@ class  UtilService {
         return $result;
     }
 
+    /**
+     * 获取POST请求的数据
+     * @param $params
+     * @param null $request
+     * @param bool $suffix
+     * @return array
+     * @throws \Exception
+     */
+    public static function postMore($params, $request = null, $suffix = false)
+    {
+        if ($request === null) $request = app('request');
+        $p = [];
+        $i = 0;
+        foreach ($params as $param) {
+            if (!is_array($param)) {
+                $p[$suffix == true ? $i++ : $param] = $request->param($param);
+            } else {
+                if (!isset($param[1])) $param[1] = null;
+                if (!isset($param[2])) $param[2] = '';
+                if (!isset($param[3])) $param[3] = '';
+                if (!isset($param[4])) $param[4] = '';
+                if (!isset($param[5])) $param[5] = '';
+                if (is_array($param[0])) {
+                    $name = is_array($param[1]) ? $param[0][0] . '/a' : $param[0][0] . '/' . $param[0][1];
+                    $keyName = $param[0][0];
+                } else {
+                    $name = is_array($param[1]) ? $param[0] . '/a' : $param[0];
+                    $keyName = $param[0];
+                }
+                $p[$suffix == true ? $i++ : (isset($param[3]) && $param[3] ? $param[3] : $keyName)] = $request->param($name, $param[1], $param[2]);
+                if (!empty_check($param[4])) {
+                    if (!is_array($param[4])) {
+                        if (is_string($param[4]) && !function_exists($param[4])) {
+                            throw new UtilException('验证的方法' . $param[4] . '未定义');
+                        }
+                        if ($param[4]($request->param($name, $param[1], $param[2]))) {
+                            throw new UtilException($param[5]);
+                        }
+                    } else {
+                        foreach ($param[4] as $k => $v) {
+                            if (is_string($v) && !function_exists($v)) {
+                                throw new UtilException('验证的方法' . $v . '未定义');
+                            }
+                            if ($v($request->param($name, $param[1], $param[2]))) {
+                                throw new UtilException(is_array($param[5]) ? $param[5][$k] : $param[5]);
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        return $p;
+    }
+
 }

+ 39 - 0
library/traits/ErrorTrait.php

@@ -0,0 +1,39 @@
+<?php
+
+namespace library\traits;
+
+/**
+ *
+ * Class BaseError
+ * @package crmeb\basic
+ */
+trait ErrorTrait
+{
+    /**
+     * 错误信息
+     * @var string
+     */
+    protected $error;
+
+    /**
+     * 设置错误信息
+     * @param string|null $error
+     * @return bool
+     */
+    protected function setError(?string $error = null)
+    {
+        $this->error = $error ?: '未知错误';
+        return false;
+    }
+
+    /**
+     * 获取错误信息
+     * @return string
+     */
+    public function getError()
+    {
+        $error = $this->error;
+        $this->error = null;
+        return $error;
+    }
+}