第一次提交

This commit is contained in:
陈狼 2025-02-15 12:13:10 +08:00
commit 5e8f28f459
1132 changed files with 363253 additions and 0 deletions

5
.example.env Normal file
View File

@ -0,0 +1,5 @@
DATABASE_TYPE=mysql
DATABASE_HOSTNAME=127.0.0.1
DATABASE_NAME=add_hd
DATABASE_USERNAME=root
DATABASE_PASSWORD=123456

9
.gitignore vendored Normal file
View File

@ -0,0 +1,9 @@
/runtime
/.idea
/.vscode
/vendor
*.log
.env
/tests/tmp
/tests/.phpunit.result.cache
/public/*

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2021 walkor<walkor@workerman.net> and contributors (see https://github.com/walkor/webman/contributors)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

21
README.md Normal file
View File

@ -0,0 +1,21 @@
apidoc
```
http://127.0.0.1:8787/apidoc/index.html#/
```
Dev
```
win php windows.php
linux
```
一些状态码
```
401 登录失效需要重新登录
402 通用错误
```
使用的一些插件地址
```
easy-sms https://github.com/overtrue/easy-sms
webman命令行 https://www.workerman.net/plugin/1
php 解析html文档 https://simplehtmldom.sourceforge.io/docs/1.9/quick-start/
```

26
app/Utils/ApiResponse.php Normal file
View File

@ -0,0 +1,26 @@
<?php
namespace App\Utils;
class ApiResponse
{
public static function success($code = 200, $data = [], $message = '操作成功')
{
return json([
'status' => 'success',
'code' => $code,
'data' => $data,
'message' => $message
]);
}
public static function error($code = 400, $data = [], $message = '操作失败')
{
return json([
'status' => 'error',
'code' => $code,
'message' => $message,
'data' => $data
]);
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace App\Utils;
class FunctionResponse
{
public static function success($code = 200, $data = [], $message = '操作成功')
{
return [
'status' => 'success',
'code' => $code,
'data' => $data,
'message' => $message
];
}
public static function error($code = 400, $data = [], $message = '操作失败')
{
return [
'status' => 'error',
'code' => $code,
'message' => $message,
'data' => $data
];
}
}

View File

@ -0,0 +1,47 @@
<?php
namespace app\command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class ConfigMySQLCommand extends Command
{
protected static $defaultName = 'config:mysql';
protected static $defaultDescription = '显示当前MySQL服务器配置';
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln('MySQL配置信息如下');
$config = config('database');
$headers = ['name', 'default', 'driver', 'host', 'port', 'database', 'username', 'password', 'unix_socket', 'charset', 'collation', 'prefix', 'strict', 'engine', 'schema', 'sslmode'];
$rows = [];
foreach ($config['connections'] as $name => $db_config) {
$row = [];
foreach ($headers as $key) {
switch ($key) {
case 'name':
$row[] = $name;
break;
case 'default':
$row[] = $config['default'] == $name ? 'true' : 'false';
break;
default:
$row[] = $db_config[$key] ?? '';
}
}
if ($config['default'] == $name) {
array_unshift($rows, $row);
} else {
$rows[] = $row;
}
}
$table = new Table($output);
$table->setHeaders($headers);
$table->setRows($rows);
$table->render();
return self::SUCCESS;
}
}

View File

@ -0,0 +1,44 @@
<?php
namespace app\command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class CreateControllerCommand extends Command
{
protected static $defaultName = 'make:apicontroller';
protected function configure()
{
$this->setDescription('Create a new controller')
->setHelp('This command allows you to create a new controller...');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
// 获取控制器名称
$controllerName = $input->getArgument('name');
if (!$controllerName) {
$output->writeln('<error>Controller name is required</error>');
return Command::FAILURE;
}
// 创建控制器文件
$controllerFile = __DIR__ . "/../../app/Controllers/api/{$controllerName}Controller.php";
if (file_exists($controllerFile)) {
$output->writeln("<error>Controller {$controllerName} already exists!</error>");
return Command::FAILURE;
}
// 控制器的基本代码模板
$controllerTemplate = "<?php\n\nnamespace App\Controllers;\n\nclass {$controllerName}Controller\n{\n // Your controller code here\n}\n";
// 将控制器内容写入文件
file_put_contents($controllerFile, $controllerTemplate);
$output->writeln("<info>Controller {$controllerName} created successfully!</info>");
return Command::SUCCESS;
}
}

View File

@ -0,0 +1,153 @@
<?php
namespace app\controller;
use support\Request;
use App\Utils\ApiResponse;
use App\model\Carousel;
use App\model\Project;
use App\model\ProjectDetailed;
use App\model\ProjectRegister;
use App\model\Carouselad;
use App\model\Mechanism;
use Tinywan\Jwt\JwtToken;
use hg\apidoc\annotation as Apidoc;
use support\Db;
/**
* @Apidoc\Title("基础控制器")
*/
class Apiv1Controller
{
protected $noNeedLogin = ['get_carousel', 'get_project', 'get_projectdetailed', 'get_mechanism_list'];
public function index(Request $request)
{
static $readme;
if (!$readme) {
$readme = file_get_contents(base_path('README.md'));
}
return $readme;
}
public function view(Request $request)
{
return view('index/view', ['name' => 'webman']);
}
/**
* @Apidoc\Title("1.0 获取首页轮播图")
* @Apidoc\Url("Apiv1/get_carousel")
* @Apidoc\Method("POST")
*/
public function get_carousel(Request $request)
{
// return json(['code' => 0, 'msg' => 'ok']);
$res['carousel'] = Carousel::all();
$res['carouselad'] = Carouselad::all();
return ApiResponse::success(200, $res);
}
/**
* @Apidoc\Title("1.0 获取所有项目")
* @Apidoc\Url("Apiv1/get_project")
* @Apidoc\Method("POST")
*/
public function get_project(Request $request)
{
//志愿者人数
// $tmp=Project::all();
// foreach($tmp as $k=>$v){
// $res_volunteer=ProjectRegister::where('projectid',$v->id)->where('type',0)->count();
// //被服务者人数
// $res_servants=ProjectRegister::where('projectid',$v->id)->where('type',1)->count();
// $ProjectDetailed = ProjectDetailed::where('projectid',$v->id)->first();
// $data = array(
// "id" => $v->id,
// "created_at" => $v->created_at,
// "updated_at" => $v->updated_at,
// "img" => $v->img,
// "start_time" => $v->start_time,
// "end_time" => $v->end_time,
// "address" => $v->address,
// "title" => $v->title,
// "type" => $v->type,
// "volunteer_max"=>$ProjectDetailed->recruitingpersonnel,
// "servants_max"=>$ProjectDetailed->registerserve,
// "volunteer"=>$res_volunteer,
// "servants"=>$res_servants
// );
// $res[]=$data;
// }
/**
* ?优化
*/
$res = Db::table('project')
->leftJoin('project_register as pr', 'project.id', '=', 'pr.projectid')
->leftJoin('project_detailed as pd', 'project.id', '=', 'pd.projectid')
->select(
'project.*',
'pd.recruitingpersonnel',
'pd.registerserve',
Db::raw('COUNT(CASE WHEN pr.type = 0 THEN 1 END) as volunteer'),
Db::raw('COUNT(CASE WHEN pr.type = 1 THEN 1 END) as servants')
)
->groupBy('project.id')
->orderBy('project.id', 'DESC')
->get();
// 转换为期望的数据结构
foreach ($res as &$v) {
$v->volunteer_max = $v->recruitingpersonnel;
$v->servants_max = $v->registerserve;
unset($v->recruitingpersonnel, $v->registerserve); // 清理不需要的字段
}
return ApiResponse::success(200, $res);
}
/**
* @Apidoc\Title("1.0 获取项目详细信息根据id")
* @Apidoc\Url("Apiv1/get_projectdetailed")
* @Apidoc\Method("POST")
* @Apidoc\Query("projectid", type="int",require=true, desc="项目id",default="1")
* @Apidoc\Returned("projectdetailed", type="string", desc="项目详细信息")
*/
public function get_projectdetailed(Request $request)
{
$data = $request->post();
$res['project'] = Project::where('id', $data['projectid'])->first();
$res['projectdetailed'] = ProjectDetailed::where('projectid', $data['projectid'])->first();
//志愿者人数
$res_volunteer = ProjectRegister::where('projectid', $data['projectid'])->where('type', 0)->count();
//被服务者人数
$res_servants = ProjectRegister::where('projectid', $data['projectid'])->where('type', 1)->count();
$res['projectRegister'] = ProjectRegister::where('projectid', $data['projectid'])->get();
$res['volunteer'] = $res_volunteer;
$res['servants'] = $res_servants;
$res['volunteer_max'] = $res['projectdetailed']->recruitingpersonnel;
$res['servants_max'] = $res['projectdetailed']->registerserve;
return ApiResponse::success(200, $res);
}
/**
* @Apidoc\Title("1.0 获取所有养老机构")
* @Apidoc\Url("Apiv1/get_mechanism_list")
* @Apidoc\Method("POST")
*/
public function get_mechanism_list(Request $request)
{
$res = Mechanism::all();
return ApiResponse::success(200, $res);
}
/**
* @Apidoc\Title("1.0 获取养老机构详细信息")
* @Apidoc\Url("Apiv1/get_mechanism")
* @Apidoc\Query("mechanism", type="int",require=true, desc="养老机构id",default="1")
* @Apidoc\Method("POST")
*/
public function get_mechanism(Request $request)
{
$data = $request->post();
$res = Mechanism::where('id', $data['id'])->get();
return ApiResponse::success(200, $res);
}
}

View File

@ -0,0 +1,35 @@
<?php
namespace app\controller;
use support\Request;
use App\Utils\ApiResponse;
class IndexController
{
public function index(Request $request)
{
static $readme;
if (!$readme) {
$readme = file_get_contents(base_path('README.md'));
}
return $readme;
}
public function view(Request $request)
{
return view('index/view', ['name' => 'webman']);
}
public function json(Request $request)
{
// return json(['code' => 0, 'msg' => 'ok']);
$users = [
['id' => 1, 'name' => '张三'],
['id' => 2, 'name' => '李四'],
];
return ApiResponse::success($users);
}
}

View File

@ -0,0 +1,55 @@
<?php
namespace app\controller;
use support\Request;
use App\Utils\ApiResponse;
use App\model\Project;
use App\model\ProjectRegister;
use App\model\ProjectDetailed;
use App\dao\MessageDao;
class ProjectRegisterController
{
public function index(Request $request)
{
}
/**
* 报名函数
*/
public function signup(Request $request)
{
$user = $request->data;
$data = $request->post();
/**
* 通过中间件获取userid
*/
$userid=$user['id'];
$projectid=$data['projectid'];
$type=$data['type'];
$search_type=$type==1?'registerserve':'recruitingpersonnel';
$res=ProjectDetailed::where('projectid',$projectid)->first();
$Project=Project::where('id',$projectid)->first();
if(ProjectRegister::where('projectid',$projectid)->where('type','=',$type)->count()==$res->$search_type){
return ApiResponse::success(402,[],"当前报名人数已经满员");
}
/**
* 查询用户是否报名过
*/
$issignup=ProjectRegister::where('userid',$userid)->where('projectid',$projectid)->count();
if($issignup==0){
$ProjectRegister=new ProjectRegister();
$ProjectRegister->projectid=$projectid;
$ProjectRegister->type=$type;
$ProjectRegister->userid=$userid;
$ProjectRegister->save();
MessageDao::SendMessage($userid,"系统提醒","您已成功报名 $Project->title ");
return ApiResponse::success(200,[],"报名成功");
}
return ApiResponse::success(402,$issignup,"您已经报名过了");
}
}

View File

@ -0,0 +1,73 @@
<?php
namespace app\controller;
use support\Request;
use App\Utils\ApiResponse;
use Tinywan\Jwt\JwtToken;
use App\model\Users;
class UserController
{
/**
* 不需要登录的方法
*/
protected $noNeedLogin = ['login','register'];
/**
* Undocumented function
* 登录
* @param Request $request
* @return void
*/
public function login(Request $request)
{
// 获取请求数据
$data = $request->post();
// 根据手机号查询用户
$db = Users::where('phone', '=', $data['phone'])->first();
// 如果未找到用户,返回错误
if (!$db) {
return ApiResponse::error(402,[] ,'用户未注册');
}
// 获取用户输入的密码
$password = $data['password'];
// 验证密码是否正确
if (password_verify($password, $db->password)) {
$user = [
'id' => $db->id,
'nickname' => $db->nickname,
'phone' => $db->phone
];
// 如果密码正确,生成 JWT 令牌
$token = JwtToken::generateToken($user);
// 返回成功响应和用户信息(可以将 token 添加到响应中)
return ApiResponse::success(200, [
'user' => $user, // 返回用户信息
'token' => $token // 返回生成的 token
]);
} else {
// 密码错误,返回错误响应
return ApiResponse::error(402,[], '用户或密码错误');
}
}
/**
* 注册
*/
public function register(Request $request)
{
$data = $request->post();
$res = [];
return ApiResponse::success(200, $res);
}
}

View File

@ -0,0 +1,81 @@
<?php
namespace app\controller\admin\api\v1;
use support\Request;
use App\Utils\ApiResponse;
use App\model\Admin;
use hg\apidoc\annotation as Apidoc;
use Intervention\Image\ImageManagerStatic as Image;
use Exception;
use support\exception\BusinessException;
use Tinywan\Jwt\JwtToken;
/**
* @Apidoc\Title("用户控制器")
*/
class AccountController
{
/**
* 不需要登录的方法
*/
protected $noNeedLogin = ['login', 'refresh'];
/**
* @Apidoc\Title("1.0 登录")
* @Apidoc\Url("admin/api/v1/account/login")
* @Apidoc\Method("POST")
* @Apidoc\Param("username", type="string",require=true, desc="用户名")
* @Apidoc\Param("password", type="string",require=true, desc="密码")
* @Apidoc\Returned("token", type="object", desc="令牌")
*/
public function login(Request $request)
{
// 获取请求数据
$data = $request->post();
// 根据手机号查询用户
$db = Admin::where('username', '=', $data['username'])->first();
// 如果未找到用户,返回错误
if (!$db) {
return ApiResponse::error(402, [], '用户未注册');
}
// 获取用户输入的密码
$password = $data['password'];
// 验证密码是否正确
if (password_verify($password, $db->password)) {
$user = [
'id' => $db->id,
'nickname' => $db->nickname,
'username' => $db->username
];
// 如果密码正确,生成 JWT 令牌
$token = JwtToken::generateToken($user);
// 返回成功响应和用户信息(可以将 token 添加到响应中)
return ApiResponse::success(200, [
'user' => $user, // 返回用户信息
'token' => $token // 返回生成的 token
]);
} else {
// 密码错误,返回错误响应
return ApiResponse::error(402, [], '密码错误');
}
}
/**
* @Apidoc\Title("1.0 刷新token")
* @Apidoc\Url("admin/api/v1/account/refresh")
* @Apidoc\Method("POST")
* @Apidoc\Param("refresh_token", type="string",require=true, desc="令牌")
* @Apidoc\Returned("token", type="object", desc="令牌")
*/
public function refresh(Request $request) {
$token = JwtToken::refreshToken();
return ApiResponse::success(200, [
'token' => $token // 返回生成的 token
]);
}
}

View File

