Esempio n. 1
0
func (this *orderManagerImpl) SubmitOrder(c cart.ICart, subject string,
	couponCode string, useBalanceDiscount bool) (order.IOrder,
	payment.IPaymentOrder, error) {
	order, py, err := this.PrepareOrder(c, subject, couponCode)
	if err != nil {
		return order, py, err
	}
	orderNo, err := order.Submit()
	tradeNo := orderNo
	if err == nil {
		cv := c.GetValue()
		cv.PaymentOpt = enum.PaymentOnlinePay
		pyUpdate := false
		//todo: 设置配送门店
		//err = order.SetShop(cv.ShopId)
		//err = order.SetDeliver(cv.DeliverId)

		// 设置支付方式
		if err = py.SetPaymentSign(cv.PaymentOpt); err != nil {
			return order, py, err
		}

		// 处理支付单
		py.BindOrder(order.GetAggregateRootId(), tradeNo)
		if _, err = py.Save(); err != nil {
			err = errors.New("下单出错:" + err.Error())
			//todo: 取消订单
			//order.Cancel(err.Error())
			domain.HandleError(err, "domain")
			return order, py, err
		}

		// 使用余额支付
		if useBalanceDiscount {
			err = py.BalanceDiscount()
			pyUpdate = true
		}

		// 如果已支付完成,则将订单设为支付完成
		if v := py.GetValue(); v.FinalFee == 0 &&
			v.State == payment.StateFinishPayment {
			for _, sub := range order.GetSubOrders() {
				sub.PaymentFinishByOnlineTrade()
			}
		}

		// 更新支付单
		if err == nil && pyUpdate {
			_, err = py.Save()
		}
	}
	return order, py, err
}
Esempio n. 2
0
// 合并购物车,并返回新的购物车
func (this *cartImpl) Combine(c cart.ICart) cart.ICart {
	if c.GetAggregateRootId() != this.GetAggregateRootId() {
		for _, v := range c.GetValue().Items {
			if item, err := this.AddItem(v.VendorId, v.ShopId,
				v.SkuId, v.Quantity, v.Checked == 1); err == nil {
				if v.Checked == 1 {
					item.Checked = 1
				}
			}
		}
		c.Destroy() //合并后,需销毁购物车
	}
	this._snapMap = nil //clean
	return this
}
Esempio n. 3
0
//  获取购物车
func (this *shoppingService) getShoppingCart(buyerId int,
	cartKey string) cart.ICart {
	var c cart.ICart
	if len(cartKey) > 0 {
		c = this._cartRep.GetShoppingCartByKey(cartKey)
	} else if buyerId > 0 {
		c = this._cartRep.GetMemberCurrentCart(buyerId)
	}
	if c == nil {
		c = this._cartRep.NewCart()
		_, err := c.Save()
		domain.HandleError(err, "service")
	}
	if c.GetValue().BuyerId <= 0 {
		err := c.SetBuyer(buyerId)
		domain.HandleError(err, "service")
	}
	return c
}
Esempio n. 4
0
// 读取购物车数据,用于预生成订单
func (o *orderImpl) RequireCart(c cart.ICart) error {
	if o.GetAggregateRootId() > 0 || o._cart != nil {
		return order.ErrRequireCart
	}
	items := c.GetValue().Items
	if len(items) == 0 {
		return cart.ErrEmptyShoppingCart
	}
	// 绑定结算购物车
	o._cart = c
	// 将购物车的商品分类整理
	o._vendorItemsMap = o.buildVendorItemMap(items)
	// 更新订单的金额
	o._vendorExpressMap = o.updateOrderFee(o._vendorItemsMap)
	// 状态设为待支付
	o._value.State = 1

	return nil
}
Esempio n. 5
0
// 将购物车转换为订单
func (this *orderManagerImpl) ParseToOrder(c cart.ICart) (order.IOrder,
	member.IMember, error) {
	var m member.IMember
	err := this.checkCartForOrder(c)
	if err != nil {
		return nil, m, err
	}
	val := &order.Order{}

	// 判断购买会员
	buyerId := c.GetValue().BuyerId
	if buyerId > 0 {
		val.BuyerId = buyerId
		m = this._memberRep.GetMember(val.BuyerId)
	}
	if m == nil {
		return nil, m, member.ErrNoSuchMember
	}
	val.State = order.StatAwaitingPayment
	o := this.CreateOrder(val)
	err = o.RequireCart(c)
	o.GetByVendor()
	return o, m, err
}