Browse Source

Shop basket write to db, save progress

Vova Tkach 5 years ago
parent
commit
0028bd3067
3 changed files with 118 additions and 0 deletions
  1. 5 0
      engine/basket/basket.go
  2. 75 0
      modules/module_shop_order.go
  3. 38 0
      utils/mysql_basket_structs.go

+ 5 - 0
engine/basket/basket.go

@@ -152,6 +152,11 @@ func (this *Basket) ProductsCount(p *SBParam) int {
 	return 0
 }
 
+func (this *Basket) GetAll(p *SBParam) *utils.MySql_basket_order {
+	// TODO: ...
+	return nil
+}
+
 func (this *Basket) Cleanup() {
 	this.Lock()
 	defer this.Unlock()

+ 75 - 0
modules/module_shop_order.go

@@ -76,6 +76,81 @@ func (this *Modules) RegisterAction_ShopOrder() *Action {
 			}
 		}
 
+		// var lastID int64 = 0
+		// if err := wrap.DB.Transaction(func(tx *wrapper.Tx) error {
+		// 	// Insert row
+		// 	res, err := tx.Exec(
+		// 		`INSERT INTO blog_posts SET
+		// 			user = ?,
+		// 			name = ?,
+		// 			alias = ?,
+		// 			category = ?,
+		// 			briefly = ?,
+		// 			content = ?,
+		// 			datetime = ?,
+		// 			active = ?
+		// 		;`,
+		// 		wrap.User.A_id,
+		// 		pf_name,
+		// 		pf_alias,
+		// 		utils.StrToInt(pf_category),
+		// 		pf_briefly,
+		// 		pf_content,
+		// 		utils.UnixTimestampToMySqlDateTime(utils.GetCurrentUnixTimestamp()),
+		// 		utils.StrToInt(pf_active),
+		// 	)
+		// 	if err != nil {
+		// 		return err
+		// 	}
+
+		// 	// Get inserted post id
+		// 	lastID, err = res.LastInsertId()
+		// 	if err != nil {
+		// 		return err
+		// 	}
+
+		// 	// Block rows
+		// 	if _, err := tx.Exec("SELECT id FROM blog_posts WHERE id = ? FOR UPDATE;", lastID); err != nil {
+		// 		return err
+		// 	}
+
+		// 	// Insert post and categories relations
+		// 	catids := utils.GetPostArrayInt("cats[]", wrap.R)
+		// 	if len(catids) > 0 {
+		// 		var catsCount int
+		// 		err = tx.QueryRow(`
+		// 			SELECT
+		// 				COUNT(*)
+		// 			FROM
+		// 				blog_cats
+		// 			WHERE
+		// 				id IN(` + strings.Join(utils.ArrayOfIntToArrayOfString(catids), ",") + `)
+		// 			FOR UPDATE;`,
+		// 		).Scan(
+		// 			&catsCount,
+		// 		)
+		// 		if *wrap.LogCpError(&err) != nil {
+		// 			return err
+		// 		}
+		// 		if len(catids) != catsCount {
+		// 			return errors.New("Inner system error")
+		// 		}
+		// 		var balkInsertArr []string
+		// 		for _, el := range catids {
+		// 			balkInsertArr = append(balkInsertArr, `(`+utils.Int64ToStr(lastID)+`,`+utils.IntToStr(el)+`)`)
+		// 		}
+		// 		if _, err = tx.Exec(
+		// 			`INSERT INTO blog_cat_post_rel (post_id,category_id) VALUES ` + strings.Join(balkInsertArr, ",") + `;`,
+		// 		); err != nil {
+		// 			return err
+		// 		}
+		// 	}
+		// 	return nil
+		// }); err != nil {
+		// 	wrap.MsgError(err.Error())
+		// 	return
+		// }
+
 		// Clear user basket
 		wrap.ShopBasket.ClearBasket(&basket.SBParam{
 			R:         wrap.R,

+ 38 - 0
utils/mysql_basket_structs.go

@@ -0,0 +1,38 @@
+package utils
+
+type MySql_basket_currency struct {
+	Id          int
+	Name        string
+	Coefficient float64
+	Code        string
+	Symbol      string
+}
+
+type MySql_basket_product struct {
+	A_product_id int
+	A_price      float64
+	A_quantity   int
+}
+
+type MySql_basket_order struct {
+	Products   *[]MySql_basket_product
+	Currency   *MySql_basket_currency
+	TotalSum   float64
+	TotalCount int
+}
+
+// type MySql_basket_order struct {
+// 	A_currency_id int
+// 	A_currency_name string
+// 	A_currency_coefficient float64
+// 	A_currency_code string
+// 	A_currency_symbol string
+// 	A_client_last_name string
+// 	A_client_first_name string
+// 	A_client_second_name string
+// 	A_client_phone string
+// 	A_client_email string
+// 	A_client_delivery_comment string
+// 	A_client_order_comment string
+// 	A_status string
+// }