Music.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace app\admin\controller\party;
  3. use app\common\controller\Backend;
  4. use think\Db;
  5. /**
  6. *
  7. *
  8. * @icon fa fa-music
  9. */
  10. class Music extends Backend
  11. {
  12. /**
  13. * Music模型对象
  14. * @var \app\admin\model\party\Music
  15. */
  16. protected $model = null;
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $this->model = new \app\admin\model\party\Music;
  21. }
  22. public function import()
  23. {
  24. parent::import();
  25. }
  26. /**
  27. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  28. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  29. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  30. */
  31. /**
  32. * 编辑
  33. */
  34. public function edit($ids = null)
  35. {
  36. $row = $this->model->get($ids);
  37. if (!$row) {
  38. $this->error(__('No Results were found'));
  39. }
  40. $adminIds = $this->getDataLimitAdminIds();
  41. if (is_array($adminIds)) {
  42. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  43. $this->error(__('You have no permission'));
  44. }
  45. }
  46. if ($this->request->isPost()) {
  47. $params = $this->request->post("row/a");
  48. if ($params) {
  49. $params = $this->preExcludeFields($params);
  50. $result = false;
  51. Db::startTrans();
  52. try {
  53. //是否采用模型验证
  54. if ($this->modelValidate) {
  55. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  56. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  57. $row->validateFailException(true)->validate($validate);
  58. }
  59. $result = $row->allowField(true)->save($params);
  60. Db::commit();
  61. } catch (ValidateException $e) {
  62. Db::rollback();
  63. $this->error($e->getMessage());
  64. } catch (PDOException $e) {
  65. Db::rollback();
  66. $this->error($e->getMessage());
  67. } catch (Exception $e) {
  68. Db::rollback();
  69. $this->error($e->getMessage());
  70. }
  71. if ($result !== false) {
  72. $this->success();
  73. } else {
  74. $this->error(__('No rows were updated'));
  75. }
  76. }
  77. $this->error(__('Parameter %s can not be empty', ''));
  78. }
  79. $row["cosurl"] = config("cos.url");
  80. $this->view->assign("row", $row);
  81. return $this->view->fetch();
  82. }
  83. }