module_shop_currencies_act_delete.go 813 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package modules
  2. import (
  3. "golang-fave/engine/wrapper"
  4. "golang-fave/utils"
  5. )
  6. func (this *Modules) RegisterAction_ShopCurrenciesDelete() *Action {
  7. return this.newAction(AInfo{
  8. WantDB: true,
  9. Mount: "shop-currencies-delete",
  10. WantAdmin: true,
  11. }, func(wrap *wrapper.Wrapper) {
  12. pf_id := wrap.R.FormValue("id")
  13. if !utils.IsNumeric(pf_id) || utils.StrToInt(pf_id) <= 1 {
  14. wrap.MsgError(`Inner system error`)
  15. return
  16. }
  17. err := wrap.DB.Transaction(func(tx *wrapper.Tx) error {
  18. // Process
  19. if _, err := tx.Exec(
  20. `DELETE FROM shop_currencies WHERE id = ?;`,
  21. utils.StrToInt(pf_id),
  22. ); err != nil {
  23. return err
  24. }
  25. return nil
  26. })
  27. if err != nil {
  28. wrap.MsgError(err.Error())
  29. return
  30. }
  31. // Reload current page
  32. wrap.Write(`window.location.reload(false);`)
  33. })
  34. }