package data_api import ( "context" "gd_management/apis" "gd_management/errors" "time" "gd_management/common.in/storage" "github.com/astaxie/beego/orm" ) func DataApiAddDataCombo(ctx context.Context, req *apis.ManagementDataApiAddDataComboReq, reply *apis.ManagementDataApiAddDataComboReply) error { if len(req.ManagementAddDataComboList) == 0 { return errors.ArgsError } task := func(o orm.Ormer) error { //deleted := false for index, _ := range req.ManagementAddDataComboList { if req.ManagementAddDataComboList[index].IsDelete { if req.ManagementAddDataComboList[index].ComboId > 0 { _, err := o.Delete(&apis.DataCombo{Id: req.ManagementAddDataComboList[index].ComboId}) if err != nil { return errors.DataBaseError } } } if req.ManagementAddDataComboList[index].QueryTypeId == 0 { return errors.ArgsError } if req.ManagementAddDataComboList[index].Price == 0 { return errors.ComboCostIsZero } if req.ManagementAddDataComboList[index].Type != 1 && req.ManagementAddDataComboList[index].Type != 2 { return errors.ComboTypeNotSupport } /*if deleted == false { deleted = true _, err := o.Raw("delete from t_gd_data_api_combo where query_type_id=? and type=?", req.ManagementAddDataComboList[index].QueryTypeId, req.ManagementAddDataComboList[index].Type).Exec() if err != nil { return errors.DataBaseError } }*/ var timeLayout = "2006-01-02 15:04:05" timeNow := time.Now().Format(timeLayout) var dataCombo apis.DataCombo dataCombo.QueryTypeId = req.ManagementAddDataComboList[index].QueryTypeId dataCombo.Type = req.ManagementAddDataComboList[index].Type dataCombo.Price = req.ManagementAddDataComboList[index].Price dataCombo.Count = req.ManagementAddDataComboList[index].Count if req.ManagementAddDataComboList[index].Type == 2 { dataCombo.TotalDay = req.ManagementAddDataComboList[index].TotalDay } dataCombo.Id = req.ManagementAddDataComboList[index].ComboId dataCombo.UpdateTime = timeNow dataCombo.CreateTime = timeNow //ataCombo.IsFree = false var err error if dataCombo.Id == 0 { _, err = o.Insert(&dataCombo) } else { _, err = o.Update(&dataCombo) } //_, err = o.Insert(&dataCombo) //_, err = o.Update(&dataCombo) if err != nil { return errors.DataBaseError } } return nil } tasks := []storage.DbaTasker{} tasks = append(tasks, storage.GenerateDbaTask(task)) storage.ExecTrans(tasks...) //reply.ComboId = id return nil }