getJsonData(); $rules = [ 'type' => 'required|int', 'content' => 'required|string' ]; $validator = $validatorFactory->make($inputData, $rules); if ($validator->fails()) { // 如果有错误(可能是多个信息),这里只取第一个错误信息返回. return json_fail($validator->errors()->first()); } $user_code = $this->getUserId(); $data = [ 'uid' => $user_code, 'type' => $inputData['type'], 'rid' => '', 'content' => $inputData['content'], ]; $create = FeedbackModel::query()->create($data); if ($inputData['type'] == 2) { $create->content = M3u8CacheRepository::getImageUrl($create->content); } $user_info = make(UserRepository::class) ->getUserInfoFromCache($user_code); $create->avatar = $user_info['avatar']; Carbon::setLocale('zh'); $create->time = Carbon::parse($create->created_at)->diffForHumans(); unset($create->uid, $create->created_at); return json_success($create); } /** * 我的反馈列表 * @return mixed */ public function list(ValidatorFactoryInterface $validatorFactory) { $inputData = $this->getJsonData(); $rules = [ 'page' => 'required|int', 'page_size' => 'required|int', ]; $validator = $validatorFactory->make($inputData, $rules); if ($validator->fails()) { return json_fail($validator->errors()->first()); } $result = FeedbackModel::query() ->where(['uid' => $this->getUserId()]) ->orderByDesc('id') ->paginate( (int)$inputData['page_size'], ['type','content','rid','created_at'], 'page', (int)$inputData['page'] ); $user_info = make(UserRepository::class) ->getUserInfoFromCache($this->getUserId()); foreach ($result as $v) { if ($v->type == 2) { $v->content = M3u8CacheRepository::getImageUrl($v->content); } if (!$v->rid) { $v->avatar = $user_info['avatar']; } Carbon::setLocale('zh'); $v->time = Carbon::parse($v->created_at)->diffForHumans(); unset($v->created_at); } return json_success($result); } }