wang jun 2 lat temu
rodzic
commit
902d8cd9f2

+ 27 - 0
application/client/controller/Tube.php

@@ -0,0 +1,27 @@
+<?php
+namespace app\client\controller;
+
+use app\client\logic\tubelogic;
+use app\common\controller\BaseController;
+
+class Tube extends BaseController
+{
+    /**
+     * 获取当日数据
+     *
+     * @return void
+     * @author wj
+     * @date 2022-08-02
+     */
+    public function gettodaydata()
+    {
+        $param = request()->post();
+        $param['date'] = date('Y-m-d');
+        $l_t = new tubelogic();
+        $result = $l_t->getdatabydate($param);
+        if (empty($result['status'])) {
+            return backjson2(0, $result['msg']);
+        }
+        return backjson2(1, "查询成功", $result['data']);
+    }
+}

+ 64 - 0
application/client/logic/tubelogic.php

@@ -0,0 +1,64 @@
+<?php
+namespace app\client\logic;
+
+use app\common\logic\baselogic;
+use app\common\model\tubemodel;
+
+/**
+ * 登记记录表
+ *
+ * @author wj
+ * @date 2022-07-22
+ */
+class tubelogic extends baselogic
+{
+
+    /**
+     * 设置请求数据规则
+     * 20220107
+     * wj
+     */
+    protected function setrules()
+    {
+        $list = [
+            'gettodaydata' => [
+                ['name' => 'page', 'title' => '当前页数', 'require' => false, 'type' => 'numeric', 'default' => 1],
+                ['name' => 'size', 'title' => '每页条数', 'require' => false, 'type' => 'numeric', 'default' => 10],
+                ['name' => 'date', 'title' => '日期', 'require' => false, 'type' => 'numeric', 'default' => 10],
+            ],
+        ];
+        return $list;
+    }
+    /**
+     * 根据日期获取未处理数据
+     *
+     * @param  [type] $arr
+     * @return void
+     * @author wj
+     * @date 2022-08-02
+     */
+    public function getdatabydate($arr)
+    {
+        $result = $this->checkparam(__FUNCTION__, $arr);
+        if (1 != $result['status']) {
+            return $result;
+        }
+        $data = $result['data'];
+        $date = $data['date'];
+        $page = $data['page'];
+        $size = $data['size'];
+        $m_t = new tubemodel();
+        $typelist = $m_t->gettesttypelist();
+        $where = ['create_date' => ['like', '%' . $date . '%'], 'detection_result' => 0];
+        $size = 10;
+        $count = $m_t->getList($where, 'count');
+        if (empty($count)) {
+            return backarr(0, "无数据");
+        }
+        $list = $m_t->getList($where, '*', $page, $size, 'id asc')->toArray();
+        if (empty($list)) {
+            return backarr(0, "无数据");
+        }
+        return backarr(1, "查询成功", $list);
+    }
+}

+ 16 - 0
application/common/controller/BaseController.php

@@ -0,0 +1,16 @@
+<?php
+/*
+ * @Author: wang jun
+ * @Date: 2022-01-18 10:57:14
+ * @Last Modified by: wang jun
+ * @Last Modified time: 2022-01-19 10:38:56
+ * 微信类
+ */
+namespace app\common\controller;
+
+use think\Controller;
+
+class BaseController extends Controller
+{
+
+}

+ 102 - 0
application/common/logic/baselogic.php

@@ -0,0 +1,102 @@
+<?php
+/*
+ * @Author: wang jun
+ * @Date: 2022-01-18 11:12:23
+ * @Last Modified by: wang jun
+ * @Last Modified time: 2022-01-19 15:58:46
+ * 微信类
+ */
+namespace app\common\logic;
+
+use think\facade\Log;
+
+class baselogic
+{
+    /**
+     * 根据配置验证param
+     * wj
+     * 20220119
+     * [[name=>'',title=>'',type=>'',regex=>"",require=>booler]]
+     */
+    protected function checkparam($functionname, $arr)
+    {
+        $param = $arr;
+        $rules = $this->setrules();
+        if (isset($rules[$functionname])) {
+            try {
+                $list = $rules[$functionname];
+                $namelist = array_column($list, 'name');
+                if (count($namelist) != count($list) || count($list) != count(array_filter($namelist))) {
+                    throw new \Exception("规则name设置错误");
+                }
+                $titlelist = array_column($list, 'title');
+                if (count($titlelist) != count($list) || count($list) != count(array_filter($titlelist))) {
+                    throw new \Exception("规则title设置错误");
+                }
+                foreach ($list as $key => $value) {
+                    $name = $value['name'];
+                    $title = $value['title'];
+                    //必填
+                    if (isset($value['require']) && $value['require']) {
+                        if (!isset($param[$name])) {
+                            throw new \Exception($title . '未填');
+                        }
+                    }
+                    if (!$value['require']) {
+                        if (!isset($param[$name])) {
+                            if (isset($value['default'])) {
+                                $param[$name] = $value['default'];
+                            }
+                        }
+                        continue;
+                    }
+
+                    $paramvalue = $param[$name];
+                    //类型
+                    if (isset($value['type'])) {
+                        $tpe = $value['type'];
+                        switch ($tpe) {
+                            case 'string':
+                                if (!is_string($paramvalue) || empty($paramvalue)) {
+                                    throw new \Exception($title . '格式错误');
+                                }
+                                break;
+                            case 'numeric':
+                                if (!is_numeric($paramvalue)) {
+                                    throw new \Exception($title . '格式错误');
+                                }
+                                break;
+                            case 'array':
+                                if (!is_array($paramvalue)) {
+                                    throw new \Exception($title . '格式错误');
+                                }
+                                break;
+                        }
+                    }
+                    //正则
+                    if (isset($value['regex'])) {
+                        $regex = $value['regex'];
+                        if (!preg_match($regex, $paramvalue)) {
+                            throw new \Exception($title . '正则格式错误');
+                        }
+                    }
+                }
+                return backarr(1, 'success', $param);
+            } catch (\Exception $e) {
+                $msg = $e->getMessage();
+                Log::error($msg);
+                return backarr(0, $msg);
+            }
+        }
+        return backarr(1, 'success', $param);
+    }
+    /**
+     * 设置请求参数验证规则
+     *
+     * @return void
+     */
+    protected function setrules()
+    {
+        return [];
+    }
+}