-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
taxus
authored and
taxus
committed
Nov 17, 2017
1 parent
c49abd2
commit dce321c
Showing
25 changed files
with
4,155 additions
and
277 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package controllers | ||
|
||
import ( | ||
"fresh/model" | ||
porder "fresh/proto/order" | ||
"log" | ||
|
||
"github.com/kataras/iris" | ||
) | ||
|
||
type orderController struct { | ||
*controller | ||
} | ||
|
||
// Create 创建订单 | ||
func (c *orderController) Create(ctx iris.Context) { | ||
params := &porder.CreateParam{} | ||
if err := c.ReadProto(ctx, params); err != nil { | ||
ctx.Text(err.Error()) | ||
return | ||
} | ||
|
||
u, err := model.LoadUserBy(ctx.GetHeader("token")) | ||
if err != nil { | ||
ctx.Text(err.Error()) | ||
return | ||
} | ||
|
||
cs, err := model.LoadSelectedCarts(u.ID) | ||
if err != nil { | ||
ctx.Text(err.Error()) | ||
return | ||
} | ||
|
||
ua, err := model.LoadShippingAddress(params.AddressID) | ||
if err != nil { | ||
ctx.Text(err.Error()) | ||
return | ||
} | ||
|
||
s, err := model.LoadShippingBy("sto_express") | ||
if err != nil { | ||
ctx.Text(err.Error()) | ||
return | ||
} | ||
|
||
o := model.NewOrder() | ||
log.Println(o) | ||
if err := o.Create(cs, ua, params.Remark, s, u.ID); err != nil { | ||
ctx.Text(err.Error()) | ||
log.Println(err) | ||
return | ||
} | ||
|
||
result := &porder.Order{ | ||
ID: o.ID, | ||
OrderSN: o.OrderSN, | ||
TotalAmount: o.TotalAmount, | ||
} | ||
c.WriteProto(ctx, result) | ||
} | ||
|
||
// List 订单列表 | ||
func (c *orderController) List(ctx iris.Context) { | ||
u, err := model.LoadUserBy(ctx.GetHeader("token")) | ||
if err != nil { | ||
ctx.Text(err.Error()) | ||
return | ||
} | ||
|
||
owgs, err := model.LoadOrderList(u.ID) | ||
if err != nil { | ||
ctx.Text(err.Error()) | ||
return | ||
} | ||
|
||
presult := &porder.List{} | ||
powgs := make([]*porder.List_OrderWithGoods, len(owgs)) | ||
for i, v := range owgs { | ||
powg := &porder.List_OrderWithGoods{ | ||
Order: &porder.List_OrderWithGoods_Order{ | ||
ID: v.Order.ID, | ||
OrderState: uint32(v.Order.OrderState), | ||
OrderSN: v.Order.OrderSN, | ||
ShippingState: uint32(v.Order.ShippingState), | ||
PayState: uint32(v.Order.PayState), | ||
GoodsPrice: v.Order.GoodsPrice, | ||
ShippingPrice: v.Order.ShippingPrice, | ||
OrderAmount: v.Order.OrderAmount, | ||
TotalAmount: v.Order.TotalAmount, | ||
AddTime: v.Order.AddTime, | ||
UserNote: v.Order.UserNote, | ||
AdminNote: v.Order.AdminNote, | ||
}, | ||
} | ||
|
||
pogs := make([]*porder.List_OrderWithGoods_OrderGoods, len(v.OrderGoodses)) | ||
for j, v1 := range v.OrderGoodses { | ||
pog := &porder.List_OrderWithGoods_OrderGoods{ | ||
ID: v1.ID, | ||
OrderID: v1.OrderID, | ||
GoodsID: v1.GoodsID, | ||
GoodsName: v1.GoodsName, | ||
GoodsNum: uint32(v1.GoodsNum), | ||
GoodsPrice: v1.GoodsPrice, | ||
CostPrice: v1.CostPrice, | ||
SpecKeyName: v1.SpecKeyName, | ||
} | ||
pogs[j] = pog | ||
} | ||
|
||
powg.OrderGoodses = pogs | ||
powgs[i] = powg | ||
} | ||
presult.Orders = powgs | ||
|
||
c.WriteProto(ctx, presult) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,8 @@ | ||
package controllers | ||
|
||
import ( | ||
"fresh/model" | ||
puser "fresh/proto/user" | ||
|
||
"github.com/kataras/iris" | ||
) | ||
|
||
type userController struct { | ||
*controller | ||
} | ||
|
||
func (c *userController) Get() { | ||
} | ||
|
||
// AllAddress 用户所有地址 | ||
func (c *userController) AllAddress(ctx iris.Context) { | ||
u, err := model.LoadUserBy(ctx.GetHeader("token")) | ||
if err != nil { | ||
ctx.Text(err.Error()) | ||
return | ||
} | ||
|
||
as, err := model.LoadUserAddress(u.ID) | ||
if err != nil { | ||
ctx.Text(err.Error()) | ||
return | ||
} | ||
c.WriteProto(ctx, c.convAddresses(as)) | ||
} | ||
|
||
// DefatultAddress 默认收货地址 | ||
func (c *userController) DefatultAddress(ctx iris.Context) { | ||
u, err := model.LoadUserBy(ctx.GetHeader("token")) | ||
if err != nil { | ||
ctx.Text(err.Error()) | ||
return | ||
} | ||
|
||
a, err := model.LoadDefaultAddress(u.ID) | ||
if err != nil { | ||
ctx.Text(err.Error()) | ||
return | ||
} | ||
|
||
c.WriteProto(ctx, c.convAddress(a)) | ||
} | ||
|
||
func (c *userController) convAddresses(as []*model.UserAddress) *puser.AllAddress { | ||
plist := &puser.AllAddress{} | ||
list := make([]*puser.Address, len(as)) | ||
for i, v := range as { | ||
list[i] = c.convAddress(v) | ||
} | ||
plist.Addresses = list | ||
return plist | ||
} | ||
|
||
func (c *userController) convAddress(a *model.UserAddress) *puser.Address { | ||
return &puser.Address{ | ||
ID: a.ID, | ||
Consignee: a.Consignee, | ||
Country: a.Country, | ||
Province: a.Province, | ||
City: a.City, | ||
District: a.District, | ||
Twon: a.Twon, | ||
Address: a.Address, | ||
Zipcode: a.Zipcode, | ||
Mobile: a.Mobile, | ||
IsDefault: a.IsDefault, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,10 @@ | ||
package model | ||
|
||
import ( | ||
"log" | ||
"testing" | ||
) | ||
|
||
func TestLoadAd(t *testing.T) { | ||
ads, err := LoadAds(9) | ||
checkErr(err) | ||
|
||
for _, v := range *ads { | ||
log.Printf("获取广告: %v \n", v) | ||
} | ||
} | ||
// func TestLoadAd(t *testing.T) { | ||
// ads, err := LoadAds(9) | ||
// checkErr(err) | ||
// | ||
// for _, v := range *ads { | ||
// log.Printf("获取广告: %v \n", v) | ||
// } | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.