module_shop_act_detach.go 921 B

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