request->param('page/d', 1); $size = $this->request->param('size/d', 30); $whereMap = [ ["is_delete", "=", CommentModel::COMMON_OFF],//未删除 ["state", "=", CommentModel::COMMON_ON],//审核通过 ]; $data = CommentModel::findList($whereMap, [], $page, $size, null, ["id" => "desc"]); return $this->json(0, "success", $data); } /** * 创建一条评论 开发中 * */ public function createComment() { $accountId = $this->request->user['user_id'] ?? 0; $accountRepo = AccountRepository::getInstance(); try { $account = $accountRepo->findById($accountId, [], function ($q) { return $q->with(['business', 'parent']); }); if (empty($account)) { throw new ValidateException('用户无效!'); } $param = [ "comment" => input("comment/s", ""),//评论内容 图片类型放入地址 语音类型放置语音文件地址 "user_code" => $account['user_code'], "create_time" => date("Y-m-d H:i:s"), "url" => input("url/s", ""),//图片地址 仅图片评论才有 "state" => CommentModel::state_default, "type" => input("type/s"),//评论类型 "lng" => input("lng/s"),//经度 "lat" => input("lat/s"),//纬度 "location" => input("location/s"), ]; CommentModel::create($param); return $this->json(); } catch (ValidateException $e) { return $this->json(4001, $e->getError()); } catch (RepositoryException $e) { return $this->json(4001, $e->getError()); } catch (Exception $e) { return $this->json(5001, '服务器繁忙!获取用户个人信息失败'); } } }