Authored by weiqingting

个人中心首页

'use strict';
class cClass{
constructor(){}
}
module.exports = cClass;
... ... @@ -4,29 +4,36 @@ const Promise = require('bluebird');
const co = Promise.coroutine;
const OrderData = require('../models/OrderData');
const orderDate=new OrderData();
const IndexModel = require('../models/Index');
const indexModel=new IndexModel();
const helpers = global.yoho.helpers;
class Account extends global.cClass{
index(req,res,next){
let $uid= '8041246';//req.user.uid;
let $udid= 'abcdrf';//req.sessionID;
const index=(req,res,next)=>{
let $uid= '8041246';//req.user.uid;
let $udid= 'abcdrf';//req.sessionID;
co(function * (){
let pall= yield Promise.all([orderDate.closeReasons(),indexModel.getInfoNumData($uid, $udid)]);
let $cancelReason=pall[0].data?pall[0].data:'';
res.render("home/index/index",{
cancelReason:$cancelReason,
content:[
{messages:pall[1]},
{latestOrders:{}}
],
helpUsUrl:''
});
})().catch(next);
}
co(function * (){
let pall= yield Promise.all([OrderData.closeReasons(),IndexModel.getInfoNumData($uid, $udid)]);
let $cancelReason=pall[0].data?pall[0].data:'';
console.log(pall[2]);
res.render("home/index/index",{
cancelReason:$cancelReason,
content:[
{messages:pall[1]},
{
latestOrders:{},
favBrand:{
more:'/brands',
brands:'brand'
},
newArrival:'new'
}
],
helpUsUrl:''
});
})().catch(next);
}
module.exports=Account;
module.exports = {
index
};
... ...
... ... @@ -26,8 +26,6 @@ app.engine('.hbs', hbs({
helpers: global.yoho.helpers
}));
global.mClass=require("./mClass");
global.cClass=require("./cClass");
// router
app.use(require('./router'));
... ...
'use strict';
var logger = global.yoho.logger;
var api = global.yoho.API;
var SearchAPI = global.yoho.SearchAPI;
const helpers = global.yoho.helpers;
class mClass{
constructor(){
this.API=api;
this.SearchAPI=SearchAPI;
this.logger=logger;
this.helpers=helpers;
}
cb(logs,options){
return (result)=>{
if (result && result.code === 200) {
return result.data;
} else {
logger.error(`${logs+JSON.stringify(options)} 接口返回数据错误`);
return false;
}
}
}
}
module.exports = mClass;
'use strict';
const Promise = require('bluebird');
const co = Promise.coroutine;
const OrderData=require('./OrderData');
const helpers = global.yoho.helpers;
const api = global.yoho.API;
class IndexModel extends global.mClass{
getPendingOrderCount($uid){
let options={
method:'web.SpaceOrders.getPendingOrderCount',
uid:$uid
};
return this.API.get('', options);
// class IndexModel extends global.mClass{
const getPendingOrderCount=($uid)=>{
let options={
method:'web.SpaceOrders.getPendingOrderCount',
uid:$uid
};
return api.get('', options);
}
const infoNum=($uid, $udid)=>{
let options={
method:'app.home.getInfoNum',
uid:$uid,
udid:$udid
}
infoNum($uid, $udid){
let options={
method:'app.home.getInfoNum',
uid:$uid,
udid:$udid
}
return this.API.get('', options);
return api.get('', options);
}
const notCommentRecordCount=($uid)=>{
let options={
method:'show.notCommentRecordCount',
uid:$uid
}
notCommentRecordCount($uid){
let options={
method:'show.notCommentRecordCount',
uid:$uid
return api.get('', options);
}
const getInfoNumData=($uid, $udid)=>{
let $result=[
{href:helpers.urlFormat('/home/orders'),name:'待处理订单','count':0},
{href:helpers.urlFormat('/home/message'),name:'未读消息','count':0},
{href:helpers.urlFormat('/home/comment'),name:'待评论商品','count':0}
];
return co(function * (){
let $getPendingOrderCount = yield getPendingOrderCount($uid);//待处理订单
console.log($getPendingOrderCount);
let $infoNumData = yield infoNum($uid, $udid); //未读消息
let $notCommentRecordCount = yield notCommentRecordCount($uid);//待评论商品
$result[0]['count']=$getPendingOrderCount.data.count?$getPendingOrderCount.data.count:0;
$result[1]['count']=$infoNumData.data.inbox_total?$infoNumData.data.inbox_total:0;
$result[2]['count']=$notCommentRecordCount.data?$notCommentRecordCount.data:0;
return $result;
})();
}
const getByNodeContent=($node, $mode)=>{
$mode=$mode||'release';
let options={
method:'web.html.content',
mode:$mode,
node:$node
};
return api.get('', options);
}
const getFooterBanner=($code)=>{
$code=$code||'20110609-152143';
return co(function *(){
let result="";
let $banner=yield getByNodeContent($code);
if($banner.code&&$banner.data){
result=$banner.data.replace('http://','//');
}
return this.API.get('', options);
}
getInfoNumData($uid, $udid){
var that=this;
let $result=[
{href:this.helpers.urlFormat('/home/orders'),name:'待处理订单','count':0},
{href:this.helpers.urlFormat('/home/message'),name:'未读消息','count':0},
{href:this.helpers.urlFormat('/home/comment'),name:'待评论商品','count':0}
];
return co(function * (){
let $getPendingOrderCount = yield that.getPendingOrderCount($uid);//待处理订单
let $infoNumData = yield that.infoNum($uid, $udid); //未读消息
let $notCommentRecordCount = yield that.notCommentRecordCount($uid);//待评论商品
$result[0]['count']=$getPendingOrderCount.data.count?$getPendingOrderCount.data.count:0;
$result[1]['count']=$infoNumData.data.inbox_total?$infoNumData.data.inbox_total:0;
$result[2]['count']=$notCommentRecordCount.data?$notCommentRecordCount.data:0;
return $result;
})();
}
getFooterBanner($code){
$code=$code||'20110609-152143';
return result;
})()
}
/**
* 订单状态
* @param type $isCancel
* @param type $status
* @param type $payType
* @param type $payStatus
* @return string
*/
// const getOrderStatus=($isCancel, $status, $payType, $payStatus)=>{
// //初始化:未取消,待付款
// let $ret={cancel:false,keyName:'noPay',statusStr:'待付款'};
// if ($isCancel == 'Y') {
// $ret = {cancel:true,statusStr:'已取消'};
// }else{
// switch ($status) {
// case 0:
// //'订单已成功,等待付款'
// if ($payType != 2 && $payStatus == 'N') {
// $ret['keyName'] = 'noPay';
// $ret['statusStr'] = '待付款';
// }
// //'订单已付款,等待备货中'
// else if ($payType != 2 && $payStatus == 'Y') {
// $ret['keyName'] = 'paid';
// $ret['statusStr'] = '备货中';
// }
// //'订单已成功,等待备货中'-货到付款
// else if ($payType == 2 && $payStatus == 'N') {
// $ret['keyName'] = 'complete';
// $ret['statusStr'] = '备货中';
// }
// break;
// case 1:
// case 2:
// case 3:
// //'订单已付款,等待备货中'
// $ret['keyName'] = 'paid';
// $ret['statusStr'] = '备货中';
// break;
// case 4:
// case 5:
// //'订单已发货'
// $ret['keyName'] = 'shipped';
// $ret['statusStr'] = '待收货';
// break;
// case 6:
// //'交易完成';
// $ret['keyName'] = 'reback';
// $ret['statusStr'] = '交易完成';
// break;
// }
// }
// return $ret;
// }
// const getExpressInfo=($orderCode, $uid, $paymetType, $createTime, $isDetail)=>{
// $isDetail=$isDetail||false;
// let $result={};
// $result['logisticsUrl'] = '';
// $result['logisticsImg'] = '';
// $result['logisticsCompany'] = '';
// $result['courierNumbe'] = '';
// if ($paymetType == 1) {
// if ($isDetail) {
// $result['logistics'] = [new Date($createTime), ' ', '您的订单已提交,等待付款'];
// }
// else {
// $result['logistics'] = new Date($createTime) + ' ' + '您的订单已提交,等待付款';
// }
// }
// if ($paymetType == 2) {
// if ($isDetail) {
// $result['logistics'] = [new Date($createTime), ' ', '您的订单已提交,等待审核'];
// }
// else {
// $result['logistics'] = new Date($createTime) +' ' + '您的订单已提交,等待审核';
// }
// }
// //有物流
// if ($orderCode && typeof _.isNumber($uid)) {
// let $logistics = yield OrderData.getLogisticsData($orderCode, $uid);
// if ($logistics['data']) {
// $result['logisticsUrl'] = $logistics['data']['url'] ? this.helper.getUrlSafe($logistics['data']['url']) : '';
// $result['logisticsImg'] = $logistics['data']['logo'] ? $logistics['data']['logo'] : '';
// $result['logisticsCompany'] = $logistics['data']['caption'] ? $logistics['data']['caption'] : '';
// $result['courierNumbe'] = $logistics['data']['express_number']? $logistics['data']['express_number'] : '';
// let $expressDetail = $logistics['data']['express_detail'] ? $logistics['data']['express_detail'] : {};
// if ($expressDetail) {
// $logisticsTmp = $result['logistics'][0]; //暂存
// $result['logistics'] = array();
// foreach ($expressDetail as $value) {
// $pos =$value['accept_address'].indexOf(' ') / 3;
// $city = $value['accept_address'].substr(0,$pos);
// $exInfo = $value['accept_address'].substr($pos);
// if ($isDetail) {
// $result['logistics'] = [$value['acceptTime'], $city, $exInfo];
// }
// else {
// $result['logistics'] = $value['acceptTime'] + $city + $exInfo;
// }
// }
// //把最初的处理放最后
// $result['logistics'] = $logisticsTmp;
// }
// }
// }
// return $result;
// }
/**
* 商品属性标签
* @param type $attribute
* @param type $goodsType
* @return string
*/
// const getGoodsTag=($attribute, $goodsType)=>{
// let $goodsTagName = '';
// switch ($goodsType) {
// //赠品
// case 'gift':
// $goodsTagName = 'freebie';
// break;
// //加价购
// case 'price_gift':
// $goodsTagName = 'advanceBuy';
// break;
// //预售
// case 'advance':
// $goodsTagName = 'preSaleGood';
// break;
// //outlet
// case 'outlet':
// $goodsTagName = '';
// break;
// //免单
// case 'free':
// $goodsTagName = '';
// break;
// //电子
// case 'ticket':
// $goodsTagName = '';
// break;
// default:
// break;
// }
// //虚拟
// if ($attribute == 3) {
// $goodsTagName = 'virtualGood';
// }
// return $goodsTagName;
// }
/**
* 获取我的订单列表数据-分页
* @param type $uid
* @param type $page
* @param type $limit
* @param type $type 获取订单类型 type=1全部,type=2待付款,type=3待发货,type=4待收货,type=5待评论(已成功) 7取消
*/
// const getOrders=($uid, $page, $limit, $type, $isPage)=>{
// return co(function *(){
// $isPage=$isPage||false;
// let getOrderDescStr={
// 1:'您还没有任何订单',
// 5:'您目前还没有成功的订单',
// 7:'您还没有任何取消的订单'
// }
// let $descStr=getOrderDescStr[$type]||'';
// let $orders={empty:$descStr};
// let $orderInfo=yield OrderData.getUserOrders($uid, $page, $limit, $type);
// if($orderInfo.data&&$orderInfo.data.order_list){
// $orders={};
// $orderInfo.data.order_list.forEach(function($orderV,$orderK){
// $orders[$orderK]['orderNum'] = $orderV['order_code']; //订单标识
// $orders[$orderK]['orderTime'] = new Date($orderV['create_time']);
// let $statusInfo = getOrderStatus($orderV['is_cancel'], $orderV['status'], $orderV['payment_type'], $orderV['payment_status']);
// //订单状态
// if ($statusInfo['cancel']) {
// $orders[$orderK]['cancel'] = $statusInfo['cancel'];
// }
// else {
// if ($statusInfo['keyName']) {
// $orders[$orderK][$statusInfo['keyName']] = true;
// //已发货,物流信息
// if ($statusInfo['keyName'] == 'shipped') {
// let $expressInfo = getExpressInfo($orderV['order_code'], $uid, $orderV['payment_type'], $orderV['create_time']);
// $orders[$orderK]['logistics'] = $expressInfo['logistics'];
// }
// }
// }
// //订单商品相关信息
// let $opRefundStatus = true; //订单不可操作退换货
// if ($orderV['order_goods'] && $orderV['order_goods']) {
// let $goods={},$refundFlag={};
// $orderV['order_goods'].forEach(function($goval,$gokey){
// $goods[$gokey]['href'] = helpers.getUrlBySkc($goval['product_id'], $goval['goods_id'], $goval['cn_alphabet']);
// $goods[$gokey]['thumb'] = $goval['goods_image'] && $goval['goods_image'] ? global.utils.getImageUrl($goval['goods_image'], 100, 100) : '';
// $goods[$gokey]['name'] = $goval['product_name'];
// $goods[$gokey]['color'] = $goval['color_name'];
// $goods[$gokey]['size'] = $goval['size_name'];
// $goods[$gokey]['price'] = $goval['goods_price'];
// let $buyNum = Number($goval['buy_number']);
// let $refundNum = Number($goval['refund_num']);
// $goods[$gokey]['count'] = $buyNum;
// $refundStatus = ($refundNum > 0) ? true : false; //只要发生一件退换,退换过的标记
// $goods[$gokey]['refundStatus'] = $refundStatus;
// $refundFlag = (($buyNum == $refundNum) && $refundNum > 0) ? 'finished' : 'unfinished'; //某一件商品全部退换结束
// $goods[$gokey]['arrivalDate'] = $goval['expect_arrival_time'];
// let $goodsTagName = self::getGoodsTag($orderV['attribute'], $goval['goods_type']);
// if ($goodsTagName) {
// $goods[$gokey][$goodsTagName] = true;
// }
// $orders[$orderK]['goods'] = $goods;
// });
// if($refundFlag.indexOf('unfinished')){
// $opRefundStatus = false;
// }
// $orders[$orderK]['pay'] = $orderV['amount']; //付款数
// $orders[$orderK]['fregit'] = $orderV['shipping_cost']; //邮费
// }
// //操作
// $orders[$orderK]['operation'] = getOperateInfo($orderV['attribute'], $orderV['is_cancel'], $orderV['status'], $orderV['payment_status'], $orderV['update_time'], $orderV['order_type'], $orderV['refund_status'], $orderV['payment_type'], $orderV['order_code'], $opRefundStatus);
// });
// if ($isPage) {
// $orders['pager']['total'] = $orderInfo['data']['total'];
// $orders['pager']['pageTotal'] = $orderInfo['data']['page_total'];
// $orders['pager']['page'] = $orderInfo['data']['page'];
// }
// return $orders;
// }
// })();
// }
// const latestOrders=($uid)=>{
// return co(function *(){
// let $orders=yield getOrders($uid, 1, 2, 1)
// return {
// more : helpers.url('/home/orders'),
// orders:$orders
// }
// })();
// }
module.exports = {
getInfoNumData,
getFooterBanner
};
}
// getBrandListUrl(){
// return this.SearchAPI.get('/yohosearch/brand/list.json', {},{cache:true});
// }
... ... @@ -112,7 +384,7 @@ class IndexModel extends global.mClass{
// return $hotBrands;
// }
// homeData(){
// let that=this;
//
// return co(function * (){
// let $result = {};
// let $url={};
... ... @@ -123,5 +395,5 @@ class IndexModel extends global.mClass{
// // $result.brand=$data.fav_brand&&!$data.fav_brand?
// }();
// }
}
module.exports = IndexModel;
// }
// module.exports = IndexModel;
... ...
'use strict';
class OrderData extends global.mClass{
const api = global.yoho.API;
/**
* 我的订单-分页
* @param type $uid
... ... @@ -9,7 +9,7 @@ class OrderData extends global.mClass{
* @param type $type 获取订单类型 type=1全部,type=2待付款,type=3待发货,type=4待收货,type=5待评论(已成功) 7取消
* @return type
*/
getUserOrders($uid, $page, $limit, $type){
exports.getUserOrders=($uid, $page, $limit, $type)=>{
$page=$page||1;
$limit=$limit||1;
$type=$type||1;
... ... @@ -20,7 +20,7 @@ class OrderData extends global.mClass{
page:$page,
limit:$limit
}
return this.API.get('', options);
return api.get('', options);
}
/**
* 订单详情
... ... @@ -28,13 +28,13 @@ class OrderData extends global.mClass{
* @param type $orderCode
* @return type
*/
getOrderDetail($uid, $orderCode){
exports.getOrderDetail=($uid, $orderCode)=>{
let options={
method: 'app.SpaceOrders.detail',
uid:$uid,
order_code:$orderCode
}
return this.API.get('',options);
return api.get('',options);
}
/**
* 取消订单
... ... @@ -42,7 +42,7 @@ class OrderData extends global.mClass{
* @param type $orderCode
* @return type
*/
cancelUserOrder($uid, $orderCode, $reason, $reasonId){
exports.cancelUserOrder=($uid, $orderCode, $reason, $reasonId)=>{
$reason=$reason||false;
$reasonId=$reasonId||false;
... ... @@ -57,7 +57,7 @@ class OrderData extends global.mClass{
reasons:$reason
});
}
return this.API.get('',options);
return api.get('',options);
}
/**
* 确认订单
... ... @@ -65,25 +65,25 @@ class OrderData extends global.mClass{
* @param type $orderCode
* @return type
*/
confirmUserOrder($uid, $orderCode){
exports.confirmUserOrder=($uid, $orderCode)=>{
let options={
method:'app.SpaceOrders.confirm',
uid:$uid,
order_code:$orderCode
}
return this.API.get('',options);
return api.get('',options);
}
/**
* 获取虚拟订单ticketCode
* @param type $orderCode
* @return type
*/
getTicketCode($orderCode){
exports.getTicketCode=($orderCode)=>{
let options={
method:'app.SpaceOrders.getQrByOrderCode',
order_code:$orderCode
}
return this.API.get('',options);
return api.get('',options);
}
/**
* 我的订单-查看物流
... ... @@ -92,13 +92,13 @@ class OrderData extends global.mClass{
* @param int $uid 用户ID
* @return array
*/
getLogisticsData($orderCode, $uid){
exports.getLogisticsData=($orderCode, $uid)=>{
let options={
method:'app.express.li',
order_code:$orderCode,
uid:$uid
};
return this.API.get('',options);
return api.get('',options);
}
/**
* 获取历史订单
... ... @@ -106,7 +106,7 @@ class OrderData extends global.mClass{
* @param type $page
* @param type $limit
*/
getHistoryOrders($uid, $page , $limit){
exports.getHistoryOrders=($uid, $page , $limit)=>{
$page=$page||1;
$limit=$limit||10;
let options={
... ... @@ -115,7 +115,7 @@ class OrderData extends global.mClass{
page:$page,
limit:$limit
}
return this.API.get('',options);
return api.get('',options);
}
/**
* 更新订单的支付方式
... ... @@ -125,24 +125,24 @@ class OrderData extends global.mClass{
* @param int $uid 用户ID
* @return array
*/
updateOrderPayment($orderCode, $payment, $uid){
exports.updateOrderPayment=($orderCode, $payment, $uid)=>{
let options={
method:'app.SpaceOrders.updateOrdersPaymentByCode',
order_code:Number($orderCode),
payment:$payment,
uid:$uid
}
return this.API.get('',options);
return api.get('',options);
}
/**
* 取消订单原因列表
* @return type
*/
closeReasons(){
exports.closeReasons=()=>{
let options={
method:'app.SpaceOrders.closeReasons'
}
return this.API.get('',options);
return api.get('',options);
}
/**
* 订单详情页——地址修改
... ... @@ -150,7 +150,7 @@ class OrderData extends global.mClass{
* @param type $address_id
* @return type
*/
updateDeliveryAddress($order_code, $user_name, $area_code, $address, $mobile, $phone){
exports.updateDeliveryAddress=($order_code, $user_name, $area_code, $address, $mobile, $phone)=>{
let options={
method:'app.SpaceOrders.updateDeliveryAddress',
order_code:$order_code,
... ... @@ -162,7 +162,7 @@ class OrderData extends global.mClass{
if($phone){
Object.assign(options,{phone:$phone})
}
return this.API.get('',options);
return api.get('',options);
}
/**
* 查看订单详情
... ... @@ -172,15 +172,12 @@ class OrderData extends global.mClass{
* @param string $sessionKey 用户会话
* @return array
*/
viewOrderData($orderCode, $uid, $sessionKey){
exports.viewOrderData=($orderCode, $uid, $sessionKey)=>{
let options={
method:'app.SpaceOrders.info',
order_code:$order_code,
uid:$uid,
session_key:$sessionKey
}
return this.API.get('',options);
return api.get('',options);
}
}
module.exports = OrderData;
... ...
... ... @@ -49,8 +49,6 @@ const homeNav = [
}
];
const OrderData = require('./models/OrderData');
const orderDate=new OrderData();
const getHomeNav = (req, res, next) => {
res.locals.path=[{href:helpers.urlFormat('/'),name:'YOHO!BUY 有货首页'},{name:'个人中心'}];
... ... @@ -90,9 +88,9 @@ const sessionEffective = (req, res, next) => {
// 查看二维码
router.get('/QRcode', [getCommonHeader, getHomeNav], personalController.QRcode);
var Account=require(`${cRoot}/Index`);
let account=new Account();
var Index=require(`${cRoot}/Index`);
router.get('/index', account.index);
router.get('/index', Index.index);
module.exports = router;
... ...