Răsfoiți Sursa

自定义表单

rkljw 2 zile în urmă
părinte
comite
8e5b685307

+ 150 - 0
app/Controller/FormController.php

@@ -0,0 +1,150 @@
+<?php
+
+declare(strict_types=1);
+namespace App\Controller;
+
+use App\JsonRpc\FormServiceInterface;
+use Hyperf\Di\Annotation\Inject;
+use Hyperf\HttpServer\Annotation\AutoController;
+use App\Tools\Result;
+use Hyperf\Validation\Contract\ValidatorFactoryInterface;
+use App\Constants\ErrorCode;
+use Hyperf\Context\Context;
+use App\Service\ImportQueueService;
+/**
+ * ClassFormController
+ * @package App\Controller
+ */
+
+class FormController extends AbstractController
+    {
+    #[Inject]
+    protected ValidatorFactoryInterface $validationFactory;
+
+    #[Inject]
+    protected ImportQueueService $Iservice;
+
+    /**
+     * @var FormServiceInterface
+     */
+    #[Inject]
+    private $formServiceClient;
+ 
+    /**
+     * 添加网站
+     * @return array
+     */
+    public function addGlobalTable()
+    {
+        $requireData = $this->request->all();
+        $validator = $this->validationFactory->make(
+            $requireData,
+            [
+                'website_id'=> 'required',
+                'name'=> 'required',
+                'table'=> 'required',
+            ],
+            [
+                'website_id.required' => '网站ID不能为空',
+                'name.required' => '表单名称不能为空',
+                'table.required' => '表单表名不能为空',
+            ]
+        );
+        if ($validator->fails()) {
+            $errorMessage = $validator->errors()->first();
+            return Result::error($errorMessage);
+        }
+
+
+        
+        $result = $this->formServiceClient->addGlobalTable($requireData);
+        if ($result['code'] != ErrorCode::SUCCESS) {
+            return Result::error($result['message'],0,[]);
+        }
+        return Result::success($result['data']);
+    }
+    /**
+     * 全局表单列表
+     * @return array
+     */
+    public function getGlobalTableList()    
+    {
+        $requireData = $this->request->all();   
+        $validator = $this->validationFactory->make(
+            $requireData,
+            [
+                'page'=> 'required',
+                'pageSize'=> 'required',
+            ],
+            [
+                'page.required' => '页码不能为空',
+                'pageSize.required' => '每页显示条数不能为空',
+            ]
+        );
+        if ($validator->fails()) {
+            $errorMessage = $validator->errors()->first();
+            return Result::error($errorMessage);
+        }
+        $result = $this->formServiceClient->getGlobalTableList($requireData);
+        if ($result['code']!= ErrorCode::SUCCESS) {
+            return Result::error($result['message'],0,[]);
+        }
+        return Result::success($result['data']);
+    }
+    /**
+     * 修改全局表单
+     */
+    public function upGlobalTable()
+    {
+        $requireData = $this->request->all();
+        $validator = $this->validationFactory->make(
+            $requireData,
+            [
+                'website_id'=> 'required',
+                'name'=> 'required',
+                'table'=> 'required',
+                'id'=> 'required',
+            ],
+            [
+                'website_id.required' => '网站ID不能为空',
+                'name.required' => '表单名称不能为空',
+                'table.required' => '表单表名不能为空',
+                'id.required' => 'id不能为空',
+            ]
+        );
+        if ($validator->fails()) {
+            $errorMessage = $validator->errors()->first();
+            return Result::error($errorMessage);
+        }
+        $result = $this->formServiceClient->upGlobalTable($requireData);
+        if ($result['code'] != ErrorCode::SUCCESS) {
+            return Result::error($result['message'],0,[]);
+        }
+        return Result::success($result['data']);
+    }
+    /** 
+     * 删除全局表单
+    */
+    public function delGlobalTable()
+    {
+        $requireData = $this->request->all();
+        $validator = $this->validationFactory->make(
+            $requireData,
+            [
+                'id'=> 'required',
+            ],
+            [
+                'id.required' => 'id不能为空',
+            ]
+        );
+        if ($validator->fails()) {
+            $errorMessage = $validator->errors()->first();
+            return Result::error($errorMessage);
+        }
+        $result = $this->formServiceClient->delGlobalTable($requireData);
+        if ($result['code'] != ErrorCode::SUCCESS) {
+            return Result::error($result['message'],0,[]);
+        }
+        return Result::success($result['data']);
+    }
+}

+ 64 - 0
app/JsonRpc/FormService.php