@ -0,0 +1,94 @@
<?php
namespace app\controller\admin\api\v1;
use support\Request;
use App\Utils\ApiResponse;
use App\model\Carousel;
use App\model\Carouselad;
use hg\apidoc\annotation as Apidoc;
/**
* @Apidoc\Title("轮播图控制器")
*/
class CarouselController
{
/**
* @Apidoc\Title("1.0 获取首页轮播图")
* @Apidoc\Url("api/admin/v1/carousel/get_carousel")
* @Apidoc\Method("POST")
*/
public function get_carousel(Request $request)
{
// return json(['code' => 0, 'msg' => 'ok']);
$res = Carousel::all();
return ApiResponse::success(200, $res);
}
/**
* @Apidoc\Title("1.0 获取首页底部轮播图")
* @Apidoc\Url("api/admin/v1/carousel/get_carouselad")
* @Apidoc\Method("POST")
*/
public function get_carouselad(Request $request)
{
$res = Carouselad::all();
return ApiResponse::success(200, $res);
}
/**
* @Apidoc\Title("1.0 添加轮播图")
* @Apidoc\Url("admin/api/v1/carousel/add")
* @Apidoc\Param("type", type="int",require=true, desc="类型0是首页轮播图1是广告图")
* @Apidoc\Param("img_url", type="string",require=true, desc="img_url")
* @Apidoc\Method("POST")
*/
public function add(Request $request)
{
$data = $request->post();
if ($data['type'] == 0) {
$Carousel = new Carousel();
} else {
$Carousel = new Carouselad();
}
$Carousel->img_url = $data['img_url'];
$Carousel->save();
return ApiResponse::success(200, []);
}
/**
* @Apidoc\Title("1.0 删除轮播图")
* @Apidoc\Url("admin/api/v1/carousel/del")
* @Apidoc\Param("type", type="int",require=true, desc="类型0是首页轮播图1是广告图")
* @Apidoc\Param("id", type="int",require=true, desc="图片id")
* @Apidoc\Method("POST")
*/
public function del(Request $request)
{
$data = $request->post();
if ($data['type'] == 0) {
$Carousel = Carousel::where('id', $data['id'])->first();
} else {
$Carousel = Carouselad::where('id', $data['id'])->first();
}
$Carousel->delete();
return ApiResponse::success(200, []);
}
/**
* @Apidoc\Title("1.0 删除轮播图")
* @Apidoc\Url("admin/api/v1/carousel/chang")
* @Apidoc\Param("type", type="int",require=true, desc="类型0是首页轮播图1是广告图")
* @Apidoc\Param("id", type="int",require=true, desc="图片id")
* @Apidoc\Method("POST")
*/
public function chang(Request $request)
{
$data = $request->post();
if ($data['type'] == 0) {
$Carousel = Carousel::where('id', $data['id'])->first();
} else {
$Carousel = Carouselad::where('id', $data['id'])->first();
}
$Carousel->img_url = $data['img_url'];
$Carousel->save();
return ApiResponse::success(200, []);
}
}

View File

@ -0,0 +1,75 @@
<?php
namespace app\controller\admin\api\v1;
use support\Request;
use App\Utils\ApiResponse;
use App\model\ProjectDetailed;
use App\model\Project;
use App\model\Hotinformation;
use hg\apidoc\annotation as Apidoc;
/**
* @Apidoc\Title("文章控制器")
*/
class HotinformationController{
protected $noNeedLogin = ['get_list','get_details'];
/**
* @Apidoc\Title("1.0 获取所有文章")
* @Apidoc\Url("admin/api/v1/hotinformation/get_list")
* @Apidoc\Param("type", type="int",require=true, desc="0是热点资讯1是银龄")
* @Apidoc\Method("POST")
*/
public function get_list(Request $request)
{
$data = $request->post();
$res = Hotinformation::where('type', $data['type'])->get();
return ApiResponse::success(200, $res);
}
/**
* @Apidoc\Title("1.0 获取文章详细")
* @Apidoc\Url("admin/api/v1/hotinformation/get_details")
* @Apidoc\Param("id", type="int",require=true, desc="文章id")
* @Apidoc\Method("POST")
*/
public function get_details(Request $request)
{
$data = $request->post();
$res = Hotinformation::where('id', $data['id'])->first();
return ApiResponse::success(200, $res);
}
/**
* @Apidoc\Title("1.0 编辑文章")
* @Apidoc\Url("admin/api/v1/hotinformation/edi")
* @Apidoc\Param("id", type="int",require=true, desc="文章id")
* @Apidoc\Method("POST")
*/
public function edi(Request $request)
{
$data = $request->post();
$hotinformation = Hotinformation::where('id', $data['id'])->first();
if(!isset($hotinformation)){
$hotinformation=new Hotinformation();
}
$hotinformation->title=$data['title'];
$hotinformation->writer=$data['writer'];
$hotinformation->content=$data['content'];
$hotinformation->type=$data['type'];
$hotinformation->img=$data['img'];
$hotinformation->weight=$data['weight'];
$hotinformation->save();
return ApiResponse::success(200, []);
}
/**
* @Apidoc\Title("1.0 删除文章")
* @Apidoc\Url("admin/api/v1/hotinformation/del")
* @Apidoc\Param("id", type="int",require=true, desc="文章id")
* @Apidoc\Method("POST")
*/
public function del(Request $request)
{
$data = $request->post();
$hotinformation = Hotinformation::where('id', $data['id'])->first();
$hotinformation->delete();
return ApiResponse::success(200, []);
}
}

View File

@ -0,0 +1,66 @@
<?php
namespace app\controller\admin\api\v1;
use support\Request;
use App\Utils\ApiResponse;
use App\model\ProjectDetailed;
use App\model\Project;
use hg\apidoc\annotation as Apidoc;
class projectController{
protected $noNeedLogin = ['edi'];
/**
* @Apidoc\Title("1.0 获取首页轮播图")
* @Apidoc\Url("admin/api/v1/project/edi")
* @Apidoc\Param("projectid", type="int",require=true, desc="项目id")
* @Apidoc\Method("POST")
*/
public function edi(Request $request)
{
$data = $request->post();
if($data['projectid']>0){
$project = Project::where('id', $data['projectid'])->first();
$projectDetailed = ProjectDetailed::where('projectid', $data['projectid'])->first();
}else{
$project =new Project();
$projectDetailed =new ProjectDetailed();
}
$project->img=$data['img'];
$project->start_time=$data['start_time'];
$project->end_time=$data['end_time'];
$project->address=$data['address'];
$project->title=$data['title'];
$project->type=$data['type'];
$project->save();
$id=Project::where('img', $data['img'])->first();
$id=$id->id;
$projectDetailed->projectid = $id;
$projectDetailed->recruitingpersonnel=(int)$data['recruitingpersonnel'];
$projectDetailed->registerserve=(int)$data['registerserve'];
$projectDetailed->servicedescription=$data['servicedescription'];
$projectDetailed->totalnumberoftimecoins=(int)$data['totalnumberoftimecoins'];
$projectDetailed->volunteergender=(int)$data['volunteergender'];
$projectDetailed->volunteerage=(int)$data['volunteerage'];
$projectDetailed->registrationisclosed=$data['registrationisclosed'];
$projectDetailed->serviceduration=$minute=floor((strtotime($data['end_time'])-strtotime($data['start_time']))%86400/60);;
$projectDetailed->save();
return ApiResponse::success(200, []);
}
/**
* @Apidoc\Title("1.0 删除")
* @Apidoc\Url("admin/api/v1/project/del")
* @Apidoc\Param("projectid", type="int",require=true, desc="项目id")
* @Apidoc\Method("POST")
*/
public function del(Request $request)
{
$data = $request->post();
$project = Project::where('id', $data['projectid'])->first();
$projectDetailed = ProjectDetailed::where('projectid', $data['projectid'])->first();
$project->delete();
$projectDetailed->delete();
return ApiResponse::success(200, []);
}
}

View File

@ -0,0 +1,208 @@
<?php
namespace app\controller\admin\api\v1;
use support\Request;
use App\Utils\ApiResponse;
use App\model\Users;
use App\model\BankLog;
use hg\apidoc\annotation as Apidoc;
use App\dao\BankDao;
use Intervention\Image\ImageManagerStatic as Image;
use Exception;
use support\exception\BusinessException;
/**
* @Apidoc\Title("上传文件控制器")
*/
class UploadController
{
protected $noNeedLogin = ['image','index','imageAiEditor'];
/**
* @Apidoc\Title("1.0 测试图片上传")
* @Apidoc\Url("admin/api/v1/Upload/image")
* @Apidoc\Method("POST")
*/
public function image(Request $request)
{
// 调用 base 方法上传文件,指定上传目录
$data = $this->base($request, '/upload/img/' . date('Ymd'));
// 获取上传文件的实际路径
$realpath = $data['realpath'];
try {
// 验证文件类型
$validMimeTypes = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'];
if (!in_array(mime_content_type($realpath), $validMimeTypes)) {
unlink($realpath);
return json([
'code' => 400,
'msg' => '只允许上传图片文件'
]);
}
// 使用 Intervention Image 处理图片
$img = Image::make($realpath);
$max_height = 11700;
$max_width = 11700;
$width = $img->width();
$height = $img->height();
$ratio = 1;
// 如果图片尺寸超过限制,则按比例缩放
if ($height > $max_height || $width > $max_width) {
$ratio = $width > $height ? $max_width / $width : $max_height / $height;
}
// 缩放并保存图片
$img->resize($width * $ratio, $height * $ratio)->save($realpath);
} catch (Exception $e) {
// 出现异常时,删除上传的文件并返回错误信息
unlink($realpath);
return json([
'code' => 500,
'msg' => '处理图片发生错误'
]);
}
// 返回成功的响应,包含图片的 URL、文件名和文件大小
return json([
'code' => 200,
'msg' => '上传成功',
'data' => [
'url' => $data['url'],
'name' => $data['name'],
'size' => $data['size'],
]
]);
}
public function index(Request $request){
return ApiResponse::success(200,[]);
}
/**
* 获取上传数据
* @param Request $request
* @param $relative_dir
* @return array
* @throws BusinessException|\Random\RandomException
*/
protected function base(Request $request, $relative_dir): array
{
$relative_dir = ltrim($relative_dir, '\\/');
$file = current($request->file());
if (!$file || !$file->isValid()) {
throw new BusinessException('未找到上传文件', 400);
}
// 使用配置文件中定义的上传路径
// $uploadPath = config('upload.path'); // 从配置文件中获取路径
$uploadPath = public_path('uploads/images');
$base_dir = rtrim($uploadPath, '\\/');
// 如果路径不存在,创建路径
$full_dir = $base_dir . DIRECTORY_SEPARATOR . $relative_dir;
if (!is_dir($full_dir)) {
mkdir($full_dir, 0777, true);
}
// 处理上传的文件
$ext = $file->getUploadExtension() ?: null;
$mime_type = $file->getUploadMimeType();
$file_name = $file->getUploadName();
$file_size = $file->getSize();
// 文件类型验证
if (!$ext && $file_name === 'blob') {
[$___image, $ext] = explode('/', $mime_type);
unset($___image);
}
$ext = strtolower($ext);
$ext_forbidden_map = ['php', 'php3', 'php5', 'css', 'js', 'html', 'htm', 'asp', 'jsp'];
if (in_array($ext, $ext_forbidden_map)) {
throw new BusinessException('不支持该格式的文件上传', 400);
}
// 生成文件路径
$relative_path = $relative_dir . '/' . bin2hex(pack('Nn', time(), random_int(1, 65535))) . ".$ext";
$full_path = $base_dir . DIRECTORY_SEPARATOR . $relative_path;
// 移动文件到新路径
$file->move($full_path);
$image_with = $image_height = 0;
if ($img_info = getimagesize($full_path)) {
[$image_with, $image_height] = $img_info;
$mime_type = $img_info['mime'];
}
return [
'url' => "https://weapp.ycylzj.com.cn/uploads/images/$relative_path",
'name' => $file_name,
'realpath' => $full_path,
'size' => $file_size,
'mime_type' => $mime_type,
'image_with' => $image_with,
'image_height' => $image_height,
'ext' => $ext,
];
}
/**
* @Apidoc\Title("1.0 AiEditor图片上传")
* @Apidoc\Url("admin/api/v1/Upload/imageAiEditor")
* @Apidoc\Method("POST")
*/
public function imageAiEditor(Request $request)
{
// 调用 base 方法上传文件,指定上传目录
$data = $this->base($request, '/upload/img/' . date('Ymd'));
// 获取上传文件的实际路径
$realpath = $data['realpath'];
try {
// 验证文件类型
$validMimeTypes = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'];
if (!in_array(mime_content_type($realpath), $validMimeTypes)) {
unlink($realpath);
return json([
'code' => 400,
'msg' => '只允许上传图片文件'
]);
}
// 使用 Intervention Image 处理图片
$img = Image::make($realpath);
$max_height = 11700;
$max_width = 11700;
$width = $img->width();
$height = $img->height();
$ratio = 1;
// 如果图片尺寸超过限制,则按比例缩放
if ($height > $max_height || $width > $max_width) {
$ratio = $width > $height ? $max_width / $width : $max_height / $height;
}
// 缩放并保存图片
$img->resize($width * $ratio, $height * $ratio)->save($realpath);
} catch (Exception $e) {
// 出现异常时,删除上传的文件并返回错误信息
unlink($realpath);
return json([
'code' => 500,
'msg' => '处理图片发生错误'
]);
}
// 返回成功的响应,包含图片的 URL、文件名和文件大小
return json([
'errorCode' => 0,
'msg' => '上传成功',
'data' => [
'src' => $data['url'],
'alt' => $data['url'],
]
]);
}
}

View File

@ -0,0 +1,121 @@
<?php
namespace app\controller\admin\api\v1;
use support\Request;
use App\Utils\ApiResponse;
use App\model\Volunteerservicecorp;
use App\model\Users;
use App\model\Volunteerservicecorpsdetailed;
use App\model\Volunteerjoinrequest;
use App\model\Message;
use hg\apidoc\annotation as Apidoc;
use plugin\admin\app\model\User;
use App\dao\VolunteerservicecorpsDao;
/**
* @Apidoc\Title("admin志愿者队伍控制器")
*/
class VolunteerservicecorpsController
{
protected $noNeedLogin = ['get_volunteerservicecorp_list','get_volunteerservicecorp_details','del_volunteerservicecorp','add_volunteerservicecorp','edi_volunteerservicecorp'];
/**
* @Apidoc\Title("1.0 志愿队查询所有")
* @Apidoc\Url("admin/api/v1/Volunteerservicecorps/get_volunteerservicecorp_list")
* @Apidoc\Method("POST")
*/
public function get_volunteerservicecorp_list(Request $request)
{
$tmp = Volunteerservicecorp::all();
$res = [];
foreach ($tmp as $k => $v) {
$tmp2 = Volunteerservicecorpsdetailed::where('groupid', $v->id)->get();
$number = Volunteerservicecorpsdetailed::where('groupid', $v->id)->count();
$leader = Users::where('id', $v->leaderid)->first(['nickname', 'phone', 'avatar']);
foreach ($tmp2 as $key => $value) {
$member[] = Users::where('id', $value->userid)->first(['nickname', 'phone', 'avatar']);
}
$res['group'][] = array('groupname' => $v->groupname, 'leaderid' => $v->leaderid, 'groupid' => $v->id, "category" => $v->category, 'img' => $v->img, 'number' => $number, 'leader' => $leader, 'member' => $member);
}
return ApiResponse::success(200, $res);
}
/**
* @Apidoc\Title("1.0 获取志愿队伍详细信息根据id")
* @Apidoc\Url("admin/api/v1/Volunteerservicecorps/get_volunteerservicecorp_details")
* @Apidoc\Param("volunteerservicecorp_id", type="int",require=true, desc="队伍id")
* @Apidoc\Method("POST")
*/
public function get_volunteerservicecorp_details(Request $request)
{
$data = $request->post();
$volunteerservicecorp_id = $data['volunteerservicecorp_id'];
$tmp = Volunteerservicecorp::where('id', $volunteerservicecorp_id)->get();
$res = [];
foreach ($tmp as $k => $v) {
$tmp2 = Volunteerservicecorpsdetailed::where('groupid', $v->id)->get();
$number = Volunteerservicecorpsdetailed::where('groupid', $v->id)->count();
$leader = Users::where('id', $v->leaderid)->first(['nickname', 'phone', 'avatar']);
foreach ($tmp2 as $key => $value) {
$member[] = Users::where('id', $value->userid)->first(['nickname', 'phone', 'avatar']);
}
$res['group'] = array('groupname' => $v->groupname, 'leaderid' => $v->leaderid, "category" => $v->category, 'briefly' => $v->briefly, 'created_at' => $v->created_at, 'img' => $v->img, 'number' => $number, 'leader' => $leader, 'member' => $member);
}
return ApiResponse::success(200, $res);
}
/**
* @Apidoc\Title("1.0 删除志愿队伍根据id")
* @Apidoc\Url("admin/api/v1/Volunteerservicecorps/del_volunteerservicecorp")
* @Apidoc\Param("groupid", type="int",require=true, desc="队伍id")
* @Apidoc\Method("POST")
*/
public function del_volunteerservicecorp(Request $request){
$data = $request->post();
VolunteerservicecorpsDao::del($data['groupid']);
return ApiResponse::success(200, []);
}
/**
* @Apidoc\Title("1.0 增加志愿队伍")
* @Apidoc\Url("admin/api/v1/Volunteerservicecorps/add_volunteerservicecorp")
* @Apidoc\Param("leaderid", type="int",require=true, desc="组长用户id")
* @Apidoc\Param("groupname", type="string",require=true, desc="组名称")
* @Apidoc\Param("category", type="string",require=true, desc="组分类")
* @Apidoc\Param("img", type="string",require=true, desc="首页图片url")
* @Apidoc\Param("briefly", type="string",require=true, desc="队伍简介")
* @Apidoc\Method("POST")
*/
public function add_volunteerservicecorp(Request $request){
$data = $request->post();
$col_array=['leaderid','groupname','category','img','briefly'];
$Volunteerservicecorp=new Volunteerservicecorp();
foreach($col_array as $v){
$Volunteerservicecorp->$v=$data[$v];
}
$Volunteerservicecorp->save();
return ApiResponse::success(200, []);
}
/**
* @Apidoc\Title("1.0 修改志愿队伍")
* @Apidoc\Url("admin/api/v1/Volunteerservicecorps/add_volunteerservicecorp")
* @Apidoc\Param("leaderid", type="int",require=true, desc="组长用户id")
* @Apidoc\Param("groupname", type="string",require=true, desc="组名称")
* @Apidoc\Param("category", type="string",require=true, desc="组分类")
* @Apidoc\Param("img", type="string",require=true, desc="首页图片url")
* @Apidoc\Param("briefly", type="string",require=true, desc="队伍简介")
* @Apidoc\Param("id", type="int",require=true, desc="队伍id")
* @Apidoc\Method("POST")
*/
public function edi_volunteerservicecorp(Request $request){
$data = $request->post();
$col_array=['leaderid','groupname','category','img','briefly'];
$Volunteerservicecorp=Volunteerservicecorp::where('id',$data['id']);
foreach($col_array as $v){
$Volunteerservicecorp->$v=$data[$v];
}
$Volunteerservicecorp->save();
return ApiResponse::success(200, []);
}
}

