|
@@ -9,6 +9,7 @@ use Illuminate\Support\Facades\DB;
|
|
use Modules\Common\Errors\Errors;
|
|
use Modules\Common\Errors\Errors;
|
|
use Modules\Common\Exceptions\CommonBusinessException;
|
|
use Modules\Common\Exceptions\CommonBusinessException;
|
|
use Modules\User\Models\User;
|
|
use Modules\User\Models\User;
|
|
|
|
+use Modules\Video\Services\VideoService;
|
|
|
|
|
|
class VideoController extends CatchController
|
|
class VideoController extends CatchController
|
|
{
|
|
{
|
|
@@ -25,8 +26,12 @@ class VideoController extends CatchController
|
|
$videoName = $request->input('videoName');
|
|
$videoName = $request->input('videoName');
|
|
$updateType = $request->input('updateType');
|
|
$updateType = $request->input('updateType');
|
|
$categoryId = $request->input('categoryId');
|
|
$categoryId = $request->input('categoryId');
|
|
|
|
+ $videoId = $request->input('videoId');
|
|
|
|
|
|
$videos = DB::table('videos')
|
|
$videos = DB::table('videos')
|
|
|
|
+ ->when($videoId, function ($query, $videoId){
|
|
|
|
+ return $query->where('id', $videoId);
|
|
|
|
+ })
|
|
->when($videoName, function ($query, $videoName){
|
|
->when($videoName, function ($query, $videoName){
|
|
return $query->where('name', 'like', '%'. $videoName . '%');
|
|
return $query->where('name', 'like', '%'. $videoName . '%');
|
|
})->when($updateType, function ($query, $updateType){
|
|
})->when($updateType, function ($query, $updateType){
|
|
@@ -35,7 +40,7 @@ class VideoController extends CatchController
|
|
return $query->where('category_id', $categoryId);
|
|
return $query->where('category_id', $categoryId);
|
|
})->orderBy('id', 'desc')
|
|
})->orderBy('id', 'desc')
|
|
->paginate($request->integer('per_page', 15));
|
|
->paginate($request->integer('per_page', 15));
|
|
- $userContext = $this->getUserContext($request);
|
|
+ $userContext = $this->getUserContext($request->input('operateUserIdßßß'));
|
|
$allVideoCategory = DB::table('video_category')
|
|
$allVideoCategory = DB::table('video_category')
|
|
->get()->keyBy('id');
|
|
->get()->keyBy('id');
|
|
foreach ($videos as $video) {
|
|
foreach ($videos as $video) {
|
|
@@ -58,12 +63,13 @@ class VideoController extends CatchController
|
|
'chargeType' => 'required|integer|in:1',
|
|
'chargeType' => 'required|integer|in:1',
|
|
'chargeSequence' => 'required|integer|min:1|max:30'
|
|
'chargeSequence' => 'required|integer|min:1|max:30'
|
|
]);
|
|
]);
|
|
- $userContext = $this->getUserContext($request);
|
|
+ $userContext = $this->getUserContext($request->input('operateUserId'));
|
|
- if($userContext['loginUserRoles']->diff(['administrator', 'optimizer'])->isEmpty()) {
|
|
+ if(!(1 == $userContext['loginUser']->id ||
|
|
|
|
+ $userContext['loginUserRoles']->diff(['administrator', 'optimizer'])->isNotEmpty())) {
|
|
CommonBusinessException::throwError(Errors::NO_OPERATE_PERMISSION);
|
|
CommonBusinessException::throwError(Errors::NO_OPERATE_PERMISSION);
|
|
}
|
|
}
|
|
$now = date('Y-m-d H:i:s');
|
|
$now = date('Y-m-d H:i:s');
|
|
- if($userContext['loginUserRoles']->contains('administrator')) {
|
|
+ if($userContext['loginUserRoles']->contains('administrator') || 1 == $userContext['loginUser']->id) {
|
|
DB::table('videos')
|
|
DB::table('videos')
|
|
->where('id', $request->input('id'))
|
|
->where('id', $request->input('id'))
|
|
->update([
|
|
->update([
|
|
@@ -147,10 +153,7 @@ class VideoController extends CatchController
|
|
$id = $request->input('id');
|
|
$id = $request->input('id');
|
|
$data = $request->except('id', 'shelf_at');
|
|
$data = $request->except('id', 'shelf_at');
|
|
$data['updated_at'] = date('Y-m-d H:i:s');
|
|
$data['updated_at'] = date('Y-m-d H:i:s');
|
|
- $video = DB::table('videos')->where('id', $id)->first();
|
|
+ $video = VideoService::getVideoByIdOrException($request->input('id'));
|
|
- if(!$video) {
|
|
|
|
- CommonBusinessException::throwError(Errors::VIDEO_NOT_EXISTS);
|
|
|
|
- }
|
|
|
|
if(2 == $request->integer('shelf_type') && 1 == $video->shelf_type) {
|
|
if(2 == $request->integer('shelf_type') && 1 == $video->shelf_type) {
|
|
$data['shelf_at'] = $data['updated_at'];
|
|
$data['shelf_at'] = $data['updated_at'];
|
|
}
|
|
}
|
|
@@ -161,57 +164,12 @@ class VideoController extends CatchController
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- private function getUserContext(Request $request) {
|
|
|
|
- $loginUser = $this->getLoginUser();
|
|
|
|
- $loginUserRoles = $this->listUserRoles();
|
|
|
|
- $operateUserId = $request->input('operateUserId');
|
|
|
|
- if($operateUserId) {
|
|
|
|
- $operateUser = User::find($operateUserId);
|
|
|
|
- $operateUserRoles = $operateUser->roles->pluck('identify');
|
|
|
|
- if($loginUser->id != $operateUser->pid) {
|
|
|
|
- CommonBusinessException::throwError(Errors::NO_OPERATE_PERMISSION);
|
|
|
|
- }
|
|
|
|
- if(!$operateUserRoles->contains('optimizer')) {
|
|
|
|
- CommonBusinessException::throwError(Errors::NO_OPERATE_PERMISSION);
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- $operateUser = $loginUser;
|
|
|
|
- $operateUserRoles = $loginUserRoles;
|
|
|
|
- }
|
|
|
|
|
|
|
|
- return compact('loginUser', 'loginUserRoles', 'operateUserRoles', 'operateUser');
|
|
|
|
- }
|
|
|
|
private function updateVideoInfo($video, $userContext) {
|
|
private function updateVideoInfo($video, $userContext) {
|
|
- if($userContext['loginUserRoles']->contains('administrator')) {
|
|
+ VideoService::updateVideoChargeInfo($video, $userContext);
|
|
- $video->charge_sequence = $video->d_charge_sequence;
|
|
|
|
- $video->charge_coin = $video->d_charge_coin;
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- if($userContext['loginUserRoles']->contains('company')) {
|
|
|
|
- if($userContext['loginUser']->id == $userContext['operateUser']->id) {
|
|
|
|
- $video->charge_sequence = $video->d_charge_sequence;
|
|
|
|
- $video->charge_coin = $video->d_charge_coin;
|
|
|
|
- return;
|
|
|
|
- } else {
|
|
|
|
- $videoUserConfig = $this->getVideoUserConfig($userContext['operateUser']->id, $video->id);
|
|
|
|
- $video->charge_sequence = $videoUserConfig->charge_sequence ?? $video->d_charge_sequence;
|
|
|
|
- $video->charge_coin = $videoUserConfig->charge_coin ?? $video->d_charge_coin;
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if($userContext['loginUserRoles']->contains('optimizer')) {
|
|
|
|
- $videoUserConfig = $this->getVideoUserConfig($userContext['loginUser']->id, $video->id);
|
|
|
|
- $video->charge_sequence = $videoUserConfig->charge_sequence ?? $video->d_charge_sequence;
|
|
|
|
- $video->charge_coin = $videoUserConfig->charge_coin ?? $video->d_charge_coin;
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- private function getVideoUserConfig($uid, $videoId) {
|
|
|
|
- return DB::table('video_user_config')
|
|
|
|
- ->where(['is_enabled' => 1, 'uid' => $uid, 'video_id' => $videoId])->first();
|
|
|
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
private function getCategoryStr($allCategory,$categoryId) {
|
|
private function getCategoryStr($allCategory,$categoryId) {
|
|
$category = $allCategory->get($categoryId);
|
|
$category = $allCategory->get($categoryId);
|