Voteplayer.php 4.8 KB

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