Added insertPricing & allPricing function

Added insertPricing & allPricing function
This commit is contained in:
cp6 2022-05-15 00:24:05 +10:00
parent 3948dd50db
commit 9204a05654
5 changed files with 30 additions and 41 deletions

View File

@ -63,16 +63,7 @@ class DomainsController extends Controller
$as_usd = $pricing->convertToUSD($request->price, $request->currency);
Pricing::create([
'service_id' => $domain_id,
'service_type' => 4,
'currency' => $request->currency,
'price' => $request->price,
'term' => $request->payment_term,
'as_usd' => $as_usd,
'usd_per_month' => $pricing->costAsPerMonth($as_usd, $request->payment_term),
'next_due_date' => $request->next_due_date,
]);
$pricing->insertPricing(4, $domain_id, $request->currency, $request->price, $request->payment_term, $as_usd, $request->next_due_date);
Domains::create([
'id' => $domain_id,

View File

@ -66,16 +66,7 @@ class ResellerController extends Controller
$as_usd = $pricing->convertToUSD($request->price, $request->currency);
Pricing::create([
'service_id' => $reseller_id,
'service_type' => 3,
'currency' => $request->currency,
'price' => $request->price,
'term' => $request->payment_term,
'as_usd' => $as_usd,
'usd_per_month' => $pricing->costAsPerMonth($as_usd, $request->payment_term),
'next_due_date' => $request->next_due_date,
]);
$pricing->insertPricing(3, $reseller_id, $request->currency, $request->price, $request->payment_term, $as_usd, $request->next_due_date);
if (!is_null($request->dedicated_ip)) {
IPs::insertIP($reseller_id, $request->dedicated_ip);

View File

@ -110,16 +110,7 @@ class ServerController extends Controller
$as_usd = $pricing->convertToUSD($request->price, $request->currency);
Pricing::create([
'service_id' => $server_id,
'service_type' => 1,
'currency' => $request->currency,
'price' => $request->price,
'term' => $request->payment_term,
'as_usd' => $as_usd,
'usd_per_month' => $pricing->costAsPerMonth($as_usd, $request->payment_term),
'next_due_date' => $request->next_due_date,
]);
$pricing->insertPricing(1, $server_id, $request->currency, $request->price, $request->payment_term, $as_usd, $request->next_due_date);
if (!is_null($request->ip1)) {
IPs::insertIP($server_id, $request->ip1);

View File

@ -64,16 +64,7 @@ class SharedController extends Controller
$as_usd = $pricing->convertToUSD($request->price, $request->currency);
Pricing::create([
'service_id' => $shared_id,
'service_type' => 2,
'currency' => $request->currency,
'price' => $request->price,
'term' => $request->payment_term,
'as_usd' => $as_usd,
'usd_per_month' => $pricing->costAsPerMonth($as_usd, $request->payment_term),
'next_due_date' => $request->next_due_date,
]);
$pricing->insertPricing(2, $shared_id, $request->currency, $request->price, $request->payment_term, $as_usd, $request->next_due_date);
Labels::deleteLabelsAssignedTo($shared_id);

View File

@ -4,7 +4,9 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Session;
class Pricing extends Model
{
@ -75,4 +77,27 @@ class Pricing extends Model
{
DB::table('pricings')->where('service_id', '=', $id)->delete();
}
public function insertPricing(int $type, string $server_id, string $currency, float $price, int $term, float $as_usd, string $next_due_date, int $is_active = 1)
{
return self::create([
'service_type' => $type,
'service_id' => $server_id,
'currency' => $currency,
'price' => $price,
'term' => $term,
'as_usd' => $as_usd,
'usd_per_month' => $this->costAsPerMonth($as_usd, $term),
'next_due_date' => $next_due_date,
'active' => ($is_active) ? 1 : 0
]);
}
public static function allPricing()
{
return Cache::remember('all_pricing', now()->addWeek(1), function () {
return DB::table('pricings')
->get();
});
}
}