正在显示
34 个修改的文件
包含
4870 行增加
和
0 行删除
.editorconfig
0 → 100644
.env.example
0 → 100644
| 1 | +APP_NAME=ai-chat.weigoutong.com | ||
| 2 | +APP_NAME_ZH=AI助手 | ||
| 3 | +APP_ENV=production | ||
| 4 | +APP_KEY=base64:3I5SI8L6rBQRvOZranhb5Zt+OS7h3WqWWgrdkHTbnFE= | ||
| 5 | +APP_DEBUG=true | ||
| 6 | +APP_URL=http://ai-chat.weigoutong.com | ||
| 7 | +APP_DOMAIN = ai-chat.weigoutong.com | ||
| 8 | + | ||
| 9 | +LOG_CHANNEL=daily | ||
| 10 | + | ||
| 11 | +DB_CONNECTION=mysql | ||
| 12 | +DB_PORT=3306 | ||
| 13 | +DB_HOST=localhost | ||
| 14 | +DB_DATABASE=ai-chat | ||
| 15 | +DB_USERNAME=root | ||
| 16 | +DB_PASSWORD=4deec965296ff346 | ||
| 17 | + | ||
| 18 | +# 远程数据库 美国服务器使用该配置 | ||
| 19 | +#DB_CONNECTION_REMOTE=mysql | ||
| 20 | +#DB_PORT_REMOTE=3306 | ||
| 21 | +#DB_HOST_REMOTE=rm-uf63r3yhy6806wdpjqo.mysql.rds.aliyuncs.com | ||
| 22 | +#DB_DATABASE_REMOTE=xzy.chatgpt | ||
| 23 | +#DB_USERNAME_REMOTE=root | ||
| 24 | +#DB_PASSWORD_REMOTE=zhangxinkeji@2003 | ||
| 25 | + | ||
| 26 | +# 远程数据库 本地服务器使用该配置 | ||
| 27 | +DB_CONNECTION_REMOTE=mysql | ||
| 28 | +DB_PORT_REMOTE=3306 | ||
| 29 | +DB_HOST_REMOTE=47.251.45.96 | ||
| 30 | +DB_DATABASE_REMOTE=ai-chat | ||
| 31 | +DB_USERNAME_REMOTE=ai-chat | ||
| 32 | +DB_PASSWORD_REMOTE=5E7mKZ3jKMTrD6wK | ||
| 33 | + | ||
| 34 | +BROADCAST_DRIVER=log | ||
| 35 | +CACHE_DRIVER=redis | ||
| 36 | +QUEUE_CONNECTION=database | ||
| 37 | +SESSION_DRIVER=redis | ||
| 38 | +SESSION_LIFETIME=120 | ||
| 39 | + | ||
| 40 | +#REDIS_CLIENT=predis | ||
| 41 | +REDIS_HOST=127.0.0.1 | ||
| 42 | +REDIS_PASSWORD=NULL | ||
| 43 | +REDIS_PORT=6379 | ||
| 44 | + | ||
| 45 | +MAIL_DRIVER=smtp | ||
| 46 | +MAIL_HOST=smtp.mailtrap.io | ||
| 47 | +MAIL_PORT=2525 | ||
| 48 | +MAIL_USERNAME=null | ||
| 49 | +MAIL_PASSWORD=null | ||
| 50 | +MAIL_ENCRYPTION=null | ||
| 51 | +MAIL_FROM_ADDRESS=null | ||
| 52 | +MAIL_FROM_NAME="${APP_NAME}" | ||
| 53 | + | ||
| 54 | +AWS_ACCESS_KEY_ID= | ||
| 55 | +AWS_SECRET_ACCESS_KEY= | ||
| 56 | +AWS_DEFAULT_REGION=us-east-1 | ||
| 57 | +AWS_BUCKET= | ||
| 58 | + | ||
| 59 | +PUSHER_APP_ID= | ||
| 60 | +PUSHER_APP_KEY= | ||
| 61 | +PUSHER_APP_SECRET= | ||
| 62 | +PUSHER_APP_CLUSTER=mt1 | ||
| 63 | + | ||
| 64 | +MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" | ||
| 65 | +MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" | ||
| 66 | + | ||
| 67 | +JWT_SECRET=3QnPNbxLuAN1DToiUSi9IKVtjN8yh0XZE0n3U77owdGF4GqhJfakCMqFyWDc0c75 | ||
| 68 | + | ||
| 69 | +# alipay 配置 | ||
| 70 | +ALI_APP_ID= | ||
| 71 | +ALI_PUBLIC_KEY= | ||
| 72 | +ALI_PRIVATE_KEY= | ||
| 73 | +# wechat 配置 | ||
| 74 | +WECHAT_OFFICIAL_ACCOUNT_APPID= | ||
| 75 | +WECHAT_OFFICIAL_ACCOUNT_SECRET= | ||
| 76 | +WECHAT_MCH_ID=1642977981 | ||
| 77 | +WECHAT_KEY=WXJ776688wxj776688LY15366249213W | ||
| 78 | +WECHAT_MINI_APPID=wxd7941b64f8b9291b | ||
| 79 | +WECHAT_MINI_SECRET=b4d742d47f9f08d3242ca8a426326a7a | ||
| 80 | + | ||
| 81 | +#openai | ||
| 82 | +OPENAI_API_KEY=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 | ||
| 83 | +#OPENAI_API_KEY=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 | ||
| 84 | +OPENAI_ORGANIZATION=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 |
.gitattributes
0 → 100644
.gitignore
0 → 100644
| 1 | +/node_modules | ||
| 2 | +/public/hot | ||
| 3 | +/public/storage | ||
| 4 | +/storage/*.key | ||
| 5 | +/storage/* | ||
| 6 | +/storage | ||
| 7 | +/vendor | ||
| 8 | +.env | ||
| 9 | +.env.backup | ||
| 10 | +.phpunit.result.cache | ||
| 11 | +Homestead.json | ||
| 12 | +Homestead.yaml | ||
| 13 | +npm-debug.log | ||
| 14 | +yarn-error.log | ||
| 15 | +_ide_helper.php | ||
| 16 | +_ide_helper_models.php | ||
| 17 | +/.idea/ | ||
| 18 | +/backup | ||
| 19 | +/vendor0711 | ||
| 20 | +/vendor0721 | ||
| 21 | +vendor0711.zip |
.styleci.yml
0 → 100644
README.en.md
0 → 100644
| 1 | + | ||
| 2 | +## 初始化 | ||
| 3 | +```shell | ||
| 4 | +#生成APP_KEY | ||
| 5 | +php artisan key:generate | ||
| 6 | + | ||
| 7 | +#生成JWT KEY | ||
| 8 | +php artisan jwt:secret | ||
| 9 | + | ||
| 10 | +# 目录 初始化 软连接 | ||
| 11 | +php artisan storage:link | ||
| 12 | + | ||
| 13 | +# 目录权限 | ||
| 14 | +chmod -R 777 storage | ||
| 15 | + | ||
| 16 | +# composer 初始化 | ||
| 17 | +composer update -o -vvv --no-dev --classmap-authoritative --ignore-platform-reqs | ||
| 18 | + | ||
| 19 | +# 禁用相关函数 | ||
| 20 | +putenv proc_open | ||
| 21 | + | ||
| 22 | +# | ||
| 23 | +composer require symfony/symfony:5.4.x -w --ignore-platform-reqs | ||
| 24 | +# 启动调度器 | ||
| 25 | +crontab -u www -e | ||
| 26 | + | ||
| 27 | +# 生产 | ||
| 28 | +00 01 * * * /usr/bin/php /mnt/www.xxx.com/artisan schedule:run >> /mnt/www.xxx.com/storage/logs/schedule.log 2>&1 | ||
| 29 | + | ||
| 30 | +# 本地 | ||
| 31 | +* * * * * /usr/local/bin/php /Users/Nova/Projects/cloud/artisan schedule:run >> /Users/Nova/Projects/cloud/storage/logs/schedule.log 2>&1 | ||
| 32 | + | ||
| 33 | +# 测试 | ||
| 34 | +00 01 * * * /usr/bin/php /mnt/umiu/artisan schedule:run >> /mnt/umiu/storage/logs/schedule.log 2>&1 | ||
| 35 | +``` | ||
| 36 | + | ||
| 37 | +## 生产环境优化 | ||
| 38 | +``` | ||
| 39 | +配置信息缓存#:php artisan config:cache | ||
| 40 | +路由缓存#:php artisan route:cache | ||
| 41 | +类映射加载优化#:php artisan optimize --force (清除命令:php artisan clear-compiled) | ||
| 42 | +自动加载优化:composer dumpautoload -o | ||
| 43 | +使用 Memcached 来存储会话:SESSION_DRIVER=memcached | ||
| 44 | +使用专业缓存驱动器:CACHE_DRIVER=redis | ||
| 45 | +``` | ||
| 46 | + | ||
| 47 | + | ||
| 48 | +## 缓存清理 | ||
| 49 | +``` | ||
| 50 | +php artisan cache:clear | ||
| 51 | +php artisan config:clear | ||
| 52 | +php artisan route:clear | ||
| 53 | +php artisan view:clear | ||
| 54 | +``` | ||
| 55 | + | ||
| 56 | +## Composer 扩展包 | ||
| 57 | +``` | ||
| 58 | +1、alibabacloud/client 阿里云sdk | ||
| 59 | +2、catlane/chunk-file-upload 单文件上传 | ||
| 60 | +3、dingo/api 框架接口 | ||
| 61 | +5、encore/laravel-admin laravel-admin | ||
| 62 | +5、fruitcake/laravel-cors 跨域 | ||
| 63 | +6、intervention/image image 扩展 | ||
| 64 | +7、jpush/jpush 极光推送 | ||
| 65 | +8、maatwebsite/excel excel 扩展 | ||
| 66 | +9、overtrue/easy-sms 短信功能 | ||
| 67 | +10、overtrue/laravel-wechat 微信 | ||
| 68 | +11、overtrue/wechat 微信 | ||
| 69 | +12、simplesoftwareio/simple-qrcode 二维码 | ||
| 70 | +13、spatie/laravel-activitylog 日志 | ||
| 71 | +14、tymon/jwt-auth jwt | ||
| 72 | +15、yansongda/laravel-pay 支付功能 | ||
| 73 | +``` | ||
| 74 | + | ||
| 75 | +## 规范 | ||
| 76 | +``` | ||
| 77 | +html:id、name 命名用"-"分割 | ||
| 78 | +css:命名用"-"分割 | ||
| 79 | + | ||
| 80 | +Jobs:将耗时的任务延时处理,比如发送邮件,从而大幅度缩短 Web 请求和相应的时间。 | ||
| 81 | +``` | ||
| 82 | +## 响应 | ||
| 83 | +``` | ||
| 84 | +错误: | ||
| 85 | +Http Status Code 非200 | ||
| 86 | +Response {"code":0,"msg":"","data":{}} | ||
| 87 | +``` | ||
| 88 | +## fix | ||
| 89 | +``` | ||
| 90 | +composer overtrue/wechat | ||
| 91 | +/Users/Nova/Projects/cloud/vendor/overtrue/wechat/src/Kernel/ServerGuard.php | ||
| 92 | +line 323 | ||
| 93 | +if (0 === stripos($content, '<')) { | ||
| 94 | +fix | ||
| 95 | +if (0 === stripos(trim($content), '<')) { | ||
| 96 | +``` | ||
| 97 | + | ||
| 98 | +## 其他 | ||
| 99 | +``` | ||
| 100 | +忽略PHP版本更新 composer update --ignore-platform-reqs | ||
| 101 | +``` | ||
| 102 | +## 自定义artisan | ||
| 103 | +``` | ||
| 104 | +目前的系统都是继承自基类,基本的方法都已经实现,需要开发新的功能的时候,只需要建立新的类即可,可以通过artisan来自动创建需要的类 | ||
| 105 | +路由:{name}s | ||
| 106 | +控制层:{Name}Controller extends BaseController | ||
| 107 | +表单验证层:{Name}Request | ||
| 108 | +逻辑层: {Name}Service | ||
| 109 | +模型层:{Name} | ||
| 110 | +转换成:{Name}Transform | ||
| 111 | +管理端gird类:{Name}Grid | ||
| 112 | +管理端form类:{Name}Form | ||
| 113 | +管理端控制层:{Name}Controller | ||
| 114 | +机构端控制层:{Name}Controller | ||
| 115 | + | ||
| 116 | + | ||
| 117 | +使用命令 php artisan make:api User --title=用户 | ||
| 118 | +1、会在 api路由中增加 $api->resource('users', UserController::class); 注意该文件是在路由文件最后,需要移动到对应的位置 | ||
| 119 | +2、会在 app\Http\Api\V1\Controllers 创建 controller 文件 UsersController | ||
| 120 | +3、会在 app\Models 创建 model 文件 User | ||
| 121 | +4、会在 app\Services 创建 service 文件 UserService | ||
| 122 | +5、会在 app\Transformers 创建 transformer 文件 UserTransformer | ||
| 123 | +6、会在 app\Http\Requests 创建 request 文件 UserCreateRequest 和 UserUpdateRequest | ||
| 124 | +7、会在 app\Policies 创建 policy 文件 UserPolicy | ||
| 125 | +8、会在 app\Admin\Grids 创建 grid 文件 UserGrid | ||
| 126 | +9、会在 app\Admin\Forms 创建 form 文件 UserForm | ||
| 127 | +10、会在 app\Admin\Controllers 创建 controller 文件 UsersController | ||
| 128 | +10、会在 app\Agency\Controllers 创建 controller 文件 UsersController | ||
| 129 | +``` | ||
| 130 | + | ||
| 131 | + | ||
| 132 | + |
| 1 | + | ||
| 2 | +## 初始化 | ||
| 3 | +```shell | ||
| 4 | +#生成APP_KEY | ||
| 5 | +php artisan key:generate | ||
| 6 | + | ||
| 7 | +#生成JWT KEY | ||
| 8 | +php artisan jwt:secret | ||
| 9 | + | ||
| 10 | +# 目录 初始化 软连接 | ||
| 11 | +php artisan storage:link | ||
| 12 | + | ||
| 13 | +# 目录权限 | ||
| 14 | +chmod -R 777 storage | ||
| 15 | + | ||
| 16 | +# composer 初始化 | ||
| 17 | +composer update -o -vvv --no-dev --classmap-authoritative --ignore-platform-reqs | ||
| 18 | + | ||
| 19 | +# 禁用相关函数 | ||
| 20 | +putenv proc_open | ||
| 21 | + | ||
| 22 | +# | ||
| 23 | +composer require symfony/symfony:5.4.x -w --ignore-platform-reqs | ||
| 24 | +# 启动调度器 | ||
| 25 | +crontab -u www -e | ||
| 26 | + | ||
| 27 | +# 生产 | ||
| 28 | +00 01 * * * /usr/bin/php /mnt/www.xxx.com/artisan schedule:run >> /mnt/www.xxx.com/storage/logs/schedule.log 2>&1 | ||
| 29 | + | ||
| 30 | +# 本地 | ||
| 31 | +* * * * * /usr/local/bin/php /Users/Nova/Projects/cloud/artisan schedule:run >> /Users/Nova/Projects/cloud/storage/logs/schedule.log 2>&1 | ||
| 32 | + | ||
| 33 | +# 测试 | ||
| 34 | +00 01 * * * /usr/bin/php /mnt/umiu/artisan schedule:run >> /mnt/umiu/storage/logs/schedule.log 2>&1 | ||
| 35 | +``` | ||
| 36 | + | ||
| 37 | +## 生产环境优化 | ||
| 38 | +``` | ||
| 39 | +配置信息缓存#:php artisan config:cache | ||
| 40 | +路由缓存#:php artisan route:cache | ||
| 41 | +类映射加载优化#:php artisan optimize --force (清除命令:php artisan clear-compiled) | ||
| 42 | +自动加载优化:composer dumpautoload -o | ||
| 43 | +使用 Memcached 来存储会话:SESSION_DRIVER=memcached | ||
| 44 | +使用专业缓存驱动器:CACHE_DRIVER=redis | ||
| 45 | +``` | ||
| 46 | + | ||
| 47 | + | ||
| 48 | +## 缓存清理 | ||
| 49 | +``` | ||
| 50 | +php artisan cache:clear | ||
| 51 | +php artisan config:clear | ||
| 52 | +php artisan route:clear | ||
| 53 | +php artisan view:clear | ||
| 54 | +``` | ||
| 55 | + | ||
| 56 | +## Composer 扩展包 | ||
| 57 | +``` | ||
| 58 | +1、alibabacloud/client 阿里云sdk | ||
| 59 | +2、catlane/chunk-file-upload 单文件上传 | ||
| 60 | +3、dingo/api 框架接口 | ||
| 61 | +5、encore/laravel-admin laravel-admin | ||
| 62 | +5、fruitcake/laravel-cors 跨域 | ||
| 63 | +6、intervention/image image 扩展 | ||
| 64 | +7、jpush/jpush 极光推送 | ||
| 65 | +8、maatwebsite/excel excel 扩展 | ||
| 66 | +9、overtrue/easy-sms 短信功能 | ||
| 67 | +10、overtrue/laravel-wechat 微信 | ||
| 68 | +11、overtrue/wechat 微信 | ||
| 69 | +12、simplesoftwareio/simple-qrcode 二维码 | ||
| 70 | +13、spatie/laravel-activitylog 日志 | ||
| 71 | +14、tymon/jwt-auth jwt | ||
| 72 | +15、yansongda/laravel-pay 支付功能 | ||
| 73 | +``` | ||
| 74 | + | ||
| 75 | +## 规范 | ||
| 76 | +``` | ||
| 77 | +html:id、name 命名用"-"分割 | ||
| 78 | +css:命名用"-"分割 | ||
| 79 | + | ||
| 80 | +Jobs:将耗时的任务延时处理,比如发送邮件,从而大幅度缩短 Web 请求和相应的时间。 | ||
| 81 | +``` | ||
| 82 | +## 响应 | ||
| 83 | +``` | ||
| 84 | +错误: | ||
| 85 | +Http Status Code 非200 | ||
| 86 | +Response {"code":0,"msg":"","data":{}} | ||
| 87 | +``` | ||
| 88 | +## fix | ||
| 89 | +``` | ||
| 90 | +composer overtrue/wechat | ||
| 91 | +/Users/Nova/Projects/cloud/vendor/overtrue/wechat/src/Kernel/ServerGuard.php | ||
| 92 | +line 323 | ||
| 93 | +if (0 === stripos($content, '<')) { | ||
| 94 | +fix | ||
| 95 | +if (0 === stripos(trim($content), '<')) { | ||
| 96 | +``` | ||
| 97 | + | ||
| 98 | +## 其他 | ||
| 99 | +``` | ||
| 100 | +忽略PHP版本更新 composer update --ignore-platform-reqs | ||
| 101 | +``` | ||
| 102 | +## 自定义artisan | ||
| 103 | +``` | ||
| 104 | +目前的系统都是继承自基类,基本的方法都已经实现,需要开发新的功能的时候,只需要建立新的类即可,可以通过artisan来自动创建需要的类 | ||
| 105 | +路由:{name}s | ||
| 106 | +控制层:{Name}Controller extends BaseController | ||
| 107 | +表单验证层:{Name}Request | ||
| 108 | +逻辑层: {Name}Service | ||
| 109 | +模型层:{Name} | ||
| 110 | +转换成:{Name}Transform | ||
| 111 | +管理端gird类:{Name}Grid | ||
| 112 | +管理端form类:{Name}Form | ||
| 113 | +管理端控制层:{Name}Controller | ||
| 114 | +机构端控制层:{Name}Controller | ||
| 115 | + | ||
| 116 | + | ||
| 117 | +使用命令 php artisan make:api User --title=用户 | ||
| 118 | +1、会在 api路由中增加 $api->resource('users', UserController::class); 注意该文件是在路由文件最后,需要移动到对应的位置 | ||
| 119 | +2、会在 app\Http\Api\V1\Controllers 创建 controller 文件 UsersController | ||
| 120 | +3、会在 app\Models 创建 model 文件 User | ||
| 121 | +4、会在 app\Services 创建 service 文件 UserService | ||
| 122 | +5、会在 app\Transformers 创建 transformer 文件 UserTransformer | ||
| 123 | +6、会在 app\Http\Requests 创建 request 文件 UserCreateRequest 和 UserUpdateRequest | ||
| 124 | +7、会在 app\Policies 创建 policy 文件 UserPolicy | ||
| 125 | +8、会在 app\Admin\Grids 创建 grid 文件 UserGrid | ||
| 126 | +9、会在 app\Admin\Forms 创建 form 文件 UserForm | ||
| 127 | +10、会在 app\Admin\Controllers 创建 controller 文件 UsersController | ||
| 128 | +10、会在 app\Agency\Controllers 创建 controller 文件 UsersController | ||
| 129 | +要将 ChatGPT 集成到 Laravel 中,可以将 ChatGPT API 请求封装为 Laravel 服务。该服务可以在需要使用 ChatGPT 的地方被注入,并可在应用程序的其余部分中使用。 | ||
| 130 | + | ||
| 131 | +首先,您需要创建服务类。该类可以使用 Guzzle Http 软件包来发出 API 请求。然后,在 config/services.php 文件中添加 ChatGPT 服务的配置。最后,您可以通过 Laravel 中的依赖注入容器使用服务。 | ||
| 132 | + | ||
| 133 | +以下是代码示例: | ||
| 134 | + | ||
| 135 | +创建服务类 | ||
| 136 | +namespace App\Services; | ||
| 137 | + | ||
| 138 | +use GuzzleHttp\Client; | ||
| 139 | + | ||
| 140 | +class ChatGPTService | ||
| 141 | +{ | ||
| 142 | + protected $http; | ||
| 143 | + | ||
| 144 | + public function __construct(Client $http) | ||
| 145 | + { | ||
| 146 | + $this->http = $http; | ||
| 147 | + } | ||
| 148 | + | ||
| 149 | + public function generateResponse($input) | ||
| 150 | + { | ||
| 151 | + $response = $this->http->post('https://api.openai.com/v1/engines/davinci-codex/completions', [ | ||
| 152 | + 'headers' => [ | ||
| 153 | + 'Authorization' => 'Bearer API_KEY', | ||
| 154 | + 'Content-Type' => 'application/json', | ||
| 155 | + ], | ||
| 156 | + 'json' => [ | ||
| 157 | + 'prompt' => $input.'\n\n', | ||
| 158 | + 'max_tokens' => 100, | ||
| 159 | + 'temperature' => 0.8, | ||
| 160 | + ], | ||
| 161 | + ]); | ||
| 162 | + | ||
| 163 | + return json_decode((string) $response->getBody(), true); | ||
| 164 | + } | ||
| 165 | +} | ||
| 166 | +添加配置信息到 services.php | ||
| 167 | +'chatgpt' => [ | ||
| 168 | + 'api_key' => env('CHATGPT_API_KEY'), | ||
| 169 | +], | ||
| 170 | +注册服务类到服务容器 | ||
| 171 | +$this->app->singleton(ChatGPTService::class, function ($app) { | ||
| 172 | + $httpClient = new \GuzzleHttp\Client(); | ||
| 173 | + return new ChatGPTService($httpClient); | ||
| 174 | +}); | ||
| 175 | +现在您可以在控制器或其他服务中注入 ChatGPT 服务,并使用它来生成响应。例如: | ||
| 176 | + | ||
| 177 | +public function index(ChatGPTService $chatGPTService) | ||
| 178 | +{ | ||
| 179 | + $chatResponse = $chatGPTService->generateResponse('Hello!'); | ||
| 180 | + return view('welcome', ['response' => $chatResponse]); | ||
| 181 | +} | ||
| 182 | +其中,'Hello!' 是 ChatGPT 服务的输入,可以将其替换为实际的用户输入。 | ||
| 183 | +``` | ||
| 184 | + | ||
| 185 | + | ||
| 186 | + |
app/Admin/Actions/Importer/FarmerImport.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Admin\Actions\Importer; | ||
| 4 | + | ||
| 5 | +use Encore\Admin\Actions\Action; | ||
| 6 | +use Illuminate\Http\Request; | ||
| 7 | + | ||
| 8 | +class FarmerImport extends Action | ||
| 9 | +{ | ||
| 10 | + protected $selector = '.farmer-import'; | ||
| 11 | + | ||
| 12 | + public function handle(Request $request) | ||
| 13 | + { | ||
| 14 | + // $request ... | ||
| 15 | + | ||
| 16 | + return $this->response()->success('Success message...')->refresh(); | ||
| 17 | + } | ||
| 18 | + | ||
| 19 | + public function html() | ||
| 20 | + { | ||
| 21 | + return <<<HTML | ||
| 22 | + <a class="btn btn-sm btn-default farmer-import">导入数据</a> | ||
| 23 | +HTML; | ||
| 24 | + } | ||
| 25 | +} |
app/Admin/Actions/Post/ImportPost.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Admin\Actions\Post; | ||
| 4 | + | ||
| 5 | +use Encore\Admin\Actions\Action; | ||
| 6 | +use Illuminate\Http\Request; | ||
| 7 | + | ||
| 8 | +class \ImportPost extends Action | ||
| 9 | +{ | ||
| 10 | + protected $selector = '.import-post'; | ||
| 11 | + | ||
| 12 | + public function handle(Request $request) | ||
| 13 | + { | ||
| 14 | + // $request ... | ||
| 15 | + | ||
| 16 | + return $this->response()->success('Success message...')->refresh(); | ||
| 17 | + } | ||
| 18 | + | ||
| 19 | + public function html() | ||
| 20 | + { | ||
| 21 | + return <<<HTML | ||
| 22 | + <a class="btn btn-sm btn-default import-post">导入数据</a> | ||
| 23 | +HTML; | ||
| 24 | + } | ||
| 25 | +} |
app/Admin/Controllers/AboutUsController.php
0 → 100644
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | ++----------------------------------------------------------------------------------------------------------------------- | ||
| 4 | + * 管理端控制层: 关于我们 控制类 | ||
| 5 | ++----------------------------------------------------------------------------------------------------------------------- | ||
| 6 | + * | ||
| 7 | + * PHP version 7 | ||
| 8 | + * | ||
| 9 | + * @category App\Admin\Controllers | ||
| 10 | + * @package App\Admin\Controllers | ||
| 11 | + * @author Richer <yangzi1028@163.com> | ||
| 12 | + * @date 2022年2月16日14:15:18 | ||
| 13 | + * @copyright 2020-2022 Richer (http://www.Richer.com/) | ||
| 14 | + * @license http://www.Richer.com/ License | ||
| 15 | + * @link http://www.Richer.com/ | ||
| 16 | + */ | ||
| 17 | +namespace App\Admin\Controllers; | ||
| 18 | + | ||
| 19 | +use App\Admin\Rewrite\Form; | ||
| 20 | +use App\Models\AboutUs; | ||
| 21 | +use Encore\Admin\Form\Tools; | ||
| 22 | +use Encore\Admin\Layout\Content; | ||
| 23 | +use Symfony\Component\HttpFoundation\Response; | ||
| 24 | + | ||
| 25 | +/** | ||
| 26 | + * Class AboutUsController. | ||
| 27 | + * | ||
| 28 | + * @category App\Admin\Controllers | ||
| 29 | + * @package App\Admin\Controllers | ||
| 30 | + * @author Richer <yangzi1028@163.com> | ||
| 31 | + * @date 2022年2月16日14:15:18 | ||
| 32 | + * @copyright 2020-2022 Richer (http://www.Richer.com/) | ||
| 33 | + * @license http://www.Richer.com/ License | ||
| 34 | + * @link http://www.Richer.com/ | ||
| 35 | + */ | ||
| 36 | +class AboutUsController extends BaseController | ||
| 37 | +{ | ||
| 38 | + // 使用Grid和Form的trait | ||
| 39 | + | ||
| 40 | + /** | ||
| 41 | + * AboutUsController constructor. | ||
| 42 | + * | ||
| 43 | + * @param AboutUs $model 注入model | ||
| 44 | + */ | ||
| 45 | + public function __construct(AboutUs $model) | ||
| 46 | + { | ||
| 47 | + // 资源显示的中文名称 | ||
| 48 | + $this->title = $model::OBJ_NAME_ZH; | ||
| 49 | + // 资源显示的名称 | ||
| 50 | + $this->type = $model::OBJ_NAME; | ||
| 51 | + // 表名称 | ||
| 52 | + $this->table = $model::TABLE; | ||
| 53 | + // 是否可查看 | ||
| 54 | + $this->can_view = true; | ||
| 55 | + // 是否可新增 | ||
| 56 | + $this->can_create = true; | ||
| 57 | + // 是否可编辑 | ||
| 58 | + $this->can_edit = true; | ||
| 59 | + // 是否可删除 | ||
| 60 | + $this->can_delete = true; | ||
| 61 | + // 是否开启下拉菜单 | ||
| 62 | + $this->dropdownActions = false; | ||
| 63 | + | ||
| 64 | + // 执行父类构造方法 | ||
| 65 | + parent::__construct($model); | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + /** | ||
| 69 | + * User setting page. | ||
| 70 | + * | ||
| 71 | + * @param Content $content | ||
| 72 | + * | ||
| 73 | + * @return Content | ||
| 74 | + */ | ||
| 75 | + public function getAboutUs(Content $content) | ||
| 76 | + { | ||
| 77 | + // 获取 boss | ||
| 78 | + $boss = $this->model->first(); | ||
| 79 | + $form = $this->settingForm(); | ||
| 80 | + $form->tools( | ||
| 81 | + function (Tools $tools) { | ||
| 82 | + $tools->disableList(); | ||
| 83 | + $tools->disableDelete(); | ||
| 84 | + $tools->disableView(); | ||
| 85 | + } | ||
| 86 | + ); | ||
| 87 | + | ||
| 88 | + if ($boss) { | ||
| 89 | + return $content | ||
| 90 | + ->title(trans('admin.user_setting')) | ||
| 91 | + ->body($form->edit(optional($boss)->id)); | ||
| 92 | + } else { | ||
| 93 | + return $content | ||
| 94 | + ->title(trans('admin.user_setting')) | ||
| 95 | + ->body($form); | ||
| 96 | + } | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + /** | ||
| 100 | + * Update user setting. | ||
| 101 | + * | ||
| 102 | + * @return Response | ||
| 103 | + */ | ||
| 104 | + public function postAboutUs() | ||
| 105 | + { | ||
| 106 | + return $this->settingForm()->store(); | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + /** | ||
| 110 | + * Update user setting. | ||
| 111 | + * | ||
| 112 | + * @return Response | ||
| 113 | + */ | ||
| 114 | + public function putAboutUs() | ||
| 115 | + { | ||
| 116 | + return $this->settingForm()->update(1); | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + /** | ||
| 120 | + * Model-form for user setting. | ||
| 121 | + * | ||
| 122 | + * @return Form | ||
| 123 | + */ | ||
| 124 | + protected function settingForm() | ||
| 125 | + { | ||
| 126 | + $form = new Form($this->model); | ||
| 127 | + $form->text('title', '标题')->required()->setWidth(10, 1)->setGroupClass('col-md-12'); | ||
| 128 | + $form->editor('body', '详情')->required()->help('请上传小于1G的视频...')->setWidth(10, 1)->setGroupClass('col-md-12'); | ||
| 129 | +// $this->formRichTextField('body', '详情', 1); | ||
| 130 | + | ||
| 131 | +// $form->textarea('name', trans('admin.name'))->rules('required')->setWidth(10, 1)->setGroupClass('col-md-12'); | ||
| 132 | + | ||
| 133 | + $form->setAction(admin_url('about-us')); | ||
| 134 | + | ||
| 135 | + $form->saved(function () { | ||
| 136 | + admin_toastr(trans('admin.update_succeeded')); | ||
| 137 | + | ||
| 138 | + return redirect(admin_url('about-us')); | ||
| 139 | + }); | ||
| 140 | + | ||
| 141 | + return $form; | ||
| 142 | + } | ||
| 143 | +} |
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | ++----------------------------------------------------------------------------------------------------------------------- | ||
| 4 | + * 管理端控制层: 管理端用户角色 控制类 | ||
| 5 | ++----------------------------------------------------------------------------------------------------------------------- | ||
| 6 | + * | ||
| 7 | + * PHP version 7 | ||
| 8 | + * | ||
| 9 | + * @category App\Admin\Controllers\Admin | ||
| 10 | + * @package App\Admin\Controllers\Admin | ||
| 11 | + * @author Richer <yangzi1028@163.com> | ||
| 12 | + * @date 2021年6月23日14:47:37 | ||
| 13 | + * @copyright 2020-2022 Richer (http://www.Richer.com/) | ||
| 14 | + * @license http://www.Richer.com/ License | ||
| 15 | + * @link http://www.Richer.com/ | ||
| 16 | + */ | ||
| 17 | +namespace App\Admin\Controllers\Admin; | ||
| 18 | + | ||
| 19 | +use App\Admin\Controllers\BaseController; | ||
| 20 | +use App\Admin\Forms\Admin\RoleForm; | ||
| 21 | +use App\Admin\Grids\Admin\RoleGrid; | ||
| 22 | +use App\Models\Admin\Role; | ||
| 23 | +use Encore\Admin\Form; | ||
| 24 | +use Encore\Admin\Grid; | ||
| 25 | + | ||
| 26 | +/** | ||
| 27 | + * Class RolesController. | ||
| 28 | + * | ||
| 29 | + * @category App\Admin\Controllers\Admin | ||
| 30 | + * @package App\Admin\Controllers\Admin | ||
| 31 | + * @author Richer <yangzi1028@163.com> | ||
| 32 | + * @date 2021年6月23日14:47:37 | ||
| 33 | + * @copyright 2020-2022 Richer (http://www.Richer.com/) | ||
| 34 | + * @license http://www.Richer.com/ License | ||
| 35 | + * @link http://www.Richer.com/ | ||
| 36 | + */ | ||
| 37 | +class RolesController extends BaseController | ||
| 38 | +{ | ||
| 39 | + // 使用Grid和Form的trait | ||
| 40 | + use RoleGrid, RoleForm; | ||
| 41 | + | ||
| 42 | + /** | ||
| 43 | + * RolesController constructor. | ||
| 44 | + * | ||
| 45 | + * @param Role $model 注入model | ||
| 46 | + */ | ||
| 47 | + public function __construct(Role $model) | ||
| 48 | + { | ||
| 49 | + // 资源显示的中名称 | ||
| 50 | + $this->title = $model::OBJ_NAME_ZH; | ||
| 51 | + // 是否可查看 | ||
| 52 | + $this->can_view = false; | ||
| 53 | + // 是否可新增 | ||
| 54 | + $this->can_create = true; | ||
| 55 | + // 是否可编辑 | ||
| 56 | + $this->can_edit = true; | ||
| 57 | + // 是否可删除 | ||
| 58 | + $this->can_delete = true; | ||
| 59 | + // 是否开启下拉菜单 | ||
| 60 | + $this->dropdownActions = false; | ||
| 61 | + | ||
| 62 | + // 执行父类构造方法 | ||
| 63 | + parent::__construct($model); | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + /** | ||
| 67 | + * Make a grid builder. | ||
| 68 | + * | ||
| 69 | + * @return Grid | ||
| 70 | + */ | ||
| 71 | + protected function grid1() | ||
| 72 | + { | ||
| 73 | + | ||
| 74 | + $grid = new Grid($this->model); | ||
| 75 | + | ||
| 76 | + $grid->column('id', 'ID')->sortable(); | ||
| 77 | +// $grid->column('slug', __('slug')); | ||
| 78 | + $grid->column('name', __('name')); | ||
| 79 | + | ||
| 80 | + $grid->column('permissions', __('permission'))->pluck('name')->label(); | ||
| 81 | + | ||
| 82 | + $grid->column('created_at', __('created_at')); | ||
| 83 | + $grid->column('updated_at', __('updated_at')); | ||
| 84 | + | ||
| 85 | + $grid->actions(function (Grid\Displayers\Actions $actions) { | ||
| 86 | + if ($actions->row->slug == 'administrator') { | ||
| 87 | + $actions->disableDelete(); | ||
| 88 | + } | ||
| 89 | + }); | ||
| 90 | + | ||
| 91 | + $grid->tools(function (Grid\Tools $tools) { | ||
| 92 | + $tools->batch(function (Grid\Tools\BatchActions $actions) { | ||
| 93 | + $actions->disableDelete(); | ||
| 94 | + }); | ||
| 95 | + }); | ||
| 96 | + | ||
| 97 | + return $grid; | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + /** | ||
| 101 | + * Make a form builder. | ||
| 102 | + * | ||
| 103 | + * @return Form | ||
| 104 | + */ | ||
| 105 | + public function form1($id = null) | ||
| 106 | + { | ||
| 107 | + $permissionModel = config('admin.database.permissions_model'); | ||
| 108 | + $roleModel = config('admin.database.roles_model'); | ||
| 109 | + | ||
| 110 | + $form = new Form(new $roleModel()); | ||
| 111 | + | ||
| 112 | + $form->display('id', 'ID'); | ||
| 113 | + | ||
| 114 | + $form->text('slug', __('slug'))->rules('required'); | ||
| 115 | + $form->text('name', __('name'))->rules('required'); | ||
| 116 | + $form->listbox('permissions', __('permissions'))->options($permissionModel::all()->pluck('name', 'id')); | ||
| 117 | + | ||
| 118 | + $form->display('created_at', __('created_at')); | ||
| 119 | + $form->display('updated_at', __('updated_at')); | ||
| 120 | + | ||
| 121 | + return $form; | ||
| 122 | + } | ||
| 123 | +} |
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | ++----------------------------------------------------------------------------------------------------------------------- | ||
| 4 | + * 管理端控制层: 会员 控制类 | ||
| 5 | ++----------------------------------------------------------------------------------------------------------------------- | ||
| 6 | + * | ||
| 7 | + * PHP version 7 | ||
| 8 | + * | ||
| 9 | + * @category App\Admin\Controllers | ||
| 10 | + * @package App\Admin\Controllers | ||
| 11 | + * @author Richer <yangzi1028@163.com> | ||
| 12 | + * @date 2020年12月28日 17:57:14 | ||
| 13 | + * @copyright 2020-2022 Richer (http://www.Richer.com/) | ||
| 14 | + * @license http://www.Richer.com/ License | ||
| 15 | + * @link http://www.Richer.com/ | ||
| 16 | + */ | ||
| 17 | +namespace App\Admin\Controllers\Admin; | ||
| 18 | + | ||
| 19 | +use App\Admin\Controllers\BaseController; | ||
| 20 | +use App\Admin\Forms\Admin\UserForm; | ||
| 21 | +use App\Admin\Grids\Admin\UserGrid; | ||
| 22 | +use App\Admin\Grids\User\UserInfoGrid; | ||
| 23 | +use App\Models\Admin\User; | ||
| 24 | +use App\Models\User\UserInfo; | ||
| 25 | +use Encore\Admin\Form; | ||
| 26 | +use Encore\Admin\Grid; | ||
| 27 | +use Encore\Admin\Show; | ||
| 28 | +use Illuminate\Support\Facades\Hash; | ||
| 29 | + | ||
| 30 | +/** | ||
| 31 | + * Class UserInfosController. | ||
| 32 | + * | ||
| 33 | + * @category App\Admin\Controllers | ||
| 34 | + * @package App\Admin\Controllers | ||
| 35 | + * @author Richer <yangzi1028@163.com> | ||
| 36 | + * @date 2020年12月28日 17:57:14 | ||
| 37 | + * @copyright 2020-2022 Richer (http://www.Richer.com/) | ||
| 38 | + * @license http://www.Richer.com/ License | ||
| 39 | + * @link http://www.Richer.com/ | ||
| 40 | + */ | ||
| 41 | +class UserInfosController extends BaseController | ||
| 42 | +{ | ||
| 43 | + // 使用Grid和Form的trait | ||
| 44 | + use UserInfoGrid, UserForm; | ||
| 45 | + | ||
| 46 | + /** | ||
| 47 | + * UsersController constructor. | ||
| 48 | + * | ||
| 49 | + * @param UserInfo $model 注入model | ||
| 50 | + */ | ||
| 51 | + public function __construct(UserInfo $model) | ||
| 52 | + { | ||
| 53 | + // 资源显示的中名称 | ||
| 54 | + $this->title = $model::OBJ_NAME_ZH; | ||
| 55 | + // 是否可查看 | ||
| 56 | + $this->can_view = false; | ||
| 57 | + // 是否可新增 | ||
| 58 | + $this->can_create = true; | ||
| 59 | + // 是否可编辑 | ||
| 60 | + $this->can_edit = true; | ||
| 61 | + // 是否可删除 | ||
| 62 | + $this->can_delete = true; | ||
| 63 | + // 是否开启下拉菜单 | ||
| 64 | + $this->dropdownActions = false; | ||
| 65 | + | ||
| 66 | + // 执行父类构造方法 | ||
| 67 | + parent::__construct($model); | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + /** | ||
| 71 | + * Make a grid builder. | ||
| 72 | + * | ||
| 73 | + * @return Grid | ||
| 74 | + */ | ||
| 75 | + protected function grid1() | ||
| 76 | + { | ||
| 77 | + $grid = new Grid($this->model); | ||
| 78 | + | ||
| 79 | + $grid->column('id', 'ID')->sortable(); | ||
| 80 | + $grid->column('username', trans('admin.username')); | ||
| 81 | + $grid->column('name', trans('admin.name')); | ||
| 82 | + $grid->column('roles', trans('admin.roles'))->pluck('name')->label(); | ||
| 83 | + $grid->column('created_at', trans('admin.created_at')); | ||
| 84 | + $grid->column('updated_at', trans('admin.updated_at')); | ||
| 85 | + | ||
| 86 | + $grid->actions(function (Grid\Displayers\Actions $actions) { | ||
| 87 | + if ($actions->getKey() == 1) { | ||
| 88 | + $actions->disableDelete(); | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + }); | ||
| 92 | + | ||
| 93 | + $grid->tools(function (Grid\Tools $tools) { | ||
| 94 | + $tools->batch(function (Grid\Tools\BatchActions $actions) { | ||
| 95 | + $actions->disableDelete(); | ||
| 96 | + }); | ||
| 97 | + }); | ||
| 98 | + | ||
| 99 | + return $grid; | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + /** | ||
| 103 | + * Make a show builder. | ||
| 104 | + * | ||
| 105 | + * @param mixed $id | ||
| 106 | + * | ||
| 107 | + * @return Show | ||
| 108 | + */ | ||
| 109 | + protected function detail($id) | ||
| 110 | + { | ||
| 111 | + $userModel = config('admin.database.users_model'); | ||
| 112 | + | ||
| 113 | + $show = new Show($userModel::findOrFail($id)); | ||
| 114 | + | ||
| 115 | + $show->field('id', 'ID'); | ||
| 116 | + $show->field('username', trans('admin.username')); | ||
| 117 | + $show->field('name', trans('admin.name')); | ||
| 118 | + $show->field('roles', trans('admin.roles'))->as(function ($roles) { | ||
| 119 | + return $roles->pluck('name'); | ||
| 120 | + })->label(); | ||
| 121 | + $show->field('permissions', trans('admin.permissions'))->as(function ($permission) { | ||
| 122 | + return $permission->pluck('name'); | ||
| 123 | + })->label(); | ||
| 124 | + $show->field('created_at', trans('admin.created_at')); | ||
| 125 | + $show->field('updated_at', trans('admin.updated_at')); | ||
| 126 | + | ||
| 127 | + return $show; | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + /** | ||
| 131 | + * Make a form builder. | ||
| 132 | + * | ||
| 133 | + * @return Form | ||
| 134 | + */ | ||
| 135 | + public function form1() | ||
| 136 | + { | ||
| 137 | + $userModel = config('admin.database.users_model'); | ||
| 138 | + $permissionModel = config('admin.database.permissions_model'); | ||
| 139 | + $roleModel = config('admin.database.roles_model'); | ||
| 140 | + | ||
| 141 | + $form = new Form(new $userModel()); | ||
| 142 | + | ||
| 143 | + $userTable = config('admin.database.users_table'); | ||
| 144 | + $connection = config('admin.database.connection'); | ||
| 145 | + | ||
| 146 | + $form->display('id', 'ID'); | ||
| 147 | + $form->text('username', trans('admin.username')) | ||
| 148 | + ->creationRules(['required', "unique:{$connection}.{$userTable}"]) | ||
| 149 | + ->updateRules(['required', "unique:{$connection}.{$userTable},username,{{id}}"]); | ||
| 150 | + | ||
| 151 | + $form->text('name', trans('admin.name'))->rules('required'); | ||
| 152 | + $form->image('avatar', trans('admin.avatar')); | ||
| 153 | + $form->password('password', trans('admin.password'))->rules('required|confirmed'); | ||
| 154 | + $form->password('password_confirmation', trans('admin.password_confirmation'))->rules('required') | ||
| 155 | + ->default(function ($form) { | ||
| 156 | + return $form->model()->password; | ||
| 157 | + }); | ||
| 158 | + | ||
| 159 | + $form->ignore(['password_confirmation']); | ||
| 160 | + | ||
| 161 | + $form->multipleSelect('roles', trans('admin.roles'))->options($roleModel::all()->pluck('name', 'id')); | ||
| 162 | + $form->multipleSelect('permissions', trans('admin.permissions'))->options($permissionModel::all()->pluck('name', 'id')); | ||
| 163 | + | ||
| 164 | + $form->display('created_at', trans('admin.created_at')); | ||
| 165 | + $form->display('updated_at', trans('admin.updated_at')); | ||
| 166 | + | ||
| 167 | + $form->saving(function (Form $form) { | ||
| 168 | + if ($form->password && $form->model()->password != $form->password) { | ||
| 169 | + $form->password = Hash::make($form->password); | ||
| 170 | + } | ||
| 171 | + }); | ||
| 172 | + | ||
| 173 | + return $form; | ||
| 174 | + } | ||
| 175 | +} |
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | ++----------------------------------------------------------------------------------------------------------------------- | ||
| 4 | + * 管理端控制层: 会员 控制类 | ||
| 5 | ++----------------------------------------------------------------------------------------------------------------------- | ||
| 6 | + * | ||
| 7 | + * PHP version 7 | ||
| 8 | + * | ||
| 9 | + * @category App\Admin\Controllers | ||
| 10 | + * @package App\Admin\Controllers | ||
| 11 | + * @author Richer <yangzi1028@163.com> | ||
| 12 | + * @date 2020年12月28日 17:57:14 | ||
| 13 | + * @copyright 2020-2022 Richer (http://www.Richer.com/) | ||
| 14 | + * @license http://www.Richer.com/ License | ||
| 15 | + * @link http://www.Richer.com/ | ||
| 16 | + */ | ||
| 17 | +namespace App\Admin\Controllers\Admin; | ||
| 18 | + | ||
| 19 | +use App\Admin\Controllers\BaseController; | ||
| 20 | +use App\Admin\Forms\Admin\UserForm; | ||
| 21 | +use App\Admin\Grids\Admin\UserGrid; | ||
| 22 | +use App\Models\Admin\User; | ||
| 23 | +use App\Models\Area\Area; | ||
| 24 | +use App\Models\Area\Village; | ||
| 25 | +use Encore\Admin\Form; | ||
| 26 | +use Encore\Admin\Grid; | ||
| 27 | +use Encore\Admin\Show; | ||
| 28 | +use Illuminate\Support\Facades\Hash; | ||
| 29 | + | ||
| 30 | +/** | ||
| 31 | + * Class UsersController. | ||
| 32 | + * | ||
| 33 | + * @category App\Admin\Controllers | ||
| 34 | + * @package App\Admin\Controllers | ||
| 35 | + * @author Richer <yangzi1028@163.com> | ||
| 36 | + * @date 2020年12月28日 17:57:14 | ||
| 37 | + * @copyright 2020-2022 Richer (http://www.Richer.com/) | ||
| 38 | + * @license http://www.Richer.com/ License | ||
| 39 | + * @link http://www.Richer.com/ | ||
| 40 | + */ | ||
| 41 | +class UsersController extends BaseController | ||
| 42 | +{ | ||
| 43 | + // 使用Grid和Form的trait | ||
| 44 | + use UserGrid, UserForm; | ||
| 45 | + | ||
| 46 | + /** | ||
| 47 | + * UsersController constructor. | ||
| 48 | + * | ||
| 49 | + * @param User $model 注入model | ||
| 50 | + */ | ||
| 51 | + public function __construct(User $model) | ||
| 52 | + { | ||
| 53 | + // 资源显示的中名称 | ||
| 54 | + $this->title = '安全负责人管理'; | ||
| 55 | + // 是否可查看 | ||
| 56 | + $this->can_view = false; | ||
| 57 | + // 是否可新增 | ||
| 58 | + $this->can_create = true; | ||
| 59 | + // 是否可编辑 | ||
| 60 | + $this->can_edit = true; | ||
| 61 | + // 是否可删除 | ||
| 62 | + $this->can_delete = true; | ||
| 63 | + // 是否开启下拉菜单 | ||
| 64 | + $this->dropdownActions = false; | ||
| 65 | + | ||
| 66 | + // 执行父类构造方法 | ||
| 67 | + parent::__construct($model); | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + /** | ||
| 71 | + * Make a grid builder. | ||
| 72 | + * | ||
| 73 | + * @return Grid | ||
| 74 | + */ | ||
| 75 | + protected function grid1() | ||
| 76 | + { | ||
| 77 | + $grid = new Grid($this->model); | ||
| 78 | + | ||
| 79 | + $grid->column('id', 'ID')->sortable(); | ||
| 80 | + $grid->column('username', trans('admin.username')); | ||
| 81 | + $grid->column('name', trans('admin.name')); | ||
| 82 | + $grid->column('roles', trans('admin.roles'))->pluck('name')->label(); | ||
| 83 | + $grid->column('created_at', trans('admin.created_at')); | ||
| 84 | + $grid->column('updated_at', trans('admin.updated_at')); | ||
| 85 | + | ||
| 86 | + $grid->actions(function (Grid\Displayers\Actions $actions) { | ||
| 87 | + if ($actions->getKey() == 1) { | ||
| 88 | + $actions->disableDelete(); | ||
| 89 | + } | ||
| 90 | + }); | ||
| 91 | + | ||
| 92 | + $grid->tools(function (Grid\Tools $tools) { | ||
| 93 | + $tools->batch(function (Grid\Tools\BatchActions $actions) { | ||
| 94 | + $actions->disableDelete(); | ||
| 95 | + }); | ||
| 96 | + }); | ||
| 97 | + | ||
| 98 | + return $grid; | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + /** | ||
| 102 | + * Make a show builder. | ||
| 103 | + * | ||
| 104 | + * @param mixed $id | ||
| 105 | + * | ||
| 106 | + * @return Show | ||
| 107 | + */ | ||
| 108 | + protected function detail($id) | ||
| 109 | + { | ||
| 110 | + $userModel = config('admin.database.users_model'); | ||
| 111 | + | ||
| 112 | + $show = new Show($userModel::findOrFail($id)); | ||
| 113 | + | ||
| 114 | + $show->field('id', 'ID'); | ||
| 115 | + $show->field('username', trans('admin.username')); | ||
| 116 | + $show->field('name', trans('admin.name')); | ||
| 117 | + $show->field('roles', trans('admin.roles'))->as(function ($roles) { | ||
| 118 | + return $roles->pluck('name'); | ||
| 119 | + })->label(); | ||
| 120 | + $show->field('permissions', trans('admin.permissions'))->as(function ($permission) { | ||
| 121 | + return $permission->pluck('name'); | ||
| 122 | + })->label(); | ||
| 123 | + $show->field('created_at', trans('admin.created_at')); | ||
| 124 | + $show->field('updated_at', trans('admin.updated_at')); | ||
| 125 | + | ||
| 126 | + return $show; | ||
| 127 | + } | ||
| 128 | + | ||
| 129 | + /** | ||
| 130 | + * Make a form builder. | ||
| 131 | + * | ||
| 132 | + * @return Form | ||
| 133 | + */ | ||
| 134 | + public function form1() | ||
| 135 | + { | ||
| 136 | + $userModel = config('admin.database.users_model'); | ||
| 137 | + $permissionModel = config('admin.database.permissions_model'); | ||
| 138 | + $roleModel = config('admin.database.roles_model'); | ||
| 139 | + | ||
| 140 | + $form = new Form(new $userModel()); | ||
| 141 | + | ||
| 142 | + $userTable = config('admin.database.users_table'); | ||
| 143 | + $connection = config('admin.database.connection'); | ||
| 144 | + | ||
| 145 | + $form->display('id', 'ID'); | ||
| 146 | + $form->text('username', trans('admin.username')) | ||
| 147 | + ->creationRules(['required', "unique:{$connection}.{$userTable}"]) | ||
| 148 | + ->updateRules(['required', "unique:{$connection}.{$userTable},username,{{id}}"]); | ||
| 149 | + | ||
| 150 | + $form->text('name', trans('admin.name'))->rules('required'); | ||
| 151 | + $form->image('avatar', trans('admin.avatar')); | ||
| 152 | + $form->password('password', trans('admin.password'))->rules('required|confirmed'); | ||
| 153 | + $form->password('password_confirmation', trans('admin.password_confirmation'))->rules('required') | ||
| 154 | + ->default(function ($form) { | ||
| 155 | + return $form->model()->password; | ||
| 156 | + }); | ||
| 157 | + | ||
| 158 | + $form->ignore(['password_confirmation']); | ||
| 159 | + | ||
| 160 | + $form->multipleSelect('roles', trans('admin.roles'))->options($roleModel::all()->pluck('name', 'id')); | ||
| 161 | + $form->multipleSelect('permissions', trans('admin.permissions'))->options($permissionModel::all()->pluck('name', 'id')); | ||
| 162 | + | ||
| 163 | + $form->display('created_at', trans('admin.created_at')); | ||
| 164 | + $form->display('updated_at', trans('admin.updated_at')); | ||
| 165 | + | ||
| 166 | + $form->saving(function (Form $form) { | ||
| 167 | + if ($form->password && $form->model()->password != $form->password) { | ||
| 168 | + $form->password = Hash::make($form->password); | ||
| 169 | + } | ||
| 170 | + }); | ||
| 171 | + | ||
| 172 | + return $form; | ||
| 173 | + } | ||
| 174 | + | ||
| 175 | + /** | ||
| 176 | + * @return \Illuminate\Http\JsonResponse | ||
| 177 | + */ | ||
| 178 | + public function areas() | ||
| 179 | + { | ||
| 180 | + $id = request('user_id'); | ||
| 181 | + | ||
| 182 | + // 获取当前用户的全部区域 | ||
| 183 | + $userAreas = optional(optional($this->model->find($id))->areas)->toArray(); | ||
| 184 | + $userVillages = []; | ||
| 185 | + $userGroups = []; | ||
| 186 | + if ($userAreas) { | ||
| 187 | + foreach ($userAreas as $userArea) { | ||
| 188 | + if ($userArea['area_type'] === Area::VILLAGE) { | ||
| 189 | + $userVillages[] = $userArea['area_id']; | ||
| 190 | + } elseif ($userArea['area_type'] === Area::GROUP) { | ||
| 191 | + $userGroups[] = $userArea['area_id']; | ||
| 192 | + } | ||
| 193 | + } | ||
| 194 | + } | ||
| 195 | + // 获取全部的社区和村并进行组合 | ||
| 196 | + $villages = Village::where('status', config('constants.STATUS_OK'))->get(['id','title'])->map(function ($village) use ($userVillages, $userGroups) { | ||
| 197 | + $groups = $village->groups()->where('status', config('constants.STATUS_OK'))->get(['id','title','village_id'])->map(function ($group) use ($userGroups) { | ||
| 198 | +// $buildings = $group->buildings()->where('status', config('constants.STATUS_OK'))->get(['id','title','group_id'])->map(function ($building) { | ||
| 199 | +// return [ | ||
| 200 | +// 'id' => $building->id , | ||
| 201 | +// 'title' => $building->title , | ||
| 202 | +// ]; | ||
| 203 | +// })->toArray(); | ||
| 204 | + $checked = ''; | ||
| 205 | + if (in_array($group->id, $userGroups)) { | ||
| 206 | + $checked = 'checked'; | ||
| 207 | + } | ||
| 208 | + return [ | ||
| 209 | + 'id' => $group->id , | ||
| 210 | + 'title' => $group->title , | ||
| 211 | + 'checked' => $checked , | ||
| 212 | +// 'children' => $buildings | ||
| 213 | + ]; | ||
| 214 | + })->toArray(); | ||
| 215 | + | ||
| 216 | + $checked = ''; | ||
| 217 | + if (in_array($village->id, $userVillages)) { | ||
| 218 | + $checked = 'checked'; | ||
| 219 | + } | ||
| 220 | + return [ | ||
| 221 | + 'id' => $village->id , | ||
| 222 | + 'title' => $village->title , | ||
| 223 | + 'children' => $groups, | ||
| 224 | + 'checked' => $checked | ||
| 225 | + ]; | ||
| 226 | + })->toArray(); | ||
| 227 | + return response()->json($villages); | ||
| 228 | + } | ||
| 229 | +} |
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | ++----------------------------------------------------------------------------------------------------------------------- | ||
| 4 | + * 管理端控制层: Advertisement 控制类 | ||
| 5 | ++----------------------------------------------------------------------------------------------------------------------- | ||
| 6 | + * | ||
| 7 | + * PHP version 7 | ||
| 8 | + * | ||
| 9 | + * @category App\Admin\Controllers | ||
| 10 | + * @package App\Admin\Controllers | ||
| 11 | + * @author Richer <yangzi1028@163.com> | ||
| 12 | + * @date 2023年4月20日14:26:14 | ||
| 13 | + * @copyright 2020-2022 Richer (http://www.Richer.com/) | ||
| 14 | + * @license http://www.Richer.com/ License | ||
| 15 | + * @link http://www.Richer.com/ | ||
| 16 | + */ | ||
| 17 | +namespace App\Admin\Controllers; | ||
| 18 | + | ||
| 19 | +use App\Admin\Forms\AdvertisementForm; | ||
| 20 | +use App\Admin\Grids\AdvertisementGrid; | ||
| 21 | +use App\Models\Advertisement; | ||
| 22 | + | ||
| 23 | +/** | ||
| 24 | + * Class AdvertisementsController. | ||
| 25 | + * | ||
| 26 | + * @package App\Admin\Controllers | ||
| 27 | + */ | ||
| 28 | +class AdvertisementsController extends BaseController | ||
| 29 | +{ | ||
| 30 | + use AdvertisementGrid, AdvertisementForm; | ||
| 31 | + | ||
| 32 | + /** | ||
| 33 | + * AdvertisementsController constructor. | ||
| 34 | + * | ||
| 35 | + * @param Advertisement $model 注入model | ||
| 36 | + */ | ||
| 37 | + public function __construct(Advertisement $model) | ||
| 38 | + { | ||
| 39 | + // 资源显示的中名称 | ||
| 40 | + $this->title = $model::OBJ_NAME_ZH; | ||
| 41 | + // 是否可查看 | ||
| 42 | + $this->can_view = false; | ||
| 43 | + // 是否可新增 | ||
| 44 | + $this->can_create = true; | ||
| 45 | + // 是否可编辑 | ||
| 46 | + $this->can_edit = true; | ||
| 47 | + // 是否可删除 | ||
| 48 | + $this->can_delete = true; | ||
| 49 | + // 是否开启下拉菜单 | ||
| 50 | + $this->dropdownActions = false; | ||
| 51 | + | ||
| 52 | + // 执行父类构造方法 | ||
| 53 | + parent::__construct($model); | ||
| 54 | + } | ||
| 55 | +} |
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | ++----------------------------------------------------------------------------------------------------------------------- | ||
| 4 | + * 管理端控制层: 区域-社区 控制类 | ||
| 5 | ++----------------------------------------------------------------------------------------------------------------------- | ||
| 6 | + * | ||
| 7 | + * PHP version 7 | ||
| 8 | + * | ||
| 9 | + * @category App\Admin\Controllers\Area | ||
| 10 | + * @package App\Admin\Controllers\Area | ||
| 11 | + * @author Richer <yangzi1028@163.com> | ||
| 12 | + * @date 2021年1月27日10:57:55 | ||
| 13 | + * @copyright 2020-2022 Richer (http://www.Richer.com/) | ||
| 14 | + * @license http://www.Richer.com/ License | ||
| 15 | + * @link http://www.Richer.com/ | ||
| 16 | + */ | ||
| 17 | +namespace App\Admin\Controllers\Area; | ||
| 18 | + | ||
| 19 | +use App\Admin\Controllers\BaseController; | ||
| 20 | +use App\Admin\Forms\Area\AreaForm; | ||
| 21 | +use App\Admin\Grids\Area\AreaGrid; | ||
| 22 | +use App\Models\Area\Area; | ||
| 23 | +use Illuminate\Http\JsonResponse; | ||
| 24 | +use Illuminate\Support\Facades\DB; | ||
| 25 | + | ||
| 26 | +/** | ||
| 27 | + * Class VillagesController. | ||
| 28 | + * | ||
| 29 | + * @category App\Admin\Controllers\Area | ||
| 30 | + * @package App\Admin\Controllers\Area | ||
| 31 | + * @author Richer <yangzi1028@163.com> | ||
| 32 | + * @date 2021年6月16日15:40:14 | ||
| 33 | + * @copyright 2020-2022 Richer (http://www.Richer.com/) | ||
| 34 | + * @license http://www.Richer.com/ License | ||
| 35 | + * @link http://www.Richer.com/ | ||
| 36 | + */ | ||
| 37 | +class AreasController extends BaseController | ||
| 38 | +{ | ||
| 39 | + // 使用Grid和Form的trait | ||
| 40 | + use AreaGrid, AreaForm; | ||
| 41 | + | ||
| 42 | + /** | ||
| 43 | + * CommunitiesController constructor. | ||
| 44 | + * | ||
| 45 | + * @param Area $model 注入model | ||
| 46 | + */ | ||
| 47 | + public function __construct(Area $model) | ||
| 48 | + { | ||
| 49 | + // 资源显示的中文名称 | ||
| 50 | + $this->title = $model::OBJ_NAME; | ||
| 51 | + // 资源显示的名称 | ||
| 52 | + $this->type = $model::OBJ_NAME; | ||
| 53 | + // 所在级别 | ||
| 54 | + $this->level = $model::LEVEL; | ||
| 55 | + // 表名称 | ||
| 56 | + $this->table = $model::TABLE; | ||
| 57 | + // 是否可查看 | ||
| 58 | + $this->can_view = false; | ||
| 59 | + // 是否可新增 | ||
| 60 | + $this->can_create = true; | ||
| 61 | + // 是否可编辑 | ||
| 62 | + $this->can_edit = true; | ||
| 63 | + // 是否可删除 | ||
| 64 | + $this->can_delete = true; | ||
| 65 | + // 是否开启下拉菜单 | ||
| 66 | + $this->dropdownActions = false; | ||
| 67 | + | ||
| 68 | + // 执行父类构造方法 | ||
| 69 | + parent::__construct($model); | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + /** | ||
| 73 | + * @return JsonResponse | ||
| 74 | + */ | ||
| 75 | + public function getSelectOptions() | ||
| 76 | + { | ||
| 77 | + $list = $this->model::getSelectOptions(request('q'), 'link'); | ||
| 78 | + return response()->json($list); | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + /** | ||
| 82 | + * @return JsonResponse | ||
| 83 | + */ | ||
| 84 | + public function getSelectOptionsByProvince() | ||
| 85 | + { | ||
| 86 | + $list = $this->model::getSelectOptionsByProvince(request('q'), 'link'); | ||
| 87 | + return response()->json($list); | ||
| 88 | + } | ||
| 89 | +} |
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | ++----------------------------------------------------------------------------------------------------------------------- | ||
| 4 | + * 管理端控制层: 区域-省份 控制类 | ||
| 5 | ++----------------------------------------------------------------------------------------------------------------------- | ||
| 6 | + * | ||
| 7 | + * PHP version 7 | ||
| 8 | + * | ||
| 9 | + * @category App\Admin\Controllers\Area | ||
| 10 | + * @package App\Admin\Controllers\Area | ||
| 11 | + * @author Richer <yangzi1028@163.com> | ||
| 12 | + * @date 2021年11月3日19:37:49 | ||
| 13 | + * @copyright 2020-2022 Richer (http://www.Richer.com/) | ||
| 14 | + * @license http://www.Richer.com/ License | ||
| 15 | + * @link http://www.Richer.com/ | ||
| 16 | + */ | ||
| 17 | +namespace App\Admin\Controllers\Area; | ||
| 18 | + | ||
| 19 | +use App\Models\Area\City; | ||
| 20 | + | ||
| 21 | +/** | ||
| 22 | + * Class CitiesController. | ||
| 23 | + * | ||
| 24 | + * @category App\Admin\Controllers\Area | ||
| 25 | + * @package App\Admin\Controllers\Area | ||
| 26 | + * @author Richer <yangzi1028@163.com> | ||
| 27 | + * @date 2021年11月3日19:37:49 | ||
| 28 | + * @copyright 2020-2022 Richer (http://www.Richer.com/) | ||
| 29 | + * @license http://www.Richer.com/ License | ||
| 30 | + * @link http://www.Richer.com/ | ||
| 31 | + */ | ||
| 32 | +class CitiesController extends AreasController | ||
| 33 | +{ | ||
| 34 | + /** | ||
| 35 | + * CitiesController constructor. | ||
| 36 | + * | ||
| 37 | + * @param City $model 注入model | ||
| 38 | + */ | ||
| 39 | + public function __construct(City $model) | ||
| 40 | + { | ||
| 41 | + // 执行父类构造方法 | ||
| 42 | + parent::__construct($model); | ||
| 43 | + } | ||
| 44 | +} |
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | ++----------------------------------------------------------------------------------------------------------------------- | ||
| 4 | + * 管理端控制层: 区域-省份 控制类 | ||
| 5 | ++----------------------------------------------------------------------------------------------------------------------- | ||
| 6 | + * | ||
| 7 | + * PHP version 7 | ||
| 8 | + * | ||
| 9 | + * @category App\Admin\Controllers\Area | ||
| 10 | + * @package App\Admin\Controllers\Area | ||
| 11 | + * @author Richer <yangzi1028@163.com> | ||
| 12 | + * @date 2021年11月3日19:37:49 | ||
| 13 | + * @copyright 2020-2022 Richer (http://www.Richer.com/) | ||
| 14 | + * @license http://www.Richer.com/ License | ||
| 15 | + * @link http://www.Richer.com/ | ||
| 16 | + */ | ||
| 17 | +namespace App\Admin\Controllers\Area; | ||
| 18 | + | ||
| 19 | +use App\Models\Area\City; | ||
| 20 | +use App\Models\Area\County; | ||
| 21 | + | ||
| 22 | +/** | ||
| 23 | + * Class CountiesController. | ||
| 24 | + * | ||
| 25 | + * @category App\Admin\Controllers\Area | ||
| 26 | + * @package App\Admin\Controllers\Area | ||
| 27 | + * @author Richer <yangzi1028@163.com> | ||
| 28 | + * @date 2021年11月3日19:37:49 | ||
| 29 | + * @copyright 2020-2022 Richer (http://www.Richer.com/) | ||
| 30 | + * @license http://www.Richer.com/ License | ||
| 31 | + * @link http://www.Richer.com/ | ||
| 32 | + */ | ||
| 33 | +class CountiesController extends AreasController | ||
| 34 | +{ | ||
| 35 | + /** | ||
| 36 | + * CountiesController constructor. | ||
| 37 | + * | ||
| 38 | + * @param County $model 注入model | ||
| 39 | + */ | ||
| 40 | + public function __construct(County $model) | ||
| 41 | + { | ||
| 42 | + // 执行父类构造方法 | ||
| 43 | + parent::__construct($model); | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | +} |
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | ++----------------------------------------------------------------------------------------------------------------------- | ||
| 4 | + * 管理端控制层: 区域-省份 控制类 | ||
| 5 | ++----------------------------------------------------------------------------------------------------------------------- | ||
| 6 | + * | ||
| 7 | + * PHP version 7 | ||
| 8 | + * | ||
| 9 | + * @category App\Admin\Controllers\Area | ||
| 10 | + * @package App\Admin\Controllers\Area | ||
| 11 | + * @author Richer <yangzi1028@163.com> | ||
| 12 | + * @date 2021年11月3日19:37:49 | ||
| 13 | + * @copyright 2020-2022 Richer (http://www.Richer.com/) | ||
| 14 | + * @license http://www.Richer.com/ License | ||
| 15 | + * @link http://www.Richer.com/ | ||
| 16 | + */ | ||
| 17 | +namespace App\Admin\Controllers\Area; | ||
| 18 | + | ||
| 19 | +use App\Models\Area\Group; | ||
| 20 | +use App\Models\Area\Village; | ||
| 21 | + | ||
| 22 | +/** | ||
| 23 | + * Class GroupsController. | ||
| 24 | + * | ||
| 25 | + * @category App\Admin\Controllers\Area | ||
| 26 | + * @package App\Admin\Controllers\Area | ||
| 27 | + * @author Richer <yangzi1028@163.com> | ||
| 28 | + * @date 2021年11月3日19:37:49 | ||
| 29 | + * @copyright 2020-2022 Richer (http://www.Richer.com/) | ||
| 30 | + * @license http://www.Richer.com/ License | ||
| 31 | + * @link http://www.Richer.com/ | ||
| 32 | + */ | ||
| 33 | +class GroupsController extends AreasController | ||
| 34 | +{ | ||
| 35 | + /** | ||
| 36 | + * GroupsController constructor. | ||
| 37 | + * | ||
| 38 | + * @param Group $model 注入model | ||
| 39 | + */ | ||
| 40 | + public function __construct(Group $model) | ||
| 41 | + { | ||
| 42 | + // 执行父类构造方法 | ||
| 43 | + parent::__construct($model); | ||
| 44 | + } | ||
| 45 | +} |
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | ++----------------------------------------------------------------------------------------------------------------------- | ||
| 4 | + * 管理端控制层: 区域-省份 控制类 | ||
| 5 | ++----------------------------------------------------------------------------------------------------------------------- | ||
| 6 | + * | ||
| 7 | + * PHP version 7 | ||
| 8 | + * | ||
| 9 | + * @category App\Admin\Controllers\Area | ||
| 10 | + * @package App\Admin\Controllers\Area | ||
| 11 | + * @author Richer <yangzi1028@163.com> | ||
| 12 | + * @date 2021年11月3日19:37:49 | ||
| 13 | + * @copyright 2020-2022 Richer (http://www.Richer.com/) | ||
| 14 | + * @license http://www.Richer.com/ License | ||
| 15 | + * @link http://www.Richer.com/ | ||
| 16 | + */ | ||
| 17 | +namespace App\Admin\Controllers\Area; | ||
| 18 | + | ||
| 19 | +use App\Models\Area\Province; | ||
| 20 | + | ||
| 21 | +/** | ||
| 22 | + * Class ProvincesController. | ||
| 23 | + * | ||
| 24 | + * @category App\Admin\Controllers\Area | ||
| 25 | + * @package App\Admin\Controllers\Area | ||
| 26 | + * @author Richer <yangzi1028@163.com> | ||
| 27 | + * @date 2021年11月3日19:37:49 | ||
| 28 | + * @copyright 2020-2022 Richer (http://www.Richer.com/) | ||
| 29 | + * @license http://www.Richer.com/ License | ||
| 30 | + * @link http://www.Richer.com/ | ||
| 31 | + */ | ||
| 32 | +class ProvincesController extends AreasController | ||
| 33 | +{ | ||
| 34 | + /** | ||
| 35 | + * ProvincesController constructor. | ||
| 36 | + * | ||
| 37 | + * @param Province $model 注入model | ||
| 38 | + */ | ||
| 39 | + public function __construct(Province $model) | ||
| 40 | + { | ||
| 41 | + // 执行父类构造方法 | ||
| 42 | + parent::__construct($model); | ||
| 43 | + } | ||
| 44 | +} |
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | ++----------------------------------------------------------------------------------------------------------------------- | ||
| 4 | + * 管理端控制层: 区域-省份 控制类 | ||
| 5 | ++----------------------------------------------------------------------------------------------------------------------- | ||
| 6 | + * | ||
| 7 | + * PHP version 7 | ||
| 8 | + * | ||
| 9 | + * @category App\Admin\Controllers\Area | ||
| 10 | + * @package App\Admin\Controllers\Area | ||
| 11 | + * @author Richer <yangzi1028@163.com> | ||
| 12 | + * @date 2021年11月3日19:37:49 | ||
| 13 | + * @copyright 2020-2022 Richer (http://www.Richer.com/) | ||
| 14 | + * @license http://www.Richer.com/ License | ||
| 15 | + * @link http://www.Richer.com/ | ||
| 16 | + */ | ||
| 17 | +namespace App\Admin\Controllers\Area; | ||
| 18 | + | ||
| 19 | +use App\Models\Area\City; | ||
| 20 | +use App\Models\Area\County; | ||
| 21 | +use App\Models\Area\Township; | ||
| 22 | + | ||
| 23 | +/** | ||
| 24 | + * Class TownshipsController. | ||
| 25 | + * | ||
| 26 | + * @category App\Admin\Controllers\Area | ||
| 27 | + * @package App\Admin\Controllers\Area | ||
| 28 | + * @author Richer <yangzi1028@163.com> | ||
| 29 | + * @date 2021年11月3日19:37:49 | ||
| 30 | + * @copyright 2020-2022 Richer (http://www.Richer.com/) | ||
| 31 | + * @license http://www.Richer.com/ License | ||
| 32 | + * @link http://www.Richer.com/ | ||
| 33 | + */ | ||
| 34 | +class TownshipsController extends AreasController | ||
| 35 | +{ | ||
| 36 | + /** | ||
| 37 | + * TownshipsController constructor. | ||
| 38 | + * | ||
| 39 | + * @param Township $model 注入model | ||
| 40 | + */ | ||
| 41 | + public function __construct(Township $model) | ||
| 42 | + { | ||
| 43 | + // 执行父类构造方法 | ||
| 44 | + parent::__construct($model); | ||
| 45 | + } | ||
| 46 | +} |
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | ++----------------------------------------------------------------------------------------------------------------------- | ||
| 4 | + * 管理端控制层: 区域-省份 控制类 | ||
| 5 | ++----------------------------------------------------------------------------------------------------------------------- | ||
| 6 | + * | ||
| 7 | + * PHP version 7 | ||
| 8 | + * | ||
| 9 | + * @category App\Admin\Controllers\Area | ||
| 10 | + * @package App\Admin\Controllers\Area | ||
| 11 | + * @author Richer <yangzi1028@163.com> | ||
| 12 | + * @date 2021年11月3日19:37:49 | ||
| 13 | + * @copyright 2020-2022 Richer (http://www.Richer.com/) | ||
| 14 | + * @license http://www.Richer.com/ License | ||
| 15 | + * @link http://www.Richer.com/ | ||
| 16 | + */ | ||
| 17 | +namespace App\Admin\Controllers\Area; | ||
| 18 | + | ||
| 19 | +use App\Models\Area\City; | ||
| 20 | +use App\Models\Area\County; | ||
| 21 | +use App\Models\Area\Township; | ||
| 22 | +use App\Models\Area\Village; | ||
| 23 | + | ||
| 24 | +/** | ||
| 25 | + * Class VillagesController. | ||
| 26 | + * | ||
| 27 | + * @category App\Admin\Controllers\Area | ||
| 28 | + * @package App\Admin\Controllers\Area | ||
| 29 | + * @author Richer <yangzi1028@163.com> | ||
| 30 | + * @date 2021年11月3日19:37:49 | ||
| 31 | + * @copyright 2020-2022 Richer (http://www.Richer.com/) | ||
| 32 | + * @license http://www.Richer.com/ License | ||
| 33 | + * @link http://www.Richer.com/ | ||
| 34 | + */ | ||
| 35 | +class VillagesController extends AreasController | ||
| 36 | +{ | ||
| 37 | + /** | ||
| 38 | + * VillagesController constructor. | ||
| 39 | + * | ||
| 40 | + * @param Village $model 注入model | ||
| 41 | + */ | ||
| 42 | + public function __construct(Village $model) | ||
| 43 | + { | ||
| 44 | + // 执行父类构造方法 | ||
| 45 | + parent::__construct($model); | ||
| 46 | + } | ||
| 47 | +} |
app/Admin/Controllers/Auth/LogController.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Admin\Controllers\Auth; | ||
| 4 | + | ||
| 5 | +use App\Models\Area\Area; | ||
| 6 | +use App\Admin\Rewrite\Auth\Database\OperationLog; | ||
| 7 | +use Encore\Admin\Controllers\LogController as BaseController; | ||
| 8 | +use Encore\Admin\Grid; | ||
| 9 | +use Illuminate\Support\Str; | ||
| 10 | + | ||
| 11 | +class LogController extends BaseController | ||
| 12 | +{ | ||
| 13 | + /** | ||
| 14 | + * {@inheritdoc} | ||
| 15 | + */ | ||
| 16 | + protected function title() | ||
| 17 | + { | ||
| 18 | + return trans('admin.operation_log'); | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + /** | ||
| 22 | + * @return Grid | ||
| 23 | + */ | ||
| 24 | + protected function grid() | ||
| 25 | + { | ||
| 26 | + $menuModel = config('admin.database.menu_model'); | ||
| 27 | + $menu = $menuModel::get()->toArray(); | ||
| 28 | + $operations = []; | ||
| 29 | + foreach ($menu as $key => $value) { | ||
| 30 | + if ($value['uri']) { | ||
| 31 | + $operation['url'] = 'admin'.$value['uri']; | ||
| 32 | + if ($value['uri'] == '/') { | ||
| 33 | + $operation['url'] = 'admin'; | ||
| 34 | + } | ||
| 35 | + } else { | ||
| 36 | + $operation['url'] = ''; | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + $operation['title'] = $value['title']; | ||
| 40 | + $operations[] = $operation; | ||
| 41 | + } | ||
| 42 | + // 增加其他的设置 | ||
| 43 | + | ||
| 44 | + $grid = new Grid(new OperationLog()); | ||
| 45 | + $ignore_path = ['admin/_handle_renderable_', 'admin/user/card','admin/user/password','admin/user/card-reader']; | ||
| 46 | + $grid->model()->whereNotIn('path', $ignore_path) | ||
| 47 | + ->where('path', 'NOT LIKE', '%select-options%') | ||
| 48 | +// ->where('path', 'NOT LIKE' ,'%handle-page%') | ||
| 49 | + ->where('path', 'NOT LIKE', '%_handle_renderable_%') | ||
| 50 | + ->where('path', 'NOT LIKE', '%_handle_action_%') | ||
| 51 | + ->orderBy('id', 'DESC'); | ||
| 52 | + $grid->column('id', 'ID')->sortable(); | ||
| 53 | + $grid->column('user.name', '访问用户'); | ||
| 54 | + $grid->path('访问地址')->label('info'); | ||
| 55 | + $grid->method_zh('请求方法')->label('primary'); | ||
| 56 | + $grid->ip('ip地址')->label('primary'); | ||
| 57 | + $grid->show('操作描述')->display(function () use ($operations) { | ||
| 58 | + $path = $this->path; | ||
| 59 | + $method = $this->method; | ||
| 60 | + $input = json_decode($this->input, true); | ||
| 61 | + $operate = ''; | ||
| 62 | + if (Str::contains($path, 'area/village/select-options')) { | ||
| 63 | + return '查询 '.Area::VILLAGE_ZH.' options 数据'; | ||
| 64 | + } elseif (Str::contains($path, 'area/group/select-options')) { | ||
| 65 | + return '查询 '.Area::GROUP_ZH.' options 数据'; | ||
| 66 | + } elseif (Str::contains($path, 'area/building/select-options')) { | ||
| 67 | + return '查询 '.Area::BUILDING_ZH.' options 数据'; | ||
| 68 | + } elseif (Str::contains($path, 'area/room/select-options')) { | ||
| 69 | + return '查询 '.Area::ROOM_ZH.' options 数据'; | ||
| 70 | + } elseif (Str::contains($path, 'admin/map-data')) { | ||
| 71 | + return '查询 地图 数据'; | ||
| 72 | + } elseif (Str::contains($path, 'auth/menu')) { | ||
| 73 | + return '进入 菜单 列表'; | ||
| 74 | + } elseif (Str::contains($path, 'map/room')) { | ||
| 75 | + return '地图 查询 房间'; | ||
| 76 | + } elseif (Str::contains($path, 'map/data-page')) { | ||
| 77 | + return '地图 地图 数据'; | ||
| 78 | + } elseif (Str::contains($path, 'admin/report-locks')) { | ||
| 79 | + return '进入 智能门锁报告 列表'; | ||
| 80 | + } elseif (Str::contains($path, 'admin/user/password')) { | ||
| 81 | + return '打开 用户密码 界面'; | ||
| 82 | + } elseif (Str::contains($path, 'admin/user/password')) { | ||
| 83 | + return '打开 用户密码 界面'; | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | +// if ($path == 'admin/area/room/select-options') { | ||
| 87 | +// dump($path); | ||
| 88 | +// } | ||
| 89 | + foreach ($operations as $key => $value) { | ||
| 90 | + if ($value['url']) { | ||
| 91 | + if (Str::startsWith($path, $value['url'])) { | ||
| 92 | + // | ||
| 93 | + if ($path == $value['url']) { | ||
| 94 | + if ($method == 'GET') { | ||
| 95 | + $operate = '进入'.$value['title'] .'列表'; | ||
| 96 | + } elseif ($method == 'POST') { | ||
| 97 | + $operate = '新增'.$value['title']; | ||
| 98 | + } | ||
| 99 | + } else { | ||
| 100 | + // 定义操作 | ||
| 101 | + $behind = 'ID为<span style="font-weight:bold;font-size:18px;padding:0 3px;"> | ||
| 102 | + {id}</span>的<span style="font-weight:bold; padding:0 3px;">'. | ||
| 103 | + $value['title']. | ||
| 104 | + '</span>'; | ||
| 105 | + $action = ''; | ||
| 106 | + $id = 0; | ||
| 107 | + if (Str::endsWith($path, 'edit')) { | ||
| 108 | + $operate = '进入'.$value['title'] .'编辑页面'; | ||
| 109 | + } elseif (Str::endsWith($path, 'create')) { | ||
| 110 | + $operate = '进入'.$value['title'] .'新增页面'; | ||
| 111 | + } elseif (Str::endsWith($path, 'chunk-file-upload')) { | ||
| 112 | + return '上传大视频'; | ||
| 113 | + } else { | ||
| 114 | + if (strstr($path, 'audit/pass')) { | ||
| 115 | + if ($method == 'PUT') { | ||
| 116 | + $temp = explode('/', $path); | ||
| 117 | + $id =$temp[count($temp)-1]; | ||
| 118 | + // $operate = '审核不通过ID为<span class="label label-info">'.$id.'</span>的'.$value['title']; | ||
| 119 | + $action ='<span style="color: green">审核通过</span>'; | ||
| 120 | + } | ||
| 121 | + } elseif (strstr($path, 'audit/refusal')) { | ||
| 122 | + if ($method == 'PUT') { | ||
| 123 | + $temp = explode('/', $path); | ||
| 124 | + $id =$temp[count($temp)-1]; | ||
| 125 | + // $operate = '审核不通过ID为<span class="label label-info">'.$id.'</span>的'.$value['title']; | ||
| 126 | + $action ='<span style="color:red">审核不通过</span>'; | ||
| 127 | + } | ||
| 128 | + } elseif (strstr($path, 'offline')) { | ||
| 129 | + if ($method == 'PUT') { | ||
| 130 | + $temp = explode('/', $path); | ||
| 131 | + $id =$temp[count($temp)-1]; | ||
| 132 | + // | ||
| 133 | + $action ='<span style="color:#f39c12">下架</span>'; | ||
| 134 | + } | ||
| 135 | + } elseif (strstr($path, 'online')) { | ||
| 136 | + if ($method == 'PUT') { | ||
| 137 | + $temp = explode('/', $path); | ||
| 138 | + $id =$temp[count($temp)-1]; | ||
| 139 | + $action ='<span style="color:#398439">上架</span>'; | ||
| 140 | + } | ||
| 141 | + } elseif (strstr($path, 'cancelTopping')) { | ||
| 142 | + if ($method == 'PUT') { | ||
| 143 | + $temp = explode('/', str_replace('/cancelTopping', '', $path)); | ||
| 144 | + $id =$temp[count($temp)-1]; | ||
| 145 | + $action ='<span style="color:#f39c12">取消置顶</span>'; | ||
| 146 | + } | ||
| 147 | + } elseif (strstr($path, 'setTopping')) { | ||
| 148 | + if ($method == 'PUT') { | ||
| 149 | + $temp = explode('/', str_replace('/setTopping', '', $path)); | ||
| 150 | + $id =$temp[count($temp)-1]; | ||
| 151 | + | ||
| 152 | + $action ='<span style="color:#398439">置顶</span>'; | ||
| 153 | + } | ||
| 154 | + } elseif (strstr($path, 'enable')) { | ||
| 155 | + if ($method == 'PUT') { | ||
| 156 | + $temp = explode('/', str_replace('/enable', '', $path)); | ||
| 157 | + $id =$temp[count($temp)-1]; | ||
| 158 | + $action ='<span style="color:#398439">启用</span>'; | ||
| 159 | + } | ||
| 160 | + } elseif (strstr($path, 'disable')) { | ||
| 161 | + if ($method == 'PUT') { | ||
| 162 | + $temp = explode('/', str_replace('/disable', '', $path)); | ||
| 163 | + $id =$temp[count($temp)-1]; | ||
| 164 | + $action ='<span style="color:#f39c12">禁用</span>'; | ||
| 165 | + } | ||
| 166 | + } elseif (strstr($path, 'restore')) { | ||
| 167 | + if ($method == 'PUT') { | ||
| 168 | + $temp = explode('/', str_replace('/restore', '', $path)); | ||
| 169 | + $id =$temp[count($temp)-1]; | ||
| 170 | + $action ='<span class="text text-success">恢复</span>'; | ||
| 171 | + } | ||
| 172 | + } elseif (strstr($path, 'drill')) { | ||
| 173 | + if ($method == 'PUT') { | ||
| 174 | + $temp = explode('/', str_replace('/drill', '', $path)); | ||
| 175 | + $id =$temp[count($temp)-1]; | ||
| 176 | + $action ='<span class="text text-warning">演习</span>'; | ||
| 177 | + } | ||
| 178 | + } elseif (strstr($path, 'notify')) { | ||
| 179 | + if ($method == 'POST') { | ||
| 180 | + $temp = explode('/', str_replace('/notify', '', $path)); | ||
| 181 | + $id =$temp[count($temp)-1]; | ||
| 182 | + $action ='<span class="text text-success">通知</span>'; | ||
| 183 | + } | ||
| 184 | + } elseif (strstr($path, 'update')) { | ||
| 185 | + if ($method == 'PUT') { | ||
| 186 | + $temp = explode('/', str_replace('/update', '', $path)); | ||
| 187 | + $id =$temp[count($temp)-1]; | ||
| 188 | + $action ='<span style="color:#398439">更新</span>'; | ||
| 189 | + } | ||
| 190 | + } elseif (strstr($path, 'info')) { | ||
| 191 | + if ($method == 'GET') { | ||
| 192 | + $temp = explode('/', str_replace('/info', '', $path)); | ||
| 193 | + $id =$temp[count($temp)-1]; | ||
| 194 | + $action ='<span style="color:#398439">查看</span>'; | ||
| 195 | + } | ||
| 196 | + } else { | ||
| 197 | + $id = str_replace($value['url'] .'/', '', $path); | ||
| 198 | + | ||
| 199 | +// if ($path == 'admin/warnings/16/users') { | ||
| 200 | +// dump($path);dump($value['url']); | ||
| 201 | +// dump($value['title']); | ||
| 202 | +// | ||
| 203 | +// } | ||
| 204 | + if ($method == 'GET') { | ||
| 205 | + $id = str_replace('/edit', '', $id); | ||
| 206 | + $action ='编辑'; | ||
| 207 | + if ($path =='admin/auth/login') { | ||
| 208 | + return '<span style="color: green">登录</span>'; | ||
| 209 | + } elseif ($path =='admin/auth/logout') { | ||
| 210 | + return '<span style="color:#999">退出登录</span>'; | ||
| 211 | + } elseif ($path =='admin/statistics/users') { | ||
| 212 | + return '查看数据面板会员统计图'; | ||
| 213 | + } elseif ($path =='admin/statistics/orders') { | ||
| 214 | + return '查看数据面板订单统计图'; | ||
| 215 | + } elseif ($path =='admin/statistics/sales') { | ||
| 216 | + return '查看数据面板销售额统计图'; | ||
| 217 | + } elseif (strstr($path, 'quotations')) { | ||
| 218 | + return '查看方案的报价单'; | ||
| 219 | + } | ||
| 220 | + } elseif ($method == 'DELETE') { | ||
| 221 | + $temp = explode('/', str_replace('/notify', '', $path)); | ||
| 222 | + $id =$temp[count($temp)-1]; | ||
| 223 | + $action ='<span class="text text-danger">删除</span>'; | ||
| 224 | + } elseif ($method == 'PUT') { | ||
| 225 | + $action ='<span style="color:#398439">更新</span>'; | ||
| 226 | + } | ||
| 227 | + } | ||
| 228 | + $behind = str_replace('{id}', $id, $behind); | ||
| 229 | + $operate = '<span style="font-weight:bold;padding:0 3px;">'.$action .'</span>'. $behind; | ||
| 230 | + } | ||
| 231 | + } | ||
| 232 | + } | ||
| 233 | + } | ||
| 234 | + } | ||
| 235 | + return $operate; | ||
| 236 | + }); | ||
| 237 | + | ||
| 238 | + $grid->column('created_at', trans('admin.created_at')); | ||
| 239 | + | ||
| 240 | + $grid->actions(function (Grid\Displayers\Actions $actions) { | ||
| 241 | + $actions->disableEdit(); | ||
| 242 | + $actions->disableView(); | ||
| 243 | + }); | ||
| 244 | + | ||
| 245 | + $grid->disableCreateButton(); | ||
| 246 | + $grid->disableExport(); | ||
| 247 | + $grid->disableRowSelector(); | ||
| 248 | + | ||
| 249 | + $grid->filter(function (Grid\Filter $filter) { | ||
| 250 | +// $userModel = config('admin.database.users_model'); | ||
| 251 | + | ||
| 252 | + $filter->between('created_at', '操作时间')->date(); | ||
| 253 | + | ||
| 254 | +// $filter->equal('user_id', 'User')->select($userModel::all()->pluck('name', 'id')); | ||
| 255 | + $filter->equal('method')->select(OperationLog::$methodShows)->placeholder('请求方法'); | ||
| 256 | +// $filter->like('path'); | ||
| 257 | +// $filter->equal('ip'); | ||
| 258 | + //去掉默认的搜索 | ||
| 259 | + $filter->disableIdFilter(); | ||
| 260 | + }); | ||
| 261 | + | ||
| 262 | + return $grid; | ||
| 263 | + } | ||
| 264 | +} |
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | ++----------------------------------------------------------------------------------------------------------------------- | ||
| 4 | + * 重写laravel-admin Auth控制类 | ||
| 5 | ++----------------------------------------------------------------------------------------------------------------------- | ||
| 6 | + * | ||
| 7 | + * @copyright Copyright | ||
| 8 | + * @author Richer | ||
| 9 | + * @package App\Admin\Controllers | ||
| 10 | + * @version 2020年3月23日,14:13:13 | ||
| 11 | + * @link | ||
| 12 | + */ | ||
| 13 | +namespace App\Admin\Controllers\Auth; | ||
| 14 | + | ||
| 15 | +use App\Admin\Rewrite\Controllers\BaseMenuController; | ||
| 16 | + | ||
| 17 | +class MenuController extends BaseMenuController | ||
| 18 | +{ | ||
| 19 | +} |
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | ++----------------------------------------------------------------------------------------------------------------------- | ||
| 4 | + * 重写laravel-admin Auth控制类 | ||
| 5 | ++----------------------------------------------------------------------------------------------------------------------- | ||
| 6 | + * | ||
| 7 | + * @copyright Copyright | ||
| 8 | + * @author Richer | ||
| 9 | + * @package App\Admin\Controllers | ||
| 10 | + * @version 2020年3月23日,14:13:13 | ||
| 11 | + * @link | ||
| 12 | + */ | ||
| 13 | +namespace App\Admin\Controllers\Auth; | ||
| 14 | + | ||
| 15 | +use App\Admin\Controllers\BaseController; | ||
| 16 | +use App\Admin\Forms\Admin\PermissionForm; | ||
| 17 | +use App\Admin\Grids\Admin\PermissionGrid; | ||
| 18 | +use App\Models\Admin\Permission; | ||
| 19 | + | ||
| 20 | +class PermissionController extends BaseController | ||
| 21 | +{ | ||
| 22 | + // 使用Grid和Form的trait | ||
| 23 | + use PermissionGrid, PermissionForm; | ||
| 24 | + | ||
| 25 | + /** | ||
| 26 | + * RoleController constructor. | ||
| 27 | + * | ||
| 28 | + * @param Permission $model 注入model | ||
| 29 | + */ | ||
| 30 | + public function __construct(Permission $model) | ||
| 31 | + { | ||
| 32 | + // 资源显示的中名称 | ||
| 33 | + $this->title = $model::OBJ_NAME; | ||
| 34 | + // 是否可查看 | ||
| 35 | + $this->can_view = false; | ||
| 36 | + // 是否可新增 | ||
| 37 | + $this->can_create = true; | ||
| 38 | + // 是否可编辑 | ||
| 39 | + $this->can_edit = true; | ||
| 40 | + // 是否可删除 | ||
| 41 | + $this->can_delete = true; | ||
| 42 | + // 执行父类构造方法 | ||
| 43 | + parent::__construct($model); | ||
| 44 | + } | ||
| 45 | +} |
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | ++----------------------------------------------------------------------------------------------------------------------- | ||
| 4 | + * 重写laravel-admin Auth控制类 | ||
| 5 | ++----------------------------------------------------------------------------------------------------------------------- | ||
| 6 | + * | ||
| 7 | + * @copyright Copyright | ||
| 8 | + * @author Richer | ||
| 9 | + * @package App\Admin\Controllers | ||
| 10 | + * @version 2020年3月23日,14:13:13 | ||
| 11 | + * @link | ||
| 12 | + */ | ||
| 13 | +namespace App\Admin\Controllers\Auth; | ||
| 14 | + | ||
| 15 | +use App\Admin\Controllers\BaseController; | ||
| 16 | +use App\Admin\Forms\Admin\RoleForm; | ||
| 17 | +use App\Admin\Grids\Admin\RoleGrid; | ||
| 18 | +use App\Admin\Rewrite\Controllers\BaseRoleController; | ||
| 19 | +use App\Models\Admin\Role; | ||
| 20 | + | ||
| 21 | +class RoleController extends BaseController | ||
| 22 | +{ | ||
| 23 | + // 使用Grid和Form的trait | ||
| 24 | + use RoleGrid, RoleForm; | ||
| 25 | + | ||
| 26 | + /** | ||
| 27 | + * RoleController constructor. | ||
| 28 | + * | ||
| 29 | + * @param Role $model 注入model | ||
| 30 | + */ | ||
| 31 | + public function __construct(Role $model) | ||
| 32 | + { | ||
| 33 | + // 资源显示的中名称 | ||
| 34 | + $this->title = $model::OBJ_NAME; | ||
| 35 | + // 是否可查看 | ||
| 36 | + $this->can_view = false; | ||
| 37 | + // 是否可新增 | ||
| 38 | + $this->can_create = true; | ||
| 39 | + // 是否可编辑 | ||
| 40 | + $this->can_edit = true; | ||
| 41 | + // 是否可删除 | ||
| 42 | + $this->can_delete = true; | ||
| 43 | + // 执行父类构造方法 | ||
| 44 | + parent::__construct($model); | ||
| 45 | + } | ||
| 46 | +} |
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | ++----------------------------------------------------------------------------------------------------------------------- | ||
| 4 | + * 管理端控制层: 重写 laravel-admin 用户 控制类 | ||
| 5 | ++----------------------------------------------------------------------------------------------------------------------- | ||
| 6 | + * | ||
| 7 | + * PHP version 7 | ||
| 8 | + * | ||
| 9 | + * @category App\Admin\Controllers\Auth | ||
| 10 | + * @package App\Admin\Controllers\Auth | ||
| 11 | + * @author Richer <yangzi1028@163.com> | ||
| 12 | + * @date 2021年11月3日13:56:38 | ||
| 13 | + * @copyright 2020-2022 Richer (http://www.Richer.com/) | ||
| 14 | + * @license http://www.Richer.com/ License | ||
| 15 | + * @link http://www.Richer.com/ | ||
| 16 | + */ | ||
| 17 | +namespace App\Admin\Controllers\Auth; | ||
| 18 | + | ||
| 19 | +use App\Admin\Controllers\BaseController; | ||
| 20 | +use App\Admin\Forms\User\AdminForm; | ||
| 21 | +use App\Admin\Forms\User\UserForm; | ||
| 22 | +use App\Admin\Grids\User\AdminGrid; | ||
| 23 | +use App\Admin\Grids\User\UserGrid; | ||
| 24 | +use App\Models\User\Admin; | ||
| 25 | +use App\Models\User\User; | ||
| 26 | +use Encore\Admin\Form; | ||
| 27 | +use Encore\Admin\Grid; | ||
| 28 | +use Encore\Admin\Show; | ||
| 29 | +use Illuminate\Support\Facades\Hash; | ||
| 30 | + | ||
| 31 | +/** | ||
| 32 | + * Class UserController | ||
| 33 | + * | ||
| 34 | + * @category App\Admin\Controllers\Auth | ||
| 35 | + * @package App\Admin\Controllers\Auth | ||
| 36 | + * @author Richer <yangzi1028@163.com> | ||
| 37 | + * @date 2021年11月3日13:56:38 | ||
| 38 | + * @copyright 2020-2022 Richer (http://www.Richer.com/) | ||
| 39 | + * @license http://www.Richer.com/ License | ||
| 40 | + * @link http://www.Richer.com/ | ||
| 41 | + */ | ||
| 42 | +class UserController extends BaseController | ||
| 43 | +{ | ||
| 44 | + | ||
| 45 | + // 使用Grid和Form的trait | ||
| 46 | + use AdminGrid, AdminForm; | ||
| 47 | + | ||
| 48 | + /** | ||
| 49 | + * UsersController constructor. | ||
| 50 | + * | ||
| 51 | + * @param Admin $model 注入model | ||
| 52 | + */ | ||
| 53 | + public function __construct(Admin $model) | ||
| 54 | + { | ||
| 55 | + // 资源显示的中名称 | ||
| 56 | + $this->title = $model::OBJ_NAME; | ||
| 57 | + // 是否可查看 | ||
| 58 | + $this->can_view = false; | ||
| 59 | + // 是否可新增 | ||
| 60 | + $this->can_create = true; | ||
| 61 | + // 是否可编辑 | ||
| 62 | + $this->can_edit = true; | ||
| 63 | + // 是否可删除 | ||
| 64 | + $this->can_delete = true; | ||
| 65 | + // 是否可导出 | ||
| 66 | + $this->can_export = false; | ||
| 67 | + // 是否列表是否开启row selector | ||
| 68 | + $this->grid_row_selector = false; | ||
| 69 | + // 是否看见回收站 | ||
| 70 | +// $this->show_trashed = true; | ||
| 71 | + // 是否开启下拉菜单 | ||
| 72 | + $this->dropdownActions = false; | ||
| 73 | + | ||
| 74 | + // 执行父类构造方法 | ||
| 75 | + parent::__construct($model); | ||
| 76 | + } | ||
| 77 | +} |
app/Admin/Controllers/AuthController.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Admin\Controllers; | ||
| 4 | + | ||
| 5 | +use Encore\Admin\Controllers\AuthController as BaseAuthController; | ||
| 6 | +use Illuminate\Support\Facades\Validator; | ||
| 7 | + | ||
| 8 | +class AuthController extends BaseAuthController | ||
| 9 | +{ | ||
| 10 | + /** | ||
| 11 | + * Get a validator for an incoming login request. | ||
| 12 | + * | ||
| 13 | + * @param array $data | ||
| 14 | + * | ||
| 15 | + * @return \Illuminate\Contracts\Validation\Validator | ||
| 16 | + */ | ||
| 17 | + protected function loginValidator(array $data) | ||
| 18 | + { | ||
| 19 | + return Validator::make($data, [ | ||
| 20 | + $this->username() => 'required', | ||
| 21 | + 'password' => 'required', | ||
| 22 | +// 'captcha' => 'required|captcha', | ||
| 23 | + ]); | ||
| 24 | + } | ||
| 25 | +} |
app/Admin/Controllers/BaseController.php
0 → 100644
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | ++----------------------------------------------------------------------------------------------------------------------- | ||
| 4 | + * 管理端控制层: 管理端 控制类 基类 | ||
| 5 | + * 控制层:后台控制层基类,提供了对后台对象的增、删、改、查、文件上传、审核等操作 | ||
| 6 | + * 后台所有控制层子类继承该类即可,只需在子类中进行参数的配置 | ||
| 7 | ++----------------------------------------------------------------------------------------------------------------------- | ||
| 8 | + * | ||
| 9 | + * PHP version 7 | ||
| 10 | + * | ||
| 11 | + * @category App\Admin\Controllers\Admin | ||
| 12 | + * @package App\Admin\Controllers\Admin | ||
| 13 | + * @author Richer <yangzi1028@163.com> | ||
| 14 | + * @date 2021年6月23日14:47:37 | ||
| 15 | + * @copyright 2020-2022 Richer (http://www.Richer.com/) | ||
| 16 | + * @license http://www.Richer.com/ License | ||
| 17 | + * @link http://www.Richer.com/ | ||
| 18 | + */ | ||
| 19 | +namespace App\Admin\Controllers; | ||
| 20 | + | ||
| 21 | +use App\Admin\Extensions\Actions\Audit; | ||
| 22 | +use App\Admin\Extensions\Actions\Disable; | ||
| 23 | +use App\Admin\Extensions\Actions\Enable; | ||
| 24 | +use App\Admin\Extensions\Actions\Offline; | ||
| 25 | +use App\Admin\Extensions\Actions\Online; | ||
| 26 | +use App\Admin\Extensions\CustomActions; | ||
| 27 | +use App\Admin\Grids\Filter\AreaFilter; | ||
| 28 | +use App\Admin\Rewrite\Facades\Admin; | ||
| 29 | +use App\Admin\Traits\GridFilterTrait; | ||
| 30 | +use App\Models\System\AuditRecord; | ||
| 31 | +use App\Models\System\OperationLog; | ||
| 32 | +use App\Models\Traits\AdministrativeDivisionTrait; | ||
| 33 | +use App\Models\User\User; | ||
| 34 | +use App\Admin\Rewrite\Grid; | ||
| 35 | +use App\Admin\Rewrite\Form; | ||
| 36 | +//use Encore\Admin\Grid; | ||
| 37 | +//use Encore\Admin\Form; | ||
| 38 | +use App\Admin\Rewrite\Show; | ||
| 39 | +use Encore\Admin\Layout\Content; | ||
| 40 | +use Encore\Admin\Controllers\AdminController; | ||
| 41 | +use App\Admin\Traits\FormFieldTrait; | ||
| 42 | +use App\Admin\Traits\GridFieldTrait; | ||
| 43 | +use App\Admin\Traits\ShowFieldTrait; | ||
| 44 | +use Exception; | ||
| 45 | +use Illuminate\Database\Eloquent\Model; | ||
| 46 | +use Illuminate\Database\Eloquent\ModelNotFoundException; | ||
| 47 | +use Illuminate\Http\JsonResponse; | ||
| 48 | +use Illuminate\Support\Arr; | ||
| 49 | +use Illuminate\Support\Facades\DB; | ||
| 50 | +use Illuminate\Support\Facades\Schema; | ||
| 51 | +use Illuminate\Support\Str; | ||
| 52 | + | ||
| 53 | +/** | ||
| 54 | + * Class BaseController | ||
| 55 | + * | ||
| 56 | + * @category App\Admin\Controllers | ||
| 57 | + * @package App\Admin\Controllers | ||
| 58 | + * @author Richer <yangzi1028@163.com> | ||
| 59 | + * @date 2020年11月13日 01:26:09 | ||
| 60 | + * @copyright 2020-2022 Richer (http://www.Richer.com/) | ||
| 61 | + * @license http://www.Richer.com/ License | ||
| 62 | + * @link http://www.Richer.com/ | ||
| 63 | + */ | ||
| 64 | +class BaseController extends AdminController | ||
| 65 | +{ | ||
| 66 | + use GridFieldTrait, FormFieldTrait, ShowFieldTrait, GridFilterTrait, AreaFilter, AdministrativeDivisionTrait; | ||
| 67 | + | ||
| 68 | + /** | ||
| 69 | + * 模型 | ||
| 70 | + * | ||
| 71 | + * @var Model | ||
| 72 | + */ | ||
| 73 | + protected $model; | ||
| 74 | + | ||
| 75 | + /** | ||
| 76 | + * 用户 | ||
| 77 | + * | ||
| 78 | + * @var User | ||
| 79 | + */ | ||
| 80 | + protected $user = null; | ||
| 81 | + | ||
| 82 | + /** | ||
| 83 | + * 是否可以新增 | ||
| 84 | + * | ||
| 85 | + * @var boolean | ||
| 86 | + */ | ||
| 87 | + protected $can_create = false; | ||
| 88 | + | ||
| 89 | + /** | ||
| 90 | + * 是否可以删除 | ||
| 91 | + * | ||
| 92 | + * @var boolean | ||
| 93 | + */ | ||
| 94 | + protected $can_delete = false; | ||
| 95 | + | ||
| 96 | + /** | ||
| 97 | + * 是否可以编辑 | ||
| 98 | + * | ||
| 99 | + * @var boolean | ||
| 100 | + */ | ||
| 101 | + protected $can_edit = false; | ||
| 102 | + | ||
| 103 | + /** | ||
| 104 | + * 是否可以查看详情 | ||
| 105 | + * | ||
| 106 | + * @var boolean | ||
| 107 | + */ | ||
| 108 | + protected $can_view = false; | ||
| 109 | + | ||
| 110 | + /** | ||
| 111 | + * 是否可以审核 | ||
| 112 | + * | ||
| 113 | + * @var boolean | ||
| 114 | + */ | ||
| 115 | + protected $can_audit = false; | ||
| 116 | + | ||
| 117 | + /** | ||
| 118 | + * 是否可以导出 | ||
| 119 | + * | ||
| 120 | + * @var boolean | ||
| 121 | + */ | ||
| 122 | + protected $can_export = false; | ||
| 123 | + | ||
| 124 | + /** | ||
| 125 | + * 是否可以上架 | ||
| 126 | + * | ||
| 127 | + * @var boolean | ||
| 128 | + */ | ||
| 129 | + protected $can_unshelve = false; | ||
| 130 | + | ||
| 131 | + /** | ||
| 132 | + * 是否可以推荐 | ||
| 133 | + * | ||
| 134 | + * @var boolean | ||
| 135 | + */ | ||
| 136 | + protected $can_recommend = false; | ||
| 137 | + | ||
| 138 | + /** | ||
| 139 | + * 是否可禁用 | ||
| 140 | + * | ||
| 141 | + * @var bool | ||
| 142 | + */ | ||
| 143 | + protected $can_disable = false; | ||
| 144 | + | ||
| 145 | + /** | ||
| 146 | + * 是否展示软删除的回收站 | ||
| 147 | + * | ||
| 148 | + * @var bool | ||
| 149 | + */ | ||
| 150 | + protected $show_trashed = false; | ||
| 151 | + | ||
| 152 | + /** | ||
| 153 | + * 是否可以导入 | ||
| 154 | + * | ||
| 155 | + * @var bool | ||
| 156 | + */ | ||
| 157 | + protected $can_import = false; | ||
| 158 | + | ||
| 159 | + /** | ||
| 160 | + * 列表是否开启row selector | ||
| 161 | + * | ||
| 162 | + * @var bool | ||
| 163 | + */ | ||
| 164 | + protected $grid_row_selector = false; | ||
| 165 | + | ||
| 166 | + /** | ||
| 167 | + * 是否开启列表操作下来菜单形式 | ||
| 168 | + */ | ||
| 169 | + protected $dropdownActions = false; | ||
| 170 | + | ||
| 171 | + | ||
| 172 | + /** | ||
| 173 | + * 资源显示的中名称 | ||
| 174 | + * | ||
| 175 | + * @var string | ||
| 176 | + */ | ||
| 177 | + protected $title; | ||
| 178 | + | ||
| 179 | + /** | ||
| 180 | + * 资源描述 | ||
| 181 | + * | ||
| 182 | + * @var array | ||
| 183 | + */ | ||
| 184 | + protected $description = []; | ||
| 185 | + | ||
| 186 | + /** | ||
| 187 | + * 资源是否有tab标签 | ||
| 188 | + * | ||
| 189 | + * @var string | ||
| 190 | + */ | ||
| 191 | + protected $tab = []; | ||
| 192 | + | ||
| 193 | + /** | ||
| 194 | + * 资源是否有子类,并且子类tab的名称 | ||
| 195 | + * | ||
| 196 | + * @var string | ||
| 197 | + */ | ||
| 198 | + protected $hasMany = []; | ||
| 199 | + | ||
| 200 | + /** | ||
| 201 | + * 当前对象的Grid对象实例 | ||
| 202 | + * | ||
| 203 | + * @var \Encore\Admin\Grid | ||
| 204 | + */ | ||
| 205 | + protected $grid = null; | ||
| 206 | + | ||
| 207 | + /** | ||
| 208 | + * 当前对象的Form对象实例 | ||
| 209 | + * | ||
| 210 | + * @var Form | ||
| 211 | + */ | ||
| 212 | + protected $form = null; | ||
| 213 | + | ||
| 214 | + /** | ||
| 215 | + * 当前对象的Form对象实例 | ||
| 216 | + * | ||
| 217 | + * @var \Encore\Admin\Show | ||
| 218 | + */ | ||
| 219 | + protected $show = null; | ||
| 220 | + | ||
| 221 | + /** | ||
| 222 | + * 执行构造方法 | ||
| 223 | + * BaseController constructor. | ||
| 224 | + * | ||
| 225 | + * @param null $model 模型 | ||
| 226 | + */ | ||
| 227 | + public function __construct($model = null) | ||
| 228 | + { | ||
| 229 | + $this->model = $model; | ||
| 230 | + $this->user = Admin::user(); | ||
| 231 | + } | ||
| 232 | + | ||
| 233 | + /** | ||
| 234 | + * 审核列表 interface. | ||
| 235 | + * | ||
| 236 | + * @param Content $content 内容 | ||
| 237 | + * | ||
| 238 | + * @return Content | ||
| 239 | + */ | ||
| 240 | + public function audit(Content $content) | ||
| 241 | + { | ||
| 242 | + return $content | ||
| 243 | + ->header($this->title.'审核列表') | ||
| 244 | + ->description($this->description) | ||
| 245 | + ->body($this->grid()); | ||
| 246 | + } | ||
| 247 | + | ||
| 248 | + /** | ||
| 249 | + * Edit interface. | ||
| 250 | + * | ||
| 251 | + * @param mixed $id id | ||
| 252 | + * @param Content $content content | ||
| 253 | + * | ||
| 254 | + * @return Content | ||
| 255 | + */ | ||
| 256 | + public function edit($id, Content $content) | ||
| 257 | + { | ||
| 258 | + return $content | ||
| 259 | + ->title($this->title()) | ||
| 260 | + ->description($this->description['edit'] ?? __('edit')) | ||
| 261 | + ->body($this->form($id)->edit($id)); | ||
| 262 | + } | ||
| 263 | + | ||
| 264 | + /** | ||
| 265 | + * 基类方法:渲染生成grid对象 | ||
| 266 | + * | ||
| 267 | + * @return Grid | ||
| 268 | + */ | ||
| 269 | + protected function grid() | ||
| 270 | + { | ||
| 271 | + $this->grid = new Grid($this->model); | ||
| 272 | + | ||
| 273 | + // 设置列表标题 | ||
| 274 | + $this->setGridTitle(); | ||
| 275 | + | ||
| 276 | + // 增加 tab | ||
| 277 | + $this->setGridTab(); | ||
| 278 | + | ||
| 279 | + // 设置默认排序规则 | ||
| 280 | + $this->setGridOrder(); | ||
| 281 | + | ||
| 282 | + // 设置默认查询条件 | ||
| 283 | + $this->setGridQuery(); | ||
| 284 | + | ||
| 285 | + // 渲染表格头筛选条件 | ||
| 286 | + $this->renderGridFilter(); | ||
| 287 | + | ||
| 288 | + // 渲染表格导出 | ||
| 289 | + $this->renderGridExporter(); | ||
| 290 | + | ||
| 291 | + // 渲染字段 | ||
| 292 | + $this->renderGridFields(); | ||
| 293 | + | ||
| 294 | + // 渲染数据操作 action | ||
| 295 | + $this->renderGridActions(); | ||
| 296 | + | ||
| 297 | + // 渲染顶部自定义工具 | ||
| 298 | + $this->renderGridTools(); | ||
| 299 | + | ||
| 300 | + return $this->grid; | ||
| 301 | + } | ||
| 302 | + | ||
| 303 | + /** | ||
| 304 | + * 设置默认排序规则 | ||
| 305 | + * | ||
| 306 | + * @return void $grid grid | ||
| 307 | + */ | ||
| 308 | + public function setGridTitle() | ||
| 309 | + { | ||
| 310 | +// $this->grid->setTitle('admin.'.$this->title); | ||
| 311 | + $this->grid->setTitle($this->title); | ||
| 312 | + } | ||
| 313 | + | ||
| 314 | + /** | ||
| 315 | + * 设置 tab | ||
| 316 | + */ | ||
| 317 | + public function setGridTab() | ||
| 318 | + { | ||
| 319 | + // | ||
| 320 | + } | ||
| 321 | + | ||
| 322 | + /** | ||
| 323 | + * 设置默认排序规则 | ||
| 324 | + * | ||
| 325 | + */ | ||
| 326 | + public function setGridOrder() | ||
| 327 | + { | ||
| 328 | + if (!request('_sort')) { | ||
| 329 | + $this->grid->model()->latest(); | ||
| 330 | + } else { | ||
| 331 | + $this->setGridOrderSpecial(); | ||
| 332 | + } | ||
| 333 | + } | ||
| 334 | + | ||
| 335 | + /** | ||
| 336 | + * 设置特殊的查询规则 | ||
| 337 | + */ | ||
| 338 | + public function setGridOrderSpecial() | ||
| 339 | + { | ||
| 340 | + $_sort = request('_sort'); | ||
| 341 | + $column = Arr::get($_sort, 'column'); | ||
| 342 | + switch ($column) { | ||
| 343 | + case 'name':// 中文排序字段 | ||
| 344 | + case 'title':// 中文排序字段 | ||
| 345 | + $_sort['convert'] = 1; | ||
| 346 | + break; | ||
| 347 | + case 'user.username': | ||
| 348 | + $_sort['column'] = 'mobile'; | ||
| 349 | + break; | ||
| 350 | + case 'gender_show': | ||
| 351 | + $_sort['column'] = 'gender'; | ||
| 352 | + break; | ||
| 353 | + } | ||
| 354 | + request()->offsetSet('_sort', $_sort); | ||
| 355 | + } | ||
| 356 | + | ||
| 357 | + /** | ||
| 358 | + * 设置默认查询条件 | ||
| 359 | + * 增加数据权限的判断。步骤: | ||
| 360 | + * 1、判断用户是否是超级管理员,并判断用户的pid,如果pid为0 则为平台总用户,不进行数据权限的判断 | ||
| 361 | + * 2、如果pid大于0 则为 平台子管理员,则需要进行数据权限的判断 | ||
| 362 | + * | ||
| 363 | + * @return void $grid grid | ||
| 364 | + */ | ||
| 365 | + public function setGridQuery() | ||
| 366 | + { | ||
| 367 | + // add by Richer 于 2021年8月31日16:59:30 回收站 | ||
| 368 | + if (request('trashed') == 1) { | ||
| 369 | + $this->grid->model()->onlyTrashed(); | ||
| 370 | + } | ||
| 371 | + | ||
| 372 | + $this->buildQuery($this->grid->model()); | ||
| 373 | + } | ||
| 374 | + | ||
| 375 | + /** | ||
| 376 | + * 渲染grid字段 | ||
| 377 | + * | ||
| 378 | + * @return void | ||
| 379 | + */ | ||
| 380 | + public function renderGridFields() | ||
| 381 | + { | ||
| 382 | + // | ||
| 383 | + } | ||
| 384 | + | ||
| 385 | + /** | ||
| 386 | + * 为grid增加筛选条件 | ||
| 387 | + * | ||
| 388 | + * @return void | ||
| 389 | + */ | ||
| 390 | + public function renderGridFilter() | ||
| 391 | + { | ||
| 392 | + // | ||
| 393 | + } | ||
| 394 | + | ||
| 395 | + /** | ||
| 396 | + * 为grid增加筛选条件 | ||
| 397 | + * | ||
| 398 | + * @return void | ||
| 399 | + */ | ||
| 400 | + public function renderGridExporter() | ||
| 401 | + { | ||
| 402 | + // | ||
| 403 | + } | ||
| 404 | + | ||
| 405 | + /** | ||
| 406 | + * 为grid的行增加操作按钮 | ||
| 407 | + * | ||
| 408 | + * @param bool $disable 是否可用 | ||
| 409 | + * | ||
| 410 | + * @return void | ||
| 411 | + */ | ||
| 412 | + public function renderGridActions($disable = false) | ||
| 413 | + { | ||
| 414 | + // 设置行操作的样式1.7.3版本以后的操作样式,如果表格字段多或者操作按钮过多可以将按钮进行修改 | ||
| 415 | + $this->setActionClass(); | ||
| 416 | + | ||
| 417 | + // 渲染每行的操作 | ||
| 418 | + $this->setRowActions(); | ||
| 419 | + | ||
| 420 | + // TODO 需要根据数据权限和功能权限来判断 | ||
| 421 | + // 禁用系统的新增按钮 | ||
| 422 | + if (!$this->can_create) { | ||
| 423 | + $this->grid->disableCreateButton(); | ||
| 424 | + } | ||
| 425 | + | ||
| 426 | + // 禁用 导出按钮 | ||
| 427 | + if (!$this->show_trashed) { | ||
| 428 | + $this->grid->disableTrashedButton(); | ||
| 429 | + } | ||
| 430 | + | ||
| 431 | + // 禁用 导入按钮 | ||
| 432 | + if (!$this->can_import) { | ||
| 433 | + $this->grid->disableImportButton(); | ||
| 434 | + } | ||
| 435 | + | ||
| 436 | +// $this->grid->disableTools(); | ||
| 437 | + } | ||
| 438 | + | ||
| 439 | + /** | ||
| 440 | + * 为grid渲染工具 | ||
| 441 | + * | ||
| 442 | + * @return void | ||
| 443 | + */ | ||
| 444 | + public function renderGridTools() | ||
| 445 | + { | ||
| 446 | + $this->grid->tools( | ||
| 447 | + function ($tools) { | ||
| 448 | + //关闭批量删除 | ||
| 449 | + $tools->batch( | ||
| 450 | + function ($batch) { | ||
| 451 | + $batch->disableDelete(); | ||
| 452 | + } | ||
| 453 | + ); | ||
| 454 | + | ||
| 455 | + // 去掉筛选的按钮 | ||
| 456 | + $tools -> disableFilterButton(); | ||
| 457 | + | ||
| 458 | + // 去掉刷新的按钮 | ||
| 459 | + $tools -> disableRefreshButton(); | ||
| 460 | + } | ||
| 461 | + ); | ||
| 462 | + | ||
| 463 | + // 禁用导出数据按钮 | ||
| 464 | + if ($this->can_export === false) { | ||
| 465 | + $this->grid->disableExport(); | ||
| 466 | + } | ||
| 467 | + | ||
| 468 | + //禁用行选择checkbox | ||
| 469 | + if ($this->grid_row_selector === false) { | ||
| 470 | + $this->grid->disableRowSelector(); | ||
| 471 | + } | ||
| 472 | + | ||
| 473 | + // 禁用选择列 | ||
| 474 | +// $this->grid->disableColumnSelector(); | ||
| 475 | + } | ||
| 476 | + | ||
| 477 | + /** | ||
| 478 | + * 设置行操作的样式 | ||
| 479 | + * | ||
| 480 | + * @return void $grid grid | ||
| 481 | + */ | ||
| 482 | + public function setActionClass() | ||
| 483 | + { | ||
| 484 | + // 设置为1.7.3版本以后的操作样式 | ||
| 485 | + if ($this->dropdownActions === true) { | ||
| 486 | + $this->grid->setActionClass(\App\Admin\Rewrite\Grid\Displayers\DropdownActions::class); | ||
| 487 | + } | ||
| 488 | + | ||
| 489 | + // 渲染批量操作按钮 | ||
| 490 | + $this->grid->tools( | ||
| 491 | + function (Grid\Tools $tools) { | ||
| 492 | + // | ||
| 493 | + } | ||
| 494 | + ); | ||
| 495 | + | ||
| 496 | + // 自定义按钮操作 | ||
| 497 | + $this->setCustomActions(); | ||
| 498 | + } | ||
| 499 | + | ||
| 500 | + /** | ||
| 501 | + * 自定义按钮 | ||
| 502 | + */ | ||
| 503 | + public function setCustomActions() | ||
| 504 | + { | ||
| 505 | + // | ||
| 506 | + } | ||
| 507 | + | ||
| 508 | + /** | ||
| 509 | + * 设置每行的操作 | ||
| 510 | + * 根据每个模块设置的权限来判断当前的操作 | ||
| 511 | + * | ||
| 512 | + * @return void $grid grid | ||
| 513 | + */ | ||
| 514 | + protected function setRowActions() | ||
| 515 | + { | ||
| 516 | + // 基本权限 | ||
| 517 | + $can_edit = $this->can_edit; | ||
| 518 | + $can_delete = $this->can_delete; | ||
| 519 | + $can_view = $this->can_view; | ||
| 520 | + $can_audit = $this->can_audit; | ||
| 521 | + $can_unshelve = $this->can_unshelve; | ||
| 522 | + $can_recommend = $this->can_recommend; | ||
| 523 | + $can_disable = $this->can_disable; | ||
| 524 | + $dropdownActions = $this->dropdownActions; | ||
| 525 | + | ||
| 526 | + $self = $this; | ||
| 527 | + | ||
| 528 | + // 对表格的每行数据进行权限的判断和操作按钮的生成 | ||
| 529 | + $this->grid->actions( | ||
| 530 | + function ($actions) use ( | ||
| 531 | + $self, | ||
| 532 | + $can_view, | ||
| 533 | + $can_edit, | ||
| 534 | + $can_delete, | ||
| 535 | + $can_audit, | ||
| 536 | + $can_unshelve, | ||
| 537 | + $can_recommend, | ||
| 538 | + $can_disable, | ||
| 539 | + $dropdownActions | ||
| 540 | + ) { | ||
| 541 | + | ||
| 542 | + // 当前数据的主键 | ||
| 543 | + $id = $actions->getKey(); | ||
| 544 | + // 当前的url | ||
| 545 | + $url = $actions->getResource(); | ||
| 546 | + | ||
| 547 | + // 禁用系统相关按钮 | ||
| 548 | + $actions->disableView(); | ||
| 549 | + // 查看按钮 | ||
| 550 | + if ($can_view === true) { | ||
| 551 | + if ($dropdownActions === false) { | ||
| 552 | + $actions -> disableView(); | ||
| 553 | + $actions->append(CustomActions::renderView($id, $url)); | ||
| 554 | + } | ||
| 555 | + } | ||
| 556 | + | ||
| 557 | + // 编辑按钮 | ||
| 558 | + $actions -> disableEdit(); | ||
| 559 | + if ($can_edit === true) { | ||
| 560 | + if ($dropdownActions === false) { | ||
| 561 | + $actions->append(CustomActions::renderEdit($id, $url)); | ||
| 562 | + } | ||
| 563 | + } | ||
| 564 | + | ||
| 565 | + // 删除按钮 | ||
| 566 | + $actions -> disableDelete(); | ||
| 567 | + if ($can_delete === true) { | ||
| 568 | + if ($dropdownActions === false) { | ||
| 569 | + $actions->append(CustomActions::renderDelete($id, $url)); | ||
| 570 | + } | ||
| 571 | + } | ||
| 572 | + | ||
| 573 | + // 可审核 | ||
| 574 | + if ($can_audit && $actions->row->audited_status == config('constants.UNAUDITED')) { | ||
| 575 | + if ($dropdownActions === true) { | ||
| 576 | + $actions->add(new Audit()); | ||
| 577 | + } else { | ||
| 578 | + $actions->append(CustomActions::renderAudit($id, $url)); | ||
| 579 | + } | ||
| 580 | + } | ||
| 581 | + | ||
| 582 | + // 可上下架 | ||
| 583 | + if ($can_unshelve) { | ||
| 584 | + // 下架按钮 | ||
| 585 | + if ($actions->row->unshelved_status == config('constants.SHELVED')) { | ||
| 586 | + if ($dropdownActions === true) { | ||
| 587 | + $actions->add(new Offline()); | ||
| 588 | + } else { | ||
| 589 | + // | ||
| 590 | + $actions->append(CustomActions::renderUnshelvedBtn($id, $url)); | ||
| 591 | + } | ||
| 592 | + } | ||
| 593 | + | ||
| 594 | + if ($actions->row->unshelved_status == config('constants.UNSHELVED')) { | ||
| 595 | + // 上架按钮 | ||
| 596 | + if ($dropdownActions === true) { | ||
| 597 | + $actions->add(new Online()); | ||
| 598 | + } else { | ||
| 599 | + $actions->append(CustomActions::renderShelvedBtn($id, $url)); | ||
| 600 | + } | ||
| 601 | + } | ||
| 602 | + } | ||
| 603 | + | ||
| 604 | + // 可取消 | ||
| 605 | + if ($can_recommend) { | ||
| 606 | + // 下架按钮 | ||
| 607 | + if ($actions->row->recommended_status == config('constants.UN_RECOMMENDED')) { | ||
| 608 | + if ($dropdownActions === true) { | ||
| 609 | + // $actions->add(new Offline()); | ||
| 610 | + } else { | ||
| 611 | + // | ||
| 612 | + $actions->append(CustomActions::renderRecommendBtn($id, $url)); | ||
| 613 | + } | ||
| 614 | + } | ||
| 615 | + | ||
| 616 | + if ($actions->row->recommended_status == config('constants.RECOMMENDED')) { | ||
| 617 | + // 上架按钮 | ||
| 618 | + if ($dropdownActions === true) { | ||
| 619 | + // $actions->add(new Online()); | ||
| 620 | + } else { | ||
| 621 | + $actions->append(CustomActions::renderUnRecommendBtn($id, $url)); | ||
| 622 | + } | ||
| 623 | + } | ||
| 624 | + } | ||
| 625 | + | ||
| 626 | + // 可禁用 | ||
| 627 | + if ($can_disable && request('trashed') != 1) { | ||
| 628 | + if ($actions->row->status == config('constants.ENABLE')) { | ||
| 629 | + if ($dropdownActions === true) { | ||
| 630 | + $actions->add(new Disable()); | ||
| 631 | + } else { | ||
| 632 | + $actions->append(CustomActions::renderDisable($id, $url)); | ||
| 633 | + } | ||
| 634 | + } else { | ||
| 635 | + if ($dropdownActions === true) { | ||
| 636 | + $actions->add(new Enable()); | ||
| 637 | + } else { | ||
| 638 | + $actions->append(CustomActions::renderEnable($id, $url)); | ||
| 639 | + } | ||
| 640 | + } | ||
| 641 | + } | ||
| 642 | + | ||
| 643 | + // add by Richer 于 2021年8月31日17:11:06 软删除恢复 | ||
| 644 | + if (request('trashed') == 1) { | ||
| 645 | + $actions->append(CustomActions::renderRestore($id, $url)); | ||
| 646 | + } | ||
| 647 | + | ||
| 648 | + // 自定义按钮操作 | ||
| 649 | + $self->setRowCustomActions($actions); | ||
| 650 | + } | ||
| 651 | + ); | ||
| 652 | + } | ||
| 653 | + | ||
| 654 | + /** | ||
| 655 | + * 自定义每行的操作 | ||
| 656 | + * 根据每个模块设置的权限来判断当前的操作 | ||
| 657 | + * | ||
| 658 | + * @param $actions | ||
| 659 | + * @return void $grid grid | ||
| 660 | + */ | ||
| 661 | + public function setRowCustomActions($actions) | ||
| 662 | + { | ||
| 663 | + // | ||
| 664 | + } | ||
| 665 | + | ||
| 666 | + /** | ||
| 667 | + * 外部href | ||
| 668 | + * | ||
| 669 | + * @return string | ||
| 670 | + */ | ||
| 671 | + public function href() | ||
| 672 | + { | ||
| 673 | + // 获取列表的路径 | ||
| 674 | + $path = request()->getUri(); | ||
| 675 | + $url = \Arr::first(explode('?', $path)); | ||
| 676 | + $param = \Arr::last(explode('?', $path)); | ||
| 677 | + | ||
| 678 | + if ($param) { | ||
| 679 | + // | ||
| 680 | + } | ||
| 681 | + $edit_path = $url.'/edit?'.$param; | ||
| 682 | + // 创建审核的提交数据 | ||
| 683 | + $pjax_url = $path; | ||
| 684 | + | ||
| 685 | + return $pjax_url; | ||
| 686 | + } | ||
| 687 | + | ||
| 688 | + /** | ||
| 689 | + * 基类方法渲染生成form对象 | ||
| 690 | + * | ||
| 691 | + * @param Int $id 用户id | ||
| 692 | + * | ||
| 693 | + * @return Form | ||
| 694 | + */ | ||
| 695 | + protected function form($id = null) | ||
| 696 | + { | ||
| 697 | + // 实例form对象 | ||
| 698 | + $this->form = new Form($this->model); | ||
| 699 | + // 渲染自定义工具 | ||
| 700 | + $this->renderFormTools(); | ||
| 701 | + // 渲染 form 字段 | ||
| 702 | + $this->renderFormFields($id); | ||
| 703 | + // 在表单提交前调用,对表单进行处理 | ||
| 704 | + $this->submitted(); | ||
| 705 | + // 保存前回调 | ||
| 706 | + $this->saving(); | ||
| 707 | + // 保存后回调 | ||
| 708 | + $this->saved(); | ||
| 709 | + | ||
| 710 | + return $this->form; | ||
| 711 | + } | ||
| 712 | + | ||
| 713 | + /** | ||
| 714 | + * 为grid渲染工具 | ||
| 715 | + * | ||
| 716 | + * @return void | ||
| 717 | + */ | ||
| 718 | + public function renderFormTools() | ||
| 719 | + { | ||
| 720 | + // if ($this->form->isCreating()) { | ||
| 721 | + // dump(1); | ||
| 722 | + // $this->form->tools(function(Form\Tools $tools) use ($this->form) { | ||
| 723 | + | ||
| 724 | + // }); | ||
| 725 | + // } | ||
| 726 | + } | ||
| 727 | + | ||
| 728 | + /** | ||
| 729 | + * 渲染表单字段 | ||
| 730 | + * | ||
| 731 | + * @param Int $id 用户id | ||
| 732 | + * | ||
| 733 | + * @return void | ||
| 734 | + */ | ||
| 735 | + public function renderFormFields($id) | ||
| 736 | + { | ||
| 737 | + // 判断当前的form表单是否有tab | ||
| 738 | + $tabs = $this->tab; | ||
| 739 | + | ||
| 740 | + $column = 1;//当前form表单显示的列数 | ||
| 741 | + | ||
| 742 | + switch (count($tabs)) { | ||
| 743 | + case 1: | ||
| 744 | + $this->form->tab( | ||
| 745 | + $tabs[0]['comment'], | ||
| 746 | + function ($form) use ($id, $column) { | ||
| 747 | + // 为form设置通用字段 | ||
| 748 | + $this -> setTab1FormCommonFields($form, $id, $column); | ||
| 749 | + } | ||
| 750 | + ); | ||
| 751 | + break; | ||
| 752 | + case 2: | ||
| 753 | + $this->form->tab( | ||
| 754 | + $tabs[0]['comment'], | ||
| 755 | + function ($form) use ($id, $column) { | ||
| 756 | + // 为form设置通用字段 | ||
| 757 | + $this -> setTab1FormCommonFields($form, $id, $column); | ||
| 758 | + } | ||
| 759 | + )->tab( | ||
| 760 | + $tabs[1]['comment'], | ||
| 761 | + function ($form) use ($id) { | ||
| 762 | + // 设置子类信息;设置第二个tab的form | ||
| 763 | + $this -> setTab2FormCommonFields($form, $id); | ||
| 764 | + } | ||
| 765 | + ); | ||
| 766 | + break; | ||
| 767 | + case 3: | ||
| 768 | + $this->form->tab( | ||
| 769 | + $tabs[0]['comment'], | ||
| 770 | + function ($form) use ($id, $column) { | ||
| 771 | + // 为form设置通用字段 | ||
| 772 | + $this->setTab1FormCommonFields($form, $id, $column); | ||
| 773 | + } | ||
| 774 | + )->tab( | ||
| 775 | + $tabs[1]['comment'], | ||
| 776 | + function ($form) use ($id) { | ||
| 777 | + // 设置子类信息;设置第二个tab的form | ||
| 778 | + $this->setTab2FormCommonFields($form, $id); | ||
| 779 | + } | ||
| 780 | + )->tab( | ||
| 781 | + $tabs[2]['comment'], | ||
| 782 | + function ($form) use ($id) { | ||
| 783 | + // 设置子类信息;设置第二个tab的form | ||
| 784 | + $this->setTab3FormCommonFields($form, $id); | ||
| 785 | + } | ||
| 786 | + ); | ||
| 787 | + break; | ||
| 788 | + case 4: | ||
| 789 | + $this->form->tab( | ||
| 790 | + $tabs[0]['comment'], | ||
| 791 | + function ($form) use ($id, $column) { | ||
| 792 | + // 为form设置通用字段 | ||
| 793 | + $this->setTab1FormCommonFields($form, $id, $column); | ||
| 794 | + } | ||
| 795 | + )->tab( | ||
| 796 | + $tabs[1]['comment'], | ||
| 797 | + function ($form) use ($id) { | ||
| 798 | + // 设置子类信息;设置第二个tab的form | ||
| 799 | + $this->setTab2FormCommonFields($form, $id); | ||
| 800 | + } | ||
| 801 | + )->tab( | ||
| 802 | + $tabs[2]['comment'], | ||
| 803 | + function ($form) use ($id) { | ||
| 804 | + // 设置子类信息;设置第二个tab的form | ||
| 805 | + $this->setTab3FormCommonFields($form, $id); | ||
| 806 | + } | ||
| 807 | + )->tab( | ||
| 808 | + $tabs[3]['comment'], | ||
| 809 | + function ($form) use ($id) { | ||
| 810 | + // 设置子类信息;设置第二个tab的form | ||
| 811 | + $this->setTab4FormCommonFields($form, $id); | ||
| 812 | + } | ||
| 813 | + ); | ||
| 814 | + break; | ||
| 815 | + | ||
| 816 | + default: | ||
| 817 | + // 为form设置通用字段 | ||
| 818 | + $this->setTab1FormCommonFields($this->form, $id, $column); | ||
| 819 | + break; | ||
| 820 | + } | ||
| 821 | + } | ||
| 822 | + | ||
| 823 | + /** | ||
| 824 | + * 基类方法:为form表单设置通用字段 | ||
| 825 | + * | ||
| 826 | + * @param Form $form form | ||
| 827 | + * @param integer $id 用户id | ||
| 828 | + * @param integer $column form表单显示几列 | ||
| 829 | + * | ||
| 830 | + * @return void | ||
| 831 | + */ | ||
| 832 | + protected function setTab1FormCommonFields($form, $id, $column = 2) | ||
| 833 | + { | ||
| 834 | + // 设置专用字段 | ||
| 835 | + $this -> setTab1FormSpecialFields($form, $id); | ||
| 836 | + } | ||
| 837 | + | ||
| 838 | + /** | ||
| 839 | + * 基类方法:为form表单设置专用特殊字段 | ||
| 840 | + * | ||
| 841 | + * @param Form $form form | ||
| 842 | + * @param integer $id 用户id | ||
| 843 | + * | ||
| 844 | + * @return void | ||
| 845 | + */ | ||
| 846 | + public function setTab1FormSpecialFields($form, $id) | ||
| 847 | + { | ||
| 848 | + // | ||
| 849 | + } | ||
| 850 | + | ||
| 851 | + /** | ||
| 852 | + * 设置第二个tab的form字段 | ||
| 853 | + * | ||
| 854 | + * @param Form $form form | ||
| 855 | + * @param integer $id 用户id | ||
| 856 | + * | ||
| 857 | + * @return void | ||
| 858 | + */ | ||
| 859 | + public function setTab2FormCommonFields($form, $id) | ||
| 860 | + { | ||
| 861 | + // 设置每个子类的特殊字段 | ||
| 862 | + $this -> setTab2FormSpecialFields($form, $id); | ||
| 863 | + } | ||
| 864 | + | ||
| 865 | + /** | ||
| 866 | + * 基类方法:为form表单第二个tab设置专用特殊字段 | ||
| 867 | + * | ||
| 868 | + * @param Form $form form | ||
| 869 | + * @param integer $id 用户id | ||
| 870 | + * | ||
| 871 | + * @return void | ||
| 872 | + */ | ||
| 873 | + public function setTab2FormSpecialFields($form, $id) | ||
| 874 | + { | ||
| 875 | + // | ||
| 876 | + } | ||
| 877 | + | ||
| 878 | + /** | ||
| 879 | + * 设置第二个tab的form字段 | ||
| 880 | + * | ||
| 881 | + * @param Form $form form | ||
| 882 | + * @param integer $id 用户id | ||
| 883 | + * | ||
| 884 | + * @return void | ||
| 885 | + */ | ||
| 886 | + public function setTab3FormCommonFields($form, $id) | ||
| 887 | + { | ||
| 888 | + // 设置每个子类的特殊字段 | ||
| 889 | + $this -> setTab3FormSpecialFields($form, $id); | ||
| 890 | + } | ||
| 891 | + | ||
| 892 | + /** | ||
| 893 | + * 基类方法:为form表单第二个tab设置专用特殊字段 | ||
| 894 | + * | ||
| 895 | + * @param Form $form form | ||
| 896 | + * @param integer $id 用户id | ||
| 897 | + * | ||
| 898 | + * @return void | ||
| 899 | + */ | ||
| 900 | + public function setTab3FormSpecialFields($form, $id) | ||
| 901 | + { | ||
| 902 | + // | ||
| 903 | + } | ||
| 904 | + | ||
| 905 | + /** | ||
| 906 | + * 设置第4个tab的form字段 | ||
| 907 | + * | ||
| 908 | + * @param Form $form form | ||
| 909 | + * @param integer $id 用户id | ||
| 910 | + * | ||
| 911 | + * @return void | ||
| 912 | + */ | ||
| 913 | + public function setTab4FormCommonFields($form, $id) | ||
| 914 | + { | ||
| 915 | + // 设置每个子类的特殊字段 | ||
| 916 | + $this -> setTab4FormSpecialFields($form, $id); | ||
| 917 | + } | ||
| 918 | + | ||
| 919 | + /** | ||
| 920 | + * 设置第4tab的form字段 | ||
| 921 | + * | ||
| 922 | + * @param Form $form form | ||
| 923 | + * @param integer $id 用户id | ||
| 924 | + * | ||
| 925 | + * @return void | ||
| 926 | + */ | ||
| 927 | + public function setTab4FormSpecialFields($form, $id) | ||
| 928 | + { | ||
| 929 | + // | ||
| 930 | + } | ||
| 931 | + | ||
| 932 | + /** | ||
| 933 | + * 在表单提交前调用 | ||
| 934 | + * | ||
| 935 | + * @return void | ||
| 936 | + */ | ||
| 937 | + protected function submitted() | ||
| 938 | + { | ||
| 939 | + $this->form->submitted( | ||
| 940 | + function (Form $form) { | ||
| 941 | + //... | ||
| 942 | + } | ||
| 943 | + ); | ||
| 944 | + } | ||
| 945 | + | ||
| 946 | + /** | ||
| 947 | + * 保存前回调 | ||
| 948 | + * | ||
| 949 | + * @return void | ||
| 950 | + */ | ||
| 951 | + protected function saving() | ||
| 952 | + { | ||
| 953 | + //保存前回调 | ||
| 954 | + $this->form->saving( | ||
| 955 | + function (Form $form) { | ||
| 956 | + | ||
| 957 | + // 只有后台新增的数据才设置,更新的时候不进行设置 | ||
| 958 | + // 获取操作 | ||
| 959 | + $actions = request()->route()->getAction(); | ||
| 960 | + | ||
| 961 | + $table = $this->model->getTable(); | ||
| 962 | + | ||
| 963 | + // 如果是以@store结尾则为新增操作 | ||
| 964 | + if (Str::endsWith($actions['uses'], '@store')) { | ||
| 965 | + $user = Admin::user(); | ||
| 966 | + $table = $this->model->getTable(); | ||
| 967 | + // 设置用户ID | ||
| 968 | + if (Schema::hasColumn($table, 'admin_id')) { | ||
| 969 | + // 隐藏域的值:默认创建时当前登录用户创建 | ||
| 970 | + $form->model()->setAttribute('admin_id', $user->id); | ||
| 971 | + } | ||
| 972 | + | ||
| 973 | + // 设置店铺ID | ||
| 974 | + if (Schema::hasColumn($table, 'shop_id')) { | ||
| 975 | + // 隐藏域的值:默认创建时当前登录用户创建 | ||
| 976 | + // $form->model()->setAttribute('shop_id', $user->shop_id); | ||
| 977 | + } | ||
| 978 | + | ||
| 979 | + if (Schema::hasColumn($table, 'user_model')) { | ||
| 980 | + // 如果没有用户,默认设置为当前操作的用户 | ||
| 981 | + $form->model()->setAttribute('user_model', 'admin'); | ||
| 982 | + } | ||
| 983 | + | ||
| 984 | + if (Schema::hasColumn($table, 'created_by')) { | ||
| 985 | + // 隐藏域的值:默认创建时当前登录用户创建 | ||
| 986 | + $form->model()->setAttribute('created_by', Admin::user()->id); | ||
| 987 | + } | ||
| 988 | + | ||
| 989 | + if (Schema::hasColumn($table, 'created_model')) { | ||
| 990 | + // 如果没有用户,默认设置为当前操作的用户 | ||
| 991 | + $form->model()->setAttribute('created_model', 'admin'); | ||
| 992 | + } | ||
| 993 | + } else { | ||
| 994 | + if (Schema::hasColumn($table, 'updated_by')) { | ||
| 995 | + // 隐藏域的值:默认创建时当前登录用户创建 | ||
| 996 | + $form->model()->setAttribute('updated_by', Admin::user()->id); | ||
| 997 | + } | ||
| 998 | + | ||
| 999 | + if (Schema::hasColumn($table, 'updated_model')) { | ||
| 1000 | + // 如果没有用户,默认设置为当前操作的用户 | ||
| 1001 | + $form->model()->setAttribute('updated_model', 'admin'); | ||
| 1002 | + } | ||
| 1003 | + } | ||
| 1004 | + } | ||
| 1005 | + ); | ||
| 1006 | + } | ||
| 1007 | + | ||
| 1008 | + /** | ||
| 1009 | + * 保存后回调 | ||
| 1010 | + * | ||
| 1011 | + * @return void | ||
| 1012 | + */ | ||
| 1013 | + protected function saved() | ||
| 1014 | + { | ||
| 1015 | + // 保存后回调 | ||
| 1016 | + $this->form->saved(function (Form $form) { | ||
| 1017 | + //... | ||
| 1018 | + }); | ||
| 1019 | + } | ||
| 1020 | + | ||
| 1021 | + /** | ||
| 1022 | + * 基类方法:渲染生成show | ||
| 1023 | + * | ||
| 1024 | + * @param Int $id 用户id | ||
| 1025 | + * | ||
| 1026 | + * @return Show | ||
| 1027 | + */ | ||
| 1028 | + protected function detail($id) | ||
| 1029 | + { | ||
| 1030 | + // 根据主键和模型实例化show对象 | ||
| 1031 | + $this ->show = new Show($this ->model->find($id)); | ||
| 1032 | + | ||
| 1033 | + // 渲染自定义工具 | ||
| 1034 | + $this->renderShowTools(); | ||
| 1035 | + // 渲染 Show 字段 | ||
| 1036 | + $this->renderShowFields(); | ||
| 1037 | + | ||
| 1038 | + return $this->show; | ||
| 1039 | + } | ||
| 1040 | + | ||
| 1041 | + /** | ||
| 1042 | + * 为详情show渲染工具 | ||
| 1043 | + * | ||
| 1044 | + * @return void | ||
| 1045 | + */ | ||
| 1046 | + protected function renderShowTools() | ||
| 1047 | + { | ||
| 1048 | + // 设置页面左上角的标题和右上角的工具栏 | ||
| 1049 | + $this->show->panel()->style('')->title(__($this->title). ' ' . __('detail'))->tools( | ||
| 1050 | + function ($tools) { | ||
| 1051 | + // TODO 需要根据权限来判断 ===== | ||
| 1052 | + $tools->disableEdit();// 禁用编辑按钮 | ||
| 1053 | + | ||
| 1054 | + $tools->disableDelete();// 禁用删除按钮 | ||
| 1055 | + } | ||
| 1056 | + ); | ||
| 1057 | + } | ||
| 1058 | + | ||
| 1059 | + /** | ||
| 1060 | + * 为详情show渲染字段 | ||
| 1061 | + * | ||
| 1062 | + * @return void | ||
| 1063 | + */ | ||
| 1064 | + protected function renderShowFields() | ||
| 1065 | + { | ||
| 1066 | + // | ||
| 1067 | + } | ||
| 1068 | + | ||
| 1069 | + /** | ||
| 1070 | + * 置顶 推荐 | ||
| 1071 | + * | ||
| 1072 | + * @param Int $id 用户id | ||
| 1073 | + * | ||
| 1074 | + * @return JsonResponse | ||
| 1075 | + */ | ||
| 1076 | + public function recommend($id) | ||
| 1077 | + { | ||
| 1078 | + try { | ||
| 1079 | + // 获取数据,如果没有获取到抛出异常 | ||
| 1080 | + $model = $this->model->findOrFail($id); | ||
| 1081 | + $model->recommended_status = config('constants.RECOMMENDED'); | ||
| 1082 | + $model->recommended_at = date('Y-m-d H:i:s'); | ||
| 1083 | + $model->recommended_by = $this->getUser()->id; | ||
| 1084 | + $result = $model->save(); | ||
| 1085 | + // 判断操作结果 | ||
| 1086 | + if ($result) { | ||
| 1087 | + return response()->json( | ||
| 1088 | + [ | ||
| 1089 | + 'code' => 0, | ||
| 1090 | + 'status' => 1, | ||
| 1091 | + 'message' => __('set_recommend_succeeded'), | ||
| 1092 | + ] | ||
| 1093 | + ); | ||
| 1094 | + } else { | ||
| 1095 | + return response()->json( | ||
| 1096 | + [ | ||
| 1097 | + 'status' => 0, | ||
| 1098 | + 'message' => __('set_recommend_failed'), | ||
| 1099 | + ] | ||
| 1100 | + ); | ||
| 1101 | + } | ||
| 1102 | + } catch (ModelNotFoundException $e) { | ||
| 1103 | + return response()->json( | ||
| 1104 | + [ | ||
| 1105 | + 'status' => 0, | ||
| 1106 | + 'message' => __('no_data'), | ||
| 1107 | + ] | ||
| 1108 | + ); | ||
| 1109 | + } | ||
| 1110 | + } | ||
| 1111 | + | ||
| 1112 | + /** | ||
| 1113 | + * 取消推荐 | ||
| 1114 | + * | ||
| 1115 | + * @param Int $id 用户id | ||
| 1116 | + * | ||
| 1117 | + * @return JsonResponse | ||
| 1118 | + */ | ||
| 1119 | + public function unRecommend($id) | ||
| 1120 | + { | ||
| 1121 | + try { | ||
| 1122 | + // 获取数据,如果没有获取到抛出异常 | ||
| 1123 | + $model = $this->model->findOrFail($id); | ||
| 1124 | + $model->recommended_status = config('constants.UN_RECOMMENDED'); | ||
| 1125 | + $model->recommended_at = null; | ||
| 1126 | + $model->recommended_by = 0; | ||
| 1127 | + $result = $model->save(); | ||
| 1128 | + | ||
| 1129 | + // 判断操作结果 | ||
| 1130 | + if ($result) { | ||
| 1131 | + return response()->json( | ||
| 1132 | + [ | ||
| 1133 | + 'code' => 0, | ||
| 1134 | + 'status' => 1, | ||
| 1135 | + 'message' => __('cancel_recommend_succeeded'), | ||
| 1136 | + ] | ||
| 1137 | + ); | ||
| 1138 | + } else { | ||
| 1139 | + return response()->json( | ||
| 1140 | + [ | ||
| 1141 | + 'code' => 1, | ||
| 1142 | + 'status' => 0, | ||
| 1143 | + 'message' => __('cancel_recommend_failed'), | ||
| 1144 | + ] | ||
| 1145 | + ); | ||
| 1146 | + } | ||
| 1147 | + } catch (ModelNotFoundException $e) { | ||
| 1148 | + return response()->json( | ||
| 1149 | + [ | ||
| 1150 | + 'status' => 0, | ||
| 1151 | + 'message' => __('no_data'), | ||
| 1152 | + ] | ||
| 1153 | + ); | ||
| 1154 | + } | ||
| 1155 | + } | ||
| 1156 | + | ||
| 1157 | + /** | ||
| 1158 | + * 下架 | ||
| 1159 | + * update by Richer 于 2020年3月31日16:34:49 业务逻辑修改 | ||
| 1160 | + * 下架的资源需要将公共库的数据删除 | ||
| 1161 | + * | ||
| 1162 | + * @param Int $id 用户id | ||
| 1163 | + * | ||
| 1164 | + * @return JsonResponse | ||
| 1165 | + */ | ||
| 1166 | + public function unshelve($id) | ||
| 1167 | + { | ||
| 1168 | + try { | ||
| 1169 | + $user = $this->getUser(); | ||
| 1170 | + | ||
| 1171 | + // 获取数据,如果没有获取到抛出异常 | ||
| 1172 | + $model = $this->model->findOrFail($id); | ||
| 1173 | + $model->unshelved_status = 1; | ||
| 1174 | + $model->unshelved_opinion = request('unshelved_opinion'); | ||
| 1175 | + $model->unshelved_at = date('Y-m-d H:i:s'); | ||
| 1176 | + $model->unshelved_by = $user->id; | ||
| 1177 | + $result = $model->save(); | ||
| 1178 | + | ||
| 1179 | + // 判断操作结果 | ||
| 1180 | + if ($result) { | ||
| 1181 | +// // 操作成功后记录操作日志 | ||
| 1182 | +// $model->operationLogs()->create([ | ||
| 1183 | +// 'user_id' => $user->id, | ||
| 1184 | +// 'user_type' => 'admin', | ||
| 1185 | +// 'type' => OperationLog::UNSHELVE, | ||
| 1186 | +// 'path' => request()->path(), | ||
| 1187 | +// 'method' => request()->method(), | ||
| 1188 | +// 'ip' => request()->ip(), | ||
| 1189 | +// 'input' => request()->all(), | ||
| 1190 | +// ]); | ||
| 1191 | + | ||
| 1192 | + return response()->json( | ||
| 1193 | + [ | ||
| 1194 | + 'status' => 1, | ||
| 1195 | + 'message' => __('unshelved_succeeded'), | ||
| 1196 | + ] | ||
| 1197 | + ); | ||
| 1198 | + } else { | ||
| 1199 | + return response()->json( | ||
| 1200 | + [ | ||
| 1201 | + 'status' => 0, | ||
| 1202 | + 'message' => __('unshelved_failed'), | ||
| 1203 | + ] | ||
| 1204 | + ); | ||
| 1205 | + } | ||
| 1206 | + } catch (ModelNotFoundException $e) { | ||
| 1207 | + return response()->json( | ||
| 1208 | + [ | ||
| 1209 | + 'status' => 0, | ||
| 1210 | + 'message' => __('no_data'), | ||
| 1211 | + ] | ||
| 1212 | + ); | ||
| 1213 | + } | ||
| 1214 | + } | ||
| 1215 | + | ||
| 1216 | + /** | ||
| 1217 | + * 上架 | ||
| 1218 | + * | ||
| 1219 | + * @param Int $id 用户id | ||
| 1220 | + * | ||
| 1221 | + * @return JsonResponse | ||
| 1222 | + */ | ||
| 1223 | + public function shelve($id) | ||
| 1224 | + { | ||
| 1225 | + try { | ||
| 1226 | + $user = $this->getUser(); | ||
| 1227 | + | ||
| 1228 | + // 获取数据,如果没有获取到抛出异常 | ||
| 1229 | + $model = $this->model->findOrFail($id); | ||
| 1230 | + $model->unshelved_status = config('constants.SHELVED'); | ||
| 1231 | + $model->unshelved_opinion= ''; | ||
| 1232 | + $model->unshelved_at = null; | ||
| 1233 | + $model->unshelved_by = 0; | ||
| 1234 | + $result = $model->save(); | ||
| 1235 | + // 判断操作结果 | ||
| 1236 | + if ($result) { | ||
| 1237 | + // 通知用户已经上架 | ||
| 1238 | +// User::find($object->user_id)->notify(new \App\Notifications\Online($object)); | ||
| 1239 | + | ||
| 1240 | + // 操作成功后记录操作日志 | ||
| 1241 | +// $model->operationLogs()->create([ | ||
| 1242 | +// 'user_id' => $user->id, | ||
| 1243 | +// 'user_type' => 'admin', | ||
| 1244 | +// 'type' => OperationLog::SHELVE, | ||
| 1245 | +// 'path' => request()->path(), | ||
| 1246 | +// 'method' => request()->method(), | ||
| 1247 | +// 'ip' => request()->ip(), | ||
| 1248 | +// 'input' => request()->all(), | ||
| 1249 | +// ]); | ||
| 1250 | + | ||
| 1251 | + return response()->json( | ||
| 1252 | + [ | ||
| 1253 | + 'status' => 1, | ||
| 1254 | + 'message' => __('shelved_succeeded'), | ||
| 1255 | + ] | ||
| 1256 | + ); | ||
| 1257 | + } else { | ||
| 1258 | + return response()->json( | ||
| 1259 | + [ | ||
| 1260 | + 'status' => 0, | ||
| 1261 | + 'message' => __('shelved_failed'), | ||
| 1262 | + ] | ||
| 1263 | + ); | ||
| 1264 | + } | ||
| 1265 | + } catch (ModelNotFoundException $e) { | ||
| 1266 | + return response()->json( | ||
| 1267 | + [ | ||
| 1268 | + 'status' => 0, | ||
| 1269 | + 'message' => __('no_data'), | ||
| 1270 | + ] | ||
| 1271 | + ); | ||
| 1272 | + } | ||
| 1273 | + } | ||
| 1274 | + | ||
| 1275 | + /** | ||
| 1276 | + * 禁用 | ||
| 1277 | + * | ||
| 1278 | + * @param Int $id id | ||
| 1279 | + * | ||
| 1280 | + * @return JsonResponse | ||
| 1281 | + */ | ||
| 1282 | + public function disable($id) | ||
| 1283 | + { | ||
| 1284 | + try { | ||
| 1285 | + // 获取数据,如果没有获取到抛出异常 | ||
| 1286 | + $model = $this->model->findOrFail($id); | ||
| 1287 | + $model->status = config('constants.DISABLE'); | ||
| 1288 | + $result = $model->save(); | ||
| 1289 | + // 判断操作结果 | ||
| 1290 | + // 判断操作结果 | ||
| 1291 | + if ($result) { | ||
| 1292 | + return response()->json( | ||
| 1293 | + [ | ||
| 1294 | + 'status' => 1, | ||
| 1295 | + 'message' => __('disable_succeeded'), | ||
| 1296 | + ] | ||
| 1297 | + ); | ||
| 1298 | + } else { | ||
| 1299 | + return response()->json( | ||
| 1300 | + [ | ||
| 1301 | + 'status' => 0, | ||
| 1302 | + 'message' => __('disable_failed'), | ||
| 1303 | + ] | ||
| 1304 | + ); | ||
| 1305 | + } | ||
| 1306 | + } catch (ModelNotFoundException $e) { | ||
| 1307 | + return response()->json( | ||
| 1308 | + [ | ||
| 1309 | + 'status' => 0, | ||
| 1310 | + 'message' => __('no_data'), | ||
| 1311 | + ] | ||
| 1312 | + ); | ||
| 1313 | + } | ||
| 1314 | + } | ||
| 1315 | + | ||
| 1316 | + /** | ||
| 1317 | + * 启用 | ||
| 1318 | + * | ||
| 1319 | + * @param Int $id 用户id | ||
| 1320 | + * | ||
| 1321 | + * @return JsonResponse | ||
| 1322 | + */ | ||
| 1323 | + public function enable($id) | ||
| 1324 | + { | ||
| 1325 | + try { | ||
| 1326 | + // 获取数据,如果没有获取到抛出异常 | ||
| 1327 | + $model = $this->model->findOrFail($id); | ||
| 1328 | + $model->status = config('constants.ENABLE'); | ||
| 1329 | + $result = $model->save(); | ||
| 1330 | + // 判断操作结果 | ||
| 1331 | + if ($result) { | ||
| 1332 | + return response()->json( | ||
| 1333 | + [ | ||
| 1334 | + 'status' => 1, | ||
| 1335 | + 'message' => __('enable_succeeded'), | ||
| 1336 | + ] | ||
| 1337 | + ); | ||
| 1338 | + } else { | ||
| 1339 | + return response()->json( | ||
| 1340 | + [ | ||
| 1341 | + 'status' => 0, | ||
| 1342 | + 'message' => __('enable_failed'), | ||
| 1343 | + ] | ||
| 1344 | + ); | ||
| 1345 | + } | ||
| 1346 | + } catch (ModelNotFoundException $e) { | ||
| 1347 | + return response()->json( | ||
| 1348 | + [ | ||
| 1349 | + 'status' => 0, | ||
| 1350 | + 'message' => __('no_data'), | ||
| 1351 | + ] | ||
| 1352 | + ); | ||
| 1353 | + } | ||
| 1354 | + } | ||
| 1355 | + | ||
| 1356 | + /** | ||
| 1357 | + * 审核通过:多级审核 | ||
| 1358 | + * | ||
| 1359 | + * @param integer $id 主键id | ||
| 1360 | + * | ||
| 1361 | + * @return JsonResponse | ||
| 1362 | + * @throws \Exception | ||
| 1363 | + */ | ||
| 1364 | + public function pass($id) | ||
| 1365 | + { | ||
| 1366 | + DB::beginTransaction(); | ||
| 1367 | + try { | ||
| 1368 | + // 获取数据,如果没有获取到抛出异常 | ||
| 1369 | + $model = $this->model->findOrFail($id); | ||
| 1370 | + | ||
| 1371 | + // 判断审核权限 | ||
| 1372 | + $can_audit = $this->checkCanAudit($model); | ||
| 1373 | + if ($can_audit === false) { | ||
| 1374 | + return response()->json( | ||
| 1375 | + [ | ||
| 1376 | + 'status' => 0, | ||
| 1377 | + 'message' =>__('audit_failed'), | ||
| 1378 | + ] | ||
| 1379 | + ); | ||
| 1380 | + } | ||
| 1381 | + | ||
| 1382 | + // 用户的角色来设置审核状态 | ||
| 1383 | + $user = $this->getUser(); | ||
| 1384 | + $audited_status = config('constants.AUDIT_PASSED'); | ||
| 1385 | + $audited_at = date('Y-m-d H:i:s'); | ||
| 1386 | + $audited_by = $user->id; | ||
| 1387 | + $audited_opinion = request('audit_opinion'); | ||
| 1388 | + // 村管理审核员 | ||
| 1389 | + switch (true) { | ||
| 1390 | + case $user->isRole('village.auditor'): | ||
| 1391 | + $model->status = $model::FIRST_AUDIT_PASSED;; | ||
| 1392 | + break; | ||
| 1393 | + case $user->isRole('village.leader'): | ||
| 1394 | + $model->status = $model::PUBLISHED; | ||
| 1395 | + break; | ||
| 1396 | +// case $user->isRole('village.auditor'): | ||
| 1397 | +// $model->first_audited_status = $audited_status; | ||
| 1398 | +// $model->first_audited_at = $audited_at; | ||
| 1399 | +// $model->first_audited_by = $audited_by; | ||
| 1400 | +// $model->first_audited_opinion = $audited_opinion; | ||
| 1401 | +// break; | ||
| 1402 | +// case $user->isRole('village.leader'): | ||
| 1403 | +// $model->second_audited_status = $audited_status; | ||
| 1404 | +// $model->second_audited_at = $audited_at; | ||
| 1405 | +// $model->second_audited_by = $audited_by; | ||
| 1406 | +// $model->second_audited_opinion = $audited_opinion; | ||
| 1407 | +// $model->status = $model::PUBLISHED; | ||
| 1408 | +// $model->released_at = $audited_at; | ||
| 1409 | +// break; | ||
| 1410 | + } | ||
| 1411 | + $result = $model->save(); | ||
| 1412 | + if ($result) { | ||
| 1413 | + // 将审核结果写入到审核记录中 | ||
| 1414 | + $auditRecord = [ | ||
| 1415 | + 'user_id' => $audited_by, | ||
| 1416 | + 'user_type' => 'admin', | ||
| 1417 | + 'audited_by' => $audited_by, | ||
| 1418 | + 'audited_status' => $audited_status, | ||
| 1419 | + 'audited_at' => $audited_at, | ||
| 1420 | + 'audited_opinion' => $audited_opinion, | ||
| 1421 | + ]; | ||
| 1422 | + $model->auditRecords()->create($auditRecord); | ||
| 1423 | + // 事务提交 | ||
| 1424 | + DB::commit(); | ||
| 1425 | + return response()->json( | ||
| 1426 | + [ | ||
| 1427 | + 'status' => 1, | ||
| 1428 | + 'message' =>__('audit_succeeded'), | ||
| 1429 | + ] | ||
| 1430 | + ); | ||
| 1431 | + } else { | ||
| 1432 | + return response()->json( | ||
| 1433 | + [ | ||
| 1434 | + 'status' => 0, | ||
| 1435 | + 'message' =>__('audit_failed'), | ||
| 1436 | + ] | ||
| 1437 | + ); | ||
| 1438 | + } | ||
| 1439 | + } catch (Exception $e) { | ||
| 1440 | + DB::rollBack(); | ||
| 1441 | + return response()->json( | ||
| 1442 | + [ | ||
| 1443 | + 'status' => 0, | ||
| 1444 | + 'message' => $e->getMessage(), | ||
| 1445 | + ] | ||
| 1446 | + ); | ||
| 1447 | + } | ||
| 1448 | +// try { | ||
| 1449 | +// // 获取数据,如果没有获取到抛出异常 | ||
| 1450 | +// $model = $this->model->findOrFail($id); | ||
| 1451 | +// $model->audited_status = config('constants.AUDIT_PASSED'); | ||
| 1452 | +// $model->audited_at = date('Y-m-d H:i:s'); | ||
| 1453 | +// $model->audited_by = Admin::user()->id; | ||
| 1454 | +// | ||
| 1455 | +// $result = $model->save(); | ||
| 1456 | +// | ||
| 1457 | +// if ($result) { | ||
| 1458 | +// return response()->json( | ||
| 1459 | +// [ | ||
| 1460 | +// 'status' => 1, | ||
| 1461 | +// 'message' =>__('audit_succeeded'), | ||
| 1462 | +// ] | ||
| 1463 | +// ); | ||
| 1464 | +// } else { | ||
| 1465 | +// return response()->json( | ||
| 1466 | +// [ | ||
| 1467 | +// 'status' => 0, | ||
| 1468 | +// 'message' =>__('audit_failed'), | ||
| 1469 | +// ] | ||
| 1470 | +// ); | ||
| 1471 | +// } | ||
| 1472 | +// } catch (ModelNotFoundException $e) { | ||
| 1473 | +// return response()->json( | ||
| 1474 | +// [ | ||
| 1475 | +// 'status' => 0, | ||
| 1476 | +// 'message' => __('no_data'), | ||
| 1477 | +// ] | ||
| 1478 | +// ); | ||
| 1479 | +// } | ||
| 1480 | + } | ||
| 1481 | + | ||
| 1482 | + /** | ||
| 1483 | + * 审核不通过 | ||
| 1484 | + * | ||
| 1485 | + * @param integer $id 主键id | ||
| 1486 | + * | ||
| 1487 | + * @return JsonResponse | ||
| 1488 | + * @throws \Exception | ||
| 1489 | + */ | ||
| 1490 | + public function refuse($id) | ||
| 1491 | + { | ||
| 1492 | + DB::beginTransaction(); | ||
| 1493 | + try { | ||
| 1494 | + $audited_opinion = request('audit_opinion'); | ||
| 1495 | + if (!$audited_opinion) { | ||
| 1496 | + return response()->json( | ||
| 1497 | + [ | ||
| 1498 | + 'status' => 0, | ||
| 1499 | + 'message' =>'请输入审核意见!', | ||
| 1500 | + ] | ||
| 1501 | + ); | ||
| 1502 | + } | ||
| 1503 | + | ||
| 1504 | + // 获取数据,如果没有获取到抛出异常 | ||
| 1505 | + $model = $this->model->findOrFail($id); | ||
| 1506 | + | ||
| 1507 | + // 判断审核权限 | ||
| 1508 | + $can_audit = $this->checkCanAudit($model); | ||
| 1509 | + if ($can_audit === false) { | ||
| 1510 | + return response()->json( | ||
| 1511 | + [ | ||
| 1512 | + 'status' => 0, | ||
| 1513 | + 'message' =>__('audit_failed'), | ||
| 1514 | + ] | ||
| 1515 | + ); | ||
| 1516 | + } | ||
| 1517 | + | ||
| 1518 | + // 用户的角色来设置审核状态 | ||
| 1519 | + $user = $this->getUser(); | ||
| 1520 | + $audited_status = config('constants.AUDIT_NOT_PASSED'); | ||
| 1521 | + $audited_at = date('Y-m-d H:i:s'); | ||
| 1522 | + $audited_by = $user->id; | ||
| 1523 | + $model->status = $model::AUDIT_NOT_PASSED; | ||
| 1524 | + | ||
| 1525 | +// | ||
| 1526 | +// | ||
| 1527 | +// // 村管理审核员 | ||
| 1528 | +// switch (true) { | ||
| 1529 | +// case $user->isRole('village.auditor'): | ||
| 1530 | +// $model->first_audited_status = $audited_status; | ||
| 1531 | +// $model->first_audited_at = $audited_at; | ||
| 1532 | +// $model->first_audited_by = $audited_by; | ||
| 1533 | +// $model->first_audited_opinion = $audited_opinion; | ||
| 1534 | +// // TODO 是否要清空以前的审批记录 | ||
| 1535 | +// $model->submitted_status = 0; | ||
| 1536 | +// $model->submitted_at = null; | ||
| 1537 | +// $model->submitted_by = 0; | ||
| 1538 | +// $model->second_audited_status = config('constants.UNAUDITED'); | ||
| 1539 | +// $model->second_audited_at = null; | ||
| 1540 | +// $model->second_audited_by = 0; | ||
| 1541 | +// $model->second_audited_opinion = 0; | ||
| 1542 | +// break; | ||
| 1543 | +// case $user->isRole('village.leader'): | ||
| 1544 | +// $model->second_audited_status = $audited_status; | ||
| 1545 | +// $model->second_audited_at = $audited_at; | ||
| 1546 | +// $model->second_audited_by = $audited_by; | ||
| 1547 | +// $model->second_audited_opinion = $audited_opinion; | ||
| 1548 | +// break; | ||
| 1549 | +// } | ||
| 1550 | + | ||
| 1551 | + $result = $model->save(); | ||
| 1552 | + if ($result) { | ||
| 1553 | + // 将审核结果写入到审核记录中 | ||
| 1554 | + $auditRecord = [ | ||
| 1555 | + 'user_id' => $audited_by, | ||
| 1556 | + 'user_type' => 'admin', | ||
| 1557 | + 'audited_by' => $audited_by, | ||
| 1558 | + 'audited_status' => $audited_status, | ||
| 1559 | + 'audited_at' => $audited_at, | ||
| 1560 | + 'audited_opinion' => $audited_opinion, | ||
| 1561 | + ]; | ||
| 1562 | + $model->auditRecords()->create($auditRecord); | ||
| 1563 | + // 事务提交 | ||
| 1564 | + DB::commit(); | ||
| 1565 | + return response()->json( | ||
| 1566 | + [ | ||
| 1567 | + 'status' => 1, | ||
| 1568 | + 'message' =>__('audit_succeeded'), | ||
| 1569 | + ] | ||
| 1570 | + ); | ||
| 1571 | + } else { | ||
| 1572 | + return response()->json( | ||
| 1573 | + [ | ||
| 1574 | + 'status' => 0, | ||
| 1575 | + 'message' =>__('audit_failed'), | ||
| 1576 | + ] | ||
| 1577 | + ); | ||
| 1578 | + } | ||
| 1579 | + } catch (Exception $e) { | ||
| 1580 | + DB::rollBack(); | ||
| 1581 | + return response()->json( | ||
| 1582 | + [ | ||
| 1583 | + 'status' => 0, | ||
| 1584 | + 'message' => $e->getMessage(), | ||
| 1585 | + ] | ||
| 1586 | + ); | ||
| 1587 | + } | ||
| 1588 | + | ||
| 1589 | + | ||
| 1590 | + try { | ||
| 1591 | + // | ||
| 1592 | + $audited_opinion = request('audit_opinion'); | ||
| 1593 | + if (!$audited_opinion) { | ||
| 1594 | + return response()->json( | ||
| 1595 | + [ | ||
| 1596 | + 'status' => 0, | ||
| 1597 | + 'message' =>'请输入审核意见!', | ||
| 1598 | + ] | ||
| 1599 | + ); | ||
| 1600 | + } | ||
| 1601 | + | ||
| 1602 | + // 获取数据,如果没有获取到抛出异常 | ||
| 1603 | + $model = $this->model->findOrFail($id); | ||
| 1604 | + $model->audited_status = config('constants.AUDIT_NOT_PASSED'); | ||
| 1605 | + $model->audited_opinion = $audited_opinion; | ||
| 1606 | + $model->audited_at = date('Y-m-d H:i:s'); | ||
| 1607 | + $model->audited_by = Admin::user()->id; | ||
| 1608 | + | ||
| 1609 | + $result = $model->save(); | ||
| 1610 | + | ||
| 1611 | + if ($result) { | ||
| 1612 | + return response()->json( | ||
| 1613 | + [ | ||
| 1614 | + 'status' => 1, | ||
| 1615 | + 'message' =>__('audit_succeeded'), | ||
| 1616 | + ] | ||
| 1617 | + ); | ||
| 1618 | + } else { | ||
| 1619 | + return response()->json( | ||
| 1620 | + [ | ||
| 1621 | + 'status' => 0, | ||
| 1622 | + 'message' =>__('audit_failed'), | ||
| 1623 | + ] | ||
| 1624 | + ); | ||
| 1625 | + } | ||
| 1626 | + } catch (ModelNotFoundException $e) { | ||
| 1627 | + return response()->json( | ||
| 1628 | + [ | ||
| 1629 | + 'status' => 0, | ||
| 1630 | + 'message' => '当前数据不存在!', | ||
| 1631 | + ] | ||
| 1632 | + ); | ||
| 1633 | + } | ||
| 1634 | + } | ||
| 1635 | + | ||
| 1636 | + /** | ||
| 1637 | + * 提交审核 | ||
| 1638 | + * | ||
| 1639 | + * @param integer $id 主键id | ||
| 1640 | + * | ||
| 1641 | + * @return JsonResponse | ||
| 1642 | + * @throws \Exception | ||
| 1643 | + */ | ||
| 1644 | + public function submit($id) | ||
| 1645 | + { | ||
| 1646 | + DB::beginTransaction(); | ||
| 1647 | + try { | ||
| 1648 | + // 获取数据,如果没有获取到抛出异常 | ||
| 1649 | + $model = $this->model->findOrFail($id); | ||
| 1650 | + | ||
| 1651 | + // 判断审核权限 | ||
| 1652 | + $can_audit = $this->checkCanSubmitAudit($model); | ||
| 1653 | + if ($can_audit === false) { | ||
| 1654 | + return response()->json( | ||
| 1655 | + [ | ||
| 1656 | + 'status' => 0, | ||
| 1657 | + 'message' =>__('提交审核失败。'), | ||
| 1658 | + ] | ||
| 1659 | + ); | ||
| 1660 | + } | ||
| 1661 | + $audited_opinion = request('audit_opinion'); | ||
| 1662 | + $user = $this->getUser(); | ||
| 1663 | + $audited_by = $user->id; | ||
| 1664 | + $audited_at = date('Y-m-d H:i:s'); | ||
| 1665 | + $model->status = $model::SUBMITTED; | ||
| 1666 | + $model->submitted_at = $audited_at; | ||
| 1667 | + $model->submitted_by = $audited_by; | ||
| 1668 | + | ||
| 1669 | + $result = $model->save(); | ||
| 1670 | + if ($result) { | ||
| 1671 | + // 将审核结果写入到审核记录中 | ||
| 1672 | + $auditRecord = [ | ||
| 1673 | + 'user_id' => $audited_by, | ||
| 1674 | + 'user_type' => 'admin', | ||
| 1675 | + 'audited_by' => $audited_by, | ||
| 1676 | + 'audited_status' => AuditRecord::SUBMITTED, | ||
| 1677 | + 'audited_at' => $audited_at, | ||
| 1678 | + 'audited_opinion' => $audited_opinion, | ||
| 1679 | + | ||
| 1680 | + ]; | ||
| 1681 | + $model->auditRecords()->create($auditRecord); | ||
| 1682 | + DB::commit(); | ||
| 1683 | + return response()->json( | ||
| 1684 | + [ | ||
| 1685 | + 'status' => 1, | ||
| 1686 | + 'message' =>__('提交审核成功。'), | ||
| 1687 | + ] | ||
| 1688 | + ); | ||
| 1689 | + } else { | ||
| 1690 | + return response()->json( | ||
| 1691 | + [ | ||
| 1692 | + 'status' => 0, | ||
| 1693 | + 'message' =>__('audit_failed'), | ||
| 1694 | + ] | ||
| 1695 | + ); | ||
| 1696 | + } | ||
| 1697 | + } catch (Exception $e) { | ||
| 1698 | + DB::rollBack(); | ||
| 1699 | + return response()->json( | ||
| 1700 | + [ | ||
| 1701 | + 'status' => 0, | ||
| 1702 | + 'message' => $e->getMessage(), | ||
| 1703 | + ] | ||
| 1704 | + ); | ||
| 1705 | + } | ||
| 1706 | + } | ||
| 1707 | + | ||
| 1708 | + /** | ||
| 1709 | + * 恢复软删除数据 | ||
| 1710 | + * | ||
| 1711 | + * @param integer $id 主键id | ||
| 1712 | + * | ||
| 1713 | + * @return JsonResponse | ||
| 1714 | + * @throws \Exception | ||
| 1715 | + */ | ||
| 1716 | + public function restore($id) | ||
| 1717 | + { | ||
| 1718 | + try { | ||
| 1719 | + // 获取数据,如果没有获取到抛出异常 | ||
| 1720 | + $model = $this->model->onlyTrashed()->findOrFail($id); | ||
| 1721 | + $model->deleted_at = null; | ||
| 1722 | + $model->restored_at = now()->toDateTimeString(); | ||
| 1723 | + $model->restored_by = Admin::user()->id; | ||
| 1724 | + $model->restored_opinion = request('restored_opinion', ''); | ||
| 1725 | + $result = $model->save(); | ||
| 1726 | + if ($result) { | ||
| 1727 | + return response()->json( | ||
| 1728 | + [ | ||
| 1729 | + 'code' => 0, | ||
| 1730 | + 'status' => 1, | ||
| 1731 | + 'message' => __('restore') . __('succeeded'), | ||
| 1732 | + ] | ||
| 1733 | + ); | ||
| 1734 | + } else { | ||
| 1735 | + return response()->json( | ||
| 1736 | + [ | ||
| 1737 | + 'code' => 1001, | ||
| 1738 | + 'status' => 0, | ||
| 1739 | + 'message' => __('restore') . __('failed'), | ||
| 1740 | + | ||
| 1741 | + ] | ||
| 1742 | + ); | ||
| 1743 | + } | ||
| 1744 | + } catch (ModelNotFoundException $e) { | ||
| 1745 | + return response()->json( | ||
| 1746 | + [ | ||
| 1747 | + 'status' => 0, | ||
| 1748 | + 'message' => '当前数据不存在!', | ||
| 1749 | + ] | ||
| 1750 | + ); | ||
| 1751 | + } | ||
| 1752 | + } | ||
| 1753 | + | ||
| 1754 | + /** | ||
| 1755 | + * 获取当前登录用户信息 | ||
| 1756 | + * | ||
| 1757 | + * @return User|\Illuminate\Contracts\Auth\Authenticatable|null | ||
| 1758 | + */ | ||
| 1759 | + public function getUser() | ||
| 1760 | + { | ||
| 1761 | + return $this->user ?? $this->user = \Admin::user(); | ||
| 1762 | + } | ||
| 1763 | + | ||
| 1764 | + /** | ||
| 1765 | + * 根据用户角色构建查询语句 | ||
| 1766 | + * | ||
| 1767 | + * @param null $query 查询语句 | ||
| 1768 | + * @param null $user 用户 | ||
| 1769 | + * @param null $user_role 用户角色 | ||
| 1770 | + * @return mixed | ||
| 1771 | + */ | ||
| 1772 | + public function buildQuery($query, $user = null, $user_role = null) | ||
| 1773 | + { | ||
| 1774 | + if (!$user) { | ||
| 1775 | + $user = $this->getUser(); | ||
| 1776 | + } | ||
| 1777 | + // 只有管理员和录入员才能进行添加和编辑 | ||
| 1778 | + if (!$user->isAdministrator() && !$user->isRole('village.reporter')) { | ||
| 1779 | + $this->can_create = false; | ||
| 1780 | + // 是否可编辑 | ||
| 1781 | + $this->can_edit = false; | ||
| 1782 | + // 是否可删除 | ||
| 1783 | + $this->can_delete = false; | ||
| 1784 | + } | ||
| 1785 | + | ||
| 1786 | + | ||
| 1787 | +// // 根据角色来判断 | ||
| 1788 | +// $role = Admin::user()->roles->pluck('slug')->first(); | ||
| 1789 | +// switch ($role) { | ||
| 1790 | +// case 'Admin': | ||
| 1791 | +// $this->can_delete = false; | ||
| 1792 | +// break; | ||
| 1793 | +// case 'KPO/NPT': | ||
| 1794 | +// $this->can_create = false; | ||
| 1795 | +// $this->can_edit = false; | ||
| 1796 | +// $this->can_delete = false; | ||
| 1797 | +// $this->can_import = false; | ||
| 1798 | +// break; | ||
| 1799 | +// case 'Teacher':// 获取我的全部学生 | ||
| 1800 | +// case 'PL': | ||
| 1801 | +// break; | ||
| 1802 | +// } | ||
| 1803 | + | ||
| 1804 | + return $query; | ||
| 1805 | + } | ||
| 1806 | + | ||
| 1807 | + /** | ||
| 1808 | + * | ||
| 1809 | + */ | ||
| 1810 | + public function importPage() | ||
| 1811 | + { | ||
| 1812 | + $model = $this->model; | ||
| 1813 | + return view('admin::grid.import', compact('model')) ; | ||
| 1814 | + } | ||
| 1815 | + | ||
| 1816 | + | ||
| 1817 | + /** | ||
| 1818 | + * 是否是管理客户端 | ||
| 1819 | + * | ||
| 1820 | + * @return bool | ||
| 1821 | + */ | ||
| 1822 | + public function isAdminClient() | ||
| 1823 | + { | ||
| 1824 | + return config('admin.route.prefix') === 'admin'; | ||
| 1825 | + } | ||
| 1826 | + | ||
| 1827 | + /** | ||
| 1828 | + * 是否是机构户端 | ||
| 1829 | + * | ||
| 1830 | + * @return bool | ||
| 1831 | + */ | ||
| 1832 | + public function isAgencyClient() | ||
| 1833 | + { | ||
| 1834 | + return config('admin.route.prefix') === 'agency'; | ||
| 1835 | + } | ||
| 1836 | + | ||
| 1837 | + /** | ||
| 1838 | + * 验证是否能进行提交审核操作 | ||
| 1839 | + * | ||
| 1840 | + * @param $model | ||
| 1841 | + * @param $status | ||
| 1842 | + * @return bool | ||
| 1843 | + */ | ||
| 1844 | + public function checkCanSubmitAudit($model, $status = 0) | ||
| 1845 | + { | ||
| 1846 | + $can = false; | ||
| 1847 | + $user = Admin::user(); | ||
| 1848 | + if ($model->status == $model::UNSUBMITTED || $model->status == $model::AUDIT_NOT_PASSED) { | ||
| 1849 | + if ($user->isRole('village.reporter') || $user->isAdministrator()) { | ||
| 1850 | + $can = true; | ||
| 1851 | + } | ||
| 1852 | + } | ||
| 1853 | + return $can; | ||
| 1854 | + | ||
| 1855 | + if ($model->status == $status) { | ||
| 1856 | + // 判断审核状态,如果一级审核未审核或者二级审核状态为 不通过 | ||
| 1857 | + $audited_status = $model->first_audited_status; | ||
| 1858 | + $audited_at = $model->first_audited_at; | ||
| 1859 | + $submitted_at = $model->submitted_at; | ||
| 1860 | + // 判断用户的角色 | ||
| 1861 | + if (($user->isRole('village.reporter') || $user->isAdministrator())) { | ||
| 1862 | + if ($model->submitted_status == 0 || ($audited_status == config('constants.AUDIT_NOT_PASSED') && $audited_at > $submitted_at)) { | ||
| 1863 | + $can = true; | ||
| 1864 | + } | ||
| 1865 | + } | ||
| 1866 | + } | ||
| 1867 | + return $can; | ||
| 1868 | + } | ||
| 1869 | + | ||
| 1870 | + /** | ||
| 1871 | + * 验证是否能进行审核操作 | ||
| 1872 | + * 1、村管理录入员 发布信息 | ||
| 1873 | + * 2、村管理审核员审核,通过后进入村领导审核,不通过则退回到 村管理录入员 | ||
| 1874 | + * 3、村领导审核通过后则直接发布,不通过则直接退回到 村管理录入员 | ||
| 1875 | + * @param $model | ||
| 1876 | + * @param $status | ||
| 1877 | + * @return bool | ||
| 1878 | + */ | ||
| 1879 | + public function checkCanAudit($model, $status = 0) | ||
| 1880 | + { | ||
| 1881 | + $can_audit = false; | ||
| 1882 | + $user = $this->getUser(); | ||
| 1883 | + switch ($model->status) { | ||
| 1884 | +// case $model::UNSUBMITTED: // 未提交审核 | ||
| 1885 | +// case $model::AUDIT_NOT_PASSED: // 已提交审核 | ||
| 1886 | +// if (($user->isRole('village.reporter') || $user->isAdministrator())) { | ||
| 1887 | +// $can_audit = true; | ||
| 1888 | +// } | ||
| 1889 | +// break; | ||
| 1890 | + case $model::SUBMITTED: // 已提交审核 | ||
| 1891 | + if ($user->isRole('village.auditor')) { | ||
| 1892 | + $can_audit = true; | ||
| 1893 | + } | ||
| 1894 | + break; | ||
| 1895 | + case $model::FIRST_AUDIT_PASSED: // 一级审核通过 | ||
| 1896 | + if ($user->isRole('village.leader')) { | ||
| 1897 | + $can_audit = true; | ||
| 1898 | + } | ||
| 1899 | + break; | ||
| 1900 | + } | ||
| 1901 | + | ||
| 1902 | + return $can_audit; | ||
| 1903 | + | ||
| 1904 | + | ||
| 1905 | + | ||
| 1906 | + | ||
| 1907 | + | ||
| 1908 | + if ($model->status == $status) { | ||
| 1909 | + // 判断用户的角色 | ||
| 1910 | + // 判断审核状态,如果一级审核未审核或者二级审核状态为 不通过 | ||
| 1911 | + $first_audited_status = $model->first_audited_status; | ||
| 1912 | + $first_audited_at = $model->first_audited_at; | ||
| 1913 | + $second_audited_status = $model->second_audited_status; | ||
| 1914 | + $second_audited_at = $model->second_audited_at; | ||
| 1915 | + $third_audited_status = $model->third_audited_status; | ||
| 1916 | + $submitted_at = $model->submitted_at; | ||
| 1917 | + $submitted_status = $model->submitted_status; | ||
| 1918 | + | ||
| 1919 | + $user = Admin::user(); | ||
| 1920 | + switch (true) { | ||
| 1921 | + case $first_audited_status == config('constants.AUDIT_NOT_PASSED'): | ||
| 1922 | + if ($user->isRole('village.auditor') && $submitted_status == 1 && $submitted_at > $first_audited_at) { | ||
| 1923 | + $can_audit = true; | ||
| 1924 | + } | ||
| 1925 | + break; | ||
| 1926 | + case $first_audited_status == config('constants.UNAUDITED'): | ||
| 1927 | + case $second_audited_status == config('constants.AUDIT_NOT_PASSED'): | ||
| 1928 | + if ($user->isRole('village.auditor') && (!$second_audited_at || $second_audited_at > $first_audited_at)) { | ||
| 1929 | + $can_audit = true; | ||
| 1930 | + } | ||
| 1931 | + | ||
| 1932 | + if ($user->isRole('village.leader') && (!$second_audited_at || $second_audited_at < $first_audited_at)) { | ||
| 1933 | + $can_audit = true; | ||
| 1934 | + } | ||
| 1935 | + break; | ||
| 1936 | + case $second_audited_status == config('constants.UNAUDITED'): | ||
| 1937 | + if ($user->isRole('village.leader')) { | ||
| 1938 | + $can_audit = true; | ||
| 1939 | + } | ||
| 1940 | + break; | ||
| 1941 | + case $third_audited_status == config('AUDIT_NOT_PASSED.UNAUDITED'): | ||
| 1942 | +// if ($user->isRole('village.leader')) { | ||
| 1943 | +// $can_audit = true; | ||
| 1944 | +// } | ||
| 1945 | + break; | ||
| 1946 | + } | ||
| 1947 | + } | ||
| 1948 | + return $can_audit; | ||
| 1949 | + } | ||
| 1950 | + | ||
| 1951 | + /** | ||
| 1952 | + * 渲染自定义的分页 ajax | ||
| 1953 | + * | ||
| 1954 | + * @param $paginator | ||
| 1955 | + * @param null $transformer | ||
| 1956 | + * @param array $params | ||
| 1957 | + * @return array | ||
| 1958 | + */ | ||
| 1959 | + public function renderPaginator($paginator, $transformer = null, $params = []) | ||
| 1960 | + { | ||
| 1961 | + // dump($paginator); | ||
| 1962 | + // 追加查询条件 | ||
| 1963 | + if ($params) { | ||
| 1964 | + array_walk($params, function ($param, $key) use (&$paginator) { | ||
| 1965 | + $paginator->appends($key, $param); | ||
| 1966 | + }); | ||
| 1967 | + } | ||
| 1968 | + | ||
| 1969 | + $items = $paginator->items() ; | ||
| 1970 | + | ||
| 1971 | + // 对数据进行转换 | ||
| 1972 | + $data = []; | ||
| 1973 | + if ($transformer) { | ||
| 1974 | + foreach ($items as $vo) { | ||
| 1975 | + $data[] = $transformer->transform($vo); | ||
| 1976 | + } | ||
| 1977 | + } else { | ||
| 1978 | + $data = $items; | ||
| 1979 | + } | ||
| 1980 | + | ||
| 1981 | + // 获取当前的页码 | ||
| 1982 | + $page = request('page', 1); | ||
| 1983 | + | ||
| 1984 | + // 全部数据 | ||
| 1985 | + $total = $paginator->total(); | ||
| 1986 | + | ||
| 1987 | + // 全部页码 | ||
| 1988 | + $lastPage = $paginator->lastPage(); | ||
| 1989 | + | ||
| 1990 | + // 当前页码 | ||
| 1991 | + $currentPage = $paginator->currentPage(); | ||
| 1992 | + | ||
| 1993 | + // 中间的页码数组 | ||
| 1994 | + $elements = []; | ||
| 1995 | + $len = $lastPage - 2; | ||
| 1996 | + $center_page = 8; | ||
| 1997 | + // 创建数组 | ||
| 1998 | + if ($lastPage <= 10) { | ||
| 1999 | + for ($i = 1; $i <= $lastPage; $i++) { | ||
| 2000 | + $elements[0][$i] = $i; | ||
| 2001 | + } | ||
| 2002 | + } else { | ||
| 2003 | + if ($currentPage < $center_page) { | ||
| 2004 | + for ($i = 1; $i <= $center_page; $i++) { | ||
| 2005 | + $elements[0][$i] = $i; | ||
| 2006 | + } | ||
| 2007 | + $elements[1] = '...'; | ||
| 2008 | + for ($i = $lastPage-1; $i <= $lastPage; $i++) { | ||
| 2009 | + $elements[2][$i] = $i; | ||
| 2010 | + } | ||
| 2011 | + }/*elseif($currentPage === $lastPage /2){ | ||
| 2012 | +// for ($i = $lastPage /2 - 4; $i <= $lastPage /2 - 4; $i++) { | ||
| 2013 | +// $elements[0][$i] = $i; | ||
| 2014 | +// } | ||
| 2015 | +// $elements[1] = '...'; | ||
| 2016 | +// for ($i = $center_page + 1; $i <= $center_page + 4; $i++) { | ||
| 2017 | +// $elements[2][$i] = $i; | ||
| 2018 | +// } | ||
| 2019 | +// $elements[2]['...'] = '...'; | ||
| 2020 | +// for ($i = $lastPage-1; $i <= $lastPage; $i++) { | ||
| 2021 | +// $elements[2][$i] = $i; | ||
| 2022 | +// } | ||
| 2023 | + }*/ elseif ($currentPage <= $lastPage /2 + 1) { | ||
| 2024 | + for ($i = 1; $i <= $center_page - 4; $i++) { | ||
| 2025 | + $elements[0][$i] = $i; | ||
| 2026 | + } | ||
| 2027 | + $elements[1] = '...'; | ||
| 2028 | + for ($i = $center_page + 1; $i <= $center_page + 4; $i++) { | ||
| 2029 | + $elements[2][$i] = $i; | ||
| 2030 | + } | ||
| 2031 | + $elements[2]['...'] = '...'; | ||
| 2032 | + for ($i = $lastPage-1; $i <= $lastPage; $i++) { | ||
| 2033 | + $elements[2][$i] = $i; | ||
| 2034 | + } | ||
| 2035 | + } else { | ||
| 2036 | + for ($i = 1; $i <= 2; $i++) { | ||
| 2037 | + $elements[0][$i] = $i; | ||
| 2038 | + } | ||
| 2039 | + $elements[1] = '...'; | ||
| 2040 | + for ($i = $lastPage-$center_page-1; $i <= $lastPage; $i++) { | ||
| 2041 | + $elements[2][$i] = $i; | ||
| 2042 | + } | ||
| 2043 | + } | ||
| 2044 | + } | ||
| 2045 | + | ||
| 2046 | + //dd($elements); | ||
| 2047 | + | ||
| 2048 | + | ||
| 2049 | + | ||
| 2050 | + $prev = ($page - 1) > 0 ? $page - 1 : 1; | ||
| 2051 | + | ||
| 2052 | + $next = ($page + 1) < $total ? $page + 1 : $total; | ||
| 2053 | + | ||
| 2054 | + return [ | ||
| 2055 | + 'items' => $data, | ||
| 2056 | + 'prev' => $prev, | ||
| 2057 | + 'next' => $next, | ||
| 2058 | + 'total' => $total, | ||
| 2059 | + 'lastPage' => $lastPage, | ||
| 2060 | + 'page' => $page, | ||
| 2061 | + 'pageSize' => request('per_page', 10), | ||
| 2062 | + 'paginator' => $paginator, | ||
| 2063 | + 'elements' => $elements, | ||
| 2064 | + 'url' => request()->url(), | ||
| 2065 | + ]; | ||
| 2066 | + } | ||
| 2067 | +} |
app/Admin/Controllers/BusesController.php
0 → 100644
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | ++----------------------------------------------------------------------------------------------------------------------- | ||
| 4 | + * 管理端控制层: Bus 控制类 | ||
| 5 | ++----------------------------------------------------------------------------------------------------------------------- | ||
| 6 | + * | ||
| 7 | + * PHP version 7 | ||
| 8 | + * | ||
| 9 | + * @category App\Admin\Controllers | ||
| 10 | + * @package App\Admin\Controllers | ||
| 11 | + * @author Richer <yangzi1028@163.com> | ||
| 12 | + * @date 2023年2月28日14:35:45 | ||
| 13 | + * @copyright 2020-2022 Richer (http://www.Richer.com/) | ||
| 14 | + * @license http://www.Richer.com/ License | ||
| 15 | + * @link http://www.Richer.com/ | ||
| 16 | + */ | ||
| 17 | +namespace App\Admin\Controllers; | ||
| 18 | + | ||
| 19 | +use App\Admin\Forms\BusForm; | ||
| 20 | +use App\Admin\Grids\BusGrid; | ||
| 21 | +use App\Admin\Shows\BusShow; | ||
| 22 | +use App\Models\Bus; | ||
| 23 | +use App\Models\User\User; | ||
| 24 | +use Illuminate\Database\Eloquent\ModelNotFoundException; | ||
| 25 | +use Illuminate\Http\JsonResponse; | ||
| 26 | +use Illuminate\Support\Facades\DB; | ||
| 27 | + | ||
| 28 | +/** | ||
| 29 | + * Class BusesController | ||
| 30 | + * @package App\Admin\Controllers | ||
| 31 | + */ | ||
| 32 | +class BusesController extends BaseController | ||
| 33 | +{ | ||
| 34 | + use BusGrid, BusForm, BusShow; | ||
| 35 | + | ||
| 36 | + /** | ||
| 37 | + * BusesController constructor. | ||
| 38 | + * | ||
| 39 | + * @param Bus $model 注入model | ||
| 40 | + */ | ||
| 41 | + public function __construct(Bus $model) | ||
| 42 | + { | ||
| 43 | + // 资源显示的中名称 | ||
| 44 | + $this->title = $model::OBJ_NAME_ZH; | ||
| 45 | + // 是否可查看 | ||
| 46 | + $this->can_view = true; | ||
| 47 | + // 是否可新增 | ||
| 48 | + $this->can_create = true; | ||
| 49 | + // 是否可编辑 | ||
| 50 | + $this->can_edit = true; | ||
| 51 | + // 是否可删除 | ||
| 52 | + $this->can_delete = true; | ||
| 53 | + // 是否开启下拉菜单 | ||
| 54 | + $this->dropdownActions = false; | ||
| 55 | + | ||
| 56 | + // 执行父类构造方法 | ||
| 57 | + parent::__construct($model); | ||
| 58 | + } | ||
| 59 | +} |
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | ++----------------------------------------------------------------------------------------------------------------------- | ||
| 4 | + * 管理端控制层: Category 控制类 | ||
| 5 | ++----------------------------------------------------------------------------------------------------------------------- | ||
| 6 | + * | ||
| 7 | + * PHP version 7 | ||
| 8 | + * | ||
| 9 | + * @category App\Admin\Controllers | ||
| 10 | + * @package App\Admin\Controllers | ||
| 11 | + * @author Richer <yangzi1028@163.com> | ||
| 12 | + * @date 2023年4月20日14:26:14 | ||
| 13 | + * @copyright 2020-2022 Richer (http://www.Richer.com/) | ||
| 14 | + * @license http://www.Richer.com/ License | ||
| 15 | + * @link http://www.Richer.com/ | ||
| 16 | + */ | ||
| 17 | +namespace App\Admin\Controllers; | ||
| 18 | + | ||
| 19 | +use App\Admin\Forms\CategoryForm; | ||
| 20 | +use App\Admin\Grids\CategoryGrid; | ||
| 21 | +use App\Jobs\Category\CategoryLabelCreatedJob; | ||
| 22 | +use App\Models\Category\Category; | ||
| 23 | +use App\Models\Category\CategoryExample; | ||
| 24 | +use App\Models\Category\CategoryLabel; | ||
| 25 | +use App\Models\Category\CategoryLabelItem; | ||
| 26 | +use App\Models\Label; | ||
| 27 | +use App\Models\LabelItem; | ||
| 28 | +use Illuminate\Database\Eloquent\ModelNotFoundException; | ||
| 29 | +use Illuminate\Http\JsonResponse; | ||
| 30 | + | ||
| 31 | +/** | ||
| 32 | + * Class CategoriesController. | ||
| 33 | + * | ||
| 34 | + * @package App\Admin\Controllers | ||
| 35 | + */ | ||
| 36 | +class CategoriesController extends BaseController | ||
| 37 | +{ | ||
| 38 | + use CategoryGrid, CategoryForm; | ||
| 39 | + | ||
| 40 | + /** | ||
| 41 | + * CategoriesController constructor. | ||
| 42 | + * | ||
| 43 | + * @param Category $model 注入model | ||
| 44 | + */ | ||
| 45 | + public function __construct(Category $model) | ||
| 46 | + { | ||
| 47 | + // 资源显示的中名称 | ||
| 48 | + $this->title = $model::OBJ_NAME_ZH; | ||
| 49 | + // 是否可查看 | ||
| 50 | + $this->can_view = false; | ||
| 51 | + // 是否可新增 | ||
| 52 | + $this->can_create = true; | ||
| 53 | + // 是否可编辑 | ||
| 54 | + $this->can_edit = true; | ||
| 55 | + // 是否可删除 | ||
| 56 | + $this->can_delete = true; | ||
| 57 | + // 是否开启下拉菜单 | ||
| 58 | + $this->dropdownActions = false; | ||
| 59 | + | ||
| 60 | + // 执行父类构造方法 | ||
| 61 | + parent::__construct($model); | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + /** | ||
| 65 | + * 获取 实例 | ||
| 66 | + * | ||
| 67 | + * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|JsonResponse | ||
| 68 | + */ | ||
| 69 | + public function examples($id) | ||
| 70 | + { | ||
| 71 | + $list = null; | ||
| 72 | + try { | ||
| 73 | + // 获取数据,如果没有获取到抛出异常 | ||
| 74 | + $model = $this->model->findOrFail($id); | ||
| 75 | + | ||
| 76 | + $list = $model->examples()->get(); | ||
| 77 | + return view('admin::category.examples', compact('id', 'list')) ; | ||
| 78 | + | ||
| 79 | + } catch (ModelNotFoundException $e) { | ||
| 80 | + return view('admin::category.examples', compact('id', 'list')) ; | ||
| 81 | + } | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + /** | ||
| 85 | + * 添加实例界面 | ||
| 86 | + * | ||
| 87 | + * @param $id | ||
| 88 | + */ | ||
| 89 | + public function examplePage($id) | ||
| 90 | + { | ||
| 91 | + $example_id = request('example_id', 0); | ||
| 92 | + $example = null; | ||
| 93 | + if ($example_id) { | ||
| 94 | + $example = CategoryExample::find($example_id); | ||
| 95 | + } | ||
| 96 | + // 获取数据,如果没有获取到抛出异常 | ||
| 97 | + return view('admin::category.example', compact('id', 'example_id','example')) ; | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + /** | ||
| 101 | + * 添加站点 | ||
| 102 | + * | ||
| 103 | + * @param integer $id 主键id | ||
| 104 | + * | ||
| 105 | + * @return JsonResponse | ||
| 106 | + */ | ||
| 107 | + public function addExample($id) | ||
| 108 | + { | ||
| 109 | + try { | ||
| 110 | + | ||
| 111 | + $example_id = request('example_id', 0); | ||
| 112 | + if ($example_id > 0) { | ||
| 113 | + // 获取数据,如果没有获取到抛出异常 | ||
| 114 | + $model = CategoryExample::findOrFail($example_id); | ||
| 115 | + $model->question = request('question'); | ||
| 116 | + $model->answer = request('answer'); | ||
| 117 | + $model->save(); | ||
| 118 | + } else { | ||
| 119 | + // 获取数据,如果没有获取到抛出异常 | ||
| 120 | + $model = $this->model->findOrFail($id); | ||
| 121 | + $model->examples()->create([ | ||
| 122 | + 'question' => request('question'), | ||
| 123 | + 'answer' => request('answer'), | ||
| 124 | + ]); | ||
| 125 | + } | ||
| 126 | + | ||
| 127 | + return response()->json( | ||
| 128 | + [ | ||
| 129 | + 'code' => 0, | ||
| 130 | + 'status' => 1, | ||
| 131 | + 'message' => __('operate_succeeded'), | ||
| 132 | + ] | ||
| 133 | + ); | ||
| 134 | + } catch (\Exception $e) { | ||
| 135 | + return response()->json( | ||
| 136 | + [ | ||
| 137 | + 'code' => 1, | ||
| 138 | + 'status' => 0, | ||
| 139 | + 'message' => $e->getMessage(), | ||
| 140 | + ] | ||
| 141 | + ); | ||
| 142 | + } | ||
| 143 | + } | ||
| 144 | + | ||
| 145 | + /** | ||
| 146 | + * 线路更新站点的顺序 | ||
| 147 | + * | ||
| 148 | + * @param integer $id 主键id | ||
| 149 | + * | ||
| 150 | + * @return JsonResponse | ||
| 151 | + */ | ||
| 152 | + public function deleteExample($id) | ||
| 153 | + { | ||
| 154 | + try { | ||
| 155 | + // 获取数据,如果没有获取到抛出异常 | ||
| 156 | + | ||
| 157 | + $model = $this->model->findOrFail($id); | ||
| 158 | + | ||
| 159 | + $result = $model->examples()->where('id', request('id'))->delete(); | ||
| 160 | + | ||
| 161 | + if ($result) { | ||
| 162 | + return response()->json( | ||
| 163 | + [ | ||
| 164 | + 'code' => 0, | ||
| 165 | + 'status' => 1, | ||
| 166 | + 'message' =>__('operate_succeeded'), | ||
| 167 | + ] | ||
| 168 | + ); | ||
| 169 | + } | ||
| 170 | + | ||
| 171 | + return response()->json( | ||
| 172 | + [ | ||
| 173 | + 'code' => 1, | ||
| 174 | + 'status' => 1, | ||
| 175 | + 'message' =>__('操作失败。'), | ||
| 176 | + ] | ||
| 177 | + ); | ||
| 178 | + | ||
| 179 | + | ||
| 180 | + } catch (\Exception $e) { | ||
| 181 | + return response()->json( | ||
| 182 | + [ | ||
| 183 | + 'code' => 1, | ||
| 184 | + 'status' => 0, | ||
| 185 | + 'message' => $e->getMessage(), | ||
| 186 | + ] | ||
| 187 | + ); | ||
| 188 | + } | ||
| 189 | + } | ||
| 190 | + | ||
| 191 | + /** | ||
| 192 | + * 获取 实例 | ||
| 193 | + * | ||
| 194 | + * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|JsonResponse | ||
| 195 | + */ | ||
| 196 | + public function labels($id) | ||
| 197 | + { | ||
| 198 | + $list = null; | ||
| 199 | + try { | ||
| 200 | + // 获取数据,如果没有获取到抛出异常 | ||
| 201 | + $model = $this->model->findOrFail($id); | ||
| 202 | + | ||
| 203 | + $list = $model->labels()->get(); | ||
| 204 | + return view('admin::category.labels', compact('id', 'list')) ; | ||
| 205 | + | ||
| 206 | + } catch (ModelNotFoundException $e) { | ||
| 207 | + return view('admin::category.labels', compact('id', 'list')) ; | ||
| 208 | + } | ||
| 209 | + } | ||
| 210 | + | ||
| 211 | + /** | ||
| 212 | + * 添加 标签 界面 | ||
| 213 | + * | ||
| 214 | + * @param $id | ||
| 215 | + */ | ||
| 216 | + public function labelPage($id) | ||
| 217 | + { | ||
| 218 | + $label_id = request('label_id', 0); | ||
| 219 | + $label = null; | ||
| 220 | + if ($label_id) { | ||
| 221 | + $label = CategoryLabel::find($label_id); | ||
| 222 | + } | ||
| 223 | + // 获取数据,如果没有获取到抛出异常 | ||
| 224 | + return view('admin::category.label', compact('id', 'label_id','label')) ; | ||
| 225 | + } | ||
| 226 | + | ||
| 227 | + /** | ||
| 228 | + * 添加 标签 | ||
| 229 | + * | ||
| 230 | + * @param integer $id 主键id | ||
| 231 | + * | ||
| 232 | + * @return JsonResponse | ||
| 233 | + */ | ||
| 234 | + public function addLabel($id) | ||
| 235 | + { | ||
| 236 | + try { | ||
| 237 | + $label_id = request('label_id', 0); | ||
| 238 | + if ($label_id > 0) { | ||
| 239 | + // 获取数据,如果没有获取到抛出异常 | ||
| 240 | + $model = CategoryLabel::findOrFail($label_id); | ||
| 241 | + $model->name = request('name'); | ||
| 242 | + $model->can_multiple = request('can_multiple', 0); | ||
| 243 | + $model->semantics = request('semantics'); | ||
| 244 | + $model->description = request('description'); | ||
| 245 | + $model->save(); | ||
| 246 | + | ||
| 247 | + } else { | ||
| 248 | + // 获取数据,如果没有获取到抛出异常 | ||
| 249 | + $model = $this->model->findOrFail($id); | ||
| 250 | + $result = $model->labels()->create([ | ||
| 251 | + 'name' => request('name'), | ||
| 252 | + 'semantics' => request('semantics'), | ||
| 253 | + 'description' => request('description'), | ||
| 254 | + 'can_multiple' => request('can_multiple', 0), | ||
| 255 | + ]); | ||
| 256 | + | ||
| 257 | + // 同步到远程服务器 | ||
| 258 | +// CategoryLabelCreatedJob::dispatch($result); | ||
| 259 | + | ||
| 260 | + } | ||
| 261 | + | ||
| 262 | + return response()->json( | ||
| 263 | + [ | ||
| 264 | + 'code' => 0, | ||
| 265 | + 'status' => 1, | ||
| 266 | + 'message' => __('operate_succeeded'), | ||
| 267 | + ] | ||
| 268 | + ); | ||
| 269 | + } catch (\Exception $e) { | ||
| 270 | + return response()->json( | ||
| 271 | + [ | ||
| 272 | + 'code' => 1, | ||
| 273 | + 'status' => 0, | ||
| 274 | + 'message' => $e->getMessage(), | ||
| 275 | + ] | ||
| 276 | + ); | ||
| 277 | + } | ||
| 278 | + } | ||
| 279 | + | ||
| 280 | + /** | ||
| 281 | + * 删除 标签 | ||
| 282 | + * | ||
| 283 | + * @param integer $id 主键id | ||
| 284 | + * | ||
| 285 | + * @return JsonResponse | ||
| 286 | + */ | ||
| 287 | + public function deleteLabel($id) | ||
| 288 | + { | ||
| 289 | + try { | ||
| 290 | + // 获取数据,如果没有获取到抛出异常 | ||
| 291 | + | ||
| 292 | + $model = $this->model->findOrFail($id); | ||
| 293 | + | ||
| 294 | + $result = $model->labels()->where('id', request('id'))->delete(); | ||
| 295 | + | ||
| 296 | + if ($result) { | ||
| 297 | + return response()->json( | ||
| 298 | + [ | ||
| 299 | + 'code' => 0, | ||
| 300 | + 'status' => 1, | ||
| 301 | + 'message' =>__('operate_succeeded'), | ||
| 302 | + ] | ||
| 303 | + ); | ||
| 304 | + } | ||
| 305 | + | ||
| 306 | + return response()->json( | ||
| 307 | + [ | ||
| 308 | + 'code' => 1, | ||
| 309 | + 'status' => 1, | ||
| 310 | + 'message' =>__('操作失败。'), | ||
| 311 | + ] | ||
| 312 | + ); | ||
| 313 | + | ||
| 314 | + | ||
| 315 | + } catch (\Exception $e) { | ||
| 316 | + return response()->json( | ||
| 317 | + [ | ||
| 318 | + 'code' => 1, | ||
| 319 | + 'status' => 0, | ||
| 320 | + 'message' => $e->getMessage(), | ||
| 321 | + ] | ||
| 322 | + ); | ||
| 323 | + } | ||
| 324 | + } | ||
| 325 | + | ||
| 326 | + /** | ||
| 327 | + * 添加 标签明细 界面 | ||
| 328 | + * | ||
| 329 | + * @param $id | ||
| 330 | + */ | ||
| 331 | + public function labelItemPage($id) | ||
| 332 | + { | ||
| 333 | + $label_item_id = request('label_item_id', 0); | ||
| 334 | + $label_item = null; | ||
| 335 | + if ($label_item_id) { | ||
| 336 | + $label_item = CategoryExample::find($label_item_id); | ||
| 337 | + } | ||
| 338 | + // 获取数据,如果没有获取到抛出异常 | ||
| 339 | + return view('admin::category.label-item', compact('id', 'label_item_id','label_item')) ; | ||
| 340 | + } | ||
| 341 | + | ||
| 342 | + /** | ||
| 343 | + * 添加 标签明细 | ||
| 344 | + * | ||
| 345 | + * @param integer $id 主键id | ||
| 346 | + * | ||
| 347 | + * @return JsonResponse | ||
| 348 | + */ | ||
| 349 | + public function addLabelItem($id) | ||
| 350 | + { | ||
| 351 | + try { | ||
| 352 | + $label_id = request('label_item_id', 0); | ||
| 353 | + if ($label_id > 0) { | ||
| 354 | + // 获取数据,如果没有获取到抛出异常 | ||
| 355 | + $model = CategoryLabelItem::findOrFail($label_id); | ||
| 356 | + $model->name = request('name'); | ||
| 357 | + $model->description = request('description'); | ||
| 358 | + $model->save(); | ||
| 359 | + } else { | ||
| 360 | + // 获取数据,如果没有获取到抛出异常 | ||
| 361 | + $model = CategoryLabel::findOrFail($id); | ||
| 362 | + $model->items()->create([ | ||
| 363 | + 'name' => request('name'), | ||
| 364 | + 'description' => request('description'), | ||
| 365 | + ]); | ||
| 366 | + } | ||
| 367 | + | ||
| 368 | + return response()->json( | ||
| 369 | + [ | ||
| 370 | + 'code' => 0, | ||
| 371 | + 'status' => 1, | ||
| 372 | + 'message' => __('operate_succeeded'), | ||
| 373 | + ] | ||
| 374 | + ); | ||
| 375 | + } catch (\Exception $e) { | ||
| 376 | + return response()->json( | ||
| 377 | + [ | ||
| 378 | + 'code' => 1, | ||
| 379 | + 'status' => 0, | ||
| 380 | + 'message' => $e->getMessage(), | ||
| 381 | + ] | ||
| 382 | + ); | ||
| 383 | + } | ||
| 384 | + } | ||
| 385 | + | ||
| 386 | + /** | ||
| 387 | + * 删除 标签明细 | ||
| 388 | + * | ||
| 389 | + * @param integer $id 主键id | ||
| 390 | + * | ||
| 391 | + * @return JsonResponse | ||
| 392 | + */ | ||
| 393 | + public function deleteLabelItem($id) | ||
| 394 | + { | ||
| 395 | + try { | ||
| 396 | + // 获取数据,如果没有获取到抛出异常 | ||
| 397 | + $result = CategoryLabelItem::where('id', request('id'))->delete(); | ||
| 398 | + | ||
| 399 | + if ($result) { | ||
| 400 | + return response()->json( | ||
| 401 | + [ | ||
| 402 | + 'code' => 0, | ||
| 403 | + 'status' => 1, | ||
| 404 | + 'message' =>__('operate_succeeded'), | ||
| 405 | + ] | ||
| 406 | + ); | ||
| 407 | + } | ||
| 408 | + | ||
| 409 | + return response()->json( | ||
| 410 | + [ | ||
| 411 | + 'code' => 1, | ||
| 412 | + 'status' => 1, | ||
| 413 | + 'message' =>__('操作失败。'), | ||
| 414 | + ] | ||
| 415 | + ); | ||
| 416 | + | ||
| 417 | + | ||
| 418 | + } catch (\Exception $e) { | ||
| 419 | + return response()->json( | ||
| 420 | + [ | ||
| 421 | + 'code' => 1, | ||
| 422 | + 'status' => 0, | ||
| 423 | + 'message' => $e->getMessage(), | ||
| 424 | + ] | ||
| 425 | + ); | ||
| 426 | + } | ||
| 427 | + } | ||
| 428 | +} |
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | ++----------------------------------------------------------------------------------------------------------------------- | ||
| 4 | + * 管理端控制层: ChatRecord 控制类 | ||
| 5 | ++----------------------------------------------------------------------------------------------------------------------- | ||
| 6 | + * | ||
| 7 | + * PHP version 7 | ||
| 8 | + * | ||
| 9 | + * @category App\Admin\Controllers | ||
| 10 | + * @package App\Admin\Controllers | ||
| 11 | + * @author Richer <yangzi1028@163.com> | ||
| 12 | + * @date 2023年4月24日13:45:56 | ||
| 13 | + * @copyright 2020-2022 Richer (http://www.Richer.com/) | ||
| 14 | + * @license http://www.Richer.com/ License | ||
| 15 | + * @link http://www.Richer.com/ | ||
| 16 | + */ | ||
| 17 | +namespace App\Admin\Controllers; | ||
| 18 | + | ||
| 19 | +use App\Admin\Grids\ChatRecordGrid; | ||
| 20 | +use App\Models\Chat\ChatRecord; | ||
| 21 | +use Illuminate\Database\Eloquent\ModelNotFoundException; | ||
| 22 | +use Illuminate\Http\JsonResponse; | ||
| 23 | + | ||
| 24 | +/** | ||
| 25 | + * Class ChatRecordsController. | ||
| 26 | + * | ||
| 27 | + * @package App\Admin\Controllers | ||
| 28 | + */ | ||
| 29 | +class ChatRecordsController extends BaseController | ||
| 30 | +{ | ||
| 31 | + use ChatRecordGrid; | ||
| 32 | + | ||
| 33 | + /** | ||
| 34 | + * ChatRecordsController constructor. | ||
| 35 | + * | ||
| 36 | + * @param ChatRecord $model 注入model | ||
| 37 | + */ | ||
| 38 | + public function __construct(ChatRecord $model) | ||
| 39 | + { | ||
| 40 | + // 资源显示的中名称 | ||
| 41 | + $this->title = $model::OBJ_NAME_ZH; | ||
| 42 | + // 是否可查看 | ||
| 43 | + $this->can_view = false; | ||
| 44 | + // 是否可新增 | ||
| 45 | + $this->can_create = false; | ||
| 46 | + // 是否可编辑 | ||
| 47 | + $this->can_edit = false; | ||
| 48 | + // 是否可删除 | ||
| 49 | + $this->can_delete = false; | ||
| 50 | + // 是否开启下拉菜单 | ||
| 51 | + $this->dropdownActions = false; | ||
| 52 | + | ||
| 53 | + // 执行父类构造方法 | ||
| 54 | + parent::__construct($model); | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + /** | ||
| 58 | + * 获取 聊天明细记录 | ||
| 59 | + * | ||
| 60 | + * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|JsonResponse | ||
| 61 | + */ | ||
| 62 | + public function items($id) | ||
| 63 | + { | ||
| 64 | + $list = null; | ||
| 65 | + try { | ||
| 66 | + // 获取数据,如果没有获取到抛出异常 | ||
| 67 | + $model = $this->model->findOrFail($id); | ||
| 68 | + | ||
| 69 | + $list = $model->items()->with(['user'])->oldest()->get(); | ||
| 70 | +// dd($list->toArray()); | ||
| 71 | +// nl2br(1); | ||
| 72 | + return view('admin::chat.items', compact('id', 'model','list')) ; | ||
| 73 | + | ||
| 74 | + } catch (ModelNotFoundException $e) { | ||
| 75 | + return view('admin::chat.items', compact('id', 'list')) ; | ||
| 76 | + } | ||
| 77 | + } | ||
| 78 | +} |
app/Admin/Controllers/ExamplesController.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Admin\Controllers; | ||
| 4 | + | ||
| 5 | +use App\Admin\Forms\ExampleForm; | ||
| 6 | +use App\Admin\Grids\ExampleGrid; | ||
| 7 | +use App\Admin\Shows\ExampleShow; | ||
| 8 | +use App\Models\Example; | ||
| 9 | +use Encore\Admin\Controllers\AdminController; | ||
| 10 | +use Encore\Admin\Form; | ||
| 11 | +use Encore\Admin\Grid; | ||
| 12 | +use Encore\Admin\Show; | ||
| 13 | + | ||
| 14 | +/** | ||
| 15 | + * Class ExamplesController. | ||
| 16 | + * | ||
| 17 | + * @category App\Admin\Controllers | ||
| 18 | + * @package App\Admin\Controllers | ||
| 19 | + * @author Richer <yangzi1028@163.com> | ||
| 20 | + * @date 2020年11月13日 01:26:09 | ||
| 21 | + * @copyright 2020-2022 Richer (http://www.Richer.com/) | ||
| 22 | + * @license http://www.Richer.com/ License | ||
| 23 | + * @link http://www.Richer.com/ | ||
| 24 | + */ | ||
| 25 | +class ExamplesController extends BaseController | ||
| 26 | +{ | ||
| 27 | + use ExampleGrid, | ||
| 28 | + ExampleForm, | ||
| 29 | + ExampleShow; | ||
| 30 | + | ||
| 31 | + /** | ||
| 32 | + * ExamplesController constructor. | ||
| 33 | + * | ||
| 34 | + * @param Example $model 注入model | ||
| 35 | + */ | ||
| 36 | + public function __construct(Example $model) | ||
| 37 | + { | ||
| 38 | + // 资源显示的中名称 | ||
| 39 | + $this->title = $model::OBJ_NAME_ZH; | ||
| 40 | + // 是否可查看 | ||
| 41 | + $this->can_view = true; | ||
| 42 | + // 是否可新增 | ||
| 43 | + $this->can_create = true; | ||
| 44 | + // 是否可编辑 | ||
| 45 | + $this->can_edit = true; | ||
| 46 | + // 是否可删除 | ||
| 47 | + $this->can_delete = true; | ||
| 48 | + // 是否可导出 | ||
| 49 | + $this->can_export = true; | ||
| 50 | + // 是否可下架 | ||
| 51 | + $this->can_unshelve = true; | ||
| 52 | + // 是否可审核 | ||
| 53 | + $this->can_audit = true; | ||
| 54 | + // 是否开启下拉菜单 | ||
| 55 | + $this->dropdownActions = false; | ||
| 56 | + | ||
| 57 | + // 执行父类构造方法 | ||
| 58 | + parent::__construct($model); | ||
| 59 | + } | ||
| 60 | +} |
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | ++----------------------------------------------------------------------------------------------------------------------- | ||
| 4 | + * 管理端控制层: Feedback 控制类 | ||
| 5 | ++----------------------------------------------------------------------------------------------------------------------- | ||
| 6 | + * | ||
| 7 | + * PHP version 7 | ||
| 8 | + * | ||
| 9 | + * @category App\Admin\Controllers | ||
| 10 | + * @package App\Admin\Controllers | ||
| 11 | + * @author Richer <yangzi1028@163.com> | ||
| 12 | + * @date 2023年4月20日14:26:14 | ||
| 13 | + * @copyright 2020-2022 Richer (http://www.Richer.com/) | ||
| 14 | + * @license http://www.Richer.com/ License | ||
| 15 | + * @link http://www.Richer.com/ | ||
| 16 | + */ | ||
| 17 | +namespace App\Admin\Controllers; | ||
| 18 | + | ||
| 19 | +use App\Admin\Forms\FeedbackForm; | ||
| 20 | +use App\Admin\Grids\FeedbackGrid; | ||
| 21 | +use App\Models\Feedback; | ||
| 22 | + | ||
| 23 | +/** | ||
| 24 | + * Class FeedbacksController. | ||
| 25 | + * | ||
| 26 | + * @package App\Admin\Controllers | ||
| 27 | + */ | ||
| 28 | +class FeedbacksController extends BaseController | ||
| 29 | +{ | ||
| 30 | + use FeedbackGrid, FeedbackForm; | ||
| 31 | + | ||
| 32 | + /** | ||
| 33 | + * FeedbacksController constructor. | ||
| 34 | + * | ||
| 35 | + * @param Feedback $model 注入model | ||
| 36 | + */ | ||
| 37 | + public function __construct(Feedback $model) | ||
| 38 | + { | ||
| 39 | + // 资源显示的中名称 | ||
| 40 | + $this->title = $model::OBJ_NAME_ZH; | ||
| 41 | + // 是否可查看 | ||
| 42 | + $this->can_view = false; | ||
| 43 | + // 是否可新增 | ||
| 44 | + $this->can_create = true; | ||
| 45 | + // 是否可编辑 | ||
| 46 | + $this->can_edit = true; | ||
| 47 | + // 是否可删除 | ||
| 48 | + $this->can_delete = true; | ||
| 49 | + // 是否开启下拉菜单 | ||
| 50 | + $this->dropdownActions = false; | ||
| 51 | + | ||
| 52 | + // 执行父类构造方法 | ||
| 53 | + parent::__construct($model); | ||
| 54 | + } | ||
| 55 | +} |
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | ++----------------------------------------------------------------------------------------------------------------------- | ||
| 4 | + * 管理端控制层: HelpCenter 控制类 | ||
| 5 | ++----------------------------------------------------------------------------------------------------------------------- | ||
| 6 | + * | ||
| 7 | + * PHP version 7 | ||
| 8 | + * | ||
| 9 | + * @category App\Admin\Controllers | ||
| 10 | + * @package App\Admin\Controllers | ||
| 11 | + * @author Richer <yangzi1028@163.com> | ||
| 12 | + * @date 2023年4月20日14:26:14 | ||
| 13 | + * @copyright 2020-2022 Richer (http://www.Richer.com/) | ||
| 14 | + * @license http://www.Richer.com/ License | ||
| 15 | + * @link http://www.Richer.com/ | ||
| 16 | + */ | ||
| 17 | +namespace App\Admin\Controllers; | ||
| 18 | + | ||
| 19 | +use App\Admin\Forms\HelpCenterForm; | ||
| 20 | +use App\Admin\Grids\HelpCenterGrid; | ||
| 21 | +use App\Models\HelpCenter; | ||
| 22 | + | ||
| 23 | +/** | ||
| 24 | + * Class HelpCentersController. | ||
| 25 | + * | ||
| 26 | + * @package App\Admin\Controllers | ||
| 27 | + */ | ||
| 28 | +class HelpCentersController extends BaseController | ||
| 29 | +{ | ||
| 30 | + use HelpCenterGrid, HelpCenterForm; | ||
| 31 | + | ||
| 32 | + /** | ||
| 33 | + * HelpCentersController constructor. | ||
| 34 | + * | ||
| 35 | + * @param HelpCenter $model 注入model | ||
| 36 | + */ | ||
| 37 | + public function __construct(HelpCenter $model) | ||
| 38 | + { | ||
| 39 | + // 资源显示的中名称 | ||
| 40 | + $this->title = $model::OBJ_NAME_ZH; | ||
| 41 | + // 是否可查看 | ||
| 42 | + $this->can_view = false; | ||
| 43 | + // 是否可新增 | ||
| 44 | + $this->can_create = true; | ||
| 45 | + // 是否可编辑 | ||
| 46 | + $this->can_edit = true; | ||
| 47 | + // 是否可删除 | ||
| 48 | + $this->can_delete = true; | ||
| 49 | + // 是否开启下拉菜单 | ||
| 50 | + $this->dropdownActions = false; | ||
| 51 | + | ||
| 52 | + // 执行父类构造方法 | ||
| 53 | + parent::__construct($model); | ||
| 54 | + } | ||
| 55 | +} |
-
请 注册 或 登录 后发表评论