From 3d09bd9a1f19583b0ee83ae893137358890f9642 Mon Sep 17 00:00:00 2001 From: RIceWqy <1840169763@qq.com> Date: Fri, 29 Dec 2023 19:15:40 +0800 Subject: [PATCH] goods --- init/init.go | 2 +- jsonrpc.json | 159 ++++++++++++++--- jyuan.json | 73 +++++--- module/cart/Cart.go | 55 ++++++ module/cart/init.go | 109 ++++++++++++ module/order/Order.go | 107 +++++++----- module/order/init.go | 311 ++++++++++++++++++++++++++++++++++ module/orderItem/OrderItem.go | 55 ------ module/orderItem/init.go | 12 -- 9 files changed, 722 insertions(+), 161 deletions(-) create mode 100644 module/cart/Cart.go create mode 100644 module/cart/init.go delete mode 100644 module/orderItem/OrderItem.go delete mode 100644 module/orderItem/init.go diff --git a/init/init.go b/init/init.go index e7bf036..01a9be3 100644 --- a/init/init.go +++ b/init/init.go @@ -11,4 +11,4 @@ import _ "src/module/good_category_re" import _ "src/module/sku" import _ "src/module/address" import _ "src/module/order" -import _ "src/module/orderItem" +import _ "src/module/cart" diff --git a/jsonrpc.json b/jsonrpc.json index b8e4028..813879b 100644 --- a/jsonrpc.json +++ b/jsonrpc.json @@ -1,24 +1,139 @@ { - "id": 1, - "username": "13369437728", - "nickname": "", - "password": "", - "email": "", - "mobile": "13369437728", - "token": "0f09fda89955c44b0e93b4af4c93194c", - "created_at": 0, - "updated_at": 0, - "group_id": 0, - "avatar": "", - "birthday": "", - "money": "", - "score": 0, - "child_user_count": 0, - "child_user_count_1": 0, - "child_user_count_2": 0, - "total_consume": "", - "user_id": 1, - "createtime": 0, - "expiretime": 0, - "expires_in": 0 + "id": 8405, + "type": "goods", + "order_sn": "202303165939181001191100", + "user_id": 11911, + "activity_type": "", + "goods_amount": "8.00", + "dispatch_amount": "0.00", + "phone": "13369437728", + "consignee": "我去", + "province_name": "上海市", + "city_name": "上海市", + "area_name": "黄浦区", + "address": "123123", + "province_id": 310000, + "city_id": 310100, + "area_id": 310101, + "status": 0, + "invoice_status": "0", + "memo": null, + "remark": "", + "total_amount": "8.00", + "score_amount": 0, + "total_fee": "8.00", + "last_total_fee": "0.00", + "discount_fee": "0.00", + "coupon_fee": "0.00", + "activity_discount_money": "0.00", + "dispatch_discount_money": "0.00", + "pay_fee": "0.00", + "score_fee": 0, + "goods_original_amount": "44.00", + "coupons_id": 0, + "transaction_id": null, + "payment_json": null, + "pay_type": null, + "paytime": null, + "ext": "{\"buy_type\":\"alone\",\"groupon_id\":0,\"expired_time\":1703748719}", + "platform": "H5", + "createtime": 1703747819, + "item": [ + { + "id": 9257, + "user_id": 11911, + "order_id": 8405, + "goods_id": 1416, + "goods_type": "normal", + "goods_sku_price_id": 2368, + "activity_id": 0, + "activity_type": null, + "item_goods_sku_price_id": 0, + "goods_sku_text": "绿色,m", + "goods_title": "多规格", + "goods_image": "https:\/\/demo.shopro.top\/uploads\/20230821\/00e97b4723771626fb44bdbf56d35a73.jpg", + "goods_original_price": "22.00", + "discount_fee": "0.00", + "goods_price": "4.00", + "goods_num": 1, + "goods_weight": 0, + "pay_price": "4.00", + "dispatch_status": 0, + "dispatch_fee": "0.00", + "dispatch_type": "express", + "dispatch_id": 23, + "store_id": 0, + "aftersale_status": 0, + "comment_status": 0, + "refund_status": 0, + "refund_fee": null, + "refund_msg": null, + "express_name": null, + "express_code": null, + "express_no": null, + "ext": "[]", + "createtime": 1703747819, + "updatetime": 1703747819, + "status_code": "nopay", + "status_name": "", + "status_desc": "", + "btns": [], + "ext_arr": [], + "status_text": "" + }, + { + "id": 9258, + "user_id": 11911, + "order_id": 8405, + "goods_id": 1416, + "goods_type": "normal", + "goods_sku_price_id": 2368, + "activity_id": 0, + "activity_type": null, + "item_goods_sku_price_id": 0, + "goods_sku_text": "绿色,m", + "goods_title": "多规格", + "goods_image": "https:\/\/demo.shopro.top\/uploads\/20230821\/00e97b4723771626fb44bdbf56d35a73.jpg", + "goods_original_price": "22.00", + "discount_fee": "0.00", + "goods_price": "4.00", + "goods_num": 1, + "goods_weight": 0, + "pay_price": "4.00", + "dispatch_status": 0, + "dispatch_fee": "0.00", + "dispatch_type": "express", + "dispatch_id": 23, + "store_id": 0, + "aftersale_status": 0, + "comment_status": 0, + "refund_status": 0, + "refund_fee": null, + "refund_msg": null, + "express_name": null, + "express_code": null, + "express_no": null, + "ext": "[]", + "createtime": 1703747819, + "updatetime": 1703747819, + "status_code": "nopay", + "status_name": "", + "status_desc": "", + "btns": [], + "ext_arr": [], + "status_text": "" + } + ], + "status_code": "nopay", + "status_name": "待付款", + "status_desc": "等待买家付款", + "btns": [ + "cancel", + "pay" + ], + "ext_arr": { + "buy_type": "alone", + "groupon_id": 0, + "expired_time": 1703748719 + } } diff --git a/jyuan.json b/jyuan.json index 6af279a..78a72e0 100644 --- a/jyuan.json +++ b/jyuan.json @@ -1,28 +1,53 @@ { - "id": 11911, - "group_id": 1, - "username": "13369437728", - "nickname": "Shopro-11911", - "mobile": "13369437728", - "avatar": "http:\/\/file.shopro.top\/uploads\/20200410\/default-avatar.png", - "birthday": null, - "money": "0.00", - "score": 0, - "verification": { - "email": 0, - "mobile": 1 - }, - "child_user_count": 0, - "child_user_count_1": 0, - "child_user_count_2": 0, - "total_consume": "0.00", - "token": "b264ef23-82fc-463b-99f7-edfcf81022b4", + "id": 8405, + "type": "goods", + "order_sn": "202303165939181001191100", "user_id": 11911, - "createtime": 1703655689, - "expiretime": 1706247689, - "expires_in": 2592000, - "group": { - "name": "普通", - "image": "https:\/\/demo.shopro.top\/uploads\/20220515\/c308afa7c896c02915f02572be8fc015.png" + "activity_type": "", + "goods_amount": "8.00", + "dispatch_amount": "0.00", + "phone": "13369437728", + "consignee": "我去", + "province_name": "上海市", + "city_name": "上海市", + "area_name": "黄浦区", + "address": "123123", + "province_id": 310000, + "city_id": 310100, + "area_id": 310101, + "status": 0, + "invoice_status": "0", + "memo": null, + "remark": "", + "total_amount": "8.00", + "score_amount": 0, + "total_fee": "8.00", + "last_total_fee": "0.00", + "discount_fee": "0.00", + "coupon_fee": "0.00", + "activity_discount_money": "0.00", + "dispatch_discount_money": "0.00", + "pay_fee": "0.00", + "score_fee": 0, + "goods_original_amount": "44.00", + "coupons_id": 0, + "transaction_id": null, + "payment_json": null, + "pay_type": null, + "paytime": null, + "ext": "{\"buy_type\":\"alone\",\"groupon_id\":0,\"expired_time\":1703748719}", + "platform": "H5", + "createtime": 1703747819, + "status_code": "nopay", + "status_name": "待付款", + "status_desc": "等待买家付款", + "btns": [ + "cancel", + "pay" + ], + "ext_arr": { + "buy_type": "alone", + "groupon_id": 0, + "expired_time": 1703748719 } } diff --git a/module/cart/Cart.go b/module/cart/Cart.go new file mode 100644 index 0000000..0a36ed4 --- /dev/null +++ b/module/cart/Cart.go @@ -0,0 +1,55 @@ +package cart + +import ( + "github.com/towgo/towgo/dao/basedboperat" + "log" + "src/module/goods" + skuPrice "src/module/skuPrice" +) + +func (Cart) TableName() string { + return "cart" + +} + +// OrderItem 表示订单项信息 +type Cart struct { + ID int64 `json:"id"` // 订单项ID + UserID int64 `json:"user_id"` // 用户ID + CartType string `json:"cart_type"` // 购物车类型 + + GoodsId int64 `json:"goods_id"` // 商品ID + GoodsIds string `json:"goods_ids"` // 商品IDs + GoodsNum int64 `json:"goods_num"` // 商品数量 + Goods goods.Goods `json:"goods"xorm:"-"` // 商品 + + ActivityID int64 `json:"activity_id"` // 活动ID + ActivityType string `json:"activity_type"` // 活动类型 + + SkuPriceId int64 `json:"sku_price_id"` //规格价格 + SkuPrice skuPrice.SKUPrice `json:"sku_price" xorm:"-"` //规格价格 + +} +type ExtArr struct { + BuyType string `json:"buy_type"` + GrouponId int64 `json:"groupon_id"` + ExpiredTime int64 `json:"expired_time"` +} + +func (cart *Cart) AfterQuery(session basedboperat.DbTransactionSession) { + var good goods.Goods + err := session.Get(&good, nil, "id = ?", cart.GoodsId) + if err != nil { + log.Println(err.Error()) + return + } + cart.Goods = good + var skuP skuPrice.SKUPrice + err = session.Get(&skuP, nil, "id = ?", cart.SkuPriceId) + if err != nil { + log.Print(err.Error()) + return + } + cart.SkuPrice = skuP + +} diff --git a/module/cart/init.go b/module/cart/init.go new file mode 100644 index 0000000..fe2b318 --- /dev/null +++ b/module/cart/init.go @@ -0,0 +1,109 @@ +package cart + +import ( + "github.com/towgo/towgo/dao/basedboperat" + "github.com/towgo/towgo/dao/ormDriver/xormDriver" + "github.com/towgo/towgo/towgo" + "src/module/usercenter" +) + +func init() { + xormDriver.Sync2(new(Cart)) + towgo.NewCRUDJsonrpcAPI("/cart", Cart{}, []Cart{}).RegAPI() + towgo.SetFunc("/cart/mycart", GetMyCart) + towgo.SetFunc("/cart/add", CartAdd) + towgo.SetFunc("/cart/edit", CartEdit) +} + +func GetMyCart(rpc towgo.JsonRpcConnection) { + user, err := usercenter.LoginByToken(rpc.GetRpcRequest().Session) + //user, err := usercenter.LoginByToken("15c59252b34734f5f106be41a8108cf3") + user.Token = rpc.GetRpcRequest().Session + if err != nil { + rpc.GetRpcResponse().Error.Set(401, err.Error()) + rpc.Write() + return + } + var c Cart + var cs []Cart + var listCart basedboperat.List + listCart.Limit = -1 + listCart.Where = append(listCart.Where, basedboperat.Condition{ + Field: "user_id", + Operator: "=", + Value: user.ID, + }) + basedboperat.ListScan(&listCart, &c, &cs) + + rpc.WriteResult(cs) +} + +type AddParams struct { + GoodsList []struct { + GoodsId int64 `json:"goods_id"` + GoodsNum int64 `json:"goods_num"` + SkuPriceId int64 `json:"sku_price_id"` + GoodsPrice string `json:"goods_price"` + } `json:"goods_list"` + Form string `json:"form"` +} + +func CartAdd(rpc towgo.JsonRpcConnection) { + var params AddParams + rpc.ReadParams(¶ms) + user, err := usercenter.LoginByToken(rpc.GetRpcRequest().Session) + //user, err := usercenter.LoginByToken("15c59252b34734f5f106be41a8108cf3") + user.Token = rpc.GetRpcRequest().Session + if err != nil { + rpc.GetRpcResponse().Error.Set(401, err.Error()) + rpc.Write() + return + } + var c Cart + for _, v := range params.GoodsList { + c = Cart{ + UserID: user.ID, + GoodsId: v.GoodsId, + GoodsNum: v.GoodsNum, + SkuPriceId: v.SkuPriceId, + } + basedboperat.Create(&c) + } + type res struct { + Id int64 `json:"id"` + UserId int64 `json:"user_id"` + GoodsId int64 `json:"goods_id"` + GoodsNum int64 `json:"goods_num"` + SkuPriceId int64 `json:"sku_price_id"` + } + rpc.WriteResult(res{ + Id: c.ID, + UserId: user.UserID, + GoodsId: c.GoodsId, + GoodsNum: c.GoodsNum, + SkuPriceId: c.SkuPriceId, + }) + +} + +type EditParams struct { + CartList []int64 `json:"cart_list"` + Value string `json:"value"` + Act string `json:"act"` +} + +func CartEdit(rpc towgo.JsonRpcConnection) { + var params EditParams + rpc.ReadParams(¶ms) + if len(params.CartList) == 0 { + rpc.WriteError(200, "请选择商品") + return + } + var c Cart + if params.Act == "delete" { + for _, v := range params.CartList { + basedboperat.Delete(&c, v, nil, nil) + } + } + rpc.WriteResult(true) +} diff --git a/module/order/Order.go b/module/order/Order.go index 0f32338..b967241 100644 --- a/module/order/Order.go +++ b/module/order/Order.go @@ -1,6 +1,11 @@ package order -import "src/module/orderItem" +import ( + "encoding/json" + "github.com/towgo/towgo/dao/basedboperat" + "log" + "src/module/cart" +) func (Order) TableName() string { return "order" @@ -9,54 +14,62 @@ func (Order) TableName() string { // Order 表示订单信息 type Order struct { - ID int64 `json:"id"` // 订单ID - Type string `json:"type"` // 订单类型 - OrderSN string `json:"order_sn"` // 订单编号 - UserID int64 `json:"user_id"` // 用户ID - ActivityType string `json:"activity_type"` // 活动类型 - GoodsAmount string `json:"goods_amount"` // 商品金额 - DispatchAmount string `json:"dispatch_amount"` // 配送费用 - Phone string `json:"phone"` // 联系电话 - Consignee string `json:"consignee"` // 收货人 - ProvinceName string `json:"province_name"` // 省份名称 - CityName string `json:"city_name"` // 城市名称 - AreaName string `json:"area_name"` // 区域名称 - Address string `json:"address"` // 收货地址 - ProvinceID int64 `json:"province_id"` // 省份ID - CityID int64 `json:"city_id"` // 城市ID - AreaID int64 `json:"area_id"` // 区域ID - Status int64 `json:"status"` // 订单状态 - InvoiceStatus string `json:"invoice_status"` // 发票状态 - Memo string `json:"memo"` // 备注 - Remark string `json:"remark"` // 备注 - TotalAmount string `json:"total_amount"` // 订单总金额 - ScoreAmount int64 `json:"score_amount"` // 积分金额 - TotalFee string `json:"total_fee"` // 总费用 - LastTotalFee string `json:"last_total_fee"` // 最终总费用 - DiscountFee string `json:"discount_fee"` // 折扣金额 - CouponFee string `json:"coupon_fee"` // 优惠券金额 - ActivityDiscountMoney string `json:"activity_discount_money"` // 活动折扣金额 - DispatchDiscountMoney string `json:"dispatch_discount_money"` // 配送折扣金额 - PayFee string `json:"pay_fee"` // 支付费用 - ScoreFee int64 `json:"score_fee"` // 积分费用 - GoodsOriginalAmount string `json:"goods_original_amount"` // 商品原始金额 - CouponsID int64 `json:"coupons_id"` // 优惠券ID - TransactionID string `json:"transaction_id"` // 交易ID - PaymentJSON string `json:"payment_json"` // 支付信息JSON - PayType string `json:"pay_type"` // 支付类型 - Paytime int64 `json:"paytime"` // 支付时间 - Ext string `json:"ext"` // 扩展信息 - Platform string `json:"platform"` // 平台 - Createtime int64 `json:"createtime"` // 创建时间 - Item []orderItem.OrderItem `json:"orderItem" xorm:"-"` // 订单项列表 - StatusCode string `json:"status_code"` // 状态编码 - StatusName string `json:"status_name"` // 状态名称 - StatusDesc string `json:"status_desc"` // 状态描述 - Btns []string `json:"btns"` // 按钮列表 - ExtArr []ExtArr `json:"ext_arr"` // 扩展信息数组 + ID int64 `json:"id"` // 订单ID + Type string `json:"type"` // 订单类型 + OrderSN string `json:"order_sn"` // 订单编号 + UserID int64 `json:"user_id"` // 用户ID + ActivityType string `json:"activity_type"` // 活动类型 + GoodsAmount string `json:"goods_amount"` // 商品金额 + DispatchAmount string `json:"dispatch_amount"` // 配送费用 + Phone string `json:"phone"` // 联系电话 + Consignee string `json:"consignee"` // 收货人 + ProvinceName string `json:"province_name"` // 省份名称 + CityName string `json:"city_name"` // 城市名称 + AreaName string `json:"area_name"` // 区域名称 + Address string `json:"address"` // 收货地址 + ProvinceID int64 `json:"province_id"` // 省份ID + CityID int64 `json:"city_id"` // 城市ID + AreaID int64 `json:"area_id"` // 区域ID + Status int64 `json:"status"` // 订单状态 + InvoiceStatus string `json:"invoice_status"` // 发票状态 + Memo string `json:"memo"` // 备注 + Remark string `json:"remark"` // 备注 + TotalAmount string `json:"total_amount"` // 订单总金额 + ScoreAmount int64 `json:"score_amount"` // 积分金额 + TotalFee string `json:"total_fee"` // 总费用 + LastTotalFee string `json:"last_total_fee"` // 最终总费用 + DiscountFee string `json:"discount_fee"` // 折扣金额 + CouponFee string `json:"coupon_fee"` // 优惠券金额 + ActivityDiscountMoney string `json:"activity_discount_money"` // 活动折扣金额 + DispatchDiscountMoney string `json:"dispatch_discount_money"` // 配送折扣金额 + PayFee string `json:"pay_fee"` // 支付费用 + ScoreFee int64 `json:"score_fee"` // 积分费用 + GoodsOriginalAmount string `json:"goods_original_amount"` // 商品原始金额 + CouponsID int64 `json:"coupons_id"` // 优惠券ID + TransactionID string `json:"transaction_id"` // 交易ID + PaymentJSON string `json:"payment_json"` // 支付信息JSON + PayType string `json:"pay_type"` // 支付类型 + Paytime int64 `json:"paytime"` // 支付时间 + Ext string `json:"ext"` // 扩展信息 + Platform string `json:"platform"` // 平台 + Createtime int64 `json:"createtime"` // 创建时间 + Item []cart.Cart `json:"item" ` // 订单项列表 + StatusCode string `json:"status_code"` // 状态编码 + StatusName string `json:"status_name"` // 状态名称 + StatusDesc string `json:"status_desc"` // 状态描述 + Btns []string `json:"btns"` // 按钮列表 + ExtArr ExtArr `json:"ext_arr" xorm:"-"` // 扩展信息数组 } type ExtArr struct { BuyType string `json:"buy_type"` GrouponId int64 `json:"groupon_id"` - ExpiredTime int64 `json:"expired_time"` + ExpiredTime int64 `json:"expired_time" ` +} + +func (o *Order) AfterQuery(session basedboperat.DbTransactionSession) { + err := json.Unmarshal([]byte(o.Ext), &o.ExtArr) + if err != nil { + log.Println(err.Error()) + return + } } diff --git a/module/order/init.go b/module/order/init.go index 2238322..bbe00e6 100644 --- a/module/order/init.go +++ b/module/order/init.go @@ -1,12 +1,323 @@ package order import ( + "encoding/json" + "fmt" + "github.com/towgo/towgo/dao/basedboperat" "github.com/towgo/towgo/dao/ormDriver/xormDriver" "github.com/towgo/towgo/towgo" + "log" + "math/rand" + "src/module/cart" + "src/module/goods" + skuPrice "src/module/skuPrice" + "src/module/usercenter" + "strconv" + "time" ) func init() { xormDriver.Sync2(new(Order)) towgo.NewCRUDJsonrpcAPI("/order", Order{}, []Order{}).RegAPI() + towgo.SetFunc("/order/createOrder", CreateOrder) + towgo.SetFunc("/order/pre", Pre) + towgo.SetFunc("/order/index", OrderList) + //towgo.SetFunc("/order/detail", Detail) +} +func OrderList(rpc towgo.JsonRpcConnection) { + type params struct { + Type string `json:"type"` + Page int64 `json:"page"` + } + var p params + rpc.ReadParams(&p) + var listOrder basedboperat.List + listOrder.Limit = -1 + if p.Type != "all" { + listOrder.Where = append(listOrder.Where, basedboperat.Condition{ + Field: "status_code", + Operator: "=", + Value: p.Type, + }) + } + var o Order + var os []Order + basedboperat.ListScan(&listOrder, &o, &os) + type data struct { + ResultOrder []Order `json:"result_order"` + CurrentPage int64 `json:"current_Page"` + LastPage int64 `json:"last_page"` + PerPage int64 `json:"per_page"` + Total int64 `json:"total"` + } + sql := "select count(id) as `count` from `" + o.TableName() + "`" + var m []map[string]interface{} + err := basedboperat.SqlQueryScan(&m, sql) + if err != nil { + log.Println(err) + } + count := int64(m[0]["count"].(float64)) + + var lastPage int64 + if count%10 == 0 { + lastPage = count / 10 + } else { + lastPage = count/10 + 1 + } + d := data{ + ResultOrder: os, + CurrentPage: p.Page, + LastPage: lastPage, + PerPage: 10, + Total: count, + } + rpc.WriteResult(d) +} +func Detail(rpc towgo.JsonRpcConnection) { + type idst struct { + Id int64 `json:"id"` + } + var i idst + rpc.ReadParams(&i) + log.Println(i) + + var o Order + err := basedboperat.Get(&o, nil, "id = ?", i.Id) + log.Println("123") + if err != nil { + rpc.WriteError(500, err.Error()) + return + } + log.Println("312") + + rpc.WriteResult(o) +} + +type PrePamars struct { + GoodsList []struct { + GoodsId int64 `json:"goods_id"` + SkuPriceId int64 `json:"sku_price_id"` + GoodsPrice string `json:"goods_price"` + GoodsNum int64 `json:"goods_num"` + } `json:"goods_list"` + From string `json:"from"` + AddressId int64 `json:"address_id"` + CouponsId int64 `json:"coupons_id"` +} + +func Pre(rpc towgo.JsonRpcConnection) { + var params PrePamars + rpc.ReadParams(¶ms) + var s skuPrice.SKUPrice + var gs []tempGoods + var g goods.Goods + var total_pre float64 + for _, v := range params.GoodsList { + total := 0.0 + if v.SkuPriceId != 0 { + basedboperat.Get(&s, nil, "id=?", v.SkuPriceId) + p, err := strconv.ParseFloat(s.Price, 64) + if err != nil { + return + } + total += p * float64(v.GoodsNum) + } else { + gp, _ := strconv.ParseFloat(v.GoodsPrice, 64) + total += gp * float64(v.GoodsNum) + } + total_pre += total + basedboperat.Get(&g, nil, "id=?", v.GoodsId) + gres := tempGoods{ + GoodsId: g.ID, + SkuPriceId: "", + GoodsPrice: g.Price, + GoodsNum: v.GoodsNum, + DispatchType: "express", + Detail: g, + GoodsOriginalAmount: g.Price, + GoodsAmount: "", + DispatchAmount: "0.00", + ScoreAmount: 0, + DispatchId: 0, + StoreId: 0, + ActivityType: "", + DiscountFee: "", + PayPrice: strconv.FormatFloat(total, 'f', -1, 64), + } + gs = append(gs, gres) + } + free := strconv.FormatFloat(total_pre, 'f', -1, 64) + + rpc.WriteResult(PreRes{ + GoodsOriginalAmount: free, + GoodsAmount: free, + OriginDispatchAmount: "", + DispatchAmount: "", + TotalAmount: free, + TotalFee: free, + DiscountFee: "", + CouponFee: "", + ActivityDiscountMoney: "", + DispatchDiscountMoney: "", + InvoiceAmount: "", + ActivityType: "", + ScoreAmount: 0, + NewGoodsList: gs, + NeedAddress: 1, + ActivityDiscountInfos: nil, + Msg: nil, + }) +} + +type PreRes struct { + GoodsOriginalAmount string `json:"goods_original_amount"` + GoodsAmount string `json:"goods_amount"` + OriginDispatchAmount string `json:"origin_dispatch_amount"` + DispatchAmount string `json:"dispatch_amount"` + TotalAmount string `json:"total_amount"` + TotalFee string `json:"total_fee"` + DiscountFee string `json:"discount_fee"` + CouponFee string `json:"coupon_fee"` + ActivityDiscountMoney string `json:"activity_discount_money"` + DispatchDiscountMoney string `json:"dispatch_discount_money"` + InvoiceAmount string `json:"invoice_amount"` + ActivityType string `json:"activity_type"` + ScoreAmount int `json:"score_amount"` + NewGoodsList []tempGoods `json:"new_goods_list"` + NeedAddress int `json:"need_address"` + ActivityDiscountInfos []interface{} `json:"activity_discount_infos"` + Msg interface{} `json:"msg"` +} +type tempGoods struct { + GoodsId int64 `json:"goods_id"` + SkuPriceId string `json:"sku_price_id"` + GoodsPrice string `json:"goods_price"` + GoodsNum int64 `json:"goods_num"` + DispatchType string `json:"dispatch_type"` + Detail goods.Goods `json:"detail"` + GoodsOriginalAmount string `json:"goods_original_amount"` + GoodsAmount string `json:"goods_amount"` + DispatchAmount string `json:"dispatch_amount"` + ScoreAmount int64 `json:"score_amount"` + DispatchId int64 `json:"dispatch_id"` + StoreId int64 `json:"store_id"` + ActivityType string `json:"activity_type"` + DiscountFee string `json:"discount_fee"` + PayPrice string `json:"pay_price"` +} +type CreateOrderParams struct { + GoodsList []struct { + GoodsId int64 `json:"goods_id"` + CartId int64 `json:"cart_id"` + SkuPriceId int64 `json:"sku_price_id"` + GoodsPrice string `json:"goods_price"` + GoodsNum int64 `json:"goods_num"` + DispatchType string `json:"dispatch_type"` + } `json:"goods_list"` + From string `json:"from"` + AddressId int64 `json:"address_id"` + CouponsId int64 `json:"coupons_id"` + Remark string `json:"remark"` + Invoice struct { + } `json:"invoice"` +} + +func CreateOrder(rpc towgo.JsonRpcConnection) { + user, err := usercenter.LoginByToken(rpc.GetRpcRequest().Session) + //user, err := usercenter.LoginByToken("15c59252b34734f5f106be41a8108cf3") + user.Token = rpc.GetRpcRequest().Session + if err != nil { + rpc.GetRpcResponse().Error.Set(401, err.Error()) + rpc.Write() + return + } + var params CreateOrderParams + rpc.ReadParams(¶ms) + var is []cart.Cart + var totalFree float64 + for _, v := range params.GoodsList { + var i cart.Cart + basedboperat.Get(&i, nil, "id=?", v.CartId) + is = append(is, i) + basedboperat.Delete(&i, i.ID, nil, nil) + floatTemp, err := strconv.ParseFloat(v.GoodsPrice, 64) + if err != nil { + return + } + totalFree += float64(v.GoodsNum) * floatTemp + } + marshal, err := json.Marshal(ExtArr{ + BuyType: "alone", + GrouponId: params.CouponsId, + ExpiredTime: time.Now().Unix(), + }) + if err != nil { + return + } + + o := Order{ + Type: "goods", + OrderSN: generateOrderNumber(), + UserID: user.ID, + ActivityType: "", + GoodsAmount: strconv.FormatFloat(totalFree, 'f', -1, 64), + DispatchAmount: "0.00", + Phone: user.Mobile, + Consignee: "我去", + ProvinceName: "上海市", + CityName: "上海市", + AreaName: "黄埔区", + Address: strconv.FormatInt(params.AddressId, 10), + ProvinceID: 310000, + CityID: 310100, + AreaID: 310101, + Status: 0, + InvoiceStatus: "0", + Memo: "", + Remark: "", + TotalAmount: "0", + ScoreAmount: 0, + TotalFee: strconv.FormatFloat(totalFree, 'f', -1, 64), + LastTotalFee: "0.00", + DiscountFee: "0.00", + CouponFee: "0.00", + ActivityDiscountMoney: "0.00", + DispatchDiscountMoney: "", + PayFee: "0.00", + ScoreFee: 0, + GoodsOriginalAmount: "66.00", + CouponsID: 0, + TransactionID: "", + PaymentJSON: "", + PayType: "", + Paytime: 0, + Ext: string(marshal), + Platform: "H5", + Createtime: time.Now().Unix(), + Item: is, + StatusCode: "nopay", + StatusName: "待付款", + StatusDesc: "等待买家付款", + Btns: []string{"cancel", "pay"}, + } + _, err = basedboperat.Create(&o) + if err != nil { + log.Println(err.Error()) + rpc.WriteError(500, err.Error()) + return + } + rpc.WriteResult(o) +} +func generateOrderNumber() string { + // 生成一个时间戳字符串 + timestamp := time.Now().UnixNano() / int64(time.Millisecond) + + // 生成一个随机数字符串 + rand.Seed(time.Now().UnixNano()) + randomNumber := rand.Intn(10000) // 这里可以根据需要调整随机数的范围 + + // 构造订单号 + orderNumber := fmt.Sprintf("%d%d", timestamp, randomNumber) + return orderNumber } diff --git a/module/orderItem/OrderItem.go b/module/orderItem/OrderItem.go deleted file mode 100644 index 5cdfd48..0000000 --- a/module/orderItem/OrderItem.go +++ /dev/null @@ -1,55 +0,0 @@ -package orderItem - -func (OrderItem) TableName() string { - return "order_item" - -} - -// OrderItem 表示订单项信息 -type OrderItem struct { - ID int64 `json:"id"` // 订单项ID - UserID int64 `json:"user_id"` // 用户ID - OrderID int64 `json:"order_id"` // 订单ID - GoodsID int64 `json:"goods_id"` // 商品ID - GoodsType string `json:"goods_type"` // 商品类型 - GoodsSkuPriceID int64 `json:"goods_sku_price_id"` // 商品SKU价格ID - ActivityID int64 `json:"activity_id"` // 活动ID - ActivityType string `json:"activity_type"` // 活动类型 - ItemGoodsSkuPriceID int64 `json:"item_goods_sku_price_id"` // 订单项商品SKU价格ID - GoodsSkuText string `json:"goods_sku_text"` // 商品SKU文本 - GoodsTitle string `json:"goods_title"` // 商品标题 - GoodsImage string `json:"goods_image"` // 商品图片 - GoodsOriginalPrice string `json:"goods_original_price"` // 商品原始价格 - DiscountFee string `json:"discount_fee"` // 折扣金额 - GoodsPrice string `json:"goods_price"` // 商品价格 - GoodsNum int64 `json:"goods_num"` // 商品数量 - GoodsWeight int64 `json:"goods_weight"` // 商品重量 - PayPrice string `json:"pay_price"` // 支付价格 - DispatchStatus int64 `json:"dispatch_status"` // 配送状态 - DispatchFee string `json:"dispatch_fee"` // 配送费用 - DispatchType string `json:"dispatch_type"` // 配送类型 - DispatchID int64 `json:"dispatch_id"` // 配送ID - StoreID int64 `json:"store_id"` // 店铺ID - AftersaleStatus int64 `json:"aftersale_status"` // 售后状态 - CommentStatus int64 `json:"comment_status"` // 评论状态 - RefundStatus int64 `json:"refund_status"` // 退款状态 - RefundFee string `json:"refund_fee"` // 退款费用 - RefundMsg string `json:"refund_msg"` // 退款消息 - ExpressName string `json:"express_name"` // 快递公司名称 - ExpressCode string `json:"express_code"` // 快递公司代码 - ExpressNo string `json:"express_no"` // 快递单号 - Ext string `json:"ext"` // 扩展信息 - Createtime int64 `json:"createtime"` // 创建时间 - Updatetime int64 `json:"updatetime"` // 更新时间 - StatusCode string `json:"status_code"` // 状态编码 - StatusName string `json:"status_name"` // 状态名称 - StatusDesc string `json:"status_desc"` // 状态描述 - Btns []string `json:"btns"` // 按钮列表 - ExtArr []ExtArr `json:"ext_arr"` // 扩展信息数组 - StatusText string `json:"status_text"` // 状态文本 -} -type ExtArr struct { - BuyType string `json:"buy_type"` - GrouponId int64 `json:"groupon_id"` - ExpiredTime int64 `json:"expired_time"` -} diff --git a/module/orderItem/init.go b/module/orderItem/init.go deleted file mode 100644 index 07c163b..0000000 --- a/module/orderItem/init.go +++ /dev/null @@ -1,12 +0,0 @@ -package orderItem - -import ( - "github.com/towgo/towgo/dao/ormDriver/xormDriver" - "github.com/towgo/towgo/towgo" -) - -func init() { - xormDriver.Sync2(new(OrderItem)) - towgo.NewCRUDJsonrpcAPI("/orderItem", OrderItem{}, []OrderItem{}).RegAPI() - -}