@@ -0,0 +1,64 @@
+<?php
+
+namespace App\JsonRpc;
+
+use Hyperf\RpcClient\AbstractServiceClient;
+use App\Model\GlobalTable;
+use App\Tools\Result;
+
+class FormService extends AbstractServiceClient implements FormServiceInterface
+{
+    /**
+     * 定义对应服务提供者的服务名称
+     * @var string
+     */
+    protected string $serviceName = 'FormService';
+    /**
+     * 定义对应服务提供者的服务协议
+     * @var string
+     */
+    protected string $protocol = 'jsonrpc-http';
+
+    /**
+     * @param array $data
+     * @return array|mixed
+     */
+    public function addGlobalTable(array $data)
+    {
+        return $this->__request(__FUNCTION__, $data);
+    }
+    /**
+     * @param array $data
+     * @return array|mixed
+     */
+    public function getGlobalTableList(array $data)
+    {
+        return $this->__request(__FUNCTION__, $data);
+    }
+    /**
+     * @param array $data
+     * @return array|mixed
+     */
+    public function getGlobalTable(array $data)
+    {
+        return $this->__request(__FUNCTION__, $data);
+    }
+
+    /**
+     * @param array $data
+     * @return array|mixed
+     */
+    public function upGlobalTable(array $data)
+    {
+        return $this->__request(__FUNCTION__, $data);
+    }
+
+    /**
+     * @param array $data
+     * @return array|mixed
+     */
+    public function delGlobalTable(array $data)
+    {
+        return $this->__request(__FUNCTION__, $data);
+    }
+}

+ 28 - 0
app/JsonRpc/FormServiceInterface.php

@@ -0,0 +1,28 @@
+<?php
+
+namespace App\JsonRpc;
+
+interface FormServiceInterface
+{
+    /**
+     * @param array $data
+     */
+    public function addGlobalTable(array $data);
+    /**
+     * @param array $data
+     */
+    public function getGlobalTableList(array $data);
+    /**
+     * @param array $data
+     */
+    public function getGlobalTable(array $data);
+    /**
+     * @param array $data
+     */
+    public function upGlobalTable(array $data);
+    /**
+     * @param array $data
+     */
+    public function delGlobalTable(array $data);
+    
+}

+ 2 - 1
app/JsonRpc/WebsiteServiceInterface.php

@@ -511,7 +511,8 @@ interface WebsiteServiceInterface
      * @param array $data
      * @return mixed
      */
-    public function upStaticResource(array $data);    /**
+    public function upStaticResource(array $data);
+    /**
      * @param array $data
      * @return mixed
      */

+ 1 - 0
app/Middleware/Auth/PublicMiddleware.php

@@ -50,6 +50,7 @@ class PublicMiddleware implements MiddlewareInterface
                 ];
 
                 $result = $this->websiteServiceClient->getWebsiteId($data);
+                var_dump($result);
                 if(!isset($result['data']['id']) || !$result['data']['id']){
                     return $this->response->json(
                         [

Fișier diff suprimat deoarece este prea mare
+ 349 - 139
composer.lock


+ 24 - 0
config/api/form.php

@@ -0,0 +1,24 @@
+<?php
+
+declare(strict_types=1);
+
+
+use App\Middleware\Auth\FooMiddleware;
+use Hyperf\HttpServer\Router\Router;
+use App\Controller\FormController;
+
+Router::addGroup(
+    '/form', function () {
+        //添加全局表单
+        Router::post('/addGlobalTable', [FormController::class, 'addGlobalTable']);
+        //修改全局表单
+        Router::post('/upGlobalTable', [FormController::class, 'upGlobalTable']);
+        //查看全局表单 
+        Router::get('/getGlobalTable', [FormController::class, 'getGlobalTable']);
+        //全局表单列表 
+        Router::get('/getGlobalTableList', [FormController::class, 'getGlobalTableList']);
+        //删除全局表单
+        Router::post('/delGlobalTable', [FormController::class, 'delGlobalTable']);
+    },
+    ['middleware' => [FooMiddleware::class]]
+);

+ 10 - 0
config/autoload/services.php

@@ -153,6 +153,16 @@ return [
                 ['host' => '127.0.0.1', 'port' => 9510],
             ],
         ],
+        [
+            //全局表单服务
+            'name' => 'FormService',
+            'service' => \App\JsonRpc\FormServiceInterface::class,
+
+            // 直接对指定的节点进行消费,通过下面的 nodes 参数来配置服务提供者的节点信息
+            'nodes' => [
+                ['host' => '127.0.0.1', 'port' => 9509],
+            ],
+        ],
     ],
 
 ];

+ 1 - 0
config/routes.php

@@ -39,3 +39,4 @@ require __DIR__ . '/api/order.php';
 require __DIR__ . '/api/collector.php';
 require __DIR__ . '/api/footer.php';
 require __DIR__ . '/api/client.php';
+require __DIR__ . '/api/form.php';

Unele fișiere nu au fost afișate deoarece prea multe fișiere au fost modificate în acest diff