func ordersJsonByCustomerid(customerId int) (string, string) { orders, err := orderdao.DeliveringUnclosedOrdersByCustomer(customerId) if err != nil { panic(err.Error()) } return toJsonList(orders) }
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", }) }