params = $params; } public function collection() { $data = Order::when($this->params['id'], function (Builder $query) { $query->where("id", $this->params['id']); })->when($this->params['userinfo'], function (Builder $query) { //根据userinfo获取用户信息 if ($user = User::where("email", $this->params['userinfo'])->orWhere("phone", $this->params['userinfo'])->orWhere("id", Utils::idHas4($this->params['userinfo']))->first()) { $query->where("user_id", $user->id); } else { $query->where("id", 0); } })->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; } }