module_shop_act_detach.go 919 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package modules
  2. import (
  3. "context"
  4. "golang-fave/engine/wrapper"
  5. "golang-fave/utils"
  6. )
  7. func (this *Modules) RegisterAction_ShopDetach() *Action {
  8. return this.newAction(AInfo{
  9. WantDB: true,
  10. Mount: "shop-detach",
  11. WantAdmin: true,
  12. }, func(wrap *wrapper.Wrapper) {
  13. pf_id := utils.Trim(wrap.R.FormValue("id"))
  14. if !utils.IsNumeric(pf_id) {
  15. wrap.MsgError(`Inner system error`)
  16. return
  17. }
  18. if err := wrap.DB.Transaction(wrap.R.Context(), func(ctx context.Context, tx *wrapper.Tx) error {
  19. if _, err := tx.Exec(`
  20. UPDATE 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. }