Authored by TaoHuang

add api

@@ -7,16 +7,42 @@ @@ -7,16 +7,42 @@
7 </div> 7 </div>
8 </div> 8 </div>
9 9
  10 + <div class="shoe bg1"></div>
  11 +
10 <div style="position: absolute; width: 100%;"> 12 <div style="position: absolute; width: 100%;">
11 - <div class="item account">  
12 - <input class="input-class" name="account" placeholder="支付宝帐号"></input> 13 + <div class="item">
  14 + <div class="logo"></div>
  15 + </div>
  16 +
  17 + <div class="item">
  18 + <div class="title"></div>
  19 + </div>
  20 +
  21 + <div class="item">
  22 + <div class="desc"></div>
  23 + </div>
  24 +
  25 + <div class="item">
  26 + <div class="account-label"></div>
13 </div> 27 </div>
14 28
15 - <div class="item username">  
16 - <input class="input-class" name="username" placeholder="支付宝姓名"></input> 29 + <div class="item">
  30 + <input class="input-class" v-model="alipayAccount" name="account" placeholder="支付宝帐号"></input>
17 </div> 31 </div>
18 32
19 - <div class="item submit"> 33 + <div class="item">
  34 + <div class="name-label"></div>
  35 + </div>
  36 +
  37 + <div class="item">
  38 + <input class="input-class" v-model="alipayName" name="username" placeholder="支付宝姓名"></input>
  39 + </div>
  40 +
  41 + <div class="item">
  42 + <div class="tip"></div>
  43 + </div>
  44 +
  45 + <div class="item">
20 <div class="btn" @click="onClick"></div> 46 <div class="btn" @click="onClick"></div>
21 </div> 47 </div>
22 48
@@ -26,14 +52,87 @@ @@ -26,14 +52,87 @@
26 52
27 <script> 53 <script>
28 54
  55 +import { Dialog } from 'cube-ui';
  56 +
