导入优化
This commit is contained in:
parent
774722e80f
commit
801343f9b3
@ -41,9 +41,7 @@ class ArtisanController extends Controller
|
||||
*/
|
||||
public function call()
|
||||
{
|
||||
set_time_limit(0);
|
||||
ini_set('memory_limit', '4096m');
|
||||
ini_set('default_socket_timeout', -1);
|
||||
begin_time_consuming();
|
||||
|
||||
$command = $this->request->get('command');
|
||||
$parameters = $this->request->get('parameters', []);
|
||||
|
@ -24,9 +24,7 @@ class Command extends BaseCommand
|
||||
{
|
||||
$this->line('开始'.$this->description);
|
||||
|
||||
set_time_limit(0);
|
||||
ini_set('memory_limit', '4096m');
|
||||
ini_set('default_socket_timeout', -1);
|
||||
begin_time_consuming();
|
||||
|
||||
parent::execute($input, $output);
|
||||
}
|
||||
|
@ -79,9 +79,7 @@ class OrderService extends Service
|
||||
*/
|
||||
public function cards(array $conditions = [])
|
||||
{
|
||||
set_time_limit(0);
|
||||
ini_set('memory_limit', '4096m');
|
||||
ini_set('default_socket_timeout', -1);
|
||||
begin_time_consuming();
|
||||
|
||||
$counts = $this->orderCardPartitionRepository->withConditions($conditions)->sum('counts');
|
||||
|
||||
|
@ -31,9 +31,7 @@ class CompanyReportService extends Service
|
||||
*/
|
||||
public function index(array $conditions = [])
|
||||
{
|
||||
set_time_limit(0);
|
||||
ini_set('memory_limit', '4096m');
|
||||
ini_set('default_socket_timeout', -1);
|
||||
begin_time_consuming();
|
||||
|
||||
$select = [
|
||||
'company_id',
|
||||
|
@ -24,9 +24,7 @@ class Command extends BaseCommand
|
||||
{
|
||||
$this->line('开始'.$this->description);
|
||||
|
||||
set_time_limit(0);
|
||||
ini_set('memory_limit', '4096m');
|
||||
ini_set('default_socket_timeout', -1);
|
||||
begin_time_consuming();
|
||||
|
||||
parent::execute($input, $output);
|
||||
}
|
||||
|
@ -298,33 +298,32 @@ class FlowPoolController extends Controller
|
||||
*/
|
||||
public function importFlows()
|
||||
{
|
||||
begin_time_consuming();
|
||||
|
||||
$file = $this->request->file('file');
|
||||
$data = ImportService::load($file, ['month', 'pool_id', 'sim', 'mebibyte']);
|
||||
|
||||
Validator::validate($data, [
|
||||
'*.month' => ['required', 'numeric'],
|
||||
'*.pool_id' => ['required', 'numeric'],
|
||||
'*.sim' => ['required', 'numeric'],
|
||||
'*.mebibyte' => ['required', 'numeric'],
|
||||
], [
|
||||
'*.month.required' => '字段month不能为空',
|
||||
'*.month.numeric' => '字段month必须为数字',
|
||||
'*.pool_id.required' => '字段pool_id不能为空',
|
||||
'*.pool_id.numeric' => '字段pool_id必须为数字',
|
||||
'*.sim.required' => '字段sim不能为空',
|
||||
'*.sim.numeric' => '字段sim必须为数字',
|
||||
'*.mebibyte.required' => '字段mebibyte不能为空',
|
||||
'*.mebibyte.numeric' => '字段mebibyte必须为数字',
|
||||
]);
|
||||
foreach ($data as $row) {
|
||||
foreach (['month', 'pool_id', 'sim', 'mebibyte'] as $key) {
|
||||
if (!isset($row[$key])) {
|
||||
throw new InvalidArgumentException("字段{$row[$key]}不能为空");
|
||||
}
|
||||
|
||||
if (!is_numeric($row[$key])) {
|
||||
throw new InvalidArgumentException("字段{$row[$key]}必须为数字");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$flowPools = app(FlowPoolRepository::class)->withConditions(['id' => array_unique(array_pluck($data, 'pool_id'))])->get()->keyBy('id')->toArray();
|
||||
|
||||
$simPackage = [];
|
||||
|
||||
foreach (array_chunk($data, 1000) as $value) {
|
||||
foreach (array_chunk($data, 10000) as $value) {
|
||||
$cards = app(OrderCardPartitionRepository::class)->select(['sim', 'package_id'])->withConditions([
|
||||
'type' => 0,
|
||||
'type' => [0, 1, 2],
|
||||
'sim' => array_pluck($value, 'sim'),
|
||||
'now' => 1,
|
||||
])->get()->pluck('package_id', 'sim')->toArray();
|
||||
|
||||
foreach ($cards as $sim => $package_id) {
|
||||
|
@ -124,6 +124,15 @@ trait OrderCardConcern
|
||||
$relation->where('transaction_no', 'like', "%{$conditions['transaction_no']}%");
|
||||
});
|
||||
}
|
||||
|
||||
if ($conditions['now']) {
|
||||
$query->where(function ($subQuery) {
|
||||
$subQuery->where(function ($timeQuery) {
|
||||
$timeQuery->where('service_start_at', '<=', Carbon::now())
|
||||
->where('service_end_at', '>=', Carbon::now());
|
||||
})->orWhereNull('service_start_at');
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
if (isset($conditions['card_status'])) {
|
||||
|
@ -6,6 +6,19 @@ use Dipper\Foundation\Support\Time;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use App\Domains\Account\Services\AccountService;
|
||||
|
||||
if (! function_exists('begin_time_consuming')) {
|
||||
/**
|
||||
* 初始化耗时任务
|
||||
*
|
||||
*/
|
||||
function begin_time_consuming()
|
||||
{
|
||||
set_time_limit(0);
|
||||
ini_set('memory_limit', '4096m');
|
||||
ini_set('default_socket_timeout', -1);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('cdn')) {
|
||||
/**
|
||||
* 生成CDN链接, 可带时间戳防盗链
|
||||
|
Loading…
x
Reference in New Issue
Block a user