Explorar o código

'课程安排管理+地块管理'

gorden hai 1 ano
pai
achega
b4f35340c2

+ 128 - 0
app/admin/controller/life/CollegeTeaching.php

@@ -0,0 +1,128 @@
+<?php
+
+namespace app\admin\controller\life;
+
+use app\admin\validate\life\CollegeTeachingValidate;
+use app\controller\Curd;
+use app\model\CollegeTeaching as teachingModel;
+use support\Request;
+use support\Response;
+
+class CollegeTeaching extends Curd
+{
+    public function __construct()
+    {
+        $this->model = new teachingModel();
+        $this->validate = true;
+        $this->validateClass = new CollegeTeachingValidate();
+    }
+
+    /**
+     * @Desc 列表
+     * @Author Gorden
+     * @Date 2024/2/27 10:29
+     *
+     * @param Request $request
+     * @return Response
+     * @throws \support\exception\BusinessException
+     */
+    public function select(Request $request): Response
+    {
+        [$where, $format, $limit, $field, $order] = $this->selectInput($request);
+        $where['teaching_is_del'] = 0;
+        $query = $this->doSelect($where, $field, $order);
+        return $this->doFormat($query, $format, $limit);
+    }
+
+    /**
+     * @Desc 新增
+     * @Author Gorden
+     * @Date 2024/2/27 10:19
+     *
+     * @param Request $request
+     * @return Response
+     * @throws \support\exception\BusinessException
+     */
+    public function insert(Request $request): Response
+    {
+        if ($this->validate && !$this->validateClass->scene('add')->check($request->post())) {
+            return json_fail($this->validateClass->getError());
+        }
+
+        $data = $this->insertInput($request);
+        $data['teaching_time'] = strtotime($data['teaching_time']);
+        $this->doInsert($data);
+        return json_success('success');
+    }
+
+    /**
+     * @Desc 修改
+     * @Author Gorden
+     * @Date 2024/2/27 10:26
+     *
+     * @param Request $request
+     * @return Response
+     * @throws \support\exception\BusinessException
+     */
+    public function update(Request $request): Response
+    {
+        if ($this->validate && !$this->validateClass->scene('update')->check($request->post())) {
+            return json_fail($this->validateClass->getError());
+        }
+
+        [$id, $data] = $this->updateInput($request);
+        $data['teaching_time'] = strtotime($data['teaching_time']);
+        $this->doUpdate($id, $data);
+        return json_success('success');
+
+    }
+
+    /**
+     * @Desc 删除
+     * @Author Gorden
+     * @Date 2024/2/27 10:35
+     *
+     * @param Request $request
+     * @return Response
+     * @throws \support\exception\BusinessException
+     */
+    public function delete(Request $request): Response
+    {
+        $ids = $this->deleteInput($request);
+        $this->doSoftDelete($ids, ['teaching_is_del' => 1]);
+
+        return json_success('success');
+    }
+
+
+    /**
+     * @Desc
+     * @Author Gorden
+     * @Date 2024/2/27 10:30
+     *
+     * @param $query
+     * @param $format
+     * @param $limit
+     * @return Response
+     */
+    protected function doFormat($query, $format, $limit): Response
+    {
+        $methods = [
+            'select' => 'formatSelect',
+            'tree' => 'formatTree',
+            'table_tree' => 'formatTableTree',
+            'normal' => 'formatNormal',
+        ];
+        $paginator = $query->paginate($limit);
+        $total = $paginator->total();
+        $items = $paginator->items();
+        if (method_exists($this, "afterQuery")) {
+            $items = call_user_func([$this, "afterQuery"], $items);
+        }
+        $format_function = $methods[$format] ?? 'formatNormal';
+        foreach ($items as &$item) {
+            $item->teaching_time = date('Y-m-d H:i:s',$item->teaching_time);
+        }
+        return call_user_func([$this, $format_function], $items, $total);
+    }
+}

+ 53 - 0
app/admin/controller/life/FarmLand.php