View File

@ -0,0 +1,117 @@
<?php
namespace app\controller\api\v1;
use support\Request;
use App\Utils\ApiResponse;
use App\model\Users;
use App\model\BankLog;
use hg\apidoc\annotation as Apidoc;
use App\dao\BankDao;
/**
* @Apidoc\Title("时间币控制器")
*/
class BankController
{
protected $noNeedLogin = ['index'];
/**
* @Apidoc\Title("1.0 测试")
* @Apidoc\Url("api/v1/bank/index")
* @Apidoc\Method("POST")
*/
public function index(Request $request)
{
return ApiResponse::success(200, []);
}
/**
* @Apidoc\Title("1.0 获取当前用户时间币余额")
* @Apidoc\Url("api/v1/bank/get")
* @Apidoc\Method("POST")
* @Apidoc\Returned("timecoin", type="int", desc="余额")
*/
public function get(Request $request)
{
$user = $request->data;
$userid = $user['id'];
$res = Users::where('id', $userid)->first('timecoin');
return ApiResponse::success(200, $res);
}
/**
* @Apidoc\Title("1.0 获取当前用户时间币记录")
* @Apidoc\Url("api/v1/bank/get_back_log")
* @Apidoc\Method("POST")
*/
public function get_back_log(Request $request)
{
$user = $request->data;
$userid = $user['id'];
$res = BankLog::where('userid', $userid)->orderBy('created_at', 'desc')->limit(3)->get();
return ApiResponse::success(200, $res);
}
/**
* @Apidoc\Title("1.0 获取当前用户时间币所有记录")
* @Apidoc\Url("api/v1/bank/get_back_log_all")
* @Apidoc\Method("POST")
*/
public function get_back_log_all(Request $request)
{
$user = $request->data;
$userid = $user['id'];
$res = BankLog::where('userid', $userid)->orderBy('created_at', 'desc')->get();
return ApiResponse::success(200, $res);
}
/**
* @Apidoc\Title("1.0 转账时间币到其他用户")
* @Apidoc\Url("api/v1/bank/transfer")
* @Apidoc\Param("amount", type="int",require=true, desc="金额",default="1")
* @Apidoc\Param("phone", type="int",require=true, desc="收款人手机号",default="我是你爹")
* @Apidoc\Method("POST")
*/
public function transfer(Request $request)
{
$data = $request->post();
$user = $request->data;
$userid = $user['id'];
$amount = $data['amount'];
$phone = $data['phone'];
$res = BankDao::transfer($userid, $phone, $amount);
if($res['status']=='error'){
return ApiResponse::success(402, $res);
}
return ApiResponse::success(200, $res);
}
/**
* @Apidoc\Title("1.0 增加时间币测试")
* @Apidoc\Url("api/v1/bank/add")
* @Apidoc\Param("amount", type="int",require=true, desc="金额",default="1")
* @Apidoc\Param("remark", type="string",require=true, desc="备注",default="我是你爹")
* @Apidoc\Method("POST")
*/
public function add(Request $request)
{
$data = $request->post();
$user = $request->data;
$userid = $user['id'];
$amount = $data['amount'];
$remark = $data['remark'];
BankDao::add($userid, $amount, $remark);
return ApiResponse::success(200, []);
}
/**
* @Apidoc\Title("1.0 搜索转账人")
* @Apidoc\Url("api/v1/bank/search_user")
* @Apidoc\Param("key", type="string",require=true, desc="关键词",default="1")
* @Apidoc\Method("POST")
*/
public function search_user(Request $request)
{
$data = $request->post();
$users = Users::where('nickname', 'like', '%' . $data['key'] . '%')
->orWhere('phone', 'like', '%' . $data['key'] . '%')
->get(['id','nickname','phone']);
return ApiResponse::success(200, $users);
}
}

View File

@ -0,0 +1,101 @@
<?php
namespace app\controller\api\v1;
use support\Request;
use App\Utils\ApiResponse;
use App\model\Users;
use App\model\Contact;
use hg\apidoc\annotation as Apidoc;
use App\dao\BankDao;
/**
* @Apidoc\Title("联系人控制器")
*/
class ContactController
{
/**
* @Apidoc\Title("1.0 获取当前用户联系人列表")
* @Apidoc\Url("api/v1/contact/get")
* @Apidoc\Param("id", type="int",require=false, desc="联系人id",default="")
* @Apidoc\Method("POST")
*/
public function get(Request $request)
{
$user = $request->data;
$userid = $user['id'];
$data = $request->post();
if (isset($data['id'])) {
$res = Contact::where('userid', $userid)->where('id', $data['id'])->first(['id', 'name', 'phone', 'relationship']);
} else {
$res = Contact::where('userid', $userid)->get(['id', 'name', 'phone', 'relationship']);
}
return ApiResponse::success(200, $res);
}
/**
* @Apidoc\Title("1.0 增加联系人")
* @Apidoc\Url("api/v1/contact/add_contact")
* @Apidoc\Method("POST")
* @Apidoc\Param("name", type="string",require=true, desc="联系人姓名",default="我是你爹")
* @Apidoc\Param("phone", type="int",require=true, desc="手机号",default="")
* @Apidoc\Param("relationship", type="int",require=true, desc="关系",default="0")
*/
public function add_contact(Request $request)
{
$user = $request->data;
$userid = $user['id'];
$data = $request->post();
$count=Contact::where('userid',$userid)->where('phone',$data['phone'])->count();
if($count>0){
return ApiResponse::success(402, [],'联系人手机号已存在');
}
$contact = new Contact();
$contact->name = $data['name'];
$contact->phone = $data['phone'];
$contact->relationship = $data['relationship'];
$contact->userid = $userid;
$contact->save();
return ApiResponse::success(200, []);
}
/**
* @Apidoc\Title("1.0 编辑联系人")
* @Apidoc\Url("api/v1/contact/edi_contact")
* @Apidoc\Param("name", type="string",require=true, desc="联系人姓名",default="我是你爹")
* @Apidoc\Param("phone", type="int",require=true, desc="手机号",default="")
* @Apidoc\Param("relationship", type="int",require=true, desc="关系",default="0")
* @Apidoc\Param("id", type="int",require=true, desc="记录id",default="0")
* @Apidoc\Method("POST")
*/
public function edi_contact(Request $request)
{
$user = $request->data;
$userid = $user['id'];
$data = $request->post();
$contact = Contact::where('userid', $userid)->where('id', $data['id'])->first();
$contact->name = $data['name'];
$contact->phone = $data['phone'];
$contact->relationship = $data['relationship'];
$contact->userid = $userid;
$contact->save();
return ApiResponse::success(200, []);
}
/**
* @Apidoc\Title("1.0 删除联系人")
* @Apidoc\Url("api/v1/contact/del_contact")
* @Apidoc\Param("id", type="int",require=true, desc="记录id",default="0")
* @Apidoc\Method("POST")
*/
public function del_contact(Request $request)
{
$user = $request->data;
$userid = $user['id'];
$data = $request->post();
$contact = Contact::where('userid', $userid)->where('id', $data['id'])->first();
$contact->delete();
return ApiResponse::success(200, []);
}
}

View File

@ -0,0 +1,60 @@
<?php
namespace app\controller\api\v1;
use support\Request;
use hg\apidoc\annotation as Apidoc;
use App\Utils\ApiResponse;
use App\model\Dictionary;
// use App\dao\UserDao;
/**
* @Apidoc\Title("客服字典")
*/
class DictionaryController
{
/**d
* @Apidoc\Title("查找所有客服字典")
* @Apidoc\Url("/api/v1/dictionary/lists")
* @Apidoc\Method("POST")
*/
public function lists()
{
//根据id查找用户
$db = Dictionary::all();
//操作不成功
if (!$db) {
return ApiResponse::error (402, '操作失败');
}
return ApiResponse::success (200, $db );
}
/**
* @Apidoc\Title("根据id更新客服字典")
* @Apidoc\Url("/api/v1/dictionary/updateId")
* @Apidoc\Method("POST")
* @Apidoc\Query("id", type="string",require=true, desc="id",default="1")
* @Apidoc\Query("key", type="string",require=true, desc="key",default="1")
* @Apidoc\Query("value", type="string",require=true, desc="value",default="1")
*/
public function updateId(Request $request)
{
$data = $request->post();
foreach ($data as $key => $value) {
$db = Dictionary::where('key', $key)->first();
$db->value = $value;
$db->save();
}
//根据id改数据库中的数据
if (!$db) {
return ApiResponse::error (402, '操作失败');
}
return ApiResponse::success (200, $db );
}
}

View File

@ -0,0 +1,56 @@
<?php
namespace app\controller\api\v1;
use support\Request;
use hg\apidoc\annotation as Apidoc;
use App\Utils\ApiResponse;
use App\model\ExchangeRate;
// use App\dao\UserDao;
/**
* @Apidoc\Title("汇率")
*/
class ExchangeRateController
{
/**
* @Apidoc\Title("查找所有汇率")
* @Apidoc\Url("/api/v1/ExchangeRate/lists")
* @Apidoc\Method("POST")
*/
public function lists()
{
//根据id查找用户
$db = ExchangeRate::all();
//操作不成功
if (!$db) {
return ApiResponse::error (402, '操作失败');
}
return ApiResponse::success (200, $db );
}
/**
* @Apidoc\Title("根据id更新汇率")
* @Apidoc\Url("/api/v1/ExchangeRate/updateId")
* @Apidoc\Method("POST")
* @Apidoc\Query("id", type="string",require=true, desc="id",default="1")
* @Apidoc\Query("points", type="string",require=true, desc="points",default="1")
* @Apidoc\Query("type", type="string",require=true, desc="type",default="1")
*/
public function updateId(Request $request)
{
$data = $request->post();
foreach ($data as $key => $value) {
$db = ExchangeRate::where('type', $key)->first();
$db->points = $value;
$db->save();
}
//根据id改数据库中的数据
if (!$db) {
return ApiResponse::error (402, '操作失败');
}
return ApiResponse::success (200, $db );
}
}

View File

@ -0,0 +1,44 @@
<?php
namespace app\controller\api\v1;
use support\Request;
use App\Utils\ApiResponse;
use App\model\Users;
use App\model\Hotinformation;
use hg\apidoc\annotation as Apidoc;
use App\dao\BankDao;
/**
* @Apidoc\Title("文章控制器")
*/
class HotinformationController
{
protected $noNeedLogin = ['get_list','get_details'];
/**
* @Apidoc\Title("1.0 获取所有文章")
* @Apidoc\Url("api/v1/hotinformation/get_list")
* @Apidoc\Param("type", type="int",require=true, desc="0是热点资讯1是银龄")
* @Apidoc\Method("POST")
*/
public function get_list(Request $request)
{
$data = $request->post();
$res = Hotinformation::where('type', $data['type'])->get();
return ApiResponse::success(200, $res);
}
/**
* @Apidoc\Title("1.0 获取文章详细")
* @Apidoc\Url("api/v1/hotinformation/get_details")
* @Apidoc\Param("id", type="int",require=true, desc="文章id")
* @Apidoc\Method("POST")
*/
public function get_details(Request $request)
{
$data = $request->post();
$res = Hotinformation::where('id', $data['id'])->first();
return ApiResponse::success(200, $res);
}
}

View File

@ -0,0 +1,48 @@
<?php
namespace app\controller\api\v1;
use Webman\Controller;
use support\Request;
use support\Response;
use Webman\File;
use App\Utils\ApiResponse;
class ImageController
{
// 显示上传图片的页面
public function showUploadForm()
{
return view('admin.image_upload');
}
// 处理图片上传
public function upload(Request $request)
{
// 获取上传的文件
$file = $request->file('image');
// 验证文件是否上传成功
if ($file && $file->isValid()) {
// 设置保存路径
$uploadPath = public_path('uploads/images');
// 生成文件名,防止重名
$filename = uniqid('img_', true) . '.' . $file->getUploadExtension();
// 保存文件
$file->move($uploadPath. $filename);
// 返回成功消息
return ApiResponse::success(200, [
'status' => 'success',
'message' => '上传成功!',
'file' => "/uploads/images/{$filename}",
]);
}
// 上传失败
return ApiResponse::success(200, [
'status' => 'error',
'message' => '文件上传失败,请重试。',
]);
}
}

View File

