<?php
namespace Niaoyun\Server;
use Admin\Model\ServerMasterModel;
use Admin\Model\ServerSystemModel;
use Common\Model\ApiCompanyModel;
use Common\Model\CrudModel;
use Common\Model\ActivityModel;
use Common\Model\RenewDegradeModel;
use Common\Model\ServerLineModel;
use Common\Model\ServerModel;
use Common\Model\ServerPortModel;
use Common\Model\ValueAddedGroupModel;
use Common\Type\ServerLine\Functions;
use DateTime;
use Niaoyun\Admin\AdminLog;
use Niaoyun\Common\FixedPriceSetting;
use Niaoyun\Common\IpUseLog;
use Niaoyun\Common\ObjectFactory;
use Niaoyun\Common\TimeGetter;
use Niaoyun\Common\UserFunction;
use Niaoyun\LocalServer\CloudApiLocalUserType;
use Niaoyun\Order\Order;
use Niaoyun\Order\OrderCheck;
use Niaoyun\Order\OrderStatusEnum;
use Niaoyun\Order\OrderType;
use Niaoyun\Promotion\Enum\PromotionDiscount;
use Niaoyun\Promotion\PromotionService;
use Niaoyun\Resources\Resources;
use Niaoyun\User\UserLog;
use Niaoyun\ValueAdded\ValueAddedServer;
use Think\Hook;
use Think\Log;
/**
* 服务器服务类
*
* Created by PhpStorm.
* Email: 2850737288@qq.com
* User: yonh
* Date: 16-8-3
* Time: 11:13
*
* [test app/Test/Controller/Service/ServerService]
*/
class ServerService
{
private $serversLogModel;
private $serversLogExtraModel;
private $serverModel;
private $serverLineModel;
public $error ='';
public $isAdmin =false;
/**
* @var \Common\Model\ApiModel
*/
private $apiModel;
/**
* @var TimeGetter
*/
private $timeGetter; //时间获取器
private $api;
//不能重建时的原因
private static $rebuild_why_not = '';
//不能迁移的原因
private static $move_why_not = '';
public $system_id = '';//用户保存外部传入的操作系统id
public static $server_lock_status= -2;//服务器锁定-2
function __construct(
$serverModel = null,
$serverLineModel = null,
$apiModel = null,
$cloudApi = null
) {
if (is_null($serverModel)) {
$serverModel = M('Servers');
}
if (is_null($serverLineModel)) {
$serverLineModel = M('ServerLine');
}
if (is_null($apiModel)) {
// D这里就有点危险了,是个坑,会实现不同模块下的apiModel类,导致方法的依赖的对象不可控
$apiModel = D('Api');
}
if (is_null($cloudApi)) {
$cloudApi = ObjectFactory::ApiCloudInstance();
}
$this->serverModel = $serverModel;
$this->serverLineModel = $serverLineModel;
$this->apiModel = $apiModel;
$this->api = $cloudApi;
$this->timeGetter = new TimeGetter();
$this->serversLogModel = M('serversLog');
$this->serversLogExtraModel = M('serversLogExtra');
}
/**
* @param $timeGetter TimeGetter
*/
public function setTimeGetter($timeGetter)
{
$this->timeGetter = $timeGetter;
}
/**
* 获取线路列表
* @return mixed
*/
public function getLines()
{
return $this->serverLineModel->select();
}
/**
* 获取最终销售价格销售价格(每月)
*
* @param $line
* @param $cpu
* @param $ram
* @param $bandwidth
* @param $defense
* @param $harddiskSize
* @param $userID 终端会员折扣
* @param $appendIpNum
*
* @return mixed
*/
public function getTotalPrice($line, $cpu, $ram, $bandwidth, $defense, $harddiskSize, $userID = 0,$appendIpNum=0)
{
$price = $this->getOriginalPrice($line, (int)$cpu, (int)$ram, (int)$bandwidth, (int)$defense, $harddiskSize,$appendIpNum);
//价格赋予2位小数
$total = round($price, 2);
return $total;
}
/**
* 获取原价价格(每月的价格)
*
*
* @param $line 线路对象
* @param $cpu
* @param $ram
* @param $bandwidth
* @param $defense
* @param $harddiskSize
* @param $appendIpNum
*
* @return mixed
*/
public function getOriginalPrice($line, $cpu, $ram, $bandwidth, $defense, $harddiskSize,$appendIpNum=0)
{
$costPrice = $this->getCostPrice($line, $cpu, $ram, $bandwidth, $defense, $harddiskSize,$appendIpNum);
$totalPrice = $costPrice * ($line['markup']);
return $totalPrice;
}
//获取线路cpu 内存价格
public function getCpuPrice($line, $cpu, $ram,$system_id='')
{
$cpuPrice = $this->getCpuAndRamPrice($cpu,$ram,$line['id'],$system_id);
if(false === $cpuPrice){
return false;
}else{
return $cpuPrice?$cpuPrice:0;
}
}
public function getDefensePrice($line, $defense)
{
if ($defense > $line['defensefreesize']) {
$defensePrice = ($defense - $line['defensefreesize']) * $line['defenseprice'];
} else {
$defensePrice = 0;
}
return $defensePrice;
}
public function getBandwidthPrice($line, $bandwidth)
{
//新增赠送带宽
//if ($line['bandwidth_free_size'] > 0 && $bandwidth >= $line['bandwidth_free_size']) {
// $bandwidth = ($bandwidth - $line['bandwidth_free_size']);
//}
if($line['bandwidth_free_size'] > 0){
$freeSize = (int)$line['bandwidth_free_size'];
if($bandwidth - $freeSize <=0){
return 0;
}
$bandPrice = $this->getBandwidthOriginalPrice($line, $bandwidth);
$bandFreePrice = $this->getBandwidthOriginalPrice($line, $freeSize);
$bandwidthPrice = $bandPrice-$bandFreePrice;
return $bandwidthPrice>0?$bandwidthPrice:0;
}else{
return $this->getBandwidthOriginalPrice($line, $bandwidth);
}
}
/**
* @param $line
* @param $bandwidth
*
* @return int
* @author xietaotao
*/
private function getBandwidthOriginalPrice($line, $bandwidth){
$bandwidthPrice = 0;
if ($bandwidth == 1) {
$bandwidthPrice += $line['bandwidth1price'];
} elseif ($bandwidth > 1 && $bandwidth <= 2) {
$bandwidthPrice += $line['bandwidth1price'] + $line['bandwidth2price'];
} elseif ($bandwidth > 2 && $bandwidth <= 3) {
$bandwidthPrice += $line['bandwidth1price'] + $line['bandwidth2price'] + $line['bandwidth3price'];
} elseif ($bandwidth > 3 && $bandwidth <= 4) {
$bandwidthPrice += $line['bandwidth1price'] + $line['bandwidth2price'] + $line['bandwidth3price'] + $line['bandwidth4price'];
} elseif ($bandwidth > 4 && $bandwidth <= 5) {
$bandwidthPrice += $line['bandwidth1price'] + $line['bandwidth2price'] + $line['bandwidth3price'] + $line['bandwidth4price'] + $line['bandwidth5price'];
} elseif ($bandwidth > 5) {
$bandwidthPrice += $line['bandwidth1price'] + $line['bandwidth2price'] + $line['bandwidth3price'] + $line['bandwidth4price'] + $line['bandwidth5price'];
$bandwidthPrice += ($bandwidth - 5) * $line['bandwidth6price'];
}
return $bandwidthPrice;
}
public function getHarddiskPrice($line, $harddiskSize)
{
$harddiskPrice = $harddiskSize * $line['harddiskprice'];
return $harddiskPrice;
}
/**
* 获取子ip月价格
* @param $line
* @param $appendIpNum
*
* @return float|int
* @author xietaotao
*/
public function getAppendIpPrice($line, $appendIpNum){
$appendIpPrice = $line['append_ip_price'];
if($appendIpPrice>0){
return $appendIpPrice * $appendIpNum;
}else{
return 0;
}
}
/**获取合作商成本价
*
* @param $line
* @param $cpu
* @param $ram
* @param $bandwidth
* @param $defense
* @param $harddiskSize
* @param $appendIpNum
*
* @return int
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录
ZKEYS公有云管理系统(大陆版) V5.2.2 (13137个子文件)
.babelrc 75B
.banner 121B
php_xxtea.c 6KB
xxtea.c 2KB
config 1KB
config 1KB
config 1KB
config 1KB
config 1KB
config 1KB
config 1KB
config 1KB
config 1KB
config 1KB
config 1KB
config 1KB
config 1KB
config 1KB
config 1KB
config 1KB
config 1KB
config 1KB
web.config 790B
CREDITS 51B
bootstrap.css 134KB
bootstrap.css 124KB
bootstrap.min.css 120KB
bootstrap.min.css 104KB
bootstrap-custom.css 97KB
bootstrap-custom.css 97KB
mui.min.css 74KB
mui.min.css 74KB
mui.min.css 74KB
frame.css 58KB
common.css 56KB
jquery-ui-1.9.2.custom.css 55KB
animate.min.css 54KB
front.css 49KB
front.css 49KB
ucCommon.css 47KB
index.css 46KB
index.css 45KB
bootstrap-theme-ny.css 45KB
ueditor.css 44KB
ueditor.css 44KB
common.css 44KB
index.css 44KB
base.css 43KB
base.css 43KB
video-js.min.css 40KB
video-js.min.css 40KB
bootstrap-theme-ny.min.css 39KB
bootstrap-theme-ny.min.css 39KB
bootstrap-theme-ny.css 39KB
ueditor.min.css 34KB
server.css 33KB
index.css 32KB
20191111.css 31KB
summer2020.css 31KB
summer2020.css 31KB
ucCommon.min.css 31KB
about.css 30KB
home.css 30KB
domain.css-v=201808056.css 27KB
domain.css 27KB
about.css-v=201808057.css 26KB
index.css 26KB
index.css 26KB
bootstrap-theme.css 26KB
index.css 24KB
20210111.css 23KB
bootstrap-theme.min.css 23KB
index.css 23KB
20201111.css 23KB
idc.css-v=201808057.css 23KB
idc.css 23KB
idc.css-v=201808056.css 23KB
bootstrap-responsive.css 22KB
video-js.css 21KB
video-js.css 21KB
icp.css 20KB
icp.css 20KB
aipage.css 19KB
host.css 19KB
summer2020group.css 19KB
summer2020group.css 19KB
20191111group.css 19KB
image.css 19KB
image.css 19KB
main.min.css 18KB
index.css 18KB
buy.css 18KB
help.css 17KB
swiper.min.css 17KB
tradeApply.css 17KB
tradeSearch.css 17KB
tradeApply.css 16KB
bootstrap-responsive.min.css 16KB
renzheng.css-v=201808056.css 16KB
renzheng.css-v=201808057.css 16KB
共 13137 条
- 1
- 2
- 3
- 4
- 5
- 6
- 132
小小玫瑰大智慧
- 粉丝: 35
- 资源: 185
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0