Voteplayer.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use Exception;
  5. use think\Db;
  6. use think\db\exception\BindParamException;
  7. use think\db\exception\DataNotFoundException;
  8. use think\db\exception\ModelNotFoundException;
  9. use think\exception\DbException;
  10. use think\exception\PDOException;
  11. use think\exception\ValidateException;
  12. /**
  13. * 投票选手管理
  14. *
  15. * @icon fa fa-circle-o
  16. */
  17. class Voteplayer extends Backend
  18. {
  19. /**
  20. * Voteplayer模型对象
  21. * @var \app\admin\model\Voteplayer
  22. */
  23. protected $model = null;
  24. public function _initialize()
  25. {
  26. parent::_initialize();
  27. $this->model = new \app\admin\model\Voteplayer;
  28. $this->view->assign("statusList", $this->model->getStatusList());
  29. }
  30. /**
  31. * 添加
  32. *
  33. * @return string
  34. * @throws \think\Exception
  35. */
  36. public function add()
  37. {
  38. if (false === $this->request->isPost()) {
  39. return $this->view->fetch();
  40. }
  41. $params = $this->request->post('row/a');
  42. if (empty($params)) {
  43. $this->error(__('Parameter %s can not be empty', ''));
  44. }
  45. $params = $this->preExcludeFields($params);
  46. //从oss上传到vod
  47. if(!empty($params['video_file'])){
  48. $full_filepath = config('upload.cdnurl').$params['video_file'];
  49. $uploadvideo = new Uploadvideo();
  50. $res = $uploadvideo->testUploadWebVideo($full_filepath,$params['name']);
  51. $params['vodid'] = $res;
  52. }
  53. //从oss上传到vod
  54. if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
  55. $params[$this->dataLimitField] = $this->auth->id;
  56. }
  57. $result = false;
  58. Db::startTrans();
  59. try {
  60. //是否采用模型验证
  61. if ($this->modelValidate) {
  62. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  63. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
  64. $this->model->validateFailException()->validate($validate);
  65. }
  66. $result = $this->model->allowField(true)->save($params);
  67. Db::commit();
  68. } catch (ValidateException|PDOException|Exception $e) {
  69. Db::rollback();
  70. $this->error($e->getMessage());
  71. }
  72. if ($result === false) {
  73. $this->error(__('No rows were inserted'));
  74. }
  75. $this->success();
  76. }
  77. /**
  78. * 编辑
  79. *
  80. * @param $ids
  81. * @return string
  82. * @throws DbException
  83. * @throws \think\Exception
  84. */
  85. public function edit($ids = null)
  86. {
  87. $row = $this->model->get($ids);
  88. if (!$row) {
  89. $this->error(__('No Results were found'));
  90. }
  91. $adminIds = $this->getDataLimitAdminIds();
  92. if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
  93. $this->error(__('You have no permission'));
  94. }
  95. if (false === $this->request->isPost()) {
  96. $this->view->assign('row', $row);
  97. return $this->view->fetch();
  98. }
  99. $params = $this->request->post('row/a');
  100. if (empty($params)) {
  101. $this->error(__('Parameter %s can not be empty', ''));
  102. }
  103. $params = $this->preExcludeFields($params);
  104. //从oss上传到vod
  105. if($row['video_file'] != $params['video_file'] && !empty($params['video_file']) ){
  106. $full_filepath = config('upload.cdnurl').$params['video_file'];
  107. $uploadvideo = new Uploadvideo();
  108. $res = $uploadvideo->testUploadWebVideo($full_filepath,$params['name']);
  109. $params['vodid'] = $res;
  110. }
  111. //从oss上传到vod
  112. $result = false;
  113. Db::startTrans();
  114. try {
  115. //是否采用模型验证
  116. if ($this->modelValidate) {
  117. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  118. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  119. $row->validateFailException()->validate($validate);
  120. }
  121. $result = $row->allowField(true)->save($params);
  122. Db::commit();
  123. } catch (ValidateException|PDOException|Exception $e) {
  124. Db::rollback();
  125. $this->error($e->getMessage());
  126. }
  127. if (false === $result) {
  128. $this->error(__('No rows were updated'));
  129. }
  130. $this->success();
  131. }
  132. }