用静态方法

This commit is contained in:
邓皓元 2019-02-22 17:58:15 +08:00
parent c5039efba8
commit d903b128fc
11 changed files with 42 additions and 41 deletions

View File

@ -93,7 +93,7 @@ class OrderController extends Controller
$orderStatues = $dicts->get('order_status');
$transactionStatuses = $dicts->get('company_transaction_status');
$order->package = app(PackageService::class)->load($order->package_id);
$order->package = PackageService::load($order->package_id);
$order->pay_channel = CommonService::namePayChannel($order->pay_channel);
$order->carrier_operator = $carrierOperators[$order->package->carrier_operator];

View File

@ -82,8 +82,8 @@ class CompanyReportDetailExport extends AbstractExport implements FromQuery, Wit
$array = [];
foreach ($rows as $item) {
$company = app(CompanyService::class)->load($item->company_id);
$package = app(PackageService::class)->load($item->package_id);
$company = CompanyService::load($item->company_id);
$package = PackageService::load($item->package_id);
$month_price = $item->unit_price / $package['service_months'];
$array[] = [

View File

@ -4,6 +4,7 @@ namespace App\Domains\Stats\Services;
use App\Dicts;
use App\Core\Service;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use App\Domains\Virtual\Services\CompanyService;
use App\Domains\Virtual\Services\PackageService;
use App\Domains\Virtual\Services\ProductService;
@ -53,8 +54,8 @@ class CompanyReportService extends Service
$res = $query->paginate($conditions['limit']);
$res->map(function ($item) {
$company = app(CompanyService::class)->load($item->company_id);
$package = app(PackageService::class)->load($item->package_id);
$company = CompanyService::load($item->company_id);
$package = PackageService::load($item->package_id);
$item->company_name = $company['name'];
$item->package_name = $package['name'];
$item->service_months = $package['service_months'] ?? 1;
@ -94,8 +95,8 @@ class CompanyReportService extends Service
$carrierOperators = app(Dicts::class)->get('carrier_operator');
$res->map(function ($item) use ($carrierOperators) {
$company = app(CompanyService::class)->load($item->company_id);
$package = app(PackageService::class)->load($item->package_id);
$company = CompanyService::load($item->company_id);
$package = PackageService::load($item->package_id);
$item->company_name = $company['name'];
$item->package_name = $package['name'];
$item->carrier_operator_name = $carrierOperators[$package['carrier_operator']];

View File

@ -82,8 +82,8 @@ class OrderController extends Controller
$orderStatues = $dicts->get('order_status');
$transactionStatuses = $dicts->get('transaction_status');
$company = app(CompanyService::class)->load($order->company_id);
$package = app(PackageService::class)->load($order->package_id);
$company = CompanyService::load($order->company_id);
$package = PackageService::load($order->package_id);
$order->company_name = $company['name'];
$order->package_name = $package['name'];

View File

@ -26,7 +26,7 @@ class AddedOrderService extends Service
{
$this->orderRepository = $orderRepository;
}
/**
* 订单列表
*
@ -40,8 +40,8 @@ class AddedOrderService extends Service
$res = $this->orderRepository->withConditions($conditions)->applyConditions()->orderBy('order_at', 'desc')->paginate($limit);
$res->map(function ($item) {
$item->company = app(CompanyService::class)->load($item->company_id);
$item->package = app(PackageService::class)->load($item->package_id);
$item->company = CompanyService::load($item->company_id);
$item->package = PackageService::load($item->package_id);
});
return $res;
@ -122,12 +122,12 @@ class AddedOrderService extends Service
}
Validator::validate($attributes, $rule, $message);
if (!$attributes['id']) {
if (!$product = app(ProductRepository::class)->withConditions(['id' => $attributes['product_id']])->first()) {
throw new NotExistException('套餐不存在或已删除');
}
if ($product->company_id != $attributes['company_id']) {
throw new NotAllowedException('非法操作');
}
@ -152,7 +152,7 @@ class AddedOrderService extends Service
$this->orderRepository->setModel($node)->update($attributes);
}
return $node;
}

View File

@ -69,7 +69,7 @@ class CardService extends Service
try {
foreach ($_timelines as &$timeline) {
$package = app(PackageService::class)->load($timeline['package_id']);
$package = PackageService::load($timeline['package_id']);
$timeline['type_name'] = self::$typeNames[$timeline['type']];
$timeline['name'] = $package['name'];
$timeline['service_start_at'] = Carbon::parse($timeline['service_start_at'])->format('Y-m');
@ -79,8 +79,8 @@ class CardService extends Service
throw $e;
}
$company = app(CompanyService::class)->load($item->company_id);
$package = app(PackageService::class)->load($item->package_id);
$company = CompanyService::load($item->company_id);
$package = PackageService::load($item->package_id);
$service_start_at = empty($_timelines) ? '' : min(array_pluck($_timelines, 'service_start_at'));
$service_end_at = empty($_timelines) ? '' : max(array_pluck($_timelines, 'service_end_at'));

View File

@ -15,7 +15,7 @@ class CompanyService extends Service
{
protected $companyRepository;
protected $companies;
protected static $companies;
/**
* 构造函数
@ -107,12 +107,12 @@ class CompanyService extends Service
return true;
}
public function load($id)
public static function load($id)
{
if (!$this->companies) {
$this->companies = $this->companyRepository->select(['id', 'name', 'status'])->withTrashed()->get()->keyBy('id');
if (!self::$companies) {
self::$companies = app(CompanyRepository::class)->select(['id', 'name', 'status'])->withTrashed()->get()->keyBy('id');
}
return $this->companies[$id];
return self::$companies[$id];
}
}

View File

@ -31,7 +31,7 @@ class FlowPoolService extends Service
protected $flowPoolSettingRepository;
protected $flowPoolCardRepository;
protected $pools;
protected static $pools;
/**
* 构造函数
@ -98,7 +98,7 @@ class FlowPoolService extends Service
])->withConditions(['pool_id' => $flowPools->pluck('id')->toArray()])->groupBy(['pool_id', 'package_id'])->get();
$packages->map(function ($item) {
$item->package_name = app(PackageService::class)->load($item->package_id)['name'];
$item->package_name = PackageService::load($item->package_id)['name'];
});
$packages = $packages->groupBy('pool_id');
@ -138,7 +138,7 @@ class FlowPoolService extends Service
$shares = app(Dicts::class)->get('shares');
$flowPools->map(function ($item) use ($carrierOperators, $shares, $packages, $settings, $setting_status) {
$item->company_name = app(CompanyService::class)->load($item['company_id'])['name'];
$item->company_name = CompanyService::load($item['company_id'])['name'];
$item->carrier_operator_name = $carrierOperators[$item['carrier_operator']];
$item->shared_name = $shares[$item['shared']];
$item->real_pool_ids = empty($item->real_pool_ids) ? [] : $item->real_pool_ids;
@ -450,7 +450,7 @@ class FlowPoolService extends Service
}
$cards->map(function ($item) use ($minimum_flows) {
$item->package_name = app(PackageService::class)->load($item->package_id)['name'];
$item->package_name = PackageService::load($item->package_id)['name'];
$item->minimum_flows = $minimum_flows[$item->package_id] ?? 0;
});
@ -471,7 +471,7 @@ class FlowPoolService extends Service
$packages = $this->flowPoolCardRepository->select(['pool_id', 'package_id'])->withConditions(['pool_id' => $pool_id])->groupBy(['pool_id', 'package_id'])->get();
$packages->map(function ($item) {
$item->package_name = app(PackageService::class)->load($item->package_id)['name'];
$item->package_name = PackageService::load($item->package_id)['name'];
});
$flowPool->setting_status = 0;
@ -511,12 +511,12 @@ class FlowPoolService extends Service
return sprintf('FP%011d', $id);
}
public function load($id)
public static function load($id)
{
if (!$this->pools) {
$this->pools = $this->flowPoolRepository->withTrashed()->get()->keyBy('id');
if (!self::$pools) {
self::$pools = app(FlowPoolRepository::class)->withTrashed()->get()->keyBy('id');
}
return $this->pools[$id];
return self::$pools[$id];
}
}

View File

@ -52,8 +52,8 @@ class OrderService extends Service
])->withConditions($conditions)->groupBy('order_id')->get()->keyBy('order_id');
$res->map(function ($item) use ($orderShipments) {
$item->company = app(CompanyService::class)->load($item->company_id);
$item->package = app(PackageService::class)->load($item->package_id);
$item->company = CompanyService::load($item->company_id);
$item->package = PackageService::load($item->package_id);
$item->unit_price = sprintf('%.02f', $item->unit_price/100);
$item->total_price = sprintf('%.02f', $item->total_price/100);
$item->custom_price = sprintf('%.02f', $item->custom_price/100);

View File

@ -16,7 +16,7 @@ class PackageService extends Service
{
protected $packageRepository;
protected $packages;
protected static $packages;
/**
* 构造函数
@ -156,12 +156,12 @@ class PackageService extends Service
return true;
}
public function load($id)
public static function load($id)
{
if (!$this->packages) {
$this->packages = $this->packageRepository->select(['id', 'name', 'carrier_operator', 'flows', 'service_months', 'status'])->withTrashed()->get()->keyBy('id');
if (!self::$packages) {
self::$packages = app(PackageRepository::class)->select(['id', 'name', 'carrier_operator', 'flows', 'service_months', 'status'])->withTrashed()->get()->keyBy('id');
}
return $this->packages[$id];
return self::$packages[$id];
}
}

View File

@ -43,8 +43,8 @@ class ProductService extends Service
})->withConditions($conditions)->applyConditions()->get();
$list->map(function ($item) {
$item->company = app(CompanyService::class)->load($item->company_id);
$item->package = app(PackageService::class)->load($item->package_id);
$item->company = CompanyService::load($item->company_id);
$item->package = PackageService::load($item->package_id);
$item->base_price = sprintf('%.02f', $item->base_price/100);
$item->renewal_price = sprintf('%.02f', $item->renewal_price/100);
$item->status = $item['package']['status'] ? 1 : $item->status;