@ -0,0 +1,219 @@
<?php
namespace app\controller\api\v1;
use support\Request;
use hg\apidoc\annotation as Apidoc;
use App\Utils\ApiResponse;
use App\model\Invite;
// use App\dao\UserDao;
/**
* @Apidoc\Title("用户层级")
*/
class InviteController
{
/**
* @Apidoc\Title("根据username找父级")
* @Apidoc\Url("/api/v1/Invite/getDayId")
* @Apidoc\Method("POST")
* @Apidoc\Query("id", type="string",require=true, desc="账户id",default="1")
*/
public function getDayId(Request $request)
{
$data = $request->post();
//根据id查找用户
$db = Invite::where('invitename', $data['id'])->first();
//操作不成功
if (!$db) {
return ApiResponse::error (402, '操作失败');
}
return ApiResponse::success (200, $db );
}
/**
* @Apidoc\Title("根据username找子级")
* @Apidoc\Url("/api/v1/Invite/getSonId")
* @Apidoc\Method("POST")
* @Apidoc\Query("id", type="string",require=true, desc="账户id",default="1")
*/
public function getSonId(Request $request)
{
$data = $request->post();
$db = Invite::where('username', $data['id'])->get();
// 如果查询结果为空,返回错误信息
if ($db->isEmpty()) {
return ApiResponse::error(402, '操作失败');
}
// 成功时返回查询结果
return ApiResponse::success(200, $db);
}
// /**
// * @Apidoc\Title("1.0 登录")
// * @Apidoc\Url("api/v1/user/login")
// * @Apidoc\Method("POST")
// * @Apidoc\Param("phone", type="string",require=true, desc="用户名|手机号")
// * @Apidoc\Param("password", type="string",require=true, desc="密码")
// * @Apidoc\Returned("user", type="object", desc="用户信息")
// * @Apidoc\Returned("token", type="object", desc="令牌")
// */
// public function login(Request $request)
// {
// // 获取请求数据
// $data = $request->post();
// // 根据手机号查询用户
// $db = Users::where('phone', '=', $data['phone'])->first();
// // 如果未找到用户,返回错误
// if (!$db) {
// return ApiResponse::error(402, '用户未注册');
// }
// // 获取用户输入的密码
// $password = $data['password'];
// // 验证密码是否正确
// if (password_verify($password, $db->password)) {
// $user = [
// 'id' => $db->id,
// 'nickname' => $db->nickname,
// 'phone' => $db->phone
// ];
// // 如果密码正确,生成 JWT 令牌
// $token = JwtToken::generateToken($user);
// // 返回成功响应和用户信息(可以将 token 添加到响应中)
// return ApiResponse::success(200, [
// 'user' => $user, // 返回用户信息
// 'token' => $token // 返回生成的 token
// ]);
// } else {
// // 密码错误,返回错误响应
// return ApiResponse::error(402, '密码错误');
// }
// }
// /**
// * @Apidoc\Title("1.0 注册")
// * @Apidoc\Url("api/v1/user/register")
// * @Apidoc\Method("POST")
// * @Apidoc\Param("phone", type="string",require=true, desc="用户名|手机号")
// * @Apidoc\Param("password", type="string",require=true, desc="密码")
// * @Apidoc\Param("idcard", type="string",require=true, desc="身份证号")
// * @Apidoc\Returned("token", type="object", desc="令牌")
// */
// public function register(Request $request)
// {
// $data = $request->post();
// $user = UserDao::register($data['phone'], $data['password'], $data['idcard']);
// if ($user['code'] != 200) {
// return ApiResponse::error(402, [], $user['message']);
// }
// $db = Users::where('phone', '=', $data['phone'])->first();
// $user = [
// 'id' => $db->id,
// 'nickname' => $db->nickname,
// 'phone' => $db->phone
// ];
// // 如果密码正确,生成 JWT 令牌
// $token = JwtToken::generateToken($user);
// $msg = new Message();
// $msg->title ="系统提醒";
// $msg->content = "您已注册成功";
// $msg->type =0;
// $msg->userid =$db->id;
// $msg->parameters="";
// // 返回成功响应和用户信息(可以将 token 添加到响应中)
// return ApiResponse::success(200, [
// 'user' => $user, // 返回用户信息
// 'token' => $token // 返回生成的 token
// ]);
// }
// /**
// * @Apidoc\Title("1.0 修改用户信息")
// * @Apidoc\Url("api/v1/user/edi")
// * @Apidoc\Method("POST")
// * @Apidoc\Param("nickname", type="string",require=true, desc="昵称")
// * @Apidoc\Param("oldpassword", type="string",require=true, desc="旧密码")
// * @Apidoc\Param("password", type="string",require=true, desc="密码")
// */
// public function edi(Request $request)
// {
// $data = $request->post();
// $user = $request->data;
// $userid = $user['id'];
// $db = Users::where('id', '=', $userid)->first();
// if (isset($data['password']) && $data['password'] != '') {
// if (password_verify($data['oldpassword'], $db->password)) {
// UserDao::chang_passwd($userid, $data['password']);
// return ApiResponse::success(200, [], "修改密码成功");
// }
// return ApiResponse::success(402, [], "旧密码错误");
// }
// if (isset($data['nickname']) && $data['nickname'] != '') {
// UserDao::chang_nickname($userid, $data['nickname']);
// $user = [
// 'id' => $db->id,
// 'nickname' => $data['nickname'],
// ];
// // 返回成功响应和用户信息(可以将 token 添加到响应中)
// return ApiResponse::success(200, [
// 'user' => $user, // 返回用户信息
// ]);
// }
// }
// /**
// * @Apidoc\Title("1.0 获取用户信息")
// * @Apidoc\Url("api/v1/user/get_info")
// * @Apidoc\Method("POST")
// */
// public function get_info(Request $request)
// {
// $data = $request->post();
// $user = $request->data;
// $userid = $user['id'];
// $db = Users::where('id', '=', $userid)->first(['phone', 'nickname']);
// return ApiResponse::success(200, $db);
// }
// /**
// * @Apidoc\Title("1.0 设置用户短信是否接受")
// * @Apidoc\Url("api/v1/user/set_msg_setting")
// * @Apidoc\Param("acceptmessages", type="int",require=true, desc="1接受0不接受")
// * @Apidoc\Method("POST")
// */
// public function set_msg_setting(Request $request)
// {
// $data = $request->post();
// $user = $request->data;
// $userid = $user['id'];
// $db = Users::where('id', '=', $userid)->first();
// $db->acceptmessages=$data['acceptmessages'];
// $db->save();
// return ApiResponse::success(200, $db);
// }
// /**
// * @Apidoc\Title("1.0 获取用户短信设置")
// * @Apidoc\Url("api/v1/user/get_msg_setting")
// * @Apidoc\Method("POST")
// */
// public function get_msg_setting(Request $request)
// {
// $data = $request->post();
// $user = $request->data;
// $userid = $user['id'];
// $db = Users::where('id', '=', $userid)->first(['acceptmessages']);
// return ApiResponse::success(200, $db);
// }
}

View File

@ -0,0 +1,266 @@
<?php
namespace app\controller\api\v1;
use support\Request;
use hg\apidoc\annotation as Apidoc;
use App\Utils\ApiResponse;
use App\model\Jobuser;
// use App\dao\UserDao;
/**
* @Apidoc\Title("JOB用户控制器")
*/
class JobuserController
{
/**
* @Apidoc\Title("获取JOB用户列表")
* @Apidoc\Url("/api/v1/jobuser/lists")
* @Apidoc\Method("POST")
* @Apidoc\Param(name="black", type="string", desc="是否黑户", required=false)
* @Apidoc\Param(name="username", type="string", desc="账号", required=false)
*/
public function lists(Request $request)
{
// 获取请求体中的参数
$params = $request->all();
// 初始化查询构造器
$query = Jobuser::query();
if ($params['black'] === null) {
// 查询 black 字段为 null 的记录
$query->whereNull('black');
} else {
// 查询 black 字段等于指定值的记录
$query->where('black', $params['black']);
}
$query->when(!empty($params['username']), function ($query) use ($params) {
$query->where('username', 'like', '%' . $params['username'] . '%');
});
$db = $query->get();
return ApiResponse::success (200, $db);
}
/**
* @Apidoc\Title("拉黑账户")
* @Apidoc\Url("/api/v1/jobuser/getBlack")
* @Apidoc\Method("POST")
* @Apidoc\Query("id", type="string",require=true, desc="账户id",default="1")
*/
public function getBlack(Request $request)
{
$data = $request->post();
//根据id更改数据black字段的值
$db = Jobuser::where('id', $data['id'])->update(['black'=>1]);
//操作不成功
if (!$db) {
return ApiResponse::error (402, '操作失败');
}
return ApiResponse::success (200, $db );
}
/**
* @Apidoc\Title("洗白账户")
* @Apidoc\Url("/api/v1/jobuser/getOutBlack")
* @Apidoc\Method("POST")
* @Apidoc\Query("id", type="string",require=true, desc="账户id",default="1")
*/
public function getOutBlack(Request $request)
{
$data = $request->post();
//根据id更改数据black字段的值
$db = Jobuser::where('id', $data['id'])->update(['black'=>null]);
//操作不成功
if (!$db) {
return ApiResponse::error (402, '操作失败');
}
return ApiResponse::success (200, $db );
}
/**
* @Apidoc\Title("根据id找账户")
* @Apidoc\Url("/api/v1/jobuser/getUserById")
* @Apidoc\Method("POST")
* @Apidoc\Query("id", type="string",require=true, desc="账户id",default="1")
*/
public function getUserById(Request $request)
{
$data = $request->post();
//根据id查找用户
$db = Jobuser::where('user_id', $data['id'])->first();
//操作不成功
if (!$db) {
return ApiResponse::error (402, '操作失败');
}
return ApiResponse::success (200, $db );
}
// /**
// * @Apidoc\Title("1.0 登录")
// * @Apidoc\Url("api/v1/user/login")
// * @Apidoc\Method("POST")
// * @Apidoc\Param("phone", type="string",require=true, desc="用户名|手机号")
// * @Apidoc\Param("password", type="string",require=true, desc="密码")
// * @Apidoc\Returned("user", type="object", desc="用户信息")
// * @Apidoc\Returned("token", type="object", desc="令牌")
// */
// public function login(Request $request)
// {
// // 获取请求数据
// $data = $request->post();
// // 根据手机号查询用户
// $db = Users::where('phone', '=', $data['phone'])->first();
// // 如果未找到用户,返回错误
// if (!$db) {
// return ApiResponse::error(402, '用户未注册');
// }
// // 获取用户输入的密码
// $password = $data['password'];
// // 验证密码是否正确
// if (password_verify($password, $db->password)) {
// $user = [
// 'id' => $db->id,
// 'nickname' => $db->nickname,
// 'phone' => $db->phone
// ];
// // 如果密码正确,生成 JWT 令牌
// $token = JwtToken::generateToken($user);
// // 返回成功响应和用户信息(可以将 token 添加到响应中)
// return ApiResponse::success(200, [
// 'user' => $user, // 返回用户信息
// 'token' => $token // 返回生成的 token
// ]);
// } else {
// // 密码错误,返回错误响应
// return ApiResponse::error(402, '密码错误');
// }
// }
// /**
// * @Apidoc\Title("1.0 注册")
// * @Apidoc\Url("api/v1/user/register")
// * @Apidoc\Method("POST")
// * @Apidoc\Param("phone", type="string",require=true, desc="用户名|手机号")
// * @Apidoc\Param("password", type="string",require=true, desc="密码")
// * @Apidoc\Param("idcard", type="string",require=true, desc="身份证号")
// * @Apidoc\Returned("token", type="object", desc="令牌")
// */
// public function register(Request $request)
// {
// $data = $request->post();
// $user = UserDao::register($data['phone'], $data['password'], $data['idcard']);
// if ($user['code'] != 200) {
// return ApiResponse::error(402, [], $user['message']);
// }
// $db = Users::where('phone', '=', $data['phone'])->first();
// $user = [
// 'id' => $db->id,
// 'nickname' => $db->nickname,
// 'phone' => $db->phone
// ];
// // 如果密码正确,生成 JWT 令牌
// $token = JwtToken::generateToken($user);
// $msg = new Message();
// $msg->title ="系统提醒";
// $msg->content = "您已注册成功";
// $msg->type =0;
// $msg->userid =$db->id;
// $msg->parameters="";
// // 返回成功响应和用户信息(可以将 token 添加到响应中)
// return ApiResponse::success(200, [
// 'user' => $user, // 返回用户信息
// 'token' => $token // 返回生成的 token
// ]);
// }
// /**
// * @Apidoc\Title("1.0 修改用户信息")
// * @Apidoc\Url("api/v1/user/edi")
// * @Apidoc\Method("POST")
// * @Apidoc\Param("nickname", type="string",require=true, desc="昵称")
// * @Apidoc\Param("oldpassword", type="string",require=true, desc="旧密码")
// * @Apidoc\Param("password", type="string",require=true, desc="密码")
// */
// public function edi(Request $request)
// {
// $data = $request->post();
// $user = $request->data;
// $userid = $user['id'];
// $db = Users::where('id', '=', $userid)->first();
// if (isset($data['password']) && $data['password'] != '') {
// if (password_verify($data['oldpassword'], $db->password)) {
// UserDao::chang_passwd($userid, $data['password']);
// return ApiResponse::success(200, [], "修改密码成功");
// }
// return ApiResponse::success(402, [], "旧密码错误");
// }
// if (isset($data['nickname']) && $data['nickname'] != '') {
// UserDao::chang_nickname($userid, $data['nickname']);
// $user = [
// 'id' => $db->id,
// 'nickname' => $data['nickname'],
// ];
// // 返回成功响应和用户信息(可以将 token 添加到响应中)
// return ApiResponse::success(200, [
// 'user' => $user, // 返回用户信息
// ]);
// }
// }
// /**
// * @Apidoc\Title("1.0 获取用户信息")
// * @Apidoc\Url("api/v1/user/get_info")
// * @Apidoc\Method("POST")
// */
// public function get_info(Request $request)
// {
// $data = $request->post();
// $user = $request->data;
// $userid = $user['id'];
// $db = Users::where('id', '=', $userid)->first(['phone', 'nickname']);
// return ApiResponse::success(200, $db);
// }
// /**
// * @Apidoc\Title("1.0 设置用户短信是否接受")
// * @Apidoc\Url("api/v1/user/set_msg_setting")
// * @Apidoc\Param("acceptmessages", type="int",require=true, desc="1接受0不接受")
// * @Apidoc\Method("POST")
// */
// public function set_msg_setting(Request $request)
// {
// $data = $request->post();
// $user = $request->data;
// $userid = $user['id'];
// $db = Users::where('id', '=', $userid)->first();
// $db->acceptmessages=$data['acceptmessages'];
// $db->save();
// return ApiResponse::success(200, $db);
// }
// /**
// * @Apidoc\Title("1.0 获取用户短信设置")
// * @Apidoc\Url("api/v1/user/get_msg_setting")
// * @Apidoc\Method("POST")
// */
// public function get_msg_setting(Request $request)
// {
// $data = $request->post();
// $user = $request->data;
// $userid = $user['id'];
// $db = Users::where('id', '=', $userid)->first(['acceptmessages']);
// return ApiResponse::success(200, $db);
// }
}

View File

@ -0,0 +1,40 @@
<?php
namespace app\controller\api\v1;
use support\Request;
use App\Utils\ApiResponse;
use App\model\Mechanism;
use hg\apidoc\annotation as Apidoc;
/**
* @Apidoc\Title("养老机构控制器")
*/
class MechanismController
{
protected $noNeedLogin = ['get_mechanism_list','get_mechanism_details'];
/**
* @Apidoc\Title("1.0 获取所有养老机构")
* @Apidoc\Url("api/v1/mechanism/get_mechanism_list")
* @Apidoc\Method("POST")
*/
public function get_mechanism_list(Request $request)
{
$res = Mechanism::all();
return ApiResponse::success(200, $res);
}
/**
* @Apidoc\Title("1.0 获取养老机构详细信息")
* @Apidoc\Url("api/v1/mechanism/get_mechanism_details")
* @Apidoc\Param("id", type="int",require=true, desc="养老机构id",default="1")
* @Apidoc\Method("POST")
*/
public function get_mechanism_details(Request $request)
{
$data = $request->post();
$res = Mechanism::where('id', $data['id'])->first();
return ApiResponse::success(200, $res);
}
}

View File

@ -0,0 +1,35 @@
<?php
namespace app\controller\api\v1;
use support\Request;
use App\Utils\ApiResponse;
use hg\apidoc\annotation as Apidoc;
use Tinywan\Jwt\JwtToken;
use App\model\Message;
/**
* @Apidoc\Title("消息提醒控制器")
*/
class MessageController{
/**
* @Apidoc\Title("1.0 获取所有消息")
* @Apidoc\Url("api/v1/message/get_list")
* @Apidoc\Method("POST")
* @Apidoc\Returned("list", type="object", desc="用户消息列表")
*/
public function get_list(Request $request){
$user = $request->data;
$userid=$user['id'];
/**
* 通过中间件获取userid
*/
$userid=$user['id'];
$res = Message::where('userid',$userid)->get();
return ApiResponse::success(200,$res);
}
}

View File

@ -0,0 +1,45 @@
<?php
namespace app\controller\api\v1;
use support\Request;
use App\Utils\ApiResponse;
use App\model\Users;
use App\model\BankLog;
use hg\apidoc\annotation as Apidoc;
use App\dao\BankDao;
use App\model\Mechanism;
use App\model\Hotinformation;
use simplehtmldom\HtmlDocument;
/**
* @Apidoc\Title("自己用的批量修改控制器")
*/
class SetController
{
/**
* @Apidoc\Title("1.0 获取所有养老机构")
* @Apidoc\Url("api/v1/Set/chang_url")
* @Apidoc\Param("url", type="string",require=true, desc="url",default="http://")
* @Apidoc\Method("POST")
*/
public function chang_url(Request $request)
{
$url = "39.98.251.138";
$res = Hotinformation::all();
foreach($res as $k => $v){
$html = new HtmlDocument();
$html->load($v->content);
$img = $html->find('img');
foreach ($img as $paragraph) {
$paragraph->src=str_replace("127.0.0.1:8787", $url, $paragraph->src);
}
$change_img_attr=$html->save();
$v->img=str_replace("127.0.0.1:8787", $url, $v->img);
$v->content = $change_img_attr;
$v->save();
}
return ApiResponse::success(200, $res);
}
}

View File

