Toggle navigation
Toggle navigation
This project
Loading...
Sign in
fe
/
yohobuywap-node
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
李靖
8 years ago
Commit
13d10ad545910116efaa52443e5898fe8f7c701e
1 parent
1ffb9b33
消息
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
182 additions
and
181 deletions
apps/home/controllers/message.js
apps/home/models/message.js
apps/home/controllers/message.js
View file @
13d10ad
...
...
@@ -4,7 +4,7 @@ const headerModel = require('../../../doraemon/models/header'), // 头部model
model
=
require
(
'../models/message'
);
const
_getList
=
(
req
,
res
,
next
)
=>
{
model
.
getList
({
req
.
ctx
(
model
)
.
getList
({
page
:
req
.
body
.
page
,
size
:
20
,
uid
:
req
.
user
.
uid
,
...
...
@@ -26,7 +26,7 @@ const _getList = (req, res, next) => {
};
const
_msgDetail
=
(
req
,
res
,
next
)
=>
{
model
.
getList
({
req
.
ctx
(
model
)
.
getList
({
page
:
req
.
body
.
page
,
size
:
1000
,
msgid
:
req
.
query
.
id
,
...
...
@@ -61,7 +61,7 @@ exports.index = (req, res, next) => {
};
exports
.
ajaxDelMes
=
(
req
,
res
,
next
)
=>
{
model
.
delMsg
({
req
.
ctx
(
model
)
.
delMsg
({
uid
:
req
.
user
.
uid
,
msgid
:
req
.
body
.
id
,
}).
then
(
result
=>
{
...
...
@@ -71,7 +71,7 @@ exports.ajaxDelMes = (req, res, next) => {
};
exports
.
pickCoupon
=
(
req
,
res
,
next
)
=>
{
model
.
pickCoupon
({
req
.
ctx
(
model
)
.
pickCoupon
({
uid
:
req
.
user
.
uid
,
couponId
:
req
.
body
.
id
,
}).
then
(
result
=>
{
...
...
@@ -92,7 +92,7 @@ exports.birthCoupon = (req, res, next) => {
pageFooter
:
true
};
model
.
_getBirthCouponById
(
req
.
user
.
uid
).
then
(
result
=>
{
req
.
ctx
(
model
)
.
_getBirthCouponById
(
req
.
user
.
uid
).
then
(
result
=>
{
res
.
render
(
'birth-coupon'
,
Object
.
assign
(
responseData
,
result
));
}).
catch
(
next
);
};
...
...
apps/home/models/message.js
View file @
13d10ad
...
...
@@ -15,199 +15,200 @@ const _formatDay = (day) => {
return
moment
(
day
).
format
(
'YYYY.MM.DD'
);
};
// 获取列表页
const
_list
=
(
result
)
=>
{
let
final
=
[];
if
(
result
.
data
&&
result
.
data
.
list
)
{
// PHP排序了,应该不用
for
(
let
item
of
result
.
data
.
list
)
{
let
obj
=
{
id
:
item
.
id
,
isNotReaded
:
item
.
is_read
===
'Y'
?
false
:
true
,
title
:
item
.
title
,
time
:
`
$
{
item
.
create_date
}
$
{
_formatTime
(
item
.
create_time
*
1000
)}
`
,
};
if
(
item
.
body
&&
item
.
type
===
'pullCoupon'
)
{
Object
.
assign
(
obj
,
{
birthType
:
true
,
// name: item.body.name,
// collarTime: item.body.collar_time,
// useTime: item.body.use_time,
isCollar
:
item
.
body
.
is_collar
===
'Y'
?
true
:
false
,
isOverTime
:
item
.
body
.
is_over_time
===
'Y'
?
true
:
false
});
}
class
messageModel
extends
global
.
yoho
.
BaseModel
{
constructor
(
ctx
)
{
super
(
ctx
);
}
// 获取列表页
_list
(
result
)
{
let
final
=
[];
if
(
result
.
data
&&
result
.
data
.
list
)
{
// PHP排序了,应该不用
for
(
let
item
of
result
.
data
.
list
)
{
let
obj
=
{
id
:
item
.
id
,
isNotReaded
:
item
.
is_read
===
'Y'
?
false
:
true
,
title
:
item
.
title
,
time
:
`
$
{
item
.
create_date
}
$
{
_formatTime
(
item
.
create_time
*
1000
)}
`
,
};
if
(
item
.
body
&&
item
.
type
===
'pullCoupon'
)
{
Object
.
assign
(
obj
,
{
birthType
:
true
,
final
.
push
(
obj
);
// name: item.body.name,
// collarTime: item.body.collar_time,
// useTime: item.body.use_time,
isCollar
:
item
.
body
.
is_collar
===
'Y'
?
true
:
false
,
isOverTime
:
item
.
body
.
is_over_time
===
'Y'
?
true
:
false
});
}
final
.
push
(
obj
);
}
}
return
final
;
}
return
final
;
};
// 获取生日信息
const
_getBirthCouponById
=
(
uid
)
=>
{
return
api
.
get
(
''
,
{
method
:
'app.promotion.queryBirthCoupon'
,
uid
:
uid
,
couponType
:
4
,
}).
then
(
result
=>
{
if
(
result
&&
result
.
data
)
{
let
final
=
{
ticket
:
[]
};
final
.
birthType
=
true
;
if
(
result
.
data
.
list
&&
result
.
data
.
list
[
0
].
body
.
is_collar
===
'Y'
)
{
final
=
{
isCollar
:
true
// 获取生日信息
_getBirthCouponById
(
uid
)
{
return
api
.
get
(
''
,
{
method
:
'app.promotion.queryBirthCoupon'
,
uid
:
uid
,
couponType
:
4
,
}).
then
(
result
=>
{
if
(
result
&&
result
.
data
)
{
let
final
=
{
ticket
:
[]
};
}
else
{
if
(
result
.
data
&&
!
result
.
data
[
0
].
err
)
{
for
(
let
coupon
of
result
.
data
)
{
final
.
ticket
.
push
({
id
:
coupon
.
id
?
coupon
.
id
:
''
,
couponAmount
:
coupon
.
couponAmount
,
couponName
:
coupon
.
couponName
.
split
(
'-'
)[
0
],
startTime
:
_formatDay
(
coupon
.
startTime
),
endTime
:
_formatDay
(
coupon
.
endTime
),
useLimit
:
coupon
.
useLimit
});
}
}
else
{
final
.
birthType
=
true
;
if
(
result
.
data
.
list
&&
result
.
data
.
list
[
0
].
body
.
is_collar
===
'Y'
)
{
final
=
{
err
:
result
.
data
[
0
].
err
isCollar
:
true
};
}
else
{
if
(
result
.
data
&&
!
result
.
data
[
0
].
err
)
{
for
(
let
coupon
of
result
.
data
)
{
final
.
ticket
.
push
({
id
:
coupon
.
id
?
coupon
.
id
:
''
,
couponAmount
:
coupon
.
couponAmount
,
couponName
:
coupon
.
couponName
.
split
(
'-'
)[
0
],
startTime
:
_formatDay
(
coupon
.
startTime
),
endTime
:
_formatDay
(
coupon
.
endTime
),
useLimit
:
coupon
.
useLimit
});
}
}
else
{
final
=
{
err
:
result
.
data
[
0
].
err
};
}
}
}
return
final
;
}
else
{
if
(
result
.
code
===
410
)
{
return
[{
err
:
result
.
message
}];
}
else
if
(
result
.
code
===
411
)
{
return
[{
err
:
result
.
message
}];
return
final
;
}
else
{
return
[];
if
(
result
.
code
===
410
)
{
return
[{
err
:
result
.
message
}];
}
else
if
(
result
.
code
===
411
)
{
return
[{
err
:
result
.
message
}];
}
else
{
return
[];
}
}
}
});
};
});
}
// 获取详情页
const
_detail
=
(
result
,
id
)
=>
{
let
final
=
{};
if
(
result
.
data
&&
result
.
data
.
list
)
{
for
(
let
item
of
result
.
data
.
list
)
{
if
(
item
.
id
===
Number
(
id
)
&&
item
.
type
!==
'showGetCoin'
&&
item
.
type
!==
'notice'
)
{
final
.
sender
=
item
.
from
;
final
.
title
=
item
.
title
;
final
.
time
=
`
$
{
item
.
create_date
}
$
{
_formatTime
(
item
.
create_time
*
1000
)}
`
;
// 时间
// 判断消息类型
switch
(
item
.
type
)
{
case
'button'
:
// 促销活动
if
(
item
.
body
)
{
final
.
sale
=
{
image
:
item
.
body
.
image
?
item
.
body
.
image
:
''
,
content
:
item
.
body
.
text
?
item
.
body
.
text
:
''
,
btnLink
:
item
.
body
.
pc_link
?
item
.
body
.
pc_link
:
''
,
btnName
:
item
.
body
.
button_text
?
item
.
body
.
button_text
:
''
,
// 获取详情页
_detail
(
result
,
id
)
{
let
final
=
{};
if
(
result
.
data
&&
result
.
data
.
list
)
{
for
(
let
item
of
result
.
data
.
list
)
{
if
(
item
.
id
===
Number
(
id
)
&&
item
.
type
!==
'showGetCoin'
&&
item
.
type
!==
'notice'
)
{
final
.
sender
=
item
.
from
;
final
.
title
=
item
.
title
;
final
.
time
=
`
$
{
item
.
create_date
}
$
{
_formatTime
(
item
.
create_time
*
1000
)}
`
;
// 时间
// 判断消息类型
switch
(
item
.
type
)
{
case
'button'
:
// 促销活动
if
(
item
.
body
)
{
final
.
sale
=
{
image
:
item
.
body
.
image
?
item
.
body
.
image
:
''
,
content
:
item
.
body
.
text
?
item
.
body
.
text
:
''
,
btnLink
:
item
.
body
.
pc_link
?
item
.
body
.
pc_link
:
''
,
btnName
:
item
.
body
.
button_text
?
item
.
body
.
button_text
:
''
,
};
}
break
;
case
'pushCoupon'
:
// 查看优惠券
if
(
item
.
body
)
{
final
.
coupons
=
[];
final
.
coupons
.
push
({
remark
:
item
.
body
.
coupon_name
?
item
.
body
.
coupon_name
:
''
,
useTime
:
item
.
body
.
time
?
item
.
body
.
time
:
''
,
id
:
item
.
body
.
inboxId
?
item
.
body
.
inboxId
:
''
,
price
:
item
.
body
.
price
?
item
.
body
.
price
:
''
,
url
:
helpers
.
urlFormat
(
'/home/coupons'
,
{
t
:
(
new
Date
().
getTime
())
/
1000
,
}),
});
}
break
;
default
:
// 普通文本
final
.
text
=
{
content
:
item
.
body
.
content
?
item
.
body
.
content
:
''
,
};
}
break
;
case
'pushCoupon'
:
// 查看优惠券
if
(
item
.
body
)
{
final
.
coupons
=
[];
final
.
coupons
.
push
({
remark
:
item
.
body
.
coupon_name
?
item
.
body
.
coupon_name
:
''
,
useTime
:
item
.
body
.
time
?
item
.
body
.
time
:
''
,
id
:
item
.
body
.
inboxId
?
item
.
body
.
inboxId
:
''
,
price
:
item
.
body
.
price
?
item
.
body
.
price
:
''
,
url
:
helpers
.
urlFormat
(
'/home/coupons'
,
{
t
:
(
new
Date
().
getTime
())
/
1000
,
}),
});
}
break
;
default
:
// 普通文本
final
.
text
=
{
content
:
item
.
body
.
content
?
item
.
body
.
content
:
''
,
};
break
;
break
;
}
}
}
}
return
final
;
}
return
final
;
};
// 获取列表或详情
const
getList
=
(
params
)
=>
{
return
api
.
get
(
''
,
{
method
:
'app.inbox.getlist'
,
page
:
params
.
page
||
1
,
size
:
params
.
size
||
10
,
uid
:
params
.
uid
,
}).
then
(
result
=>
{
if
(
params
.
msgid
)
{
// 绕的一比
return
_detail
(
result
,
params
.
msgid
);
}
else
{
return
_list
(
result
);
}
});
};
// 获取列表或详情
getList
(
params
)
{
return
api
.
get
(
''
,
{
method
:
'app.inbox.getlist'
,
page
:
params
.
page
||
1
,
size
:
params
.
size
||
10
,
uid
:
params
.
uid
,
}).
then
(
result
=>
{
if
(
params
.
msgid
)
{
// 绕的一比
return
this
.
_detail
(
result
,
params
.
msgid
);
}
else
{
return
this
.
_list
(
result
);
}
});
}
// 删除消息
const
delMsg
=
(
params
)
=>
{
return
api
.
get
(
''
,
{
method
:
'app.inbox.delmessage'
,
uid
:
params
.
uid
,
id
:
params
.
msgid
,
}).
then
(
result
=>
{
if
(
result
&&
result
.
code
===
200
)
{
return
{
code
:
200
};
}
else
{
return
{
code
:
400
,
message
:
'出错啦~'
,
};
}
});
};
// 删除消息
delMsg
(
params
)
{
return
api
.
get
(
''
,
{
method
:
'app.inbox.delmessage'
,
uid
:
params
.
uid
,
id
:
params
.
msgid
,
}).
then
(
result
=>
{
if
(
result
&&
result
.
code
===
200
)
{
return
{
code
:
200
};
}
else
{
return
{
code
:
400
,
message
:
'出错啦~'
,
};
}
});
}
// 领取优惠券
const
pickCoupon
=
(
params
)
=>
{
return
api
.
get
(
''
,
{
method
:
'app.promotion.getCoupon'
,
uid
:
params
.
uid
,
couponId
:
params
.
couponId
,
}).
then
(
result
=>
{
if
(
result
&&
result
.
code
===
200
)
{
return
{
code
:
200
};
}
else
{
return
{
code
:
result
.
code
,
message
:
result
.
message
,
};
}
});
};
// 领取优惠券
pickCoupon
(
params
)
{
return
api
.
get
(
''
,
{
method
:
'app.promotion.getCoupon'
,
uid
:
params
.
uid
,
couponId
:
params
.
couponId
,
}).
then
(
result
=>
{
if
(
result
&&
result
.
code
===
200
)
{
return
{
code
:
200
};
}
else
{
return
{
code
:
result
.
code
,
message
:
result
.
message
,
};
}
});
}
}
module
.
exports
=
{
getList
,
delMsg
,
pickCoupon
,
_getBirthCouponById
};
module
.
exports
=
messageModel
;
...
...
Please
register
or
login
to post a comment