select()->toArray(); return $this->json(0, 'success', $data); } /** * 上报 * * @return Json * @throws Exception */ public function report(): Json { $data = input(); $accountId = $this->request->user['user_id'] ?? 0; if (empty($data)) { return $this->json(); } if (!is_array($data)) { $data = json_decode($data, true); } $insert = []; if (count($data) > 1000) { //TODO 太大就分片处理 } else { foreach ($data as $d) { if (!isset($d['e']) || !isset($d['t'])) { return $this->json(4001, '参数错误'); } $arr = []; $arr['event_id'] = (int) ($d['e'] ?? 0); $arr['account_id'] = $accountId; $arr['content_id'] = (int) ($d['c'] ?? 0); $t = (strlen($d['t']) == 13) ? $d['t'] / 1000 : $d['t']; $arr['created_at'] = date('Y-m-d H:i:s', $t); $insert[] = $arr; } } // 若量大 时间长 可丢入队列操作 if (count($insert) > 0) { (new AccountFootmarks())->saveAll($insert); } return $this->json(); } }