Exemplo n.º 1
0
func (s *OrderService) BatchCloseOrder(money float64, customerId int) {
	debug.Log("Incoming Money: %v", money)
	person, err := Person.GetPersonById(customerId)
	if err != nil {
		panic(err.Error())
	}
	// get unclosed orders for somebody
	orders, err := orderdao.DeliveringUnclosedOrdersByCustomer(customerId)
	if err != nil {
		panic(err.Error())
	}

	// collect totalorder price
	var totalOrderPrice float64
	for _, o := range orders {
		totalOrderPrice += o.SumOrderPrice()
	}

	// money used as total shouldbe: inputmoney + (accountballance - allorder's price)
	totalmoney := money + (person.AccountBallance + totalOrderPrice)

	for _, order := range orders {
		if totalmoney-order.SumOrderPrice() >= 0 {
			err := s.ChangeOrderStatus(order.TrackNumber, "done")
			if err != nil {
				panic(err.Error())
			}
			totalmoney -= order.SumOrderPrice()
		}
	}
	accountdao.CreateIncoming(&model.AccountIncoming{
		CustomeId: person.Id,
		Incoming:  money,
	})
	// modify customer's accountballance
	person.AccountBallance += money
	personservice.Update(person) // TODO: chagne place

	// create chagne log at the same time:
	accountdao.CreateAccountChangeLog(&model.AccountChangeLog{
		CustomerId: person.Id,
		Delta:      money,
		Account:    person.AccountBallance,
		Type:       2, // create order
		// RelatedOrderTN: 0,
		Reason: "Batch insert",
	})

}
Exemplo n.º 2
0
// NOTE: event name is case sensitive. Kill this when add cache.
func (p *ProductList) Ondelete(productId int) *exit.Exit {
	debug.Log("Delete Product %d", productId)
	service.Product.DeleteProduct(productId)
	// TODO make this default redirect.
	return route.RedirectDispatch(p.Source, "/product/list")
}
Exemplo n.º 3
0
func load() {
	cache = make(map[string]Items, 100)

	persons, err := persondao.ListAll("customer")
	// persons, err := personservice.ListCustomer()
	if err != nil {
		panic(err.Error())
	} else {
		debug.Log("[suggest] load %v customers.", len(persons))
		personItems := NewItems(len(persons))
		for i, person := range persons {
			personItems[i] = &Item{
				Id:          person.Id,
				Text:        person.Name,
				QuickString: parseQuickText(person.Name),
				Type:        "1",
			}
		}
		sort.Sort(personItems)
		cache[Customer] = personItems
	}

	factories, err := persondao.ListAll("factory")
	// factories, err := personservice.ListFactory()
	if err != nil {
		panic(err.Error())
	} else {
		debug.Log("[suggest] load %v factories.", len(factories))
		factoryItems := NewItems(len(factories))
		for i, factory := range factories {
			factoryItems[i] = &Item{
				Id:          factory.Id,
				Text:        factory.Name,
				QuickString: parseQuickText(factory.Name), // TODO
				Type:        "2",
			}
		}
		sort.Sort(factoryItems)
		cache[Factory] = factoryItems
	}

	// TODO: chagne to step load.
	parser := productdao.EntityManager().NewQueryParser().Where().Limit(10000) // all limit to 1w
	products, err := productdao.List(parser)
	if err != nil {
		panic(err.Error())
	}
	// products := dal.ListProduct()
	debug.Log("[suggest] load %v products.", len(products))
	productItems := NewItems(len(products))
	for i, product := range products {
		productItems[i] = &Item{
			Id:          product.Id,
			SN:          product.ProductId,
			Text:        product.Name,
			QuickString: parseQuickText(product.Name), // TODO
			Type:        "3",
		}
	}
	sort.Sort(productItems)
	cache[Product] = productItems

	debug.Log("Loading suggest done. Use 0.00 ms.")
}