Demoss.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use \think\Request;
  5. use \think\Db;
  6. class Demoss extends Api
  7. {
  8. protected $noNeedLogin = ['*'];
  9. protected $noNeedRight = ['*'];
  10. public function index()
  11. {
  12. $this->success('13245645');
  13. }
  14. public function aaa()
  15. {
  16. $this->success('请求成功');
  17. }
  18. /**
  19. * 墨色数审计结果批量查询
  20. *
  21. * 用法:
  22. * GET /api/demoss/batch?gdbhs=Y2680921,Y2680920
  23. */
  24. public function batch()
  25. {
  26. // 1. GET 请求校验(和现有接口风格一致)
  27. if (!$this->request->isGet()) {
  28. $this->error('请求方式错误');
  29. }
  30. // 2. 接收参数
  31. $req = $this->request->param();
  32. $gdbhsStr = isset($req['gdbhs']) ? trim($req['gdbhs']) : '';
  33. if (empty($gdbhsStr)) {
  34. $this->error('参数 gdbhs 不能为空');
  35. }
  36. // 3. 解析成数组
  37. $gdbhList = array_filter(array_map('trim', explode(',', $gdbhsStr)));
  38. if (empty($gdbhList)) {
  39. $this->error('gdbhs 解析后为空');
  40. }
  41. $gdbhList = array_slice(array_unique($gdbhList), 0, 200);
  42. // 4. 查询(用 db() 辅助函数,自动加表前缀)
  43. // 前提:审计表已改名为 {prefix}audit_color_check
  44. $rows = db('audit_color_check')
  45. ->where('gdbh', 'in', $gdbhList)
  46. ->field('gdbh,gxh,gxmc,colors_count,gy_ms,sczl_ms,error_field,is_valid,reason,suggestion,sczl_rq')
  47. ->select();
  48. if (!$rows) {
  49. // 和现有风格一致:查询无数据不报错,返回空 map
  50. $this->success('成功', []);
  51. }
  52. // 5. 组装成 map:key = "gdbh-gxh"
  53. $resultMap = [];
  54. foreach ($rows as $row) {
  55. $key = $row['gdbh'] . '-' . $row['gxh'];
  56. $resultMap[$key] = [
  57. 'gdbh' => $row['gdbh'],
  58. 'gxh' => $row['gxh'],
  59. 'gxmc' => $row['gxmc'],
  60. 'colors_count' => (int)$row['colors_count'],
  61. 'gy_ms' => (float)$row['gy_ms'],
  62. 'sczl_ms' => (float)$row['sczl_ms'],
  63. 'error_field' => $row['error_field'],
  64. 'is_valid' => (int)$row['is_valid'],
  65. 'reason' => $row['reason'],
  66. 'suggestion' => $row['suggestion'],
  67. 'sczl_rq' => $row['sczl_rq'],
  68. ];
  69. }
  70. // 6. 返回
  71. $this->success('成功', $resultMap);
  72. }
  73. }