Authored by 邱骏

merge

/**
* 0元抽奖活动
* @author: yyq <yanqing.yang@yoho.cn>
* @date: 19/07/2018
*/
const coupon511Model = require('../../api/models/coupon511');
const valid = require('../../../utils/validator');
const logger = global.yoho.logger;
module.exports = {
status(req, res, next) {
let data = valid(req.body, {
uid: {type: 'number', empty: false},
});
if (!data.uid) {
return res.json({
code: 400,
message: '参数错误'
});
}
return req.ctx(coupon511Model).getStatus(data.uid).then(result => {
res.json(result);
}).catch(next);
},
take(req, res, next) {
const inx = +req.query.couponInx;
let data = valid(req.body, {
uid: {type: 'number', empty: false},
sessionKey: {type: 'string', empty: false},
appVersion: {type: 'string', empty: false},
appSessionType: {type: 'string', empty: true}
});
logger.warn(`inx: ${inx}, data: ${JSON.stringify(data)}`);
if (!inx || !data.uid) {
return res.json({
code: 400,
message: '参数错误'
});
}
return req.ctx(coupon511Model).takeCoupon(data, inx).then(result => {
res.json(result);
}).catch(next);
}
};
... ...
const _ = require('lodash');
const aes = require('../../../utils/aes');
const moment = require('moment');
const mySqlCli = global.yoho.utils.mysqlCli;
const UfoApi = global.yoho.UfoAPI;
const TABLE_PRIZE = 'act_prize_user_log';
const TABLE_USER_DETAIL = 'act_user_detail_info';
const logger = global.yoho.logger;
const mysqlCli = global.yoho.utils.mysqlCli;
const coupons = ['57008016-f16a-4814-854b-2ed8c8cab3b5', '418b5d9b-6574-4d62-8457-d74da6ec94e2'];
class Coupon511 extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
this.redis = global.yoho.redis;
this.client = this.redis.client;
}
_getCoupon(uid, inx) {
const token = coupons[inx - 1];
return this.get({
url: 'coupon',
data: {
method: 'ufo.coupons.send',
uid: uid,
coupon_tokens: token
},
api: UfoApi
});
}
concatPhone(uid) {
let phone = '';
let appStrLen = 11 - uid.toString().length;
for (let i = 0; i < appStrLen; i++) {
phone += '0';
}
phone += uid.toString();
return phone;
}
_saveUserInfo(uid) {
let actId = 9999, name = '000', birthday = moment().format('YYYY-MM-DD'), gender = 0, email = 'u@yoho.cn', province = '', city = '';
let phone = this.concatPhone(uid);
let strFind = `SELECT COUNT(*) AS user_count
FROM ${TABLE_USER_DETAIL}
WHERE act_id=:actId
AND user_phone=:phone`;
let strInsert = `INSERT INTO ${TABLE_USER_DETAIL}
(act_id, user_name, user_birthday, user_gender,
user_phone, user_email, user_province, user_city)
VALUES (:actId, :name, :birthday, :gender, :phone, :email, :province, :city)`;
return mySqlCli.query(strFind, {
actId,
phone
}).then(ret => {
if (ret && ret[0].user_count <= 0) {
return mySqlCli.insert(strInsert, {
actId,
name,
birthday,
gender,
phone,
email,
province,
city
}).then(ret2 => {
return Promise.resolve({
code: 200,
message: '用户信息添加成功',
data: ret2
});
});
} else {
return Promise.resolve({
code: 203,
message: '已存在的用户信息'
});
}
});
}
async getStatus(uid) {
const hasInx = await this.client.getAsync(`coupon511_${uid}`);
if (hasInx) {
return {
code: 200,
data: hasInx
};
}
return {
code: 204,
};
}
async takeCoupon(obj, inx) {
const hasInx = await this.client.getAsync(`coupon511_${obj.uid}`);
if (hasInx) {
return {
code: 200,
message: '已领取过 不可重复领取'
};
}
let uid = {
toString: () => {
return _.parseInt(obj.uid);
},
sessionKey: obj.sessionKey,
appVersion: obj.appVersion,
appSessionType: obj.sessionType
};
let result;
if (inx < 3) {
result = await this._getCoupon(uid, inx);
} else {
this._saveUserInfo(obj.uid);
result = {
code: 200,
message: '领取成功'
};
}
if (result.code === 200 || result.code === 401) {
this.client.set(`coupon511_${obj.uid}`, inx.toString());
}
return result;
}
}
module.exports = Coupon511;
... ...
... ... @@ -16,6 +16,7 @@ const redpac = require('./controllers/redpac');
const excel = require('./controllers/excel');
const multipart = require('connect-multiparty');
const wheelSurf = require('./controllers/wheel-surf');
const coupon511 = require('./controllers/coupon511');
const common = require('./controllers/common');
const mutilpartMiddleware = multipart();
const yohoActivitys = require('./controllers/yoho-activitys');
... ... @@ -85,6 +86,8 @@ router.post('/activity/wheelSurf/user/prize', wheelSurf.getUserPrize);
// 公共服务
router.get('/common/resource', common.getResource);
router.post('/coupon511/status', coupon511.status);
router.post('/coupon511/take', coupon511.take);
router.get('/activity/yohoActivitys/create', yohoActivitys.actCreate); // 创建一个活动
router.get('/activity/yohoActivitys/actInfo', yohoActivitys.getActInfo); // 获取活动信息
... ...
... ... @@ -20,13 +20,14 @@ module.exports = {
// yohoVerifyUdid: '0f626ede-0e17-460b-a8ea-069ee506e8e9',
domains: {
api: 'http://api-test3.dev.yohocorp.com/',
service: 'http://api-test3.dev.yohocorp.com/',
singleApi: 'http://api-test3.yohops.com:9999/',
// api: 'http://api-test3.dev.yohocorp.com/',
// service: 'http://api-test3.dev.yohocorp.com/',
// singleApi: 'http://api-test3.yohops.com:9999/',
// singleApi: 'http://api.yoho.cn/',
// api: 'http://api.yoho.cn/',
// service: 'http://service.yoho.cn/',
singleApi: 'http://api.yoho.cn/',
api: 'http://api.yoho.cn/',
service: 'http://service.yoho.cn/',
ufo: 'http://2.yohobuy.com',
store: 'http://192.168.102.47:8080/portal-gateway/wechat/',
serviceNotify: 'http://service.yoho.cn/',
platformApi: 'http://172.16.6.210:8088/',
... ... @@ -148,6 +149,7 @@ if (isProduction) {
assetUrl: `/yoho-activity-platform/${pkg.version}/`,
domains: {
api: 'http://api.yoho.yohoops.org/',
ufo: 'http://ufoapi.yohoops.org/',
store: 'https://openstore.yohobuy.com',
service: 'http://api.yoho.yohoops.org/',
global: 'http://api-global.yohobuy.com',
... ... @@ -220,6 +222,7 @@ if (isProduction) {
assetUrl: `/yoho-activity-platform/${pkg.version}/`,
domains: {
api: 'http://api-test3.dev.yohocorp.com/',
ufo: process.env.UFO_API || 'http://java-yohoufo-fore.test3.ingress.dev.yohocorp.com/ufo-gateway/',
service: 'http://api-test3.dev.yohocorp.com/',
global: 'http://global-test-soa.yohops.com:9999/',
store: 'http://192.168.102.210:8080/portal-gateway/wechat/',
... ...
... ... @@ -40,6 +40,15 @@ const serverError = (err, req, res, next) => { // eslint-disable-line
} catch(e) {} // eslint-disable-line
}
if (err && err.code === 401) {
if (req.xhr) {
return res.status(401).json(err);
} else if (req.jsonp) {
err.auth = true;
return res.jsonp(err);
}
}
return res.status(code).json({
code: code,
message: msg
... ...