module_shop_currencies_act_delete.go 936 B

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