mirror of
https://github.com/Bigherollc/wticreatorstudio.git
synced 2026-08-02 03:16:27 -04:00
Updated to latest
This commit is contained in:
@@ -59,6 +59,7 @@ use Modules\StudioPlus\Jobs\ApplyWatermark;
|
||||
use Modules\StudioPlus\Jobs\ApplyWatermarkNewServer;
|
||||
use Modules\StudioPlus\Jobs\UpdateVideoMeta;
|
||||
use Modules\StudioPlus\Services\WatermarkService;
|
||||
use Modules\StudioPlus\Services\VideoInvoice;
|
||||
|
||||
class StudioPlusVideoController extends Controller
|
||||
{
|
||||
@@ -69,11 +70,7 @@ class StudioPlusVideoController extends Controller
|
||||
private $googleApiEndpoint;
|
||||
private $bucket;
|
||||
|
||||
public function __construct(
|
||||
private InvoiceRepository $invoiceRepository,
|
||||
private InvoiceSettingRepository $invoiceSettingRepository,
|
||||
private InvoiceSettingService $invoiceSettingService
|
||||
) {
|
||||
public function __construct() {
|
||||
$this->storageClient = new StorageClient([
|
||||
'keyFile' => json_decode(file_get_contents(module_path('StudioPlus', 'google-cloud-platform.json')), true)
|
||||
]);
|
||||
@@ -377,7 +374,7 @@ class StudioPlusVideoController extends Controller
|
||||
$validated['amazon_total_reviews'] = Arr::get((new AmazonProductService)->getASINReviews($validated['asin']), 'total_reviews') ?? 0;
|
||||
$studioPlusVideo->update($validated);
|
||||
|
||||
$this->addIncentiveItem($studioPlusVideo);
|
||||
(new VideoInvoice())->addIncentiveItem($studioPlusVideo);
|
||||
|
||||
if ($request->filled('thumbnail_id')) {
|
||||
$studioPlusVideo->thumbnails()
|
||||
@@ -446,7 +443,7 @@ class StudioPlusVideoController extends Controller
|
||||
'name' => $validated['status']
|
||||
]);
|
||||
|
||||
$this->addIncentiveItem($studioPlusVideo);
|
||||
(new VideoInvoice())->addIncentiveItem($studioPlusVideo);
|
||||
DB::commit();
|
||||
|
||||
//return response()->noContent();
|
||||
@@ -457,6 +454,7 @@ class StudioPlusVideoController extends Controller
|
||||
} catch (\Exception $ex) {
|
||||
DB::rollBack();
|
||||
|
||||
dd($ex->getMessage());
|
||||
//throw new \Exception($ex->getMessage());
|
||||
return response()->json([
|
||||
'message' => 'Failed to update status.'
|
||||
@@ -471,81 +469,6 @@ class StudioPlusVideoController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
private function isValidStatus(StudioPlusVideo $studioPlusVideo): bool
|
||||
{
|
||||
return in_array($studioPlusVideo->status, [StudioPlusVideo::STATUS_PUBLISHED, StudioPlusVideo::STATUS_AMAZON_APPROVED, StudioPlusVideo::STATUS_AMAZON_UPLOADED]);
|
||||
}
|
||||
|
||||
private function addIncentiveItem(StudioPlusVideo $studioPlusVideo): void
|
||||
{
|
||||
if (!InvoiceSettingService::isValidUserRole($studioPlusVideo->channel->user)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->isValidStatus($studioPlusVideo)) {
|
||||
$studioPlusVideo = $studioPlusVideo->load('asinData');
|
||||
$user = $studioPlusVideo->channel->user;
|
||||
|
||||
$latestInvoiceNumber = $this->invoiceSettingService->getLatestInvoiceNumber($user);
|
||||
$invoice = $this->invoiceRepository->getInvoiceOfMonth($user, $latestInvoiceNumber);
|
||||
|
||||
$invoice->items()->updateOrCreate(
|
||||
[
|
||||
'studio_plus_video_id' => $studioPlusVideo->id,
|
||||
],
|
||||
[
|
||||
'item_no' => 1,
|
||||
'name' => 'Video upload payout',
|
||||
'description' => "ASIN {$studioPlusVideo->asin}",
|
||||
'amount' => $studioPlusVideo->asinData->payout_amount,
|
||||
'quantity' => 1,
|
||||
'issue_date' => now()->toDateString(),
|
||||
'type' => InvoiceItem::TYPE_VIDEO_UPLOAD_PAYOUT,
|
||||
'range_amount' => $studioPlusVideo->asinData->range_amount
|
||||
]
|
||||
);
|
||||
|
||||
$this->addIncentiveItemToUpline($user, $studioPlusVideo);
|
||||
} else {
|
||||
InvoiceItem::query()
|
||||
->where('studio_plus_video_id', $studioPlusVideo->id)
|
||||
->delete();
|
||||
}
|
||||
}
|
||||
|
||||
private function addIncentiveItemToUpline(User $user, StudioPlusVideo $studioPlusVideo): void
|
||||
{
|
||||
if (!$user->parent_id) return;
|
||||
|
||||
$incentive = StudioPlusIncentive::query()
|
||||
->where('description', '$1 per video from Team Members')
|
||||
->first();
|
||||
|
||||
if (!$incentive) return;
|
||||
|
||||
$parentUser = User::query()
|
||||
->where('id', $user->parent_id)
|
||||
->first();
|
||||
|
||||
$latestInvoiceNumber = $this->invoiceSettingService->getLatestInvoiceNumber($parentUser);
|
||||
$invoice = $this->invoiceRepository->getInvoiceOfMonth($parentUser, $latestInvoiceNumber);
|
||||
|
||||
$invoice->items()->updateOrCreate(
|
||||
[
|
||||
'studio_plus_video_id' => $studioPlusVideo->id,
|
||||
],
|
||||
[
|
||||
'item_no' => 1,
|
||||
'name' => 'Downline Incentives',
|
||||
'description' => "Downline bonus ({$user->first_name})",
|
||||
'amount' => $incentive->amount_value_earned,
|
||||
'quantity' => 1,
|
||||
'issue_date' => now()->toDateString(),
|
||||
'type' => InvoiceItem::TYPE_DOWNLINE_INCENTIVES,
|
||||
'range_amount' => $studioPlusVideo->asinData->range_amount
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function statistics(Request $request)
|
||||
{
|
||||
@@ -909,7 +832,7 @@ class StudioPlusVideoController extends Controller
|
||||
|
||||
$video->update($validated);
|
||||
|
||||
$this->addIncentiveItem($video);
|
||||
(new VideoInvoice())->addIncentiveItem($video);
|
||||
|
||||
if ($request->filled('thumbnail_id')) {
|
||||
$video->thumbnails()
|
||||
@@ -1000,9 +923,9 @@ class StudioPlusVideoController extends Controller
|
||||
'studio_plus_asin_id' => ['required_without:is_short'],
|
||||
'job_request_id' => $request->video_type['need_job_request'] ? ['required', 'exists:job_requests,id'] : ['nullable'],
|
||||
'title' => ['required'],
|
||||
'asin' => ['required'],
|
||||
'product_name' => ['required'],
|
||||
'brand' => ['required']
|
||||
'asin' => $request->video_type['need_job_request'] ? ['required'] : ['nullable'],
|
||||
'product_name' => $request->video_type['need_job_request'] ? ['required'] : ['nullable'],
|
||||
'brand' => $request->video_type['need_job_request'] ? ['required'] : ['nullable'],
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user