|
@@ -20,7 +20,6 @@ import (
|
|
|
"fohow.com/apps/helpers"
|
|
"fohow.com/apps/helpers"
|
|
|
"fohow.com/apps/models/cow_order_model"
|
|
"fohow.com/apps/models/cow_order_model"
|
|
|
"fohow.com/apps/models/merchant_model"
|
|
"fohow.com/apps/models/merchant_model"
|
|
|
- "fohow.com/apps/models/subject_model"
|
|
|
|
|
"fohow.com/apps/models/user_model"
|
|
"fohow.com/apps/models/user_model"
|
|
|
"fohow.com/libs/tool"
|
|
"fohow.com/libs/tool"
|
|
|
"strings"
|
|
"strings"
|
|
@@ -29,9 +28,13 @@ import (
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
var updateExpressLock sync.Mutex
|
|
var updateExpressLock sync.Mutex
|
|
|
|
|
+var createOrder sync.Mutex
|
|
|
|
|
+var MultreateOrder sync.Mutex
|
|
|
|
|
|
|
|
//下单
|
|
//下单
|
|
|
func (self *OrderController) Create() {
|
|
func (self *OrderController) Create() {
|
|
|
|
|
+ createOrder.Lock()
|
|
|
|
|
+ defer createOrder.Unlock()
|
|
|
_pid := self.Ctx.Input.Param(":id")
|
|
_pid := self.Ctx.Input.Param(":id")
|
|
|
pId, _ := strconv.ParseInt(_pid, 10, 64)
|
|
pId, _ := strconv.ParseInt(_pid, 10, 64)
|
|
|
_count := self.Ctx.Input.Param(":count")
|
|
_count := self.Ctx.Input.Param(":count")
|
|
@@ -50,68 +53,6 @@ func (self *OrderController) Create() {
|
|
|
//if user.IsBlackUser == 1 {
|
|
//if user.IsBlackUser == 1 {
|
|
|
// self.ReturnError(403, apps.AccountError, "", nil)
|
|
// self.ReturnError(403, apps.AccountError, "", nil)
|
|
|
//}
|
|
//}
|
|
|
- //加入限购逻辑
|
|
|
|
|
- if product.PurchaseLimitCount > 0 {
|
|
|
|
|
- if product.PurchaseLimitCount < count {
|
|
|
|
|
- self.ReturnError(403, []string{apps.OverLimitCount[0], fmt.Sprintf("该商品限购%d件", product.PurchaseLimitCount)}, "", nil)
|
|
|
|
|
- } else {
|
|
|
|
|
- purchaseTotalCount := order_model.GetOrderCountByPIdAndWxUId(pId, wxUId)
|
|
|
|
|
- //历史已经买够到限购数量了
|
|
|
|
|
- if product.PurchaseLimitCount <= purchaseTotalCount {
|
|
|
|
|
- self.ReturnError(403, []string{apps.PurchasedReachLimit[0], fmt.Sprintf("该商品限购%d件", product.PurchaseLimitCount)}, "", nil)
|
|
|
|
|
- }
|
|
|
|
|
- //历史没买够数量,但是历史总数+想购买的数量 超过限购数量
|
|
|
|
|
- if product.PurchaseLimitCount < (purchaseTotalCount + count) {
|
|
|
|
|
- canBuyCount := product.PurchaseLimitCount - purchaseTotalCount
|
|
|
|
|
- self.ReturnError(403, []string{apps.PurchasedReachLimit[0], fmt.Sprintf("您还可以购买%d件", canBuyCount)}, "", nil)
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- //判断剩余数量
|
|
|
|
|
- leftCount := int64(0)
|
|
|
|
|
- product.SoldCount = order_model.GetSoldCountByPId(product.Id, false)
|
|
|
|
|
- leftCount = product.Count - product.SoldCount
|
|
|
|
|
- if count > leftCount {
|
|
|
|
|
- self.ReturnError(403, apps.ProductStockNotEnough, "", nil)
|
|
|
|
|
- }
|
|
|
|
|
- //商品销售专题---start
|
|
|
|
|
- isJoinSubjectPrize := false //商品是否参与专题的抽奖, 考虑开奖时间
|
|
|
|
|
- productSaleSubjectId := int64(0) //专题的id
|
|
|
|
|
- sId, _ := self.GetInt64("sid", 0)
|
|
|
|
|
- if sId > 0 {
|
|
|
|
|
- subject := subject_model.GetProductSaleSubjectById(sId, false)
|
|
|
|
|
- if subject != nil {
|
|
|
|
|
- productIds := subject.ProductIds
|
|
|
|
|
- productIdArray := strings.Split(productIds, ",")
|
|
|
|
|
- for _, productIdItem := range productIdArray {
|
|
|
|
|
- productId, err := strconv.ParseInt(productIdItem, 10, 64)
|
|
|
|
|
- if err == nil && productId == pId {
|
|
|
|
|
- productSaleSubjectId = subject.Id
|
|
|
|
|
- if subject.IsPrizeAct && subject.OpenPrizeTime.Unix() > time.Now().Unix() {
|
|
|
|
|
- isJoinSubjectPrize = true
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- subjects := subject_model.GetPrizeActProductSaleSubjectsByProductId(pId, false)
|
|
|
|
|
- if len(subjects) > 0 {
|
|
|
|
|
- for _, item := range subjects {
|
|
|
|
|
- productIds := item.ProductIds
|
|
|
|
|
- productIdArray := strings.Split(productIds, ",")
|
|
|
|
|
- for _, productIdItem := range productIdArray {
|
|
|
|
|
- productId, err := strconv.ParseInt(productIdItem, 10, 64)
|
|
|
|
|
- if err == nil && productId == pId {
|
|
|
|
|
- productSaleSubjectId = item.Id
|
|
|
|
|
- if item.IsPrizeAct && item.OpenPrizeTime.Unix() > time.Now().Unix() {
|
|
|
|
|
- isJoinSubjectPrize = true
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- //商品销售专题---end
|
|
|
|
|
-
|
|
|
|
|
//秒杀逻辑: 判断是否处于秒杀时间段内
|
|
//秒杀逻辑: 判断是否处于秒杀时间段内
|
|
|
if product.SeckilShowPrice > 0 {
|
|
if product.SeckilShowPrice > 0 {
|
|
|
now := time.Now()
|
|
now := time.Now()
|
|
@@ -121,37 +62,25 @@ func (self *OrderController) Create() {
|
|
|
self.ReturnError(403, apps.SeckillIsEnd, "", nil)
|
|
self.ReturnError(403, apps.SeckillIsEnd, "", nil)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- //限新逻辑: 微信支付完成购买过商品的用户
|
|
|
|
|
- if product.IsOnlyNew {
|
|
|
|
|
- paiedOrder := order_model.GetPaiedOrderByWxUIdAndPayWayLimitOne(wxUId, order_model.PAY_WAY_WEIXIN, false)
|
|
|
|
|
- if paiedOrder != nil {
|
|
|
|
|
- self.ReturnError(403, apps.OnlyNew, "", nil)
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- totalPrice := product.RoboBalancePrice * count
|
|
|
|
|
|
|
+ totalPrice := product.Price * count
|
|
|
//小兔微信,测试微信支付
|
|
//小兔微信,测试微信支付
|
|
|
- if wxUId == 42452 {
|
|
|
|
|
|
|
+ if wxUId == 76 {
|
|
|
totalPrice = 1
|
|
totalPrice = 1
|
|
|
}
|
|
}
|
|
|
freight := order_model.FREIGHT
|
|
freight := order_model.FREIGHT
|
|
|
- if totalPrice >= order_model.FREIGHT_LIMIT {
|
|
|
|
|
|
|
+ if totalPrice >= order_model.FREIGHT_LIMIT || beego.AppConfig.String("RunMode") == "dev" {
|
|
|
freight = int64(0)
|
|
freight = int64(0)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
order := new(order_model.Order).CreateNew(wxUId, uId,
|
|
order := new(order_model.Order).CreateNew(wxUId, uId,
|
|
|
totalPrice, freight, order_model.SOURCE_XCX)
|
|
totalPrice, freight, order_model.SOURCE_XCX)
|
|
|
- if order != nil {
|
|
|
|
|
- if productSaleSubjectId > 0 {
|
|
|
|
|
- order.IsJoinSubjectPrize = isJoinSubjectPrize
|
|
|
|
|
- order.ProductSaleSubjectId = productSaleSubjectId
|
|
|
|
|
- }
|
|
|
|
|
- order.Save()
|
|
|
|
|
- //创建订单明细
|
|
|
|
|
- go new(order_model.OrderDetail).Create(order.OrderId, order.Id, product.Id, product.Price, product.RoboBalancePrice, product.Name,
|
|
|
|
|
- count)
|
|
|
|
|
|
|
+ if order == nil {
|
|
|
|
|
+ self.ReturnError(403, apps.CreateOrderFail, "", nil)
|
|
|
}
|
|
}
|
|
|
|
|
+ order.Save()
|
|
|
|
|
+ //创建订单明细
|
|
|
|
|
+ go new(order_model.OrderDetail).Create(order.OrderId, order.Id, product.Id, product.Price, product.RoboBalancePrice, product.Name,
|
|
|
|
|
+ count)
|
|
|
|
|
|
|
|
type Order struct {
|
|
type Order struct {
|
|
|
OrderId string `json:"order_id"`
|
|
OrderId string `json:"order_id"`
|
|
@@ -182,20 +111,24 @@ func (self *OrderController) GetExpressNo() {
|
|
|
|
|
|
|
|
//购物车下单
|
|
//购物车下单
|
|
|
func (self *OrderController) MultipleCreate() {
|
|
func (self *OrderController) MultipleCreate() {
|
|
|
|
|
+ MultreateOrder.Lock()
|
|
|
|
|
+ defer MultreateOrder.Unlock()
|
|
|
uId := self.GetCurrentUserId()
|
|
uId := self.GetCurrentUserId()
|
|
|
wxUId := self.GetCurrentWxUserId()
|
|
wxUId := self.GetCurrentWxUserId()
|
|
|
-
|
|
|
|
|
ids := self.GetString("ids")
|
|
ids := self.GetString("ids")
|
|
|
nums := self.GetString("nums")
|
|
nums := self.GetString("nums")
|
|
|
-
|
|
|
|
|
if len(nums) <= 0 || len(ids) <= 0 {
|
|
if len(nums) <= 0 || len(ids) <= 0 {
|
|
|
self.ReturnError(403, apps.NoCart, "", nil)
|
|
self.ReturnError(403, apps.NoCart, "", nil)
|
|
|
}
|
|
}
|
|
|
totalPrice := int64(0)
|
|
totalPrice := int64(0)
|
|
|
|
|
+ //创建订单
|
|
|
|
|
+ order := new(order_model.Order).CreateNew(wxUId, uId,
|
|
|
|
|
+ totalPrice, int64(0), order_model.SOURCE_XCX)
|
|
|
|
|
+ if order == nil {
|
|
|
|
|
+ self.ReturnError(403, apps.CreateOrderFail, "", nil)
|
|
|
|
|
+ }
|
|
|
c_arr := strings.Split(ids, ",")
|
|
c_arr := strings.Split(ids, ",")
|
|
|
- beego.BeeLogger.Warn("c_arr(%s)", c_arr)
|
|
|
|
|
c_nums := strings.Split(nums, ",")
|
|
c_nums := strings.Split(nums, ",")
|
|
|
- beego.BeeLogger.Warn("c_nums(%s)", c_nums)
|
|
|
|
|
for key, s_item := range c_arr {
|
|
for key, s_item := range c_arr {
|
|
|
cId, _ := strconv.ParseInt(s_item, 10, 64)
|
|
cId, _ := strconv.ParseInt(s_item, 10, 64)
|
|
|
cNums := int64(1)
|
|
cNums := int64(1)
|
|
@@ -211,70 +144,17 @@ func (self *OrderController) MultipleCreate() {
|
|
|
if product == nil {
|
|
if product == nil {
|
|
|
self.ReturnError(403, apps.NoExist, "", nil)
|
|
self.ReturnError(403, apps.NoExist, "", nil)
|
|
|
}
|
|
}
|
|
|
- //加入限购逻辑
|
|
|
|
|
- if product.PurchaseLimitCount > 0 {
|
|
|
|
|
- if product.PurchaseLimitCount < cNums {
|
|
|
|
|
- self.ReturnError(403, []string{apps.OverLimitCount[0], fmt.Sprintf("%s商品限购%d件", product.Name, product.PurchaseLimitCount)}, "", nil)
|
|
|
|
|
- } else {
|
|
|
|
|
- purchaseTotalCount := order_model.GetOrderCountByPIdAndWxUId(cartItem.ProductId, wxUId)
|
|
|
|
|
- //历史已经买够到限购数量了
|
|
|
|
|
- if product.PurchaseLimitCount <= purchaseTotalCount {
|
|
|
|
|
- self.ReturnError(403, []string{apps.PurchasedReachLimit[0], fmt.Sprintf("%s商品限购%d件", product.Name, product.PurchaseLimitCount)}, "", nil)
|
|
|
|
|
- }
|
|
|
|
|
- //历史没买够数量,但是历史总数+想购买的数量 超过限购数量
|
|
|
|
|
- if product.PurchaseLimitCount < (purchaseTotalCount + cNums) {
|
|
|
|
|
- canBuyCount := product.PurchaseLimitCount - purchaseTotalCount
|
|
|
|
|
- self.ReturnError(403, []string{apps.PurchasedReachLimit[0], fmt.Sprintf("%s您还可以购买%d件", product.Name, canBuyCount)}, "", nil)
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- //普通下单--判断剩余数量
|
|
|
|
|
- product.SoldCount = order_model.GetSoldCountByPId(product.Id, false)
|
|
|
|
|
- leftCount := product.Count - product.SoldCount
|
|
|
|
|
- if cNums > leftCount {
|
|
|
|
|
- self.ReturnError(403, []string{apps.ProductStockNotEnough[0], fmt.Sprintf("%s商品库存不足", product.Name)}, "", nil)
|
|
|
|
|
- }
|
|
|
|
|
- //限新逻辑: 微信支付完成购买过商品的用户
|
|
|
|
|
- if product.IsOnlyNew {
|
|
|
|
|
- paiedOrder := order_model.GetPaiedOrderByWxUIdAndPayWayLimitOne(wxUId, order_model.PAY_WAY_WEIXIN, false)
|
|
|
|
|
- if paiedOrder != nil {
|
|
|
|
|
- self.ReturnError(403, []string{apps.OnlyNew[0], fmt.Sprintf("%s仅限新人购买", product.Name)}, "", nil)
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
totalPrice += product.Price * cNums
|
|
totalPrice += product.Price * cNums
|
|
|
- //小兔微信,测试微信支付
|
|
|
|
|
- if wxUId == 12 {
|
|
|
|
|
- //totalPrice = 1
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ go new(order_model.OrderDetail).Create(order.OrderId, order.Id, cartItem.ProductId, product.Price, product.RoboBalancePrice, product.Name,
|
|
|
|
|
+ cNums)
|
|
|
}
|
|
}
|
|
|
freight := order_model.FREIGHT
|
|
freight := order_model.FREIGHT
|
|
|
- if totalPrice >= order_model.FREIGHT_LIMIT {
|
|
|
|
|
|
|
+ if totalPrice >= order_model.FREIGHT_LIMIT || beego.AppConfig.String("RunMode") == "dev" {
|
|
|
freight = int64(0)
|
|
freight = int64(0)
|
|
|
}
|
|
}
|
|
|
- order := new(order_model.Order).CreateNew(wxUId, uId,
|
|
|
|
|
- totalPrice, freight, order_model.SOURCE_XCX)
|
|
|
|
|
- if order != nil {
|
|
|
|
|
- order.Save()
|
|
|
|
|
- //创建订单明细
|
|
|
|
|
- for key, s_item := range c_arr {
|
|
|
|
|
- cId, _ := strconv.ParseInt(s_item, 10, 64)
|
|
|
|
|
- cNums := int64(1)
|
|
|
|
|
- cNums, _ = strconv.ParseInt(c_nums[key], 10, 64)
|
|
|
|
|
- cartItem := order_model.GetCartById(cId)
|
|
|
|
|
- if cartItem == nil {
|
|
|
|
|
- self.ReturnError(403, apps.NoExist, "", nil)
|
|
|
|
|
- }
|
|
|
|
|
- if cartItem.WxUserId != wxUId {
|
|
|
|
|
- self.ReturnError(403, apps.AccountError, "", nil)
|
|
|
|
|
- }
|
|
|
|
|
- product := product_model.GetProductById(cartItem.ProductId, false)
|
|
|
|
|
- if product == nil {
|
|
|
|
|
- self.ReturnError(403, apps.NoExist, "", nil)
|
|
|
|
|
- }
|
|
|
|
|
- new(order_model.OrderDetail).Create(order.OrderId, order.Id, cartItem.ProductId, product.Price, product.RoboBalancePrice, product.Name,
|
|
|
|
|
- cNums)
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ order.TotalPrice = totalPrice
|
|
|
|
|
+ order.Freight = freight
|
|
|
|
|
+ order.Save()
|
|
|
go ClearCart(order.UserId, order.OrderId)
|
|
go ClearCart(order.UserId, order.OrderId)
|
|
|
type Order struct {
|
|
type Order struct {
|
|
|
OrderId string `json:"order_id"`
|
|
OrderId string `json:"order_id"`
|