diff --git a/app/Http/Controllers/Admin/SupplyDemandController.php b/app/Http/Controllers/Admin/SupplyDemandController.php new file mode 100755 index 0000000..7a59743 --- /dev/null +++ b/app/Http/Controllers/Admin/SupplyDemandController.php @@ -0,0 +1,191 @@ +all(); + $list = $this->model->with('user')->where(function ($query) use ($all) { + if (isset($all['filter']) && !empty($all['filter'])) { + foreach ($all['filter'] as $condition) { + $key = $condition['key'] ?? null; + $op = $condition['op'] ?? null; + $value = $condition['value'] ?? null; + if (!isset($key) || !isset($op) || !isset($value)) { + continue; + } + // 等于 + if ($op == 'eq') { + $query->where($key, $value); + } + // 不等于 + if ($op == 'neq') { + $query->where($key, '!=', $value); + } + // 大于 + if ($op == 'gt') { + $query->where($key, '>', $value); + } + // 大于等于 + if ($op == 'egt') { + $query->where($key, '>=', $value); + } + // 小于 + if ($op == 'lt') { + $query->where($key, '<', $value); + } + // 小于等于 + if ($op == 'elt') { + $query->where($key, '<=', $value); + } + // 模糊搜索 + if ($op == 'like') { + $query->where($key, 'like', '%' . $value . '%'); + } + // 否定模糊搜索 + if ($op == 'notlike') { + $query->where($key, 'not like', '%' . $value . '%'); + } + // 范围搜索 + if ($op == 'range') { + list($from, $to) = explode(',', $value); + if (empty($from) || empty($to)) { + continue; + } + $query->whereBetween($key, [$from, $to]); + } + } + } + })->orderBy($all['sort_name'] ?? 'id', $all['sort_type'] ?? 'desc'); + if (isset($all['is_export']) && !empty($all['is_export'])) { + $list = $list->get()->toArray(); + $export_fields = $all['export_fields'] ?? []; + // 导出文件名字 + $tableName = $this->model->getTable(); + $filename = (new CustomForm())->getTableComment($tableName); + return Excel::download(new BaseExport($export_fields, $list, $tableName), $filename . date('YmdHis') . '.xlsx'); + } else { + // 输出 + $list = $list->paginate($all['page_size'] ?? 20); + } + return $this->success($list); + } + + /** + * @OA\Get( + * path="/api/admin/supply-demand/show", + * tags={"供需信息管理"}, + * summary="详情", + * description="", + * @OA\Parameter(name="id", in="query", @OA\Schema(type="string"), required=true, description="id"), + * @OA\Parameter(name="show_relation", in="query", @OA\Schema(type="string"), required=false, description="需要输出的关联关系数组,填写输出指定数据"), + * @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"), + * @OA\Response( + * response="200", + * description="暂无" + * ) + * ) + */ + public function show() + { + $all = \request()->all(); + $messages = [ + 'id.required' => 'Id必填', + ]; + $validator = Validator::make($all, [ + 'id' => 'required' + ], $messages); + if ($validator->fails()) { + return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]); + } + $detail = $this->model->with('user')->find($all['id']); + return $this->success($detail); + } + + /** + * @OA\Post( + * path="/api/admin/supply-demand/save", + * tags={"供需信息管理"}, + * summary="更新或新增", + * @OA\Parameter(name="id", in="query", @OA\Schema(type="integer"), required=false, description="需求供应表ID(存在则更新,不存在则新增)"), + * @OA\Parameter(name="title", in="query", @OA\Schema(type="string"), required=false, description="标题"), + * @OA\Parameter(name="supply_demand_type_id", in="query", @OA\Schema(type="integer"), required=false, description="分类ID"), + * @OA\Parameter(name="content", in="query", @OA\Schema(type="string"), required=false, description="内容"), + * @OA\Parameter(name="tag", in="query", @OA\Schema(type="string"), required=false, description="标签"), + * @OA\Parameter(name="wechat", in="query", @OA\Schema(type="string"), required=false, description="微信号"), + * @OA\Parameter(name="mobile", in="query", @OA\Schema(type="string"), required=false, description="电话"), + * @OA\Parameter(name="email", in="query", @OA\Schema(type="string"), required=false, description="邮箱"), + * @OA\Parameter(name="status", in="query", @OA\Schema(type="integer"), required=false, description="审核状态(0:待审核;1:通过;2:拒绝)"), + * @OA\Response( + * response=200, + * description="操作成功" + * ) + * ) + */ + public function save() + { + return parent::save(); + } + + /** + * @OA\Get( + * path="/api/admin/supply-demand/destroy", + * tags={"供需信息管理"}, + * summary="删除", + * description="", + * @OA\Parameter(name="id", in="query", @OA\Schema(type="string"), required=true, description="id"), + * @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"), + * @OA\Response( + * response="200", + * description="暂无" + * ) + * ) + */ + public function destroy() + { + return parent::destroy(); + } + + +} diff --git a/app/Http/Controllers/Admin/SupplyDemandTypeController.php b/app/Http/Controllers/Admin/SupplyDemandTypeController.php new file mode 100755 index 0000000..53d0a22 --- /dev/null +++ b/app/Http/Controllers/Admin/SupplyDemandTypeController.php @@ -0,0 +1,186 @@ +all(); + $list = $this->model->with('icon')->where(function ($query) use ($all) { + if (isset($all['filter']) && !empty($all['filter'])) { + foreach ($all['filter'] as $condition) { + $key = $condition['key'] ?? null; + $op = $condition['op'] ?? null; + $value = $condition['value'] ?? null; + if (!isset($key) || !isset($op) || !isset($value)) { + continue; + } + // 等于 + if ($op == 'eq') { + $query->where($key, $value); + } + // 不等于 + if ($op == 'neq') { + $query->where($key, '!=', $value); + } + // 大于 + if ($op == 'gt') { + $query->where($key, '>', $value); + } + // 大于等于 + if ($op == 'egt') { + $query->where($key, '>=', $value); + } + // 小于 + if ($op == 'lt') { + $query->where($key, '<', $value); + } + // 小于等于 + if ($op == 'elt') { + $query->where($key, '<=', $value); + } + // 模糊搜索 + if ($op == 'like') { + $query->where($key, 'like', '%' . $value . '%'); + } + // 否定模糊搜索 + if ($op == 'notlike') { + $query->where($key, 'not like', '%' . $value . '%'); + } + // 范围搜索 + if ($op == 'range') { + list($from, $to) = explode(',', $value); + if (empty($from) || empty($to)) { + continue; + } + $query->whereBetween($key, [$from, $to]); + } + } + } + })->orderBy($all['sort_name'] ?? 'id', $all['sort_type'] ?? 'desc'); + if (isset($all['is_export']) && !empty($all['is_export'])) { + $list = $list->get()->toArray(); + $export_fields = $all['export_fields'] ?? []; + // 导出文件名字 + $tableName = $this->model->getTable(); + $filename = (new CustomForm())->getTableComment($tableName); + return Excel::download(new BaseExport($export_fields, $list, $tableName), $filename . date('YmdHis') . '.xlsx'); + } else { + // 输出 + $list = $list->paginate($all['page_size'] ?? 20); + } + return $this->success($list); + } + + /** + * @OA\Get( + * path="/api/admin/supply-demand-type/show", + * tags={"供需类型管理"}, + * summary="详情", + * description="", + * @OA\Parameter(name="id", in="query", @OA\Schema(type="string"), required=true, description="id"), + * @OA\Parameter(name="show_relation", in="query", @OA\Schema(type="string"), required=false, description="需要输出的关联关系数组,填写输出指定数据"), + * @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"), + * @OA\Response( + * response="200", + * description="暂无" + * ) + * ) + */ + public function show() + { + $all = \request()->all(); + $messages = [ + 'id.required' => 'Id必填', + ]; + $validator = Validator::make($all, [ + 'id' => 'required' + ], $messages); + if ($validator->fails()) { + return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]); + } + $detail = $this->model->with(underlineToHump($all['show_relation'] ?? []))->find($all['id']); + return $this->success($detail); + } + + /** + * @OA\Post( + * path="/api/admin/supply-demand-type/save", + * tags={"供需类型管理"}, + * summary="更新或新增", + * @OA\Parameter(name="id", in="query", @OA\Schema(type="integer"), required=true, description="id"), + * @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="验证token"), + * @OA\Parameter(name="name", in="query", @OA\Schema(type="string"), description="名字"), + * @OA\Parameter(name="icon_id", in="query", @OA\Schema(type="string", format="date"), description="icon的id"), + * @OA\Parameter(name="status", in="query", @OA\Schema(type="string", format="date"), description="状态0禁用1启用"), + * @OA\Response( + * response=200, + * description="操作成功" + * ) + * ) + */ + public function save() + { + return parent::save(); + } + + /** + * @OA\Get( + * path="/api/admin/supply-demand-type/destroy", + * tags={"供需类型管理"}, + * summary="删除", + * description="", + * @OA\Parameter(name="id", in="query", @OA\Schema(type="string"), required=true, description="id"), + * @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"), + * @OA\Response( + * response="200", + * description="暂无" + * ) + * ) + */ + public function destroy() + { + return parent::destroy(); + } + + +} diff --git a/app/Models/Message.php b/app/Models/Message.php new file mode 100755 index 0000000..8a254f5 --- /dev/null +++ b/app/Models/Message.php @@ -0,0 +1,14 @@ +hasOne(User::class, 'id', 'user_id'); + } + +} + diff --git a/database/migrations/2025_06_20_100410_create_supply_demands_table.php b/database/migrations/2025_06_20_100410_create_supply_demands_table.php new file mode 100644 index 0000000..546c855 --- /dev/null +++ b/database/migrations/2025_06_20_100410_create_supply_demands_table.php @@ -0,0 +1,49 @@ +comment('需求供应表'); + $table->id(); + // 用户id + $table->integer('user_id')->nullable()->comment('用户id'); + $table->string('title')->nullable()->comment('标题'); + // 分类 + $table->integer('type')->nullable()->comment('分类1供应2需求'); + // 内容 + $table->text('content')->nullable()->comment('内容'); + // 标签 + $table->string('tag')->nullable()->comment('标签'); + // 微信号 + $table->string('wechat')->nullable()->comment('微信号'); + // 电话 + $table->string('mobile')->nullable()->comment('电话'); + // 邮箱 + $table->string('email')->nullable()->comment('邮箱'); + // 审核状态 + $table->tinyInteger('status')->default(0)->comment('状态0待审核1通过2拒绝'); + $table->timestamps(); + $table->softDeletes(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('supply_demand_types'); + } +}; diff --git a/database/migrations/2025_06_20_101705_create_messages_table.php b/database/migrations/2025_06_20_101705_create_messages_table.php new file mode 100644 index 0000000..28d1305 --- /dev/null +++ b/database/migrations/2025_06_20_101705_create_messages_table.php @@ -0,0 +1,42 @@ +comment('消息表'); + $table->id(); + // 用户id + $table->integer('user_id')->nullable()->comment('用户id'); + // 接收人id + $table->integer('to_user_id')->nullable()->comment('接收人id'); + // 需求id + $table->integer('supply_demand_id')->nullable()->comment('需求id'); + // 消息内容 + $table->text('content')->nullable()->comment('消息内容'); + // 接收方是否已读 + $table->tinyInteger('is_read')->nullable()->default(0)->comment('接收方是否已读0否1是'); + $table->timestamps(); + $table->softDeletes(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('massages'); + } +}; diff --git a/routes/api.php b/routes/api.php index eba611c..3748582 100755 --- a/routes/api.php +++ b/routes/api.php @@ -166,6 +166,12 @@ Route::group(["namespace" => "Admin", "prefix" => "admin"], function () { Route::get('course-appointment-total/destroy', [\App\Http\Controllers\Admin\CourseAppointmentTotalController::class, "destroy"]); Route::post('course-appointment-total/batch-update-total', [\App\Http\Controllers\Admin\CourseAppointmentTotalController::class, "batchUpdateTotal"]); + // 供需信息 + Route::get('supply-demand/index', [\App\Http\Controllers\Admin\SupplyDemandController::class, "index"]); + Route::get('supply-demand/show', [\App\Http\Controllers\Admin\SupplyDemandController::class, "show"]); + Route::post('supply-demand/save', [\App\Http\Controllers\Admin\SupplyDemandController::class, "save"]); + Route::get('supply-demand/destroy', [\App\Http\Controllers\Admin\SupplyDemandController::class, "destroy"]); + }); });