|
|
@@ -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 {
|