Commit 0d27eb51 authored by 刘松's avatar 刘松

complex

parent 0b12a7e4
FROM node:7.6 FROM node:latest
RUN mkdir -p /usr/src/app RUN mkdir -p /usr/src/app
......
...@@ -14,6 +14,7 @@ const mongoose = require('mongoose'); ...@@ -14,6 +14,7 @@ const mongoose = require('mongoose');
const sessions = require('./db/mongo/session'); const sessions = require('./db/mongo/session');
const cron = require('./lib/cron'); const cron = require('./lib/cron');
const cron_gather = require('./lib/cron_gather'); const cron_gather = require('./lib/cron_gather');
const cron_auto = require('./lib/cron_auto');
const options = { const options = {
useMongoClient: true useMongoClient: true
...@@ -54,5 +55,6 @@ console.log(process.env.NODE_ENV + 'server started on port ' + config.port); ...@@ -54,5 +55,6 @@ console.log(process.env.NODE_ENV + 'server started on port ' + config.port);
if(process.env.NODE_ENV === 'production'){ if(process.env.NODE_ENV === 'production'){
cron.start(); cron.start();
cron_gather.start(); cron_gather.start();
cron_auto.start();
} }
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
body{ body{
background: #ececec background: #ececec;
font-size: 13px;
} }
.wrapper,.login-wrapper{ .wrapper,.login-wrapper{
background: #ececec; background: #ececec;
...@@ -83,6 +84,18 @@ body{ ...@@ -83,6 +84,18 @@ body{
text-align: center; text-align: center;
background: #5587b3; background: #5587b3;
} }
div.ant-row .ant-col-6:nth-of-type(1) .box h3{
background: #5587b3;
}
div.ant-row .ant-col-6:nth-of-type(2) .box h3{
background: #ffb980;
}
div.ant-row .ant-col-6:nth-of-type(3) .box h3 {
background: #5ab1ef;
}
div.ant-row .ant-col-6:nth-of-type(4) .box h3{
background: #97b552;
}
.box span{ .box span{
font-size: 20px; font-size: 20px;
width: 58%; width: 58%;
...@@ -97,7 +110,7 @@ body{ ...@@ -97,7 +110,7 @@ body{
width: 500px; width: 500px;
} }
.detail-body span{ .detail-body span{
width: 50%; width: 33.3%;
display: inline-block; display: inline-block;
} }
.detail-body-list{ .detail-body-list{
...@@ -122,3 +135,57 @@ body{ ...@@ -122,3 +135,57 @@ body{
.detail-body-list span:nth-of-type(3){ .detail-body-list span:nth-of-type(3){
width: 10%; width: 10%;
} }
.tool-box{
display: flex;
display: -webkit-flex; /* Safari */
align-items: center;
flex-direction: row;
justify-content:flex-start;
}
.tool-box .none{
margin-left: 20px;
/* background: aquamarine; */
height: 100%;
width: 100%;
min-width: 200px;
text-align: center;
}
.label-info{
border-bottom: 1px solid #b1abab;
padding: 10px 0px;
}
.label-info label{
font-size: 13px;
font-weight: bold;
width: 200px;
float: left;
}
label.tkllabel{
font-size: 13px;
font-weight: bold;
width: 200px;
padding: 10px 0px;
display: block;
}
.label-info p{
display: block;
max-width: 100%;
overflow: hidden;
word-wrap: break-word;
}
.label-info div{
margin-left: 10px;
}
.label-info img{
width: 100px;
}
.model-box{
height: 150px;
overflow: auto;
}
.model{
float: left;
margin: 0px 9px 10px 0px;
}
...@@ -22,6 +22,18 @@ module.exports = { ...@@ -22,6 +22,18 @@ module.exports = {
{ {
path:'qd', path:'qd',
component:require('../../jsx/setting/qd.jsx') component:require('../../jsx/setting/qd.jsx')
},
{
path:'tools',
component:require('../../jsx/setting/tools.jsx')
},
{
path:'tools_num2',
component:require('../../jsx/setting/tool2s.jsx')
},
{
path:'ips',
component:require('../../jsx/setting/ips.jsx')
} }
] ]
} }
\ No newline at end of file
...@@ -9,14 +9,17 @@ const MenuItemGroup = Menu.ItemGroup; ...@@ -9,14 +9,17 @@ const MenuItemGroup = Menu.ItemGroup;
const ButtonGroup = Button.Group; const ButtonGroup = Button.Group;
const { Header, Footer, Sider, Content } = Layout; const { Header, Footer, Sider, Content } = Layout;
const mapLocations = ['/manage/statistics','/manage','/manage/setting','/manage/tkl','/manage/schedule','/manage/qd'] const mapLocations = ['/manage/statistics','/manage','/manage/ips','/manage/setting','/manage/tkl','/manage/schedule','/manage/qd','/manage/tools','/manage/tools_num2']
class Main extends React.Component{ class Main extends React.Component{
constructor(props){ constructor(props){
super(props); super(props);
this.map = ['数据统计','数据统计','配置','淘口令','渠道管理'] this.map = ['口令数据','汇总数据','IP数据','推广页面管理','淘口令','推广计划','渠道管理','小工具','小工具2'];
console.dir(location.pathname);
var pathname = location.pathname;
console.dir(mapLocations.indexOf(pathname));
this.state = { this.state = {
current: '1', current: mapLocations.indexOf(pathname) >= 0 ? mapLocations.indexOf(pathname) : 0,
openKeys: [], openKeys: [],
theme: 'dark', theme: 'dark',
username:null username:null
...@@ -25,7 +28,8 @@ class Main extends React.Component{ ...@@ -25,7 +28,8 @@ class Main extends React.Component{
handleClick(e){ handleClick(e){
//this.props.dispatch(actions.getMenu()); //this.props.dispatch(actions.getMenu());
if(e.key == 6){ this.setState({current:e.key})
if(e.key == 9){
api('GET', 'logout').then(function(res){ api('GET', 'logout').then(function(res){
if(res.result == 'ok') location.href = '/'; if(res.result == 'ok') location.href = '/';
}); });
...@@ -48,7 +52,7 @@ class Main extends React.Component{ ...@@ -48,7 +52,7 @@ class Main extends React.Component{
} }
render(){ render(){
console.log(this.props.menu.currentPage); console.log(this.state.current);
return ( return (
<Layout className="layout"> <Layout className="layout">
<Header> <Header>
...@@ -58,25 +62,28 @@ class Main extends React.Component{ ...@@ -58,25 +62,28 @@ class Main extends React.Component{
<Menu <Menu
theme="dark" theme="dark"
mode="horizontal" mode="horizontal"
defaultSelectedKeys = {[ this.props.menu.currentPage +'' ]} defaultSelectedKeys = {[ this.state.current ]}
onClick={ this.handleClick.bind(this) } onClick={ this.handleClick.bind(this) }
style={{ lineHeight: '64px' }} style={{ lineHeight: '64px' }}
> >
<SubMenu title={<span>数据统计</span>}> <SubMenu title={<span>数据统计</span>}>
<Menu.Item key="1">汇总数据</Menu.Item> <Menu.Item key="1">汇总数据</Menu.Item>
<Menu.Item key="0">口令数据</Menu.Item> <Menu.Item key="0">口令数据</Menu.Item>
<Menu.Item key="2">IP数据</Menu.Item>
</SubMenu> </SubMenu>
<Menu.Item key="2">推广页管理</Menu.Item> <Menu.Item key="3">推广页管理</Menu.Item>
<Menu.Item key="3">淘口令</Menu.Item> <Menu.Item key="4">淘口令</Menu.Item>
<Menu.Item key="4">推广计划</Menu.Item> <Menu.Item key="5">推广计划</Menu.Item>
<Menu.Item key="5">渠道管理</Menu.Item> <Menu.Item key="6">渠道管理</Menu.Item>
<Menu.Item key="6" style ={{ float:'right'}}><Icon type="logout" />{ this.state.username }</Menu.Item> <Menu.Item key="7">小工具</Menu.Item>
<Menu.Item key="8">小工具2</Menu.Item>
<Menu.Item key="9" style ={{ float:'right'}}><Icon type="logout" />{ this.state.username }</Menu.Item>
</Menu> </Menu>
</Header> </Header>
<Content style={{ padding: '0 50px' }}> <Content style={{ padding: '0 50px' }}>
<Breadcrumb style={{ margin: '12px 0' }}> <Breadcrumb style={{ margin: '12px 0' }}>
<Breadcrumb.Item>{ this.map[ this.props.menu.currentPage ]}</Breadcrumb.Item> <Breadcrumb.Item>{ parseInt(this.state.current) < 3 ? '数据统计' : '配置与管理'}</Breadcrumb.Item>
<Breadcrumb.Item>{ this.props.menu.currentPage == '0' ? '数据统计' : (this.props.menu.currentPage == '0' ? '汇总数据' : "配置" )}</Breadcrumb.Item> <Breadcrumb.Item>{ this.map[ this.state.current ]}</Breadcrumb.Item>
</Breadcrumb> </Breadcrumb>
<div style={{ background: '#fff', padding: 24, minHeight: 280 }}>{ <div style={{ background: '#fff', padding: 24, minHeight: 280 }}>{
this.props.children this.props.children
...@@ -90,7 +97,7 @@ class Main extends React.Component{ ...@@ -90,7 +97,7 @@ class Main extends React.Component{
} }
} }
function mapStateToProps (state) { /*function mapStateToProps (state) {
return state; return state;
} }*/
module.exports = connect(mapStateToProps)(Main); module.exports = Main;
\ No newline at end of file \ No newline at end of file
const React = require('react'); const React = require('react');
/*const connect = require('react-redux').connect;
const actions = require('../../js/actions');*/
const moment = require('moment'); const moment = require('moment');
const api = require('../../js/api'); const api = require('../../js/api');
import json2xlsx from '../../js/json2xlsx'; import json2xlsx from '../../js/json2xlsx';
import { Table, Icon, DatePicker, Alert, Row, Col, Spin, Button,Badge} from 'antd'; import { Table, Icon, DatePicker, Alert, Row, Col, Spin, Button,Select,Radio} from 'antd';
const Option = Select.Option;
const { RangePicker } = DatePicker; const { RangePicker } = DatePicker;
class Details extends React.Component{ class Ips extends React.Component{
constructor(props){ constructor(props){
super(props); super(props);
console.dir(this.props); this.range = [moment().subtract(6,'days').format('YYYYMMDD'), moment().format('YYYYMMDD')];
this.state= { details :[],status:'pending',pagination:{current:1,pageSize:10,total:100},modalVisible:false,username:'channel',qd:null,date:null}; this.state= { currentDate:null,qds:[],ips :[],status:'pending',pagination:{current:1,pageSize:100,total:1},sort:'updatedAt',currentQd:'all' };
} }
getQueryString(name) {
var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
var r = window.location.search.substr(1).match(reg);
if (r != null) {
return unescape(r[2]);
}
return null;
}
componentDidMount(){ componentDidMount(){
let pagination = this.state.pagination;
//alert(this.getQueryString('date') + this.getQueryString('qd'));
let qd = this.getQueryString('qd');
let date = this.getQueryString('date');
this.setState({qd:qd,date:date});
if(document.cookie.match('username=[a-zA-Z0-9]+')[0] && document.cookie.match('username=[a-zA-Z0-9]+')[0].split('=')[1]){ if(document.cookie.match('username=[a-zA-Z0-9]+')[0] && document.cookie.match('username=[a-zA-Z0-9]+')[0].split('=')[1]){
this.setState({username:document.cookie.match('username=[a-zA-Z0-9]+')[0].split('=')[1]}); this.setState({username:document.cookie.match('username=[a-zA-Z0-9]+')[0].split('=')[1]});
} }
let pagination = this.state.pagination;
api('GET', 'qds?skip=0&limit=1000').then((res) => {
this.setState({qds:res.result});
});
//let data = { start:moment().add(-6,'days').format('YYYYMMDD'),end:moment().format('YYYYMMDD')}; //let data = { start:moment().add(-6,'days').format('YYYYMMDD'),end:moment().format('YYYYMMDD')};
api('GET', 'details?'+'skip=0&limit=' + pagination.pageSize+'&qd='+qd+'&date='+date).then((res) => { api('GET', 'ips?'+'skip=0&limit=' + pagination.pageSize+'&qd=all').then((res) => {
this.setState({details:res.result,status:'ready',pagination:{current:res.pagination.skip,pageSize:res.pagination.limit,total:res.pagination.total},info:{quan:'',good:''}}) this.setState({ips:res.result,status:'ready',pagination:{current:res.pagination.skip,pageSize:res.pagination.limit,total:res.pagination.total}})
console.dir(res.result);
}); });
} }
getdetails(pagination){ getips(pagination,value,date){
console.dir(pagination); api('GET', 'qds?skip=0&limit=1000').then((res) => {
this.setState({qds:res.result});
});
this.setState({status:'pending'}); this.setState({status:'pending'});
api('GET', 'details?'+'skip='+ (pagination.current-1) + '&limit=' + pagination.pageSize +'&qd=' + this.state.qd+'&date=' + this.state.date).then((res) => { var url = 'ips?'+'skip='+ (pagination.current-1) + '&limit=' + pagination.pageSize;
this.setState({details:res.result,status:'ready',pagination:{current:res.pagination.skip,pageSize:res.pagination.limit,total:res.pagination.total}}) if(value)
console.dir(res.result); url += ('&qd='+ value);
if(date)
url += ('&date='+ date);
api('GET', url).then((res) => {
this.setState({ips:res.result,status:'ready',pagination:{current:res.pagination.skip,pageSize:res.pagination.limit,total:res.pagination.total}})
}); });
} }
onChange(pagination) { onChange(pagination) {
this.getdetails(pagination); //let data = { start:dateString[0],end:dateString[1]};
this.getips(pagination,this.state.currentQd,this.state.currentDate);
//this.props.dispatch(actions.getMainData(data));
}
onChangeDate(date, dateString){
this.setState({currentDate:dateString});
this.getips({current:1,pageSize:this.state.pagination.pageSize},this.state.currentQd,dateString);
} }
exportData(){ exportData(){
//json2xlsx(data,{sheetName:"基础数据", filename : '基础数据'+moment().format('YYYYMMDD')+'.xlsx'}); //json2xlsx(data,{sheetName:"基础数据", filename : '基础数据'+moment().format('YYYYMMDD')+'.xlsx'});
} }
handleSort(e){
this.setState({sort:e.target.value});
this.getips({current:1,pageSize:this.state.pagination.pageSize},e.target.value);
}
handleChange(value) {
this.setState({currentQd:value});
this.getips({pageSize:this.state.pagination.pageSize,current:1},value,this.state.currentDate)
//console.log(`selected ${value}`);
}
render(){
render(){
console.dir(this.state.pagination);
let children = [<Option key='all'>全部</Option>];
for (var i = 0; i < this.state.qds.length; i++) {
let item = this.state.qds[i];
children.push(<Option key={item._id}>{ item.user }</Option>);
}
const columns = [ const columns = [
{ {
title: '渠道', title: '日期',
dataIndex: 'qd', dataIndex: 'date',
key: 'qd', key: 'date',
width: 60, width: 100,
render: text => <span href="#">{text}</span>, render: text => <span href="#">{text}</span>,
}, },
{ {
title: '计划ID', title: 'ip',
dataIndex: 'schedule', dataIndex: 'ip',
key: 'schedule', key: 'ip',
width: 100, width: 100,
render: text => <span href="#">{text}</span>, render: text => <span href="#">{text}</span>,
}, },{
{ title: '次数',
title: '商品页面', dataIndex: 'times',
dataIndex: 'link', key: 'times',
key: 'link',
width: 100, width: 100,
render: text => <span href="#">{text}</span>, render: text => <span href="#">{text}</span>,
}, },
{ {
title: '淘口令', title: '渠道',
dataIndex: 'tkl', dataIndex: 'qd',
key: 'tkl', key: 'qd',
width: 100, width: 100,
// sorter: (a, b) => { a.qd - b.qd},
render: text => <span href="#">{text}</span>, render: text => <span href="#">{text}</span>,
},
{
title: '请求数',
dataIndex: 'times',
key: 'times',
width: 40,
render: text => <span href="#">{text}</span>
} }
]; ];
let data = []; let data = [];
let details = this.state.details; let count = 0;
for(let i = 0;i<details.length;i++){ let ips = this.state.ips;
for(let i = 0;i<ips.length;i++){
data.push({ data.push({
key:i, key:i,
qd:details[i].info , ip:ips[i].ip,
schedule:details[i].schedule, date:ips[i].date,
link:(details[i].link && details[i].link['target']) || '--', times:ips[i].times,
tkl:details[i].status, qd:(ips[i]['qd'] && ips[i]['qd']['user']) || '--'
times:details[i].createdAt
}); });
} }
return ( return (
<div> this.state.username == 'admin' ? <div>
<Alert <DatePicker onChange={ this.onChangeDate.bind(this) } format={'YYYYMMDD'} style={{ width:200,margin:'10px'}}/>
message="提示" <Select
description="淘口令油后台任务自动生成" style={{ width:200,margin:'10px 0px'}}
type="info" placeholder="输入渠道名称"
/> defaultValue="all"
onChange={this.handleChange.bind(this)}
>
{children}
</Select>
<Spin spinning= { this.state.status == 'pending' }> <Spin spinning= { this.state.status == 'pending' }>
<Table columns={columns} dataSource = { data } size="middle" pagination={ this.state.pagination } onChange = { this.onChange.bind(this)} bordered/> <Table columns={columns} dataSource = { data } size="middle" pagination={ this.state.pagination } onChange = { this.onChange.bind(this)} bordered/>
</Spin> </Spin>
</div> </div>: <Alert
message="抱歉"
description="您没有权限"
type="warning"
/>
) )
} }
} }
module.exports = Details; /*
function mapStateToProps (state) {
return state;
}
module.exports = connect(mapStateToProps)(DashBoard);*/
module.exports = Ips;
...@@ -5,7 +5,7 @@ const api = require('../../js/api'); ...@@ -5,7 +5,7 @@ const api = require('../../js/api');
import json2xlsx from '../../js/json2xlsx'; import json2xlsx from '../../js/json2xlsx';
import { Table, Icon, DatePicker, Alert, Row, Col, Spin, Button,Modal,Form,Input,Switch} from 'antd'; import { Table, Icon, DatePicker, Alert, Row, Col, Spin, Button,Modal,Form,Input,Switch,InputNumber,message} from 'antd';
const { RangePicker } = DatePicker; const { RangePicker } = DatePicker;
const FormItem = Form.Item; const FormItem = Form.Item;
...@@ -59,12 +59,48 @@ class Qd extends React.Component{ ...@@ -59,12 +59,48 @@ class Qd extends React.Component{
}); });
} }
ipsChange(data,value){
console.dir(data);
console.dir(value);
var key = data['key'];
var qds = this.state.qds;
//console.dir(qds.length + '====');
qds[key]['iplimit'] = value;
console.dir(qds[key]['iplimit']);
this.setState({qds:qds});
}
putIpData(data){
console.dir(data);
api('POST','put_ip',{iplimit:data['ip'],id:data['id']}).then( res => {
message.success('执行成功, 影响'+ (res.result ? res.result.nModified : 0 )+" 条数据");
});
}
setModalVisible(b){ setModalVisible(b){
this.setState({modalVisible:b}); this.setState({modalVisible:b});
} }
exportData(){ exportData(){
//json2xlsx(data,{sheetName:"基础数据", filename : '基础数据'+moment().format('YYYYMMDD')+'.xlsx'});
}
checkUpdate(qd){
var qds = this.state.qds;
var data = {
ipstatus:qd['ipstatus'] && qd['ipstatus'] == 'use' ? 'disable' : 'use',
id:qd['id']
}
var self = this;
api('POST', 'qd_update',data).then((res) => {
if(res.result && res.result.nModified){
message.success('执行成功, 影响'+ (res.result ? res.result.nModified : 0 )+" 条数据");
qds[qd['key']]['ipstatus'] = (qd['ipstatus'] && qd['ipstatus'] == 'use' ? 'disable' : 'use');
self.setState({qds:qds});
}
});
} }
render(){ render(){
...@@ -104,6 +140,19 @@ class Qd extends React.Component{ ...@@ -104,6 +140,19 @@ class Qd extends React.Component{
key: 'tkl', key: 'tkl',
width: 40, width: 40,
render: text => <span href="#">{text}</span>, render: text => <span href="#">{text}</span>,
},
{
title: 'IP控制(状态 / 次数)',
dataIndex: 'ip',
key: 'ip',
width: 100,
render: (text,data) => <div>
<Switch checked={ data.ipstatus == 'use' ? true : false } onChange={this.checkUpdate.bind(this,data)} style = {{'marginRight': '10px'}}/>
<InputNumber min={0} max={1000000000000000} value = { text || 0 } onChange = { this.ipsChange.bind(this,data)}/>
<Button type="primary" onClick={ this.putIpData.bind(this,data) } style = {{ marginLeft:'10px' }}>
确定
</Button>
</div>
} }
]; ];
let data = []; let data = [];
...@@ -111,10 +160,12 @@ class Qd extends React.Component{ ...@@ -111,10 +160,12 @@ class Qd extends React.Component{
for(let i = 0;i<qds.length;i++){ for(let i = 0;i<qds.length;i++){
data.push({ data.push({
key:i, key:i,
id:qds[i]._id , ipstatus:(qds[i].ipstatus) || 'disable',
id:qds[i]._id,
user:qds[i].user, user:qds[i].user,
info:qds[i].info || '--', info:qds[i].info || '--',
schedule:(qds[i].schedule_count) || 0, schedule:(qds[i].schedule_count) || 0,
ip:(qds[i].iplimit) || 0,
tkl:(qds[i].tkl_count) || 0 tkl:(qds[i].tkl_count) || 0
}); });
} }
...@@ -163,7 +214,7 @@ class Qd extends React.Component{ ...@@ -163,7 +214,7 @@ class Qd extends React.Component{
</Form> </Form>
</Modal> </Modal>
</div>: <Alert </div>: <Alert
message="提示" message="抱歉"
description="您没有权限" description="您没有权限"
type="warning" type="warning"
/> />
......
...@@ -4,40 +4,45 @@ const api = require('../../js/api'); ...@@ -4,40 +4,45 @@ const api = require('../../js/api');
import json2xlsx from '../../js/json2xlsx'; import json2xlsx from '../../js/json2xlsx';
import { Table, Icon, DatePicker, Alert, Row, Col, Spin, Button,Modal,Form,Input,Switch,message} from 'antd'; import { Table, Icon, Alert, Row, Col, Spin, Button,Modal,Form,Input,Switch,message,Select,DatePicker} from 'antd';
const { RangePicker } = DatePicker; const { RangePicker } = DatePicker;
const Option = Select.Option;
const FormItem = Form.Item; const FormItem = Form.Item;
class Schedule extends React.Component{ class Schedule extends React.Component{
constructor(props){ constructor(props){
super(props); super(props);
console.dir(this.props); this.state= { currentQd:'all',qds:[],schedules :[],status:'pending',pagination:{current:1,pageSize:10,total:1},modalVisible:false,username:'channel'};
this.state= { schedules :[],status:'pending',pagination:{current:1,pageSize:10,total:1},modalVisible:false,username:'channel'};
} }
componentDidMount(){ componentDidMount(){
let pagination = this.state.pagination; let pagination = this.state.pagination;
if(document.cookie.match('username=[a-zA-Z0-9]+')[0] && document.cookie.match('username=[a-zA-Z0-9]+')[0].split('=')[1]){ if(document.cookie.match('username=[a-zA-Z0-9]+')[0] && document.cookie.match('username=[a-zA-Z0-9]+')[0].split('=')[1]){
this.setState({username:document.cookie.match('username=[a-zA-Z0-9]+')[0].split('=')[1]}); this.setState({username:document.cookie.match('username=[a-zA-Z0-9]+')[0].split('=')[1]});
} }
api('GET', 'qds?skip=0&limit=1000').then((res) => {
this.setState({qds:res.result});
});
//let data = { start:moment().add(-6,'days').format('YYYYMMDD'),end:moment().format('YYYYMMDD')}; //let data = { start:moment().add(-6,'days').format('YYYYMMDD'),end:moment().format('YYYYMMDD')};
api('GET', 'schedules?'+'skip=0&limit=' + pagination.pageSize).then((res) => { api('GET', 'schedules?'+'skip=0&limit=' + pagination.pageSize).then((res) => {
this.setState({schedules:res.result,status:'ready',pagination:{current:res.pagination.skip,pageSize:res.pagination.limit,total:res.pagination.total},info:{quan:'',good:''}}) this.setState({schedules:res.result,status:'ready',pagination:{current:res.pagination.skip,pageSize:res.pagination.limit,total:res.pagination.total},info:{quan:'',good:''}})
console.dir(res.result);
}); });
} }
getschedules(pagination){ getschedules(pagination,qd){
console.dir(pagination); console.dir(pagination);
this.setState({status:'pending'}) this.setState({status:'pending'});
api('GET', 'schedules?'+'skip='+ (pagination.current-1) + '&limit=' + pagination.pageSize).then((res) => { var url = 'schedules?'+'skip='+ (pagination.current-1) + '&limit=' + pagination.pageSize;
if(qd && qd !== 'all')
url += ('&qd='+ qd);
api('GET', url).then((res) => {
this.setState({schedules:res.result,status:'ready',pagination:{current:res.pagination.skip,pageSize:res.pagination.limit,total:res.pagination.total}}) this.setState({schedules:res.result,status:'ready',pagination:{current:res.pagination.skip,pageSize:res.pagination.limit,total:res.pagination.total}})
console.dir(res.result); console.dir(res.result);
}); });
} }
onChange(pagination) { onChange(pagination) {
this.getschedules(pagination); this.getschedules(pagination,this.state.currentQd);
} }
createSchedule(){ createSchedule(){
...@@ -53,11 +58,12 @@ class Schedule extends React.Component{ ...@@ -53,11 +58,12 @@ class Schedule extends React.Component{
var self = this; var self = this;
this.props.form.validateFields((err, values) => { this.props.form.validateFields((err, values) => {
if (!err) { if (!err) {
console.dir(values) if(values['final'])
values['final'] = values.final.valueOf();
api('POST', 'schedule',values).then((res) => { api('POST', 'schedule',values).then((res) => {
if(res && res.result){ if(res && res.result){
self.setModalVisible(false); self.setModalVisible(false);
self.getschedules({limit:this.state.pagination.pageSize,skip:0}); self.getschedules({pageSize:this.state.pagination.pageSize,current:1});
} }
}); });
} }
...@@ -66,7 +72,7 @@ class Schedule extends React.Component{ ...@@ -66,7 +72,7 @@ class Schedule extends React.Component{
checkUpdate(schedule){ checkUpdate(schedule){
var schedules = this.state.schedules; var schedules = this.state.schedules;
var data = { var data = {
status:schedule['status'] == 'use' ? 'disable' : 'use', status:schedule['status'] && schedule['status']['status'] == 'use' ? 'disable' : 'use',
scheduleId:schedule['id'] scheduleId:schedule['id']
} }
var self = this; var self = this;
...@@ -76,7 +82,7 @@ class Schedule extends React.Component{ ...@@ -76,7 +82,7 @@ class Schedule extends React.Component{
message.success('执行成功, 生成'+ (res.new ? res.new.length : 0 )+" 条淘口令"); message.success('执行成功, 生成'+ (res.new ? res.new.length : 0 )+" 条淘口令");
else else
message.success('执行成功, 删除'+ (res.remove_result ? res.remove_result.nModified : 0 )+" 条淘口令"); message.success('执行成功, 删除'+ (res.remove_result ? res.remove_result.nModified : 0 )+" 条淘口令");
schedules[schedule['key']]['status'] = (schedule['status'] == 'use' ? 'disable' : 'use'); schedules[schedule['key']]['status'] = (schedule['status'] && schedule['status']['status'] == 'use' ? 'disable' : 'use');
self.setState({schedules:schedules}); self.setState({schedules:schedules});
} }
//message.success('执行成功, 生成 '+(res.new ? res.new.length : 0) +" 条,删除 "+ (res.remove_result ? res.remove_result.nModified : 0 )+" 条"); //message.success('执行成功, 生成 '+(res.new ? res.new.length : 0) +" 条,删除 "+ (res.remove_result ? res.remove_result.nModified : 0 )+" 条");
...@@ -84,17 +90,38 @@ class Schedule extends React.Component{ ...@@ -84,17 +90,38 @@ class Schedule extends React.Component{
} }
tklUpdate(schedule){ tklUpdate(schedule){
console.dir(schedule);
api('POST', 'newtkl',{id:schedule.id}).then((res) => { api('POST', 'newtkl',{id:schedule.id}).then((res) => {
if(res && res.result =='ok') if(res && res.result =='ok')
message.success('执行成功, 生成 '+(res.new ? res.new.length : 0) +" 条,删除 "+ (res.remove_result ? res.remove_result.nModified : 0 )+" 条"); message.success('执行成功, 生成 '+(res.new ? res.new.length : 0) +" 条,删除 "+ (res.remove_result ? res.remove_result.nModified : 0 )+" 条");
}); });
} }
autoUpdate(schedule){
var schedules = this.state.schedules;
var data = {
auto:schedule['status'] && schedule['status']['auto'] == 'use' ? 'disable' : 'use',
scheduleId:schedule['id']
}
var self = this;
api('POST', 'schedule_auto_update',data).then((res) => {
if(res && res.schedule){
schedules[schedule['key']]['auto'] = (schedule['status'] && schedule['status']['auto'] == 'use' ? 'disable' : 'use');
self.setState({schedules:schedules});
}
//message.success('执行成功, 生成 '+(res.new ? res.new.length : 0) +" 条,删除 "+ (res.remove_result ? res.remove_result.nModified : 0 )+" 条");
});
}
exportData(){ exportData(){
//json2xlsx(data,{sheetName:"基础数据", filename : '基础数据'+moment().format('YYYYMMDD')+'.xlsx'}); //json2xlsx(data,{sheetName:"基础数据", filename : '基础数据'+moment().format('YYYYMMDD')+'.xlsx'});
} }
handleChange(value) {
this.setState({currentQd:value});
this.getschedules({pageSize:this.state.pagination.pageSize,current:1},value)
//console.log(`selected ${value}`);
}
render(){ render(){
const { getFieldDecorator, getFieldsError, getFieldError, isFieldTouched } = this.props.form; const { getFieldDecorator, getFieldsError, getFieldError, isFieldTouched } = this.props.form;
const columns = [ const columns = [
...@@ -123,30 +150,36 @@ class Schedule extends React.Component{ ...@@ -123,30 +150,36 @@ class Schedule extends React.Component{
title: '可用淘口令', title: '可用淘口令',
dataIndex: 'tkls', dataIndex: 'tkls',
key: 'tkls', key: 'tkls',
width: 10, width: 5,
render: text => <span href="#">{text}</span>,
},
{
title: '推广次数',
dataIndex: 'times',
key: 'times',
width: 50,
render: text => <span href="#">{text}</span>, render: text => <span href="#">{text}</span>,
}, },
{ {
title: '创建日期', title: '创建日期',
dataIndex: 'create', dataIndex: 'create',
key: 'create', key: 'create',
width: 70, width: 75,
render: text => <span href="#">{text}</span>,
},
{
title: '截止日期',
dataIndex: 'final',
key: 'final',
width: 75,
render: text => <span href="#">{text}</span>, render: text => <span href="#">{text}</span>,
},{ },{
title: '投放状态 / 操作', title: '投放状态 / 手动替换 / 定时更新 ',
dataIndex: 'status', dataIndex: 'status',
key: 'status', key: 'status',
width: 30, width: 130,
render: (text,schedule) => <div><Switch checked={ text == 'use' ? true : false } onChange={this.checkUpdate.bind(this,schedule)} style = {{'margin-right': '17px'}}/><Button onClick = {this.tklUpdate.bind(this,schedule)}>生成淘口令</Button></div>, render: (data,schedule) => <div><Switch checked={ data.status == 'use' ? true : false } onChange={this.checkUpdate.bind(this,schedule)} style = {{'marginRight': '10px'}}/><Button onClick = {this.tklUpdate.bind(this,schedule)} style = {{'marginRight': '10px'}}>生成淘口令</Button>
<Switch checked={ data.auto == 'use' ? true : false } onChange={this.autoUpdate.bind(this,schedule)} style = {{'marginRight': '17px'}}/></div>,
} }
]; ];
let children = [<Option key='all'>全部</Option>];
for (var i = 0; i < this.state.qds.length; i++) {
let item = this.state.qds[i];
children.push(<Option key={item._id}>{ item.user }</Option>);
}
let data = []; let data = [];
let schedules = this.state.schedules; let schedules = this.state.schedules;
for(let i = 0;i<schedules.length;i++){ for(let i = 0;i<schedules.length;i++){
...@@ -158,8 +191,9 @@ class Schedule extends React.Component{ ...@@ -158,8 +191,9 @@ class Schedule extends React.Component{
data.push({ data.push({
key:i, key:i,
id:(schedules[i]._id && schedules[i]._id) || '--', id:(schedules[i]._id && schedules[i]._id) || '--',
final:schedules[i].final || '--',
names:names || '--', names:names || '--',
status:schedules[i].status, status:{ status:schedules[i].status,auto:schedules[i].auto},
qd:((schedules[i].qd && schedules[i].qd['user']) || '--') + ' /' + ((schedules[i].qd && schedules[i].qd['_id']) || '--'), qd:((schedules[i].qd && schedules[i].qd['user']) || '--') + ' /' + ((schedules[i].qd && schedules[i].qd['_id']) || '--'),
tkls:(schedules[i].count), tkls:(schedules[i].count),
times:schedules[i].times, times:schedules[i].times,
...@@ -171,6 +205,14 @@ class Schedule extends React.Component{ ...@@ -171,6 +205,14 @@ class Schedule extends React.Component{
<Button type="primary" icon="plus" onClick={ this.createSchedule.bind(this) } style={{ margin:'10px 0px'}}> <Button type="primary" icon="plus" onClick={ this.createSchedule.bind(this) } style={{ margin:'10px 0px'}}>
创建计划 创建计划
</Button> </Button>
<Select
style={{ float:'right',width:200,margin:'10px 0px'}}
placeholder="输入渠道名称"
defaultValue="all"
onChange={this.handleChange.bind(this)}
>
{children}
</Select>
<Spin spinning= { this.state.status == 'pending' }> <Spin spinning= { this.state.status == 'pending' }>
<Table columns={columns} dataSource = { data } size="middle" pagination={ this.state.pagination } onChange = { this.onChange.bind(this)} bordered/> <Table columns={columns} dataSource = { data } size="middle" pagination={ this.state.pagination } onChange = { this.onChange.bind(this)} bordered/>
</Spin> </Spin>
...@@ -203,6 +245,15 @@ class Schedule extends React.Component{ ...@@ -203,6 +245,15 @@ class Schedule extends React.Component{
<Input prefix={<span style={{ fontSize: 13 }}>推广次数</span>} placeholder="例如:1000000" /> <Input prefix={<span style={{ fontSize: 13 }}>推广次数</span>} placeholder="例如:1000000" />
)} )}
</FormItem> </FormItem>
<FormItem>
<span style={{ fontSize: 13,display:"block" }}>截止日期</span>
{getFieldDecorator('final',{ type: 'object', required: true, message: 'Please select time!' })(
<DatePicker
showTime
format="YYYY-MM-DD HH:mm:ss"
placeholder="选择"/>
)}
</FormItem>
<FormItem> <FormItem>
<Button type="primary" htmlType="submit" className="login-form-button"> <Button type="primary" htmlType="submit" className="login-form-button">
一键生成 一键生成
...@@ -211,7 +262,7 @@ class Schedule extends React.Component{ ...@@ -211,7 +262,7 @@ class Schedule extends React.Component{
</Form> </Form>
</Modal> </Modal>
</div>: <Alert </div>: <Alert
message="提示" message="抱歉"
description="您没有权限" description="您没有权限"
type="warning" type="warning"
/> />
......
...@@ -4,7 +4,8 @@ const api = require('../../js/api'); ...@@ -4,7 +4,8 @@ const api = require('../../js/api');
import json2xlsx from '../../js/json2xlsx'; import json2xlsx from '../../js/json2xlsx';
import { Table, Icon, DatePicker, Alert, Row, Col, Spin, Button,Modal,Form,Input} from 'antd'; import { Table, Icon, DatePicker, Alert, Row, Col, Spin, Button,Modal,Form,Input,Radio} from 'antd';
const RadioGroup = Radio.Group;
const { RangePicker } = DatePicker; const { RangePicker } = DatePicker;
const FormItem = Form.Item; const FormItem = Form.Item;
...@@ -13,7 +14,7 @@ class Agent extends React.Component{ ...@@ -13,7 +14,7 @@ class Agent extends React.Component{
constructor(props){ constructor(props){
super(props); super(props);
console.dir(this.props); console.dir(this.props);
this.state= { links :[],status:'pending',pagination:{current:1,pageSize:10,total:1},modalVisible:false,username:'channel'}; this.state= { links :[],status:'pending',pagination:{current:1,pageSize:500,total:1},modalVisible:false,username:'channel'};
} }
componentDidMount(){ componentDidMount(){
let pagination = this.state.pagination; let pagination = this.state.pagination;
...@@ -53,6 +54,9 @@ class Agent extends React.Component{ ...@@ -53,6 +54,9 @@ class Agent extends React.Component{
var self = this; var self = this;
this.props.form.validateFields((err, values) => { this.props.form.validateFields((err, values) => {
if (!err) { if (!err) {
for(var k in values){
if(values[k]) values[k] = values[k].trim();
}
api('POST', 'link',values).then((res) => { api('POST', 'link',values).then((res) => {
if(res && res.result){ if(res && res.result){
self.setModalVisible(false); self.setModalVisible(false);
...@@ -105,7 +109,7 @@ class Agent extends React.Component{ ...@@ -105,7 +109,7 @@ class Agent extends React.Component{
render: text => <span href="#">{text}</span>, render: text => <span href="#">{text}</span>,
}, },
{ {
title: '二合一', title: '目标链接',
dataIndex: 'target', dataIndex: 'target',
key: 'target', key: 'target',
width: 100, width: 100,
...@@ -192,6 +196,16 @@ class Agent extends React.Component{ ...@@ -192,6 +196,16 @@ class Agent extends React.Component{
})( })(
<Input prefix={<span style={{ fontSize: 13 }}>PID</span>} placeholder="例如:mm_33320967_40070156_153504280" /> <Input prefix={<span style={{ fontSize: 13 }}>PID</span>} placeholder="例如:mm_33320967_40070156_153504280" />
)} )}
</FormItem>
<FormItem
label="推广使用"
>
{getFieldDecorator('select')(
<RadioGroup>
<Radio value="quan">优惠券链接</Radio>
<Radio value="target">二合一链接</Radio>
</RadioGroup>
)}
</FormItem> </FormItem>
<FormItem> <FormItem>
<Button type="primary" htmlType="submit" className="login-form-button"> <Button type="primary" htmlType="submit" className="login-form-button">
...@@ -201,7 +215,7 @@ class Agent extends React.Component{ ...@@ -201,7 +215,7 @@ class Agent extends React.Component{
</Form> </Form>
</Modal> </Modal>
</div> : <Alert </div> : <Alert
message="提示" message="抱歉"
description="您没有权限" description="您没有权限"
type="warning" type="warning"
/> />
......
...@@ -107,14 +107,14 @@ class Tbkls extends React.Component{ ...@@ -107,14 +107,14 @@ class Tbkls extends React.Component{
this.state.username == 'admin' ? <div> this.state.username == 'admin' ? <div>
<Alert <Alert
message="提示" message="提示"
description="淘口令后台任务自动生成" description="淘口令后台任务自动生成"
type="info" type="info"
/> />
<Spin spinning= { this.state.status == 'pending' }> <Spin spinning= { this.state.status == 'pending' }>
<Table columns={columns} dataSource = { data } size="middle" pagination={ this.state.pagination } onChange = { this.onChange.bind(this)} bordered/> <Table columns={columns} dataSource = { data } size="middle" pagination={ this.state.pagination } onChange = { this.onChange.bind(this)} bordered/>
</Spin> </Spin>
</div>: <Alert </div>: <Alert
message="提示" message="抱歉"
description="您没有权限" description="您没有权限"
type="warning" type="warning"
/> />
......
const React = require('react');
const moment = require('moment');
const api = require('../../js/api');
import json2xlsx from '../../js/json2xlsx';
import { Table, Icon, DatePicker, Alert, Spin, Button,Badge,Form,Input,InputNumber,Row,Col,message,Card} from 'antd';
const FormItem = Form.Item;
class Tools extends React.Component{
constructor(props){
super(props);
console.dir(this.props);
this.state= { tkls:[],good:{title:'',pict_url:'',target:''} ,status:'pending'};
}
componentDidMount(){
}
handleSubmit(e){
e.preventDefault();
var self = this;
this.props.form.validateFields((err, values) => {
if (!err) {
console.dir(values);
/* api('POST', 'link',values).then((res) => {
if(res && res.result){
self.setModalVisible(false);
self.getLinks({limit:this.state.pagination.pageSize,skip:0});
}
});*/
self.getTkls(values);
}
});
}
getTkls(data){
//this.setState({status:'pending'});
api('POST', 'tool2_tbkls',data).then((res) => {
//this.setState({details:res.result,status:'ready',pagination:{current:res.pagination.skip,pageSize:res.pagination.limit,total:res.pagination.total}})
if(res.result && res.good) this.setState({tkls:res.result,good:res.good,status:'ready'});
else message.warn('请求错误');
});
}
render(){
const { getFieldDecorator, getFieldsError, getFieldError, isFieldTouched } = this.props.form;
var list = [];
this.state.tkls.forEach(item => {
list.push(<span className ='model' >{ item.model }</span>)
});
return (
<div className ='tool-box'>
<Form onSubmit={this.handleSubmit.bind(this)} className="login-form" style ={{ width:'50%','max-width': '350px','min-width': '300px','background': '#ddd','padding': '10px'}}>
<FormItem
label="淘口令数量"
>
{getFieldDecorator('num', { initialValue: 10 })(
<InputNumber min={1} max={100} />
)}
<span className="ant-form-text"></span>
</FormItem>
<FormItem>
{getFieldDecorator('url', {
rules: [{ required: true, message: '链接不能为空' }],
})(
<Input prefix={<span style={{ fontSize: 13 }}>优惠券链接</span>} placeholder="例如:https://taoquan.taobao.com/coupon/unify_apply.htm?sellerId=2194810505&activityId=5c3186407cd441d48ecd2460815793e6" />
)}
</FormItem>
<FormItem>
{getFieldDecorator('logo', {
rules: [{ required: false, message: '图片链接不能为空' }],
})(
<Input prefix={<span style={{ fontSize: 13 }}>图片链接</span>} placeholder="例如:https://detail.tmall.com/item.htm?id=40663494639" />
)}
</FormItem>
<FormItem>
{getFieldDecorator('text', {
rules: [{ required: true, message: '推广语' }],
})(
<Input prefix={<span style={{ fontSize: 13 }}>推广语</span>} placeholder="例如:mm_33320967_40070156_153504280" />
)}
</FormItem>
<FormItem>
<Button type="primary" htmlType="submit" className="login-form-button">
一键生成
</Button>
</FormItem>
</Form>
{
this.state.status !== 'pending' ?
<div style ={{ padding:'50px 30px','min-width':'500px'}}>
<div className ='label-info'>
<label>LOGO大图</label>
<img src = { this.state.good.logo } />
</div>
<div className ='label-info'>
<label>推广语</label>
<div><p>{ this.state.good.text }</p></div>
</div>
<div className ='label-info'>
<label>目标连接</label>
<div><p>{ this.state.good.url }</p></div>
</div>
<label className='tkllabel'>淘口令</label>
<div className = 'model-box'>
{ list }
</div>
</div> : <div className ='none'>填写内容,尝试生成淘口令吧 ~ ~</div>
}
</div>
)
}
}
Tools = Form.create()(Tools);
module.exports = Tools;
const React = require('react');
const moment = require('moment');
const api = require('../../js/api');
import json2xlsx from '../../js/json2xlsx';
import { Table, Icon, DatePicker, Alert, Spin, Button,Badge,Form,Input,InputNumber,Row,Col,message,Card} from 'antd';
const FormItem = Form.Item;
class Tools extends React.Component{
constructor(props){
super(props);
console.dir(this.props);
this.state= { tkls:[],good:{title:'',pict_url:'',target:''} ,status:'pending'};
}
componentDidMount(){
}
handleSubmit(e){
e.preventDefault();
var self = this;
this.props.form.validateFields((err, values) => {
if (!err) {
console.dir(values);
/* api('POST', 'link',values).then((res) => {
if(res && res.result){
self.setModalVisible(false);
self.getLinks({limit:this.state.pagination.pageSize,skip:0});
}
});*/
self.getTkls(values);
}
});
}
getTkls(data){
//this.setState({status:'pending'});
api('POST', 'tool_tbkls',data).then((res) => {
//this.setState({details:res.result,status:'ready',pagination:{current:res.pagination.skip,pageSize:res.pagination.limit,total:res.pagination.total}})
if(res.result && res.good) this.setState({tkls:res.result,good:res.good,status:'ready'});
else message.warn('请求错误');
});
}
render(){
const { getFieldDecorator, getFieldsError, getFieldError, isFieldTouched } = this.props.form;
var list = [];
this.state.tkls.forEach(item => {
list.push(<span className ='model' >{ item.model }</span>)
});
return (
<div className ='tool-box'>
<Form onSubmit={this.handleSubmit.bind(this)} className="login-form" style ={{ width:'50%','max-width': '350px','min-width': '300px','background': '#ddd','padding': '10px'}}>
<FormItem
label="淘口令数量"
>
{getFieldDecorator('num', { initialValue: 10 })(
<InputNumber min={1} max={100} />
)}
<span className="ant-form-text"></span>
</FormItem>
<FormItem>
{getFieldDecorator('quan', {
rules: [{ required: true, message: '优惠券链接不能为空' }],
})(
<Input prefix={<span style={{ fontSize: 13 }}>优惠券链接</span>} placeholder="例如:https://taoquan.taobao.com/coupon/unify_apply.htm?sellerId=2194810505&activityId=5c3186407cd441d48ecd2460815793e6" />
)}
</FormItem>
<FormItem>
{getFieldDecorator('good', {
rules: [{ required: true, message: '商品连接不能为空' }],
})(
<Input prefix={<span style={{ fontSize: 13 }}>商品连接</span>} placeholder="例如:https://detail.tmall.com/item.htm?id=40663494639" />
)}
</FormItem>
<FormItem>
{getFieldDecorator('pid', {
rules: [{ required: true, message: 'pid不能为空' }],
})(
<Input prefix={<span style={{ fontSize: 13 }}>PID</span>} placeholder="例如:mm_33320967_40070156_153504280" />
)}
</FormItem>
<FormItem>
<Button type="primary" htmlType="submit" className="login-form-button">
一键生成
</Button>
</FormItem>
</Form>
{
this.state.status !== 'pending' ?
<div style ={{ padding:'50px 30px','min-width':'500px'}}>
<div className ='label-info'>
<label>LOGO大图</label>
<img src = { this.state.good.pict_url } />
</div>
<div className ='label-info'>
<label>推广语</label>
<div><p>{ this.state.good.title }</p></div>
</div>
<div className ='label-info'>
<label>二合一连接</label>
<div><p>{ this.state.good.target }</p></div>
</div>
<label className='tkllabel'>淘口令</label>
<div className = 'model-box'>
{ list }
</div>
</div> : <div className ='none'>填写内容,尝试生成淘口令吧 ~ ~</div>
}
</div>
)
}
}
Tools = Form.create()(Tools);
module.exports = Tools;
...@@ -14,7 +14,7 @@ class DashBoard extends React.Component{ ...@@ -14,7 +14,7 @@ class DashBoard extends React.Component{
constructor(props){ constructor(props){
super(props); super(props);
this.range = [moment().subtract(6,'days').format('YYYYMMDD'), moment().format('YYYYMMDD')]; this.range = [moment().subtract(14,'days').format('YYYYMMDD'), moment().format('YYYYMMDD')];
this.state= { logs :[],status:'pending',pagination:{current:1,pageSize:100,total:1},sort:'updatedAt' }; this.state= { logs :[],status:'pending',pagination:{current:1,pageSize:100,total:1},sort:'updatedAt' };
} }
componentDidMount(){ componentDidMount(){
......
const React = require('react'); const React = require('react');
/*const connect = require('react-redux').connect;
const actions = require('../../js/actions');*/
const moment = require('moment'); const moment = require('moment');
const api = require('../../js/api'); const api = require('../../js/api');
import ReactEcharts from "echarts-for-react";
import json2xlsx from '../../js/json2xlsx'; import json2xlsx from '../../js/json2xlsx';
import { Table, Icon, DatePicker, Alert, Row, Col, Spin, Button,Popover} from 'antd'; import { Table, Icon, DatePicker, Alert, Row, Col, Spin, Button,Popover,Form,Input,Modal,InputNumber,message,Select} from 'antd';
const FormItem = Form.Item;
const { RangePicker } = DatePicker; const { RangePicker } = DatePicker;
class Gather extends React.Component{ class Gather extends React.Component{
constructor(props){ constructor(props){
super(props); super(props);
this.range = [moment().subtract(6,'days').format('YYYYMMDD'), moment().format('YYYYMMDD')]; //this._t = null;
this.state= { qdgathers :[],status:'pending',pagination:{current:1,pageSize:20,total:100},username:'channel',tody:{ tkl_count:0,count:0,schedule_count:0} ,none_tkls:[],list:[]}; this.range = [moment().subtract(14,'days').format('YYYYMMDD'), moment().format('YYYYMMDD')];
this.state= { range:this.range,currentQd:'all',qds:[],qdgathers :[],status:'pending',pagination:{current:1,pageSize:20,total:100},username:'channel',tody:{ tkl_count:0,count:0,schedule_count:0} ,none_tkls:[],list:[],modalVisible:false,xAxis:[],series:[],loading:true};
} }
componentDidMount(){ componentDidMount(){
let data = { start:moment().add(-6,'days').format('YYYYMMDD'),end:moment().format('YYYYMMDD')}; //let data = { start:moment().add(-6,'days').format('YYYYMMDD'),end:moment().format('YYYYMMDD')};
if(document.cookie.match('username=[a-zA-Z0-9]+')[0] && document.cookie.match('username=[a-zA-Z0-9]+')[0].split('=')[1]){ if(document.cookie.match('username=[a-zA-Z0-9]+')[0] && document.cookie.match('username=[a-zA-Z0-9]+')[0].split('=')[1]){
this.setState({username:document.cookie.match('username=[a-zA-Z0-9]+')[0].split('=')[1]}); this.setState({username:document.cookie.match('username=[a-zA-Z0-9]+')[0].split('=')[1]});
if(document.cookie.match('username=[a-zA-Z0-9]+')[0].split('=')[1] == 'admin')
api('GET', 'qds?skip=0&limit=1000').then((res) => {
this.setState({qds:res.result});
});
} }
api('GET', 'gathers/qd?skip=0&limit=20').then((res) => { api('GET', 'gathers/qd?skip=0&limit=20').then((res) => {
this.setState({qdgathers:res.result,status:'ready',none_tkls:res.none_tkls,list:res.list,pagination:{current:res.pagination.skip,pageSize:res.pagination.limit,total:res.pagination.total}}); this.setState({qdgathers:res.result,status:'ready',none_tkls:res.none_tkls,list:res.list,pagination:{current:res.pagination.skip,pageSize:res.pagination.limit,total:res.pagination.total}});
...@@ -27,6 +33,104 @@ class Gather extends React.Component{ ...@@ -27,6 +33,104 @@ class Gather extends React.Component{
}); });
} }
onChartReady(chart){
//console.dir('in onChartReady');
var self = this;
if(document.cookie.match('username=[a-zA-Z0-9]+')[0] && document.cookie.match('username=[a-zA-Z0-9]+')[0].split('=')[1]){
this.getCharts(this.range[0],this.range[1]);
chart.hideLoading();
}
/* this._t = setTimeout(function() {
chart.hideLoading();
}, 3000);*/
}
getCharts(start,end){
var self = this;
this.setState({loading:true});
api('GET','gatherall?start=' +start+ '&end=' + end).then((res) => {
if(res.status == 'ok' && res.list && res.list.length){
var times = [];
var dc_times = [];
var xAxis = [];
res.list.sort(function(a,b){ return parseInt(a._id) - parseInt(b._id) });
for(var k in res.list){
var item = res.list[k];
times.push(item.times);
dc_times.push(item.dc_times);
xAxis.push(item.date);
}
self.setState({series:[ {
name:'请求数',
type:'line',
stack: '总量',
areaStyle: {normal: {}},
data:times
},
{
name:'导出数',
type:'line',
stack: '总量',
areaStyle: {normal: {}},
data:dc_times
}],xAxis:xAxis,loading:false});
}
else
message.warn('取数错误');
//this.setState({}});
});
}
getLoadingOption(){
//console.dir('in getLoadingOption');
return {
text: '加载中...',
color: '#4413c2',
textColor: '#270240',
maskColor: '#108ee982',//'rgba(194, 88, 86, 0.3)',
zlevel: 0
};
}
getOption(){
return {
title: {
text: '每日走势图'
},
tooltip : {
trigger: 'axis'
},
legend: {
data:['请求数','导出数']
},
toolbox: {
feature: {
saveAsImage: {}
}
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis : [
{
type : 'category',
boundaryGap : false,
data : this.state.xAxis
}
],
yAxis : [
{
type : 'value'
}
],
series : this.state.series
};
}
handle(list,tkl_count){ handle(list,tkl_count){
var sum = 0; var sum = 0;
for(var k in list){ for(var k in list){
...@@ -36,9 +140,12 @@ class Gather extends React.Component{ ...@@ -36,9 +140,12 @@ class Gather extends React.Component{
} }
getQdGathers(pagination){ getQdGathers(pagination,qd){
this.setState({status:'pending'}) this.setState({status:'pending'});
api('GET', 'gathers/qd?'+'skip='+ (pagination.current-1) + '&limit=' + pagination.pageSize).then((res) => { var url = 'gathers/qd?'+'skip='+ (pagination.current-1) + '&limit=' + pagination.pageSize;
if(qd && qd !== 'all' && this.state.username == 'admin')
url += ('&qd='+ qd);
api('GET',url).then((res) => {
this.setState({qdgathers:res.result,status:'ready',pagination:{current:res.pagination.skip,pageSize:res.pagination.limit,total:res.pagination.total},none_tkls:res.none_tkls,list:res.list}); this.setState({qdgathers:res.result,status:'ready',pagination:{current:res.pagination.skip,pageSize:res.pagination.limit,total:res.pagination.total},none_tkls:res.none_tkls,list:res.list});
this.handle(res.list,res.tkl_count); this.handle(res.list,res.tkl_count);
}); });
...@@ -47,11 +154,28 @@ class Gather extends React.Component{ ...@@ -47,11 +154,28 @@ class Gather extends React.Component{
onChange(pagination) { onChange(pagination) {
//let data = { start:dateString[0],end:dateString[1]}; //let data = { start:dateString[0],end:dateString[1]};
//this.props.dispatch(actions.getMainData(data)); //this.props.dispatch(actions.getMainData(data));
this.getQdGathers(pagination); this.getQdGathers(pagination,this.state.currentQd);
} }
onChangeDate(){ dc_timesChange(data,value){
console.dir(data);
console.dir(value);
var key = data['key'];
var qdgathers = this.state.qdgathers;
console.dir(qdgathers.length + '====');
qdgathers[key]['dc_times'] = value;
this.setState({qdgathers:qdgathers})
}
componentWillUnmount() {
//clearTimeout(this._t);
};
onChangeDate(date,dateString){
//let data = { start:dateString[0],end:dateString[1]};
//this.range = ;
this.setState({range:[dateString[0],dateString[1]]});
this.getCharts(dateString[0],dateString[1])
//console.dir(data);
} }
exportData(){ exportData(){
...@@ -59,6 +183,31 @@ class Gather extends React.Component{ ...@@ -59,6 +183,31 @@ class Gather extends React.Component{
//json2xlsx(data,{sheetName:"基础数据", filename : '基础数据'+moment().format('YYYYMMDD')+'.xlsx'}); //json2xlsx(data,{sheetName:"基础数据", filename : '基础数据'+moment().format('YYYYMMDD')+'.xlsx'});
} }
setModalVisible(b){
this.setState({modalVisible:b});
}
detaiShow(){
this.setModalVisible(true);
}
putexData(data){
console.dir(data);
api('POST','put_data',{dc_times:data['dc_times'],id:data['id']}).then( res => {
message.success('执行成功, 影响'+ (res.result ? res.result.nModified : 0 )+" 条数据");
});
}
handleSubmit(){
}
handleChange(value) {
this.setState({currentQd:value});
this.getQdGathers({pageSize:this.state.pagination.pageSize,current:1},value)
//console.log(`selected ${value}`);
}
detailData(data){ detailData(data){
console.dir(data); console.dir(data);
var date = data.date; var date = data.date;
...@@ -67,20 +216,20 @@ class Gather extends React.Component{ ...@@ -67,20 +216,20 @@ class Gather extends React.Component{
} }
render(){ render(){
console.dir(this.state.pagination); const { getFieldDecorator, getFieldsError, getFieldError, isFieldTouched } = this.props.form;
const columns = [ const columns = [
{ {
title: '日期', title: '日期',
dataIndex: 'date', dataIndex: 'date',
key: 'date', key: 'date',
width: 80, width: 40,
render: text => <span href="#">{text}</span>, render: text => <span href="#">{text}</span>,
}, },
{ {
title: '渠道/分发ID', title: '渠道/分发ID',
dataIndex: 'user', dataIndex: 'user',
key: 'user', key: 'user',
width: 100, width: 120,
render: text => <span href="#">{text}</span>, render: text => <span href="#">{text}</span>,
}, },
{ {
...@@ -105,7 +254,37 @@ class Gather extends React.Component{ ...@@ -105,7 +254,37 @@ class Gather extends React.Component{
render: text => <span href="#">{text}</span>, render: text => <span href="#">{text}</span>,
} }
]; ];
if(this.state.username == 'admin') const modal_columns = [
{
title: '日期',
dataIndex: 'date',
key: 'date',
width: 40,
render: text => <span href="#">{text}</span>,
},
{
title: '渠道',
dataIndex: 'user',
key: 'user',
width: 10,
render: text => <span href="#">{text}</span>,
},
{
title: '推广页',
dataIndex: 'page',
key: 'page',
width: 100,
render: text => <span href="#">{text}</span>,
},
{
title: '请求数',
dataIndex: 'times',
key: 'times',
width: 50,
render: text => <span href="#">{text}</span>,
}
];
if(this.state.username == 'admin'){
columns.push({ columns.push({
title: '详情', title: '详情',
dataIndex: 'detail', dataIndex: 'detail',
...@@ -118,13 +297,33 @@ class Gather extends React.Component{ ...@@ -118,13 +297,33 @@ class Gather extends React.Component{
</Popover> </Popover>
}); });
let range = this.range; columns.push({
title: '操作',
dataIndex: 'put',
key: 'put',
width: 10,
render: (text,data) =><div>
<InputNumber min={0} max={1000000000000000} value = { text || 0 } onChange = { this.dc_timesChange.bind(this,data)}/>
<Button type="primary" icon="plus" onClick={ this.putexData.bind(this,data) } style = {{ marginLeft:'10px' }}>
录入
</Button>
</div>
});
}
let children = [<Select.Option key='all'>全部</Select.Option>];
for (var i = 0; i < this.state.qds.length; i++) {
let item = this.state.qds[i];
children.push(<Select.Option key={item._id}>{ item.user }</Select.Option>);
}
let range = this.state.range;
var start = range[0]; var start = range[0];
var end = range[1]; var end = range[1];
let ranges = []; let ranges = [];
ranges.push(moment(start,'YYYYMMDD')); ranges.push(moment(start,'YYYYMMDD'));
ranges.push(moment(end,'YYYYMMDD')); ranges.push(moment(end,'YYYYMMDD'));
let data = []; let data = [];
let modal_data = [];
let count = 0; let count = 0;
let qdgathers = this.state.qdgathers; let qdgathers = this.state.qdgathers;
...@@ -133,11 +332,13 @@ class Gather extends React.Component{ ...@@ -133,11 +332,13 @@ class Gather extends React.Component{
var detail_list_show = []; var detail_list_show = [];
var data_item = { var data_item = {
key:i, key:i,
id:item._id,
qd:(item.qd && item.qd._id), qd:(item.qd && item.qd._id),
date:item.date, date:item.date,
user:(item.qd && item.qd.user) + ' / ' + (item.qd && item.qd._id), user:(item.qd && item.qd.user) + ' / ' + (item.qd && item.qd._id),
times:item.times || 0, times:item.times || 0,
dc_times:item.dc_times || 0, dc_times:item.dc_times || 0,
put:item.dc_times || 0,
rate:item.dc_times / item.times ? ((item.dc_times / item.times).toFixed(6) * 100).toFixed(3) : 0 rate:item.dc_times / item.times ? ((item.dc_times / item.times).toFixed(6) * 100).toFixed(3) : 0
} }
if(this.state.username == 'admin'){ if(this.state.username == 'admin'){
...@@ -150,6 +351,13 @@ class Gather extends React.Component{ ...@@ -150,6 +351,13 @@ class Gather extends React.Component{
if(_item.schedule && _item.schedule.links) if(_item.schedule && _item.schedule.links)
links = _item.schedule.links.map( x => x.name).join(',') links = _item.schedule.links.map( x => x.name).join(',')
var times = _item.times; var times = _item.times;
modal_data.push({
key:i + '' + j,
date:item.date,
user:(item.qd && item.qd.user),
page:links,
times:times
});
detail_list_show.push(<div className="detail-body-list" key={ schedule_id }><span>{ schedule_id }</span><span>{ links }</span><span>{ times }</span></div>); detail_list_show.push(<div className="detail-body-list" key={ schedule_id }><span>{ schedule_id }</span><span>{ links }</span><span>{ times }</span></div>);
} }
var detail_content = ( var detail_content = (
...@@ -169,7 +377,8 @@ class Gather extends React.Component{ ...@@ -169,7 +377,8 @@ class Gather extends React.Component{
for(var i in none_tkls){ for(var i in none_tkls){
sum += none_tkls[i]['times']; sum += none_tkls[i]['times'];
let qd = none_tkls[i]["qd"]; let qd = none_tkls[i]["qd"];
if(qd) list_show.push(<div className="detail-body" key={ qd['user'] }><span>{qd['user']}</span><span>{ none_tkls[i]['times'] }</span></div>) let iplimit = none_tkls[i]["iplimit"] || 0;
list_show.push(<div className="detail-body" key={ Math.random() }><span>{ qd && qd['user'] || '未知'}</span><span>{ iplimit == 1 ? 'ip限制' : 'bug' }</span><span>{ none_tkls[i]['times'] }</span></div>)
} }
var map2qd = {}; var map2qd = {};
for(var k in list){ for(var k in list){
...@@ -233,10 +442,48 @@ class Gather extends React.Component{ ...@@ -233,10 +442,48 @@ class Gather extends React.Component{
</Col> </Col>
</Row> </Row>
</div> </div>
{<RangePicker onChange={ this.onChangeDate.bind(this) } value={ ranges } format={'YYYYMMDD'} style={{margin:'10px 0px'}}/>} { this.state.username == 'admin' ? <RangePicker onChange={ this.onChangeDate.bind(this) } value={ ranges } format={'YYYYMMDD'} style={{margin:'10px 0px'}}/> : <div></div> }
{ this.state.username == 'admin' ? <ReactEcharts
option={this.getOption()}
style={{height: '350px', width: '100%',margin:'20px 0px'}}
onChartReady={this.onChartReady.bind(this)}
loadingOption={this.getLoadingOption.bind(this)()}
showLoading={this.state.loading}
className='react_for_echarts' /> : <div></div>}
<div style={{ overflow:"hidden"}}>
<Button type="primary" icon="export" onClick={ this.exportData.bind(this) } style={{ float:'right',margin:'10px 0px'}}> <Button type="primary" icon="export" onClick={ this.exportData.bind(this) } style={{ float:'right',margin:'10px 0px'}}>
导出数据 导出数据
</Button> </Button>
{
this.state.username == 'admin' ?
<Button type="primary" onClick={ this.detaiShow.bind(this) } style={{ float:'right',margin:'10px'}}>
本页详情
</Button> : <div></div>
}
{
this.state.username == 'admin' ? <Modal
title="数据详情"
style={{ top: 30 }}
visible={this.state.modalVisible}
footer = { null }
onCancel = { this.setModalVisible.bind(this,false) }
>
<Table columns={ modal_columns } dataSource = { modal_data } size="middle" bordered/>
</Modal> : <div></div>
}
{
this.state.username == 'admin' ? <Select
style={{ float:'left',width:200,margin:'10px 0px'}}
placeholder="输入渠道名称"
defaultValue="all"
onChange={this.handleChange.bind(this)}
>
{children}
</Select>: <div></div>
}
</div>
<Spin spinning= { this.state.status == 'pending' }> <Spin spinning= { this.state.status == 'pending' }>
<Table columns={columns} dataSource = { data } pagination={ this.state.pagination } onChange = { this.onChange.bind(this)} size="middle" bordered/> <Table columns={columns} dataSource = { data } pagination={ this.state.pagination } onChange = { this.onChange.bind(this)} size="middle" bordered/>
</Spin> </Spin>
...@@ -251,7 +498,7 @@ function mapStateToProps (state) { ...@@ -251,7 +498,7 @@ function mapStateToProps (state) {
} }
module.exports = connect(mapStateToProps)(DashBoard);*/ module.exports = connect(mapStateToProps)(DashBoard);*/
Gather = Form.create()(Gather);
module.exports = Gather; module.exports = Gather;
......
...@@ -5,7 +5,9 @@ module.exports = { ...@@ -5,7 +5,9 @@ module.exports = {
//mongo:'mongodb://127.0.0.1:27017/taoarticle', //mongo:'mongodb://127.0.0.1:27017/taoarticle',
taobao: { taobao: {
host:"http://gw.api.taobao.com/router/rest", host:"http://gw.api.taobao.com/router/rest",
appKey:"24594025",//"23580470",//"23390725", appKey:"23390725",
appSecret:'def2396c763580d49e4a0aa15c4c18bd'//"e5f350cbdbd6db2a8727f0b65dac1f7c",//"0575587ba36b29fa5680ad571c5e51f4" appSecret:'0575587ba36b29fa5680ad571c5e51f4'
//appKey:"24594025",//"23580470",//"23390725",
// appSecret:'def2396c763580d49e4a0aa15c4c18bd'//"e5f350cbdbd6db2a8727f0b65dac1f7c",//"0575587ba36b29fa5680ad571c5e51f4"
} }
}; };
\ No newline at end of file
...@@ -4,7 +4,9 @@ module.exports = { ...@@ -4,7 +4,9 @@ module.exports = {
mongo:'mongodb://user:password@mongo-gp-content-distribution-1.localhost:1302,mongo-gp-content-distribution-2.localhost:1302,mongo-gp-content-distribution-3.localhost:1302/taoarticle?replicaSet=gp-content-aiweibang', mongo:'mongodb://user:password@mongo-gp-content-distribution-1.localhost:1302,mongo-gp-content-distribution-2.localhost:1302,mongo-gp-content-distribution-3.localhost:1302/taoarticle?replicaSet=gp-content-aiweibang',
taobao: { taobao: {
host:"http://gw.api.taobao.com/router/rest", host:"http://gw.api.taobao.com/router/rest",
appKey:"24594025",//"23580470",//"23390725", appKey:"23390725",
appSecret:'def2396c763580d49e4a0aa15c4c18bd'//"e5f350cbdbd6db2a8727f0b65dac1f7c",//"0575587ba36b29fa5680ad571c5e51f4" appSecret:'0575587ba36b29fa5680ad571c5e51f4'
//appKey:"24594025",//"23580470",//"23390725",
//appSecret:'def2396c763580d49e4a0aa15c4c18bd'//"e5f350cbdbd6db2a8727f0b65dac1f7c",//"0575587ba36b29fa5680ad571c5e51f4"
} }
}; };
\ No newline at end of file
...@@ -13,6 +13,14 @@ const schema = mongoose.Schema({ ...@@ -13,6 +13,14 @@ const schema = mongoose.Schema({
required: true, required: true,
set: v => hash(v) set: v => hash(v)
}, },
ipstatus:{
type:String,
required:false
},
iplimit:{
type:Number,
required:false
},
info:{ info:{
type: String, type: String,
unique: false unique: false
......
const mongoose = require('mongoose');
const {ObjectId} = mongoose.SchemaTypes;
const schema = mongoose.Schema({
ip: {
type: String,
required: true
},
date:{
type:String,
required:true
},
qd: {
type: ObjectId,
ref:'tao-agent',
required: true
},
times:{
type:Number,
required:true
}
}, {
timestamps: true
});
schema.index({ip: 1});
module.exports = mongoose.model('tao-ip', schema);
...@@ -15,6 +15,14 @@ const schema = mongoose.Schema({ ...@@ -15,6 +15,14 @@ const schema = mongoose.Schema({
times:{ times:{
type:Number, type:Number,
required: true required: true
},
auto:{
type:String,
required: false
},
final:{
type:Number,
required:false
} }
}, { }, {
timestamps: true timestamps: true
......
...@@ -9,12 +9,14 @@ const Session = require('../db/mongo/session'); ...@@ -9,12 +9,14 @@ const Session = require('../db/mongo/session');
const Agent = require('../db/mongo/tao-agent'); const Agent = require('../db/mongo/tao-agent');
const Schedule = require('../db/mongo/tao-schedule'); const Schedule = require('../db/mongo/tao-schedule');
const GatherData = require('../db/mongo/tao-data'); const GatherData = require('../db/mongo/tao-data');
const Ip = require('../db/mongo/tao-ip');
const Nonetkl = require('../db/mongo/tao-nonetkl-log'); const Nonetkl = require('../db/mongo/tao-nonetkl-log');
const url = require('url'); const url = require('url');
const not_full = 'params not full error'; const not_full = 'params not full error';
const not_right = 'params not right error'; const not_right = 'params not right error';
const not_login = 'please login first'; const not_login = 'please login first';
const not_auth = 'auth error'; const not_auth = 'auth error';
const {ObjectId} = mongoose.SchemaTypes;
function dateFormat(target,format) { function dateFormat(target,format) {
return moment(new Date(target.getTime()),'x').format(format || 'YYYYMMDD HH:mm:ss'); return moment(new Date(target.getTime()),'x').format(format || 'YYYYMMDD HH:mm:ss');
...@@ -29,7 +31,6 @@ function urlArgs(query) { ...@@ -29,7 +31,6 @@ function urlArgs(query) {
continue; continue;
} }
var name = pairs[i].substring(0, pos); var name = pairs[i].substring(0, pos);
console.log(name);
var value = pairs[i].substring(pos + 1); var value = pairs[i].substring(pos + 1);
args[name] = value; args[name] = value;
} }
...@@ -71,7 +72,6 @@ exports.logs = async (req, res, next) => { ...@@ -71,7 +72,6 @@ exports.logs = async (req, res, next) => {
var sort_body = {}; var sort_body = {};
if(sort) sort_body[ sort ] = -1; if(sort) sort_body[ sort ] = -1;
sort_body['updatedAt'] = -1; sort_body['updatedAt'] = -1;
console.dir(sort_body);
let options = {limit:parseInt(limit),skip:parseInt(skip)*limit,sort:sort_body}; let options = {limit:parseInt(limit),skip:parseInt(skip)*limit,sort:sort_body};
var session_body = await Session.findById(sess); var session_body = await Session.findById(sess);
var logs = []; var logs = [];
...@@ -104,17 +104,50 @@ exports.logs = async (req, res, next) => { ...@@ -104,17 +104,50 @@ exports.logs = async (req, res, next) => {
} }
} }
exports.getIps = async(req,res,next) => {
let now = moment().add(0,'hours').format('YYYYMMDD');
let { qd = 'all', date = now,limit = 100,skip = 0} = req.query;
if(!qd ) return res.status(400).send(not_full);
let sess = req.cookies['sess'];
if(sess){
var none_tkls = [];
var session_body = await Session.findById(sess);
if(session_body){
var user = session_body.toJSON().user;
if(user != '5a1e81f8c86fa7aa4b51b18b'){
res.status(400).send(not_auth);
}
else{
var qs = {date:date};
if(qd != 'all')
qs['qd'] = mongoose.Types.ObjectId(qd);
let options = {limit:parseInt(limit),skip:parseInt(skip)*limit,sort:{times:-1}};
console.dir(qs);
var result = await Ip.find(qs,null,options).populate('qd','user');
var total = await Ip.count(qs);
res.send({ status:'ok',result:result,pagination:{total:total,skip:parseInt(skip)+1,limit:limit}});
}
}
else
res.status(400).send(not_auth);
}
else
res.status(400).send(not_login);
}
exports.getQdGatherData = async (req, res, next) => { exports.getQdGatherData = async (req, res, next) => {
let {limit = 100,skip = 0,sort = {'date': -1},qd} = req.query; let {limit = 100,skip = 0,sort = {'date': -1},qd} = req.query;
let options = {limit:parseInt(limit),skip:parseInt(skip)*limit,sort}; let options = {limit:parseInt(limit),skip:parseInt(skip)*limit,sort};
let sess = req.cookies['sess']; let sess = req.cookies['sess'];
var qs = {};
if(sess){ if(sess){
if(qd)
qs['qd'] = qd;
var none_tkls = []; var none_tkls = [];
var session_body = await Session.findById(sess); var session_body = await Session.findById(sess);
if(session_body){ if(session_body){
var user = session_body.toJSON().user; var user = session_body.toJSON().user;
var qs = {};
var match_qs = {date:moment().format('YYYYMMDD')}; var match_qs = {date:moment().format('YYYYMMDD')};
var kl_qs = {status:'use'}; var kl_qs = {status:'use'};
//console.log(user); //console.log(user);
...@@ -160,6 +193,7 @@ exports.getQdGatherData = async (req, res, next) => { ...@@ -160,6 +193,7 @@ exports.getQdGatherData = async (req, res, next) => {
}); });
none_tkls = await Nonetkl.find({date:match_qs['date']}).populate('qd','user').limit(1000); none_tkls = await Nonetkl.find({date:match_qs['date']}).populate('qd','user').limit(1000);
} }
console.dir(qs);
var gatherDatas = await GatherData.find(qs,null,options).populate('qd','user').populate({path:'schedules.schedule',populate:{path:'links',select:'name'}}); var gatherDatas = await GatherData.find(qs,null,options).populate('qd','user').populate({path:'schedules.schedule',populate:{path:'links',select:'name'}});
let total = await GatherData.count(qs,null); let total = await GatherData.count(qs,null);
let tkl_count = await Kouling.count(kl_qs,null); let tkl_count = await Kouling.count(kl_qs,null);
...@@ -175,6 +209,81 @@ exports.getQdGatherData = async (req, res, next) => { ...@@ -175,6 +209,81 @@ exports.getQdGatherData = async (req, res, next) => {
} }
exports.putGatherData = async(req,res,next) => {
let { dc_times = 0,id} = req.body;
if(!id ) return res.status(400).send(not_full);
let sess = req.cookies['sess'];
if(sess){
var none_tkls = [];
var session_body = await Session.findById(sess);
if(session_body){
var user = session_body.toJSON().user;
if(user != '5a1e81f8c86fa7aa4b51b18b'){
res.status(400).send(not_auth);
}
else{
console.dir(dc_times);
console.dir(id);
var result = await GatherData.update({_id:id},{$set:{dc_times:dc_times}});
res.send({status:'ok',result:result});
}
}
else
res.status(400).send(not_auth);
}
else
res.status(400).send(not_login);
}
exports.putIp = async(req,res,next) => {
let { iplimit = 0,id} = req.body;
if(!id ) return res.status(400).send(not_full);
let sess = req.cookies['sess'];
if(sess){
var none_tkls = [];
var session_body = await Session.findById(sess);
if(session_body){
var user = session_body.toJSON().user;
if(user != '5a1e81f8c86fa7aa4b51b18b'){
res.status(400).send(not_auth);
}
else{
console.dir(iplimit);
console.dir(id);
var result = await Agent.update({_id:id},{$set:{iplimit:iplimit}});
res.send({status:'ok',result:result});
}
}
else
res.status(400).send(not_auth);
}
else
res.status(400).send(not_login);
}
exports.putQdUpdate = async(req,res,next) => {
let { ipstatus = 'use',id} = req.body;
if(!id ) return res.status(400).send(not_full);
let sess = req.cookies['sess'];
if(sess){
var none_tkls = [];
var session_body = await Session.findById(sess);
if(session_body){
var user = session_body.toJSON().user;
if(user != '5a1e81f8c86fa7aa4b51b18b'){
res.status(400).send(not_auth);
}
else{
var result = await Agent.update({_id:id},{$set:{ipstatus:ipstatus}});
res.send({status:'ok',result:result});
}
}
else
res.status(400).send(not_auth);
}
else
res.status(400).send(not_login);
}
exports.getTbkls = async (req, res, next) => { exports.getTbkls = async (req, res, next) => {
let {limit = 100,skip = 0,sort = {'updatedAt': -1}} = req.query; let {limit = 100,skip = 0,sort = {'updatedAt': -1}} = req.query;
...@@ -211,11 +320,7 @@ exports.getLinks = async (req, res, next) => { ...@@ -211,11 +320,7 @@ exports.getLinks = async (req, res, next) => {
} }
exports.createLink = async (req, res, next) => { exports.createLink = async (req, res, next) => {
let {quan,pid,good,name} = req.body; let {quan,pid,good,name,select = 'target'} = req.body;
/* let sess = req.cookies['sess'];
let sessBody = await Session.findById(sess).populate('user','user role');
console.dir(sessBody.toJSON());
return;*/
if(!pid || !good || !quan || !name ) if(!pid || !good || !quan || !name )
res.status(400).send(not_full); res.status(400).send(not_full);
else{ else{
...@@ -228,7 +333,11 @@ exports.createLink = async (req, res, next) => { ...@@ -228,7 +333,11 @@ exports.createLink = async (req, res, next) => {
let goodInfo = await tao.getGood(goodQuery['id']); let goodInfo = await tao.getGood(goodQuery['id']);
let title = goodInfo['title']; let title = goodInfo['title'];
let pic = goodInfo['pict_url'] || ''; let pic = goodInfo['pict_url'] || '';
let target = 'https://uland.taobao.com/coupon/edetail?activityId='+ quanQuery['activityId']+'&itemId='+goodQuery['id']+'&pid='+pid+'&dx=1&src=tkm_tkmwz'; let target = '';
if(select == 'target')
target = 'https://uland.taobao.com/coupon/edetail?activityId='+ quanQuery['activityId']+'&itemId='+goodQuery['id']+'&pid='+pid+'&dx=1&src=tkm_tkmwz';
else
target = quan;
tao.saveLink({name,quan,pid,good,title,pic,target},function(e,result){ tao.saveLink({name,quan,pid,good,title,pic,target},function(e,result){
if(e) throw e; if(e) throw e;
res.send({result:'ok',result:result}) res.send({result:'ok',result:result})
...@@ -242,16 +351,22 @@ exports.createLink = async (req, res, next) => { ...@@ -242,16 +351,22 @@ exports.createLink = async (req, res, next) => {
} }
exports.getSchedules = async (req, res, next) => { exports.getSchedules = async (req, res, next) => {
let {limit = 100,skip = 0,sort = {'createdAt': -1}} = req.query; let {limit = 100,skip = 0,sort = {'createdAt': -1},qd = 'all'} = req.query;
let options = {limit:parseInt(limit),skip:parseInt(skip)*limit,sort}; let options = {limit:parseInt(limit),skip:parseInt(skip)*limit,sort};
let schedules = await Schedule.find({},null,options).populate('links','name title target').populate('qd','user'); var qs = {};
if(qd != 'all')
qs = {qd:qd}
console.dir(qs);
let schedules = await Schedule.find(qs,null,options).populate('links','name title target').populate('qd','user');
var tasks = []; var tasks = [];
schedules.forEach( (item) => { schedules.forEach( (item) => {
tasks.push(Kouling.count({schedule:item._id,status:'use'})); tasks.push(Kouling.count({schedule:item._id,status:'use'}));
}); });
//schedules = schedules.map(x => { x = x.toJSON(); ;return x });
//console.dir(schedules);
Promise.all(tasks).then(async function(arr){ Promise.all(tasks).then(async function(arr){
let total = await Schedule.count({},null); let total = await Schedule.count(qs,null);
schedules = schedules.map( (x,i) => { var a = x.toJSON();a['createdAt'] = dateFormat(a['createdAt']); a['count'] = arr[i]; return a}); schedules = schedules.map( (x,i) => { var a = x.toJSON();if(a.final){ a.final = moment(a.final,'x').format('YYYYMMDD HH:mm:ss') } ;a['createdAt'] = dateFormat(a['createdAt']); a['count'] = arr[i]; return a});
res.send({ status:'ok',result:schedules,pagination:{total:total,skip:parseInt(skip)+1,limit:limit}}); res.send({ status:'ok',result:schedules,pagination:{total:total,skip:parseInt(skip)+1,limit:limit}});
}); });
} }
...@@ -259,8 +374,8 @@ exports.getSchedules = async (req, res, next) => { ...@@ -259,8 +374,8 @@ exports.getSchedules = async (req, res, next) => {
exports.getQds = async (req, res, next) => { exports.getQds = async (req, res, next) => {
let {limit = 100,skip = 0,sort = {'createdAt': -1}} = req.query; let {limit = 100,skip = 0,sort = {'createdAt': -1}} = req.query;
let options = {limit:parseInt(limit),skip:parseInt(skip)*limit,sort}; let options = {limit:parseInt(limit),skip:parseInt(skip)*limit,sort};
let qds = await Agent.find({},null,options); let qds = await Agent.find({user:{$ne:'admin'}},null,options);
let total = await Agent.count({},null,options); let total = await Agent.count({user:{$ne:'admin'}},null,options);
var tasks = []; var tasks = [];
var _tasks = []; var _tasks = [];
qds.forEach( (item) => { qds.forEach( (item) => {
...@@ -287,7 +402,12 @@ exports.createQd = async (req, res, next) => { ...@@ -287,7 +402,12 @@ exports.createQd = async (req, res, next) => {
}); });
} }
exports.updateAutoSchedule = async (req, res, next) => {
let {scheduleId,auto} = req.body;
console.dir(req.body);
let result = await Schedule.update({_id:scheduleId},{$set:{auto:auto}},{multi:true});
res.send({ status:'ok',schedule:result});
}
exports.updateSchedule = async (req, res, next) => { exports.updateSchedule = async (req, res, next) => {
let {scheduleId,status} = req.body; let {scheduleId,status} = req.body;
...@@ -318,7 +438,6 @@ exports.updateSchedule = async (req, res, next) => { ...@@ -318,7 +438,6 @@ exports.updateSchedule = async (req, res, next) => {
} }
}); });
var tkls = await Promise.all(tasks); var tkls = await Promise.all(tasks);
console.dir(tkls);
if(tkls && tkls.length){ if(tkls && tkls.length){
var ids = []; var ids = [];
for(var k in tkls){ for(var k in tkls){
...@@ -334,7 +453,7 @@ exports.updateSchedule = async (req, res, next) => { ...@@ -334,7 +453,7 @@ exports.updateSchedule = async (req, res, next) => {
} }
exports.createSchedule = async (req, res, next) => { exports.createSchedule = async (req, res, next) => {
let {user,times,status='use',names} = req.body; let {user,times,status='use',names,final} = req.body;
var links = []; var links = [];
try{ try{
if(!user || !times || !names) if(!user || !times || !names)
...@@ -352,7 +471,8 @@ exports.createSchedule = async (req, res, next) => { ...@@ -352,7 +471,8 @@ exports.createSchedule = async (req, res, next) => {
var qd = agent.toJSON()['_id']; var qd = agent.toJSON()['_id'];
var links = ids; var links = ids;
var tkl_Tasks = []; var tkl_Tasks = [];
tao.saveSchedule({qd,links,status,times},function(e,result){ if(final) final = parseInt(final);
tao.saveSchedule({qd,links,status,times,final},function(e,result){
if(e || !result._id) throw (e || result); if(e || !result._id) throw (e || result);
var schedule = result._id; var schedule = result._id;
arr.forEach(async item => { arr.forEach(async item => {
...@@ -414,6 +534,100 @@ exports.newTbkl = async (req, res, next) => { ...@@ -414,6 +534,100 @@ exports.newTbkl = async (req, res, next) => {
} }
exports.adminTbkl = async(req,res,next) => {
var { num = 10,quan,pid,good} = req.body;
if(!pid || !good || !quan ) return res.status(400).send(not_full);
let sess = req.cookies['sess'];
if(sess){
var none_tkls = [];
var session_body = await Session.findById(sess);
if(session_body){
var user = session_body.toJSON().user;
if(user != '5a1e81f8c86fa7aa4b51b18b'){
res.status(400).send(not_auth);
}
else{
var quanQuery = urlArgs(url.parse(quan).query);
var goodQuery = urlArgs(url.parse(good).query);
if(!pid || !goodQuery['id'])
res.status(400).send(not_full);
else{
var goodInfo = await tao.getGood(goodQuery['id']);
var title = goodInfo['title'];
var pic = goodInfo['pict_url'] || '';
var target = 'https://uland.taobao.com/coupon/edetail?activityId='+ quanQuery['activityId']+'&itemId='+goodQuery['id']+'&pid='+pid+'&dx=1&src=tkm_tkmwz';
goodInfo['target'] = target;
num = parseInt(num);
var tasks = [];
for(var i = 0;i< num;i++){
tasks.push(tao.createTbkl(title,target,pic));
}
var arrs = await Promise.all(tasks);
res.send({status:'ok',result:arrs,good:goodInfo});
}
}
}
else
res.status(400).send(not_auth);
}else{
res.status(400).send(not_auth);
}
}
exports.getAllGatherData = async(req,res,next) => {
var {start,end} = req.query;
if(!start || !end) return res.status(400).send(not_full);
let sess = req.cookies['sess'];
if(sess){
var none_tkls = [];
var session_body = await Session.findById(sess);
if(session_body){
var user = session_body.toJSON().user;
if(user != '5a1e81f8c86fa7aa4b51b18b'){
res.status(400).send(not_auth);
}
else{
console.dir(start);
console.dir(end);
const condition = {'date': {'$gte': moment(start, 'YYYYMMDD').startOf('day').toDate(),'$lt': moment(end, 'YYYYMMDD').endOf('day').toDate()}};
var list = await GatherData.aggregate([
{
$match:condition
},
{
$group:{
_id: "$date",
times:{ $sum:"$times" },
dc_times:{ $sum:"$dc_times" }
}
}
]);
list.map(x => { x._id = moment(x._id).format('YYYYMMDD'); x['date'] = moment(x._id).format('YYYY/MM/DD'); return x;})
res.send({status:'ok',list:list})
}
}
else
res.status(400).send(not_auth);
}else{
res.status(400).send(not_auth);
}
}
exports.admin2Tbkl = async(req,res,next) => {
var { num = 10,logo,text,url} = req.body;
if(!text || !url ) return res.status(400).send(not_full);
var tasks = [];
for(var i = 0;i< num;i++){
tasks.push(tao.createnormalTbkl(text,url,logo));
}
var arrs = await Promise.all(tasks);
res.send({status:'ok',result:arrs,good:{logo:logo,text:text,url:url}});
}
/*exports.getDetails = async (req,res,next) => { /*exports.getDetails = async (req,res,next) => {
...@@ -472,12 +686,18 @@ exports.newTbkl = async (req, res, next) => { ...@@ -472,12 +686,18 @@ exports.newTbkl = async (req, res, next) => {
} }
}*/ }*/
var createTbkl = async (data) => { var createTbkl = async (data) => {
let {title,target,pic,qd} = data; let {title,target,pic,qd} = data;
return new Promise(async (r,d) => { return new Promise(async (r,d) => {
try { try {
let tbklInfo = await tao.createTbkl(title,target,pic); let targetQuery = urlArgs(url.parse(target).query);
var tbklInfo = null;
console.dir(targetQuery);
if(targetQuery['pid'])
tbklInfo = await tao.createTbkl(title,target,pic);
else
tbklInfo = await tao.createnormalTbkl(title,target,pic);
console.dir(tbklInfo);
let model = tbklInfo.model; let model = tbklInfo.model;
let _data = { info:model,schedule:data.schedule,link:data.link,creater:qd,status:'use' }; let _data = { info:model,schedule:data.schedule,link:data.link,creater:qd,status:'use' };
tao.saveKouling(_data,function(e,result){ tao.saveKouling(_data,function(e,result){
......
...@@ -51,6 +51,13 @@ async function tbklTask () { ...@@ -51,6 +51,13 @@ async function tbklTask () {
schedules.forEach( async item => { schedules.forEach( async item => {
let schedule = item.toJSON()._id; let schedule = item.toJSON()._id;
var qd = item.toJSON().qd; var qd = item.toJSON().qd;
var tasks_schedules = [];
var tasks_schedule_koulings = [];
if(item.final && item.final < moment().format('x')){
tasks_schedules.push(Kouling.update({status:'use',schedule:schedule},{$set:{status:'disable'}},{multi:true}));
tasks_schedule_koulings.push(Schedule.update({_id:schedule},{$set:{status:"disable"}},{multi:true}));
}
// console.dir(schedule); // console.dir(schedule);
// 查询计划内 超过20000 请求 淘口令 // 查询计划内 超过20000 请求 淘口令
//console.dir({times:{$gte:10},status:'use',schedule:schedule}); //console.dir({times:{$gte:10},status:'use',schedule:schedule});
...@@ -76,6 +83,12 @@ async function tbklTask () { ...@@ -76,6 +83,12 @@ async function tbklTask () {
tasks_log.push(Log.update({_id:item._id},{$set:{status:'disable'}})); tasks_log.push(Log.update({_id:item._id},{$set:{status:'disable'}}));
} }
}); });
if(tasks_schedule_koulings.length && tasks_schedules.length){
var tasks_schedule_koulings_arr = await Promise.all(tasks_schedule_koulings);
var tasks_schedules_arr = await Promise.all(tasks_schedules);
console.log('更新计划 结束 影响' + tasks_schedules_arr.length + '条数据');
console.log('更新计划相关口令 影响' + tasks_schedule_koulings_arr.length + '条数据');
}
if(tasks_new.length&&tasks_old.length&&tasks_log.length){ if(tasks_new.length&&tasks_old.length&&tasks_log.length){
var oldArrs = await Promise.all(tasks_old) var oldArrs = await Promise.all(tasks_old)
var logArrs = await Promise.all(tasks_log); var logArrs = await Promise.all(tasks_log);
......
const cron = require('cron');
const nodemailer = require('nodemailer');
const Schedule = require('../db/mongo/tao-schedule');
const Kouling = require('../db/mongo/tao-kouling');
const Log = require('../db/mongo/tao-log');
const tao = require('./tao');
const _ = require('lodash');
const moment = require('moment');
const controller = require('./controller');
const max = 10000;
var CronJob = cron.CronJob;
var job = new CronJob({
cronTime: '0 */30 * * * *',
onTick: function() {
tbklTask();
},
start: false,
});
async function sendMail(email,body) {
var smtpTransport = nodemailer.createTransport({
auth: {
user: "liusong@goyoo.com",
pass: "323609zhang"
},
host: 'smtp.exmail.qq.com',
port: 465
});
var mailOptions = {
from: "liusong@goyoo.com",
to: email, //发给谁
subject: '淘口令后台定时任务错误', //主题
text: body
};
smtpTransport.sendMail(mailOptions, function (err, response) {
if (!err) {
console.log('发送邮件成功');
} else {
console.log('发送邮件失败,请重试');
}
});
}
async function tbklTask () {
console.log('定时更新开始 =====> ');
try {
//let tkls = await Kouling.find({status:'use'}).populate('link','title target').limit(1000);
// 查询进行中计划
let schedules = await Schedule.find({status:'use'}).populate('links').limit(500);
if(schedules.length == 0) console.log(' auto 更新结束 无任务');
else
schedules.forEach( async item => {
item = item.toJSON();
var schedule = item._id;
var qd = item.qd;
var auto = item.auto;
var links = item.links;
// console.dir(schedule);
// 查询计划内 超过20000 请求 淘口令
//console.dir({times:{$gte:10},status:'use',schedule:schedule});
let logs = await Log.find({times:{$gte:max},schedule:schedule,status:{$ne:'disable'}}).populate('link','title target pic').limit(1000);
var tasks_new = [];
var tasks_old = [];
if(auto == 'use'){
links.forEach( _item => {
var data = {
title:_item.title,
target:_item.target,
schedule:schedule,
link:_item._id,
status:'use',
qd:qd,
pic:_item.pic
}
for(var i = 0;i<10; i++){
tasks_new.push(controller.createTbkl(data));
}
tasks_old.push(Kouling.update({schedule:schedule,status:{$ne:'disable'}},{$set:{status:'disable'}},{multi:true}));
//tasks_log.push(Log.update({_id:item._id},{$set:{status:'disable'}}));
});
}
if(tasks_old.length){
var oldArrs = await Promise.all(tasks_old);
console.dir(oldArrs);
console.log('auto 删除老口令 结束 影响' + oldArrs.length + '条数据');
}
if(tasks_new.length){
var newArrs = await Promise.all(tasks_new);
console.dir(newArrs);
console.log('auto 增加新口令 结束 影响' + newArrs.length + '条数据');
}
if(tasks_new.length || tasks_old.length){
console.log(' auto 更新计划'+ item._id +'结束 有任务');
}
else{
console.log(' auto 更新结束 '+ item._id +' 无任务');
}
});
} catch (err) {
console.dir(err);
console.dir('更新异常 =====>');
let mailList = 'liusong@goyoo.com';
sendMail(mailList, err.toString());
}
}
module.exports.start = function ()
{
job.start();
};
...@@ -76,6 +76,8 @@ exports.getGood = (id) => { ...@@ -76,6 +76,8 @@ exports.getGood = (id) => {
'platform':'1', 'platform':'1',
'num_iids':id 'num_iids':id
},function(error, response) { },function(error, response) {
console.dir(error);
console.dir(response);
if(response.results && response.results.n_tbk_item && response.results.n_tbk_item[0] && !error) r(response.results.n_tbk_item[0]); if(response.results && response.results.n_tbk_item && response.results.n_tbk_item[0] && !error) r(response.results.n_tbk_item[0]);
else d(error || 'unknown error'); else d(error || 'unknown error');
}); });
...@@ -89,8 +91,28 @@ exports.createTbkl = (title,url,pic) => { ...@@ -89,8 +91,28 @@ exports.createTbkl = (title,url,pic) => {
'url':url, 'url':url,
'logo':pic 'logo':pic
}, function(error, response) { }, function(error, response) {
console.dir(error);
console.dir(response);
if (response && response.data && !error) r(response.data); if (response && response.data && !error) r(response.data);
else d(error); else d(error);
}) })
}); });
} }
exports.createnormalTbkl = (title,url,pic) => {
return new Promise((r,d) => {
var data = {
'text':title,
'url':url
};
if(pic)
data['logo'] = pic;
client.execute('taobao.wireless.share.tpwd.create', {tpwd_param:data}, function(error, response) {
console.dir(error);
console.dir(response);
if (response && !error) r(response);
else d(error);
})
});
}
\ No newline at end of file
const config = require('../config/index');
const tao = require('./tao');
const mongoose = require('mongoose');
const Link = require('../db/mongo/tao-link');
const url = require('url');
global.Promise = mongoose.Promise = require('bluebird');
var map = {
"mm_32247283_40828228_165418621":"mm_26653811_40818629_165538497",
"mm_32247283_40828228_165436284":"mm_26653811_40818629_165524713",
"mm_32247283_40828228_165412765":"mm_26653811_40818629_165512995",
"mm_32247283_40828228_165428432":"mm_26653811_40818629_165556147",
"mm_32247283_40828228_165410854":"mm_26653811_40818629_165544355",
"mm_32247283_40828228_165410854":"mm_26653811_40818629_165536576",
"mm_32247283_40828228_165436294":"mm_26653811_40818629_165556151",
"mm_32247283_40828228_165426474":"mm_26653811_40818629_165516975",
"mm_32247283_40828228_165418633":"mm_26653811_40818629_165522716",
"mm_32247283_40828228_165436297":"mm_26653811_40818629_165558027",
"mm_32247283_40828228_165430368":"mm_26653811_40818629_165516976",
"mm_32247283_40828228_165404879":"mm_26653811_40818629_165534578",
"mm_32247283_40828228_165420613":"mm_26653811_40818629_165514883",
"mm_32247283_40828228_165432351":"mm_26653811_40818629_165556142",
"mm_32247283_40828228_165412776":"mm_26653811_40818629_165514897",
"mm_32247283_40828228_165428747":"mm_26653811_40818629_165526725",
"mm_32247283_40828228_165438626":"mm_26653811_40818629_165524728",
"mm_32247283_40828228_165448438":"mm_26653811_40818629_165522725",
"mm_32247283_40828228_165432741":"mm_26653811_40818629_165552199",
"mm_32247283_40828228_165442582":"mm_26653811_40818629_165530703",
"mm_32247283_40828228_165424941":"mm_26653811_40818629_165536596",
"mm_32247283_40828228_165412788":"mm_26653811_40818629_165554205",
"mm_32247283_40828228_165432381":"mm_26653811_40818629_165548277",
"mm_32247283_40828228_165448106":"mm_26653811_40818629_165542506",
"mm_32247283_40828228_165446155":"mm_26653811_40818629_165526743",
"mm_32247283_40828228_165438287":"mm_26653811_40818629_165528787",
"mm_32247283_40828228_165418651":"mm_26653811_40818629_165542512",
"mm_32247283_40828228_165438290":"mm_26653811_40818629_165520897",
"mm_32247283_40828228_165422578":"mm_26653811_40818629_165560023",
"mm_32247283_40828228_165430397":"mm_26653811_40818629_165528793",
"mm_32247283_40828228_165430398":"mm_26653811_40818629_165554217",
"mm_32247283_40828228_165448428":"mm_26653811_40818629_165558060",
"mm_32247283_40828228_165448429":"mm_26653811_40818629_165538530",
"mm_32247283_40828228_165422602":"mm_26653811_40818629_165526760",
"mm_32247283_40828228_165412828":"mm_26653811_40818629_165560042",
"mm_32247283_40828228_165408900":"mm_26653811_40818629_165562027",
"mm_32247283_40828228_165420678":"mm_26653811_40818629_165530741",
"mm_32247283_40828228_165428487":"mm_26653811_40818629_165514932",
"mm_32247283_40828228_165440306":"mm_26653811_40818629_165558078",
"mm_32247283_40828228_165424636":"mm_26653811_40818629_165528806",
"mm_32247283_40828228_165404947":"mm_26653811_40818629_165530745",
"mm_32247283_40828228_165416723":"mm_26653811_40818629_165554240",
"mm_32247283_40828228_165436350":"mm_26653811_40818629_165546312"}
function getQueryString(name,url,pid) {
var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
var r = url.replace(reg,'&pid='+ pid +'&');
return r;
if (r != null) {
return unescape(r[2]);
}
return null;
}
const options = {
useMongoClient: true
};
mongoose.connect(config.mongo, options);
async function run(){
console.dir('items.length =======');
var items = await Link.find({});
console.dir('=======');
console.dir(items.length);
var tasks = [];
var count = 0;
items.forEach( item => {
var pid = item.pid;
count++;
/* console.log('=='+item.target);
console.log(getQueryString('pid',item.target));*/
//console.dir(item.pid == getQueryString('pid',item.target));
if(map[pid]){
tasks.push(Link.update({_id:item._id},{$set:{pid:map[pid],target:getQueryString('pid',item.target,map[pid])}}));
//var result = await Link.update({_id:_id},{$set:{pid:map[pid],target:getQueryString('pid',item.target,map[pid])}});
//console.dir(result);
}
});
var arrs = await Promise.all(tasks);
console.dir(arrs);
}
run();
\ No newline at end of file
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
"cookie-parser": "^1.4.3", "cookie-parser": "^1.4.3",
"cookie-session": "^1.3.0", "cookie-session": "^1.3.0",
"cron": "^1.2.1", "cron": "^1.2.1",
"echarts": "^3.8.5",
"echarts-for-react": "^2.0.4",
"es6-promise": "^4.0.5", "es6-promise": "^4.0.5",
"eslint-plugin-react": "^7.1.0", "eslint-plugin-react": "^7.1.0",
"express": "^4.14.1", "express": "^4.14.1",
......
...@@ -20,13 +20,22 @@ router.post('/newtkl',controller.newTbkl); ...@@ -20,13 +20,22 @@ router.post('/newtkl',controller.newTbkl);
router.post('/link',controller.createLink); router.post('/link',controller.createLink);
router.post('/put_data',controller.putGatherData);
router.post('/put_ip',controller.putIp);
router.post('/qd_update',controller.putQdUpdate);
//router.get('/details',controller.getDetails); //router.get('/details',controller.getDetails);
router.post('/tool_tbkls',controller.adminTbkl);
router.post('/tool2_tbkls',controller.admin2Tbkl);
router.get('/schedules',controller.getSchedules); router.get('/schedules',controller.getSchedules);
router.post('/schedule',controller.createSchedule); router.post('/schedule',controller.createSchedule);
router.post('/schedule_update',controller.updateSchedule); router.post('/schedule_update',controller.updateSchedule);
router.post('/schedule_auto_update',controller.updateAutoSchedule);
router.get('/gathers/qd',controller.getQdGatherData); router.get('/gathers/qd',controller.getQdGatherData);
router.get('/gatherall',controller.getAllGatherData);
router.get('/ips',controller.getIps);
module.exports = router; module.exports = router;
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment