| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- <?php
- /* * ********************************************************************
- * ProxmoxVPS Product developed. (27.03.19)
- * *
- *
- * CREATED BY MODULESGARDEN -> http://modulesgarden.com
- * CONTACT -> contact@modulesgarden.com
- *
- *
- * This software is furnished under a license and may be used and copied
- * only in accordance with the terms of such license and with the
- * inclusion of the above copyright notice. This software or any other
- * copies thereof may not be provided or otherwise made available to any
- * other person. No title to and ownership of the software is hereby
- * transferred.
- *
- *
- * ******************************************************************** */
- namespace ModulesGarden\ProxmoxAddon\App\Services\Vps;
- use ModulesGarden\ProxmoxAddon\App\Models\Whmcs\CustomField;
- use ModulesGarden\ProxmoxAddon\App\Models\Whmcs\CustomFieldValue;
- use ModulesGarden\ProxmoxAddon\App\Models\Whmcs\Hosting;
- use ModulesGarden\ProxmoxAddon\App\Services\Utility;
- use ModulesGarden\ProxmoxAddon\App\Enum\Vps\ConfigurableOption;
- trait HostingService
- {
- /**
- * @return mixed
- */
- public function getHostingId()
- {
- if (!$this->hostingId)
- {
- $this->hostingId = $this->getWhmcsParamByKey("serviceid");
- }
- return $this->hostingId;
- }
- /**
- * @param mixed $hostingId
- */
- public function setHostingId($hostingId)
- {
- $this->hostingId = $hostingId;
- return $this;
- }
- /**
- * @return Hosting
- */
- public function hosting()
- {
- if ($this->hosting instanceof Hosting)
- {
- return $this->hosting;
- }
- return $this->hosting = Hosting::where("id", $this->getHostingId())->firstOrFail();
- }
- public function isActive()
- {
- return Hosting::ofId($this->getHostingId())->active()->count() == 1;
- }
- public function isSupportedModule()
- {
- return Hosting::ofServerType($this->getHostingId(), "proxmoxVPS")->count() == 1;
- }
- private function getCustomFieldId($fieldName)
- {
- return CustomField::select("id")
- ->where("type", "product")
- ->where("relid", $this->hosting()->packageid)
- ->where("fieldname", "like", $fieldName . "%")
- ->value("id");
- }
- public function customFieldUpdate($name, $value = '')
- {
- $fieldId = $this->getCustomFieldId($name);
- //Update
- if (CustomFieldValue::where('fieldid', $fieldId)->where("relid", $this->getHostingId())->count())
- {
- return CustomFieldValue::where('fieldid', $fieldId)->where("relid", $this->getHostingId())->update(['value' => $value]);
- }
- //Create
- $customFiledValue = new CustomFieldValue();
- $customFiledValue->fill([
- 'fieldid' => $fieldId,
- 'relid' => $this->getHostingId(),
- 'value' => $value
- ]);
- return $customFiledValue->save();
- }
- public function saveUsageLimit()
- {
- //bandwidth
- if ($this->getWhmcsConfigOption(ConfigurableOption::BANDWIDTH))
- {
- $bandwidthMb = $this->getWhmcsConfigOption(ConfigurableOption::BANDWIDTH);
- Utility::unitFormat($bandwidthMb, "gb", 'mb');
- }
- else
- {
- if ($this->getWhmcsConfigOption('Bandwidth Limit'))
- {
- $bandwidthMb = $this->getWhmcsConfigOption('Bandwidth Limit');
- Utility::unitFormat($bandwidthMb, "gb", 'mb');
- }
- else
- {
- if ($this->configuration()->getBandwidth())
- {
- $bandwidthMb = $this->configuration()->getBandwidth();
- Utility::unitFormat($bandwidthMb, "gb", 'mb');
- }
- }
- }
- //disk
- $diskMb = 0;
- if ($this->getWhmcsConfigOption(ConfigurableOption::DISK_SIZE))
- {
- $diskMb = $this->getWhmcsConfigOption(ConfigurableOption::DISK_SIZE);
- Utility::unitFormat($diskMb, $this->configuration()->getDiskUnit(), 'mb');
- }
- else
- {
- if ($this->configuration()->getDiskSize())
- {
- $diskMb = $this->configuration()->getDiskSize();
- Utility::unitFormat($diskMb, "gb", 'mb');
- }
- }
- $this->hosting()->update(['disklimit' => $diskMb, "bwlimit" => $bandwidthMb, "lastupdate" => date("Y-m-d H:i:s")]);
- }
- public function isBandwidthOverageUsage()
- {
- }
- }
|