@ -0,0 +1,186 @@
<?php
namespace app\controller\api\v1;
use support\Request;
use App\Utils\ApiResponse;
use hg\apidoc\annotation as Apidoc;
use Tinywan\Jwt\JwtToken;
use App\model\Users;
use App\model\Message;
use App\dao\UserDao;
/**
* @Apidoc\Title("用户控制器")
*/
class UserController
{
/**
* 不需要登录的方法
*/
protected $noNeedLogin = ['login', 'register'];
/**
* @Apidoc\Title("1.0 登录")
* @Apidoc\Url("api/v1/user/login")
* @Apidoc\Method("POST")
* @Apidoc\Param("phone", type="string",require=true, desc="用户名|手机号")
* @Apidoc\Param("password", type="string",require=true, desc="密码")
* @Apidoc\Returned("user", type="object", desc="用户信息")
* @Apidoc\Returned("token", type="object", desc="令牌")
*/
public function login(Request $request)
{
// 获取请求数据
$data = $request->post();
// 根据手机号查询用户
$db = Users::where('phone', '=', $data['phone'])->first();
// 如果未找到用户,返回错误
if (!$db) {
return ApiResponse::error(402, '用户未注册');
}
// 获取用户输入的密码
$password = $data['password'];
// 验证密码是否正确
if (password_verify($password, $db->password)) {
$user = [
'id' => $db->id,
'nickname' => $db->nickname,
'phone' => $db->phone
];
// 如果密码正确,生成 JWT 令牌
$token = JwtToken::generateToken($user);
// 返回成功响应和用户信息(可以将 token 添加到响应中)
return ApiResponse::success(200, [
'user' => $user, // 返回用户信息
'token' => $token // 返回生成的 token
]);
} else {
// 密码错误,返回错误响应
return ApiResponse::error(402, '密码错误');
}
}
/**
* @Apidoc\Title("1.0 注册")
* @Apidoc\Url("api/v1/user/register")
* @Apidoc\Method("POST")
* @Apidoc\Param("phone", type="string",require=true, desc="用户名|手机号")
* @Apidoc\Param("password", type="string",require=true, desc="密码")
* @Apidoc\Param("idcard", type="string",require=true, desc="身份证号")
* @Apidoc\Returned("token", type="object", desc="令牌")
*/
public function register(Request $request)
{
$data = $request->post();
$user = UserDao::register($data['phone'], $data['password'], $data['idcard']);
if ($user['code'] != 200) {
return ApiResponse::error(402, [], $user['message']);
}
$db = Users::where('phone', '=', $data['phone'])->first();
$user = [
'id' => $db->id,
'nickname' => $db->nickname,
'phone' => $db->phone
];
// 如果密码正确,生成 JWT 令牌
$token = JwtToken::generateToken($user);
$msg = new Message();
$msg->title ="系统提醒";
$msg->content = "您已注册成功";
$msg->type =0;
$msg->userid =$db->id;
$msg->parameters="";
// 返回成功响应和用户信息(可以将 token 添加到响应中)
return ApiResponse::success(200, [
'user' => $user, // 返回用户信息
'token' => $token // 返回生成的 token
]);
}
/**
* @Apidoc\Title("1.0 修改用户信息")
* @Apidoc\Url("api/v1/user/edi")
* @Apidoc\Method("POST")
* @Apidoc\Param("nickname", type="string",require=true, desc="昵称")
* @Apidoc\Param("oldpassword", type="string",require=true, desc="旧密码")
* @Apidoc\Param("password", type="string",require=true, desc="密码")
*/
public function edi(Request $request)
{
$data = $request->post();
$user = $request->data;
$userid = $user['id'];
$db = Users::where('id', '=', $userid)->first();
if (isset($data['password']) && $data['password'] != '') {
if (password_verify($data['oldpassword'], $db->password)) {
UserDao::chang_passwd($userid, $data['password']);
return ApiResponse::success(200, [], "修改密码成功");
}
return ApiResponse::success(402, [], "旧密码错误");
}
if (isset($data['nickname']) && $data['nickname'] != '') {
UserDao::chang_nickname($userid, $data['nickname']);
$user = [
'id' => $db->id,
'nickname' => $data['nickname'],
];
// 返回成功响应和用户信息(可以将 token 添加到响应中)
return ApiResponse::success(200, [
'user' => $user, // 返回用户信息
]);
}
}
/**
* @Apidoc\Title("1.0 获取用户信息")
* @Apidoc\Url("api/v1/user/get_info")
* @Apidoc\Method("POST")
*/
public function get_info(Request $request)
{
$data = $request->post();
$user = $request->data;
$userid = $user['id'];
$db = Users::where('id', '=', $userid)->first(['phone', 'nickname']);
return ApiResponse::success(200, $db);
}
/**
* @Apidoc\Title("1.0 设置用户短信是否接受")
* @Apidoc\Url("api/v1/user/set_msg_setting")
* @Apidoc\Param("acceptmessages", type="int",require=true, desc="1接受0不接受")
* @Apidoc\Method("POST")
*/
public function set_msg_setting(Request $request)
{
$data = $request->post();
$user = $request->data;
$userid = $user['id'];
$db = Users::where('id', '=', $userid)->first();
$db->acceptmessages=$data['acceptmessages'];
$db->save();
return ApiResponse::success(200, $db);
}
/**
* @Apidoc\Title("1.0 获取用户短信设置")
* @Apidoc\Url("api/v1/user/get_msg_setting")
* @Apidoc\Method("POST")
*/
public function get_msg_setting(Request $request)
{
$data = $request->post();
$user = $request->data;
$userid = $user['id'];
$db = Users::where('id', '=', $userid)->first(['acceptmessages']);
return ApiResponse::success(200, $db);
}
}

View File

@ -0,0 +1,178 @@
<?php
namespace app\controller\api\v1;
use support\Request;
use App\Utils\ApiResponse;
use App\model\Volunteerservicecorp;
use App\model\Users;
use App\model\Volunteerservicecorpsdetailed;
use App\model\Volunteerjoinrequest;
use App\model\Message;
use hg\apidoc\annotation as Apidoc;
use plugin\admin\app\model\User;
use App\dao\MessageDao;
/**
* @Apidoc\Title("志愿者队伍控制器")
*/
class VolunteerservicecorpsController
{
protected $noNeedLogin = [];
/**
* @Apidoc\Title("1.0 获取所有志愿队伍")
* @Apidoc\Url("api/v1/Volunteerservicecorps/get_volunteerservicecorp_list")
* @Apidoc\Method("POST")
*/
public function get_volunteerservicecorp_list(Request $request)
{
$tmp = Volunteerservicecorp::all();
$res = [];
foreach ($tmp as $k => $v) {
$tmp2 = Volunteerservicecorpsdetailed::where('groupid', $v->id)->get();
$number = Volunteerservicecorpsdetailed::where('groupid', $v->id)->count();
$leader = Users::where('id', $v->leaderid)->first(['nickname', 'phone', 'avatar']);
foreach ($tmp2 as $key => $value) {
$member[] = Users::where('id', $value->userid)->first(['nickname', 'phone', 'avatar']);
}
$res['group'][] = array('groupname' => $v->groupname, 'leaderid' => $v->leaderid, 'groupid' => $v->id, "category" => $v->category, 'img' => $v->img, 'number' => $number, 'leader' => $leader, 'member' => $member);
}
return ApiResponse::success(200, $res);
}
/**
* @Apidoc\Title("1.0 获取志愿队伍详细信息根据id")
* @Apidoc\Url("api/v1/Volunteerservicecorps/get_volunteerservicecorp_details")
* @Apidoc\Param("volunteerservicecorp_id", type="int",require=true, desc="队伍id")
* @Apidoc\Method("POST")
*/
public function get_volunteerservicecorp_details(Request $request)
{
$data = $request->post();
$volunteerservicecorp_id = $data['volunteerservicecorp_id'];
$tmp = Volunteerservicecorp::where('id', $volunteerservicecorp_id)->get();
$res = [];
foreach ($tmp as $k => $v) {
$tmp2 = Volunteerservicecorpsdetailed::where('groupid', $v->id)->get();
$number = Volunteerservicecorpsdetailed::where('groupid', $v->id)->count();
$leader = Users::where('id', $v->leaderid)->first(['nickname', 'phone', 'avatar']);
foreach ($tmp2 as $key => $value) {
$member[] = Users::where('id', $value->userid)->first(['nickname', 'phone', 'avatar']);
}
$res['group'] = array('groupname' => $v->groupname, 'leaderid' => $v->leaderid, "category" => $v->category, 'briefly' => $v->briefly, 'created_at' => $v->created_at, 'img' => $v->img, 'number' => $number, 'leader' => $leader, 'member' => $member);
}
return ApiResponse::success(200, $res);
}
/**
* @Apidoc\Title("1.0 志愿队伍报名接口")
* @Apidoc\Url("api/v1/Volunteerservicecorps/join")
* @Apidoc\Param("groupid", type="int",require=true, desc="队伍id")
* @Apidoc\Method("POST")
*/
public function join(Request $request)
{
$data = $request->post();
$groupid = $data['groupid'];
$user = $request->data;
$userid = $user['id'];
//志愿者队伍
$isjoin = Volunteerservicecorpsdetailed::where('groupid', $groupid)->where('userid', $userid)->count();
//志愿者申请
$filed = Volunteerjoinrequest::where('groupid', $groupid)->where('userid', $userid)->count();
if ($isjoin > 0) {
return ApiResponse::success(402, [], "您已经报名过了");
}
if ($filed > 0) {
return ApiResponse::success(402, [], "申请已提交,待审核");
}
$tmp = Volunteerservicecorp::where('id', $groupid)->first();
$volunteerjoinrequest = new volunteerjoinrequest();
$volunteerjoinrequest->userid = $userid;
$volunteerjoinrequest->groupid = $groupid;
$volunteerjoinrequest->status = 0;
$volunteerjoinrequest->remark = "";
$volunteerjoinrequest->save();
MessageDao::SendMessage($userid,"系统通知","$tmp->groupname 申请已提交 等待队长审批");
//TODO这里没写队长通知 时间来不及
// Unset($Message);
// $Message = new Message();
// $Message->content = "您有一条待审批消息";
// $Message->title = "系统通知";
$user = User::where('id', $userid)->first();
$json['nickname'] = $user->nickname;
$json['userid'] = $user->id;
$json['groupid'] = $groupid;
// $Message->parameters = json_encode($json);
// $Message->userid = $tmp->leaderid;
// $Message->save();
MessageDao::SendMessage($tmp->leaderid,"系统通知","您有一条待审批消息",json_encode($json));
return ApiResponse::success(200, []);
}
/**
* @Apidoc\Title("1.0 志愿队伍搜索接口")
* @Apidoc\Url("api/v1/Volunteerservicecorps/search")
* @Apidoc\Param("type", type="int",require=true, desc="0是按照类型搜索1是按照名称")
* @Apidoc\Param("key", type="string",require=true, desc="key")
* @Apidoc\Method("POST")
*/
public function search(Request $request)
{
$data = $request->post();
$type = $data['type'];
$key = $data['key'];
var_dump($type);
if ($type == 1) {
$Volunteerservicecorp = Volunteerservicecorp::where('groupname', 'like', '%' . $key . '%')->get();
} else {
$Volunteerservicecorp = Volunteerservicecorp::where('category', 'like', '%' . $key . '%')->get();
}
$tmp = $Volunteerservicecorp;
$res = [];
foreach ($tmp as $k => $v) {
$tmp2 = Volunteerservicecorpsdetailed::where('groupid', $v->id)->get();
$number = Volunteerservicecorpsdetailed::where('groupid', $v->id)->count();
$leader = Users::where('id', $v->leaderid)->first(['nickname', 'phone', 'avatar']);
foreach ($tmp2 as $key => $value) {
$member[] = Users::where('id', $value->userid)->first(['nickname', 'phone', 'avatar']);
}
$res['group'][] = array('groupname' => $v->groupname, 'leaderid' => $v->leaderid, 'groupid' => $v->id, "category" => $v->category, 'img' => $v->img, 'number' => $number, 'leader' => $leader, 'member' => $member);
}
return ApiResponse::success(200, $res);
}
/**
* @Apidoc\Title("1.0 志愿队伍审批接口")
* @Apidoc\Url("api/v1/Volunteerservicecorps/approval")
* @Apidoc\Param("type", type="int",require=true, desc="0同意1不同意")
* @Apidoc\Param("groupid", type="int",require=true, desc="队伍id")
* @Apidoc\Param("userid", type="int",require=true, desc="userid")
* @Apidoc\Method("POST")
*/
public function approval(Request $request)
{
$data = $request->post();
$user = $request->data;
$userid = $user['id'];
$Volunteerservicecorp = Volunteerservicecorp::where('id', $data['groupid'])->first();
if ($userid != $Volunteerservicecorp->leaderid) {
return ApiResponse::success(402, [], '不是队长没有审核权限');
}
if ($user['type'] == 0) {
$volunteerservicecorpsdetailed = new Volunteerservicecorpsdetailed();
$volunteerservicecorpsdetailed->userid = $data['userid'];
$volunteerservicecorpsdetailed->groupid = $data['groupid'];
$volunteerservicecorpsdetailed->save();
$volunteerjoinrequest = volunteerjoinrequest::where('groupid', $data['groupid'])->where('userid', $data['userid'])->first();
$volunteerjoinrequest->status = 2;
$volunteerjoinrequest->save();
$Volunteerservicecorp = Volunteerservicecorp::where('id', $data['groupid'])->first();
MessageDao::SendMessage($data['userid'],"系统通知","您加入的志愿队 $Volunteerservicecorp->groupname 已同意申请");
return ApiResponse::success(200, [], '成功');
}
$volunteerjoinrequest = volunteerjoinrequest::where('groupid', $data['groupid'])->where('userid', $data['userid'])->first();
$volunteerjoinrequest->status = 1;
MessageDao::SendMessage($data['userid'],"系统通知","您加入的志愿队 $Volunteerservicecorp->groupname 已拒绝您的申请");
$volunteerjoinrequest->save();
return ApiResponse::success(200, [], '成功');
}
}

View File

@ -0,0 +1,55 @@
<?php
namespace app\controller\api\v1;
use support\Request;
use hg\apidoc\annotation as Apidoc;
use App\Utils\ApiResponse;
use App\model\Withdraw;
// use App\dao\UserDao;
/**
* @Apidoc\Title("提现管理")
*/
class WithdrawController
{
/**
* @Apidoc\Title("查找所有提现记录")
* @Apidoc\Url("/api/v1/withdraw/lists")
* @Apidoc\Param(name="black", type="string", desc="是否黑户", required=false)
* @Apidoc\Param(name="username", type="string", desc="账号", required=false)
* @Apidoc\Method("POST")
*/
public function lists(Request $request)
{
//根据id查找用户
$db = Withdraw::all();
//操作不成功
if (!$db) {
return ApiResponse::error (402, '操作失败');
}
return ApiResponse::success (200, $db );
}
// /**
// * @Apidoc\Title("根据username找子级")
// * @Apidoc\Url("/api/v1/Invite/getSonId")
// * @Apidoc\Method("POST")
// * @Apidoc\Query("id", type="string",require=true, desc="账户id",default="1")
// */
// public function getSonId(Request $request)
// {
// $data = $request->post();
// $db = Invite::where('username', $data['id'])->get();
// // 如果查询结果为空,返回错误信息
// if ($db->isEmpty()) {
// return ApiResponse::error(402, '操作失败');
// }
// // 成功时返回查询结果
// return ApiResponse::success(200, $db);
// }
}

85
app/dao/BankDao.php Normal file
View File

@ -0,0 +1,85 @@
<?php
namespace app\dao;
use App\model\Users;
use App\model\BankLog;
use plugin\admin\app\model\User;
class BankDao {
/**
* 转账函数
*
* @param int $senderAccountId - 发送账户ID
* @param int $receiverAccountId - 接收账户手机号
* @param float $amount - 转账金额
* @return array - 返回转账结果
*/
public static function transfer($senderAccountId, $receiverAccountId, $amount) {
// 假设账户数据存储在一个简单的数组或数据库中
// 模拟账户余额数据(实际应用中应查询数据库)
$senderAccount=Users::where('id',$senderAccountId)->first();
$receiverAccount=Users::where('phone',$receiverAccountId)->first();
// 检查接收账户是否存在
if (!isset($receiverAccount)) {
return ['status' => 'error', 'message' => '接收账户不存在'];
}
// 检查转账金额是否合法
if ($amount <= 0) {
return ['status' => 'error', 'message' => '时间币必须大于0'];
}
// 检查发送账户余额是否足够
if ($senderAccount->timecoin < $amount) {
return ['status' => 'error', 'message' => '时间币余额不足'];
}
// 执行转账操作
self::add($senderAccount->id,$amount-$amount*2,"赠送给 $receiverAccountId 时间币 $amount");
self::add($receiverAccount->id,$amount,"收到 $senderAccount->phone 赠予 时间币 $amount");
return [
'status' => 'success',
'message' => '转账成功',
];
}
/**
* 增加时间币 传入负数就是减法
*
* @param [type] $userid 用户id
* @param [type] $amount 金额
* @param [type] $remark 备注
* @return void
*/
public static function add($userid, $amount,$remark) {
$user = Users::where('id',$userid)->first();
$log=new BankLog();
$log->userid=$userid;
$log->money=$amount;
$log->remark=$remark;
$log->save();
$user->timecoin+=$amount;
$user->Save();
}
/**
* 减少用户时间币 好像废弃了
*
* @param [type] $userid 用户id
* @param [type] $amount 金额
* @param [type] $remark 备注
* @return void
*/
public static function subtraction($userid, $amount,$remark) {
$user = Users::where('id',$userid)->first('timecoin');
$log=new BankLog();
$log->userid=$userid;
$log->money=$amount;
$log->remark=$remark;
$log->save();
$user->timecoin-=$amount;
$user->Save();
}
}

27
app/dao/MessageDao.php Normal file
View File

@ -0,0 +1,27 @@
<?php
namespace app\dao;
use App\model\Message;
use App\model\BankLog;
use plugin\admin\app\model\User;
class MessageDao {
/**
* 发送消息 提醒
*
* @param [int] $to_user_id 用户id
* @param [string] $title 标题
* @param [string] $content 内容
* @param string $parameters 携带参数
* @return void
*/
public static function SendMessage($to_user_id,$title,$content,$parameters=""){
$Message = new Message();
$Message->content = $content;
$Message->title = $title;
$Message->parameters = $parameters;
$Message->userid = $to_user_id;
$Message->save();
}
}

