PaymentChannel.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace app\admin\controller;
  3. use app\BaseController;
  4. use app\common\model\PaymentChannelModel;
  5. use think\App;
  6. use think\facade\View;
  7. use think\Request;
  8. class PaymentChannel extends BaseController
  9. {
  10. private $model;
  11. public function __construct(App $app)
  12. {
  13. $this->model = new PaymentChannelModel();
  14. parent::__construct($app);
  15. }
  16. public function index() {
  17. View::assign("list",$this->model->findAll());
  18. return view();
  19. }
  20. public function add() {
  21. if ($this->request->isAjax()) {
  22. $params = $this->request->param();
  23. $this->model->save([
  24. 'name' => $params['name'],
  25. 'icon' => $params['icon'],
  26. ]);
  27. return $this->ok(true);
  28. }
  29. return view();
  30. }
  31. public function delete(Request $request) {
  32. $params = $request->param();
  33. if(!isset($params['ids']))
  34. return $this->fail(lang("Please select the data you want to delete"));
  35. $this->model->deleteByIds(explode(',',$params['ids']));
  36. return $this->ok(true);
  37. }
  38. public function edit() {
  39. $params = $this->request->param();
  40. if(!isset($params['id']))
  41. return $this->fail(lang('ID not exist'));
  42. $channel = $this->model->findById($params['id']);
  43. if($this->request->isAjax()) {
  44. $res = $this->model->where('id',$params['id'])->update([
  45. 'icon' => $params['icon'],
  46. 'name' => $params['name'],
  47. 'update_time' => time()
  48. ]);
  49. return $this->ok($res);
  50. }
  51. View::assign('channel', $channel);
  52. return view();
  53. }
  54. /**
  55. * @return \think\response\Json
  56. */
  57. public function upload() {
  58. // 获取表单上传文件 例如上传了001.jpg
  59. $file = request()->file('file');
  60. // 上传到本地服务器
  61. $save_name = \think\facade\Filesystem::disk('public')->putFile( 'icon', $file);
  62. return $this->ok(str_replace('\\',"/",'/storage/'.$save_name));
  63. }
  64. }