PaymentChannel.php 2.2 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. $list = $this->model->findAll();
  18. foreach ($list as &$item) $item['type_str'] = ['默认类型', '御龙币设置', '信用卡设置'][$item['type'] - 1];
  19. View::assign("list", $list);
  20. return view();
  21. }
  22. public function add() {
  23. if ($this->request->isAjax()) {
  24. $params = $this->request->param();
  25. $this->model->save([
  26. 'name' => $params['name'],
  27. 'icon' => $params['icon'],
  28. ]);
  29. return $this->ok(true);
  30. }
  31. return view();
  32. }
  33. public function delete(Request $request) {
  34. $params = $request->param();
  35. if(!isset($params['ids']))
  36. return $this->fail(lang("Please select the data you want to delete"));
  37. $this->model->deleteByIds(explode(',',$params['ids']));
  38. return $this->ok(true);
  39. }
  40. public function edit() {
  41. $params = $this->request->param();
  42. if(!isset($params['id']))
  43. return $this->fail(lang('ID not exist'));
  44. $channel = $this->model->findById($params['id']);
  45. if($this->request->isAjax()) {
  46. $res = $this->model->where('id',$params['id'])->update([
  47. 'icon' => $params['icon'],
  48. 'name' => $params['name'],
  49. 'update_time' => time()
  50. ]);
  51. return $this->ok($res);
  52. }
  53. View::assign('channel', $channel);
  54. return view();
  55. }
  56. /**
  57. * @return \think\response\Json
  58. */
  59. public function upload() {
  60. // 获取表单上传文件 例如上传了001.jpg
  61. $file = request()->file('file');
  62. // 上传到本地服务器
  63. $save_name = \think\facade\Filesystem::disk('public')->putFile( 'icon', $file);
  64. return $this->ok(str_replace('\\',"/",'/storage/'.$save_name));
  65. }
  66. }