module_shop_currencies_act_delete.go 885 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 := utils.Trim(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. wrap.RecreateProductXmlFile()
  32. wrap.ResetCacheBlocks()
  33. // Reload current page
  34. wrap.Write(`window.location.reload(false);`)
  35. })
  36. }