lz_pdo_查询以及批增数据
$result = $DB->prepare("SELECT calendar_date, calendar_date_name, calendar_day_off, calendar_day_worked FROM `admin_calendar` WHERE calendar_date BETWEEN :start - INTERVAL 2 MONTH AND :end + INTERVAL 2 MONTH AND (calendar_day_off <> 0 OR calendar_day_worked <> 0) ORDER BY `calendar_date` DESC"); $result->bindvalue(':start', $_GET['start'], PDO::PARAM_STR); $result->bindvalue(':end', $_GET['end'], PDO::PARAM_STR); if (!$result->execute()) { Flight::error(new Exception(errorInfo($query))); } $items = []; while ($row = $result->fetch(PDO::FETCH_BOTH)) { $row_array['id'] = $row['calendar_date']; $row_array['name'] = $row['calendar_date_name']; $row_array['calendar_day_off'] = $row['calendar_day_off']; $row_array['calendar_day_worked'] = $row['calendar_day_worked']; if ($row['calendar_day_off'] == 1) { $row_array['color'] = '#6BC6B6'; } elseif ($row['calendar_day_worked'] == 1) { $row_array['color'] = '#EE4C4E'; } array_push($items, $row_array); } Flight::json(['data' => ['items' => $items]]);
批增:
<?php /** * @api {post} /eamic/ws/rest/v1/19099toolMovement 写入工具移动数据 * @apiParam (Request body) tool_id * @apiParam (Request body) tool_movement_time * @apiParam (Request body) tool_movement_nature * @apiParam (Request body) tool_movement_employee_id * @apiParam (Request body) tool_movement_wo_id * @apiParam (Request body) tool_movement_remarks * @apiHeaderExample {json} Header-Example: * { * "Authorization": "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="(用真实验证信息替换), * "Content-Type": "application/json" * } { "data": { "totalItems": 2, "success": 2, "failed": 0, "create": "2022-06-23 18:03:38", "details": [ { "tool_id": 360, "insert_tool_id": 437 }, { "tool_id": 360, "insert_tool_id": 438 } ] } } */ // 获取请求体,@的作用为屏蔽警告,可去除。 $post = @file_get_contents('php://input'); // 解析成数组 $post = json_decode($post, true); $query = $DB->prepare(" INSERT INTO sp_tool_movement ( tool_id, tool_movement_time, tool_movement_employee_id, tool_movement_nature, tool_movement_wo_id, tool_movement_remarks ) VALUES ( :tool_id, :tool_movement_time, :tool_movement_employee_id, :tool_movement_nature, :tool_movement_wo_id, :tool_movement_remarks ) "); // 定义一个空的数组,也就是返回的参数详情 $details = []; // 返回的成功还是失败 $success = 0; // 定义一个空列 $failed = 0; foreach ($post as $datum) { if (!isset($datum['tool_id'])) { $failed += 1; $details[] = ['tool_id' => '', 'result' => 'failed: tool_id not provided.']; continue; } $query->bindvalue('tool_id', $datum['tool_id']); $query->bindvalue( 'tool_movement_time', isset($datum['tool_movement_time']) ? $datum['tool_movement_time'] : '' ); $query->bindvalue( 'tool_movement_employee_id', isset($datum['tool_movement_employee_id']) ? $datum['tool_movement_employee_id'] : '' ); $query->bindvalue( ':tool_movement_nature', isset($datum['tool_movement_nature']) ? $datum['tool_movement_nature'] : '' ); $query->bindvalue( ':tool_movement_wo_id', isset($datum['tool_movement_wo_id']) ? $datum['tool_movement_wo_id'] : '' ); $query->bindvalue( ':tool_movement_remarks', isset($datum['tool_movement_remarks']) ? $datum['tool_movement_remarks'] : '' ); if (!$query->execute()) { Flight::error(new RuntimeException(errorInfo($query))); } if ($query->rowCount()) { $success += $query->rowCount(); } $details[] = [ 'tool_id' => $datum['tool_id'], 'insert_tool_id' => (int) $DB->lastInsertId(), ]; } $result = [ 'totalItems' => count($data), 'success' => $success, 'failed' => $failed, 'create' => $tmp_now, 'details' => $details, ]; update_log($result);
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
2021-06-17 构造方法__construct()与析构方法__destruct() 构造方法:刚出生时婴儿的啼哭 析构方法:老人临终时的遗言