コード例 #1
0
ファイル: OrderList.go プロジェクト: elivoa/gotapestry
func (p *OrderList) _onStatusEvent(trackNumber int64, status string, tab string) *exit.Exit {
	err := orderservice.ChangeOrderStatus(trackNumber, status)
	if err != nil {
		panic(err.Error())
	}
	return route.RedirectDispatch(route.GetRefererFromURL(p.Request()), "/order/list")
}
コード例 #2
0
ファイル: ConstList.go プロジェクト: elivoa/gotapestry
func (p *ConstList) Ondelete(id int64) interface{} {
	fmt.Println("\n\n\n\n$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")
	fmt.Println("things i want to see is:  ", p.Referer)
	if _, err := service.Const.DeleteById(id); err != nil {
		panic(err)
	}
	// return exit.RedirectFirstValid(p.Referer, "/admin/preference/")
	refererurl := route.GetRefererFromURL(p.Request())
	return route.RedirectDispatch(refererurl, "/admin/preference/")
}
コード例 #3
0
ファイル: order.go プロジェクト: elivoa/gotapestry
// **** important logic ****
// when close order. 结款, Close Order
func (p *ButtonSubmitHere) OnSuccessFromCloseForm() *exit.Exit {
	fmt.Println("\n\n\n>>>>>>>>>>>>>>>>>>>> On success from close order.................", p.TrackNumber)

	// 1/2 update delivery informantion to order.
	order, err := orderservice.GetOrderByTrackingNumber(p.TrackNumber)
	if err != nil {
		panic(err.Error())
	}
	order.Status = "done"
	_, err = service.Order.UpdateOrder(order)
	if err != nil {
		panic(err.Error())
	}

	// 2/2 update customer's AccountBallance
	customer, err := service.Person.GetPersonById(order.CustomerId)
	if err != nil {
		panic(err)
	}
	if customer == nil {
		panic(fmt.Sprintf("Customer not found for order! id %v", order.CustomerId))
	}
	customer.AccountBallance += p.Money
	if _, err = personservice.Update(customer); err != nil {
		panic(err.Error())
	}

	// create chagne log at the same time:
	accountdao.CreateAccountChangeLog(&model.AccountChangeLog{
		CustomerId:     customer.Id,
		Delta:          p.Money,
		Account:        customer.AccountBallance,
		Type:           3, // batch close order.
		RelatedOrderTN: order.TrackNumber,
		Reason:         "",
	})
	return route.RedirectDispatch(p.Referer, "/order/list")
}
コード例 #4
0
ファイル: ProductList.go プロジェクト: elivoa/gotapestry
// 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")
}
コード例 #5
0
ファイル: order.go プロジェクト: elivoa/gotapestry
// **** 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
}
コード例 #6
0
ファイル: ProductList.go プロジェクト: elivoa/gotapestry
func (p *ProductList) Onhide(productId int) *exit.Exit {
	service.Product.ChangeStatus(productId, product.StatusHide)
	return route.RedirectDispatch(p.Referer, "product/list/"+p.Capital)
}
コード例 #7
0
ファイル: ProductList.go プロジェクト: elivoa/gotapestry
// NOTE: event name is case sensitive. Kill this when add cache.
func (p *ProductList) Ondelete(productId int) *exit.Exit {
	service.Product.DeleteProduct(productId)
	return route.RedirectDispatch(p.Referer, "product/list/"+p.Capital)
}