shop.js
4.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
'use strict';
const mRoot = '../models';
const headerModel = require('../../../doraemon/models/header');
const shopService = require(`${mRoot}/shop-service`);
const helpers = global.yoho.helpers;
const _ = require('lodash');
const crypto = global.yoho.crypto;
const authcode = require(`${global.utils}/authcode`);
const base64_str_encode = ($input) => {
return $input.replace('+/=', '-_.');
}
const index = (req, res, next) => {
let channel = req.cookies._Channel || 'boys';
let responseData = {
module: 'shop',
page: 'shop',
footerTop: true
};
headerModel.requestHeaderData(channel).then(result => {
responseData.headerData = result.headerData;
res.render('settled', responseData);
}).catch(next);
};
const apply = (req, res, next) => {
let channel = req.cookies._Channel || 'boys';
let uid = req.user.uid;
let loginUrl;
let adpic = {'_project': 'adpic', 'format_str': []};
if (!uid) {
loginUrl = helpers.urlFormat('/signin.html', {
refer: helpers.urlFormat('/shop/apply')
});
res.redirect(loginUrl);
}
let responseData = {
module: 'shop',
page: 'shop',
footerTop: true
};
Promise.all([headerModel.requestHeaderData(channel), shopService.applyAction()]).then(result => {
responseData.headerData = result[0].headerData;
responseData.oneCategory = result[1];
responseData.uploadKey = base64_str_encode(authcode(JSON.stringify(adpic), 'yohobuy_upload_system', null, 'encode'));
res.render('apply', responseData);
}).catch(next);
};
const getTwoCategoryAction = (req, res, next) => {
let id = req.query.id;
if (id < 1) {
let data = {
message: 'id不能为空'
};
return data;
}
shopService.getTwoCategory(id).then(result => {
res.json(result);
}).catch(next);
};
const applysave = (req, res, next) => {
let uid = req.user.uid,
param = {},
data = {},
categoryInfo = [],
storeInfo = [];
for (let key in req.body) {
param[_.camelCase(key)] = req.body[key];
}
if (param.sellerRole === '') {
param.sellerRole = param.otherSellerRole;
}
if (!param.brandName || param.brandName === '' || !param.registerStatus || param.registerStatus === '' ||
!param.sellerName || param.sellerName === '' || !param.zipCode || param.zipCode === '' ||
!param.contacts || param.contacts === '' || !param.contactPhone || param.contactPhone === '' ||
!param.contactEmail || param.contactEmail === '' || !param.sellerRole || param.sellerRole === '') {
data.message = '请输入必填信息';
data.code = 400;
return data;
}
if (param.categoryOne && _.isArray(param.categoryOne) && _.isArray(param.categoryTwo) &&
_.isArray(param. categoryPrice)) {
_.forEach(param.categoryOne, function(val, key) {
if (val === '') {
return;
}
categoryInfo.push({
category_one: val,
category_two: param.categoryOne[key],
category_price: param.categoryPrice[key]
});
});
}
param.categoryInfo = JSON.stringify(categoryInfo);
param.producer = param.originCountry + ' ' + param.originProvince + ' ' + param.originCity;
param.quarterNum = parseInt(param.quarterNum, 10);
param.haveStore = parseInt(param.haveStore, 10);
if (param.newCycle === '') {
param.newCycle = param.ortherNewCycle;
}
if (param.haveStore && _.isArray(param.storeAddress) && _.isArray(param.storeSalesVolume)) {
_.forEach(param.storeAddress, function(val, key) {
if (val === '') {
return;
}
storeInfo.push({
store_address: val,
store_sales_volume: param.categoryOne[key]
});
});
}
param.storeInfo = JSON.stringify(storeInfo);
param.uid = uid;
shopService.insertApply(param).then(result => {
res.json(result);
}).catch(next);
};
module.exports = {
index,
apply,
getTwoCategoryAction,
applysave
};