企业、套餐软删除关联优化
This commit is contained in:
parent
963636927c
commit
96e76f1038
@ -37,8 +37,12 @@ class AddedOrderService extends Service
|
||||
{
|
||||
$limit = $conditions['limit'] ?? 35;
|
||||
|
||||
$res = $this->orderRepository->with(['company:id,name','package:id,name,carrier_operator'])
|
||||
->withConditions($conditions)->applyConditions()->orderBy('order_at', 'desc')->paginate($limit);
|
||||
$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);
|
||||
});
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
@ -15,6 +15,8 @@ class CompanyService extends Service
|
||||
{
|
||||
protected $companyRepository;
|
||||
|
||||
protected $companies;
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*
|
||||
@ -104,4 +106,13 @@ class CompanyService extends Service
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function load($id)
|
||||
{
|
||||
if (!$this->companies) {
|
||||
$this->companies = $this->companyRepository->select(['id', 'name'])->withTrashed()->get()->keyBy('id');
|
||||
}
|
||||
|
||||
return $this->companies[$id];
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,11 @@ use App\Exceptions\NotExistException;
|
||||
use App\Exceptions\NotAllowedException;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use App\Domains\Virtual\Services\CommonService;
|
||||
use App\Domains\Virtual\Services\CompanyService;
|
||||
use App\Domains\Virtual\Services\PackageService;
|
||||
use App\Domains\Virtual\Repositories\OrderRepository;
|
||||
use App\Domains\Virtual\Repositories\CompanyRepository;
|
||||
use App\Domains\Virtual\Repositories\PackageRepository;
|
||||
use App\Domains\Virtual\Repositories\ProductRepository;
|
||||
|
||||
class OrderService extends Service
|
||||
@ -37,14 +41,14 @@ class OrderService extends Service
|
||||
{
|
||||
$limit = $conditions['limit'] ?? 35;
|
||||
|
||||
$res = $this->orderRepository->with(['company:id,name','package:id,name,carrier_operator'])
|
||||
->withConditions($conditions)->applyConditions()->orderBy('order_at', 'desc')->paginate($limit);
|
||||
|
||||
$res = $this->orderRepository->withConditions($conditions)->applyConditions()->orderBy('order_at', 'desc')->paginate($limit);
|
||||
|
||||
$res->map(function ($item) {
|
||||
$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);
|
||||
$item->company = app(CompanyService::class)->load($item->company_id);
|
||||
$item->package = app(PackageService::class)->load($item->package_id);
|
||||
$item->unit_price = floatval(sprintf('%.02f', $item->unit_price/100));
|
||||
$item->total_price = floatval(sprintf('%.02f', $item->total_price/100));
|
||||
$item->custom_price = floatval(sprintf('%.02f', $item->custom_price/100));
|
||||
});
|
||||
|
||||
return $res;
|
||||
|
@ -16,6 +16,8 @@ class PackageService extends Service
|
||||
{
|
||||
protected $packageRepository;
|
||||
|
||||
protected $packages;
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*
|
||||
@ -147,4 +149,13 @@ class PackageService extends Service
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function load($id)
|
||||
{
|
||||
if (!$this->packages) {
|
||||
$this->packages = $this->packageRepository->select(['id', 'name', 'carrier_operator', 'flows', 'service_months'])->withTrashed()->get()->keyBy('id');
|
||||
}
|
||||
|
||||
return $this->packages[$id];
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,8 @@ use App\Models\Virtual\Product;
|
||||
use App\Exceptions\NotExistException;
|
||||
use App\Exceptions\NotAllowedException;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use App\Domains\Virtual\Services\CompanyService;
|
||||
use App\Domains\Virtual\Services\PackageService;
|
||||
use App\Domains\Virtual\Repositories\PackageRepository;
|
||||
use App\Domains\Virtual\Repositories\ProductRepository;
|
||||
|
||||
@ -31,10 +33,11 @@ class ProductService extends Service
|
||||
*/
|
||||
public function index(array $conditions = [])
|
||||
{
|
||||
$list = $this->productRepository->with(['company:id,name', 'package:id,name,carrier_operator'])
|
||||
->withConditions($conditions)->applyConditions()->get();
|
||||
$list = $this->productRepository->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->base_price = sprintf('%.02f', $item->base_price/100);
|
||||
$item->renewal_price = sprintf('%.02f', $item->renewal_price/100);
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user