| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use \think\Request;
- use \think\Db;
- class Demoss extends Api
- {
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- public function index()
- {
- $this->success('13245645');
- }
- public function aaa()
- {
- $this->success('请求成功');
- }
- /**
- * 墨色数审计结果批量查询
- *
- * 用法:
- * GET /api/demoss/batch?gdbhs=Y2680921,Y2680920
- */
- public function batch()
- {
- // 1. GET 请求校验(和现有接口风格一致)
- if (!$this->request->isGet()) {
- $this->error('请求方式错误');
- }
- // 2. 接收参数
- $req = $this->request->param();
- $gdbhsStr = isset($req['gdbhs']) ? trim($req['gdbhs']) : '';
- if (empty($gdbhsStr)) {
- $this->error('参数 gdbhs 不能为空');
- }
- // 3. 解析成数组
- $gdbhList = array_filter(array_map('trim', explode(',', $gdbhsStr)));
- if (empty($gdbhList)) {
- $this->error('gdbhs 解析后为空');
- }
- $gdbhList = array_slice(array_unique($gdbhList), 0, 200);
- // 4. 查询(用 db() 辅助函数,自动加表前缀)
- // 前提:审计表已改名为 {prefix}audit_color_check
- $rows = db('audit_color_check')
- ->where('gdbh', 'in', $gdbhList)
- ->field('gdbh,gxh,gxmc,colors_count,gy_ms,sczl_ms,error_field,is_valid,reason,suggestion,sczl_rq')
- ->select();
- if (!$rows) {
- // 和现有风格一致:查询无数据不报错,返回空 map
- $this->success('成功', []);
- }
- // 5. 组装成 map:key = "gdbh-gxh"
- $resultMap = [];
- foreach ($rows as $row) {
- $key = $row['gdbh'] . '-' . $row['gxh'];
- $resultMap[$key] = [
- 'gdbh' => $row['gdbh'],
- 'gxh' => $row['gxh'],
- 'gxmc' => $row['gxmc'],
- 'colors_count' => (int)$row['colors_count'],
- 'gy_ms' => (float)$row['gy_ms'],
- 'sczl_ms' => (float)$row['sczl_ms'],
- 'error_field' => $row['error_field'],
- 'is_valid' => (int)$row['is_valid'],
- 'reason' => $row['reason'],
- 'suggestion' => $row['suggestion'],
- 'sczl_rq' => $row['sczl_rq'],
- ];
- }
- // 6. 返回
- $this->success('成功', $resultMap);
- }
- }
|