mirror of
https://github.com/Bigherollc/wticreatorstudio.git
synced 2026-10-20 12:03:29 -04:00
Subscription Module Update
Payment Codes for china team
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Subscription\Repositories;
|
||||
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Modules\Subscription\Entities\PaymentCode;
|
||||
use Modules\Subscription\Entities\PaymentCodeAddon;
|
||||
|
||||
class PaymentCodeRepository
|
||||
{
|
||||
|
||||
public function all() {
|
||||
return PaymentCode::with(['user','planPrice.plan','addons'])->withSum('addons', 'price')->orderBy('id')->get();
|
||||
}
|
||||
|
||||
public function create($request) {
|
||||
$data = $request->except('_token');
|
||||
|
||||
$total = 0;
|
||||
$paymentCode = PaymentCode::create($data);
|
||||
if($data['addons'] != null){
|
||||
$paymentCode->addons()->createMany($data['addons']);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function update($request) {
|
||||
$data = $request->except('_token');
|
||||
|
||||
$paymentCode = PaymentCode::find($data['id']);
|
||||
if($paymentCode){
|
||||
$paymentCode->update($data);
|
||||
|
||||
foreach ($data['addons'] as $key => $addon) {
|
||||
$paymentCode->addons()->updateOrCreate(
|
||||
[
|
||||
'id' => $addon['id'] ?? null,
|
||||
],
|
||||
$addon
|
||||
);
|
||||
}
|
||||
|
||||
$addOnsId = collect($data['addons'])->pluck('id')->toArray();
|
||||
$paymentCode->addons()->whereNotIn('id', $addOnsId)->delete();
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user