Toggle navigation
Toggle navigation
This project
Loading...
Sign in
fe
/
yoho-blk
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
1
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
jinhu.tung
9 years ago
Commit
dd4a62e8281ddb9d54d07bc43db96da78b21d682
1 parent
6556effd
server side set cookie
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
74 deletions
apps/shopping/controllers/cart.js
public/js/shopping/cart/cart.js
apps/shopping/controllers/cart.js
View file @
dd4a62e
...
...
@@ -14,6 +14,7 @@ exports.index = (req, res) => {
const
uid
=
req
.
user
.
uid
||
null
;
cartModel
.
getCartData
(
shoppingKey
,
uid
).
then
((
result
)
=>
{
// console.log(JSON.stringify(result, '', 4))
if
(
result
.
code
===
200
)
{
res
.
display
(
'cart'
,
_
.
merge
({
module
:
'shopping'
,
...
...
@@ -31,37 +32,6 @@ exports.index = (req, res) => {
});
};
// 检查库存
exports
.
checkInventory
=
(
req
,
res
)
=>
{
let
chkResult
,
invalidProIds
=
[],
productId
=
req
.
query
.
productId
,
result
=
{};
if
(
productId
===
'ALL'
)
{
chkResult
=
false
;
invalidProIds
.
push
(
'286143'
);
}
else
{
if
(
req
.
query
.
productId
===
'286143'
)
{
chkResult
=
false
;
}
else
{
chkResult
=
true
;
}
}
if
(
invalidProIds
.
length
)
{
_
.
merge
(
result
,
{
invalidProIds
:
invalidProIds
});
}
_
.
merge
(
result
,
{
valid
:
chkResult
});
res
.
json
(
result
);
};
// 修改数量
exports
.
changeProductNum
=
(
req
,
res
)
=>
{
...
...
@@ -71,13 +41,15 @@ exports.changeProductNum = (req, res) => {
const
uid
=
req
.
user
.
uid
;
const
shoppingKey
=
req
.
cookies
.
_SPK
;
const
sku
=
req
.
body
.
sku
;
const
goodTpye
=
req
.
body
.
goodType
;
if
(
changeType
===
'INCREASE'
)
{
cartModel
.
modifyProductNum
({
increaseNum
:
1
,
// 默认是1
uid
,
shoppingKey
,
sku
sku
,
goodTpye
}).
then
(
result
=>
{
console
.
log
(
'changeProductNum-INCREASE-result:'
,
result
);
if
(
result
.
code
===
200
)
{
...
...
@@ -102,7 +74,8 @@ exports.changeProductNum = (req, res) => {
decreaseNum
:
1
,
// 默认是1
uid
,
shoppingKey
,
sku
sku
,
goodTpye
}).
then
(
result
=>
{
console
.
log
(
'changeProductNum-DECREASE-result:'
,
result
);
if
(
result
.
code
===
200
)
{
...
...
@@ -199,6 +172,7 @@ exports.addToCart = (req, res) => {
shoppingKey
:
req
.
cookies
.
_SPK
||
null
,
uid
:
req
.
user
.
uid
}).
then
((
result
)
=>
{
res
.
cookie
(
'_SPK'
,
result
.
data
.
shopping_key
);
res
.
json
(
result
);
});
};
...
...
@@ -234,39 +208,5 @@ exports.toggleSelectGoods = (req, res) => {
});
};
// 购物车商品选择与取消选择
exports
.
modifyProductNum
=
(
req
,
res
)
=>
{
const
uid
=
req
.
user
.
uid
;
const
shoppingKey
=
req
.
cookies
.
_SPK
;
const
changeType
=
req
.
body
.
changeType
;
const
changeNum
=
req
.
body
.
changeNum
;
const
sku
=
req
.
body
.
sku
;
let
params
=
{
uid
,
shoppingKey
,
sku
};
if
(
changeType
===
'INCREASE'
)
{
_
.
merge
(
params
,
{
increaseNum
:
changeNum
});
}
else
if
(
changeType
===
'DECREASE'
)
{
_
.
merge
(
params
,
{
decreaseNum
:
changeNum
});
}
else
{
// TODO
// CHANGE
}
cartModel
.
modifyProductNum
(
params
).
then
(
result
=>
{
res
.
json
(
_
.
merge
(
cartModel
.
filterCartData
(
result
,
uid
),
{
code
:
result
.
code
,
message
:
result
.
message
}));
});
};
...
...
public/js/shopping/cart/cart.js
View file @
dd4a62e
...
...
@@ -11,7 +11,6 @@ var _confirm = Dialog.Confirm;
var
_alert
=
Dialog
.
Alert
;
var
Util
=
require
(
'./util'
);
var
hbs
=
require
(
'yoho-handlebars'
);
var
common
=
require
(
'../../common'
);
var
Stepper
=
require
(
'./stepper'
);
var
Cart
=
{
...
...
@@ -23,22 +22,16 @@ var Cart = {
* @params { Function } callback 购买结果回调
*/
addToCart
:
function
(
params
,
callback
)
{
// TODO
// common.setCookie('uid', '20000058');
Util
.
ajax
({
url
:
'/shopping/cart/add'
,
type
:
'POST'
,
data
:
params
,
success
:
function
(
res
)
{
if
(
res
.
code
===
200
)
{
common
.
setCookie
(
'_SPK'
,
res
.
data
.
shopping_key
);
if
(
callback
)
{
return
callback
(
res
);
}
}
},
fail
:
function
()
{
// TODO
}
});
},
...
...
Please
register
or
login
to post a comment