Market.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. /**
  5. * 币币合约控制管理
  6. *
  7. * @icon fa fa-circle-o
  8. */
  9. class Market extends Backend
  10. {
  11. /**
  12. * Market模型对象
  13. * @var \app\admin\model\Market
  14. */
  15. protected $model = null;
  16. public function _initialize()
  17. {
  18. parent::_initialize();
  19. $this->model = new \app\admin\model\Market();
  20. }
  21. /**
  22. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  23. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  24. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  25. */
  26. /**
  27. * @return string|\think\response\Json
  28. * @throws \think\Exception
  29. */
  30. public function index()
  31. {
  32. return $this->setting('commission');
  33. }
  34. /**
  35. * 会员设置
  36. * @return string
  37. * @throws \think\Exception
  38. */
  39. public function handlingset()
  40. {
  41. return $this->setting('handlingset');
  42. }
  43. /**
  44. * 设置
  45. * @param string $type
  46. * @return string
  47. * @throws \think\Exception
  48. */
  49. private function setting($type = 'commission', $params = false)
  50. {
  51. $row = $this->model->find();
  52. if (!$row) {
  53. $defaultVo['createtime'] = time();
  54. $defaultVo['updatetime'] = time();
  55. $this->model->data($defaultVo)->save();
  56. }
  57. if ($this->request->isPost()) {
  58. if ($params === false) {
  59. $params = $this->request->param("row/a");
  60. }
  61. if ($params) {
  62. //TODO 启用过滤,打开注释,设置每种type类型的允许键名
  63. try {
  64. $result = $this->model->where('id',$row['id'])->update($params);
  65. if ($result !== false) {
  66. $this->success('');
  67. } else {
  68. $this->error($row->getError());
  69. }
  70. } catch (\think\exception\PDOException $e) {
  71. $this->error($e->getMessage());
  72. }
  73. }
  74. $this->error(__('Parameter %s can not be empty', ''));
  75. }
  76. $this->view->assign("row", $row);
  77. return $this->view->fetch();
  78. }
  79. }