|
|
@@ -62,62 +62,63 @@ func (self *PayController) payExchange(oId, payWay, tradPwd, returnUrl, source,
|
|
|
if order.Status != order_model.STATUS_UNPAY {
|
|
|
self.ReturnError(403, apps.NotUnPay, "", nil)
|
|
|
}
|
|
|
- //第一次支付已更新支付方式,第一次支付才计算支付金额
|
|
|
- if len(order.PayWay) <= 0 {
|
|
|
- SaleNumsMap := make(map[int64]int64)
|
|
|
- //支付方式判断
|
|
|
- if (order.OrderType == order_model.ORDER_TYPE_SEKILL || order.OrderType == order_model.ORDER_TYPE_SHOP) && payWay == pay_model.PAYWAY_BALANCE {
|
|
|
- self.ReturnError(403, apps.NotRightPayWay, "", nil)
|
|
|
+ SaleNumsMap := make(map[int64]int64)
|
|
|
+ //支付方式判断
|
|
|
+ if (order.OrderType == order_model.ORDER_TYPE_SEKILL || order.OrderType == order_model.ORDER_TYPE_SHOP) && payWay == pay_model.PAYWAY_BALANCE {
|
|
|
+ self.ReturnError(403, apps.NotRightPayWay, "", nil)
|
|
|
+ }
|
|
|
+ //获取购物商品明细
|
|
|
+ buy_price_total := int64(0)
|
|
|
+ total_price := int64(0)
|
|
|
+ list := order_model.GetAllDetailsOrderId(order.OrderId, false)
|
|
|
+ for _, item := range list {
|
|
|
+ //商品状态
|
|
|
+ product := product_model.GetProductById(item.ProductId, false)
|
|
|
+ if product == nil {
|
|
|
+ self.ReturnError(403, []string{apps.ProductNotExist[0], fmt.Sprintf("%s产品不存在", product.Name)}, "", nil)
|
|
|
}
|
|
|
- //获取购物商品明细
|
|
|
- buy_price_total := int64(0)
|
|
|
- total_price := int64(0)
|
|
|
- list := order_model.GetAllDetailsOrderId(order.OrderId, false)
|
|
|
- for _, item := range list {
|
|
|
- //商品状态
|
|
|
- product := product_model.GetProductById(item.ProductId, false)
|
|
|
- if product == nil {
|
|
|
- self.ReturnError(403, []string{apps.ProductNotExist[0], fmt.Sprintf("%s产品不存在", product.Name)}, "", nil)
|
|
|
- }
|
|
|
- //商品下架
|
|
|
- if product.Status == product_model.PRODUCT_STATUS_DOWN {
|
|
|
- self.ReturnError(403, []string{apps.ProductOffSale[0], fmt.Sprintf("%s产品已经下架", product.Name)}, "", nil)
|
|
|
+ //商品下架
|
|
|
+ if product.Status == product_model.PRODUCT_STATUS_DOWN {
|
|
|
+ self.ReturnError(403, []string{apps.ProductOffSale[0], fmt.Sprintf("%s产品已经下架", product.Name)}, "", nil)
|
|
|
+ }
|
|
|
+ //秒杀逻辑: 判断是否处于秒杀时间段内
|
|
|
+ if product.SeckilShowPrice > 0 {
|
|
|
+ now := time.Now()
|
|
|
+ if now.Unix() < product.SeckillStart.Unix() {
|
|
|
+ self.ReturnError(403, []string{apps.SeckillNotStart[0], fmt.Sprintf("%s秒杀活动尚未开始", product.Name)}, "", nil)
|
|
|
+ } else if now.Unix() > product.SeckillEnd.Unix() {
|
|
|
+ self.ReturnError(403, []string{apps.SeckillIsEnd[0], fmt.Sprintf("%s秒杀活动已经结束", product.Name)}, "", nil)
|
|
|
}
|
|
|
- //秒杀逻辑: 判断是否处于秒杀时间段内
|
|
|
- if product.SeckilShowPrice > 0 {
|
|
|
- now := time.Now()
|
|
|
- if now.Unix() < product.SeckillStart.Unix() {
|
|
|
- self.ReturnError(403, []string{apps.SeckillNotStart[0], fmt.Sprintf("%s秒杀活动尚未开始", product.Name)}, "", nil)
|
|
|
- } else if now.Unix() > product.SeckillEnd.Unix() {
|
|
|
- self.ReturnError(403, []string{apps.SeckillIsEnd[0], fmt.Sprintf("%s秒杀活动已经结束", product.Name)}, "", nil)
|
|
|
+ }
|
|
|
+ //限购逻辑
|
|
|
+ if product.PurchaseLimitCount > 0 {
|
|
|
+ if product.PurchaseLimitCount < item.Count {
|
|
|
+ self.ReturnError(403, []string{apps.OverLimitCount[0], fmt.Sprintf("%s商品限购%d件", product.Name, product.PurchaseLimitCount)}, "", nil)
|
|
|
+ } else {
|
|
|
+ purchaseTotalCount := order_model.GetOrderCountByPIdAndWxUId(product.Id, wxUId)
|
|
|
+ //历史已经买够到限购数量了
|
|
|
+ if product.PurchaseLimitCount <= purchaseTotalCount {
|
|
|
+ self.ReturnError(403, []string{apps.PurchasedReachLimit[0], fmt.Sprintf("%s商品限购%d件", product.Name, product.PurchaseLimitCount)}, "", nil)
|
|
|
}
|
|
|
- }
|
|
|
- //限购逻辑
|
|
|
- if product.PurchaseLimitCount > 0 {
|
|
|
- if product.PurchaseLimitCount < item.Count {
|
|
|
- self.ReturnError(403, []string{apps.OverLimitCount[0], fmt.Sprintf("%s商品限购%d件", product.Name, product.PurchaseLimitCount)}, "", nil)
|
|
|
- } else {
|
|
|
- purchaseTotalCount := order_model.GetOrderCountByPIdAndWxUId(product.Id, 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 + item.Count) {
|
|
|
- canBuyCount := product.PurchaseLimitCount - purchaseTotalCount
|
|
|
- self.ReturnError(403, []string{apps.PurchasedReachLimit[0], fmt.Sprintf("%s您还可以购买%d件", product.Name, canBuyCount)}, "", nil)
|
|
|
- }
|
|
|
+ //历史没买够数量,但是历史总数+想购买的数量 超过限购数量
|
|
|
+ if product.PurchaseLimitCount < (purchaseTotalCount + item.Count) {
|
|
|
+ canBuyCount := product.PurchaseLimitCount - purchaseTotalCount
|
|
|
+ self.ReturnError(403, []string{apps.PurchasedReachLimit[0], fmt.Sprintf("%s您还可以购买%d件", product.Name, canBuyCount)}, "", nil)
|
|
|
}
|
|
|
}
|
|
|
- buy_price_total += product.BuyPrice * item.Count
|
|
|
- total_price += product.Price * item.Count
|
|
|
- SaleNumsMap[product.Id] = item.Count
|
|
|
- }
|
|
|
- storeMap := SaleNumsMap
|
|
|
- resultStore, prdName := FindNotEnoughPrd(storeMap)
|
|
|
- if resultStore {
|
|
|
- self.ReturnError(403, []string{apps.ProductStockNotEnough[0], fmt.Sprintf("%s商品库存不足", prdName)}, "", nil)
|
|
|
}
|
|
|
+ buy_price_total += product.BuyPrice * item.Count
|
|
|
+ total_price += product.Price * item.Count
|
|
|
+ SaleNumsMap[product.Id] = item.Count
|
|
|
+ }
|
|
|
+ storeMap := SaleNumsMap
|
|
|
+ resultStore, prdName := FindNotEnoughPrd(storeMap)
|
|
|
+ if resultStore {
|
|
|
+ self.ReturnError(403, []string{apps.ProductStockNotEnough[0], fmt.Sprintf("%s商品库存不足", prdName)}, "", nil)
|
|
|
+ }
|
|
|
+ //第一次支付已更新支付方式,第一次支付才计算支付金额
|
|
|
+ if len(order.PayWay) <= 0 {
|
|
|
+
|
|
|
order.Remark = remark
|
|
|
order.PayWay = payWay
|
|
|
order.Contact = address.Contact
|