Ejemplo n.º 1
0
// 应用优惠券
func (this *orderManagerImpl) applyCoupon(m member.IMember, order order.IOrder,
	py payment.IPaymentOrder, couponCode string) error {
	po := py.GetValue()
	cp := this._promRep.GetCouponByCode(
		m.GetAggregateRootId(), couponCode)
	// 如果优惠券不存在
	if cp == nil {
		return errors.New("优惠券无效")
	}
	// 获取优惠券
	coupon := cp.(promotion.ICouponPromotion)
	result, err := coupon.CanUse(m, po.TotalFee)
	if result {
		if coupon.CanTake() {
			_, err = coupon.GetTake(m.GetAggregateRootId())
			//如果未占用,则占用
			if err != nil {
				err = coupon.Take(m.GetAggregateRootId())
			}
		} else {
			_, err = coupon.GetBind(m.GetAggregateRootId())
		}
		if err != nil {
			domain.HandleError(err, "domain")
			err = errors.New("优惠券无效")
		} else {
			//应用优惠券
			if err = order.ApplyCoupon(coupon); err == nil {
				_, err = py.CouponDiscount(coupon)
			}
		}
	}
	return err
}
Ejemplo n.º 2
0
// 生成支付单
func (this *orderManagerImpl) createPaymentOrder(m member.IMember,
	o order.IOrder) payment.IPaymentOrder {
	val := o.GetValue()
	v := &payment.PaymentOrderBean{
		BuyUser:     m.GetAggregateRootId(),
		PaymentUser: m.GetAggregateRootId(),
		VendorId:    0,
		OrderId:     0,
		// 支付单金额
		TotalFee: val.FinalAmount,
		// 余额抵扣
		BalanceDiscount: 0,
		// 积分抵扣
		IntegralDiscount: 0,
		// 系统支付抵扣金额
		SystemDiscount: 0,
		// 优惠券金额
		CouponDiscount: 0,
		// 立减金额
		SubFee: 0,
		// 支付选项
		PaymentOpt: payment.OptPerm,
		// 支付方式
		PaymentSign: enum.PaymentOnlinePay,
		//创建时间
		CreateTime: time.Now().Unix(),
		// 在线支付的交易单号
		OuterNo: "",
		//支付时间
		PaidTime: 0,
		// 状态:  0为未付款,1为已付款,2为已取消
		State: payment.StateNotYetPayment,
	}
	v.FinalFee = v.TotalFee - v.SubFee - v.SystemDiscount -
		v.IntegralDiscount - v.BalanceDiscount
	return this._payRep.CreatePaymentOrder(v)
}
Ejemplo n.º 3
0
func (this *orderManagerImpl) SmartConfirmOrder(o order.IOrder) error {

	return nil

	//todo:  自动确认订单
	var err error
	v := o.GetValue()
	log.Printf("[ AUTO][OrderSetup]:%s - Confirm \n", v.OrderNo)
	var sp shop.IShop
	if biShops == nil {
		// /pay/return_alipay?out_trade_no=ZY1607375766&request_token=requestToken&result=success&trade_no
		// =2016070221001004880246862127&sign=75a18ca0d75750ac22fedbbe6468c187&sign_type=MD5
		//todo:  拆分订单
		biShops = this._merchant.ShopManager().GetBusinessInShops()
	}
	if len(biShops) == 1 {
		sp = biShops[0]
	} else {
		sp, err = this.SmartChoiceShop(v.ShippingAddress)
		if err != nil {
			//todo:
			panic("not impl")
			//order.Suspend("智能分配门店失败!原因:" + err.Error())
			return err
		}
	}

	if sp != nil && sp.Type() == shop.TypeOfflineShop {
		sv := sp.GetValue()
		//todo: set shop
		panic("not impl")
		//order.SetShop(sp.GetDomainId())
		err = o.Confirm()
		//err = order.Process()
		ofs := sp.(shop.IOfflineShop).GetShopValue()
		o.AppendLog(&order.OrderLog{
			Type:     int(order.LogSetup),
			IsSystem: 1,
			Message:  fmt.Sprintf("自动分配门店:%s,电话:%s", sv.Name, ofs.Tel),
		})
	}
	return err
}