Commit a80e3a24 by 马玮

Add account tool

parent 2b30ad5d
/*
User: MaWei
Date: 2017.7.31
*/
'use strict';
const program = require('commander');
const config = require('config');
const DealerHelper = require('./lib/helpers/Dealer');
program
.version('0.1.0')
.option('-t, --task <task name>', 'Task list: addAccount')
.option('-d, --dealerID <thirdparty account ID>', 'Assign dealerID')
.option('-w, --webname <thirdparty webname>', 'Webname list: autohome, easypass')
.option('-u, --username <thirdparty username>', 'Assign username')
.option('-p, --password <thirdparty password>', 'Assign password')
.parse(process.argv);
const commandError = [];
if (!program.task) {
commandError.push('缺少task!');
}
if (!program.dealerID) {
commandError.push('缺少dealerID!');
}
if (!program.webname) {
commandError.push('缺少webname!');
}
if (!program.username) {
commandError.push('缺少username!');
}
if (!program.password) {
commandError.push('缺少password!');
}
const validTasks = ['addAccount'];
if (program.task && !validTasks.includes(program.task)) {
commandError.push('网站类型不合法!');
}
const validWebsites = ['autohome', 'easypass'];
if (program.webname && !validWebsites.includes(program.webname)) {
commandError.push('网站类型不合法!');
}
if (commandError.length > 0) {
console.log(commandError.join(': '));
program.outputHelp();
process.exit(1);
}
(async () => {
if (program.task === 'addAccount') {
const success = await DealerHelper.addAccount(program);
if (success === true) {
console.log('账号添加成功!');
} else {
console.log('账号添加失败!');
}
process.exit();
}
})();
\ No newline at end of file
...@@ -3,7 +3,6 @@ User: MaWei ...@@ -3,7 +3,6 @@ User: MaWei
Date: 2017.7.31 Date: 2017.7.31
*/ */
'use strict'; 'use strict';
const path = require('path');
const program = require('commander'); const program = require('commander');
const config = require('config'); const config = require('config');
const captcha = require('./lib/captcha'); const captcha = require('./lib/captcha');
...@@ -17,12 +16,12 @@ program ...@@ -17,12 +16,12 @@ program
.parse(process.argv); .parse(process.argv);
const commandError = []; const commandError = [];
if (!program.thirdpartyAccountID) {
commandError.push('缺少thirdpartyAccountID!');
}
if (!program.task) { if (!program.task) {
commandError.push('缺少task!'); commandError.push('缺少task!');
} }
if (!program.thirdpartyAccountID) {
commandError.push('缺少thirdpartyAccountID!');
}
if (commandError.length > 0) { if (commandError.length > 0) {
console.log(commandError.join(': ')); console.log(commandError.join(': '));
......
...@@ -236,9 +236,7 @@ class DealerHelper { ...@@ -236,9 +236,7 @@ class DealerHelper {
const sql = `INSERT INTO crm_dealer_thirdparty_summary SET const sql = `INSERT INTO crm_dealer_thirdparty_summary SET
dealerID = ?, createdAt = UNIX_TIMESTAMP(), updatedAt = UNIX_TIMESTAMP(), dealerID = ?, createdAt = UNIX_TIMESTAMP(), updatedAt = UNIX_TIMESTAMP(),
totalClue = (SELECT COUNT(*) FROM crm_clue WHERE shop_id = ? AND create_type = 4) totalClue = (SELECT COUNT(*) FROM crm_clue WHERE shop_id = ? AND create_type = 4)
ON DUPLICATE KEY UPDATE ON DUPLICATE KEY UPDATE totalClue = VALUES(totalClue), updatedAt = VALUES(updatedAt)`;
totalClue = VALUES(totalClue),
updatedAt = VALUES(updatedAt)`;
const replacements = [params.dealerID, params.dealerID]; const replacements = [params.dealerID, params.dealerID];
console.log(replacements); console.log(replacements);
const connection = await DI.getConnection('MASTER_CRM'); const connection = await DI.getConnection('MASTER_CRM');
...@@ -261,6 +259,36 @@ class DealerHelper { ...@@ -261,6 +259,36 @@ class DealerHelper {
} }
}); });
} }
static async addAccount(params) {
return new Promise(async (resolve, reject) => {
try {
params.password = new Buffer(params.password).toString('base64');
const sql = `INSERT INTO crm_dealer_thirdparty_account SET
dealerID = ?, webname = ?, username = ?, password = ?, createdAt = UNIX_TIMESTAMP()
ON DUPLICATE KEY UPDATE
username = VALUES(username), password = VALUES(password)`;
const replacements = [params.dealerID, params.webname, params.username, params.password];
console.log(replacements);
const connection = await DI.getConnection('MASTER_CRM');
connection.query(
sql,
replacements,
function(err, results, fields) {
connection.release();
if (err) {
reject(err);
} else {
resolve(true);
}
}
);
} catch (e) {
reject(e);
}
});
}
} }
module.exports = DealerHelper; module.exports = DealerHelper;
\ No newline at end of file
UPDATE `crm_dd_input_type` SET `name`='易车' WHERE (`id`='21'); UPDATE `crm_dd_input_type` SET `name`='易车' WHERE (`id`='21');
ALTER TABLE `crm_clue` ALTER IGNORE TABLE `crm_clue`
ADD INDEX `customer_car` (`shop_id`, `clue_input_type`, `customer_phone`, `intention_des`, `create_time`); ADD UNIQUE INDEX `customer_car` (`shop_id`, `clue_input_type`, `customer_phone`, `intention_des`(191), `create_time`);
\ No newline at end of file \ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
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 sign in to comment