123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- <?php
- namespace App\Http\Controllers\Admin\Setting;
- use Illuminate\Http\Request;
- use App\Services\AipHttpClient;
- use App\Http\Controllers\Controller;
- use App\Models\System\SysConfig;
- use Illuminate\Support\Facades\Auth;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Storage;
- class ConfigController extends Controller
- {
- public function index()
- {
- $data = SysConfig::get();
- return view('admin.setting.config.index', compact('data'));
- }
- public function update(Request $request)
- {
- $data = $request->all();
- foreach ($data as $k => $v) {
- if($v == ''){
- return $this->responseData(400, '请把内容全部填写');
- }
- }
- DB::beginTransaction();
- try{
- $admin_id = Auth::guard('admin')->id();
- $time = nowDate();
- foreach ($data as $k => $v) {
- if(is_array($v)){
- $v = json_encode($v);
- }
- SysConfig::where('config_key',$k)->update([
- 'config_val'=> $v
- ]);
- }
- DB::commit();
- return $this->responseData(200, 'success');
- } catch (\Exception $e) {
- DB::rollBack();
- return $this->responseData(400, $e->getMessage());
- }
- }
-
- public function uploadfile($file, $disk)
- {
- if (!$file->isValid()) {
- return $this->responseData(400, '文件不合法');
- }
- //原文件名
- $originalName = $file->getClientOriginalName();
- //扩展名
- $ext = $file->getClientOriginalExtension();
- //MimeType
- $type = $file->getClientMimeType();
- //临时绝对路径
- $realPath = $file->getRealPath();
- $filename = date('Ymd') . '/' . date('YmdHis') . rand(100, 1000) . '.' . $ext;
- $res = Storage::disk($disk)->put($filename, file_get_contents($realPath));
-
- $url = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http";
- $url .= "://" . $_SERVER['HTTP_HOST'];
- return $res ? $this->responseData(200, 'success', ['url' => $url . '/uploads/' . $disk . '/' . $filename]) : $this->responseData(400, 'error');
- }
-
- public function clearjobcache(Request $request)
- {
- $data = SysConfig::where('config_key','job_url')->first();
- if(empty($data)){
- return $this->responseData(400, '请先配置任务域名url.');
- }
- if(empty($data->config_val->url) || $data->config_val->url == '' || $data->config_val->url == null){
- return $this->responseData(400, '请先配置任务域名url');
- }
-
- $url = $data->config_val->url.'/api/config/clear_timing';
- $AipHttpClient = new AipHttpClient();
-
- $res = $AipHttpClient->postnew($url);
-
- if(empty($res)){
- return $this->responseData(400, '检查任务是否已启动1');
- }else{
- $res = json_decode($res,true);
- if(empty($res['code'])){
- return $this->responseData(400, '检查任务是否已启动2');
- }else{
- if($res['code'] == 200){
- return $this->responseData(200, 'success');
- }else{
- return $this->responseData(400, '检查任务是否已启动3');
- }
- }
- }
- }
-
- public function checkjob(Request $request)
- {
- $data = SysConfig::where('config_key','job_url')->first();
- if(empty($data)){
- return $this->responseData(400, '请先配置任务域名url.');
- }
- if(empty($data->config_val->url) || $data->config_val->url == '' || $data->config_val->url == null){
- return $this->responseData(400, '请先配置任务域名url');
- }
-
- $url = $data->config_val->url.'/api/config/check_status';
- $AipHttpClient = new AipHttpClient();
-
- $res = $AipHttpClient->postnew($url);
-
- if(empty($res)){
- return $this->responseData(400, '已停止1');
- }else{
- $res = json_decode($res,true);
- if(empty($res['code'])){
- return $this->responseData(400, '已停止2');
- }else{
- if($res['code'] == 200){
- return $this->responseData(200, '运行正常');
- }else{
- return $this->responseData(400, '已停止3');
- }
- }
- }
- }
- }
|