parent
d51f04a8d1
commit
3d09bd9a1f
@ -1,24 +1,139 @@
|
|||||||
{
|
{
|
||||||
"id": 1,
|
"id": 8405,
|
||||||
"username": "13369437728",
|
"type": "goods",
|
||||||
"nickname": "",
|
"order_sn": "202303165939181001191100",
|
||||||
"password": "",
|
"user_id": 11911,
|
||||||
"email": "",
|
"activity_type": "",
|
||||||
"mobile": "13369437728",
|
"goods_amount": "8.00",
|
||||||
"token": "0f09fda89955c44b0e93b4af4c93194c",
|
"dispatch_amount": "0.00",
|
||||||
"created_at": 0,
|
"phone": "13369437728",
|
||||||
"updated_at": 0,
|
"consignee": "我去",
|
||||||
"group_id": 0,
|
"province_name": "上海市",
|
||||||
"avatar": "",
|
"city_name": "上海市",
|
||||||
"birthday": "",
|
"area_name": "黄浦区",
|
||||||
"money": "",
|
"address": "123123",
|
||||||
"score": 0,
|
"province_id": 310000,
|
||||||
"child_user_count": 0,
|
"city_id": 310100,
|
||||||
"child_user_count_1": 0,
|
"area_id": 310101,
|
||||||
"child_user_count_2": 0,
|
"status": 0,
|
||||||
"total_consume": "",
|
"invoice_status": "0",
|
||||||
"user_id": 1,
|
"memo": null,
|
||||||
"createtime": 0,
|
"remark": "",
|
||||||
"expiretime": 0,
|
"total_amount": "8.00",
|
||||||
"expires_in": 0
|
"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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,28 +1,53 @@
|
|||||||
{
|
{
|
||||||
"id": 11911,
|
"id": 8405,
|
||||||
"group_id": 1,
|
"type": "goods",
|
||||||
"username": "13369437728",
|
"order_sn": "202303165939181001191100",
|
||||||
"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",
|
|
||||||
"user_id": 11911,
|
"user_id": 11911,
|
||||||
"createtime": 1703655689,
|
"activity_type": "",
|
||||||
"expiretime": 1706247689,
|
"goods_amount": "8.00",
|
||||||
"expires_in": 2592000,
|
"dispatch_amount": "0.00",
|
||||||
"group": {
|
"phone": "13369437728",
|
||||||
"name": "普通",
|
"consignee": "我去",
|
||||||
"image": "https:\/\/demo.shopro.top\/uploads\/20220515\/c308afa7c896c02915f02572be8fc015.png"
|
"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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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
|
||||||
|
|
||||||
|
}
|
||||||
@ -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)
|
||||||
|
}
|
||||||
@ -1,12 +1,323 @@
|
|||||||
package order
|
package order
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"github.com/towgo/towgo/dao/basedboperat"
|
||||||
"github.com/towgo/towgo/dao/ormDriver/xormDriver"
|
"github.com/towgo/towgo/dao/ormDriver/xormDriver"
|
||||||
"github.com/towgo/towgo/towgo"
|
"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() {
|
func init() {
|
||||||
xormDriver.Sync2(new(Order))
|
xormDriver.Sync2(new(Order))
|
||||||
towgo.NewCRUDJsonrpcAPI("/order", Order{}, []Order{}).RegAPI()
|
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
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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"`
|
|
||||||
}
|
|
||||||
@ -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()
|
|
||||||
|
|
||||||
}
|
|
||||||
Loading…
Reference in new issue