12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- package entity
- import (
- "database/sql"
- "errors"
- "app.yhyue.com/moapp/jybase/date"
- . "bp.jydev.jianyu360.cn/BaseService/goodsCenter/public/db"
- )
- var Base_goods_function_define = Base_goods_function_define_struct{}
- //商品库
- type Base_goods_function_define_struct struct {
- Goods_code string
- Name string
- Appid string
- Function_code string
- Function_code_arr []string
- }
- //新增商品功能
- func (b *Base_goods_function_define_struct) Add() (int64, error) {
- now := date.NowFormat(date.Date_Full_Layout)
- if b.Appid == "" || b.Name == "" || b.Goods_code == "" {
- return -1, errors.New("缺失参数,请检查必要参数")
- }
- if c := Mysql_BaseService.CountBySql(`select count(1) from base_goods where code = ?`, b.Goods_code); c <= 0 {
- return -1, errors.New("请确认商品代码是否正确")
- }
- //商品功能定义明细表需要字段
- base_goods_function_detail_fields := []string{"appid", "goods_function_define_id", "function_code"}
- base_goods_function_detail_values := []interface{}{}
- //多个功能代码
- //新增商品功能定义表、商品功能定义明细表
- ok := Mysql_BaseService.ExecTx("新增商品功能", func(tx *sql.Tx) bool {
- //商品功能定义表
- id1 := Mysql_BaseService.InsertByTx(tx, "base_goods_function_define", map[string]interface{}{
- "appid": b.Appid,
- "goods_code": b.Goods_code,
- "name": b.Name,
- "create_time": now,
- })
- for _, v := range b.Function_code_arr {
- base_goods_function_detail_values = append(base_goods_function_detail_values, b.Appid)
- base_goods_function_detail_values = append(base_goods_function_detail_values, id1)
- base_goods_function_detail_values = append(base_goods_function_detail_values, v)
- }
- //商品功能定义明细表
- id2, id3 := Mysql_BaseService.InsertIgnoreBatch("base_goods_function_define_detail", base_goods_function_detail_fields, base_goods_function_detail_values)
- return id1 > 0 && id2 != -1 && id3 != -1
- })
- if ok {
- return 1, nil
- }
- return -1, errors.New("新增失败")
- }
|