module_shop_currencies_act_delete.go 957 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. 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. ctx,
  22. `DELETE FROM fave_shop_currencies WHERE id = ?;`,
  23. utils.StrToInt(pf_id),
  24. ); err != nil {
  25. return err
  26. }
  27. return nil
  28. })
  29. if err != nil {
  30. wrap.MsgError(err.Error())
  31. return
  32. }
  33. wrap.RecreateProductXmlFile()
  34. wrap.ResetCacheBlocks()
  35. // Reload current page
  36. wrap.Write(`window.location.reload(false);`)
  37. })
  38. }