注销同步

This commit is contained in:
邓皓元 2019-03-25 18:21:57 +08:00
parent e053b6be6b
commit c0f511e5d7
14 changed files with 259 additions and 37 deletions

View File

@ -27,7 +27,6 @@ class Kernel extends ConsoleKernel
{
$logPath = storage_path('logs/artisan.log');
$schedule->command('real:sync-activated')->cron('* */4 * * *')->withoutOverlapping()->appendOutputTo($logPath);
$schedule->command('real:sync-cancelled')->cron('* */4 * * *')->withoutOverlapping()->appendOutputTo($logPath);
}
/**

View File

@ -8,6 +8,7 @@ use App\Models\Mongo\TblCard;
use MongoDB\BSON\UTCDateTime;
use Illuminate\Support\Facades\DB;
use App\Domains\Card\Repositories\CardRepository;
use Symfony\Component\Console\Input\InputArgument;
use App\Domains\Virtual\Repositories\OrderCardPartitionRepository;
class ActivatedSync extends Command
@ -78,4 +79,24 @@ class ActivatedSync extends Command
app(CardRepository::class)->forgetCached();
app(OrderCardPartitionRepository::class)->forgetCached();
}
protected function getDay()
{
if ($day = $this->argument('day')) {
if (!preg_match('/\d{4}-\d{1,2}-\d{1,2}/', $day)) {
throw new \App\Exceptions\InvalidArgumentException('请输入正确的日期 #示例: 2018-10-01');
}
return Carbon::parse($day)->startOfDay();
}
return Carbon::yesterday()->startOfDay();
}
protected function getArguments()
{
return [
['day', InputArgument::OPTIONAL, '要同步的数据日期,默认昨天 #示例: 2018-10-01'],
];
}
}

View File

@ -6,24 +6,26 @@ use Carbon\Carbon;
use App\Models\Card\Card;
use Illuminate\Support\Facades\DB;
use App\Domains\Card\Repositories\CardRepository;
use Symfony\Component\Console\Input\InputArgument;
use App\Domains\Virtual\Repositories\OrderCardPartitionRepository;
class CancelledSync extends Command
{
protected $name = 'real:sync-cancelled';
protected $description = '同步注销数据(每天同步昨天的注销数据)';
protected $description = '同步注销数据(每月同步上个月的注销数据)';
protected $limit = 1000;
public function handle()
{
$day = $this->getDay();
$datetime = $this->getDateTime();
$starttime = $datetime->copy()->startOfMonth()->startOfDay()->timestamp;
$endtime = $datetime->copy()->endOfMonth()->endOfDay()->timestamp;
$cancelRecords = DB::connection('real')->table('jxc_cancel_card')
->where('cn_date', $day->format('Y-m-d'))
->where('cn_status', 1)->get();
->where('cn_create_time', '>=', $starttime)
->where('cn_create_time', '<=', $endtime)
->where('cn_status', 1)->get()->keyBy('cn_id');
$this->line('待同步条数:'.count($cancelRecords));
@ -34,38 +36,23 @@ class CancelledSync extends Command
$cards = DB::connection('real')->table('jxc_cancel_card_item')
->whereIn('item_cn_id', $cancelRecords->pluck('cn_id')->toArray())->get();
$array = [];
$cards = $cards->chunk(1000);
foreach ($cards as $item) {
$array[] = [
'sim' => $item->item_sim,
'cancelled_at' => $day,
];
foreach ($cards as $values) {
$array = [];
foreach ($values as $item) {
$record = $cancelRecords[$item->item_cn_id];
$array[] = [
'sim' => $item->item_sim,
'cancelled_at' => Carbon::createFromTimestamp($record->cn_create_time),
];
}
Card::updateBatch($array, 'sim::int8');
}
Card::updateBatch($array, 'sim::int8');
app(CardRepository::class)->forgetCached();
app(OrderCardPartitionRepository::class)->forgetCached();
}
protected function getDay()
{
if ($day = $this->argument('day')) {
if (!preg_match('/\d{4}-\d{1,2}-\d{1,2}/', $day)) {
throw new \App\Exceptions\InvalidArgumentException('请输入正确的日期 #示例: 2018-10-01');
}
return Carbon::parse($day)->startOfDay();
}
return Carbon::yesterday()->startOfDay();
}
protected function getArguments()
{
return [
['day', InputArgument::OPTIONAL, '要同步的数据日期,默认昨天 #示例: 2018-10-01'],
];
}
}

View File

@ -39,6 +39,9 @@ class Artisan extends Model
'real:sync-mongo' => '同步卡基础信息数据',
'real:sync-order' => '同步RD基础订单数据',
'real:sync-package' => '同步RD套餐数据',
'real:sync-cancelled' => '同步RD注销数据',
'real:sync-refund' => '同步RD退货数据',
'real:sync-activated' => '同步RD激活数据',
'virtual:sync-company' => '同步VD企业数据',
'virtual:sync-package' => '同步VD套餐数据',
'virtual:sync-product' => '同步VD定价',

View File

@ -0,0 +1,64 @@
<template>
<Modal
:closable="false"
:mask-closable="false"
:title="'注销卡同步'"
@on-visible-change="visibleChange"
v-model="my_show"
:width="1200"
>
<div class="page-edit-wrap uinn-lr20">
<ui-loading :show="page_loading.show"></ui-loading>
<Steps :current="current" :status="status">
<Step
:title="item.title"
:content="item.content"
v-for="(item, index) in steps"
:key="index"
></Step>
</Steps>
<Row type="flex" justify="center" class="umar-t15" v-if="steps[current] && steps[current]['datePicker']">
<DatePicker
:editable="false"
placeholder="请选择时间"
placement="bottom-start"
type="month"
v-model.trim="month"
></DatePicker>
</Row>
<Row type="flex" justify="center" class="umar-t15">
<Circle :size="250" :percent="circle.percent" stroke-linecap="square">
<div class="circle-text">
<h1>{{circle.percent}}%</h1>
<br>
<p>{{circle.content}}</p>
</div>
</Circle>
</Row>
</div>
<footer class="ta-c" slot="footer">
<Button @click="clear" class="w-80" ghost type="primary" :disabled="disabled">取消</Button>
<Button
:loading="loading"
@click="call"
class="w-80"
type="primary"
v-if="this.status === 'wait'"
:disabled="disabled"
>{{ current ? '下一步' : '开始同步'}}</Button>
<Button
:loading="loading"
@click="clear"
class="w-80"
type="primary"
v-if="this.status === 'finish'"
>完成</Button>
</footer>
</Modal>
</template>
<script src="./js/cancelled.js"></script>

View File

@ -18,6 +18,10 @@
<Button @click="openRefund(true)" icon="md-arrow-dropleft" type="primary">退货同步</Button>
</div>
<div class="handle-item">
<Button @click="openCancelled(true)" icon="md-close" type="primary">注销同步</Button>
</div>
<div class="handle-item">
<Button @click="search.show=!search.show" ghost icon="ios-search" type="primary">搜索</Button>
</div>
@ -84,6 +88,12 @@
@add-success="index"
@update-success="index(list_data.current_page)"
></ui-refund>
<ui-cancelled
:show.sync="cancelledObj.show"
@add-success="index"
@update-success="index(list_data.current_page)"
></ui-cancelled>
</div>
</template>

View File

@ -0,0 +1,115 @@
export default {
props: {
show: {
type: Boolean,
default: false
}
},
watch: {
show(bool) {
this.my_show = bool;
if (bool) {
this.current = 0;
this.status = 'wait';
this.circle.percent = 0;
this.circle.content = '未开始';
}
}
},
data() {
return {
my_show: false,
loading: false,
disabled: false,
steps: [
{
'title': '同步注销',
'content': '指定月份的注销数据',
'command': 'real:sync-cancelled',
'max': 100,
'datePicker': true
}
],
current: 0,
circle: {
percent: 0,
content: '未开始'
},
status: 'wait',
month: this.moment().subtract('1', 'months').startOf('month').format('YYYY-MM')
};
},
methods: {
call() {
if (!this.steps[this.current]) {
return;
}
this.disabled = true;
let params = {};
params.command = this.steps[this.current]['command'];
if (!params.command) {
return this.$Message.error('命令错误');
}
if (this.steps[this.current]['datePicker']) {
if (!this.month) {
return this.$Message.error('请选择要同步的月份');
}
params.parameters = {
month: this.moment(this.month).format('YYYY-MM')
};
}
let max = this.steps[this.current]['max'];
this.status = 'process';
this.circle.content = '正在' + this.steps[this.current]['title'];
let interval = setInterval(() => {
if (this.circle.percent < max) {
this.circle.percent++;
}
}, 1000);
service.post('/api/artisan/call', params).then(res => {
if (res.code == 0) {
this.circle.content = this.steps[this.current]['title'] + '完成';
this.circle.percent = max;
this.status = (max == 100) ? 'finish' : 'wait';
this.current++;
} else {
this.circle.content = '同步失败';
this.circle.percent = this.steps[this.current - 1] ? this.steps[this.current - 1]['max'] : 0;
this.status = 'error';
}
this.disabled = false;
clearInterval(interval);
}).catch((err) => {
this.circle.content = '同步失败';
this.circle.percent = this.steps[this.current - 1] ? this.steps[this.current - 1]['max'] : 0;
this.status = 'error';
this.disabled = false;
clearInterval(interval);
});
},
changeStep(value) {
this.current = value + 1;
},
visibleChange(bool) {
if (!bool) {
this.$emit('update:show', false);
}
},
clear() {
this.my_show = false;
}
}
};

View File

@ -2,7 +2,8 @@ export default {
name: 'RealSync',
components: {
UiEdit: resolve => require(['views/artisan/real-sync/edit'], resolve),
UiRefund: resolve => require(['views/artisan/real-sync/refund'], resolve)
UiRefund: resolve => require(['views/artisan/real-sync/refund'], resolve),
UiCancelled: resolve => require(['views/artisan/real-sync/cancelled'], resolve)
},
data() {
return {
@ -12,7 +13,8 @@ export default {
'real:sync-mongo': '同步卡基础信息数据',
'real:sync-order': '同步RD基础订单数据',
'real:sync-package': '同步RD套餐数据',
'real:sync-refund': '同步RD退货数据'
'real:sync-refund': '同步RD退货数据',
'real:sync-cancelled': '同步RD注销数据'
},
options: {
command: null,
@ -25,6 +27,9 @@ export default {
refundObj: {
show: false
},
cancelledObj: {
show: false
},
search: {
show: false
},
@ -101,6 +106,16 @@ export default {
};
},
/**
* [openCancelled 打开编辑弹窗]
* @return {[type]} [description]
*/
openCancelled(bool) {
this.cancelledObj = {
show: bool
};
},
/**
* [request 刷新]
* @return {[type]} [description]

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -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-25bd8946.ae776acd.css rel=prefetch><link href=/css/chunk-996b1e80.5cadf3d0.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-25bd8946.f77857c1.js rel=prefetch><link href=/js/chunk-996b1e80.d3b45e46.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.f8a9a9de.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.f8a9a9de.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-2e798a12.698b0ec2.css rel=prefetch><link href=/css/chunk-996b1e80.5cadf3d0.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-2e798a12.d09459b0.js rel=prefetch><link href=/js/chunk-996b1e80.d3b45e46.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.ac2b5fd2.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.ac2b5fd2.js></script></body></html>