Forráskód Böngészése

智能设备分类管理

gorden 1 éve
szülő
commit
93257f34c4

+ 55 - 0
app/admin/controller/smart_devices/ProductController.php

@@ -0,0 +1,55 @@
+<?php
+
+namespace app\admin\controller\smart_devices;
+
+use app\admin\validate\smart_devices\ProductValidate;
+use app\controller\Curd;
+use app\model\SmartDevicesProduct;
+use support\Request;
+use support\Response;
+
+class ProductController extends Curd
+{
+    public function __construct()
+    {
+        $this->model = new SmartDevicesProduct();
+        $this->validate = true;
+        $this->validateClass = new ProductValidate();
+    }
+
+    /**
+     * @Desc 列表
+     * @Author Gorden
+     * @Date 2024/3/8 13:34
+     *
+     * @param Request $request
+     * @return Response
+     * @throws \support\exception\BusinessException
+     */
+    public function select(Request $request): Response
+    {
+        [$where, $format, $limit, $field, $order] = $this->selectInput($request);
+        $order = $request->get('order', 'desc');
+        $field = $field ?? 'product_add_time';
+        $where['product_is_del'] = 0;
+        $query = $this->doSelect($where, $field, $order);
+        return $this->doFormat($query, $format, $limit);
+    }
+
+    /**
+     * @Desc 删除
+     * @Author Gorden
+     * @Date 2024/3/8 13:34
+     *
+     * @param Request $request
+     * @return Response
+     * @throws \support\exception\BusinessException
+     */
+    public function delete(Request $request): Response
+    {
+        $ids = $this->deleteInput($request);
+        $this->doSoftDelete($ids, ['product_is_del' => 1]);
+
+        return json_success('success');
+    }
+}

+ 27 - 0
app/admin/validate/smart_devices/ProductValidate.php

@@ -0,0 +1,27 @@
+<?php
+
+namespace app\admin\validate\smart_devices;
+
+use think\Validate;
+
+class ProductValidate extends Validate
+{
+    protected $rule = [
+        'product_id' => 'require|integer',
+        'product_category_id' => 'require|integer',
+        'product_name' => 'require|max:255',
+        'product_img' => 'regex:/^[0-9a-zA-Z\.\/]+$/',
+        'product_brand' => 'max:255',
+        'product_code' => 'max:255',
+        'product_type' => 'require|integer',
+        'product_is_bind_many' => 'require|integer',
+        'product_is_bind_rome' => 'require|integer'
+    ];
+
+    protected $message = [];
+
+    protected $scene = [
+        'add' => ['product_category_id', 'product_name', 'product_img', 'product_brand', 'product_code', 'product_type', 'product_is_bind_many', 'product_is_bind_rome'],
+        'update' => ['product_id', 'product_category_id', 'product_name', 'product_img', 'product_brand', 'product_code', 'product_type', 'product_is_bind_many', 'product_is_bind_rome'],
+    ];
+}

+ 18 - 0
app/model/SmartDevicesProduct.php

@@ -0,0 +1,18 @@
+<?php
+
+namespace app\model;
+
+use support\Model;
+
+class SmartDevicesProduct extends Model
+{
+    protected $table = 'smart_devices_product';
+
+    protected $primaryKey = 'product_id';
+
+    protected $dateFormat = 'U';
+
+    const CREATED_AT = 'product_create_time';
+
+    const UPDATED_AT = 'product_update_time';
+}

+ 8 - 8
route/admin.php

@@ -352,13 +352,13 @@ Route::group('/admin', function () {
             \app\middleware\AdminAuthCheck::class
         ]);
         /* 智能设备管理 */
-//        Route::group('/deptPremises', function () {
-//            Route::get('/list', [\app\admin\controller\marketing\DeptPremisesController::class, 'select']);
-//            Route::post('/add', [\app\admin\controller\marketing\DeptPremisesController::class, 'insert']);
-//            Route::post('/update', [\app\admin\controller\marketing\DeptPremisesController::class, 'update']);
-//            Route::delete('/delete', [\app\admin\controller\marketing\DeptPremisesController::class, 'delete']);
-//        })->middleware([
-//            \app\middleware\AdminAuthCheck::class
-//        ]);
+        Route::group('/product', function () {
+            Route::get('/list', [\app\admin\controller\smart_devices\ProductController::class, 'select']);
+            Route::post('/add', [\app\admin\controller\smart_devices\ProductController::class, 'insert']);
+            Route::post('/update', [\app\admin\controller\smart_devices\ProductController::class, 'update']);
+            Route::delete('/delete', [\app\admin\controller\smart_devices\ProductController::class, 'delete']);
+        })->middleware([
+            \app\middleware\AdminAuthCheck::class
+        ]);
     });
 });