Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
更新:优化程序可扩展性
- Loading branch information
1 parent
a4e8e29
commit 8dac5b6
Showing
23 changed files
with
342 additions
and
285 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 76 additions & 60 deletions
136
app/Plugins/Core/src/Controller/Pay/PayAdminController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,120 +1,136 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* This file is part of zhuchunshu. | ||
* @link https://github.com/zhuchunshu | ||
* @document https://github.com/zhuchunshu/super-forum | ||
* @contact laravel@88.com | ||
* @license https://github.com/zhuchunshu/super-forum/blob/master/LICENSE | ||
*/ | ||
namespace App\Plugins\Core\src\Controller\Pay; | ||
|
||
use App\Middleware\AdminMiddleware; | ||
use App\Plugins\Core\src\Handler\FileUpload; | ||
use App\Plugins\Core\src\Models\PayConfig; | ||
use App\Plugins\Core\src\Models\PayOrder; | ||
use Hyperf\HttpServer\Annotation\{Controller, GetMapping, Middleware, PostMapping}; | ||
use Hyperf\HttpServer\Annotation\Controller; | ||
use Hyperf\HttpServer\Annotation\GetMapping; | ||
use Hyperf\HttpServer\Annotation\Middleware; | ||
use Hyperf\HttpServer\Annotation\PostMapping; | ||
|
||
#[Controller(prefix: '/admin/Pay')] | ||
#[Middleware(AdminMiddleware::class)] | ||
class PayAdminController | ||
{ | ||
/** | ||
* 订单 | ||
* 订单. | ||
* @return \Psr\Http\Message\ResponseInterface | ||
*/ | ||
#[GetMapping(path:"")] | ||
public function index(){ | ||
#[GetMapping(path: '')] | ||
public function index() | ||
{ | ||
$where_column = request()->input('where_column'); | ||
$q = request()->input('trade_no'); | ||
if(!$where_column){ | ||
if (! $where_column) { | ||
$_orderBy = 'ASC'; | ||
if ($q){ | ||
$page = PayOrder::query()->where('trade_no','like','%'.$q.'%')->orWhere('id','like','%'.$q.'%')->paginate(15); | ||
}else{ | ||
if ($q) { | ||
$page = PayOrder::query()->where('trade_no', 'like', '%' . $q . '%')->orWhere('id', 'like', '%' . $q . '%')->paginate(15); | ||
} else { | ||
$page = PayOrder::query()->paginate(15); | ||
} | ||
return view('App::Pay.admin.index',['page'=>$page,'_orderBy' => $_orderBy]); | ||
return view('App::Pay.admin.index', ['page' => $page, '_orderBy' => $_orderBy]); | ||
} | ||
$_orderBy = match (request()->input('_orderBy')){ | ||
$_orderBy = match (request()->input('_orderBy')) { | ||
'ASC' => 'DESC', | ||
'DESC' => 'ASC', | ||
}; | ||
if ($q){ | ||
$page = PayOrder::query()->where('trade_no','like','%'.$q.'%')->orWhere('id','like','%'.$q.'%')->orderBy($where_column,$_orderBy)->paginate(15); | ||
|
||
}else{ | ||
$page = PayOrder::query()->orderBy($where_column,$_orderBy)->paginate(15); | ||
if ($q) { | ||
$page = PayOrder::query()->where('trade_no', 'like', '%' . $q . '%')->orWhere('id', 'like', '%' . $q . '%')->orderBy($where_column, $_orderBy)->paginate(15); | ||
} else { | ||
$page = PayOrder::query()->orderBy($where_column, $_orderBy)->paginate(15); | ||
} | ||
return view('App::Pay.admin.index',['page'=>$page,'_orderBy' => $_orderBy]); | ||
return view('App::Pay.admin.index', ['page' => $page, '_orderBy' => $_orderBy]); | ||
} | ||
|
||
/** | ||
* 配置 | ||
* 配置. | ||
*/ | ||
#[GetMapping(path:"config")] | ||
public function config(){ | ||
#[GetMapping(path: 'config')] | ||
public function config() | ||
{ | ||
return view('App::Pay.admin.config'); | ||
} | ||
|
||
#[PostMapping(path:'config')] | ||
public function config_save(FileUpload $fileUpload){ | ||
#[PostMapping(path: 'config')] | ||
public function config_save(FileUpload $fileUpload) | ||
{ | ||
// 先处理上传的文件 | ||
foreach (request()->getUploadedFiles() as $name=>$file){ | ||
foreach (request()->getUploadedFiles() as $name => $file) { | ||
// 获取文件 | ||
$file = request()->file($name); | ||
if ($file->isFile()){ | ||
if ($file->isFile()) { | ||
// 保存文件 | ||
$file = $fileUpload->save($file,'admin','pay_wechat_'); | ||
$file = $fileUpload->save($file, 'admin', 'pay_wechat_'); | ||
// 获取文件路径 | ||
$file = $file['raw_path']; | ||
// 插入到数据库 | ||
$this->config_save_insert($name,$file); | ||
$this->config_save_insert($name, $file); | ||
} | ||
} | ||
// 后处理保存的字符串内容 | ||
foreach(request()->all() as $key => $value){ | ||
$this->config_save_insert($key,$value); | ||
foreach (request()->all() as $key => $value) { | ||
$this->config_save_insert($key, $value); | ||
} | ||
pay()->clean_options(); | ||
return redirect()->url('/admin/Pay/config')->with('success','更新成功')->go(); | ||
} | ||
|
||
private function config_save_insert($name,$value): bool | ||
{ | ||
if(PayConfig::query()->where('name',$name)->exists()){ | ||
// 存在则更新 | ||
PayConfig::query()->where('name',$name)->update([ | ||
'value' => $value | ||
]); | ||
return true; | ||
} | ||
|
||
// 不存在则新建 | ||
PayConfig::query()->create([ | ||
'value' => $value, | ||
'name' => $name | ||
]); | ||
return true; | ||
return redirect()->url('/admin/Pay/config')->with('success', '更新成功')->go(); | ||
} | ||
|
||
/** | ||
* 支付设置 | ||
* 支付设置. | ||
* @return \Psr\Http\Message\ResponseInterface | ||
*/ | ||
#[GetMapping(path:"setting")] | ||
public function setting(){ | ||
#[GetMapping(path: 'setting')] | ||
public function setting() | ||
{ | ||
return view('App::Pay.admin.setting'); | ||
} | ||
|
||
#[PostMapping(path:"setting")] | ||
public function setting_submit(){ | ||
$pay = request()->input('pay',[]); | ||
$pay = json_encode($pay,JSON_UNESCAPED_UNICODE); | ||
$this->config_save_insert('enable',$pay); | ||
#[PostMapping(path: 'setting')] | ||
public function setting_submit() | ||
{ | ||
$pay = request()->input('pay', []); | ||
$pay = json_encode($pay, JSON_UNESCAPED_UNICODE); | ||
$this->config_save_insert('enable', $pay); | ||
pay()->clean_options(); | ||
return redirect()->url('/admin/Pay/setting')->with('success','更新成功')->go(); | ||
return redirect()->url('/admin/Pay/setting')->with('success', '更新成功')->go(); | ||
//return view('App::Pay.admin.setting'); | ||
} | ||
|
||
#[GetMapping(path:'{trade_no}/order')] | ||
public function order_show($trade_no){ | ||
if (!PayOrder::query()->where('trade_no',$trade_no)->exists()){ | ||
return redirect()->url('/admin/Pay')->with('danger','订单不存在')->go(); | ||
#[GetMapping(path: '{trade_no}/order')] | ||
public function order_show($trade_no) | ||
{ | ||
if (! PayOrder::query()->where('trade_no', $trade_no)->exists()) { | ||
return redirect()->url('/admin/Pay')->with('danger', '订单不存在')->go(); | ||
} | ||
return pay()->find($trade_no); | ||
} | ||
} | ||
|
||
private function config_save_insert($name, $value): bool | ||
{ | ||
if (PayConfig::query()->where('name', $name)->exists()) { | ||
// 存在则更新 | ||
PayConfig::query()->where('name', $name)->update([ | ||
'value' => $value, | ||
]); | ||
return true; | ||
} | ||
|
||
// 不存在则新建 | ||
PayConfig::query()->create([ | ||
'value' => $value, | ||
'name' => $name, | ||
]); | ||
return true; | ||
} | ||
} |
Oops, something went wrong.