@@ -0,0 +1,53 @@
+<?php
+
+namespace app\admin\controller\life;
+
+use app\admin\validate\life\FarmLandValidate;
+use app\controller\Curd;
+use app\model\FarmLand as FarmLandModel;
+use support\Request;
+use support\Response;
+
+class FarmLand extends Curd
+{
+    public function __construct()
+    {
+        $this->model = new FarmLandModel();
+        $this->validate = true;
+        $this->validateClass = new FarmLandValidate();
+    }
+
+    /**
+     * @Desc 列表
+     * @Author Gorden
+     * @Date 2024/2/27 14:46
+     *
+     * @param Request $request
+     * @return Response
+     * @throws \support\exception\BusinessException
+     */
+    public function select(Request $request): Response
+    {
+        [$where, $format, $limit, $field, $order] = $this->selectInput($request);
+        $where['land_is_del'] = 0;
+        $query = $this->doSelect($where, $field, $order);
+        return $this->doFormat($query, $format, $limit);
+    }
+
+    /**
+     * @Desc 删除
+     * @Author Gorden
+     * @Date 2024/2/27 14:49
+     *
+     * @param Request $request
+     * @return Response
+     * @throws \support\exception\BusinessException
+     */
+    public function delete(Request $request): Response
+    {
+        $ids = $this->deleteInput($request);
+        $this->doSoftDelete($ids, ['land_is_del' => 1]);
+
+        return json_success('success');
+    }
+}

+ 24 - 0
app/admin/validate/life/CollegeTeachingValidate.php

@@ -0,0 +1,24 @@
+<?php
+
+namespace app\admin\validate\life;
+
+use think\Validate;
+
+class CollegeTeachingValidate extends Validate
+{
+    protected $rule = [
+        'teaching_id' => 'require|integer',
+        'teaching_name' => 'require|chsDash',
+        'teaching_time' => 'date',
+        'teaching_courses_id' => 'require|integer',
+        'teaching_price' => 'float',
+        'teaching_status' => 'integer',
+        'teaching_is_del' => 'integer',
+    ];
+
+    protected $message = [];
+
+    protected $scene = [
+        'add' => ['teaching_name', 'teaching_courses_id', 'teaching_price', 'teaching_status'],
+    ];
+}

+ 23 - 0
app/admin/validate/life/FarmLandValidate.php

@@ -0,0 +1,23 @@
+<?php
+
+namespace app\admin\validate\life;
+
+use think\Validate;
+
+class FarmLandValidate extends Validate
+{
+    protected $rule = [
+        'land_id' => 'require|integer',
+        'land_name' => 'require|chsDash',
+        'land_price' => 'require|float',
+        'land_long' => 'require|regex:/^[0-9\.]+$/',
+        'land_lat' => 'require|regex:/^[0-9\.]+$/'
+    ];
+
+    protected $message = [];
+
+    protected $scene = [
+        'add' => ['land_name', 'land_price', 'land_long', 'land_lat'],
+        'update' => ['land_id', 'land_name', 'land_price', 'land_long', 'land_lat'],
+    ];
+}

+ 18 - 0
app/model/CollegeTeaching.php

@@ -0,0 +1,18 @@
+<?php
+
+namespace app\model;
+
+use support\Model;
+
+class CollegeTeaching extends Model
+{
+    protected $table = 'college_teaching';
+
+    protected $primaryKey = 'teaching_id';
+
+    protected $dateFormat = 'U';
+
+    public const CREATED_AT = 'teaching_addTime';
+
+    public const UPDATED_AT = 'teaching_updateTime';
+}

+ 18 - 0
app/model/FarmLand.php

@@ -0,0 +1,18 @@
+<?php
+
+namespace app\model;
+
+use support\Model;
+
+class FarmLand extends Model
+{
+    protected $table = 'farm_land';
+
+    protected $primaryKey = 'land_id';
+
+    protected $dateFormat = 'U';
+
+    public const CREATED_AT = 'land_addTime';
+
+    public const UPDATED_AT = 'land_updateTime';
+}

+ 18 - 0
route/api.php

@@ -137,5 +137,23 @@ Route::group('/admin', function () {
         })->middleware([
             \app\middleware\AdminAuthCheck::class
         ]);
+        /* 课程安排管理 */
+        Route::group('/teaching', function () {
+            Route::get('/list', [\app\admin\controller\life\CollegeTeaching::class, 'select']);
+            Route::post('/add', [\app\admin\controller\life\CollegeTeaching::class, 'insert']);
+            Route::post('/update', [\app\admin\controller\life\CollegeTeaching::class, 'update']);
+            Route::delete('/delete', [\app\admin\controller\life\CollegeTeaching::class, 'delete']);
+        })->middleware([
+            \app\middleware\AdminAuthCheck::class
+        ]);
+        /* 地块管理 */
+        Route::group('/farmLand', function () {
+            Route::get('/list', [\app\admin\controller\life\FarmLand::class, 'select']);
+            Route::post('/add', [\app\admin\controller\life\FarmLand::class, 'insert']);
+            Route::post('/update', [\app\admin\controller\life\FarmLand::class, 'update']);
+            Route::delete('/delete', [\app\admin\controller\life\FarmLand::class, 'delete']);
+        })->middleware([
+            \app\middleware\AdminAuthCheck::class
+        ]);
     });
 });