base_goods_function_define.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package entity
  2. import (
  3. "database/sql"
  4. "errors"
  5. "app.yhyue.com/moapp/jybase/date"
  6. . "bp.jydev.jianyu360.cn/BaseService/goodsCenter/public/db"
  7. )
  8. var Base_goods_function_define = Base_goods_function_define_struct{}
  9. //商品库
  10. type Base_goods_function_define_struct struct {
  11. Goods_code string
  12. Name string
  13. Appid string
  14. Function_code string
  15. Function_code_arr []string
  16. }
  17. //新增商品功能
  18. func (b *Base_goods_function_define_struct) Add() (int64, error) {
  19. now := date.NowFormat(date.Date_Full_Layout)
  20. if b.Appid == "" || b.Name == "" || b.Goods_code == "" {
  21. return -1, errors.New("缺失参数,请检查必要参数")
  22. }
  23. if c := Mysql_BaseService.CountBySql(`select count(1) from base_goods where code = ?`, b.Goods_code); c <= 0 {
  24. return -1, errors.New("请确认商品代码是否正确")
  25. }
  26. //商品功能定义明细表需要字段
  27. base_goods_function_detail_fields := []string{"appid", "goods_function_define_id", "function_code"}
  28. base_goods_function_detail_values := []interface{}{}
  29. //多个功能代码
  30. //新增商品功能定义表、商品功能定义明细表
  31. ok := Mysql_BaseService.ExecTx("新增商品功能", func(tx *sql.Tx) bool {
  32. //商品功能定义表
  33. id1 := Mysql_BaseService.InsertByTx(tx, "base_goods_function_define", map[string]interface{}{
  34. "appid": b.Appid,
  35. "goods_code": b.Goods_code,
  36. "name": b.Name,
  37. "create_time": now,
  38. })
  39. for _, v := range b.Function_code_arr {
  40. base_goods_function_detail_values = append(base_goods_function_detail_values, b.Appid)
  41. base_goods_function_detail_values = append(base_goods_function_detail_values, id1)
  42. base_goods_function_detail_values = append(base_goods_function_detail_values, v)
  43. }
  44. //商品功能定义明细表
  45. id2, id3 := Mysql_BaseService.InsertIgnoreBatch("base_goods_function_define_detail", base_goods_function_detail_fields, base_goods_function_detail_values)
  46. return id1 > 0 && id2 != -1 && id3 != -1
  47. })
  48. if ok {
  49. return 1, nil
  50. }
  51. return -1, errors.New("新增失败")
  52. }