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
Plain Diff
Browse Files
Authored by
郭成尧
7 years ago
Commit
adbff0f399089acf51868f181be9f09bb5cce645
2 parents
05ec1731
725c8ae5
Merge branch 'feature/coupon' into release/180420
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
114 additions
and
33 deletions
apps/cart/controllers/buy-now-controller.js
apps/cart/controllers/order.js
apps/cart/models/buy-now-model.js
apps/cart/models/cart.js
apps/cart/views/action/select-coupons.hbs
apps/cart/views/partial/cart/coupon-info.hbs
apps/home/controllers/coupon-new.js
apps/home/views/action/coupons/page.hbs
public/js/cart/buynow-order-ensure.page.js
public/js/cart/order-ensure.js
utils/helpers.js
utils/payment-process.js
apps/cart/controllers/buy-now-controller.js
View file @
adbff0f
...
...
@@ -89,7 +89,8 @@ class BuyNowController {
uid
:
uid
,
product_sku
:
req
.
query
.
product_sku
,
sku_type
:
req
.
query
.
sku_type
,
buy_number
:
buy_number
buy_number
:
buy_number
,
delivery_way
:
orderInfo
.
delivery_way
}),
req
.
ctx
(
shoppingModel
).
countUsableGiftCard
(
uid
)
// 可用礼品卡数量
]);
...
...
@@ -131,7 +132,8 @@ class BuyNowController {
coupon
:
paymentProcess
.
handleCoupons
({
paymentApiCouponData
:
_
.
get
(
result
,
'data.coupon_pay'
,
{}),
validCouponCount
:
_
.
get
(
validCouponCount
,
'data.count'
,
0
),
orderComputeCouponPay
:
_
.
get
(
computeData
,
'data.coupon_pay'
)
orderComputeCouponPay
:
_
.
get
(
computeData
,
'data.coupon_pay'
),
userCheckCoupon
:
orderInfo
.
user_check_coupon
}),
selectAddressUrl
:
helpers
.
urlFormat
(
'/cart/index/buynow/selectAddress'
,
{
product_sku
:
product_sku
,
...
...
@@ -176,26 +178,51 @@ class BuyNowController {
* @param {*} next
*/
orderCompute
(
req
,
res
,
next
)
{
co
(
function
*
()
{
let
result
=
yield
req
.
ctx
(
BuyNowModel
).
compute
({
uid
:
req
.
user
.
uid
,
cart_type
:
req
.
body
.
cart_type
,
delivery_way
:
req
.
body
.
delivery_way
,
payment_type
:
req
.
body
.
payment_type
,
product_sku
:
req
.
body
.
product_sku
,
buy_number
:
req
.
body
.
buy_number
,
coupon_code
:
req
.
body
.
coupon_code
,
gift_card_code
:
req
.
body
.
gift_card_code
,
use_yoho_coin
:
req
.
body
.
use_yoho_coin
});
let
orderInfo
;
try
{
orderInfo
=
JSON
.
parse
(
req
.
cookies
.
buynow_info
);
}
catch
(
e
)
{
logger
.
info
(
`
orderEnsure
:
get
buynow
-
order
-
info
from
cookie
error
:
$
{
JSON
.
stringify
(
e
)}
`
);
orderInfo
=
{};
res
.
clearCookie
(
'buynow_info'
,
actCkOpthn
);
}
co
(
function
*
()
{
let
[
result
,
validCouponCount
]
=
yield
Promise
.
all
([
req
.
ctx
(
BuyNowModel
).
compute
({
uid
:
req
.
user
.
uid
,
cart_type
:
req
.
body
.
cart_type
,
delivery_way
:
req
.
body
.
delivery_way
,
payment_type
:
req
.
body
.
payment_type
,
product_sku
:
req
.
body
.
product_sku
,
buy_number
:
req
.
body
.
buy_number
,
coupon_code
:
req
.
body
.
coupon_code
,
gift_card_code
:
req
.
body
.
gift_card_code
,
use_yoho_coin
:
req
.
body
.
use_yoho_coin
}),
req
.
ctx
(
BuyNowModel
).
countUsableCoupon
({
uid
:
req
.
user
.
uid
,
product_sku
:
req
.
body
.
product_sku
,
sku_type
:
req
.
body
.
sku_type
,
buy_number
:
req
.
body
.
buy_number
,
delivery_way
:
req
.
body
.
delivery_way
})
]);
let
finalResult
=
_
.
get
(
result
,
'data'
,
{});
if
(
finalResult
)
{
_
.
set
(
finalResult
,
'use_yoho_coin'
,
paymentProcess
.
transPrice
(
_
.
get
(
result
,
'data.use_yoho_coin'
)));
_
.
set
(
finalResult
,
'yohoCoinCompute'
,
paymentProcess
.
yohoCoinCompute
(
result
.
data
));
_
.
set
(
finalResult
,
'coupon'
,
paymentProcess
.
handleCoupons
({
paymentApiCouponData
:
{},
validCouponCount
:
_
.
get
(
validCouponCount
,
'data.count'
,
0
),
orderComputeCouponPay
:
_
.
get
(
finalResult
,
'coupon_pay'
),
userCheckCoupon
:
orderInfo
.
user_check_coupon
}));
}
return
res
.
json
(
result
.
data
);
return
res
.
json
(
finalResult
);
})().
catch
(
next
);
}
...
...
apps/cart/controllers/order.js
View file @
adbff0f
...
...
@@ -163,6 +163,15 @@ exports.orderCompute = (req, res, next) => {
let
uid
=
req
.
user
.
uid
;
let
skuList
=
req
.
body
.
skuList
;
let
type
=
req
.
body
.
type
;
let
orderInfo
;
try
{
orderInfo
=
JSON
.
parse
(
req
.
cookies
[
'order-info'
]);
}
catch
(
e
)
{
logger
.
info
(
`
orderEnsure
:
get
orderInfo
from
cookie
error
:
$
{
JSON
.
stringify
(
e
)}
`
);
orderInfo
=
{};
res
.
clearCookie
(
'order-info'
,
actCkOpthn
);
}
if
(
type
!==
'tickets'
)
{
let
params
=
{
...
...
@@ -185,7 +194,8 @@ exports.orderCompute = (req, res, next) => {
}).
catch
(
next
);
}
else
{
req
.
ctx
(
cartModel
).
orderCompute
(
_
.
assign
(
params
,
{
product_sku_list
:
skuList
product_sku_list
:
skuList
,
userCheckCoupon
:
orderInfo
.
user_check_coupon
})).
then
(
result
=>
{
res
.
json
(
result
);
}).
catch
(
next
);
...
...
apps/cart/models/buy-now-model.js
View file @
adbff0f
...
...
@@ -20,7 +20,8 @@ class BuyNowModel extends global.yoho.BaseModel {
uid
:
params
.
uid
,
product_sku
:
params
.
product_sku
,
sku_type
:
params
.
sku_type
||
'I'
,
buy_number
:
params
.
buy_number
buy_number
:
params
.
buy_number
,
delivery_way
:
params
.
delivery_way
},
param
:
{
cache
:
false
...
...
apps/cart/models/cart.js
View file @
adbff0f
...
...
@@ -114,7 +114,8 @@ class cartModel extends global.yoho.BaseModel {
coupon
:
paymentProcess
.
handleCoupons
({
paymentApiCouponData
,
validCouponCount
:
validCouponCount
,
orderComputeCouponPay
:
orderCompute
.
coupon_pay
orderComputeCouponPay
:
orderCompute
.
coupon_pay
,
userCheckCoupon
:
orderInfoCookie
.
user_check_coupon
}),
giftCards
:
paymentProcess
.
handleGiftCards
({
validGiftCardCount
:
validGiftCardCount
,
...
...
@@ -130,11 +131,26 @@ class cartModel extends global.yoho.BaseModel {
* 购物车结算--支付方式和配送方式选择以及是否使用有货币接口返回的数据处理
*/
orderCompute
(
params
)
{
return
this
.
ctx
.
req
.
ctx
(
shoppingModel
).
orderComputeAPI
(
params
).
then
(
result
=>
{
if
(
result
&&
result
.
data
)
{
result
.
data
.
use_yoho_coin
=
paymentProcess
.
transPrice
(
result
.
data
.
use_yoho_coin
);
result
.
data
.
yohoCoinCompute
=
paymentProcess
.
yohoCoinCompute
(
result
.
data
);
return
result
.
data
;
return
Promise
.
all
([
this
.
ctx
.
req
.
ctx
(
shoppingModel
).
orderComputeAPI
(
params
),
this
.
ctx
.
req
.
ctx
(
shoppingModel
).
getValidCouponCount
({
uid
:
params
.
uid
,
delivery_way
:
params
.
delivery_way
})
]).
then
(
result
=>
{
let
computerResult
=
result
[
0
];
let
validCouponCount
=
_
.
get
(
result
[
1
],
'data.count'
,
0
);
if
(
computerResult
&&
computerResult
.
data
)
{
computerResult
.
data
.
use_yoho_coin
=
paymentProcess
.
transPrice
(
computerResult
.
data
.
use_yoho_coin
);
computerResult
.
data
.
yohoCoinCompute
=
paymentProcess
.
yohoCoinCompute
(
computerResult
.
data
);
computerResult
.
data
.
coupon
=
paymentProcess
.
handleCoupons
({
paymentApiCouponData
:
{},
validCouponCount
:
validCouponCount
,
orderComputeCouponPay
:
_
.
get
(
computerResult
,
'data.coupon_pay'
),
userCheckCoupon
:
params
.
user_check_coupon
});
return
computerResult
.
data
;
}
else
{
return
{};
}
...
...
apps/cart/views/action/select-coupons.hbs
View file @
adbff0f
{{#
result
}}
<section>
<div
class=
"filter-box"
>
<span
class=
"filter-btn valid active"
data-num=
"
{{
usableCouponNumStr
}}
"
>
可用(
{{
usableCouponNumStr
}}
)
</span>
<span
class=
"filter-btn invalid"
data-num=
"
{{
unusableCouponNumStr
}}
"
>
不可用(
{{
unusableCouponNumStr
}}
)
</span>
<span
class=
"filter-btn valid active"
data-num=
"
{{
usableCouponNumStr
}}
"
>
可用
{{#
notEqualEither
usableCouponNumStr
'0'
}}
(
{{
usableCouponNumStr
}}
)
{{/
notEqualEither
}}
</span>
<span
class=
"filter-btn invalid"
data-num=
"
{{
unusableCouponNumStr
}}
"
>
不可用
{{#
notEqualEither
unusableCouponNumStr
'0'
}}
(
{{
unusableCouponNumStr
}}
)
{{/
notEqualEither
}}
</span>
</div>
<div
class=
"exchange-box"
>
<input
type=
"text"
name=
"couponCodeInput"
placeholder=
"请输入优惠券码"
>
...
...
apps/cart/views/partial/cart/coupon-info.hbs
View file @
adbff0f
...
...
@@ -10,7 +10,7 @@
{{
showText
}}
</span>
<span
class=
"coupon-info pull-right
{{#
isEqualOr
info
'无可用'
}}
no-can-use
{{/
isEqualOr
}}
"
>
{{
priceText
}}
<span
class=
"coupon-price-info"
>
{{
priceText
}}
</span>
<i
class=
"iconfont"
>

</i>
</span>
{{/if}}
...
...
apps/home/controllers/coupon-new.js
View file @
adbff0f
...
...
@@ -35,9 +35,9 @@ class CouponNew {
let
pageData
=
_
.
get
(
couponsApi
,
'data'
,
{});
let
couponNum
=
_
.
get
(
couponNumApi
,
'data'
,
null
);
let
couponNumStr
=
{
notuse
:
0
,
use
:
0
,
overtime
:
0
notuse
:
'0'
,
use
:
'0'
,
overtime
:
'0'
};
let
couponList
=
_
.
get
(
pageData
,
'couponList'
,
[]);
...
...
apps/home/views/action/coupons/page.hbs
View file @
adbff0f
...
...
@@ -2,14 +2,14 @@
{{#
couponNumStr
}}
<div
class=
"filter-box"
>
<span
class=
"filter-btn-box"
>
<span
class=
"filter-btn no-used active"
data-num=
"
{{
notuse
}}
"
>
未使用
(
{{
notuse
}}
)
</span>
<span
class=
"filter-btn no-used active"
data-num=
"
{{
notuse
}}
"
>
未使用
{{#
notEqualEither
notuse
'0'
}}
(
{{
notuse
}}
)
{{/
notEqualEither
}}
</span>
<span
class=
"iconfont icon-down show-filter-btn active"
></span>
</span>
<span
class=
"filter-btn-box"
>
<span
class=
"filter-btn used"
data-num=
"
{{
use
}}
"
>
已使用
(
{{
use
}}
)
</span>
<span
class=
"filter-btn used"
data-num=
"
{{
use
}}
"
>
已使用
{{#
notEqualEither
use
'0'
}}
(
{{
use
}}
)
{{/
notEqualEither
}}
</span>
</span>
<span
class=
"filter-btn-box"
>
<span
class=
"filter-btn invalid"
data-num=
"
{{
overtime
}}
"
>
已失效
(
{{
overtime
}}
)
</span>
<span
class=
"filter-btn invalid"
data-num=
"
{{
overtime
}}
"
>
已失效
{{#
notEqualEither
overtime
'0'
}}
(
{{
overtime
}}
)
{{/
notEqualEither
}}
</span>
</span>
</div>
{{/
couponNumStr
}}
...
...
public/js/cart/buynow-order-ensure.page.js
View file @
adbff0f
...
...
@@ -131,6 +131,8 @@ function orderCompute() {
$
(
'.price-cost span'
).
html
(
'¥'
+
res
.
last_order_amount
);
$
(
'.bill span'
).
html
(
'¥'
+
res
.
last_order_amount
);
$
(
'.total'
).
html
(
total
);
$
(
'.coupon .count'
).
html
(
res
.
coupon
.
showText
);
$
(
'.coupon .coupon-price-info'
).
html
(
res
.
coupon
.
priceText
);
}
updateDeliverWay
(
deliver_way
);
...
...
public/js/cart/order-ensure.js
View file @
adbff0f
...
...
@@ -173,6 +173,8 @@ function orderCompute() {
$
(
'.price-cost span'
).
html
(
'¥'
+
res
.
last_order_amount
);
$
(
'.bill span'
).
html
(
'¥'
+
res
.
last_order_amount
);
$
(
'.total'
).
html
(
total
);
$
(
'.coupon .count'
).
html
(
res
.
coupon
.
showText
);
$
(
'.coupon .coupon-price-info'
).
html
(
res
.
coupon
.
priceText
);
}
updateDeliverId
(
deliverId
);
...
...
utils/helpers.js
View file @
adbff0f
...
...
@@ -180,6 +180,27 @@ module.exports = {
return
opt
.
inverse
(
this
);
// eslint-disable-line
}
},
notEqualEither
:
function
()
{
let
args
=
Array
.
prototype
.
slice
.
call
(
arguments
);
let
v1
=
args
[
0
];
let
opt
=
args
[
args
.
length
-
1
];
let
isTrue
=
false
;
for
(
let
i
=
1
;
i
<
args
.
length
-
1
;
i
++
)
{
if
(
v1
===
args
[
i
])
{
isTrue
=
true
;
break
;
}
}
if
(
!
isTrue
)
{
return
opt
.
fn
(
this
);
// eslint-disable-line
}
else
{
return
opt
.
inverse
(
this
);
// eslint-disable-line
}
},
ifand
:
function
()
{
let
args
=
Array
.
prototype
.
slice
.
call
(
arguments
);
let
opt
=
args
[
args
.
length
-
1
];
...
...
utils/payment-process.js
View file @
adbff0f
...
...
@@ -366,7 +366,9 @@ function handleCoupons(params) {
showText
=
`
$
{
validCouponCount
}
张可用`
;
}
if
(
!
_
.
isEmpty
(
orderComputeCouponPay
)
&&
couponData
.
coupon_count
)
{
if
(
!
_
.
isEmpty
(
orderComputeCouponPay
)
&&
couponData
.
coupon_count
&&
params
.
userCheckCoupon
===
'Y'
)
{
showText
=
`已选
$
{
couponData
.
coupon_count
}
张`
;
priceText
=
`
-
¥
$
{
couponData
.
coupon_amount_str
}
`
;
}
...
...
Please
register
or
login
to post a comment