自动激活
This commit is contained in:
parent
45e00b1cd2
commit
94450bafd2
@ -27,6 +27,7 @@ class Kernel extends ConsoleKernel
|
||||
{
|
||||
$logPath = storage_path('logs/artisan.log');
|
||||
$schedule->command('real:sync-activated')->cron('* */4 * * *')->withoutOverlapping()->appendOutputTo($logPath);
|
||||
$schedule->command('virtual:schedule-auto-activate')->cron('* * * 1 *')->withoutOverlapping()->appendOutputTo($logPath);
|
||||
}
|
||||
|
||||
/**
|
||||
|
78
app/Domains/Virtual/Commands/Schedule/AutoActivate.php
Normal file
78
app/Domains/Virtual/Commands/Schedule/AutoActivate.php
Normal file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Virtual\Commands\Schedule;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Domains\Card\Repositories\CardRepository;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use App\Domains\Virtual\Repositories\OrderCardPartitionRepository;
|
||||
use App\Models\Card\Card;
|
||||
|
||||
class AutoActivate extends Command
|
||||
{
|
||||
protected $name = 'virtual:schedule-auto-activate';
|
||||
|
||||
protected $description = '自动激活脚本';
|
||||
|
||||
const INTERVAL_MONTH = 6;
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$datetime = $this->getDateTime();
|
||||
|
||||
$time = $datetime->copy()->subMonths(self::INTERVAL_MONTH);
|
||||
|
||||
$this->info('自动激活脚本');
|
||||
|
||||
// $simArray = app(OrderCardPartitionRepository::class)->select('sim')
|
||||
// ->where('created_at', '>=', $time->copy()->startOfMonth())
|
||||
// ->where('created_at', '<=', $time->copy()->endOfMonth())
|
||||
// ->whereNull('service_start_at')
|
||||
// ->get()->pluck('sim')->toArray();
|
||||
|
||||
// $this->info(microtime(true));
|
||||
|
||||
// foreach (array_chunk($simArray, 1000) as $values) {
|
||||
// Card::query()->whereIn('sim', $values)->whereNull('virtual_activated_at')->update(['virtual_activated_at' => $datetime->startOfMonth()]);
|
||||
// $values = implode(',', array_keys($values));
|
||||
// DB::statement("select fix_timelines('{{$values}}'::INT8[]);");
|
||||
// }
|
||||
|
||||
$sql = "WITH sim_array AS (
|
||||
SELECT sim FROM virtual_order_cards WHERE created_at >= '%s' AND created_at <= '%s' AND service_start_at IS NULL
|
||||
), activate_updates AS (
|
||||
UPDATE cards SET virtual_activated_at='%s' WHERE sim IN (SELECT * FROM sim_array) AND virtual_activated_at IS NULL
|
||||
)
|
||||
SELECT fix_timelines(ARRAY(SELECT * FROM sim_array));
|
||||
";
|
||||
|
||||
DB::statement(sprintf($sql, $time->copy()->startOfMonth(), $time->copy()->endOfMonth(), $datetime->startOfMonth()));
|
||||
|
||||
app(CardRepository::class)->forgetCached();
|
||||
app(OrderCardPartitionRepository::class)->forgetCached();
|
||||
|
||||
$this->info('自动激活脚本执行完毕');
|
||||
}
|
||||
|
||||
protected function getDateTime()
|
||||
{
|
||||
if ($month = $this->argument('month')) {
|
||||
if (!preg_match('/\d{4}-\d{1,2}/', $month)) {
|
||||
throw new \App\Exceptions\InvalidArgumentException('请输入正确的年月 #示例: 2018-10');
|
||||
}
|
||||
|
||||
return Carbon::parse($month)->startOfMonth();
|
||||
}
|
||||
|
||||
return Carbon::now()->startOfMonth();
|
||||
}
|
||||
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['month', InputArgument::OPTIONAL, '要同步的数据月份,默认上个月 #示例: 2018-10'],
|
||||
];
|
||||
}
|
||||
}
|
@ -22,6 +22,7 @@ class VirtualServiceProvider extends ServiceProvider
|
||||
// $this->mergeConfigFrom(realpath(__DIR__ . '/../config.php'), 'domain.virtual');
|
||||
|
||||
$this->commands([
|
||||
\App\Domains\Virtual\Commands\Schedule\AutoActivate::class,
|
||||
\App\Domains\Virtual\Commands\Sync\CompanySync::class,
|
||||
\App\Domains\Virtual\Commands\Sync\PackageSync::class,
|
||||
\App\Domains\Virtual\Commands\Sync\ProductSync::class,
|
||||
|
@ -81,19 +81,19 @@ trait OrderCardConcern
|
||||
}
|
||||
|
||||
if (isset($conditions['service_start_starttime'])) {
|
||||
$query->where('created_at', '>=', Carbon::parse($conditions['service_start_starttime']));
|
||||
$query->where('service_start_at', '>=', Carbon::parse($conditions['service_start_starttime']));
|
||||
}
|
||||
|
||||
if (isset($conditions['service_start_endtime'])) {
|
||||
$query->where('created_at', '<=', Carbon::parse($conditions['service_start_endtime']));
|
||||
$query->where('service_start_at', '<=', Carbon::parse($conditions['service_start_endtime']));
|
||||
}
|
||||
|
||||
if (isset($conditions['service_end_starttime'])) {
|
||||
$query->where('created_at', '>=', Carbon::parse($conditions['service_end_starttime']));
|
||||
$query->where('service_end_at', '>=', Carbon::parse($conditions['service_end_starttime']));
|
||||
}
|
||||
|
||||
if (isset($conditions['service_end_endtime'])) {
|
||||
$query->where('created_at', '<=', Carbon::parse($conditions['service_end_endtime']));
|
||||
$query->where('service_end_at', '<=', Carbon::parse($conditions['service_end_endtime']));
|
||||
}
|
||||
|
||||
if (isset($conditions['month'])) {
|
||||
|
@ -389,8 +389,6 @@ class OrderService extends Service
|
||||
'total_price' => $value[0]['unit_price'] * $counts,
|
||||
'custom_price' => $value[0]['unit_price'] * $counts,
|
||||
'order_at' => $order_at,
|
||||
'order_status' => 3,
|
||||
'transaction_status' => 1,
|
||||
'created_at' => $order_at,
|
||||
'updated_at' => $order_at,
|
||||
];
|
||||
@ -424,6 +422,8 @@ class OrderService extends Service
|
||||
|
||||
$orderId = $maxId + 1;
|
||||
|
||||
$counts = array_sum(array_pluck($attributes['cards'], 'counts'));
|
||||
|
||||
$orders[] = [
|
||||
'id' => $orderId,
|
||||
'sn' => $this->generateSn(),
|
||||
@ -438,8 +438,6 @@ class OrderService extends Service
|
||||
'total_price' => $product['price'] * $counts,
|
||||
'custom_price' => $product['price'] * $counts,
|
||||
'order_at' => $order_at,
|
||||
'order_status' => 3,
|
||||
'transaction_status' => 0,
|
||||
'created_at' => $order_at,
|
||||
'updated_at' => $order_at,
|
||||
];
|
||||
@ -455,7 +453,6 @@ class OrderService extends Service
|
||||
'package_id' => $product['package_id'],
|
||||
'counts' => $cardCounts[$card->sim],
|
||||
'unit_price' => $product['price'],
|
||||
'transaction_status' => 0,
|
||||
'created_at' => $order_at,
|
||||
'updated_at' => $order_at,
|
||||
];
|
||||
|
@ -31,9 +31,10 @@ DECLARE
|
||||
temp_service_end_at TIMESTAMP;
|
||||
activated_at TIMESTAMP;
|
||||
BEGIN
|
||||
RAISE NOTICE 't1';
|
||||
SELECT array_to_json(array_agg(row_to_json(t))) INTO activate_cards
|
||||
FROM (SELECT cards.sim, cards.virtual_activated_at FROM vd.cards WHERE cards.sim = ANY ($1)) t;
|
||||
|
||||
RAISE NOTICE 't2';
|
||||
query := 'SELECT
|
||||
virtual_order_cards_partition.id,
|
||||
virtual_order_cards_partition.type,
|
||||
@ -52,9 +53,11 @@ BEGIN
|
||||
|
||||
FOR order_row IN EXECUTE query USING $1
|
||||
LOOP
|
||||
RAISE NOTICE 't3';
|
||||
SELECT value->>'virtual_activated_at' INTO activated_at
|
||||
FROM json_array_elements(activate_cards::JSON)
|
||||
WHERE value->>'sim' = order_row.sim::TEXT;
|
||||
RAISE NOTICE 't4';
|
||||
|
||||
IF NOT FOUND THEN
|
||||
temp_service_start_at := NULL;
|
||||
@ -109,6 +112,7 @@ BEGIN
|
||||
service_end_at := COALESCE(order_row.service_end_at::TIMESTAMP, temp_service_end_at::TIMESTAMP);
|
||||
RETURN NEXT;
|
||||
END LOOP;
|
||||
RAISE NOTICE 't5';
|
||||
RETURN;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
@ -116,14 +120,22 @@ $$ LANGUAGE plpgsql;
|
||||
CREATE OR REPLACE FUNCTION FIX_TIMELINES(INT8[])
|
||||
RETURNS void
|
||||
AS $$
|
||||
DECLARE
|
||||
chunk INT8[] := '{}';
|
||||
sim INT8;
|
||||
BEGIN
|
||||
UPDATE vd.virtual_order_cards_partition
|
||||
SET service_start_at=tmp.service_start_at,
|
||||
service_end_at=tmp.service_end_at
|
||||
FROM (SELECT * FROM GET_TIMELINES($1)) as tmp
|
||||
WHERE tmp.id = virtual_order_cards_partition.id;
|
||||
FOREACH sim IN ARRAY $1 LOOP
|
||||
chunk := chunk || sim;
|
||||
IF array_length(chunk, 1) = 1000 THEN
|
||||
UPDATE vd.virtual_order_cards_partition SET service_start_at=tmp.service_start_at, service_end_at=tmp.service_end_at FROM (SELECT * FROM GET_TIMELINES(chunk)) as tmp WHERE tmp.id = virtual_order_cards_partition.id;
|
||||
chunk := '{}';
|
||||
END IF;
|
||||
END LOOP;
|
||||
IF array_length(chunk, 1) > 0 THEN
|
||||
UPDATE vd.virtual_order_cards_partition SET service_start_at=tmp.service_start_at, service_end_at=tmp.service_end_at FROM (SELECT * FROM GET_TIMELINES(chunk)) as tmp WHERE tmp.id = virtual_order_cards_partition.id;
|
||||
END IF;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql SET synchronous_commit TO OFF;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE OR REPLACE FUNCTION FIX_ORDER_COUNTS()
|
||||
RETURNS BOOLEAN
|
||||
|
@ -97,19 +97,26 @@ export function reset(data) {
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
export function ship(data) {
|
||||
let params = new FormData();
|
||||
let config = {};
|
||||
let params = null;
|
||||
|
||||
for (const key in data) {
|
||||
if (data.hasOwnProperty(key)) {
|
||||
params.append(key, data[key]);
|
||||
if (data.type === 1) {
|
||||
params = new FormData();
|
||||
|
||||
for (const key in data) {
|
||||
if (data.hasOwnProperty(key)) {
|
||||
params.append(key, data[key]);
|
||||
}
|
||||
}
|
||||
|
||||
config = {
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data'
|
||||
}
|
||||
};
|
||||
} else {
|
||||
params = data;
|
||||
}
|
||||
|
||||
let config = {
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data'
|
||||
}
|
||||
};
|
||||
|
||||
return service.post('api/virtual/orders/ship', params, config);
|
||||
}
|
||||
|
@ -41,8 +41,6 @@ export default {
|
||||
return this.$Message.error('请上传文件');
|
||||
}
|
||||
|
||||
console.log(this.file);
|
||||
|
||||
params.file = this.file;
|
||||
};
|
||||
|
||||
|
2
public/js/app.a4043849.js
Normal file
2
public/js/app.a4043849.js
Normal file
File diff suppressed because one or more lines are too long
1
public/js/app.a4043849.js.map
Normal file
1
public/js/app.a4043849.js.map
Normal file
File diff suppressed because one or more lines are too long
2
public/js/chunk-bb3b064e.1bc45bb8.js
Normal file
2
public/js/chunk-bb3b064e.1bc45bb8.js
Normal file
File diff suppressed because one or more lines are too long
1
public/js/chunk-bb3b064e.1bc45bb8.js.map
Normal file
1
public/js/chunk-bb3b064e.1bc45bb8.js.map
Normal file
File diff suppressed because one or more lines are too long
@ -1 +1 @@
|
||||
<!DOCTYPE html><html><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=\favicon.ico><script src=\config.js></script><title></title><link href=/css/chunk-996b1e80.5cadf3d0.css rel=prefetch><link href=/css/chunk-bb3b064e.bc6b17af.css rel=prefetch><link href=/js/chunk-00ae0766.3874cd10.js rel=prefetch><link href=/js/chunk-07a274ec.c3ad5dec.js rel=prefetch><link href=/js/chunk-996b1e80.d3b45e46.js rel=prefetch><link href=/js/chunk-bb3b064e.b8bb8795.js rel=prefetch><link href=/css/app.d71a8195.css rel=preload as=style><link href=/css/chunk-vendors.3c3b2e85.css rel=preload as=style><link href=/js/app.7ef53e3c.js rel=preload as=script><link href=/js/chunk-vendors.ed6443e8.js rel=preload as=script><link href=/css/chunk-vendors.3c3b2e85.css rel=stylesheet><link href=/css/app.d71a8195.css rel=stylesheet></head><body><noscript><strong>很抱歉,如果没有启用JavaScript,程序不能正常工作,若要继续使用请启用它。</strong></noscript><div id=app></div><script src=/js/chunk-vendors.ed6443e8.js></script><script src=/js/app.7ef53e3c.js></script></body></html>
|
||||
<!DOCTYPE html><html><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=\favicon.ico><script src=\config.js></script><title></title><link href=/css/chunk-996b1e80.5cadf3d0.css rel=prefetch><link href=/css/chunk-bb3b064e.bc6b17af.css rel=prefetch><link href=/js/chunk-00ae0766.3874cd10.js rel=prefetch><link href=/js/chunk-07a274ec.c3ad5dec.js rel=prefetch><link href=/js/chunk-996b1e80.d3b45e46.js rel=prefetch><link href=/js/chunk-bb3b064e.1bc45bb8.js rel=prefetch><link href=/css/app.d71a8195.css rel=preload as=style><link href=/css/chunk-vendors.3c3b2e85.css rel=preload as=style><link href=/js/app.a4043849.js rel=preload as=script><link href=/js/chunk-vendors.ed6443e8.js rel=preload as=script><link href=/css/chunk-vendors.3c3b2e85.css rel=stylesheet><link href=/css/app.d71a8195.css rel=stylesheet></head><body><noscript><strong>很抱歉,如果没有启用JavaScript,程序不能正常工作,若要继续使用请启用它。</strong></noscript><div id=app></div><script src=/js/chunk-vendors.ed6443e8.js></script><script src=/js/app.a4043849.js></script></body></html>
|
Loading…
x
Reference in New Issue
Block a user