Commit 3f46088c by chenjinjing

部署V2版本

parent d2c64498
{ {}
"1730970187744": {} \ No newline at end of file
}
\ No newline at end of file
{ {}
"1727399696222": { \ No newline at end of file
"isSubmit": false,
"S": [
{
"xsid": "C002",
"xsnr": "熟悉整套生产运输流程",
"isChoice": false
},
{
"xsid": "C003",
"xsnr": "有瓷器的实际设计成功经验",
"isChoice": false
}
],
"W": [],
"O": [],
"T": []
},
"1730970187744": {
"isSubmit": false,
"S": [],
"W": [],
"O": [
{
"xsid": "C003",
"xsnr": "有瓷器的实际设计成功经验",
"isChoice": false
},
{
"xsid": "C004",
"xsnr": "在多地有熟识的好友可以提供咨询协助",
"isChoice": false
}
],
"T": []
}
}
\ No newline at end of file
{ {
{ {
"1730970187744": {
"普通线索": [
{
"xsid": "C001",
"xsnr": "马可波罗要定制1000只瓷器",
"isChoice": false,
"sfbx": "否"
}
],
"SWOT": [
{
"xsid": "C002",
"xsnr": "熟悉整套生产运输流程",
"isChoice": false,
"sfbx": "否"
},
{
"xsid": "C003",
"xsnr": "有瓷器的实际设计成功经验",
"isChoice": true,
"sfbx": "否"
},
{
"xsid": "C004",
"xsnr": "在多地有熟识的好友可以提供咨询协助",
"isChoice": true,
"sfbx": "否"
},
{
"xsid": "C005",
"xsnr": "有景德镇瓷胚的进货渠道",
"isChoice": false,
"sfbx": "否"
},
{
"xsid": "C006",
"xsnr": "资金匮乏",
"isChoice": false,
"sfbx": "否"
},
{
"xsid": "C007",
"xsnr": "没有外贸经验",
"isChoice": false,
"sfbx": "否"
},
{
"xsid": "C008",
"xsnr": "没有成熟团队",
"isChoice": false,
"sfbx": "否"
},
{
"xsid": "C015",
"xsnr": "广州气候适宜",
"isChoice": false,
"sfbx": "否"
},
{
"xsid": "C013",
"xsnr": "西洋有大量的瓷器进口需求",
"isChoice": false,
"sfbx": "否"
}
],
"竞合": [
{
"xsid": "C023",
"xsnr": "从马可波罗口中得知,西洋订单大增",
"isChoice": false,
"sfbx": "否"
},
{
"xsid": "C024",
"xsnr": "西洋订单货品质量和交货时限有严格要求",
"isChoice": false,
"sfbx": "否"
}
],
"ROI": [
{
"xsid": "C046",
"xsnr": "定制精美瓷器售价",
"isChoice": false,
"sfbx": "制成瓷器"
},
{
"xsid": "C047",
"xsnr": "定制普通瓷器售价",
"isChoice": false,
"sfbx": "制成瓷器"
},
{
"xsid": "C048",
"xsnr": "通用精美瓷器售价",
"isChoice": false,
"sfbx": "制成瓷器"
},
{
"xsid": "C049",
"xsnr": "通用普通瓷器售价",
"isChoice": false,
"sfbx": "制成瓷器"
},
{
"xsid": "C027",
"xsnr": "工人甲",
"isChoice": false,
"sfbx": "工人"
},
{
"xsid": "C028",
"xsnr": "工人乙",
"isChoice": false,
"sfbx": "工人"
},
{
"xsid": "C029",
"xsnr": "工人丙",
"isChoice": false,
"sfbx": "工人"
},
{
"xsid": "C030",
"xsnr": "工人丁",
"isChoice": false,
"sfbx": "工人"
},
{
"xsid": "C031",
"xsnr": "工人戊",
"isChoice": false,
"sfbx": "工人"
},
{
"xsid": "C032",
"xsnr": "工人己",
"isChoice": false,
"sfbx": "工人"
},
{
"xsid": "C033",
"xsnr": "工人庚",
"isChoice": false,
"sfbx": "工人"
},
{
"xsid": "C034",
"xsnr": "工人辛",
"isChoice": false,
"sfbx": "工人"
},
{
"xsid": "C035",
"xsnr": "画师1",
"isChoice": false,
"sfbx": "画师"
},
{
"xsid": "C036",
"xsnr": "画师2",
"isChoice": false,
"sfbx": "画师"
},
{
"xsid": "C037",
"xsnr": "画师3",
"isChoice": false,
"sfbx": "画师"
},
{
"xsid": "C038",
"xsnr": "掌柜A",
"isChoice": false,
"sfbx": "掌柜"
},
{
"xsid": "C039",
"xsnr": "掌柜B",
"isChoice": false,
"sfbx": "掌柜"
}
]
},
"1727399696222": {
"普通线索": [], "普通线索": [],
"SWOT": [ "SWOT": [
{ {
...@@ -237,5 +52,4 @@ ...@@ -237,5 +52,4 @@
], ],
"竞合": [], "竞合": [],
"ROI": [] "ROI": []
}
} }
\ No newline at end of file
{ {
{ {
"1727399696222": {
"初始资金": 500, "初始资金": 500,
"天数": 215, "天数": 73,
"结算": 500, "结算": 500,
"广州府介绍": false, "广州府介绍": false,
"酒馆剧情": 2,
"当前线索确认": 1,
"商行选择": false,
"SWOT": true,
"ROI": false,
"竞合": false,
"码头": {
"S011": {
"当前对话id": "17",
"已获得的线索": [
"C023",
"C013",
"C046",
"C047",
"C048",
"C049",
"C001",
"C024"
]
}
},
"酒馆": {
"S023": {
"当前对话id": 1,
"已获得的线索": []
},
"S024": {
"当前对话id": 1
},
"S022": {
"当前对话id": "2"
},
"S021": {
"当前对话id": 1
}
}
},
"1729153582461": {
"初始资金": 500,
"天数": 112,
"结算": 500,
"广州府介绍": false,
"酒馆剧情": 0,
"当前线索确认": 0,
"商行选择": false,
"SWOT": false,
"ROI": false,
"竞合": false
},
"1730359559228": {
"初始资金": 500,
"天数": 0,
"结算": 500,
"广州府介绍": true,
"酒馆剧情": 0,
"当前线索确认": 0,
"商行选择": false,
"SWOT": false,
"ROI": false,
"竞合": false
},
"1730970187744": {
"初始资金": 500,
"天数": 3,
"结算": -112700,
"广州府介绍": false,
"酒馆剧情": 2,
"当前线索确认": 1,
"商行选择": true,
"SWOT": true,
"ROI": true,
"竞合": false,
"码头": {
"S011": {
"当前对话id": "17",
"已获得的线索": [
"C023",
"C013",
"C046",
"C047",
"C048",
"C049",
"C001",
"C024"
]
}
},
"酒馆": {
"S021": {
"当前对话id": 1,
"已获得的线索": []
}
}
},
"1730359573927": {
"初始资金": 500,
"天数": 0,
"结算": 500,
"广州府介绍": true,
"酒馆剧情": 0,
"当前线索确认": 0,
"商行选择": false,
"SWOT": false,
"ROI": false,
"竞合": false
},
"1730970810891": {
"初始资金": 500,
"天数": 0,
"结算": 500,
"广州府介绍": true,
"酒馆剧情": 0,
"当前线索确认": 0,
"商行选择": false,
"SWOT": false,
"ROI": false,
"竞合": false
},
"1732604118825": {
"初始资金": 500,
"天数": 0,
"结算": 500,
"广州府介绍": true,
"酒馆剧情": 0, "酒馆剧情": 0,
"当前线索确认": 0, "当前线索确认": 0,
"商行选择": false, "商行选择": false,
"SWOT": false, "SWOT": false,
"ROI": false, "ROI": false,
"竞合": false "竞合": false
}
} }
\ No newline at end of file
{ {
{ {
"1727399696222": {
"SWOT": 7.6923076923076925,
"ROI": 0,
"竞合": 0
},
"1729153582461": {
"SWOT": 0,
"ROI": 0,
"竞合": 0
},
"1730359559228": {
"SWOT": 0,
"ROI": 0,
"竞合": 0
},
"1730970187744": {
"SWOT": 0
},
"1730359573927": {
"SWOT": 0,
"ROI": 0,
"竞合": 0
},
"1730970810891": {
"SWOT": 0,
"ROI": 0,
"竞合": 0
},
"1732604118825": {
"SWOT": 0, "SWOT": 0,
"ROI": 0, "ROI": 0,
"竞合": 0 "竞合": 0
}
} }
\ No newline at end of file
{ {}
{ {}
"1730970187744": {} \ No newline at end of file
}
\ No newline at end of file
{ {}
{ {}
"SWOT": { \ No newline at end of file
"S": [
"C002",
"C003",
"C004",
"C005"
],
"W": [
"C006",
"C007",
"C008"
],
"O": [
"C012",
"C013",
"C014"
],
"T": [
"C009",
"C010",
"C011"
]
},
"ROI": {
"R": [
"C046",
"C047",
"C048",
"C049"
],
"I": [
"C027",
"C028",
"C029",
"C030",
"C031",
"C032",
"C033",
"C034",
"C035",
"C036",
"C037",
"C038",
"C039",
"C040",
"C041",
"C042",
"C043",
"C044",
"C045"
]
},
"竞合": {
"供方": [
"C017",
"C018"
],
"现有竞争": [
"C019"
],
"潜在竞争": [
"C020"
],
"替代竞争": [
"C021",
"C022"
],
"买方": [
"C023",
"C024"
]
}
}
\ No newline at end of file
{ {}
{ {}
"1730970187744": { \ No newline at end of file
"人工": {
"工人": "C025",
"画师": "C032",
"掌柜": "C035"
},
"原材料": {
"瓷器": "C041",
"颜料": "C039"
},
"运输": "C037",
"制成瓷器": "C045"
}
}
\ No newline at end of file
{ {
{ {
"瓷器": { "瓷器": {
"定制精美瓷器": { "定制精美瓷器": {
"瓷器": "C040", "瓷器": "C044",
"颜料": "C038", "颜料": "C042",
"单价": 300, "单价": 300,
"固定成本": 200 "固定成本": 200
}, },
"定制普通瓷器": { "定制普通瓷器": {
"瓷器": "C040", "瓷器": "C044",
"颜料": "C039", "颜料": "C043",
"单价": 270, "单价": 270,
"固定成本": 190 "固定成本": 190
}, },
"通用精美瓷器": { "通用精美瓷器": {
"瓷器": "C041", "瓷器": "C045",
"颜料": "C038", "颜料": "C042",
"单价": 170, "单价": 170,
"固定成本": 120 "固定成本": 120
}, },
"通用普通瓷器": { "通用普通瓷器": {
"瓷器": "C041", "瓷器": "C045",
"颜料": "C039", "颜料": "C043",
"单价": 150, "单价": 150,
"固定成本": 110 "固定成本": 110
} }
}, },
"人员成本": { "人员成本": {
"C023": { "C027": {
"ycl": 360, "ycl": 360,
"gz": 150, "gz": 150,
"fjcb": 0.42 "fjcb": 0.42
}, },
"C024": { "C028": {
"ycl": 450, "ycl": 450,
"gz": 150, "gz": 150,
"fjcb": 0.33 "fjcb": 0.33
}, },
"C025": { "C029": {
"ycl": 510, "ycl": 510,
"gz": 150, "gz": 150,
"fjcb": 0.29 "fjcb": 0.29
}, },
"C026": { "C030": {
"ycl": 840, "ycl": 840,
"gz": 300, "gz": 300,
"fjcb": 0.36 "fjcb": 0.36
}, },
"C027": { "C031": {
"ycl": 960, "ycl": 960,
"gz": 300, "gz": 300,
"fjcb": 0.31 "fjcb": 0.31
}, },
"C028": { "C032": {
"ycl": 1050, "ycl": 1050,
"gz": 300, "gz": 300,
"fjcb": 0.29 "fjcb": 0.29
}, },
"C029": { "C033": {
"ycl": 1350, "ycl": 1350,
"gz": 450, "gz": 450,
"fjcb": 0.33 "fjcb": 0.33
}, },
"C030": { "C034": {
"ycl": 1650, "ycl": 1650,
"gz": 450, "gz": 450,
"fjcb": 0.27 "fjcb": 0.27
}, },
"C031": { "C035": {
"ycl": 500, "ycl": 500,
"gz": 1000, "gz": 1000,
"fjcb": 2 "fjcb": 2
}, },
"C032": { "C036": {
"ycl": 1320, "ycl": 1320,
"gz": 2000, "gz": 2000,
"fjcb": 1.52 "fjcb": 1.52
}, },
"C033": { "C037": {
"ycl": 1900, "ycl": 1900,
"gz": 3000, "gz": 3000,
"fjcb": 1.58 "fjcb": 1.58
}, },
"C034": { "C038": {
"ycl": 1000, "ycl": 1000,
"gz": 1000, "gz": 1000,
"fjcb": 1 "fjcb": 1
}, },
"C035": { "C039": {
"ycl": 1100, "ycl": 1100,
"gz": 1050, "gz": 1050,
"fjcb": 0.95 "fjcb": 0.95
} }
}, },
"运输成本": { "运输成本": {
"C036": { "C040": {
"sjmc": "车路", "sjmc": "车路",
"xjb": 1.33 "xjb": 1.33
}, },
"C037": { "C041": {
"sjmc": "水路", "sjmc": "水路",
"xjb": 1 "xjb": 1
} }
......
[ [
...@@ -19,8 +19,7 @@ ...@@ -19,8 +19,7 @@
{ {
"userId": "1730970187744", "userId": "1730970187744",
"loginId": "111", "loginId": "111",
"pwd": "123456", "pwd": "123456"
"name": "小陈"
}, },
{ {
"userId": "1730359573927", "userId": "1730359573927",
......
No preview for this file type
No preview for this file type
...@@ -6,16 +6,16 @@ ...@@ -6,16 +6,16 @@
import { HARITYPE, NOWCLUE } from "../config/enum"; import { HARITYPE, NOWCLUE } from "../config/enum";
import { xiansuoTableData, guyongTableData } from "../data/table/tableData"; import { xiansuoTableData, guyongTableData } from "../data/table/tableData";
import { successResult } from "../tools/systemTools"; import { successResult } from "../tools/systemTools";
import { changeJsonData, getJsonData } from "../util/tools"; import { changeUserJsonData, getUserJsonData } from "../util/tools";
/** /**
* 是否启用线索 * 是否启用线索
* @param userId * @param userId
*/ */
export function isEnabled(userId:string) { export async function isEnabled(userId:string) {
//获取已有json数据 //获取已有json数据
let baseData = getJsonData("json/基础数据.json")[userId]; let baseData:any = await getUserJsonData(`基础数据.json`, userId);
let isEnabled = { let isEnabled = {
"SWOT": baseData.SWOT, "SWOT": baseData.SWOT,
"ROI": baseData.ROI, "ROI": baseData.ROI,
...@@ -27,37 +27,9 @@ export function isEnabled(userId:string) { ...@@ -27,37 +27,9 @@ export function isEnabled(userId:string) {
/** /**
* 弃用
* 添加线索 todo线索改为剧情走过才添加
* @param userId
*/
export function addClue(userId:string) {
let excelData = xiansuoTableData();
let clueExcelData = excelData["线索表"].dataList;
let writeClueAll = {};
/**添加全部线索 */
let clueData = {};
clueExcelData.forEach( info => {
let {xsid, xsnr, xslx, xslxxf, zs, dhgl, sfbx} = info;
if (!clueData[xslx]) clueData[xslx] = [];
clueData[xslx].push({xsid, xsnr});
if (!writeClueAll[userId]) writeClueAll[userId] = [];
writeClueAll[userId].push({xsid, xsnr, isChoice:false});
})
let allClueJson = getJsonData("json/全部线索.json");
if(!allClueJson[userId] || allClueJson[userId].length == 0) addAllClue(writeClueAll);
console.log(`${userId}全部线索添加成功`);
}
/**
* 添加细分线索 todo线索改为剧情走过才添加 * 添加细分线索 todo线索改为剧情走过才添加
*/ */
export function xfxxClue() { export async function xfxxClue(userId) {
let excelData = xiansuoTableData(); let excelData = xiansuoTableData();
let clueExcelData = excelData["线索表"].dataList; let clueExcelData = excelData["线索表"].dataList;
...@@ -86,9 +58,7 @@ export function xfxxClue() { ...@@ -86,9 +58,7 @@ export function xfxxClue() {
"竞合":jinheClue "竞合":jinheClue
}; };
changeJsonData("json/细分线索.json", xfxxClueJson); await changeUserJsonData("细分线索.json", userId, xfxxClueJson);
// let xfClueJson = getJsonData("json/细分线索.json");
// if(!xfClueJson || Object.keys(xfxxClueJson).length === 0) changeJsonData("json/细分线索.json", xfxxClueJson);
console.log(`细分线索添加成功`); console.log(`细分线索添加成功`);
} }
...@@ -98,47 +68,26 @@ export function xfxxClue() { ...@@ -98,47 +68,26 @@ export function xfxxClue() {
* 提交线索 * 提交线索
* @param clueType 线索类型【SWOT、ROI、竞合】 * @param clueType 线索类型【SWOT、ROI、竞合】
*/ */
export function submitClue(userId, clueType) { export async function submitClue(userId, clueType) {
let jsonData = getJsonData(`json/${clueType}.json`); let jsonData = await getUserJsonData(`${clueType}.json`, userId);
let baseData = jsonData; let baseData = jsonData;
//isSubmit:false【未提交】、true【提交】 //isSubmit:false【未提交】、true【提交】
baseData[userId]["isSubmit"] = true; baseData["isSubmit"] = true;
changeJsonData("json/已提交线索.json", baseData); await changeUserJsonData("已提交线索.json", userId, baseData);
console.log("已提交线索"); console.log("已提交线索");
/**清空原有剧情和线索 */
// restart(userId);
return successResult(); return successResult();
} }
/** /**
* 弃用
* 添加全部线索
* @param data
*/
export function addAllClue(data) {
let jsonData = getJsonData("json/全部线索.json");
let baseData = jsonData;
//isChoice:false【未选择】、true【已选择】
if (Object.keys(baseData).length === 0 || !baseData) {
changeJsonData("json/全部线索.json", data);
console.log("已添加全部线索");
}
}
/**
* 线索 * 线索
* 有参数返回对应线索类型数据,没有参数返回已走过剧情的全部线索数据 * 有参数返回对应线索类型数据,没有参数返回已走过剧情的全部线索数据
* @param clueType 线索类型 * @param clueType 线索类型
* @returns * @returns
*/ */
export function getClue(userId, clueType?) { export async function getClue(userId, clueType?) {
let excelData = xiansuoTableData(); let excelData = xiansuoTableData();
let clueExcelData = excelData["线索表"].dataList; let clueExcelData = excelData["线索表"].dataList;
...@@ -149,26 +98,13 @@ export function getClue(userId, clueType?) { ...@@ -149,26 +98,13 @@ export function getClue(userId, clueType?) {
clueData[xslx].push({xsid, xsnr, sfbx}); clueData[xslx].push({xsid, xsnr, sfbx});
}) })
/**如果登录的账号没有全部线索数据,则写入json */
// let allClueJson = getJsonData("json/全部线索.json");
// let writeClueAll = allClueJson;
// if (Object.keys(allClueJson[userId]).length == 0) {
// writeClueAll[userId] = {};
// clueExcelData.forEach( info => {
// let {xsid, xsnr, xslx, xslxxf, sfbx} = info;
// if (!writeClueAll[userId][xslx]) writeClueAll[userId][xslx] = [];
// writeClueAll[userId][xslx].push({xsid, xsnr, isChoice:false, sfbx});
// })
// //写入json
// changeJsonData("json/全部线索.json", writeClueAll);
// }
let clueList = []; let clueList = [];
let guyongJson = getJsonData("json/雇佣选择.json"); let guyongJson = await getUserJsonData("雇佣选择.json", userId);
let guyongUserJson = guyongJson[userId]; let guyongUserJson = guyongJson;
let grData:any = {"工人":[], "画师":[], "掌柜":[], "运输":[], "颜料":[], "瓷器":[], "是":[], "否":[], "制成瓷器":[]}; let grData:any = {"工人":[], "画师":[], "掌柜":[], "运输":[], "颜料":[], "瓷器":[], "是":[], "否":[], "制成瓷器":[]};
/**特化ROI线索列表,返回已选择的工人、画师、掌柜 */ /**特化ROI线索列表,返回已选择的工人、画师、掌柜、运输等 */
if (clueType == "ROI") { if (clueType == "ROI") {
//根据原材料选择出制作的是哪个款式的瓷器 //根据原材料选择出制作的是哪个款式的瓷器
let gyExcelData = guyongTableData(); let gyExcelData = guyongTableData();
...@@ -183,8 +119,7 @@ export function getClue(userId, clueType?) { ...@@ -183,8 +119,7 @@ export function getClue(userId, clueType?) {
guyongUserJson["制成瓷器"] = xsid; guyongUserJson["制成瓷器"] = xsid;
} }
}) })
guyongJson[userId] = guyongUserJson; await changeUserJsonData("雇佣选择.json", userId, guyongUserJson);
changeJsonData("json/雇佣选择.json", guyongJson);
let ROI = []; let ROI = [];
clueData[clueType].forEach( info => { clueData[clueType].forEach( info => {
...@@ -219,21 +154,18 @@ export function getClue(userId, clueType?) { ...@@ -219,21 +154,18 @@ export function getClue(userId, clueType?) {
clueData["ROI"] = ROI; clueData["ROI"] = ROI;
} }
let allClueChange = getJsonData("json/全部线索.json"); let allClueChange = await getUserJsonData("全部线索.json", userId);
if(clueType) { if(clueType) {
clueData[clueType].forEach( info => { clueData[clueType].forEach( info => {
// for(let key in allClueChange[userId]) { allClueChange[clueType].forEach( thisClue => {
// }
allClueChange[userId][clueType].forEach( thisClue => {
if(info.xsid == thisClue.xsid) { if(info.xsid == thisClue.xsid) {
clueList.push(thisClue); clueList.push(thisClue);
} }
}) })
}) })
} else { } else {
for(let key in allClueChange[userId]) { for(let key in allClueChange) {
allClueChange[userId][key].forEach( thisClue => { allClueChange[key].forEach( thisClue => {
clueList.push(thisClue); clueList.push(thisClue);
}) })
} }
...@@ -250,7 +182,6 @@ export function getClue(userId, clueType?) { ...@@ -250,7 +182,6 @@ export function getClue(userId, clueType?) {
}); });
} }
return clueList; return clueList;
} }
...@@ -259,11 +190,11 @@ export function getClue(userId, clueType?) { ...@@ -259,11 +190,11 @@ export function getClue(userId, clueType?) {
* 回显细分线索 * 回显细分线索
* @param clueType 线索类型【SWOT、ROI、竞合】 * @param clueType 线索类型【SWOT、ROI、竞合】
*/ */
export function getChoiceClue(userId, clueType) { export async function getChoiceClue(userId, clueType) {
let jsonData = getJsonData(`json/${clueType}.json`); let jsonData = await getUserJsonData(`${clueType}.json`, userId);
let baseData = {}; let baseData = {};
if (Object.keys(jsonData).length === 0) baseData = {}; if (Object.keys(jsonData).length === 0) baseData = {};
else baseData = jsonData[userId]; else baseData = jsonData;
return baseData; return baseData;
} }
...@@ -276,39 +207,39 @@ export function getChoiceClue(userId, clueType) { ...@@ -276,39 +207,39 @@ export function getChoiceClue(userId, clueType) {
* @param xsid 线索id: C001 * @param xsid 线索id: C001
* @returns * @returns
*/ */
export function delClue(userId, clueType, xxType, xsid) { export async function delClue(userId, clueType, xxType, xsid) {
let jsonData = getJsonData(`json/${clueType}.json`); let jsonData = await getUserJsonData(`${clueType}.json`, userId);
let baseData = jsonData; let baseData = jsonData;
let clueData = baseData[userId][xxType]; let clueData = baseData[xxType];
/**过滤掉xsid的元素 */ /**过滤掉xsid的元素 */
let clueDelData = clueData.filter(x => ![xsid].includes(x.xsid)); let clueDelData = clueData.filter(x => ![xsid].includes(x.xsid));
baseData[userId][xxType] = clueDelData; baseData[xxType] = clueDelData;
changeJsonData(`json/${clueType}.json`, baseData); await changeUserJsonData(`${clueType}.json`, userId, baseData);
console.log(baseData); console.log(baseData);
let allClueJson = getJsonData("json/全部线索.json"); let allClueJson = await getUserJsonData("全部线索.json", userId);
// let allClueData = allClueJson; // let allClueData = allClueJson;
for (let key in allClueJson[userId]) { for (let key in allClueJson) {
allClueJson[userId][key].forEach( thisClue => { allClueJson[key].forEach( thisClue => {
if(xsid == thisClue.xsid) thisClue.isChoice = false; if(xsid == thisClue.xsid) thisClue.isChoice = false;
}); });
} }
changeJsonData("json/全部线索.json", allClueJson); await changeUserJsonData(`全部线索.json`, userId, allClueJson);
if (xxType == "R") { if (xxType == "R") {
let excelData = guyongTableData(); let excelData = guyongTableData();
let ciqiExcel = excelData['制作瓷器'].dataList; let ciqiExcel = excelData['制作瓷器'].dataList;
let ciqiMoney = 0; let ciqiMoney = 0;
let baseClueJson = getJsonData("json/基础数据.json"); let baseClueJson = await getUserJsonData("基础数据.json", userId);
ciqiExcel.forEach( info => { ciqiExcel.forEach( info => {
if (info.xsid == xsid) ciqiMoney = info.sj; if (info.xsid == xsid) ciqiMoney = info.sj;
}); });
//加上定制瓷器金额 //加上定制瓷器金额
let jsje = baseClueJson[userId]["结算"] || 0; let jsje = baseClueJson["结算"] || 0;
baseClueJson[userId]["结算"] = jsje - ciqiMoney * 1000; baseClueJson["结算"] = jsje - ciqiMoney * 1000;
changeJsonData("json/基础数据.json", baseClueJson); await changeUserJsonData("基础数据.json", userId, baseClueJson);
} }
return successResult(); return successResult();
...@@ -319,8 +250,8 @@ export function delClue(userId, clueType, xxType, xsid) { ...@@ -319,8 +250,8 @@ export function delClue(userId, clueType, xxType, xsid) {
* 提交线索 * 提交线索
* @param userId * @param userId
*/ */
export function checkClue(userId) { export async function checkClue(userId) {
let jsonData = getJsonData("json/提交分数.json")[userId]; let jsonData = await getUserJsonData("提交分数.json", userId);
let swot = jsonData["SWOT"] || 0; let swot = jsonData["SWOT"] || 0;
let roi = jsonData["ROI"] || 0; let roi = jsonData["ROI"] || 0;
...@@ -372,11 +303,11 @@ export function checkClue(userId) { ...@@ -372,11 +303,11 @@ export function checkClue(userId) {
* 只需清空已选择线索,剧情不需要重新玩 * 只需清空已选择线索,剧情不需要重新玩
* @param userId * @param userId
*/ */
export function againAnswer(userId) { export async function againAnswer(userId) {
//根据原材料选择出制作的是哪个款式的瓷器 //根据原材料选择出制作的是哪个款式的瓷器
let baseClueJson = getJsonData("json/基础数据.json"); let baseClueJson = await getUserJsonData("基础数据.json", userId);
let guyongJson = getJsonData("json/雇佣选择.json"); let guyongJson = await getUserJsonData("雇佣选择.json", userId);
let guyongUserJson = guyongJson[userId]; let guyongUserJson = guyongJson;
let gyExcelData = guyongTableData(); let gyExcelData = guyongTableData();
let zzcqExcelData = gyExcelData["制作瓷器"].dataList; let zzcqExcelData = gyExcelData["制作瓷器"].dataList;
...@@ -394,27 +325,27 @@ export function againAnswer(userId) { ...@@ -394,27 +325,27 @@ export function againAnswer(userId) {
}) })
//删去结算金额上的定制瓷器金额 //删去结算金额上的定制瓷器金额
let jsje = baseClueJson[userId]["结算"] || 0; let jsje = baseClueJson["结算"] || 0;
baseClueJson[userId]["结算"] = jsje - ciqiMoney * 1000; baseClueJson["结算"] = jsje - ciqiMoney * 1000;
changeJsonData("json/基础数据.json", baseClueJson); await changeUserJsonData("基础数据.json", userId, baseClueJson);
let againJson = ["SWOT", "ROI", "竞合"]; let againJson = ["SWOT", "ROI", "竞合"];
for (let i = 0; i < againJson.length; i++) { for (let i = 0; i < againJson.length; i++) {
let allJson = getJsonData(`json/${againJson[i]}.json`); let allJson = await getUserJsonData(`${againJson[i]}.json`, userId);
allJson[userId] = {}; allJson = {};
changeJsonData(`json/${againJson[i]}.json`, allJson); await changeUserJsonData(`${againJson[i]}.json`, userId, allJson);
} }
/**修改全部线索的已选中 */ /**修改全部线索的已选中 */
let allClueJson = getJsonData("json/全部线索.json"); let allClueJson = await getUserJsonData("全部线索.json", userId);
// let allClueData = allClueJson; // let allClueData = allClueJson;
for (let key in allClueJson[userId]) { for (let key in allClueJson) {
allClueJson[userId][key].forEach( thisClue => { allClueJson[key].forEach( thisClue => {
thisClue.isChoice = false; thisClue.isChoice = false;
}); });
} }
changeJsonData("json/全部线索.json", allClueJson); await changeUserJsonData("全部线索.json", userId, allClueJson);
return successResult(); return successResult();
} }
...@@ -425,18 +356,18 @@ export function againAnswer(userId) { ...@@ -425,18 +356,18 @@ export function againAnswer(userId) {
* 当前用户数据全部清空 * 当前用户数据全部清空
* @param userId * @param userId
*/ */
export function againStart(userId) { export async function againStart(userId) {
let againJson = ["雇佣选择", "全部线索", "提交分数", "细分线索", "SWOT", "ROI", "竞合"]; let againJson = ["雇佣选择", "全部线索", "提交分数", "细分线索", "SWOT", "ROI", "竞合"];
for (let i = 0; i < againJson.length; i++) { for (let i = 0; i < againJson.length; i++) {
let allJson = getJsonData(`json/${againJson[i]}.json`); let allJson = await getUserJsonData(`${againJson[i]}.json`, userId);
allJson[userId] = {}; allJson = {};
changeJsonData(`json/${againJson[i]}.json`, allJson); await changeUserJsonData(`${againJson[i]}.json`, userId, allJson);
} }
let userJson = getJsonData("json/基础数据.json"); let userJson = await getUserJsonData("基础数据.json", userId);
let writeBaseAll = userJson; let writeBaseAll = userJson;
writeBaseAll[userId] = { writeBaseAll = {
"初始资金": 500, "初始资金": 500,
"天数":1, "天数":1,
"结算":500, "结算":500,
...@@ -451,7 +382,7 @@ export function againStart(userId) { ...@@ -451,7 +382,7 @@ export function againStart(userId) {
} }
//写入json //写入json
changeJsonData("json/基础数据.json", writeBaseAll); await changeUserJsonData("基础数据.json", userId, writeBaseAll);
return successResult(); return successResult();
} }
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
import { NOWCLUE } from "../config/enum"; import { NOWCLUE } from "../config/enum";
import { successResult } from "../tools/systemTools"; import { successResult } from "../tools/systemTools";
import { changeJsonData, getJsonData } from "../util/tools"; import { changeUserJsonData, getUserJsonData } from "../util/tools";
/** /**
...@@ -17,14 +17,14 @@ import { changeJsonData, getJsonData } from "../util/tools"; ...@@ -17,14 +17,14 @@ import { changeJsonData, getJsonData } from "../util/tools";
* @param subdivide 细分线索类型【供方、现有竞争、潜在竞争、替代竞争、买方】 * @param subdivide 细分线索类型【供方、现有竞争、潜在竞争、替代竞争、买方】
* @param xs [{xsid:"", xsnr:""}, ...] * @param xs [{xsid:"", xsnr:""}, ...]
*/ */
export function submitJinheClue(userId, subdivide, xs) { export async function submitJinheClue(userId, subdivide, xs) {
let jsonData = getJsonData("json/竞合.json"); let jsonData = await getUserJsonData("竞合.json", userId);
/**处理确认选择的线索 */ /**处理确认选择的线索 */
let jinheClueData = jsonData; let jinheClueData = jsonData;
//没有对应用户数据先添加一个基础格式,有的话直接push //没有对应用户数据先添加一个基础格式,有的话直接push
if (!jinheClueData[userId] || Object.keys(jinheClueData[userId]).length === 0) { if (!jinheClueData || Object.keys(jinheClueData).length === 0) {
jinheClueData[userId] = { jinheClueData = {
"isSubmit": false, "isSubmit": false,
"供方": [], "供方": [],
"现有竞争": [], "现有竞争": [],
...@@ -36,35 +36,35 @@ export function submitJinheClue(userId, subdivide, xs) { ...@@ -36,35 +36,35 @@ export function submitJinheClue(userId, subdivide, xs) {
//isSubmit:false【未提交】、true【提交】 //isSubmit:false【未提交】、true【提交】
/**当前线索类型未提交时,可以修改添加线索 */ /**当前线索类型未提交时,可以修改添加线索 */
if (!jinheClueData[userId]["isSubmit"]) { if (!jinheClueData["isSubmit"]) {
for (let i = 0; i < xs.length; i++) { for (let i = 0; i < xs.length; i++) {
// let xsInfo = xs[i]; // let xsInfo = xs[i];
jinheClueData[userId][subdivide].push(xs[i]); jinheClueData[subdivide].push(xs[i]);
} }
changeJsonData("json/竞合.json", jinheClueData); await changeUserJsonData("竞合.json", userId, jinheClueData);
console.log("添加ROI线索成功"); console.log("添加ROI线索成功");
} else { } else {
console.log("线索已提交,无法重复提交"); console.log("线索已提交,无法重复提交");
} }
/**修改全部线索.json的对应线索为已选择 isChoice:true */ /**修改全部线索.json的对应线索为已选择 isChoice:true */
let allClueJson = getJsonData("json/全部线索.json"); let allClueJson = await getUserJsonData("全部线索.json", userId);
let allClueData = allClueJson; let allClueData = allClueJson;
xs.forEach( info => { xs.forEach( info => {
let {xsid, xsnr} = info; let {xsid, xsnr} = info;
for(let key in allClueData[userId]) { for(let key in allClueData) {
allClueData[userId][key].forEach( thisClue => { allClueData[key].forEach( thisClue => {
if(xsid == thisClue.xsid) thisClue.isChoice = true; if(xsid == thisClue.xsid) thisClue.isChoice = true;
}) })
} }
}); });
changeJsonData("json/全部线索.json", allClueData); await changeUserJsonData("全部线索.json", userId, allClueData);
let baseJsonData = getJsonData("json/基础数据.json"); let baseJsonData = await getUserJsonData("基础数据.json", userId);
baseJsonData[userId]["当前线索确认"] = NOWCLUE.竞合; baseJsonData["当前线索确认"] = NOWCLUE.竞合;
changeJsonData("json/基础数据.json", baseJsonData); await changeUserJsonData("基础数据.json", userId, baseJsonData);
return successResult(); return successResult();
} }
...@@ -75,10 +75,10 @@ export function submitJinheClue(userId, subdivide, xs) { ...@@ -75,10 +75,10 @@ export function submitJinheClue(userId, subdivide, xs) {
* 计算选择正确的竞合线索 * 计算选择正确的竞合线索
* @param userId * @param userId
*/ */
export function checkJinhe(userId) { export async function checkJinhe(userId) {
/**获取细分线索 */ /**获取细分线索 */
let xfclueJson = getJsonData("json/细分线索.json"); let xfclueJson = await getUserJsonData("细分线索.json", userId);
let clueJson = getJsonData("json/竞合.json")[userId]; let clueJson = await getUserJsonData("竞合.json", userId);
let sumClue = 0; //线索总数 let sumClue = 0; //线索总数
let rightClue = 0; //选对线索数 let rightClue = 0; //选对线索数
...@@ -103,10 +103,10 @@ export function checkJinhe(userId) { ...@@ -103,10 +103,10 @@ export function checkJinhe(userId) {
/**计算分数 */ /**计算分数 */
// score = rightClue/sumClue*(1/5)*20; // score = rightClue/sumClue*(1/5)*20;
score = (rightClue/sumClue)*20; score = (rightClue/sumClue)*20;
let submitJsonData = getJsonData("json/提交分数.json"); let submitJsonData = await getUserJsonData("提交分数.json", userId);
let submitScore = submitJsonData; let submitScore = submitJsonData;
submitScore[userId]["竞合"] = score; submitScore["竞合"] = score;
changeJsonData("json/提交分数.json", submitScore); await changeUserJsonData("提交分数.json", userId, submitScore);
return successResult(); return successResult();
} }
......
...@@ -3,13 +3,11 @@ ...@@ -3,13 +3,11 @@
*/ */
import { HARITYPE, NOWCLUE } from "../config/enum"; import { HARITYPE, NOWCLUE } from "../config/enum";
import { ERRORENUM } from "../config/errorEnum";
import { systemConfig } from "../config/serverConfig"; import { systemConfig } from "../config/serverConfig";
import { guyongTableData, juqingTableData, NPCTableData, xiansuoTableData } from "../data/table/tableData"; import { guyongTableData, juqingTableData, NPCTableData, xiansuoTableData } from "../data/table/tableData";
import { successErrorResult, successResult } from "../tools/systemTools"; import { successErrorResult, successResult } from "../tools/systemTools";
import { BizError } from "../util/bizError"; import { changeUserJsonData, getJsonData, getUserJsonData } from "../util/tools";
import { changeJsonData, getJsonData } from "../util/tools"; import { xfxxClue } from "./clue";
import { addAllClue, xfxxClue } from "./clue";
/** /**
...@@ -19,21 +17,21 @@ import { addAllClue, xfxxClue } from "./clue"; ...@@ -19,21 +17,21 @@ import { addAllClue, xfxxClue } from "./clue";
* @param dhId 对话id(后置剧情id) * @param dhId 对话id(后置剧情id)
* @returns * @returns
*/ */
export function getPlayData(userId:string, type:string, playId:string, dhId:string) { export async function getPlayData(userId:string, type:string, playId:string, dhId:string) {
let allClueJson = getJsonData("json/基础数据.json"); let allClueJson = await getUserJsonData("基础数据.json", userId);
let hireData = getJsonData("json/雇佣选择.json"); let hireData = await getUserJsonData("雇佣选择.json", userId);
let hireWorker = hireData; let hireWorker = hireData;
let duihua = playId; let duihua = playId;
if (playId == "S021" || playId == "S025") { if (playId == "S021" || playId == "S025") {
duihua = `${playId}_1`; duihua = `${playId}_1`;
if (allClueJson[userId]["酒馆剧情"] > HARITYPE.未开始) { if (allClueJson["酒馆剧情"] > HARITYPE.未开始) {
duihua = `${playId}_${allClueJson[userId]["酒馆剧情"]}`; duihua = `${playId}_${allClueJson["酒馆剧情"]}`;
} }
} }
/**获取玩家昵称 */ /**获取玩家昵称 */
let userData = getJsonData("json/用户.json"); let userData = await getJsonData("用户.json");
let name = ""; let name = "";
userData.forEach( info => { userData.forEach( info => {
if (info.userId == userId) { if (info.userId == userId) {
...@@ -47,7 +45,7 @@ export function getPlayData(userId:string, type:string, playId:string, dhId:stri ...@@ -47,7 +45,7 @@ export function getPlayData(userId:string, type:string, playId:string, dhId:stri
let playData = excelData[duihua].dataList; let playData = excelData[duihua].dataList;
let nextStory:any = {}; let nextStory:any = {};
playData.forEach( info => { playData.forEach( async info => {
let {dhid, dh, jqlx, hzjqid, glnpc, glxsid} = info; let {dhid, dh, jqlx, hzjqid, glnpc, glxsid} = info;
if (dhid == dhId) { if (dhid == dhId) {
...@@ -57,9 +55,9 @@ export function getPlayData(userId:string, type:string, playId:string, dhId:stri ...@@ -57,9 +55,9 @@ export function getPlayData(userId:string, type:string, playId:string, dhId:stri
if(nextStory.dhlx == "玩家") nextStory.glnpc = name; if(nextStory.dhlx == "玩家") nextStory.glnpc = name;
//记录当前走到的剧情 //记录当前走到的剧情
plotClues(userId, type, playId, dhId, glxsid); await plotClues(userId, type, playId, dhId, glxsid);
//剧情走完添加对应用户的对应线索数据 //剧情走完添加对应用户的对应线索数据
addAllClueByPlan(userId, glxsid); await addAllClueByPlan(userId, glxsid);
} }
}); });
...@@ -69,15 +67,12 @@ export function getPlayData(userId:string, type:string, playId:string, dhId:stri ...@@ -69,15 +67,12 @@ export function getPlayData(userId:string, type:string, playId:string, dhId:stri
nextStory.hzjqid = JSON.parse(nextStory.hzjqid); nextStory.hzjqid = JSON.parse(nextStory.hzjqid);
for (let i = 0; i < nextStory.hzjqid.length; i++ ) { for (let i = 0; i < nextStory.hzjqid.length; i++ ) {
let dhData = playData.find(s => s.dhid == nextStory.hzjqid[i]); let dhData = playData.find(s => s.dhid == nextStory.hzjqid[i]);
addAllClueByPlan(userId, dhData.glxsid); await addAllClueByPlan(userId, dhData.glxsid);
dhData["ispop"] = false; dhData["ispop"] = false;
if(dhData.jqlx == "工人" || dhData.jqlx == "画师" || dhData.jqlx == "掌柜") { if(dhData.jqlx == "工人" || dhData.jqlx == "画师" || dhData.jqlx == "掌柜") {
dhData.ispop = true; dhData.ispop = true;
} else if (dhData.jqlx == "运输") {
if (!hireWorker[userId]) hireWorker[userId] = {};
hireWorker[userId]["运输"] = dhData.glxsid;
changeJsonData("json/雇佣选择.json", hireWorker);
} }
if(dhData) dhStory.push(dhData); if(dhData) dhStory.push(dhData);
} }
nextStory.hzjq = dhStory; nextStory.hzjq = dhStory;
...@@ -85,102 +80,27 @@ export function getPlayData(userId:string, type:string, playId:string, dhId:stri ...@@ -85,102 +80,27 @@ export function getPlayData(userId:string, type:string, playId:string, dhId:stri
if(nextStory.dhlx == "玩家") nextStory.glnpc = name; if(nextStory.dhlx == "玩家") nextStory.glnpc = name;
} }
/**运输选择 */
if (nextStory.glnpc == "邢万里" && nextStory.hzjqid == "999") {
if (!hireWorker) hireWorker = {};
hireWorker["运输"] = nextStory.glxsid;
await changeUserJsonData("雇佣选择.json", userId, hireWorker);
}
if (nextStory.hzjqid == '999') { if (nextStory.hzjqid == '999') {
xfxxClue(); await xfxxClue(userId);
/**剧情完成可添加SWOT线索 */ /**剧情完成可添加SWOT线索 */
if (type == "码头") { if (type == "码头") {
allClueJson[userId]["SWOT"] = true; allClueJson["SWOT"] = true;
} else if (type == "酒馆") { } else if (type == "酒馆") {
allClueJson[userId]["酒馆剧情"] = HARITYPE.已选择; allClueJson["酒馆剧情"] = HARITYPE.已选择;
//酒馆剧情观看完毕、颜料瓷器已选择、SWOT已确认、工人已选择 //酒馆剧情观看完毕、颜料瓷器已选择、SWOT已确认、工人已选择、运输方式已选择
if(allClueJson[userId]["酒馆剧情"] == HARITYPE.已选择 && allClueJson[userId]["商行选择"]) allClueJson[userId]["ROI"] = true; if(allClueJson["酒馆剧情"] == HARITYPE.已选择 && allClueJson["商行选择"] && hireWorker["运输"]) allClueJson["ROI"] = true;
} }
//更新json数据 //更新json数据
changeJsonData("json/基础数据.json", allClueJson); await changeUserJsonData("基础数据.json", userId, allClueJson);
}
}
return nextStory;
}
/**
* 弃用
* 酒馆剧情
* @param type 酒馆
* @param playId SO12
* @param dhId 对话id(后置剧情id)
* @returns
*/
export function getJGPlayData(userId:string, type:string, playId:string, dhId:string) {
let allClueJson = getJsonData("json/基础数据.json");
/**获取玩家昵称 */
let userData = getJsonData("json/用户.json");
let name = "";
userData.forEach( info => {
if (info.userId == userId) {
if (info["name"]) name = info["name"]
else name = info.loginId;
}
})
let duihua = `${playId}_1`;
if (allClueJson[userId]["酒馆剧情"] > HARITYPE.未开始) {
duihua = `${playId}_${allClueJson[userId]["酒馆剧情"]}`;
}
/**剧情完成可添加ROI线索 */
let excelData = juqingTableData(type, duihua);
if (!excelData || Object.keys(excelData).length === 0) return successErrorResult("该NPC暂未开通剧情");
//剧情走完添加对应用户的对应线索数据
let playData = excelData[duihua].dataList;
let nextStory:any = {};
playData.forEach( info => {
let {dhid, dh, jqlx, hzjqid, glnpc, glxsid} = info;
if (dhid == dhId) {
//根据传入的id查找对应对话
nextStory = info;
nextStory["img"] = `${systemConfig.ipUrl}NPC/${glnpc}.png`;
if(nextStory.dhlx == "玩家") nextStory.glnpc = name;
//记录当前走到的剧情
plotClues(userId, type, duihua, dhId, glxsid);
//剧情走完添加对应用户的对应线索数据
addAllClueByPlan(userId, glxsid);
}
});
if (nextStory) {
let dhStory = [];
if(nextStory.jqlx == "选择") {
nextStory.hzjqid = JSON.parse(nextStory.hzjqid);
for (let i = 0; i < nextStory.hzjqid.length; i++ ) {
let dhData = playData.find(s => s.dhid == nextStory.hzjqid[i]);
dhData["ispop"] = false;
if(dhData.jqlx == "工人" || dhData.jqlx == "画师" || dhData.jqlx == "掌柜") {
dhData.ispop = true;
} }
if(dhData) dhStory.push(dhData);
}
nextStory.hzjq = dhStory;
nextStory.img = `${systemConfig.ipUrl}NPC/${nextStory.glnpc}.png`;
if(nextStory.dhlx == "玩家") nextStory.glnpc = name;
}
}
if (nextStory.hzjqid == '999') {
xfxxClue();
allClueJson[userId]["酒馆剧情"] = HARITYPE.已选择;
//酒馆剧情观看完毕、颜料瓷器已选择、SWOT已确认、工人已选择
if(allClueJson[userId]["酒馆剧情"] == HARITYPE.已选择 && allClueJson[userId]["商行选择"]) allClueJson[userId]["ROI"] = true;
//更新json数据
changeJsonData("json/基础数据.json", allClueJson);
} }
return nextStory; return nextStory;
...@@ -192,7 +112,7 @@ export function getJGPlayData(userId:string, type:string, playId:string, dhId:st ...@@ -192,7 +112,7 @@ export function getJGPlayData(userId:string, type:string, playId:string, dhId:st
* @param type * @param type
* @returns * @returns
*/ */
export function getNPCData(type) { export async function getNPCData(type) {
let excelData = NPCTableData(); let excelData = NPCTableData();
let npcData = excelData['NPC'].dataList; let npcData = excelData['NPC'].dataList;
...@@ -211,9 +131,9 @@ export function getNPCData(type) { ...@@ -211,9 +131,9 @@ export function getNPCData(type) {
/** /**
* 剧情相关线索 * 剧情相关线索
*/ */
export function plotClues(userId:string, type:string, playId:string, dhId:string, glxsid:string) { export async function plotClues(userId:string, type:string, playId:string, dhId:string, glxsid:string) {
//获取已有json数据 //获取已有json数据
let baseData = getJsonData("json/基础数据.json"); let baseData = await getUserJsonData("基础数据.json", userId);
let userData = {}; let userData = {};
if(Object.keys(baseData).length === 0) { //没有对应数据的情况 if(Object.keys(baseData).length === 0) { //没有对应数据的情况
...@@ -249,8 +169,7 @@ export function plotClues(userId:string, type:string, playId:string, dhId:string ...@@ -249,8 +169,7 @@ export function plotClues(userId:string, type:string, playId:string, dhId:string
} }
} }
} else { //已经有对应数据 } else { //已经有对应数据
userData = baseData[userId]; userData = baseData;
// userData["结算"] = baseData["1727399696222"]["结算"] + 50; //暂时一个剧情对话回合加50银两
if (!userData[type]) { if (!userData[type]) {
userData[type] = {}; userData[type] = {};
if(!userData[type][playId]) userData[type][playId] = {"当前对话id":"", "已获得的线索":[]}; if(!userData[type][playId]) userData[type][playId] = {"当前对话id":"", "已获得的线索":[]};
...@@ -294,12 +213,8 @@ export function plotClues(userId:string, type:string, playId:string, dhId:string ...@@ -294,12 +213,8 @@ export function plotClues(userId:string, type:string, playId:string, dhId:string
} }
} }
} }
let changeData = baseData;
changeData[userId] = userData
//更新json数据 //更新json数据
changeJsonData("json/基础数据.json", changeData); await changeUserJsonData("基础数据.json", userId, userData);
console.log("基础数据更新成功"); console.log("基础数据更新成功");
} }
...@@ -309,7 +224,7 @@ export function plotClues(userId:string, type:string, playId:string, dhId:string ...@@ -309,7 +224,7 @@ export function plotClues(userId:string, type:string, playId:string, dhId:string
* @param playType 剧情类型 * @param playType 剧情类型
* @returns * @returns
*/ */
export function pubHire(playType) { export async function pubHire(playType) {
let excelData = guyongTableData(); let excelData = guyongTableData();
let hireData = excelData['雇佣表'].dataList; let hireData = excelData['雇佣表'].dataList;
...@@ -334,17 +249,17 @@ export function pubHire(playType) { ...@@ -334,17 +249,17 @@ export function pubHire(playType) {
* @param playType 剧情类型 * @param playType 剧情类型
* @param xsId 线索id * @param xsId 线索id
*/ */
export function submitHire(userId, playType, xsId) { export async function submitHire(userId, playType, xsId) {
//获取已有json数据 //获取已有json数据
let hireData = getJsonData("json/雇佣选择.json"); let hireData = await getUserJsonData("雇佣选择.json", userId);
let hireWorker = hireData; let hireWorker = hireData;
let oldxsid = ""; let oldxsid = "";
if (!hireWorker[userId]) hireWorker[userId] = {}; if (!hireWorker) hireWorker = {};
if (!hireWorker[userId]["人工"]) hireWorker[userId]["人工"] = {}; if (!hireWorker["人工"]) hireWorker["人工"] = {};
else oldxsid = hireWorker[userId]["人工"][playType]; else oldxsid = hireWorker["人工"][playType];
hireWorker[userId]["人工"][playType] = xsId; hireWorker["人工"][playType] = xsId;
changeJsonData("json/雇佣选择.json", hireWorker); await changeUserJsonData("雇佣选择.json", userId, hireWorker);
console.log(`雇佣${playType}添加成功,线索id${xsId}`); console.log(`雇佣${playType}添加成功,线索id${xsId}`);
/**雇佣工人成功,扣除工资部分 */ /**雇佣工人成功,扣除工资部分 */
...@@ -357,22 +272,22 @@ export function submitHire(userId, playType, xsId) { ...@@ -357,22 +272,22 @@ export function submitHire(userId, playType, xsId) {
if (info.xsid == oldxsid) oldgz = parseInt(info.gz); if (info.xsid == oldxsid) oldgz = parseInt(info.gz);
}); });
//扣除雇佣工人工资 //扣除雇佣工人工资
let baseData = getJsonData("json/基础数据.json"); let baseData = await getUserJsonData("基础数据.json", userId);
let jisuan = baseData[userId]["结算"] || 0; let jisuan = baseData["结算"] || 0;
baseData[userId]["结算"] = jisuan + oldgz - hireMoney; baseData["结算"] = jisuan + oldgz - hireMoney;
changeJsonData("json/基础数据.json", baseData); await changeUserJsonData("基础数据.json", userId, baseData);
return successResult(); return successResult();
} }
/**回显雇佣工人 */ /**回显雇佣工人 */
export function displayHire(userId) { export async function displayHire(userId) {
//获取已有json数据 //获取已有json数据
let hireData = getJsonData("json/雇佣选择.json"); let hireData = await getUserJsonData("雇佣选择.json", userId);
let hireWorker = {}; let hireWorker = {};
if (!hireData[userId] || Object.keys(hireData[userId]).length === 0) hireData[userId] = {"人工":{"工人": "", "画师": "", "掌柜": ""}}; if (!hireData || Object.keys(hireData).length === 0) hireData = {"人工":{"工人": "", "画师": "", "掌柜": ""}};
hireWorker = hireData[userId]["人工"]; hireWorker = hireData["人工"];
return hireWorker; return hireWorker;
} }
...@@ -383,7 +298,7 @@ export function displayHire(userId) { ...@@ -383,7 +298,7 @@ export function displayHire(userId) {
* @param type 类型 * @param type 类型
* @returns * @returns
*/ */
export function rawMaterial(type) { export async function rawMaterial(type) {
let excelData = guyongTableData(); let excelData = guyongTableData();
let rawMaterialData = excelData['原材料'].dataList; let rawMaterialData = excelData['原材料'].dataList;
...@@ -407,21 +322,21 @@ export function rawMaterial(type) { ...@@ -407,21 +322,21 @@ export function rawMaterial(type) {
* @param type 剧情类型 * @param type 剧情类型
* @param xsId 线索id * @param xsId 线索id
*/ */
export function submitRawMaterial(userId, type, xsId) { export async function submitRawMaterial(userId, type, xsId) {
//获取已有json数据 //获取已有json数据
let rawMaterialData = getJsonData("json/雇佣选择.json"); let rawMaterialData = await getUserJsonData("雇佣选择.json", userId);
let rawMaterial = rawMaterialData; let rawMaterial = rawMaterialData;
let oldxsid = ""; let oldxsid = "";
if (!rawMaterial[userId]) rawMaterial[userId] = {}; if (!rawMaterial) rawMaterial = {};
if (!rawMaterial[userId]["原材料"]) rawMaterial[userId]["原材料"] = {}; if (!rawMaterial["原材料"]) rawMaterial["原材料"] = {};
else oldxsid = rawMaterial[userId]["原材料"][type]; else oldxsid = rawMaterial["原材料"][type];
rawMaterial[userId]["原材料"][type] = xsId; rawMaterial["原材料"][type] = xsId;
//运输类型默认水路 todo //运输类型默认水路 todo
rawMaterial[userId]["运输"] = "C037"; // rawMaterial["运输"] = "C037";
changeJsonData("json/雇佣选择.json", rawMaterial); await changeUserJsonData("雇佣选择.json", userId, rawMaterial);
console.log(`选择${type}添加成功,线索id${xsId}`); console.log(`选择${type}添加成功,线索id${xsId}`);
/**购买原材料成功,扣除原材料价格 */ /**购买原材料成功,扣除原材料价格 */
...@@ -435,14 +350,14 @@ export function submitRawMaterial(userId, type, xsId) { ...@@ -435,14 +350,14 @@ export function submitRawMaterial(userId, type, xsId) {
}); });
//扣除100个瓷器和颜料的价格 todo //扣除100个瓷器和颜料的价格 todo
let baseData = getJsonData("json/基础数据.json"); let baseData = await getUserJsonData("基础数据.json", userId);
let jsje = baseData[userId]["结算"] || 0; let jsje = baseData["结算"] || 0;
baseData[userId]["结算"] = jsje + oldgz*1000 - rawMaterialMoney*1000; baseData["结算"] = jsje + oldgz*1000 - rawMaterialMoney*1000;
baseData[userId]["商行选择"] = true; baseData["商行选择"] = true;
//酒馆剧情观看完毕、颜料瓷器已选择、SWOT已确认、工人已选择 //酒馆剧情观看完毕、颜料瓷器已选择、SWOT已确认、工人已选择
if(baseData[userId]["酒馆剧情"] == HARITYPE.已选择 && baseData[userId]["商行选择"]) baseData[userId]["ROI"] = true; if(baseData["酒馆剧情"] == HARITYPE.已选择 && baseData["商行选择"]) baseData["ROI"] = true;
changeJsonData("json/基础数据.json", baseData); await changeUserJsonData("基础数据.json", userId, baseData);
return successResult(); return successResult();
} }
...@@ -453,12 +368,12 @@ export function submitRawMaterial(userId, type, xsId) { ...@@ -453,12 +368,12 @@ export function submitRawMaterial(userId, type, xsId) {
* @param userId * @param userId
* @returns * @returns
*/ */
export function displayRawMaterial(userId) { export async function displayRawMaterial(userId) {
//获取已有json数据 //获取已有json数据
let hireData = getJsonData("json/雇佣选择.json"); let hireData = await getUserJsonData("雇佣选择.json", userId);
let hireWorker = {}; let hireWorker = {};
if (!hireData[userId] || Object.keys(hireData[userId]).length === 0) hireData[userId] = {"原材料":{"瓷器":"", "颜料":""}}; if (!hireData || Object.keys(hireData).length === 0) hireData = {"原材料":{"瓷器":"", "颜料":""}};
hireWorker = hireData[userId]["原材料"]; hireWorker = hireData["原材料"];
return hireWorker; return hireWorker;
} }
...@@ -468,14 +383,14 @@ export function displayRawMaterial(userId) { ...@@ -468,14 +383,14 @@ export function displayRawMaterial(userId) {
* 广州府是否第一次阅读 * 广州府是否第一次阅读
* @param userId * @param userId
*/ */
export function getGzf(userId) { export async function getGzf(userId) {
//获取已有json数据 //获取已有json数据
let baseJsonData = getJsonData("json/基础数据.json"); let baseJsonData = await getUserJsonData("基础数据.json", userId);
let firstGzf = baseJsonData[userId]["广州府介绍"]; let firstGzf = baseJsonData["广州府介绍"];
let writeBaseAll = baseJsonData; let writeBaseAll = baseJsonData;
writeBaseAll[userId]["广州府介绍"] = false; writeBaseAll["广州府介绍"] = false;
changeJsonData("json/基础数据.json", writeBaseAll); await changeUserJsonData("基础数据.json", userId, writeBaseAll);
return {firstGzf}; return {firstGzf};
} }
...@@ -485,37 +400,36 @@ export function getGzf(userId) { ...@@ -485,37 +400,36 @@ export function getGzf(userId) {
* 广州府介绍 * 广州府介绍
* @param userId * @param userId
*/ */
export function getIntroduceGzf(userId) { export async function getIntroduceGzf(userId) {
//获取已有json数据 //获取已有json数据
let baseJsonData = getJsonData("json/广州府介绍.json"); let baseJsonData = await getJsonData("广州府介绍.json");
//获取已有json数据 //获取已有json数据
let baseData = getJsonData("json/全部线索.json"); let baseData = await getUserJsonData("全部线索.json", userId);
/**获取表格数据 */ /**获取表格数据 */
let excelData = xiansuoTableData(); let excelData = xiansuoTableData();
let clueExcelData = excelData["线索表"].dataList; let clueExcelData = excelData["线索表"].dataList;
let userData = baseData; let userData = baseData;
if(Object.keys(baseData).length === 0) { //没有对应数据的情况 //没有对应数据的情况
userData[userId] = {}; if(!baseData || Object.keys(baseData).length === 0) userData = {};
}
clueExcelData.forEach( info => { clueExcelData.forEach( info => {
let {xsid, xsnr, xslx, xslxxf, dhgl, sfbx} = info; let {xsid, xsnr, xslx, xslxxf, dhgl, sfbx} = info;
if (!userData[userId]) userData[userId] = {}; if (!userData) userData = {};
if (!userData[userId][xslx]) userData[userId][xslx] = []; if (!userData[xslx]) userData[xslx] = [];
//匹配线索id //匹配线索id
if (dhgl == "开篇1" || dhgl == "开篇2") { if (dhgl == "开篇1" || dhgl == "开篇2") {
//检查数组中是否已经有对象的xsid等于当前xsid //检查数组中是否已经有对象的xsid等于当前xsid
let exists = userData[userId][xslx].find(s => s.xsid == xsid); let exists = userData[xslx].find(s => s.xsid == xsid);
//如果不存在,则添加该线索 //如果不存在,则添加该线索
if (!exists) { if (!exists) {
userData[userId][xslx].push({xsid, xsnr, isChoice:false, sfbx}); userData[xslx].push({xsid, xsnr, isChoice:false, sfbx});
} }
} }
}) })
changeJsonData("json/全部线索.json", userData); await changeUserJsonData("全部线索.json", userId, userData);
console.log("已添加全部线索"); console.log("已添加全部线索");
return baseJsonData; return baseJsonData;
...@@ -526,11 +440,11 @@ export function getIntroduceGzf(userId) { ...@@ -526,11 +440,11 @@ export function getIntroduceGzf(userId) {
* 是否能进入酒馆剧情 * 是否能进入酒馆剧情
* @param userId * @param userId
*/ */
export function firstPubHire(userId) { export async function firstPubHire(userId) {
let baseJsonData = getJsonData("json/基础数据.json"); let baseJsonData = await getUserJsonData("基础数据.json", userId);
let isEnabled = false; let isEnabled = false;
/**判断是否确认SWOT线索 */ /**判断是否确认SWOT线索 */
if (baseJsonData[userId]["酒馆剧情"] > HARITYPE.未开始) isEnabled = true; if (baseJsonData["酒馆剧情"] > HARITYPE.未开始) isEnabled = true;
return {isEnabled}; return {isEnabled};
} }
...@@ -541,18 +455,17 @@ export function firstPubHire(userId) { ...@@ -541,18 +455,17 @@ export function firstPubHire(userId) {
* @param userId * @param userId
* @param glxsid * @param glxsid
*/ */
export function addAllClueByPlan(userId, glxsid) { export async function addAllClueByPlan(userId, glxsid) {
//获取已有json数据 //获取已有json数据
let baseData = getJsonData("json/全部线索.json"); let baseData = await getUserJsonData("全部线索.json", userId);
/**获取表格数据 */ /**获取表格数据 */
let excelData = xiansuoTableData(); let excelData = xiansuoTableData();
let clueExcelData = excelData["线索表"].dataList; let clueExcelData = excelData["线索表"].dataList;
let userData = baseData; let userData = baseData;
if(Object.keys(baseData).length === 0) { //没有对应数据的情况 //没有对应数据的情况
userData[userId] = {}; if(Object.keys(baseData).length === 0) userData = {};
}
/**关联的线索 */ /**关联的线索 */
if (glxsid) { if (glxsid) {
let fruitsEmpty; let fruitsEmpty;
...@@ -564,10 +477,10 @@ export function addAllClueByPlan(userId, glxsid) { ...@@ -564,10 +477,10 @@ export function addAllClueByPlan(userId, glxsid) {
} }
let distinctMap = {};//用于去重线索的map let distinctMap = {};//用于去重线索的map
if (!userData[userId]) userData[userId] = {}; if (!userData) userData = {};
for (let xslx in userData[userId]) { for (let xslx in userData) {
distinctMap[xslx] = {}; distinctMap[xslx] = {};
userData[userId][xslx].forEach(info => { userData[xslx].forEach(info => {
let {xsid} = info; let {xsid} = info;
distinctMap[xslx][xsid] = info; distinctMap[xslx][xsid] = info;
}); });
...@@ -579,17 +492,16 @@ export function addAllClueByPlan(userId, glxsid) { ...@@ -579,17 +492,16 @@ export function addAllClueByPlan(userId, glxsid) {
//命中 //命中
if (distinctMap[xslx][xsid]) return; if (distinctMap[xslx][xsid]) return;
//去重之后的并且需要添加到用户里面的 //去重之后的并且需要添加
if (!userData[userId]) userData[userId] = {}; if (!userData[xslx]) userData[xslx] = [];
if (!userData[userId][xslx]) userData[userId][xslx] = []; userData[info.xslx].push({xsid, xsnr, isChoice:false, sfbx});
userData[userId][info.xslx].push({xsid, xsnr, isChoice:false, sfbx});
} }
}); });
} }
changeJsonData("json/全部线索.json", userData); await changeUserJsonData("全部线索.json", userId, userData);
console.log("已添加全部线索"); console.log("已添加全部线索");
} }
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
import { NOWCLUE } from "../config/enum"; import { NOWCLUE } from "../config/enum";
import { guyongTableData } from "../data/table/tableData"; import { guyongTableData } from "../data/table/tableData";
import { successResult } from "../tools/systemTools"; import { successResult } from "../tools/systemTools";
import { changeJsonData, getJsonData } from "../util/tools"; import { changeUserJsonData, getJsonData, getUserJsonData } from "../util/tools";
/** /**
...@@ -18,15 +18,15 @@ import { changeJsonData, getJsonData } from "../util/tools"; ...@@ -18,15 +18,15 @@ import { changeJsonData, getJsonData } from "../util/tools";
* @param subdivide 细分线索类型【R、O、I】 * @param subdivide 细分线索类型【R、O、I】
* @param xs [{xsid:"", xsnr:""}, ...] * @param xs [{xsid:"", xsnr:""}, ...]
*/ */
export function submitROIClue(userId, subdivide, xs) { export async function submitROIClue(userId, subdivide, xs) {
let jsonData = getJsonData("json/ROI.json"); let jsonData = await getUserJsonData("ROI.json", userId);
let baseClueJson = getJsonData("json/基础数据.json"); let baseClueJson = await getUserJsonData("基础数据.json", userId);
/**处理确认选择的线索 */ /**处理确认选择的线索 */
let ROIClueData = jsonData; let ROIClueData = jsonData;
//没有对应用户数据先添加一个基础格式,有的话直接push //没有对应用户数据先添加一个基础格式,有的话直接push
if (!ROIClueData[userId] || Object.keys(ROIClueData[userId]).length === 0) { if (!ROIClueData || Object.keys(ROIClueData).length === 0) {
ROIClueData[userId] = { ROIClueData = {
"isSubmit": false, "isSubmit": false,
"R": [], "R": [],
"I": [] "I": []
...@@ -35,25 +35,25 @@ import { changeJsonData, getJsonData } from "../util/tools"; ...@@ -35,25 +35,25 @@ import { changeJsonData, getJsonData } from "../util/tools";
//isSubmit:false【未提交】、true【提交】 //isSubmit:false【未提交】、true【提交】
/**当前线索类型未提交时,可以修改添加线索 */ /**当前线索类型未提交时,可以修改添加线索 */
if (!ROIClueData[userId]["isSubmit"]) { if (!ROIClueData["isSubmit"]) {
for (let i = 0; i < xs.length; i++) { for (let i = 0; i < xs.length; i++) {
// let xsInfo = xs[i]; // let xsInfo = xs[i];
ROIClueData[userId][subdivide].push(xs[i]); ROIClueData[subdivide].push(xs[i]);
} }
changeJsonData("json/ROI.json", ROIClueData); await changeUserJsonData("ROI.json", userId, ROIClueData);
console.log("添加ROI线索成功"); console.log("添加ROI线索成功");
} else { } else {
console.log("线索已提交,无法重复提交"); console.log("线索已提交,无法重复提交");
} }
/**修改全部线索.json的对应线索为已选择 isChoice:true */ /**修改全部线索.json的对应线索为已选择 isChoice:true */
let allClueJson = getJsonData("json/全部线索.json"); let allClueJson = await getUserJsonData("全部线索.json", userId);
let allClueData = allClueJson; let allClueData = allClueJson;
xs.forEach( info => { xs.forEach( info => {
let {xsid, xsnr} = info; let {xsid, xsnr} = info;
for(let key in allClueData[userId]) { for(let key in allClueData) {
allClueData[userId][key].forEach( thisClue => { allClueData[key].forEach( thisClue => {
if(xsid == thisClue.xsid) thisClue.isChoice = true; if(xsid == thisClue.xsid) thisClue.isChoice = true;
}) })
} }
...@@ -69,19 +69,19 @@ import { changeJsonData, getJsonData } from "../util/tools"; ...@@ -69,19 +69,19 @@ import { changeJsonData, getJsonData } from "../util/tools";
if (info.xsid == xsid) ciqiMoney = info.sj; if (info.xsid == xsid) ciqiMoney = info.sj;
}); });
//加上定制瓷器金额 //加上定制瓷器金额
baseClueJson[userId]["结算"] = baseClueJson[userId]["结算"] + ciqiMoney * 1000; baseClueJson["结算"] = baseClueJson["结算"] + ciqiMoney * 1000;
} }
}); });
changeJsonData("json/全部线索.json", allClueData); await changeUserJsonData("全部线索.json", userId, allClueData);
/**ROI线索选择完成可添加竞合线索 */ /**ROI线索选择完成可添加竞合线索 */
baseClueJson[userId]["竞合"] = true; baseClueJson["竞合"] = true;
baseClueJson[userId]["当前线索确认"] = NOWCLUE.ROI; baseClueJson["当前线索确认"] = NOWCLUE.ROI;
//更新json数据 //更新json数据
changeJsonData("json/基础数据.json", baseClueJson); await changeUserJsonData("基础数据.json", userId, baseClueJson);
return successResult(); return successResult();
} }
...@@ -91,10 +91,10 @@ import { changeJsonData, getJsonData } from "../util/tools"; ...@@ -91,10 +91,10 @@ import { changeJsonData, getJsonData } from "../util/tools";
* 计算选择正确的ROI线索 * 计算选择正确的ROI线索
* @param userId * @param userId
*/ */
export function checkROI(userId) { export async function checkROI(userId) {
let gygrJson = getJsonData("json/雇佣选择.json"); //获取雇佣工人表 let gygrJson = await getUserJsonData("雇佣选择.json", userId); //获取雇佣工人表
let 雇佣选择 = gygrJson[userId]; let 雇佣选择 = gygrJson;
let cqzzJson = getJsonData("json/瓷器制造.json"); let cqzzJson = await getJsonData("瓷器制造.json");
/** /**
* 计算工人、画师、掌柜一起的人员成本 * 计算工人、画师、掌柜一起的人员成本
...@@ -127,7 +127,8 @@ export function checkROI(userId) { ...@@ -127,7 +127,8 @@ export function checkROI(userId) {
* 计算运输成本 * 计算运输成本
*/ */
let 运输成本 = cqzzJson["运输成本"]; let 运输成本 = cqzzJson["运输成本"];
let yscb = 运输成本[雇佣选择["运输"]].xjb; let yscb = 0;
if (运输成本[雇佣选择["运输"]].xjb) yscb = 运输成本[雇佣选择["运输"]].xjb;
let 净利润 = (瓷器利润-rycb-yscb)/瓷器单价; let 净利润 = (瓷器利润-rycb-yscb)/瓷器单价;
...@@ -138,10 +139,10 @@ export function checkROI(userId) { ...@@ -138,10 +139,10 @@ export function checkROI(userId) {
if (净利润>20 && 净利润<25) score = 10; if (净利润>20 && 净利润<25) score = 10;
if (净利润<20) score = 0; if (净利润<20) score = 0;
let submitJsonData = getJsonData("json/提交分数.json"); let submitJsonData = await getUserJsonData("提交分数.json", userId);
let submitScore = submitJsonData; let submitScore = submitJsonData;
submitScore[userId]["ROI"] = score; submitScore["ROI"] = score;
changeJsonData("json/提交分数.json", submitScore); await changeUserJsonData("提交分数.json", userId, submitScore);
return successResult(); return successResult();
} }
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
import { HARITYPE, NOWCLUE } from "../config/enum"; import { HARITYPE, NOWCLUE } from "../config/enum";
import { successResult } from "../tools/systemTools"; import { successResult } from "../tools/systemTools";
import { changeJsonData, getJsonData } from "../util/tools"; import { changeUserJsonData, getUserJsonData } from "../util/tools";
/** /**
...@@ -17,14 +17,14 @@ import { changeJsonData, getJsonData } from "../util/tools"; ...@@ -17,14 +17,14 @@ import { changeJsonData, getJsonData } from "../util/tools";
* @param subdivide 细分线索类型【S、W、O、T】 * @param subdivide 细分线索类型【S、W、O、T】
* @param xs [{xsid:"", xsnr:""}, ...] * @param xs [{xsid:"", xsnr:""}, ...]
*/ */
export function submitSWOTClue(userId, subdivide, xs) { export async function submitSWOTClue(userId, subdivide, xs) {
let jsonData = getJsonData("json/SWOT.json"); let jsonData = await getUserJsonData("SWOT.json", userId);
/**处理确认选择的线索 */ /**处理确认选择的线索 */
let SWOTClueData = jsonData; let SWOTClueData = jsonData;
//没有对应用户数据先添加一个基础格式,有的话直接push //没有对应用户数据先添加一个基础格式,有的话直接push
if (!SWOTClueData[userId] || Object.keys(SWOTClueData[userId]).length === 0) { if (!SWOTClueData || Object.keys(SWOTClueData).length === 0) {
SWOTClueData[userId] = { SWOTClueData = {
"isSubmit": false, "isSubmit": false,
"S": [], "S": [],
"W": [], "W": [],
...@@ -35,36 +35,36 @@ import { changeJsonData, getJsonData } from "../util/tools"; ...@@ -35,36 +35,36 @@ import { changeJsonData, getJsonData } from "../util/tools";
//isSubmit:false【未提交】、true【提交】 //isSubmit:false【未提交】、true【提交】
/**当前线索类型未提交时,可以修改添加线索 */ /**当前线索类型未提交时,可以修改添加线索 */
if (!SWOTClueData[userId]["isSubmit"]) { if (!SWOTClueData["isSubmit"]) {
for (let i = 0; i < xs.length; i++) { for (let i = 0; i < xs.length; i++) {
// let xsInfo = xs[i]; // let xsInfo = xs[i];
SWOTClueData[userId][subdivide].push(xs[i]); SWOTClueData[subdivide].push(xs[i]);
} }
changeJsonData("json/SWOT.json", SWOTClueData); await changeUserJsonData("SWOT.json", userId, SWOTClueData);
console.log("添加SWOT线索成功"); console.log("添加SWOT线索成功");
} else { } else {
console.log("线索已提交,无法重复提交"); console.log("线索已提交,无法重复提交");
} }
/**修改全部线索.json的对应线索为已选择 isChoice:true */ /**修改全部线索.json的对应线索为已选择 isChoice:true */
let allClueJson = getJsonData("json/全部线索.json"); let allClueJson = await getUserJsonData("全部线索.json", userId);
let allClueData = allClueJson; let allClueData = allClueJson;
xs.forEach( info => { xs.forEach( info => {
let {xsid, xsnr} = info; let {xsid, xsnr} = info;
for(let key in allClueData[userId]) { for(let key in allClueData) {
allClueData[userId][key].forEach( thisClue => { allClueData[key].forEach( thisClue => {
if(xsid == thisClue.xsid) thisClue.isChoice = true; if(xsid == thisClue.xsid) thisClue.isChoice = true;
}) })
} }
}); });
changeJsonData("json/全部线索.json", allClueData); await changeUserJsonData("全部线索.json", userId, allClueData);
let baseJsonData = getJsonData("json/基础数据.json"); let baseJsonData = await getUserJsonData("基础数据.json", userId);
baseJsonData[userId]["当前线索确认"] = NOWCLUE.SWOT; baseJsonData["当前线索确认"] = NOWCLUE.SWOT;
if (baseJsonData[userId]["酒馆剧情"] < HARITYPE.已开始) baseJsonData[userId]["酒馆剧情"] = HARITYPE.已开始; if (baseJsonData["酒馆剧情"] < HARITYPE.已开始) baseJsonData["酒馆剧情"] = HARITYPE.已开始;
changeJsonData("json/基础数据.json", baseJsonData); await changeUserJsonData("基础数据.json", userId, baseJsonData);
return successResult(); return successResult();
} }
...@@ -74,10 +74,10 @@ import { changeJsonData, getJsonData } from "../util/tools"; ...@@ -74,10 +74,10 @@ import { changeJsonData, getJsonData } from "../util/tools";
* 计算选择正确的SWOT线索 * 计算选择正确的SWOT线索
* @param userId * @param userId
*/ */
export function checkSWOT(userId) { export async function checkSWOT(userId) {
/**获取细分线索 */ /**获取细分线索 */
let xfclueJson = getJsonData("json/细分线索.json"); let xfclueJson = await getUserJsonData("细分线索.json", userId);
let clueJson = getJsonData("json/SWOT.json")[userId]; let clueJson = await getUserJsonData("SWOT.json", userId);
let sumClue = 0; //线索总数 let sumClue = 0; //线索总数
let rightClue = 0; //选对线索数 let rightClue = 0; //选对线索数
...@@ -100,10 +100,10 @@ export function checkSWOT(userId) { ...@@ -100,10 +100,10 @@ export function checkSWOT(userId) {
let score = 0; let score = 0;
// score = rightClue/sumClue*(1/4)*50; // score = rightClue/sumClue*(1/4)*50;
score = (rightClue/sumClue)*50; score = (rightClue/sumClue)*50;
let submitJsonData = getJsonData("json/提交分数.json"); let submitJsonData = await getUserJsonData("提交分数.json", userId);
let submitScore = submitJsonData; let submitScore = submitJsonData;
submitScore[userId]["SWOT"] = score; submitScore["SWOT"] = score;
changeJsonData("json/提交分数.json", submitScore); await changeUserJsonData("提交分数.json", userId, submitScore);
return successResult(); return successResult();
} }
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
import { HARITYPE, NOWCLUE } from "../config/enum"; import { HARITYPE, NOWCLUE } from "../config/enum";
import { guyongTableData, xiansuoTableData } from "../data/table/tableData"; import { guyongTableData, xiansuoTableData } from "../data/table/tableData";
import { changeJsonData, getJsonData } from "../util/tools"; import { addJson, changeJsonData, changeUserJsonData, getJsonData, getUserJsonData } from "../util/tools";
/** /**
...@@ -12,36 +12,30 @@ import { changeJsonData, getJsonData } from "../util/tools"; ...@@ -12,36 +12,30 @@ import { changeJsonData, getJsonData } from "../util/tools";
* 基础数据没有的话也写入 * 基础数据没有的话也写入
* todo线索改为剧情走过才添加 * todo线索改为剧情走过才添加
*/ */
export function initAllClue(userId) { export async function initAllClue(userId) {
let excelData = xiansuoTableData(); let baseJsonData = await getUserJsonData("基础数据.json", userId);
let clueExcelData = excelData["线索表"].dataList; let submitJsonData = await getUserJsonData("提交分数.json", userId);
let userJsonData = getJsonData("json/用户.json");
let allClueJsonData = getJsonData("json/全部线索.json");
let baseJsonData = getJsonData("json/基础数据.json");
let submitJsonData = getJsonData("json/提交分数.json");
let writeClueAll = allClueJsonData;
let writeBaseAll = baseJsonData; let writeBaseAll = baseJsonData;
let submitClue = submitJsonData; let submitClue = submitJsonData;
/**如果登录的账号没有全部线索数据,则写入json /**如果登录的账号没有全部线索数据,则写入json
* 弃用,改为走过相关剧情添加对应线索 * 弃用,改为走过相关剧情添加对应线索
*/ */
// if (!allClueJsonData[userId] || Object.keys(allClueJsonData[userId]).length === 0) { // if (!allClueJsonData || Object.keys(allClueJsonData).length === 0) {
// writeClueAll[userId] = {}; // writeClueAll = {};
// clueExcelData.forEach( info => { // clueExcelData.forEach( info => {
// let {xsid, xsnr, xslx, xslxxf, sfbx} = info; // let {xsid, xsnr, xslx, xslxxf, sfbx} = info;
// if (!writeClueAll[userId][xslx]) writeClueAll[userId][xslx] = []; // if (!writeClueAll[xslx]) writeClueAll[xslx] = [];
// writeClueAll[userId][xslx].push({xsid, xsnr, isChoice:false, sfbx}); // writeClueAll[xslx].push({xsid, xsnr, isChoice:false, sfbx});
// }) // })
// //写入json // //写入json
// changeJsonData("json/全部线索.json", writeClueAll); // await changeUserJsonData("全部线索.json", userId, writeClueAll);
// } // }
/**如果登录的账号没有基础数据,则写入json */ /**如果登录的账号没有基础数据,则写入json */
if (!baseJsonData[userId] || Object.keys(baseJsonData[userId]).length === 0) { if (!baseJsonData || Object.keys(baseJsonData).length === 0) {
writeBaseAll[userId] = { writeBaseAll = {
"初始资金": 500, "初始资金": 500,
"天数":0, "天数":0,
"结算":500, "结算":500,
...@@ -55,17 +49,17 @@ export function initAllClue(userId) { ...@@ -55,17 +49,17 @@ export function initAllClue(userId) {
"竞合": false "竞合": false
} }
//写入json //写入json
changeJsonData("json/基础数据.json", writeBaseAll); await changeUserJsonData("基础数据.json", userId, writeBaseAll);
} }
/**如果登录的账号没有初始化分数数据,则写入json */ /**如果登录的账号没有初始化分数数据,则写入json */
if (!submitJsonData[userId] || Object.keys(submitJsonData[userId]).length === 0) { if (!submitJsonData || Object.keys(submitJsonData).length === 0) {
submitClue[userId] = { submitClue = {
SWOT:0, SWOT:0,
ROI:0, ROI:0,
竞合:0 竞合:0
}; };
//写入json //写入json
changeJsonData("json/提交分数.json", submitClue); await changeUserJsonData("提交分数.json", userId, submitClue);
} }
} }
...@@ -73,7 +67,7 @@ export function initAllClue(userId) { ...@@ -73,7 +67,7 @@ export function initAllClue(userId) {
/** /**
* 初始化制作瓷器成本数据 * 初始化制作瓷器成本数据
*/ */
export function initCiqi() { export async function initCiqi() {
let excelData = guyongTableData(); let excelData = guyongTableData();
let 雇佣Data = excelData['雇佣表'].dataList; let 雇佣Data = excelData['雇佣表'].dataList;
let 运输Data = excelData['运输'].dataList; let 运输Data = excelData['运输'].dataList;
...@@ -133,7 +127,7 @@ export function initCiqi() { ...@@ -133,7 +127,7 @@ export function initCiqi() {
let 成本 = {瓷器, 人员成本, 运输成本} let 成本 = {瓷器, 人员成本, 运输成本}
changeJsonData("json/瓷器制造.json", 成本); await changeJsonData("瓷器制造.json", 成本);
} }
...@@ -142,16 +136,16 @@ export function initCiqi() { ...@@ -142,16 +136,16 @@ export function initCiqi() {
* 登录开始计算 30分钟加一天 * 登录开始计算 30分钟加一天
* @param userId * @param userId
*/ */
export function gameLoop(userId) { export async function gameLoop(userId) {
let baseJsonData = getJsonData("json/基础数据.json"); let baseJsonData = await getUserJsonData("基础数据.json", userId);
// let baseData = baseJsonData[userId]; // let baseData = baseJsonData;
baseJsonData[userId]["天数"]++; if (baseJsonData) baseJsonData["天数"]++;
//60000毫秒 = 1分钟,设定30分钟游戏内天数+1 //60000毫秒 = 1分钟,设定30分钟游戏内天数+1
setTimeout(gameLoop, 60000*30, userId); setTimeout(await gameLoop, 60000*30, userId);
changeJsonData("json/基础数据.json", baseJsonData); await changeUserJsonData("基础数据.json", userId, baseJsonData);
} }
......
...@@ -7,7 +7,7 @@ import { ERRORENUM } from "../config/errorEnum"; ...@@ -7,7 +7,7 @@ import { ERRORENUM } from "../config/errorEnum";
import { xiansuoTableData } from "../data/table/tableData"; import { xiansuoTableData } from "../data/table/tableData";
import { successErrorResult, successResult } from "../tools/systemTools"; import { successErrorResult, successResult } from "../tools/systemTools";
import { BizError } from "../util/bizError"; import { BizError } from "../util/bizError";
import { changeJsonData, getJsonData } from "../util/tools"; import { changeUserJsonData, getUserJsonData, getJsonData, changeJsonData, addJson } from "../util/tools";
import { gameLoop, initAllClue } from "./task"; import { gameLoop, initAllClue } from "./task";
let fs = require('fs'); let fs = require('fs');
let path = require('path'); let path = require('path');
...@@ -17,26 +17,26 @@ let path = require('path'); ...@@ -17,26 +17,26 @@ let path = require('path');
* @param loginId 账号 * @param loginId 账号
* @param pwd 密码 * @param pwd 密码
*/ */
export function login(loginId, pwd) { export async function login(loginId, pwd) {
let userData = getJsonData("json/用户.json"); let userData = await getJsonData("用户.json");
let dataInfo = {}; let dataInfo = {};
/**判断是否有对应账号 */ /**判断是否有对应账号 */
let hasUser = userData.some(item => item.loginId === loginId); let hasUser = userData.some(item => item.loginId === loginId);
if (!hasUser) throw new BizError(ERRORENUM.账号不存在); if (!hasUser) throw new BizError(ERRORENUM.账号不存在);
let firstLogin = false; let firstLogin = false;
userData.forEach( info => { for (let i = 0; i < userData.length; i++) {
initAllClue(info.userId); let info = userData[i];
if (info.loginId == loginId) { if (info.loginId == loginId) {
await addJson(info.userId);
if (info.pwd != pwd) throw new BizError(ERRORENUM.账号或密码错误); if (info.pwd != pwd) throw new BizError(ERRORENUM.账号或密码错误);
await initAllClue(info.userId);
if (!info.name) firstLogin = true; if (!info.name) firstLogin = true;
dataInfo = {userId:info.userId, loginId:info.loginId, firstLogin}; dataInfo = {userId:info.userId, loginId:info.loginId, firstLogin};
gameLoop(info.userId); await gameLoop(info.userId);
}
} }
// dataInfo["firstlogin"] = initAllClue(info.userId);
})
return dataInfo; return dataInfo;
} }
...@@ -47,8 +47,8 @@ export function login(loginId, pwd) { ...@@ -47,8 +47,8 @@ export function login(loginId, pwd) {
* @param loginId 账号 * @param loginId 账号
* @param pwd 密码 * @param pwd 密码
*/ */
export function register(loginId, pwd) { export async function register(loginId, pwd) {
let userData = getJsonData("json/用户.json"); let userData = await getJsonData("用户.json");
const NowMs = new Date().valueOf(); const NowMs = new Date().valueOf();
...@@ -60,15 +60,9 @@ export function register(loginId, pwd) { ...@@ -60,15 +60,9 @@ export function register(loginId, pwd) {
} }
); );
changeJsonData("json/用户.json", userData); await changeUserJsonData("用户.json", userData, NowMs);
let dirPath = path.join(__dirname.substring(0,__dirname.indexOf("out")), `json/${NowMs}`); addJson(NowMs);
try {
fs.mkdirSync(dirPath, { recursive: true });
console.log(`文件夹${dirPath}已成功创建`);
} catch (err) {
console.error(`文件夹${dirPath}创建失败${err.message}`);
}
return successResult(); return successResult();
} }
...@@ -78,14 +72,14 @@ export function register(loginId, pwd) { ...@@ -78,14 +72,14 @@ export function register(loginId, pwd) {
* 基础数据【当前天数、银两数】 * 基础数据【当前天数、银两数】
* @returns * @returns
*/ */
export function getBaseData(userId) { export async function getBaseData(userId) {
let baseData = getJsonData("json/基础数据.json"); let baseData = await getUserJsonData("基础数据.json", userId);
let basicsData = { let basicsData = {
day:0, day:0,
tael:500 tael:500
} }
basicsData.day = baseData[userId]["天数"] || 0; basicsData.day = baseData["天数"] || 0;
// basicsData.tael = baseData[userId]["结算"] || 0; //todo第一幕不计算金额,直接使用500金 // basicsData.tael = baseData["结算"] || 0; //todo第一幕不计算金额,直接使用500金
return basicsData; return basicsData;
} }
...@@ -96,12 +90,12 @@ export function register(loginId, pwd) { ...@@ -96,12 +90,12 @@ export function register(loginId, pwd) {
* @param clueType * @param clueType
* @returns * @returns
*/ */
export function getCount(userId) { export async function getCount(userId) {
let excelData = xiansuoTableData(); let excelData = xiansuoTableData();
let clueExcelData = excelData["线索表"].dataList; let clueExcelData = excelData["线索表"].dataList;
let jsonData = getJsonData("json/全部线索.json"); let jsonData = await getUserJsonData("全部线索.json", userId);
let clueData = jsonData[userId]; let clueData = jsonData;
let personalData = { let personalData = {
clue:"", clue:"",
...@@ -118,19 +112,19 @@ export function getCount(userId) { ...@@ -118,19 +112,19 @@ export function getCount(userId) {
// if (info.isChoice) clue++ // if (info.isChoice) clue++
// }) // })
} }
personalData.clue = `${allClue}/${clue}`; //总线索数(线索配置表里的所有线索)/当前解锁的线索数 personalData.clue = `${clue}/${allClue}`; //总线索数(线索配置表里的所有线索)/当前解锁的线索数
// 银两数 todo 第一幕不计算银两数,默认展示500金 // 银两数 todo 第一幕不计算银两数,默认展示500金
// let baseData = getJsonData("json/基础数据.json"); // let baseData = await getUserJsonData("基础数据.json", userId);
// personalData.tael = baseData[userId]["结算"]; // personalData.tael = baseData["结算"];
// 雇佣人数 // 雇佣人数
let hireData = getJsonData("json/雇佣选择.json"); let hireData = await getUserJsonData("雇佣选择.json", userId);
if (hireData[userId]) { if (hireData) {
if (Object.keys(hireData[userId]).length != 0) { if (Object.keys(hireData).length != 0) {
if (!hireData[userId]["人工"]) hireData[userId]["人工"] = {} if (!hireData["人工"]) hireData["人工"] = {}
if (Object.keys(hireData[userId]["人工"]).length != 0) { if (Object.keys(hireData["人工"]).length != 0) {
personalData.hire = Object.keys(hireData[userId]["人工"]).length; personalData.hire = Object.keys(hireData["人工"]).length;
} }
} }
} }
...@@ -179,8 +173,8 @@ const nicknameRegex = /^[a-zA-Z0-9_\u4e00-\u9fa5]+$/; ...@@ -179,8 +173,8 @@ const nicknameRegex = /^[a-zA-Z0-9_\u4e00-\u9fa5]+$/;
* 修改昵称 * 修改昵称
* @param userId * @param userId
*/ */
export function updateName(userId, name) { export async function updateName(userId, name) {
let userData = getJsonData("json/用户.json"); let userData = await getJsonData("用户.json");
let isOk = true; let isOk = true;
let result; let result;
userData.forEach( info => { userData.forEach( info => {
...@@ -201,7 +195,7 @@ const nicknameRegex = /^[a-zA-Z0-9_\u4e00-\u9fa5]+$/; ...@@ -201,7 +195,7 @@ const nicknameRegex = /^[a-zA-Z0-9_\u4e00-\u9fa5]+$/;
}) })
if(isOk) { if(isOk) {
changeJsonData("json/用户.json", userData); changeJsonData("用户.json", userData);
result = successResult(); result = successResult();
} }
......
...@@ -9,7 +9,7 @@ async function lanuch() { ...@@ -9,7 +9,7 @@ async function lanuch() {
await initConfig(); await initConfig();
httpServer.createServer( systemConfig.port ); httpServer.createServer( systemConfig.port );
console.log('This indicates that the server is started successfully.'); console.log('This indicates that the server is started successfully.');
initCiqi(); await initCiqi();
// let key = crypto.randomBytes(32).toString('hex'); //"4fa9998e3be1bd3fa7b8def3969115858c6f19f9ef36e2e71f61645e9767764c" // let key = crypto.randomBytes(32).toString('hex'); //"4fa9998e3be1bd3fa7b8def3969115858c6f19f9ef36e2e71f61645e9767764c"
// let iv = crypto.randomBytes(16).toString('hex'); //"db2be0c856f44e68b818ff6ef7f018c1" // let iv = crypto.randomBytes(16).toString('hex'); //"db2be0c856f44e68b818ff6ef7f018c1"
// await initConfiguration(); // await initConfiguration();
......
...@@ -51,11 +51,11 @@ export function setRouter(httpServer){ ...@@ -51,11 +51,11 @@ export function setRouter(httpServer){
* @param req * @param req
* @param res * @param res
*/ */
function login(req, res) { async function login(req, res) {
let reqConf = {loginId:'String', pwd:'String'}; let reqConf = {loginId:'String', pwd:'String'};
let {loginId, pwd} = eccReqParamater(reqConf, req.body); let {loginId, pwd} = eccReqParamater(reqConf, req.body);
let result = userBiz.login(loginId, pwd); let result = await userBiz.login(loginId, pwd);
res.success(result); res.success(result);
} }
...@@ -63,11 +63,11 @@ function login(req, res) { ...@@ -63,11 +63,11 @@ function login(req, res) {
/** /**
* 修改昵称 * 修改昵称
*/ */
function updateName(req, res) { async function updateName(req, res) {
let userId = req.headers.userid; let userId = req.headers.userid;
let {name} = req.body; let {name} = req.body;
let result = userBiz.updateName(userId, name); let result = await userBiz.updateName(userId, name);
res.success(result); res.success(result);
} }
...@@ -77,27 +77,27 @@ function updateName(req, res) { ...@@ -77,27 +77,27 @@ function updateName(req, res) {
* @param req * @param req
* @param res * @param res
*/ */
function register(req, res) { async function register(req, res) {
let reqConf = {loginId:'String', pwd:'String'}; let reqConf = {loginId:'String', pwd:'String'};
let {loginId, pwd} = eccReqParamater(reqConf, req.body); let {loginId, pwd} = eccReqParamater(reqConf, req.body);
let result = userBiz.register(loginId, pwd); let result = await userBiz.register(loginId, pwd);
res.success(result); res.success(result);
} }
/**基础数据 */ /**基础数据 */
function getBaseData(req, res) { async function getBaseData(req, res) {
let userId = req.headers.userid; let userId = req.headers.userid;
let result = userBiz.getBaseData(userId); let result = await userBiz.getBaseData(userId);
res.success(result); res.success(result);
} }
/**统计获得线索数 */ /**统计获得线索数 */
function getCount(req, res) { async function getCount(req, res) {
let userId = req.headers.userid; let userId = req.headers.userid;
let result = userBiz.getCount(userId); let result = await userBiz.getCount(userId);
res.success(result); res.success(result);
} }
...@@ -107,17 +107,11 @@ function getCount(req, res) { ...@@ -107,17 +107,11 @@ function getCount(req, res) {
* @param req * @param req
* @param res * @param res
*/ */
function getPlay(req, res) { async function getPlay(req, res) {
let userId = req.headers.userid; let userId = req.headers.userid;
// 商行、SO11、对话Id(后置剧情id) // 商行、SO11、对话Id(后置剧情id)
let {type, playId, dhId} = req.body; let {type, playId, dhId} = req.body;
let result; let result = await playBiz.getPlayData(userId, type, playId, dhId);
// if (type == "酒馆") {
// result = playBiz.getJGPlayData(userId, type, playId, dhId);
// } else {
// }
result = playBiz.getPlayData(userId, type, playId, dhId);
res.success(result); res.success(result);
} }
...@@ -127,11 +121,11 @@ function getPlay(req, res) { ...@@ -127,11 +121,11 @@ function getPlay(req, res) {
* @param req * @param req
* @param res * @param res
*/ */
function pubHire(req, res) { async function pubHire(req, res) {
// 剧情type // 剧情type
let {playType} = req.body; let {playType} = req.body;
let result = playBiz.pubHire(playType); let result = await playBiz.pubHire(playType);
res.success(result); res.success(result);
} }
...@@ -141,12 +135,12 @@ function pubHire(req, res) { ...@@ -141,12 +135,12 @@ function pubHire(req, res) {
* @param req * @param req
* @param res * @param res
*/ */
function submitHire(req, res) { async function submitHire(req, res) {
let userId = req.headers.userid; let userId = req.headers.userid;
// 剧情type // 剧情type
let {playType, xsId} = req.body; let {playType, xsId} = req.body;
let result = playBiz.submitHire(userId, playType, xsId); let result = await playBiz.submitHire(userId, playType, xsId);
res.success(result); res.success(result);
} }
...@@ -156,10 +150,10 @@ function submitHire(req, res) { ...@@ -156,10 +150,10 @@ function submitHire(req, res) {
* @param req * @param req
* @param res * @param res
*/ */
function displayHire(req, res) { async function displayHire(req, res) {
let userId = req.headers.userid; let userId = req.headers.userid;
let result = playBiz.displayHire(userId); let result = await playBiz.displayHire(userId);
res.success(result); res.success(result);
} }
...@@ -169,11 +163,11 @@ function displayHire(req, res) { ...@@ -169,11 +163,11 @@ function displayHire(req, res) {
* @param req * @param req
* @param res * @param res
*/ */
function rawMaterial(req, res) { async function rawMaterial(req, res) {
// 颜料、瓷器 // 颜料、瓷器
let {type} = req.body; let {type} = req.body;
let result = playBiz.rawMaterial(type); let result = await playBiz.rawMaterial(type);
res.success(result); res.success(result);
} }
...@@ -183,11 +177,11 @@ function displayHire(req, res) { ...@@ -183,11 +177,11 @@ function displayHire(req, res) {
* @param req * @param req
* @param res * @param res
*/ */
function submitRawMaterial(req, res) { async function submitRawMaterial(req, res) {
let userId = req.headers.userid; let userId = req.headers.userid;
let {type, xsId} = req.body; let {type, xsId} = req.body;
let result = playBiz.submitRawMaterial(userId, type, xsId); let result = await playBiz.submitRawMaterial(userId, type, xsId);
res.success(result); res.success(result);
} }
...@@ -197,10 +191,10 @@ function submitRawMaterial(req, res) { ...@@ -197,10 +191,10 @@ function submitRawMaterial(req, res) {
* @param req * @param req
* @param res * @param res
*/ */
function displayRawMaterial(req, res) { async function displayRawMaterial(req, res) {
let userId = req.headers.userid; let userId = req.headers.userid;
let result = playBiz.displayRawMaterial(userId); let result = await playBiz.displayRawMaterial(userId);
res.success(result); res.success(result);
} }
...@@ -210,10 +204,10 @@ function displayRawMaterial(req, res) { ...@@ -210,10 +204,10 @@ function displayRawMaterial(req, res) {
* @param req * @param req
* @param res * @param res
*/ */
function getGzf(req, res) { async function getGzf(req, res) {
let userId = req.headers.userid; let userId = req.headers.userid;
let result = playBiz.getGzf(userId); let result = await playBiz.getGzf(userId);
res.success(result); res.success(result);
} }
...@@ -223,10 +217,10 @@ function getGzf(req, res) { ...@@ -223,10 +217,10 @@ function getGzf(req, res) {
* @param req * @param req
* @param res * @param res
*/ */
function getIntroduceGzf(req, res) { async function getIntroduceGzf(req, res) {
let userId = req.headers.userid; let userId = req.headers.userid;
let result = playBiz.getIntroduceGzf(userId); let result = await playBiz.getIntroduceGzf(userId);
res.success(result); res.success(result);
} }
...@@ -236,10 +230,10 @@ function getIntroduceGzf(req, res) { ...@@ -236,10 +230,10 @@ function getIntroduceGzf(req, res) {
* @param req * @param req
* @param res * @param res
*/ */
function firstPubHire(req, res) { async function firstPubHire(req, res) {
let userId = req.headers.userid; let userId = req.headers.userid;
let result = playBiz.firstPubHire(userId); let result = await playBiz.firstPubHire(userId);
res.success(result); res.success(result);
} }
...@@ -249,10 +243,10 @@ function getIntroduceGzf(req, res) { ...@@ -249,10 +243,10 @@ function getIntroduceGzf(req, res) {
* @param req * @param req
* @param res * @param res
*/ */
function getNPC(req, res) { async function getNPC(req, res) {
let {type} = req.body; let {type} = req.body;
let result = playBiz.getNPCData(type); let result = await playBiz.getNPCData(type);
res.success(result); res.success(result);
} }
...@@ -262,10 +256,10 @@ function getNPC(req, res) { ...@@ -262,10 +256,10 @@ function getNPC(req, res) {
* @param req * @param req
* @param res * @param res
*/ */
function isEnabled(req, res) { async function isEnabled(req, res) {
let userId = req.headers.userid; let userId = req.headers.userid;
let result = clueBiz.isEnabled(userId); let result = await clueBiz.isEnabled(userId);
res.success(result); res.success(result);
} }
...@@ -276,24 +270,24 @@ function getNPC(req, res) { ...@@ -276,24 +270,24 @@ function getNPC(req, res) {
* @param req * @param req
* @param res * @param res
*/ */
function getClue(req, res) { async function getClue(req, res) {
let userId = req.headers.userid; let userId = req.headers.userid;
let {clueType} = req.body; let {clueType} = req.body;
let result; let result;
if(clueType) result = clueBiz.getClue(userId, clueType); if(clueType) result = await clueBiz.getClue(userId, clueType);
else result = clueBiz.getClue(userId); else result = await clueBiz.getClue(userId);
res.success(result); res.success(result);
} }
/**取消选中线索 */ /**取消选中线索 */
function delClue(req, res) { async function delClue(req, res) {
let userId = req.headers.userid; let userId = req.headers.userid;
let {clueType, xxType, xsid} = req.body; let {clueType, xxType, xsid} = req.body;
let result = clueBiz.delClue(userId, clueType, xxType, xsid); let result = await clueBiz.delClue(userId, clueType, xxType, xsid);
res.success(result); res.success(result);
} }
...@@ -303,10 +297,10 @@ function delClue(req, res) { ...@@ -303,10 +297,10 @@ function delClue(req, res) {
* @param req * @param req
* @param res * @param res
*/ */
function checkClue(req, res) { async function checkClue(req, res) {
let userId = req.headers.userid; let userId = req.headers.userid;
let result = clueBiz.checkClue(userId); let result = await clueBiz.checkClue(userId);
res.success(result); res.success(result);
} }
...@@ -316,10 +310,10 @@ function checkClue(req, res) { ...@@ -316,10 +310,10 @@ function checkClue(req, res) {
* @param req * @param req
* @param res * @param res
*/ */
function againAnswer(req, res) { async function againAnswer(req, res) {
let userId = req.headers.userid; let userId = req.headers.userid;
let result = clueBiz.againAnswer(userId); let result = await clueBiz.againAnswer(userId);
res.success(result); res.success(result);
} }
...@@ -329,10 +323,10 @@ function checkClue(req, res) { ...@@ -329,10 +323,10 @@ function checkClue(req, res) {
* @param req * @param req
* @param res * @param res
*/ */
function againStart(req, res) { async function againStart(req, res) {
let userId = req.headers.userid; let userId = req.headers.userid;
let result = clueBiz.againStart(userId); let result = await clueBiz.againStart(userId);
res.success(result); res.success(result);
} }
...@@ -342,11 +336,11 @@ function checkClue(req, res) { ...@@ -342,11 +336,11 @@ function checkClue(req, res) {
* @param req * @param req
* @param res * @param res
*/ */
function getChoiceClue(req, res) { async function getChoiceClue(req, res) {
let userId = req.headers.userid; let userId = req.headers.userid;
let {clueType} = req.body; let {clueType} = req.body;
let result = clueBiz.getChoiceClue(userId, clueType); let result = await clueBiz.getChoiceClue(userId, clueType);
res.success(result); res.success(result);
} }
...@@ -356,17 +350,17 @@ function getChoiceClue(req, res) { ...@@ -356,17 +350,17 @@ function getChoiceClue(req, res) {
* @param req * @param req
* @param res * @param res
*/ */
function submitClue(req, res) { async function submitClue(req, res) {
let userId = req.headers.userid; let userId = req.headers.userid;
let {clueType, subdivide, xs} = req.body; let {clueType, subdivide, xs} = req.body;
let result; let result;
if (clueType == "SWOT") { if (clueType == "SWOT") {
result = swotBiz.submitSWOTClue(userId, subdivide, xs); result = await swotBiz.submitSWOTClue(userId, subdivide, xs);
} else if (clueType == "ROI") { } else if (clueType == "ROI") {
result = roiBiz.submitROIClue(userId, subdivide, xs); result = await roiBiz.submitROIClue(userId, subdivide, xs);
} else if (clueType == "竞合") { } else if (clueType == "竞合") {
result = jinheBiz.submitJinheClue(userId, subdivide, xs); result = await jinheBiz.submitJinheClue(userId, subdivide, xs);
} }
res.success(result); res.success(result);
} }
...@@ -377,10 +371,10 @@ function submitClue(req, res) { ...@@ -377,10 +371,10 @@ function submitClue(req, res) {
* @param req * @param req
* @param res * @param res
*/ */
function checkSWOT(req, res) { async function checkSWOT(req, res) {
let userId = req.headers.userid; let userId = req.headers.userid;
let result = swotBiz.checkSWOT(userId); let result = await swotBiz.checkSWOT(userId);
res.success(result); res.success(result);
} }
...@@ -390,10 +384,10 @@ function checkSWOT(req, res) { ...@@ -390,10 +384,10 @@ function checkSWOT(req, res) {
* @param req * @param req
* @param res * @param res
*/ */
function checkROI(req, res) { async function checkROI(req, res) {
let userId = req.headers.userid; let userId = req.headers.userid;
let result = roiBiz.checkROI(userId); let result = await roiBiz.checkROI(userId);
res.success(result); res.success(result);
} }
...@@ -403,10 +397,10 @@ function checkROI(req, res) { ...@@ -403,10 +397,10 @@ function checkROI(req, res) {
* @param req * @param req
* @param res * @param res
*/ */
function checkJinhe(req, res) { async function checkJinhe(req, res) {
let userId = req.headers.userid; let userId = req.headers.userid;
let result = jinheBiz.checkJinhe(userId); let result = await jinheBiz.checkJinhe(userId);
res.success(result); res.success(result);
} }
......
...@@ -41,14 +41,30 @@ export function getRandomInt(min, max) { ...@@ -41,14 +41,30 @@ export function getRandomInt(min, max) {
* @param jsonName json文件名称 * @param jsonName json文件名称
* @returns * @returns
*/ */
export function getJsonData(jsonName) { export async function getJsonData(jsonName) {
let filename = path.join(__dirname.substring(0,__dirname.indexOf("out")), jsonName); let filename = path.join(__dirname.substring(0,__dirname.indexOf(`out`)), `json/${jsonName}`);
let jsonObject = fs.readFileSync(filename, 'utf-8'); let jsonObject = fs.readFileSync(filename, 'utf-8');
let baseData;
if (jsonObject) baseData = JSON.parse(jsonObject);
console.log(baseData);
return baseData;
}
let baseData = JSON.parse(jsonObject);
/**
* 获取对应登录用户的数据json
* @param jsonName json文件名称
* @returns
*/
export async function getUserJsonData(jsonName, userId) {
let filename = path.join(__dirname.substring(0,__dirname.indexOf(`out`)), `json/${userId}/${jsonName}`);
let jsonObject = fs.readFileSync(filename, 'utf-8');
let baseData;
if (jsonObject) baseData = JSON.parse(jsonObject);
console.log(baseData); console.log(baseData);
return baseData; return baseData;
} }
...@@ -57,12 +73,77 @@ export function getJsonData(jsonName) { ...@@ -57,12 +73,77 @@ export function getJsonData(jsonName) {
* 更新json数据 * 更新json数据
* @param jsonName json文件名称 * @param jsonName json文件名称
*/ */
export function changeJsonData(jsonName, data) { export async function changeJsonData(jsonName, data) {
let jsonData = JSON.stringify(data, null, 2);
let filename = path.join(__dirname.substring(0,__dirname.indexOf(`out`)), `json/${jsonName}`);
fs.writeFileSync(filename, jsonData);
console.log('文件写入成功');
// fs.writeFile(filename, jsonData, (err) => {
// if (err) {
// console.log(`写入${jsonName}文件失败`);
// }
// console.log('文件写入成功');
// });
}
/**
* 更新对应用户json数据
* @param jsonName json文件名称
*/
export async function changeUserJsonData(jsonName, userId, data) {
let jsonData = JSON.stringify(data, null, 2); let jsonData = JSON.stringify(data, null, 2);
let filename = path.join(__dirname.substring(0,__dirname.indexOf("out")), jsonName); let filename = path.join(__dirname.substring(0,__dirname.indexOf(`out`)), `json/${userId}/${jsonName}`);
fs.writeFileSync(filename, jsonData); fs.writeFileSync(filename, jsonData);
console.log('文件写入成功'); console.log('文件写入成功');
// fs.writeFile(filename, jsonData, (err) => {
// if (err) {
// console.log(`写入${jsonName}文件失败`);
// }
// console.log('文件写入成功');
// });
} }
/**
* 添加对应user的文件夹
* @param userId
*/
export function addJson(userId) {
/**判断没有当前登录用户的文件夹则新建一个 */
let dirPath = path.join(__dirname.substring(0,__dirname.indexOf("out")), `json/${userId}`);
if (!fs.existsSync(dirPath)) {
try {
fs.mkdirSync(dirPath, { recursive: true });
console.log(`文件夹${dirPath}已成功创建`);
// 指定你要创建的 JSON 文件的路径和名称
let jsonName = ["雇佣选择.json", "基础数据.json", "竞合.json", "全部线索.json", "提交分数.json", "细分线索.json", "ROI.json", "SWOT.json"];
for(let i = 0; i < jsonName.length; i++) {
let jsonFilePath = path.join(dirPath, `${jsonName[i]}`);
// 转换为 JSON 字符串
let jsonData = '';
let jsonString = JSON.stringify(jsonData, null, 2)
// 文件夹创建成功后,写入 JSON 文件
fs.writeFileSync(jsonFilePath, jsonString);
console.log('文件写入成功');
}
} catch (err) {
console.error(`文件夹${dirPath}创建失败${err.message}`);
}
} else {
console.log(`文件夹${dirPath}已存在`);
}
}
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