Exemple #1
0
func (p *PersonDetail) ShouldShowLeavingMessage(o *model.Order) bool {
	switch model.OrderType(o.Type) {
	// case model.Wholesale, model.ShippingInstead:
	case model.Wholesale, model.SubOrder:
		return true
	}
	return false
}
Exemple #2
0
// calculate order,
func _calculateOrder(order *model.Order) {
	switch model.OrderType(order.Type) {
	case model.SubOrder, model.Wholesale:
		if order.Details != nil && len(order.Details) > 0 {
			order.CalculateOrder()
		}
	case model.ShippingInstead:
		// this type of order's total price is calculated by sub
		// orders, which is difficult to calculate, so I calclate sum
		// in page, and then submit to the parent order.
		// So, here does nothing.
	}
}
Exemple #3
0
// Print only. do nothing.
func (p *OrderList) FixPrintOrderLink(order *model.Order) string {
	switch model.OrderType(order.Type) {
	case model.Wholesale:
		return fmt.Sprintf("/order/print/%v", order.TrackNumber)
	case model.ShippingInstead:
		return fmt.Sprintf("/order/shippinginsteadprint/%v", order.TrackNumber)
	case model.SubOrder:
		return "#Error"
	default:
		return fmt.Sprintf("%v", order.Type)
	}
	panic(fmt.Sprintf("Wrong order type for %v", order.TrackNumber))
}
Exemple #4
0
func (p *OrderList) ViewLink(order *model.Order) string {
	switch model.OrderType(order.Type) {
	case model.Wholesale:
		return fmt.Sprintf("/order/view/%v", order.TrackNumber)
	case model.ShippingInstead:
		return fmt.Sprintf("/order/create/shippinginstead/%v?readonly=true", order.TrackNumber)
	case model.SubOrder:
		return "#Error"
	default:
		return fmt.Sprintf("%v", order.Type)
	}
	panic(fmt.Sprintf("Wrong order type for %v", order.TrackNumber))
}
Exemple #5
0
// to some action and then redirect to print page.
func (p *OrderList) PrintOrderLink(order *model.Order) string {
	switch model.OrderType(order.Type) {
	case model.Wholesale:
		// TODO auto generate this via builtin eventlink component.
		// TODO: Use link generator to generate this link.
		return fmt.Sprintf("/order/list.orderlist:Print/%v", order.TrackNumber)
	case model.ShippingInstead:
		return fmt.Sprintf("/order/list.orderlist:ShippingInsteadOrderPrint/%v", order.TrackNumber)
	case model.SubOrder:
		return "#Error"
	default:
		return fmt.Sprintf("%v", order.Type)
	}
	panic(fmt.Sprintf("Wrong order type for %v", order.TrackNumber))
}
Exemple #6
0
func (p *OrderList) EditLink(order *model.Order) string {
	var editlink string
	switch model.OrderType(order.Type) {
	case model.Wholesale:
		editlink = fmt.Sprintf("/order/create/detail/%v", order.Id)
	case model.ShippingInstead:
		editlink = fmt.Sprintf("/order/create/shippinginstead/%v", order.TrackNumber)
	case model.SubOrder:
		editlink = "#Error"
	default:
		editlink = fmt.Sprintf("%v", order.Type)
	}
	return editlink

	// add return url // another method to return page to add referer
	refer := p.Request().URL.RequestURI()
	return editlink + "?referer=" + refer // TODO: need encode
	// panic(fmt.Sprintf("Wrong order type for %v", order.TrackNumber))
}
Exemple #7
0
// **** important logic ****
// TODO transaction. Move to right place. 发货
func (p *ButtonSubmitHere) OnSuccessFromDeliverForm() *exit.Exit {

	var expressFee int64 = 0
	if p.DaoFu == "on" {
		// if order.ExpressFee == -1, means this is `daofu`, don't add -1 to 累计欠款.
		// TODO add field isDaofu to order table. Change ExpressFee to 0;
		expressFee = -1
	} else {
		expressFee = p.ExpressFee
	}

	if _, err := service.Order.DeliverOrder(
		p.TrackNumber, p.DeliveryTrackingNumber, p.DeliveryMethod, expressFee); err != nil {
		panic(err)
	}
	return route.RedirectDispatch(p.Referer, "/order/list")

	if false { // backup, has been replace with above.

		/////////////

		// 1/2 update delivery informantion to order.

		// 1. get order form db.
		order, err := orderservice.GetOrderByTrackingNumber(p.TrackNumber)
		if err != nil {
			panic(err.Error())
		}

		// 2. set data back to order.
		order.DeliveryTrackingNumber = p.DeliveryTrackingNumber
		order.DeliveryMethod = p.DeliveryMethod
		if p.DaoFu == "on" {
			// if order.ExpressFee == -1, means this is `daofu`, don't add -1 to 累计欠款.
			// TODO add field isDaofu to order table. Change ExpressFee to 0;
			order.ExpressFee = -1
		} else {
			order.ExpressFee = p.ExpressFee
		}
		order.Status = "delivering"

		// 3. get person, check if customer exists.
		customer, err := service.Person.GetPersonById(order.CustomerId)
		if err != nil {
			panic(err)
		} else if customer == nil {
			panic(fmt.Sprintf("Customer not found for order! id %v", order.CustomerId))
		}

		// 4. the last chance to update accumulated.
		order.Accumulated = -customer.AccountBallance

		// 5. save order changes.
		if _, err := service.Order.UpdateOrder(order); err != nil {
			panic(err.Error())
		}

		// 6. update customer's AccountBallance
		switch model.OrderType(order.Type) {
		case model.Wholesale, model.SubOrder: // 代发不参与, 代发订单由其子订单负责参与累计欠款的统计;
			customer.AccountBallance -= order.TotalPrice
			if order.ExpressFee > 0 {
				customer.AccountBallance -= float64(order.ExpressFee)
			}
			if _, err = personservice.Update(customer); err != nil {
				panic(err.Error())
			}

			// create chagne log.
			accountdao.CreateAccountChangeLog(&model.AccountChangeLog{
				CustomerId:     customer.Id,
				Delta:          -order.TotalPrice,
				Account:        customer.AccountBallance,
				Type:           2, // order.send
				RelatedOrderTN: order.TrackNumber,
				Reason:         "",
			})

		}
		fmt.Println(">>>>>>>>>>>>>>>>>>>> update all done......................")
	}
	return nil
}
Exemple #8
0
// Update Order 的所有逻辑都在这里了;
func (s *OrderService) UpdateOrder(order *model.Order) (*model.Order, error) {

	// 更新 Tracking Number 到子订单的 Tracking No
	for _, detail := range order.Details {
		// TODO: additional check if order tracking number not match;
		detail.OrderTrackNumber = order.TrackNumber
	}

	var needUpdateBallance = false
	// If status change from other to takeaway, mark as need update ballance.
	// Order中只包含新数据,旧的数据必须从数据库中取出了;也顺便再次验证是否存在这个订单;
	if oldOrder, err := s.GetOrder(order.Id); err != nil {
		return nil, err // panic(err)
	} else {
		// this makes mistake.
		// if oldOrder.DeliveryMethod == "TakeAway" {
		// 	return nil, errors.New("自提状态的订单不能再修改!")
		// }

		// 自提,非自提;状态是发货中,和其他
		// 更新情况1: 修改订单时,由非自提状态改为自提状态,需要修改累计欠款;
		if oldOrder.DeliveryMethod != "TakeAway" && order.DeliveryMethod == "TakeAway" {
			order.Status = "delivering"
			needUpdateBallance = true
		}
		// 更新情况2: 非自提状态点发货,}
		if order.Status == "delivering" { // 需要修改累计欠款
			if oldOrder.Status == "done" || oldOrder.Status == "canceled" {
				return nil, errors.New(fmt.Sprintf("%s状态的订单状态不能修改为delivering!", oldOrder.Status))
			}
			needUpdateBallance = true
		}

		// update order
		_processOrderCustomerPrice(order)    // update order custumize price when confirm order.
		_calculateOrder(order)               // calculate order statistic fields.
		_processingUpdateOrderDetails(order) // update order detail into db;

		_update_order_accumulated(order) // debug option
		// update order
		if _, err := orderdao.UpdateOrder(order); err != nil {
			return nil, err
		}
	}

	// update account ballance. upate stocks left.
	if needUpdateBallance {
		// 代发的父订单不参与非累计欠款, 代发订单由其子订单负责参与累计欠款的统计;
		// 代发父订单的逻辑应该也到不了这里。
		fmt.Println(">> update account ballance. delta: ", -order.SumOrderPrice())

		switch model.OrderType(order.Type) {
		case model.Wholesale, model.SubOrder:

			Account.UpdateAccountBalance(order.CustomerId, -order.SumOrderPrice(),
				"Create Order", order.TrackNumber)

		}

		// update stocks
		_reduceProductStocks(order.Details)

	}
	return order, nil
}