109
app/dao/UserDao.php Normal file
View File

@ -0,0 +1,109 @@
<?php
namespace app\dao;
use App\model\Users;
use App\model\BankLog;
use App\Utils\FunctionResponse;
class UserDao
{
/**
* 用户注册函数
*
* @param string $phone 手机号
* @param string $password 密码
* @param string $idcard 身份证号
* @return mixed
*/
public static function register($phone, $password, $idcard)
{
// 检测手机号是否唯一
if (Users::where('phone', $phone)->count() > 0) {
return FunctionResponse::error(400, [], '手机号已存在');
}
// 检测身份证号码 并提取信息
$idCardInfo = self::getDetailsFromIdCard($idcard);
if ($idCardInfo['code'] !== 200) {
return $idCardInfo; // 返回错误信息
}
// 你可以在此处添加更多的注册逻辑,例如:存储用户信息到数据库
// 假设我们通过 Users 模型来创建用户
$user = new Users();
$user->phone = $phone;
$user->password = password_hash($password, PASSWORD_DEFAULT); // 密码加密
$user->cardid = $idcard;
$user->birthday = $idCardInfo['data']['birthDate']; // 出生日期
$user->gender = $idCardInfo['data']['gender']; // 性别
$user->avatar = ''; // 头像
$user->save();
return FunctionResponse::success(200, ['$phone' => $phone], '注册成功');
}
/**
* 检查身份证号,提取身份证号信息
*
* @param string $idCard
* @return array
*/
private static function getDetailsFromIdCard($idCard)
{
$birthDate = '';
$gender = '';
// 校验并处理18位身份证
if (strlen($idCard) === 18) {
// 提取出生日期
$birthDate = substr($idCard, 6, 8); // 获取出生日期YYYYMMDD
// 性别判断顺序码第17位奇数为男偶数为女
$genderCode = (int) $idCard[16];
$gender = $genderCode % 2;
} else {
return FunctionResponse::error(400, [], '身份证格式不对');
}
// 格式化出生日期
$birthYear = substr($birthDate, 0, 4);
$birthMonth = substr($birthDate, 4, 2);
$birthDay = substr($birthDate, 6, 2);
$formattedBirthDate = $birthYear . '-' . $birthMonth . '-' . $birthDay;
return FunctionResponse::success(200, [
'birthDate' => $formattedBirthDate, // 出生日期格式化
'gender' => $gender, // 性别
]);
}
/**
* 手机号是否唯一
* @param [string] $phone
* @return [bole] 有手机号返回 true 没有返回flase
*/
private static function isThePhoneNumberUnique($phone)
{
return Users::where('phone', $phone)->count() > 0;
}
/**
* 修改密码
* @param [int] $userid 用户id
* @param [string] $phone 密码
*/
public static function chang_passwd($userid,$password){
//哈希密码
$hasa_password=password_hash($password, PASSWORD_DEFAULT);
Users::where('id', $userid)->update(['password' => $hasa_password]);
}
/**
* 修改用户名
* @param [int] $userid 用户id
* @param [string] $nickname 用户名
*/
public static function chang_nickname($userid,$nickname){
Users::where('id', $userid)->update(['nickname' => $nickname]);
}
}

View File

@ -0,0 +1,33 @@
<?php
namespace app\dao;
use App\model\Users;
use App\model\BankLog;
use App\Utils\FunctionResponse;
use App\model\Volunteerservicecorp;
use App\model\Volunteerservicecorpsdetailed;
use App\model\Volunteerjoinrequest;
/**
* 志愿者服务队Dao层
*/
class VolunteerservicecorpsDao {
/**
* 删除志愿者服务队
* 连带审批记录一起删除
* @param [type] $groupid
* @return void
*/
public static function del($groupid){
$Volunteerservicecorpsdetailed = Volunteerservicecorpsdetailed::where('groupid', $groupid)->first();
$Volunteerservicecorpsdetailed->delete();
$Volunteerservicecorp = Volunteerservicecorp::where('id', $groupid)->first();
$Volunteerservicecorp->delete();
$Volunteerjoinrequest=Volunteerjoinrequest::where('groupid', $groupid)->get();
foreach($Volunteerjoinrequest as $k => $v){
$v->delete();
}
}
}

4
app/functions.php Normal file
View File

@ -0,0 +1,4 @@
<?php
/**
* Here is your custom functions.
*/

View File

@ -0,0 +1,24 @@
<?php
namespace App\Middleware;
use Webman\MiddlewareInterface;
use Webman\Http\Request;
use Webman\Http\Response;
class CorsMiddleware implements MiddlewareInterface
{
public function process(Request $request, callable $handler) : Response
{
// 如果是options请求则返回一个空响应否则继续向洋葱芯穿越并得到一个响应
$response = $request->method() == 'OPTIONS' ? response('') : $handler($request);
// 给响应添加跨域相关的http头
$response->withHeaders([
'Access-Control-Allow-Credentials' => 'true',
'Access-Control-Allow-Origin' => $request->header('origin', '*'),
'Access-Control-Allow-Methods' => $request->header('access-control-request-method', '*'),
'Access-Control-Allow-Headers' => $request->header('access-control-request-headers', '*'),
]);
return $response;
}
}

View File

@ -0,0 +1,69 @@
<?php
namespace App\Middleware;
use Tinywan\Jwt\JwtToken;
use App\Utils\ApiResponse;
use Webman\Http\Request;
use Webman\Http\Response;
use Webman\MiddlewareInterface;
use ReflectionClass;
class JwtAuthMiddleware implements MiddlewareInterface
{
/**
* 处理请求
*
* @param Request $request
* @param callable $handler
* @return Response
*/
public function process(Request $request, callable $handler): Response
{
/**
* 通过反射获取不需要登录的方法
*/
$controller = new ReflectionClass($request->controller);
/**
* apidoc 直接继续向洋葱芯穿越
*/
if($controller->name=='hg\apidoc\Controller'){
return $handler($request);
}
$noNeedLogin = $controller->getDefaultProperties()['noNeedLogin'] ?? [];
if (in_array($request->action, $noNeedLogin)) {
// 不需要登录的方法继续向洋葱芯穿越
return $handler($request);
}
// 获取 Authorization 头部中的 token通常格式为 "Bearer <token>"
$token = $request->header('Authorization') ?? '';
// 检查 token 是否为空
if (empty($token)) {
return ApiResponse::error(401, ['error' => '缺少令牌'], '未授权');
}
// 移除 Bearer 前缀并获取纯 token
// if (strpos($token, 'Bearer ') === 0) {
// $token = substr($token, 7); // 去掉 "Bearer " 部分
// }
try {
// 解码 token返回用户信息
$decoded = JwtToken::getExtend($token);
// var_dump($decoded);
} catch (\Exception $e) {
// 解码失败,返回无效令牌错误
return ApiResponse::error(401, ['error' => '无效的令牌'], '未授权');
}
// 将解码后的用户信息存储到请求对象的 user 属性中
// $request = $request->withAttribute('user', $decoded);
$request->data = $decoded;
// 继续处理请求,传递给下一个中间件或控制器,并返回响应
return $handler($request);
}
}

View File

@ -0,0 +1,42 @@
<?php
/**
* This file is part of webman.
*
* Licensed under The MIT License
* For full copyright and license information, please see the MIT-LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @author walkor<walkor@workerman.net>
* @copyright walkor<walkor@workerman.net>
* @link http://www.workerman.net/
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace app\middleware;
use Webman\MiddlewareInterface;
use Webman\Http\Response;
use Webman\Http\Request;
/**
* Class StaticFile
* @package app\middleware
*/
class StaticFile implements MiddlewareInterface
{
public function process(Request $request, callable $next): Response
{
// Access to files beginning with. Is prohibited
if (strpos($request->path(), '/.') !== false) {
return response('<h1>403 forbidden</h1>', 403);
}
/** @var Response $response */
$response = $next($request);
// Add cross domain HTTP header
/*$response->withHeaders([
'Access-Control-Allow-Origin' => '*',
'Access-Control-Allow-Credentials' => 'true',
]);*/
return $response;
}
}

40
app/model/Admin.php Normal file
View File

@ -0,0 +1,40 @@
<?php
namespace app\model;
use support\Model;
/**
* @property integer $id ID(主键)
* @property string $username 用户名
* @property string $nickname 昵称
* @property string $password 密码
* @property string $avatar 头像
* @property string $email 邮箱
* @property string $mobile 手机
* @property string $created_at 创建时间
* @property string $updated_at 更新时间
* @property string $login_at 登录时间
* @property string $roles 角色
* @property integer $status 状态 0正常 1禁用
*/
class Admin extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'wa_admins';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
}

31
app/model/BankLog.php Normal file
View File

@ -0,0 +1,31 @@
<?php
namespace app\model;
use support\Model;
/**
* @property integer $id 主键(主键)
* @property string $created_at 创建时间
* @property string $updated_at 更新时间
* @property integer $userid 关联用户id
* @property integer $money
* @property string $remark 备注
*/
class BankLog extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'bank_log';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
}

28
app/model/Carousel.php Normal file
View File

@ -0,0 +1,28 @@
<?php
namespace app\model;
use support\Model;
/**
* @property integer $id 主键(主键)
* @property string $created_at 创建时间
* @property string $updated_at 更新时间
* @property string $img_url 图片地址
*/
class Carousel extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'carousel';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
}

31
app/model/Carouselad.php Normal file
View File

@ -0,0 +1,31 @@
<?php
namespace app\model;
use support\Model;
/**
* @property integer $id 主键(主键)
* @property string $created_at 创建时间
* @property string $updated_at 更新时间
* @property string $img_url 图片url
*/
class Carouselad extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'carouselad';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
}

32
app/model/Contact.php Normal file
View File

@ -0,0 +1,32 @@
<?php
namespace app\model;
use support\Model;
/**
* @property integer $id 主键(主键)
* @property string $created_at 创建时间
* @property string $updated_at 更新时间
* @property integer $userid 用户id
* @property integer $relationship 亲属关系0父母1子女2配偶3其他
* @property string $name 姓名
* @property integer $phone 电话
*/
class Contact extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'contact';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
}

32
app/model/Dictionary.php Normal file
View File

@ -0,0 +1,32 @@
<?php
namespace app\model;
use support\Model;
/**
* @property integer $id 主键(主键)
* @property string $created_at 创建时间
* @property string $updated_at 更新时间
* @property string $key key
* @property string $value value
*/
class Dictionary extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'dictionary';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
}

View File

@ -0,0 +1,26 @@
<?php
namespace app\model;
use support\Model;
class ExchangeRate extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'exchange_rate';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
public $timestamps = false;
}

View File

@ -0,0 +1,35 @@
<?php
namespace app\model;
use support\Model;
/**
* @property integer $id 主键(主键)
* @property string $created_at 创建时间
* @property string $updated_at 更新时间
* @property string $title 标题
* @property string $writer 作者
* @property string $content 内容
* @property integer $type 类型0是热点资讯1是银龄动态
* @property string $img 图片地址
*/
class Hotinformation extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'hotinformation';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
}

25
app/model/Invite.php Normal file
View File

@ -0,0 +1,25 @@
<?php
namespace app\model;
use support\Model;
class Invite extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'invite';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
public $timestamps = false;
}

24
app/model/Jobuser.php Normal file
View File

@ -0,0 +1,24 @@
<?php
namespace app\model;
use support\Model;
class Jobuser extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'user';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
public $timestamps = false;
}

34
app/model/Mechanism.php Normal file
View File

@ -0,0 +1,34 @@
<?php
namespace app\model;
use support\Model;
/**
* @property integer $id 主键(主键)
* @property string $created_at 创建时间
* @property string $updated_at 更新时间
* @property string $name 名称
* @property integer $level 星级最高五级
* @property string $address 地址
* @property integer $bed 床位数
* @property string $characteristic 特色
* @property string $briefIntroduction 简介
* @property string $imgurl 首页图片地址
*/
class Mechanism extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'mechanism';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
}

33
app/model/Message.php Normal file
View File

@ -0,0 +1,33 @@
<?php
namespace app\model;
use support\Model;
/**
* @property integer $id 主键(主键)
* @property string $created_at 创建时间
* @property string $updated_at 更新时间
* @property string $title 标题
* @property string $content 内容
* @property integer $type 消息类型 0通知1会话
* @property integer $userid 用户id
* @property string $parameters 携带参数
*/
class Message extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'message';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
}

33
app/model/Project.php Normal file
View File

@ -0,0 +1,33 @@
<?php
namespace app\model;
use support\Model;
/**
* @property integer $id 主键(主键)
* @property string $created_at 创建时间
* @property string $updated_at 更新时间
* @property string $img 首页图
* @property string $start_time 开始时间
* @property string $end_time 结束时间
* @property string $address 地址
* @property string $title 标题
* @property string $type 分类
*/
class Project extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'project';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
}

View File

@ -0,0 +1,35 @@
<?php
namespace app\model;
use support\Model;
/**
* @property string $created_at 创建时间
* @property string $updated_at 更新时间
* @property integer $projectid 对应项目id(主键)
* @property integer $serviceduration 服务时长单位分钟
* @property integer $recruitingpersonnel 招募人数志愿者
* @property integer $registerserve 招募人数被服务者
* @property string $servicedescription 服务说明
* @property integer $totalnumberoftimecoins 时间币/每个人
* @property integer $volunteergender 志愿者性别要求1为男0为女
* @property integer $volunteerage 志愿者年龄
* @property string $registrationisclosed 报名截止日期
*/
class ProjectDetailed extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'project_detailed';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'projectid';
}

View File

@ -0,0 +1,30 @@
<?php
namespace app\model;
use support\Model;
/**
* @property integer $id 主键(主键)
* @property string $created_at 创建时间
* @property string $updated_at 更新时间
* @property integer $projectid 项目id
* @property integer $type 类型0是志愿者1是被服务者
* @property integer $userid 用户id
*/
class ProjectRegister extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'project_register';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
}

29
app/model/Test.php Normal file
View File

@ -0,0 +1,29 @@
<?php
namespace app\model;
use support\Model;
class Test extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'test';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = false;
}

36
app/model/Users.php Normal file
View File

@ -0,0 +1,36 @@
<?php
namespace app\model;
use support\Model;
/**
* @property integer $id 主键(主键)
* @property string $created_at 创建时间
* @property string $updated_at 更新时间
* @property string $cardid 身份证号码
* @property integer $phone 手机号码
* @property string $nickname 昵称
* @property integer $timecoin 时间币
* @property integer $gender 性别1男性0女性
* @property integer $status 1是启用0是禁止
* @property string $birthday 出生日期
* @property string $avatar 头像url地址
* @property string $password 密码
*/
class Users extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'users';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
}

View File

@ -0,0 +1,34 @@
<?php
namespace app\model;
use support\Model;
/**
* @property integer $id 主键(主键)
* @property string $created_at 创建时间
* @property string $updated_at 更新时间
* @property integer $userid 申请加入用户id
* @property integer $status 状态码0提交申请1通过未加入2已完成
* @property string $remark 用户申请备注
* @property integer $groupid 用户申请的志愿队id
*/
class Volunteerjoinrequest extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'volunteerjoinrequest';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
}

View File

@ -0,0 +1,32 @@
<?php
namespace app\model;
use support\Model;
/**
* @property integer $id 主键(主键)
* @property string $created_at 创建时间
* @property string $updated_at 更新时间
* @property integer $leaderid 组长id
* @property string $groupname 组名
* @property string $category 类目|分割
* @property string $img 主要图
* @property string $briefly 队伍简介
*/
class Volunteerservicecorp extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'volunteerservicecorps';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
}

View File

@ -0,0 +1,32 @@
<?php
namespace app\model;
use support\Model;
/**
* @property integer $id 主键(主键)
* @property string $created_at 创建时间
* @property string $updated_at 更新时间
* @property integer $userid 用户id
* @property integer $groupid 对应的组id
*/
class Volunteerservicecorpsdetailed extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'volunteerservicecorpsdetailed';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
}

25
app/model/Withdraw.php Normal file
View File

@ -0,0 +1,25 @@
<?php
namespace app\model;
use support\Model;
class Withdraw extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'withdraw';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
public $timestamps = false;
}

10
app/process/Http.php Normal file
View File

@ -0,0 +1,10 @@
<?php
namespace app\process;
use Webman\App;
class Http extends App
{
}

258
app/process/Monitor.php Normal file
View File

