浏览代码

增加店铺专区商品下单接口

abiao 5 年之前
父节点
当前提交
430a2f389d

+ 66 - 0
go/gopath/src/fohow.com/apps/controllers/order_controller/order_controller.go

@@ -26,6 +26,7 @@ import (
 var updateExpressLock sync.Mutex
 var createOrder sync.Mutex
 var MultreateOrder sync.Mutex
+var MultShopOrder sync.Mutex
 
 //下单
 func (self *OrderController) Create() {
@@ -196,6 +197,71 @@ func (self *OrderController) MultipleCreate() {
 	self.ServeJSON()
 }
 
+//店铺专区下单
+func (self *OrderController) MultShopCreate() {
+	MultShopOrder.Lock()
+	defer MultShopOrder.Unlock()
+	uId := self.GetCurrentUserId()
+	wxUId := self.GetCurrentWxUserId()
+	ids := self.GetString("ids")
+	nums := self.GetString("nums")
+	if len(nums) <= 0 || len(ids) <= 0 {
+		self.ReturnError(403, apps.NoCart, "", nil)
+	}
+	totalPrice := int64(0)
+	//创建订单
+	order := new(order_model.Order).CreateNew(wxUId, uId,
+		totalPrice, int64(0), order_model.ORDER_TYPE_SHOP, order_model.SOURCE_XCX)
+	if order == nil {
+		self.ReturnError(403, apps.CreateOrderFail, "", nil)
+	}
+	c_arr := strings.Split(ids, ",")
+	c_nums := strings.Split(nums, ",")
+	for key, s_item := range c_arr {
+		pId, _ := strconv.ParseInt(s_item, 10, 64)
+		cNums := int64(1)
+		cNums, _ = strconv.ParseInt(c_nums[key], 10, 64)
+		product := product_model.GetProductById(pId, false)
+		if product == nil {
+			self.ReturnError(403, apps.NoExist, "", nil)
+		}
+
+		//获取商品属性详情
+		sizeName := ""
+		colorName := ""
+		if product.SizeId > 0 {
+			productSize := product_model.GetProductAttrValueById(product.SizeId)
+			if productSize != nil {
+				sizeName = productSize.Name
+			}
+		}
+		if product.ColorId > 0 {
+			productColor := product_model.GetProductAttrValueById(product.ColorId)
+			if productColor != nil {
+				colorName = productColor.Name
+			}
+		}
+		totalPrice += product.Price * cNums
+		go new(order_model.OrderDetail).Create(order.OrderId, order.Id, pId, product.Price, product.RoboBalancePrice, product.Name, sizeName, colorName, cNums)
+	}
+	freight := order_model.FREIGHT
+	if totalPrice >= order_model.FREIGHT_LIMIT || beego.AppConfig.String("RunMode") == "dev" {
+		freight = int64(0)
+	}
+	order.TotalPrice = totalPrice
+	order.Freight = freight
+	order.Save()
+
+	//未支付订单加入取消队列
+	cancelKey := helpers.GetOrderCancelList()
+	helpers.ThrowInRedisList(cancelKey, order.OrderId)
+	type Order struct {
+		OrderId string `json:"order_id"`
+	}
+	self.Data["json"] = &Order{OrderId: order.OrderId}
+	self.ServeJSON()
+}
+
 func ClearCart(userId int64, orderId string) {
 	orderDetails := order_model.GetAllDetailsOrderId(orderId)
 	for _, item := range orderDetails {

+ 2 - 1
go/gopath/src/fohow.com/apps/models/order_model/order.go

@@ -41,9 +41,10 @@ const (
 	OPERATE_CONFIRM = "confirm" //确认收货
 	OPERATE_CANCEL  = "cancel"  //取消订单
 
-	//订单类型 0:普通订单, 1:代销订单, 2:自用订单
+	//订单类型 0:普通订单, 1:秒杀订单, 2:店铺订单
 	ORDER_TYPE_NORMAL = int64(0)
 	ORDER_TYPE_SEKILL = int64(1)
+	ORDER_TYPE_SHOP   = int64(2)
 
 	FREIGHT_LIMIT   = int64(9900)
 	FREIGHT         = int64(500)

+ 3 - 0
go/gopath/src/fohow.com/routers/routes.go

@@ -274,4 +274,7 @@ func init() {
 	//批量调整 删除购物车商品项
 	beego.Router("/v1/cart/mult_delele", &order_controller.OrderController{}, "post:MultChangeItemDelete")
 
+	//----------------购物车 -------------------
+	//店铺专区下单
+	beego.Router("/v1/shop/order_mul", &order_controller.OrderController{}, "post:MultShopCreate")
 }