module_shop_act_detach.go 940 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. 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. ctx,
  21. `UPDATE fave_shop_products SET
  22. parent_id = NULL,
  23. active = 0
  24. WHERE
  25. id = ?
  26. ;`,
  27. utils.StrToInt(pf_id),
  28. ); err != nil {
  29. return err
  30. }
  31. return nil
  32. }); err != nil {
  33. wrap.MsgError(err.Error())
  34. return
  35. }
  36. wrap.RecreateProductXmlFile()
  37. wrap.ResetCacheBlocks()
  38. // Reload current page
  39. wrap.Write(`window.location.reload(false);`)
  40. })
  41. }