导入优化

This commit is contained in:
邓皓元 2019-04-22 09:30:02 +08:00
parent 774722e80f
commit 801343f9b3
8 changed files with 43 additions and 32 deletions

View File

@ -41,9 +41,7 @@ class ArtisanController extends Controller
*/ */
public function call() public function call()
{ {
set_time_limit(0); begin_time_consuming();
ini_set('memory_limit', '4096m');
ini_set('default_socket_timeout', -1);
$command = $this->request->get('command'); $command = $this->request->get('command');
$parameters = $this->request->get('parameters', []); $parameters = $this->request->get('parameters', []);

View File

@ -24,9 +24,7 @@ class Command extends BaseCommand
{ {
$this->line('开始'.$this->description); $this->line('开始'.$this->description);
set_time_limit(0); begin_time_consuming();
ini_set('memory_limit', '4096m');
ini_set('default_socket_timeout', -1);
parent::execute($input, $output); parent::execute($input, $output);
} }

View File

@ -79,9 +79,7 @@ class OrderService extends Service
*/ */
public function cards(array $conditions = []) public function cards(array $conditions = [])
{ {
set_time_limit(0); begin_time_consuming();
ini_set('memory_limit', '4096m');
ini_set('default_socket_timeout', -1);
$counts = $this->orderCardPartitionRepository->withConditions($conditions)->sum('counts'); $counts = $this->orderCardPartitionRepository->withConditions($conditions)->sum('counts');

View File

@ -31,9 +31,7 @@ class CompanyReportService extends Service
*/ */
public function index(array $conditions = []) public function index(array $conditions = [])
{ {
set_time_limit(0); begin_time_consuming();
ini_set('memory_limit', '4096m');
ini_set('default_socket_timeout', -1);
$select = [ $select = [
'company_id', 'company_id',

View File

@ -24,9 +24,7 @@ class Command extends BaseCommand
{ {
$this->line('开始'.$this->description); $this->line('开始'.$this->description);
set_time_limit(0); begin_time_consuming();
ini_set('memory_limit', '4096m');
ini_set('default_socket_timeout', -1);
parent::execute($input, $output); parent::execute($input, $output);
} }

View File

@ -298,33 +298,32 @@ class FlowPoolController extends Controller
*/ */
public function importFlows() public function importFlows()
{ {
begin_time_consuming();
$file = $this->request->file('file'); $file = $this->request->file('file');
$data = ImportService::load($file, ['month', 'pool_id', 'sim', 'mebibyte']); $data = ImportService::load($file, ['month', 'pool_id', 'sim', 'mebibyte']);
Validator::validate($data, [ foreach ($data as $row) {
'*.month' => ['required', 'numeric'], foreach (['month', 'pool_id', 'sim', 'mebibyte'] as $key) {
'*.pool_id' => ['required', 'numeric'], if (!isset($row[$key])) {
'*.sim' => ['required', 'numeric'], throw new InvalidArgumentException("字段{$row[$key]}不能为空");
'*.mebibyte' => ['required', 'numeric'], }
], [
'*.month.required' => '字段month不能为空', if (!is_numeric($row[$key])) {
'*.month.numeric' => '字段month必须为数字', throw new InvalidArgumentException("字段{$row[$key]}必须为数字");
'*.pool_id.required' => '字段pool_id不能为空', }
'*.pool_id.numeric' => '字段pool_id必须为数字', }
'*.sim.required' => '字段sim不能为空', }
'*.sim.numeric' => '字段sim必须为数字',
'*.mebibyte.required' => '字段mebibyte不能为空',
'*.mebibyte.numeric' => '字段mebibyte必须为数字',
]);
$flowPools = app(FlowPoolRepository::class)->withConditions(['id' => array_unique(array_pluck($data, 'pool_id'))])->get()->keyBy('id')->toArray(); $flowPools = app(FlowPoolRepository::class)->withConditions(['id' => array_unique(array_pluck($data, 'pool_id'))])->get()->keyBy('id')->toArray();
$simPackage = []; $simPackage = [];
foreach (array_chunk($data, 1000) as $value) { foreach (array_chunk($data, 10000) as $value) {
$cards = app(OrderCardPartitionRepository::class)->select(['sim', 'package_id'])->withConditions([ $cards = app(OrderCardPartitionRepository::class)->select(['sim', 'package_id'])->withConditions([
'type' => 0, 'type' => [0, 1, 2],
'sim' => array_pluck($value, 'sim'), 'sim' => array_pluck($value, 'sim'),
'now' => 1,
])->get()->pluck('package_id', 'sim')->toArray(); ])->get()->pluck('package_id', 'sim')->toArray();
foreach ($cards as $sim => $package_id) { foreach ($cards as $sim => $package_id) {

View File

@ -124,6 +124,15 @@ trait OrderCardConcern
$relation->where('transaction_no', 'like', "%{$conditions['transaction_no']}%"); $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'])) { if (isset($conditions['card_status'])) {

View File

@ -6,6 +6,19 @@ use Dipper\Foundation\Support\Time;
use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Event;
use App\Domains\Account\Services\AccountService; 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')) { if (! function_exists('cdn')) {
/** /**
* 生成CDN链接, 可带时间戳防盗链 * 生成CDN链接, 可带时间戳防盗链