Commit ade80309 authored by yaobeibei's avatar yaobeibei

update

parent a7a6d6d1
......@@ -3,7 +3,7 @@ const {
MONGO_STOCK_DB = 'mongodb://root:h4R1FWWVcNiR@10.11.3.136:1304/rmk-invoicing',
MONGO_URI = 'mongodb://bjwjh-admin:c9yJ2gBFkp7U6@10.11.3.136:1302/tag_urls?authSource=admin',
JWT_SECRET = '9104b291d48a4844d2a346a695d2602fa4d8ffe7328f7c98c27270b32a6b636f',
HOST = 'http://callcenter.xiaoyun.com',
HOST = 'http://api-callcenter.wjh.xiaoyun.com',
APPID = 'wx868fb5b459229a1e',
APPSECRET = '17d470ec5bbe1560ade35e8014c5d993',
accessKey = 'D1CSX8QB0BTCDRTSK32E',
......
......@@ -123,10 +123,11 @@ setInterval(async () => {
await unbind();
}, STAMP);
// 获取订单列表
//
exports.bind = async (ctx, next) => {
let {
clue,
callerType,
caller,
callback_data
} = ctx.request.body;
......@@ -135,29 +136,41 @@ exports.bind = async (ctx, next) => {
ctx.assert(clueObj && clueObj.account + '' === ctx.state.user._id + '', 500, '参数错误,clue', {
code: 1
});
ctx.assert(/^1(3|4|5|7|8|9)\d{9}$/.test(caller), 500, '参数错误,caller', {
ctx.assert(caller/*/^1(3|4|5|7|8|9)\d{9}$/.test(caller)*/, 500, '参数错误,caller', {
code: 1
});
let { unikey, from: operator, province, city, account, type: clueType, _id, user } = clueObj;
await unbindWhenCall(caller + '');
let provinceCode = areaCode(province, city);
try {
let rep = await api({
method: 'POST',
url: HOST + '/binding',
body: {
let body_data = {
caller: caller + '',
unikey: unikey,
province: provinceCode,
operator
},
};
console.dir(body_data);
if(!/^1(3|4|5|7|8|9)\d{9}$/.test(caller)) body_data.callerType = 'FIXED_PHO';
if(callerType) {
ctx.assert(callerType == 'FIXED_PHO', 500, '参数错误,callerType', {
code: 1
});
body_data.callerType = callerType;
}
if(unikey.indexOf('TY') >=0) body_data.opVersion = 'v1';
let rep = await api({
method: 'POST',
url: HOST + '/binding',
body: body_data,
json: true
});
console.dir(rep);
let { bindID, volan } = rep;
console.dir('请求绑定成功' + caller );
let callTask = await new CallTask({ clueType, user, callback_data, from: operator, bindID, unikey, caller, called: volan, account, clue: _id, account, startTime: Date.now() }).save();
let callTask = await new CallTask({ clueType, user, callback_data, from: operator, bindID, unikey, caller: body_data.caller, called: volan, account, clue: _id, account, startTime: Date.now() }).save();
await Clue.updateOne({
_id
}, {
......
......@@ -144,7 +144,7 @@ exports.createAuto = async(ctx, next) => {
try {
ctx.websocket.on('message', async function(message) {
let { order, start, end } = JSON.parse(message);
let { order, start, end, max } = JSON.parse(message);
//let order = "5c8f3f30189f42000721d983";
if(!tools.valid(order)) {
ctx.websocket.send(JSON.stringify({ type: 'warning', message: '订单ID 格式错误' }));
......@@ -211,8 +211,7 @@ exports.createAuto = async(ctx, next) => {
let todoUnikeys = [];
for(let url of hosts) {
ctx.websocket.send(JSON.stringify({ type: 'info', message: `准备匹配url: ${url}`}));
let res = await getRepoUnikeys({
let query = {
"size": need,
"page": 1,
"citys": [],
......@@ -222,12 +221,19 @@ exports.createAuto = async(ctx, next) => {
"exactMatch": true,
start,
end
});
}
if(city) query.citys = city;
else {
if(province) query.provinces = province;
}
let res = await getRepoUnikeys(query);
if(res.status == 'ok') {
let repoUnikeys = res.result;
ctx.websocket.send(JSON.stringify({ type: 'info', message: `匹配${url}成功,共${repoUnikeys.length}条数据`}));
todoUnikeys = todoUnikeys.concat(repoUnikeys);
//todoUnikeys = todoUnikeys.filter(x => x.unikey.indexOf('TY') == -1);
ctx.websocket.send(JSON.stringify({ type: 'info', message: `累计匹配${todoUnikeys.length}条数据`}));
if(need <= todoUnikeys.length) {
ctx.websocket.send(JSON.stringify({ type: 'info', message: `匹配数据已满足需求数据,跳出循环`}));
......@@ -397,3 +403,97 @@ exports.create = async (ctx, next) => {
}
}
}
// 修改数据标签
/*(async function (argument) {
let orders = [
{
code:"OD20190327005",
hosts:[{
from: 'mobile.mlnglobal.com',
replace: 'kh.10jqka.com.cn'
}]
},
{
code:"OD20190329001",
hosts:[{
from: 'newhouse.fang.com',
replace: 'kh.10jqka.com.cn'
}]
},
{
code:"OD20190402001",
hosts:[{
from: 'fang.anjuke.com',
replace: 'kh.10jqka.com.cn'
}]
},
{
code:"OD20190419008",
hosts:[{
from: 'huaian.jiwu.com',
replace: 'kh.10jqka.com.cn'
}]
},
{
code:"OD20190422006",
hosts:[{
from: 'www.yiddtea.com',
replace: 'kh.10jqka.com.cn'
}]
},
{
code:"OD20190422008",
hosts:[{
from: 'www.runzeyufu.com',
replace: 'kh.10jqka.com.cn'
}]
},
{
code:"OD20190423001",
hosts:[{
from: 'yt.newhouse.fang.com',
replace: 'kh.10jqka.com.cn'
}]
},
{
code:"OD20190423002",
hosts:[{
from: 'www.haozu.com',
replace: 'kh.10jqka.com.cn'
}]
},{
code:"OD20190423003",
hosts:[{
from: 'fang.anjuke.com',
replace: 'kh.10jqka.com.cn'
}]
}];
for(let o of orders) {
let { code, hosts, province, city } = o;
let order = await Order.findOne({ code });
let { group } = order;
let conditions = {};
let setObj = {};
for(let host of hosts) {
let { from, replace } = host;
let rep = await Clue.updateMany({ host: replace, order: order._id }, {
$set: {
host: from,
virtualHost: hash(from)
}
})
let count = await Clue.count({ host: replace, order: order._id })
console.dir(count)
}
}
})()*/
......@@ -6,6 +6,8 @@ const _ = require('lodash');
const mongoose = require('mongoose');
const groupContrl = require('./group');
const Order = require('db/mongo/open/order');
const Clue = require('db/mongo/open/clue');
const Group = require('db/mongo/open/group');
const User = require('db/mongo/open/user');
const {
ObjectId
......@@ -76,7 +78,20 @@ exports.list = async (ctx, next) => {
}
}
}
/*
(async function (argument) {
let as = await Order.find();
for(let a of as) {
let { code, _id } = a
console.dir(code);
let aa = await Order.updateOne({
_id
},{
$set: { code: 'O' + code}
})
console.dir(aa);
}
})()*/
exports.check = async(ctx, next) => {
let {
......@@ -102,6 +117,36 @@ exports.check = async(ctx, next) => {
}
}
exports.close = async(ctx, next) => {
let {
order
} = ctx.request.body;
ctx.assert(tools.valid(order), 500, '参数错误,order', {
code: 1
});
let orderObj = await Order.findById(order);
ctx.assert(orderObj , 500, '参数错误,order', {
code: 1
});
if(orderObj.status == '已关闭') {
ctx.body = {
status: 'ok'
}
} else {
let count = await Clue.count({ order: ObjectId(order) });
orderObj.clue = count;
orderObj.status = '已关闭';
orderObj.history = orderObj.history.concat([{
status: '已关闭',
date: new Date()
}])
await orderObj.save();
}
ctx.body = {
status: 'ok'
}
}
exports.all = async (ctx, next) => {
let {
id=0,
......@@ -140,7 +185,10 @@ exports.all = async (ctx, next) => {
let orders = await Order.find(conditions, null, {
skip,
limit
limit,
sort: {
createdAt: -1
}
}).populate('origin', 'account user code meta awardCount type award count clue group subOrder status meta').populate(
'account', 'company nickname phone zyxKey'
).populate('user', 'company name').populate('group', 'hosts province sex city age name');
......@@ -258,3 +306,115 @@ exports.create = async (ctx, next) => {
}
}
}
// 修改画像
/*(async function (argument) {
let orders = [
{
code:"OD20190327005",
hosts:[{
from: 'mobile.mlnglobal.com',
replace: 'kh.10jqka.com.cn'
}]
},
{
code:"OD20190329001",
hosts:[{
from: 'newhouse.fang.com',
replace: 'kh.10jqka.com.cn'
}]
},
{
code:"OD20190402001",
hosts:[{
from: 'fang.anjuke.com',
replace: 'kh.10jqka.com.cn'
}]
},
{
code:"OD20190419008",
hosts:[{
from: 'huaian.jiwu.com',
replace: 'kh.10jqka.com.cn'
}]
},
{
code:"OD20190422006",
hosts:[{
from: 'www.yiddtea.com',
replace: 'kh.10jqka.com.cn'
}]
},
{
code:"OD20190422008",
hosts:[{
from: 'www.runzeyufu.com',
replace: 'kh.10jqka.com.cn'
}]
},
{
code:"OD20190423001",
hosts:[{
from: 'yt.newhouse.fang.com',
replace: 'kh.10jqka.com.cn'
}]
},
{
code:"OD20190423002",
hosts:[{
from: 'www.haozu.com',
replace: 'kh.10jqka.com.cn'
}]
},{
code:"OD20190423003",
hosts:[{
from: 'fang.anjuke.com',
replace: 'kh.10jqka.com.cn'
}]
}];
for(let o of orders) {
let { code, hosts, province, city } = o;
// console.dir(hosts);
let order = await Order.findOne({ code });
let { group } = order;
let conditions = {};
let setObj = {};
if(hosts) {
conditions['hosts'] = { '$in': hosts.map( x =>
x.from
) }
setObj['$push'] = { hosts: {
$each: hosts.map( x => x.replace)
} }
}
if(province !== undefined ){
conditions.province = province.from;
if(setObj['$set'])
setObj['$set']['province'] = province.to ;
else
setObj['$set'] = { province: province.to };
}
if(city !== undefined) {
conditions.city = city.from
if(setObj['$set'])
setObj['$set']['city'] = city.to ;
else
setObj['$set'] = { city: city.to };
}
//console.dir(conditions);
console.dir(setObj);
conditions._id = group;
//let rep = await Group.updateOne(conditions, setObj);
console.dir(rep);
//console.dir(setObj);
}
})()*/
const _ = require('lodash');
const api = require('utils/api');
const mongoose = require('mongoose');
const Order = require('db/mongo/open/order');
const OrderProduction = require('db/mongo/open/order_production');
const Clue = require('db/mongo/open/clue');
const User = require('db/mongo/open/user');
const Lock = require('db/mongo/open/lock');
const Group = require('db/mongo/open/group');
const Unikey = require('db/mongo/stock/unikey');
const UnikeyOut = require('db/mongo/stock/unikeyout');
const {
ObjectId
} = require('mongoose').Types;
/*画像替换*/
// 线索标签替换
/*(async function() {
})()*/
\ No newline at end of file
......@@ -15,12 +15,12 @@ const schema = mongoose.Schema({
required: true
},
caller: { // 主叫号
type: Number,
type: String,
required: true,
},
callback_data: String,
called: { // 被叫号
type: Number,
type: String,
required: true,
},
account: { // 账户
......
......@@ -14,7 +14,8 @@ module.exports = (opt = {}) => {
'/api/clue/input',
'/api/order/check',
'/api/order/all',
'/api/order/check'
'/api/order/check',
'/api/order/close'
]
});
};
\ No newline at end of file
......@@ -6,4 +6,5 @@ router.post('/list', Auth.auth, $.list);
router.post('/create', Auth.auth, $.create);
router.post('/all', $.all);
router.post('/check', $.check);
router.post('/close', $.close);
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