@ -0,0 +1,258 @@
<?php
/**
* This file is part of webman.
*
* Licensed under The MIT License
* For full copyright and license information, please see the MIT-LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @author walkor<walkor@workerman.net>
* @copyright walkor<walkor@workerman.net>
* @link http://www.workerman.net/
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace app\process;
use FilesystemIterator;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use SplFileInfo;
use Workerman\Timer;
use Workerman\Worker;
/**
* Class FileMonitor
* @package process
*/
class Monitor
{
/**
* @var array
*/
protected $paths = [];
/**
* @var array
*/
protected $extensions = [];
/**
* @var array
*/
protected $loadedFiles = [];
/**
* @var string
*/
public static $lockFile = __DIR__ . '/../../runtime/monitor.lock';
/**
* Pause monitor
* @return void
*/
public static function pause()
{
file_put_contents(static::$lockFile, time());
}
/**
* Resume monitor
* @return void
*/
public static function resume(): void
{
clearstatcache();
if (is_file(static::$lockFile)) {
unlink(static::$lockFile);
}
}
/**
* Whether monitor is paused
* @return bool
*/
public static function isPaused(): bool
{
clearstatcache();
return file_exists(static::$lockFile);
}
/**
* FileMonitor constructor.
* @param $monitorDir
* @param $monitorExtensions
* @param array $options
*/
public function __construct($monitorDir, $monitorExtensions, array $options = [])
{
static::resume();
$this->paths = (array)$monitorDir;
$this->extensions = $monitorExtensions;
foreach (get_included_files() as $index => $file) {
$this->loadedFiles[$file] = $index;
if (strpos($file, 'webman-framework/src/support/App.php')) {
break;
}
}
if (!Worker::getAllWorkers()) {
return;
}
$disableFunctions = explode(',', ini_get('disable_functions'));
if (in_array('exec', $disableFunctions, true)) {
echo "\nMonitor file change turned off because exec() has been disabled by disable_functions setting in " . PHP_CONFIG_FILE_PATH . "/php.ini\n";
} else {
if ($options['enable_file_monitor'] ?? true) {
Timer::add(1, function () {
$this->checkAllFilesChange();
});
}
}
$memoryLimit = $this->getMemoryLimit($options['memory_limit'] ?? null);
if ($memoryLimit && ($options['enable_memory_monitor'] ?? true)) {
Timer::add(60, [$this, 'checkMemory'], [$memoryLimit]);
}
}
/**
* @param $monitorDir
* @return bool
*/
public function checkFilesChange($monitorDir): bool
{
static $lastMtime, $tooManyFilesCheck;
if (!$lastMtime) {
$lastMtime = time();
}
clearstatcache();
if (!is_dir($monitorDir)) {
if (!is_file($monitorDir)) {
return false;
}
$iterator = [new SplFileInfo($monitorDir)];
} else {
// recursive traversal directory
$dirIterator = new RecursiveDirectoryIterator($monitorDir, FilesystemIterator::SKIP_DOTS | FilesystemIterator::FOLLOW_SYMLINKS);
$iterator = new RecursiveIteratorIterator($dirIterator);
}
$count = 0;
foreach ($iterator as $file) {
$count ++;
/** var SplFileInfo $file */
if (is_dir($file->getRealPath())) {
continue;
}
// check mtime
if (in_array($file->getExtension(), $this->extensions, true) && $lastMtime < $file->getMTime()) {
$lastMtime = $file->getMTime();
if (DIRECTORY_SEPARATOR === '/' && isset($this->loadedFiles[$file->getRealPath()])) {
echo "$file updated but cannot be reloaded because only auto-loaded files support reload.\n";
continue;
}
$var = 0;
exec('"'.PHP_BINARY . '" -l ' . $file, $out, $var);
if ($var) {
continue;
}
echo $file . " updated and reload\n";
// send SIGUSR1 signal to master process for reload
if (DIRECTORY_SEPARATOR === '/') {
posix_kill(posix_getppid(), SIGUSR1);
} else {
return true;
}
break;
}
}
if (!$tooManyFilesCheck && $count > 1000) {
echo "Monitor: There are too many files ($count files) in $monitorDir which makes file monitoring very slow\n";
$tooManyFilesCheck = 1;
}
return false;
}
/**
* @return bool
*/
public function checkAllFilesChange(): bool
{
if (static::isPaused()) {
return false;
}
foreach ($this->paths as $path) {
if ($this->checkFilesChange($path)) {
return true;
}
}
return false;
}
/**
* @param $memoryLimit
* @return void
*/
public function checkMemory($memoryLimit)
{
if (static::isPaused() || $memoryLimit <= 0) {
return;
}
$ppid = posix_getppid();
$childrenFile = "/proc/$ppid/task/$ppid/children";
if (!is_file($childrenFile) || !($children = file_get_contents($childrenFile))) {
return;
}
foreach (explode(' ', $children) as $pid) {
$pid = (int)$pid;
$statusFile = "/proc/$pid/status";
if (!is_file($statusFile) || !($status = file_get_contents($statusFile))) {
continue;
}
$mem = 0;
if (preg_match('/VmRSS\s*?:\s*?(\d+?)\s*?kB/', $status, $match)) {
$mem = $match[1];
}
$mem = (int)($mem / 1024);
if ($mem >= $memoryLimit) {
posix_kill($pid, SIGINT);
}
}
}
/**
* Get memory limit
* @return float
*/
protected function getMemoryLimit($memoryLimit)
{
if ($memoryLimit === 0) {
return 0;
}
$usePhpIni = false;
if (!$memoryLimit) {
$memoryLimit = ini_get('memory_limit');
$usePhpIni = true;
}
if ($memoryLimit == -1) {
return 0;
}
$unit = strtolower($memoryLimit[strlen($memoryLimit) - 1]);
if ($unit === 'g') {
$memoryLimit = 1024 * (int)$memoryLimit;
} else if ($unit === 'm') {
$memoryLimit = (int)$memoryLimit;
} else if ($unit === 'k') {
$memoryLimit = ((int)$memoryLimit / 1024);
} else {
$memoryLimit = ((int)$memoryLimit / (1024 * 1024));
}
if ($memoryLimit < 30) {
$memoryLimit = 30;
}
if ($usePhpIni) {
$memoryLimit = (int)(0.8 * $memoryLimit);
}
return $memoryLimit;
}
}

14
app/view/index/view.html Normal file
View File

@ -0,0 +1,14 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="/favicon.ico"/>
<title>webman</title>
</head>
<body>
hello <?=htmlspecialchars($name)?>
</body>
</html>

66
composer.json Normal file
View File

@ -0,0 +1,66 @@
{
"name": "workerman/webman",
"type": "project",
"keywords": [
"high performance",
"http service"
],
"homepage": "https://www.workerman.net",
"license": "MIT",
"description": "High performance HTTP Service Framework.",
"authors": [
{
"name": "walkor",
"email": "walkor@workerman.net",
"homepage": "https://www.workerman.net",
"role": "Developer"
}
],
"support": {
"email": "walkor@workerman.net",
"issues": "https://github.com/walkor/webman/issues",
"forum": "https://wenda.workerman.net/",
"wiki": "https://workerman.net/doc/webman",
"source": "https://github.com/walkor/webman"
},
"require": {
"php": ">=7.2",
"workerman/webman-framework": "^1.5.0",
"monolog/monolog": "^2.0",
"webman/admin": "^0.6.33",
"tinywan/jwt": "^1.6",
"webman-micro/migrations": "^1.0",
"webman/console": "^1.3",
"vlucas/phpdotenv": "^5.6",
"hg/apidoc": "^5.2",
"hhink/webman-sms": "^1.0",
"simplehtmldom/simplehtmldom": "^2.0@RC"
},
"suggest": {
"ext-event": "For better performance. "
},
"autoload": {
"psr-4": {
"": "./",
"app\\": "./app",
"App\\": "./app",
"app\\View\\Components\\": "./app/view/components"
},
"files": [
"./support/helpers.php"
]
},
"scripts": {
"post-package-install": [
"support\\Plugin::install"
],
"post-package-update": [
"support\\Plugin::install"
],
"pre-package-uninstall": [
"support\\Plugin::uninstall"
]
},
"minimum-stability": "dev",
"prefer-stable": true
}

5023
composer.lock generated Normal file

File diff suppressed because it is too large Load Diff

26
config/app.php Normal file
View File

@ -0,0 +1,26 @@
<?php
/**
* This file is part of webman.
*
* Licensed under The MIT License
* For full copyright and license information, please see the MIT-LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @author walkor<walkor@workerman.net>
* @copyright walkor<walkor@workerman.net>
* @link http://www.workerman.net/
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
use support\Request;
return [
'debug' => true,
'error_reporting' => E_ALL,
'default_timezone' => 'Asia/Shanghai',
'request_class' => Request::class,
'public_path' => base_path() . DIRECTORY_SEPARATOR . 'public',
'runtime_path' => base_path(false) . DIRECTORY_SEPARATOR . 'runtime',
'controller_suffix' => 'Controller',
'controller_reuse' => false,
];

21
config/autoload.php Normal file
View File

@ -0,0 +1,21 @@
<?php
/**
* This file is part of webman.
*
* Licensed under The MIT License
* For full copyright and license information, please see the MIT-LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @author walkor<walkor@workerman.net>
* @copyright walkor<walkor@workerman.net>
* @link http://www.workerman.net/
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
return [
'files' => [
base_path() . '/app/functions.php',
base_path() . '/support/Request.php',
base_path() . '/support/Response.php',
]
];

18
config/bootstrap.php Normal file
View File

@ -0,0 +1,18 @@
<?php
/**
* This file is part of webman.
*
* Licensed under The MIT License
* For full copyright and license information, please see the MIT-LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @author walkor<walkor@workerman.net>
* @copyright walkor<walkor@workerman.net>
* @link http://www.workerman.net/
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
return [
support\bootstrap\Session::class,
support\bootstrap\LaravelDb::class,
];

30
config/cache.php Normal file
View File

@ -0,0 +1,30 @@
<?php
/**
* This file is part of webman.
*
* Licensed under The MIT License
* For full copyright and license information, please see the MIT-LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @author walkor<walkor@workerman.net>
* @copyright walkor<walkor@workerman.net>
* @link http://www.workerman.net/
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
return [
'default' => 'file',
'stores' => [
'file' => [
'driver' => 'file',
'path' => runtime_path('cache')
],
'redis' => [
'driver' => 'redis',
'connection' => 'default'
],
'array' => [
'driver' => 'array'
]
]
];

15
config/container.php Normal file
View File

@ -0,0 +1,15 @@
<?php
/**
* This file is part of webman.
*
* Licensed under The MIT License
* For full copyright and license information, please see the MIT-LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @author walkor<walkor@workerman.net>
* @copyright walkor<walkor@workerman.net>
* @link http://www.workerman.net/
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
return new Webman\Container;

45
config/database.php Normal file
View File

@ -0,0 +1,45 @@
<?php
/**
* This file is part of webman.
*
* Licensed under The MIT License
* For full copyright and license information, please see the MIT-LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @author walkor<walkor@workerman.net>
* @copyright walkor<walkor@workerman.net>
* @link http://www.workerman.net/
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
return [
'default' => 'mysql',
'connections' => [
// 'mysql' => [
// 'driver' => 'mysql',
// 'host' => '149.129.107.38',
// 'port' => '3306',
// 'database' => 'wechatapplet',
// 'username' => 'wechatapplet',
// 'password' => 'Br6D722xXGB4tR7Z',
// 'charset' => 'utf8mb4',
// 'collation' => 'utf8mb4_general_ci',
// 'prefix' => '',
// 'strict' => true,
// 'engine' => null,
// ],
'mysql' => [
'driver' => 'mysql',
'host' => '127.0.0.1',
'port' => '3306',
'database' => 'app_hd',
'username' => 'root',
'password' => '123456',
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_general_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
],
];

15
config/dependence.php Normal file
View File

@ -0,0 +1,15 @@
<?php
/**
* This file is part of webman.
*
* Licensed under The MIT License
* For full copyright and license information, please see the MIT-LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @author walkor<walkor@workerman.net>
* @copyright walkor<walkor@workerman.net>
* @link http://www.workerman.net/
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
return [];

5
config/event.php Normal file
View File

@ -0,0 +1,5 @@
<?php
return [
];

17
config/exception.php Normal file
View File

@ -0,0 +1,17 @@
<?php
/**
* This file is part of webman.
*
* Licensed under The MIT License
* For full copyright and license information, please see the MIT-LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @author walkor<walkor@workerman.net>
* @copyright walkor<walkor@workerman.net>
* @link http://www.workerman.net/
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
return [
'' => support\exception\Handler::class,
];

32
config/log.php Normal file
View File

@ -0,0 +1,32 @@
<?php
/**
* This file is part of webman.
*
* Licensed under The MIT License
* For full copyright and license information, please see the MIT-LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @author walkor<walkor@workerman.net>
* @copyright walkor<walkor@workerman.net>
* @link http://www.workerman.net/
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
return [
'default' => [
'handlers' => [
[
'class' => Monolog\Handler\RotatingFileHandler::class,
'constructor' => [
runtime_path() . '/logs/webman.log',
7, //$maxFiles
Monolog\Logger::DEBUG,
],
'formatter' => [
'class' => Monolog\Formatter\LineFormatter::class,
'constructor' => [null, 'Y-m-d H:i:s', true],
],
]
],
],
];

21
config/middleware.php Normal file
View File

@ -0,0 +1,21 @@
<?php
/**
* This file is part of webman.
*
* Licensed under The MIT License
* For full copyright and license information, please see the MIT-LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @author walkor<walkor@workerman.net>
* @copyright walkor<walkor@workerman.net>
* @link http://www.workerman.net/
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
return [
'' => [
// ... 这里省略其它中间件
app\middleware\CorsMiddleware::class,
app\middleware\JwtAuthMiddleware::class,
]
];

View File

@ -0,0 +1,97 @@
<?php
return [
'enable' => true,
'apidoc' => [
// (选配)文档标题,显示在左上角与首页
'title' => 'Apidoc',
// (选配)文档描述,显示在首页
'desc' => '',
// (必须)设置文档的应用/版本
'apps' => [
[
// (必须)标题
'title'=>'Api接口',
// (必须)控制器目录地址
'path'=>'app\controller',
// 必须唯一的key
'key'=>'api',
]
],
// (必须)指定通用注释定义的文件地址
'definitions' => "app\common\controller\Definitions",
// 必须自动生成url规则当接口不添加@Apidoc\Url ("xxx")注解时,使用以下规则自动生成
'auto_url' => [
// 字母规则lcfirst=首字母小写ucfirst=首字母大写;
'letter_rule' => "lcfirst",
// url前缀
'prefix'=>"",
],
// (选配)是否自动注册路由
'auto_register_routes'=>false,
// (必须)缓存配置
'cache' => [
// 是否开启缓存
'enable' => false,
],
// (必须)权限认证配置
'auth' => [
// 是否启用密码验证
'enable' => false,
// 全局访问密码
'password' => "123456",
// 密码加密盐
'secret_key' => "apidoc#hg_code",
// 授权访问后的有效期
'expire' => 24*60*60
],
// 全局参数
'params'=>[
// 选配全局的请求Header
'header'=>[
// name=字段名type=字段类型require=是否必须default=默认值desc=字段描述
['name'=>'Authorization','type'=>'string','require'=>true,'desc'=>'身份令牌Token'],
],
// 选配全局的请求Query
'query'=>[
// 同上 header
],
// 选配全局的请求Body
'body'=>[
// 同上 header
],
],
// 全局响应体
'responses'=>[
// 成功响应体
'success'=>[
['name'=>'code','desc'=>'业务代码','type'=>'int','require'=>1],
['name'=>'message','desc'=>'业务信息','type'=>'string','require'=>1],
//参数同上 headersmain=true来指定接口Returned参数挂载节点
['name'=>'data','desc'=>'业务数据','main'=>true,'type'=>'object','require'=>1],
],
// 异常响应体
'error'=>[
['name'=>'code','desc'=>'业务代码','type'=>'int','require'=>1,'md'=>'/docs/HttpError.md'],
['name'=>'message','desc'=>'业务信息','type'=>'string','require'=>1],
]
],
//(选配)默认作者
'default_author'=>'',
//(选配)默认请求类型
'default_method'=>'GET',
//选配Apidoc允许跨域访问
'allowCrossDomain'=>false,
/**
* (选配)解析时忽略带@注解的关键词,当注解中存在带@字符并且非Apidoc注解 @key test此时Apidoc页面报类似以下错误时:
* [Semantical Error] The annotation "@key" in method xxx() was never imported. Did you maybe forget to add a "use" statement for this annotation?
*/
'ignored_annitation'=>[],
// (选配)数据库配置
'database'=>[],
// 选配Markdown文档
'docs' => [],
// (选配)接口生成器配置 注意:是一个二维数组
'generator' =>[]
]
];

View File

