module_shop_currencies_act_delete.go 938 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package modules
  2. import (
  3. "context"
  4. "golang-fave/engine/utils"
  5. "golang-fave/engine/wrapper"
  6. )
  7. func (this *Modules) RegisterAction_ShopCurrenciesDelete() *Action {
  8. return this.newAction(AInfo{
  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(wrap.R.Context(), func(ctx context.Context, tx *wrapper.Tx) error {
  18. // Process
  19. if _, err := tx.Exec(
  20. ctx,
  21. `DELETE FROM fave_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. }