29 export default { 57 export default {
30 name: 'AlipayForm', 58 name: 'AlipayForm',
  59 + components: {
  60 + Dialog
  61 + },
  62 + data() {
  63 + return {
  64 + alipayAccount: '',
  65 + alipayName: ''
  66 + };
  67 + },
31 methods: { 68 methods: {
32 onClick() { 69 onClick() {
33 - console.log('huangtao'); 70 + if (!this.alipayAccount || !this.alipayName) {
  71 + this.$createToast({
  72 + type: 'warn',
  73 + time: 1000,
  74 + txt: '不能为空'
  75 + }).show();
  76 + return;
  77 + }
  78 +
  79 + this.showBtn();
34 }, 80 },
35 onBack() { 81 onBack() {
36 this.$yoho.finishPage({}); 82 this.$yoho.finishPage({});
  83 + },
  84 + content() {
  85 + return `信息一旦提交后不可修改,确认提交吗?<br>支付宝账号:${this.alipayAccount} <br>支付宝姓名:${this.alipayName}`;
  86 + },
  87 + showBtn() {
  88 + this.$createDialog({
  89 + type: 'confirm',
  90 + content: this.content(),
  91 + confirmBtn: {
  92 + text: '确定',
  93 + active: true,
  94 + disabled: false,
  95 + href: 'javascript:;'
  96 + },
  97 + cancelBtn: {
  98 + text: '取消',
  99 + active: false,
  100 + disabled: false,
  101 + href: 'javascript:;'
  102 + },
  103 + onConfirm: () => {
  104 + this.submit();
  105 + },
  106 + onCancel: () => {
  107 + // this.$createToast({
  108 + // type: 'warn',
  109 + // time: 1000,
  110 + // txt: '点击取消按钮'
  111 + // }).show();
  112 + }
  113 + }).show();
  114 + },
  115 + submit() {
  116 + this.$api.post('/alipay/submit', {
  117 + alipayAccount: this.alipayAccount,
  118 + alipayName: this.alipayName
  119 + }).then(result => {
  120 + if (result.code !== 200) {
  121 + this.$createToast({
  122 + type: 'warn',
  123 + time: 1000,
  124 + txt: result.message
  125 + }).show();
  126 + return;
  127 + }
  128 +
  129 + this.$createToast({
  130 + type: 'text',
  131 + time: 1000,
  132 + txt: result.message
  133 + }).show();
  134 + });
  135 +
37 } 136 }
38 } 137 }
39 }; 138 };
@@ -49,7 +148,75 @@ export default { @@ -49,7 +148,75 @@ export default {
49 } 148 }
50 149
51 .bg { 150 .bg {
52 - background-image: url("~statics/image/alipay/bg.jpg"); 151 + background-image: url("~statics/image/alipay/bg1.png");
  152 + background-size: contain;
  153 + }
  154 +
  155 + .bg1 {
  156 + background-image: url("~statics/image/alipay/bg2.png");
  157 + background-size: cover;
  158 + }
  159 +
  160 + .logo {
  161 + display: inline-block;
  162 + width: 361px;
  163 + height: 62px;
  164 + margin-top: 45px;
  165 + background-image: url("~statics/image/alipay/logo.png");
  166 + background-size: cover;
  167 + }
  168 +
  169 + .title {
  170 + display: inline-block;
  171 + width: 474px;
  172 + height: 240px;
  173 + margin-top: 40px;
  174 + background-image: url("~statics/image/alipay/title.png");
  175 + background-size: cover;
  176 + }
  177 +
  178 + .desc {
  179 + display: inline-block;
  180 + width: 645px;
  181 + height: 352px;
  182 + margin-top: 30px;
  183 + background-image: url("~statics/image/alipay/desc.png");
  184 + background-size: cover;
  185 + }
  186 +
  187 + .tip {
  188 + display: inline-block;
  189 + width: 483px;
  190 + height: 52px;
  191 + margin-top: 20px;
  192 + background-image: url("~statics/image/alipay/tip.png");
  193 + background-size: cover;
  194 + }
  195 +
  196 + .shoe {
  197 + position: absolute;
  198 + bottom: 0;
  199 + width: 100%;
  200 + height: 213px;
  201 + background-image: url("~statics/image/alipay/bg2.png");
  202 + background-size: cover;
  203 + }
  204 +
  205 + .account-label {
  206 + display: inline-block;
  207 + width: 181px;
  208 + height: 33px;
  209 + margin-top: 50px;
  210 + background-image: url("~statics/image/alipay/account.png");
  211 + background-size: cover;
  212 + }
  213 +
  214 + .name-label {
  215 + display: inline-block;
  216 + width: 181px;
  217 + height: 32px;
  218 + margin-top: 25px;
  219 + background-image: url("~statics/image/alipay/name.png");
53 background-size: cover; 220 background-size: cover;
54 } 221 }
55 222
@@ -61,6 +228,7 @@ export default { @@ -61,6 +228,7 @@ export default {
61 .input-class { 228 .input-class {
62 width: 480px; 229 width: 480px;
63 height: 57px; 230 height: 57px;
  231 + margin-top: 20px;
64 border: 2px solid #131835; 232 border: 2px solid #131835;
65 font-size: 17px; 233 font-size: 17px;
66 color: #131835; 234 color: #131835;
@@ -84,8 +252,11 @@ export default { @@ -84,8 +252,11 @@ export default {
84 252
85 .btn { 253 .btn {
86 display: inline-block; 254 display: inline-block;
87 - width: 300px;  
88 - height: 130px; 255 + width: 227px;
  256 + height: 71px;
  257 + margin-top: 40px;
  258 + background-image: url("~statics/image/alipay/btn.png");
  259 + background-size: cover;
89 } 260 }
90 261
91 .header { 262 .header {
@@ -132,6 +132,13 @@ module.exports = { @@ -132,6 +132,13 @@ module.exports = {
132 SECRET_KEY: '_x2VtO7fEmylgjojmLi7qwTBtRm30S8BrO0FxOPK', 132 SECRET_KEY: '_x2VtO7fEmylgjojmLi7qwTBtRm30S8BrO0FxOPK',
133 ORIGIN: 'https://cdn.yoho.cn', 133 ORIGIN: 'https://cdn.yoho.cn',
134 BUCKET_NAME: 'yohocdn' 134 BUCKET_NAME: 'yohocdn'
  135 + },
  136 + mysql: {
  137 + host: 'localhost',
  138 + userName: 'root',
  139 + password: 'root',
  140 + port: '3306',
  141 + db: 'yoho_apm_test'
135 } 142 }
136 }; 143 };
137 144
@@ -263,6 +270,13 @@ if (isProduction) { @@ -263,6 +270,13 @@ if (isProduction) {
263 prettyPrint: true, 270 prettyPrint: true,
264 debugStdout: true 271 debugStdout: true
265 } 272 }
  273 + },
  274 + mysql: {
  275 + host: '192.168.102.219',
  276 + userName: 'yh_test',
  277 + password: 'yh_test',
  278 + port: '3306',
  279 + db: 'yoho_apm_test'
266 } 280 }
267 }); 281 });
268 } 282 }
@@ -81,13 +81,16 @@ exports.createApp = async(app) => { @@ -81,13 +81,16 @@ exports.createApp = async(app) => {
81 const ssrApiMiddleware = require('./doraemon/middleware/ssr-api'); 81 const ssrApiMiddleware = require('./doraemon/middleware/ssr-api');
82 const ssrRouteMiddleware = require('./doraemon/middleware/ssr'); 82 const ssrRouteMiddleware = require('./doraemon/middleware/ssr');
83 const qiniuMiddleware = require('./doraemon/middleware/qiniu'); 83 const qiniuMiddleware = require('./doraemon/middleware/qiniu');
  84 + const alipayRouter = require('./doraemon/router');
84 85
85 // YOHO 前置中间件 86 // YOHO 前置中间件
86 app.use(setYohoDataMiddleware); 87 app.use(setYohoDataMiddleware);
87 app.use(userMiddleware); 88 app.use(userMiddleware);
88 app.get('/mapp/getToken', qiniuMiddleware.getToken); 89 app.get('/mapp/getToken', qiniuMiddleware.getToken);
  90 + app.use('/mapp/alipay', alipayRouter);
89 app.use('/mapp', ssrApiMiddleware); 91 app.use('/mapp', ssrApiMiddleware);
90 92
  93 +
91 app.use(ssrRouteMiddleware.routers); 94 app.use(ssrRouteMiddleware.routers);
92 95
93 app.all('*', ssrRouteMiddleware.ssrRender); // 404 96 app.all('*', ssrRouteMiddleware.ssrRender); // 404
  1 +const alipayService = require('./alipay.service');
  2 +
  3 +function submit(req, res, next) {
  4 + const { alipayAccount, alipayName } = req.body;
  5 + const uid = req.user.uid;
  6 +
  7 + // if (!uid) {
  8 + // return res.json({
  9 + // code: 401,
  10 + // message: '抱歉,您暂未登录!'
  11 + // });
  12 + // }
  13 +
  14 + if (!alipayAccount || !alipayName) {
  15 + return res.json({
  16 + code: 404,
  17 + message: '用户名或帐号不能为空,请重新填写'
  18 + });
  19 + }
  20 +
  21 + alipayService.create({ uid, alipayAccount, alipayName }).then(result => {
  22 + if (result.error) {
  23 + return res.json(result.error);
  24 + }
  25 +
  26 + return res.json(result);
  27 + }).catch(next);
  28 +}
  29 +
  30 +module.exports = {
  31 + submit
  32 +};
  1 +const mysql = require('./mysql-client');
  2 +const TABEL = 'user_alipay';
  3 +
  4 +
  5 +async function insert(data) {
  6 + return mysql(TABEL).insert({
  7 + ...data,
  8 + createdAt: new Date().valueOf()
  9 + });
  10 +}
  11 +
  12 +module.exports = {
  13 + insert
  14 +};
  1 +const alipayRepository = require('./alipay.repository');
  2 +const { logger } = global.yoho;
  3 +
  4 +async function create({ uid, alipayAccount, alipayName }) {
  5 + try {
  6 + const result = await alipayRepository.insert({
  7 + uid, alipayAccount, alipayName
  8 + });
  9 +
  10 + if (!result) {
  11 + return {
  12 + error: {
  13 + code: 500,
  14 + message: '服务器出错,请稍候再来提交'
  15 + }
  16 + };
  17 + }
  18 +
  19 + return {
  20 + code: 200,
  21 + message: '提交成功'
  22 + };
  23 + } catch (e) {
  24 + if (e.code === 'ER_DUP_ENTRY') {
  25 + // 重复的情况
  26 + return {
  27 + error: {
  28 + code: 404,
  29 + message: '您已提交过支付宝信息,请不要重复提交!'
  30 + }
  31 + };
  32 + } else {
  33 + logger.error('mysql error =>', e);
  34 +
  35 + return {
  36 + error: {
  37 + code: 500,
  38 + message: '服务器出错,请稍候再来提交'
  39 + }
  40 + };
  41 + }
  42 + }
  43 +}
  44 +
  45 +module.exports = {
  46 + create
  47 +};
  1 +const knex = require('knex');
  2 +const config = global.yoho.config;
  3 +
  4 +function init() {
  5 + return knex({
  6 + client: 'mysql',
  7 + connection: {
  8 + host: config.mysql.host,
  9 + port: config.mysql.port,
  10 + user: config.mysql.userName,
  11 + password: config.mysql.password,
  12 + database: config.mysql.db
  13 + },
  14 + pool: { min: 0, max: 10 }
  15 + });
  16 +}
  17 +
  18 +module.exports = init();
@@ -7,7 +7,10 @@ @@ -7,7 +7,10 @@
7 'use strict'; 7 'use strict';
8 8
9 const router = require('express').Router(); // eslint-disable-line 9 const router = require('express').Router(); // eslint-disable-line
10 -// const cRoot = './controllers';  
11 10
  11 +const alipayController = require('./middleware/alipay.controller');
  12 +const auth = require('./middleware/auth');
  13 +
  14 +router.post('/submit', alipayController.submit);
12 15
13 module.exports = router; 16 module.exports = router;
@@ -42,8 +42,10 @@ @@ -42,8 +42,10 @@
42 "express": "^4.16.4", 42 "express": "^4.16.4",
43 "express-session": "^1.15.6", 43 "express-session": "^1.15.6",
44 "fastclick": "^1.0.6", 44 "fastclick": "^1.0.6",
  45 + "knex": "^0.16.3",
45 "lodash": "^4.17.11", 46 "lodash": "^4.17.11",
46 "lottie-web": "^5.4.2", 47 "lottie-web": "^5.4.2",
  48 + "mysql": "^2.16.0",
47 "qiniu": "^7.2.1", 49 "qiniu": "^7.2.1",
48 "request-promise": "^4.2.2", 50 "request-promise": "^4.2.2",
49 "serve-favicon": "^2.5.0", 51 "serve-favicon": "^2.5.0",