15669368801 4 年 前
コミット
25e4cf0504

+ 28 - 0
app/adminapi/controller/v1/company/Company.php

@@ -0,0 +1,28 @@
+<?php
+
+namespace app\adminapi\controller\v1\company;
+
+use app\adminapi\controller\AuthController;
+use crmeb\services\{UtilService as Util};
+use app\models\section\SectionModel;
+use app\models\company\CompanyModel;
+use think\Request;
+
+class Company extends AuthController
+{
+    /**
+     * 显示资源列表
+     *
+     * @return \think\Response
+     */
+    public function index()
+    {
+        $where = Util::getMore([
+            ['title', ''],
+            ['sid', 0],
+            ['page', 1],
+            ['limit', 10]
+        ], $this->request);
+        $list = CompanyModel::systemPage($where);
+        return $this->success($list);
+    }

+ 144 - 0
app/adminapi/controller/v1/section/Section.php

@@ -0,0 +1,144 @@
+<?php
+
+namespace app\adminapi\controller\v1\section;
+
+use app\adminapi\controller\AuthController;
+use app\models\section\SectionModel;
+use think\Request;
+use think\facade\Route as Url;
+use crmeb\services\{
+    FormBuilder as Form, UtilService as Util
+};
+
+/**
+ * 部门管理
+ */
+class Section extends AuthController
+{
+    /**
+     * 显示资源列表
+     */
+    public function index()
+    {
+        $where = Util::getMore([
+            ['page', 1],
+            ['limit', 15],
+            ['status', ''],
+            ['title', ''],
+        ], $this->request);
+        $list = SectionModel::systemPage($where);
+        return $this->success($list);
+    }
+
+    /**
+     * 显示创建资源表单页.
+     *
+     * @return \think\Response
+     */
+    public function create()
+    {
+        $f = array();
+        $f[] = Form::input('title', '部门名称');
+        $f[] = Form::input('intr', '部门简介')->type('textarea');
+        $f[] = Form::frameImageOne('image', '部门图片', Url::buildUrl('admin/widget.images/index', array('fodder' => 'image')))->icon('ios-add')->width('60%')->height('435px');
+        $f[] = Form::number('sort', '排序', 0);
+        $f[] = Form::radio('status', '状态', 1)->options([['value' => 1, 'label' => '显示'], ['value' => 0, 'label' => '隐藏']]);
+        return $this->makePostForm('添加部门', $f, Url::buildUrl('/section/section'), 'POST');
+    }
+
+    /**
+     * 保存新建的资源
+     *
+     * @param \think\Request $request
+     * @return \think\Response
+     */
+    public function save(Request $request)
+    {
+        $data = Util::postMore([
+            'title',
+            'intr',
+            ['image', []],
+            ['sort', 0],
+            'status',]);
+        if (!$data['title']) return $this->fail('请输入部门名称');
+        if (count($data['image']) != 1) return $this->fail('请选择部门图片,并且只能上传一张');
+        if ($data['sort'] < 0) return $this->fail('排序不能是负数');
+        $data['add_time'] = time();
+        $data['image'] = $data['image'][0];
+        $res = SectionModel::create($data);
+        return $this->success('添加部门成功!');
+    }
+
+    /**
+     * 显示编辑资源表单页.
+     *
+     * @param int $id
+     * @return \think\Response
+     */
+    public function edit($id)
+    {
+        if (!$id) return $this->fail('参数错误');
+        $section = SectionModel::get($id)->getData();
+        if (!$section) return $this->fail('数据不存在!');
+        $f = array();
+        $f[] = Form::input('title', '部门名称', $section['title']);
+        $f[] = Form::input('intr', '部门简介', $section['intr'])->type('textarea');
+        $f[] = Form::frameImageOne('image', '部门图片', Url::buildUrl('admin/widget.images/index', array('fodder' => 'image')), $section['image'])->icon('ios-add')->width('60%')->height('435px');
+        $f[] = Form::number('sort', '排序', 0);
+        $f[] = Form::radio('status', '状态', $section['status'])->options([['value' => 1, 'label' => '显示'], ['value' => 0, 'label' => '隐藏']]);
+        return $this->makePostForm('编辑部门', $f, Url::buildUrl('/section/section/' . $id), 'PUT');
+    }
+
+    /**
+     * 保存更新的资源
+     *
+     * @param \think\Request $request
+     * @param int $id
+     * @return \think\Response
+     */
+    public function update(Request $request, $id)
+    {
+        $data = Util::postMore([
+            'title',
+            'intr',
+            ['image', []],
+            ['sort', 0],
+            'status',]);
+        if (!$data['title']) return $this->fail('请输入分类名称');
+        if (count($data['image']) != 1) return $this->fail('请选择分类图片,并且只能上传一张');
+        if ($data['sort'] < 0) return $this->fail('排序不能是负数');
+        $data['image'] = $data['image'][0];
+        if (!SectionModel::get($id)) return $this->fail('编辑的记录不存在!');
+        SectionModel::edit($data, $id);
+        return $this->success('修改成功!');
+    }
+
+    /**
+     * 删除指定资源
+     *
+     * @param int $id
+     * @return \think\Response
+     */
+    public function delete($id)
+    {
+        $res = SectionModel::edit(['is_del' => 1], $id, 'id');
+        if (!$res)
+            return $this->fail(SectionModel::getErrorInfo('删除失败,请稍候再试!'));
+        else
+            return $this->success('删除成功!');
+    }
+
+    /**
+     * 修改状态
+     * @param $id
+     * @param $status
+     * @return mixed
+     */
+    public function set_status($id, $status)
+    {
+        if ($status == '' || $id == 0) return $this->fail('参数错误');
+        SectionModel::where(['id' => $id])->update(['status' => $status]);
+        return $this->success($status == 0 ? '隐藏成功' : '显示成功');
+    }
+
+}

+ 18 - 0
app/adminapi/route/company.php

@@ -0,0 +1,18 @@
+<?php
+
+use think\facade\Route;
+
+/**
+ * 公司管理 相关路由
+ */
+Route::group('company', function () {
+    //公司资源路由
+    Route::resource('company', 'v1.company.Company')->name('CompanyResource');
+    //修改状态
+    Route::put('company/set_status/:id/:status', 'v1.company.Company/set_status')->name('CompanyStatus');
+
+})->middleware([
+    \app\http\middleware\AllowOriginMiddleware::class,
+    \app\adminapi\middleware\AdminAuthTokenMiddleware::class,
+    \app\adminapi\middleware\AdminCkeckRole::class
+]);

+ 18 - 0
app/adminapi/route/section.php

@@ -0,0 +1,18 @@
+<?php
+
+use think\facade\Route;
+
+/**
+ * 部门管理 相关路由
+ */
+Route::group('section', function () {
+    //部门资源路由
+    Route::resource('section', 'v1.section.Section')->name('SectionResource');
+    //修改状态
+    Route::put('section/set_status/:id/:status', 'v1.section.Section/set_status')->name('SectionStatus');
+
+})->middleware([
+    \app\http\middleware\AllowOriginMiddleware::class,
+    \app\adminapi\middleware\AdminAuthTokenMiddleware::class,
+    \app\adminapi\middleware\AdminCkeckRole::class
+]);

+ 37 - 0
app/models/company/CompanyModel.php

@@ -0,0 +1,37 @@
+<?php
+
+namespace app\models\company;
+
+use think\facade\Db;
+use crmeb\traits\ModelTrait;
+use crmeb\basic\BaseModel;
+
+class CompanyModel extends BaseModel
+{
+	/**
+     * 数据表主键
+     * @var string
+     */
+    protected $pk = 'id';
+
+    /**
+     * 模型名称
+     * @var string
+     */
+    protected $name = 'company';
+
+    use ModelTrait;
+
+    public static function systemPage($where)
+    {
+        $model = new self;
+        if ($where['title'] !== '') $model = $model->where('title', 'LIKE', "%$where[title]%");
+        if ($where['sid'] !== '') $model = $model->where('sid', $where['sid']);
+        $model = $model->where('is_del', 0);
+        $model = $model->order('sort desc,id desc');
+        $count = $model->count();
+        $list = $model->page((int)$where['page'], (int)$where['limit'])->select()->toArray();
+        return compact('count', 'list');
+    }
+
+}

+ 37 - 0
app/models/section/SectionModel.php

@@ -0,0 +1,37 @@
+<?php
+
+namespace app\models\section;
+
+use think\facade\Db;
+use crmeb\traits\ModelTrait;
+use crmeb\basic\BaseModel;
+
+class SectionModel extends BaseModel
+{
+	/**
+     * 数据表主键
+     * @var string
+     */
+    protected $pk = 'id';
+
+    /**
+     * 模型名称
+     * @var string
+     */
+    protected $name = 'section';
+
+    use ModelTrait;
+
+    public static function systemPage($where)
+    {
+        $model = new self;
+        if ($where['title'] !== '') $model = $model->where('title', 'LIKE', "%$where[title]%");
+        if ($where['status'] !== '') $model = $model->where('status', $where['status']);
+        $model = $model->where('is_del', 0);
+        $model = $model->order('sort desc,id desc');
+        $count = $model->count();
+        $list = $model->page((int)$where['page'], (int)$where['limit'])->select()->toArray();
+        return compact('count', 'list');
+    }
+
+}