@ -0,0 +1,3 @@
<?php
// 注册Apidoc路由
hg\apidoc\providers\WebmanService::register();

View File

@ -0,0 +1,32 @@
<?php
use Overtrue\EasySms\Strategies\OrderStrategy;
return [
'enable' => true,
// HTTP 请求的超时时间(秒)
'timeout' => 5.0,
// 默认发送配置
'default' => [
// 网关调用策略,默认:顺序调用
'strategy' => OrderStrategy::class,
// 默认可用的发送网关
'gateways' => [
'aliyun',
],
],
// 可用的网关配置
'gateways' => [
'errorlog' => [
'file' => '/tmp/easy-sms.log',
],
'aliyun' => [
'access_key_id' => '************',
'access_key_secret' => '**********************',
'sign_name' => '签名',
],
],
];

View File

@ -0,0 +1,71 @@
<?php
return [
'enable' => true,
'jwt' => [
// 算法类型 HS256、HS384、HS512、RS256、RS384、RS512、ES256、ES384、Ed25519
'algorithms' => 'HS256',
// access令牌秘钥
'access_secret_key' => '2022d3d3LmJq',
// access令牌过期时间单位秒。默认 2 小时
'access_exp' => 7200,
// refresh令牌秘钥
'refresh_secret_key' => '2022KTxigxc9o50c',
// refresh令牌过期时间单位秒。默认 7 天
'refresh_exp' => 604800,
// refresh 令牌是否禁用,默认不禁用 false
'refresh_disable' => false,
// 令牌签发者
'iss' => 'webman.tinywan.cn',
// 某个时间点后才能访问单位秒。30 表示当前时间30秒后才能使用
'nbf' => 0,
// 时钟偏差冗余时间,单位秒。建议这个余地应该不大于几分钟。
'leeway' => 60,
// 单设备登录
'is_single_device' => false,
// 缓存令牌时间,单位:秒。默认 7 天
'cache_token_ttl' => 604800,
// 缓存令牌前缀
'cache_token_pre' => 'JWT:TOKEN:',
// 用户信息模型
'user_model' => function($uid){
return [];
},
/**
* access令牌私钥
*/
'access_private_key' => <<<EOD
-----BEGIN RSA PRIVATE KEY-----
...
-----END RSA PRIVATE KEY-----
EOD,
/**
* access令牌公钥
*/
'access_public_key' => <<<EOD
-----BEGIN PUBLIC KEY-----
...
-----END PUBLIC KEY-----
EOD,
/**
* refresh令牌私钥
*/
'refresh_private_key' => <<<EOD
-----BEGIN RSA PRIVATE KEY-----
...
-----END RSA PRIVATE KEY-----
EOD,
/**
* refresh令牌公钥
*/
'refresh_public_key' => <<<EOD
-----BEGIN PUBLIC KEY-----
...
-----END PUBLIC KEY-----
EOD,
],
];

View File

@ -0,0 +1,21 @@
<?php
return [
'enable' => true,
"paths" => [
"migrations" => "database/migrations",
"seeds" => "database/seeders"
],
"environments" => [
"default_migration_table" => "phinxlog",
"default_environment" => "product",
"product" => [
"adapter" => "mysql",
"host" => getenv("DB_HOST", '149.129.107.38'),
"name" => getenv("DB_NAME", 'wechatapplet'),
"user" => getenv("DB_USER", 'wechatapplet'),
"pass" => getenv("DB_PASSWORD", 'Br6D722xXGB4tR7Z'),
"port" => getenv("DB_PORT", '3306'),
"charset" => "utf8"
]
]
];

View File

@ -0,0 +1,14 @@
<?php
declare(strict_types=1);
return [
WebmanMicro\Migrations\Command\Breakpoint::class,
WebmanMicro\Migrations\Command\Create::class,
WebmanMicro\Migrations\Command\Migrate::class,
WebmanMicro\Migrations\Command\Rollback::class,
WebmanMicro\Migrations\Command\SeedCreate::class,
WebmanMicro\Migrations\Command\SeedRun::class,
WebmanMicro\Migrations\Command\Status::class,
WebmanMicro\Migrations\Command\ListAliases::class,
WebmanMicro\Migrations\Command\Test::class
];

View File

@ -0,0 +1,24 @@
<?php
return [
'enable' => true,
'build_dir' => BASE_PATH . DIRECTORY_SEPARATOR . 'build',
'phar_filename' => 'webman.phar',
'bin_filename' => 'webman.bin',
'signature_algorithm'=> Phar::SHA256, //set the signature algorithm for a phar and apply it. The signature algorithm must be one of Phar::MD5, Phar::SHA1, Phar::SHA256, Phar::SHA512, or Phar::OPENSSL.
'private_key_file' => '', // The file path for certificate or OpenSSL private key file.
'exclude_pattern' => '#^(?!.*(composer.json|/.github/|/.idea/|/.git/|/.setting/|/runtime/|/vendor-bin/|/build/|/vendor/webman/admin/))(.*)$#',
'exclude_files' => [
'.env', 'LICENSE', 'composer.json', 'composer.lock', 'start.php', 'webman.phar', 'webman.bin'
],
'custom_ini' => '
memory_limit = 256M
',
];

View File

@ -0,0 +1,4 @@
<?php
return [
'enable' => true,
];

View File

@ -0,0 +1,17 @@
<?php
/**
* This file is part of webman.
*
* Licensed under The MIT License
* For full copyright and license information, please see the MIT-LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @author walkor<walkor@workerman.net>
* @copyright walkor<walkor@workerman.net>
* @link http://www.workerman.net/
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
return [
Webman\Event\BootStrap::class,
];

View File

@ -0,0 +1,7 @@
<?php
use Webman\Event\EventListCommand;
return [
EventListCommand::class
];

62
config/process.php Normal file
View File

@ -0,0 +1,62 @@
<?php
/**
* This file is part of webman.
*
* Licensed under The MIT License
* For full copyright and license information, please see the MIT-LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @author walkor<walkor@workerman.net>
* @copyright walkor<walkor@workerman.net>
* @link http://www.workerman.net/
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
use support\Log;
use support\Request;
use app\process\Http;
global $argv;
return [
'webman' => [
'handler' => Http::class,
'listen' => 'http://0.0.0.0:8787',
'count' => cpu_count() * 4,
'user' => '',
'group' => '',
'reusePort' => false,
'eventLoop' => '',
'context' => [],
'constructor' => [
'requestClass' => Request::class,
'logger' => Log::channel('default'),
'appPath' => app_path(),
'publicPath' => public_path()
]
],
// File update detection and automatic reload
'monitor' => [
'handler' => app\process\Monitor::class,
'reloadable' => false,
'constructor' => [
// Monitor these directories
'monitorDir' => array_merge([
app_path(),
config_path(),
base_path() . '/process',
base_path() . '/support',
base_path() . '/resource',
base_path() . '/.env',
], glob(base_path() . '/plugin/*/app'), glob(base_path() . '/plugin/*/config'), glob(base_path() . '/plugin/*/api')),
// Files with these suffixes will be monitored
'monitorExtensions' => [
'php', 'html', 'htm', 'env'
],
'options' => [
'enable_file_monitor' => !in_array('-d', $argv) && DIRECTORY_SEPARATOR === '/',
'enable_memory_monitor' => DIRECTORY_SEPARATOR === '/',
]
]
]
];

22
config/redis.php Normal file
View File

@ -0,0 +1,22 @@
<?php
/**
* This file is part of webman.
*
* Licensed under The MIT License
* For full copyright and license information, please see the MIT-LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @author walkor<walkor@workerman.net>
* @copyright walkor<walkor@workerman.net>
* @link http://www.workerman.net/
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
return [
'default' => [
'host' => '127.0.0.1',
'password' => null,
'port' => 6379,
'database' => 0,
],
];

21
config/route.php Normal file
View File

@ -0,0 +1,21 @@
<?php
/**
* This file is part of webman.
*
* Licensed under The MIT License
* For full copyright and license information, please see the MIT-LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @author walkor<walkor@workerman.net>
* @copyright walkor<walkor@workerman.net>
* @link http://www.workerman.net/
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
use Webman\Route;
use App\Middleware\JwtAuthMiddleware;
Route::any('/login', [app\controller\UserController::class, 'login'])->middleware([JwtAuthMiddleware::class]);
Route::any('/signup', [app\controller\ProjectRegisterController::class, 'signup'])->middleware([JwtAuthMiddleware::class]);

23
config/server.php Normal file
View File

@ -0,0 +1,23 @@
<?php
/**
* This file is part of webman.
*
* Licensed under The MIT License
* For full copyright and license information, please see the MIT-LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @author walkor<walkor@workerman.net>
* @copyright walkor<walkor@workerman.net>
* @link http://www.workerman.net/
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
return [
'event_loop' => '',
'stop_timeout' => 2,
'pid_file' => runtime_path() . '/webman.pid',
'status_file' => runtime_path() . '/webman.status',
'stdout_file' => runtime_path() . '/logs/stdout.log',
'log_file' => runtime_path() . '/logs/workerman.log',
'max_package_size' => 10 * 1024 * 1024
];

65
config/session.php Normal file
View File

@ -0,0 +1,65 @@
<?php
/**
* This file is part of webman.
*
* Licensed under The MIT License
* For full copyright and license information, please see the MIT-LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @author walkor<walkor@workerman.net>
* @copyright walkor<walkor@workerman.net>
* @link http://www.workerman.net/
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
use Webman\Session\FileSessionHandler;
use Webman\Session\RedisSessionHandler;
use Webman\Session\RedisClusterSessionHandler;
return [
'type' => 'file', // or redis or redis_cluster
'handler' => FileSessionHandler::class,
'config' => [
'file' => [
'save_path' => runtime_path() . '/sessions',
],
'redis' => [
'host' => '127.0.0.1',
'port' => 6379,
'auth' => '',
'timeout' => 2,
'database' => '',
'prefix' => 'redis_session_',
],
'redis_cluster' => [
'host' => ['127.0.0.1:7000', '127.0.0.1:7001', '127.0.0.1:7001'],
'timeout' => 2,
'auth' => '',
'prefix' => 'redis_session_',
]
],
'session_name' => 'PHPSID',
'auto_update_timestamp' => false,
'lifetime' => 7*24*60*60,
'cookie_lifetime' => 365*24*60*60,
'cookie_path' => '/',
'domain' => '',
'http_only' => true,
'secure' => false,
'same_site' => '',
'gc_probability' => [1, 1000],
];

23
config/static.php Normal file
View File

@ -0,0 +1,23 @@
<?php
/**
* This file is part of webman.
*
* Licensed under The MIT License
* For full copyright and license information, please see the MIT-LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @author walkor<walkor@workerman.net>
* @copyright walkor<walkor@workerman.net>
* @link http://www.workerman.net/
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
/**
* Static file settings
*/
return [
'enable' => true,
'middleware' => [ // Static file Middleware
//app\middleware\StaticFile::class,
],
];

25
config/translation.php Normal file
View File

@ -0,0 +1,25 @@
<?php
/**
* This file is part of webman.
*
* Licensed under The MIT License
* For full copyright and license information, please see the MIT-LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @author walkor<walkor@workerman.net>
* @copyright walkor<walkor@workerman.net>
* @link http://www.workerman.net/
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
/**
* Multilingual configuration
*/
return [
// Default language
'locale' => 'zh_CN',
// Fallback language
'fallback_locale' => ['zh_CN', 'en'],
// Folder where language files are stored
'path' => base_path() . '/resource/translations',
];

22
config/view.php Normal file
View File

@ -0,0 +1,22 @@
<?php
/**
* This file is part of webman.
*
* Licensed under The MIT License
* For full copyright and license information, please see the MIT-LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @author walkor<walkor@workerman.net>
* @copyright walkor<walkor@workerman.net>
* @link http://www.workerman.net/
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
use support\view\Raw;
use support\view\Twig;
use support\view\Blade;
use support\view\ThinkPHP;
return [
'handler' => Raw::class
];

View File

@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class V20250105020018 extends AbstractMigration
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change(): void
{
}
}

View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
</body>
</html>

View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
</body>
</html>

127
plugin/admin/api/Auth.php Normal file
View File

@ -0,0 +1,127 @@
<?php
namespace plugin\admin\api;
use plugin\admin\app\model\Role;
use plugin\admin\app\model\Rule;
use support\exception\BusinessException;
use function admin;
/**
* 对外提供的鉴权接口
*/
class Auth
{
/**
* 判断权限
* 如果没有权限则抛出异常
* @param string $controller
* @param string $action
* @return void
* @throws \ReflectionException|BusinessException
*/
public static function access(string $controller, string $action)
{
$code = 0;
$msg = '';
if (!static::canAccess($controller, $action, $code, $msg)) {
throw new BusinessException($msg, $code);
}
}
/**
* 判断是否有权限
* @param string $controller
* @param string $action
* @param int $code
* @param string $msg
* @return bool
* @throws \ReflectionException|BusinessException
*/
public static function canAccess(string $controller, string $action, int &$code = 0, string &$msg = ''): bool
{
// 无控制器信息说明是函数调用,函数不属于任何控制器,鉴权操作应该在函数内部完成。
if (!$controller) {
return true;
}
// 获取控制器鉴权信息
$class = new \ReflectionClass($controller);
$properties = $class->getDefaultProperties();
$noNeedLogin = $properties['noNeedLogin'] ?? [];
$noNeedAuth = $properties['noNeedAuth'] ?? [];
// 不需要登录
if (in_array($action, $noNeedLogin)) {
return true;
}
// 获取登录信息
$admin = admin();
if (!$admin) {
$msg = '请登录';
// 401是未登录固定的返回码
$code = 401;
return false;
}
// 不需要鉴权
if (in_array($action, $noNeedAuth)) {
return true;
}
// 当前管理员无角色
$roles = $admin['roles'];
if (!$roles) {
$msg = '无权限';
$code = 2;
return false;
}
// 角色没有规则
$rules = Role::whereIn('id', $roles)->pluck('rules');
$rule_ids = [];
foreach ($rules as $rule_string) {
if (!$rule_string) {
continue;
}
$rule_ids = array_merge($rule_ids, explode(',', $rule_string));
}
if (!$rule_ids) {
$msg = '无权限';
$code = 2;
return false;
}
// 超级管理员
if (in_array('*', $rule_ids)){
return true;
}
// 如果action为index规则里有任意一个以$controller开头的权限即可
if (strtolower($action) === 'index') {
$rule = Rule::where(function ($query) use ($controller, $action) {
$controller_like = str_replace('\\', '\\\\', $controller);
$query->where('key', 'like', "$controller_like@%")->orWhere('key', $controller);
})->whereIn('id', $rule_ids)->first();
if ($rule) {
return true;
}
$msg = '无权限';
$code = 2;
return false;
}
// 查询是否有当前控制器的规则
$rule = Rule::where(function ($query) use ($controller, $action) {
$query->where('key', "$controller@$action")->orWhere('key', $controller);
})->whereIn('id', $rule_ids)->first();
if (!$rule) {
$msg = '无权限';
$code = 2;
return false;
}
return true;
}
}

View File

@ -0,0 +1,93 @@
<?php
namespace plugin\admin\api;
class Install
{
/**
* 安装
*
* @param $version
* @return void
*/
public static function install($version)
{
// 导入菜单
Menu::import(static::getMenus());
}
/**
* 卸载
*
* @param $version
* @return void
*/
public static function uninstall($version)
{
// 删除菜单
foreach (static::getMenus() as $menu) {
Menu::delete($menu['name']);
}
}
/**
* 更新
*
* @param $from_version
* @param $to_version
* @param $context
* @return void
*/
public static function update($from_version, $to_version, $context = null)
{
// 删除不用的菜单
if (isset($context['previous_menus'])) {
static::removeUnnecessaryMenus($context['previous_menus']);
}
// 导入新菜单
Menu::import(static::getMenus());
}
/**
* 更新前数据收集等
*
* @param $from_version
* @param $to_version
* @return array|array[]
*/
public static function beforeUpdate($from_version, $to_version)
{
// 在更新之前获得老菜单通过context传递给 update
return ['previous_menus' => static::getMenus()];
}
/**
* 获取菜单
*
* @return array|mixed
*/
public static function getMenus()
{
clearstatcache();
if (is_file($menu_file = __DIR__ . '/../config/menu.php')) {
$menus = include $menu_file;
return $menus ?: [];
}
return [];
}
/**
* 删除不需要的菜单
*
* @param $previous_menus
* @return void
*/
public static function removeUnnecessaryMenus($previous_menus)
{
$menus_to_remove = array_diff(Menu::column($previous_menus, 'name'), Menu::column(static::getMenus(), 'name'));
foreach ($menus_to_remove as $name) {
Menu::delete($name);
}
}
}

Some files were not shown because too many files have changed in this diff Show More