params = $params; } public function collection() { $data = Order::where("user_id", $this->params['user_id'])->orderByDesc("id")->get()->map(function (Order $model) { $goodsInfo = ""; foreach ($model->goods as $g) { $goodsInfo .= sprintf("%s %s x %s (%s) \n", $g->goods->name, $g->sn, $g->count, implode("-", Arr::pluck($g->custom ?? [], "value"))); } return [ "id" => $model->id, "goods" => $goodsInfo, "user_id" => Utils::idNo4($model->user_id), "name" => $model->user->name, "phone" => $model->user->phone, "email" => $model->user->email, "created_at" => $model->created_at->format("Y-m-d H:i:s"), ]; }); $data->prepend(["编号", "商品信息", "用户ID", "用户昵称", "用户手机", "用户邮箱", "询价时间"]); return $data; } }