module_shop_act_detach.go 856 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package modules
  2. import (
  3. "golang-fave/engine/wrapper"
  4. "golang-fave/utils"
  5. )
  6. func (this *Modules) RegisterAction_ShopDetach() *Action {
  7. return this.newAction(AInfo{
  8. WantDB: true,
  9. Mount: "shop-detach",
  10. WantAdmin: true,
  11. }, func(wrap *wrapper.Wrapper) {
  12. pf_id := 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(func(tx *wrapper.Tx) error {
  18. if _, err := tx.Exec(`
  19. UPDATE shop_products SET
  20. parent_id = NULL,
  21. active = 0
  22. WHERE
  23. id = ?
  24. ;`,
  25. utils.StrToInt(pf_id),
  26. ); err != nil {
  27. return err
  28. }
  29. return nil
  30. }); err != nil {
  31. wrap.MsgError(err.Error())
  32. return
  33. }
  34. wrap.RecreateProductXmlFile()
  35. wrap.ResetCacheBlocks()
  36. // Reload current page
  37. wrap.Write(`window.location.reload(false);`)
  38. })
  39. }