resp := make(map[string] interface{})
db_glass_local_order := database.Db_conn["db_glass_local_order"]
sess := db_glass_local_order.NewSession()
order_id := c.PostForm("order_id")
customer_company := c.PostForm("customer_company")
operator_id := c.PostForm("operator_id")
items := c.PostForm("items")
if err := sess.Begin(); err != nil {
resp["status"] = "1"
resp["msg"] = err
c.JSON(http.StatusOK, resp)
return
}
sql := "INSERT INTO `tb_local_order`(`id`, `customer_company`, `operator_id`) VALUES ('"+ order_id +"', '"+ customer_company +"', '"+ operator_id +"')"
_, err := sess.QueryString(sql)
err_handle.Check(err,c)
if err != nil{
sess.Rollback()
resp["status"] = "1"
resp["msg"] = "数据库写入失败!"
c.JSON(http.StatusOK, resp)
return
}
var items_data []map[string]string
items1:=[]byte(items)
err =json.Unmarshal(items1,&items_data)
err_handle.Check(err,c)
for _,v := range items_data{
sql := "INSERT INTO `tb_local_order_item`(`id`, `order_id`, `brand_id`, `category_id`, `level_id`, `width`, `height`, `thickness`, `chip`, `pkg_num`) VALUES ('"+ v["id"] +"', '"+ order_id +"', '"+ v["brand_id"] +"', '"+ v["category_id"] +"', '"+ v["level_id"] +"', "+ v["width"] +", "+ v["height"] +", "+ v["thickness"] +", "+ v["chip"] +", "+ v["pkg_num"] +",);"
_, err := sess.QueryString(sql)
err_handle.Check(err,c)
if err != nil{
sess.Rollback()
resp["status"] = "1"
resp["msg"] = "数据库写入失败!"
c.JSON(http.StatusOK, resp)
return
}
}
sess.Commit()
resp["status"] = "0"
c.JSON(http.StatusOK, resp)