Browse Source

CP Shop, change order status action

Vova Tkach 5 years ago
parent
commit
b5bb1fcf29
3 changed files with 55 additions and 1 deletions
  1. 1 1
      assets/cp.scripts.js
  2. 0 0
      assets/cp.scripts.js.go
  3. 54 0
      modules/module_shop_act_order_set_status.go

+ 1 - 1
assets/cp.scripts.js

@@ -7747,7 +7747,7 @@
 						url: '/cp/',
 						url: '/cp/',
 						data: {
 						data: {
 							action: 'shop-order-set-status',
 							action: 'shop-order-set-status',
-							order_id: id,
+							id: id,
 							status: status,
 							status: status,
 						}
 						}
 					}).done(function(data) {
 					}).done(function(data) {

File diff suppressed because it is too large
+ 0 - 0
assets/cp.scripts.js.go


+ 54 - 0
modules/module_shop_act_order_set_status.go

@@ -0,0 +1,54 @@
+package modules
+
+import (
+	"golang-fave/engine/wrapper"
+	"golang-fave/utils"
+)
+
+func (this *Modules) RegisterAction_ShopOrderSetStatus() *Action {
+	return this.newAction(AInfo{
+		WantDB:    true,
+		Mount:     "shop-order-set-status",
+		WantAdmin: true,
+	}, func(wrap *wrapper.Wrapper) {
+		pf_id := wrap.R.FormValue("id")
+		pf_status := wrap.R.FormValue("status")
+
+		if !utils.IsNumeric(pf_id) {
+			wrap.MsgError(`Inner system error`)
+			return
+		}
+
+		if !utils.IsNumeric(pf_status) {
+			wrap.MsgError(`Inner system error`)
+			return
+		}
+
+		if !(utils.StrToInt(pf_status) >= 0 && utils.StrToInt(pf_status) <= 4) {
+			wrap.MsgError(`Inner system error`)
+			return
+		}
+
+		if err := wrap.DB.Transaction(func(tx *wrapper.Tx) error {
+			if _, err := tx.Exec(
+				`UPDATE shop_orders SET
+					status = ?
+				WHERE
+					id = ?
+				;`,
+				utils.StrToInt(pf_status),
+				utils.StrToInt(pf_id),
+			); err != nil {
+				return err
+			}
+
+			return nil
+		}); err != nil {
+			wrap.MsgError(err.Error())
+			return
+		}
+
+		// Reload current page
+		wrap.Write(`window.location.reload(false);`)
+	})
+}

Some files were not shown because too many files changed in this diff