123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- package data_api
- import (
- "context"
- "gd_management/apis"
- "gd_management/common.in/storage"
- "gd_management/errors"
- "github.com/astaxie/beego/orm"
- "time"
- )
- func DataApiSetFreeDataCombo(ctx context.Context, req *apis.ManagementDataApiSetFreeDataComboReq, reply *apis.ManagementDataApiSetFreeDataComboReply) error {
- if req.QueryTypeId == 0 {
- return errors.ArgsError
- }
- task := func(o orm.Ormer) error {
- _, err := o.Raw("update t_gd_data_api_query_type set is_free=?,unit_price=? where id=?", req.DataApiQueryTypeIsFree, req.UnitPrice, req.QueryTypeId).Exec()
- if err != nil {
- return errors.DataBaseError
- }
- // TODO 同步商户单价数据(购买后同步)
- // update t_gd_merchant_data_api set unit_price=1 where unit_price=0
- if req.DataApiQueryTypeIsFree == false {
- var dataCombo apis.DataCombo
- err := o.QueryTable("t_gd_data_api_combo").Filter("query_type_id", req.QueryTypeId).Filter("type", 0).One(&dataCombo)
- if err != nil && err != orm.ErrNoRows {
- return errors.DataBaseError
- }
- var timeLayout = "2006-01-02 15:04:05"
- timeNow := time.Now().Format(timeLayout)
- dataCombo.QueryTypeId = req.QueryTypeId
- dataCombo.Count = req.Count
- dataCombo.UpdateTime = timeNow
- //dataCombo.IsFree = true
- dataCombo.Type = 0 //免费套餐
- if err == nil {
- _, err := o.Update(&dataCombo)
- if err != nil {
- return errors.DataBaseError
- }
- } else if err != nil && err == orm.ErrNoRows {
- dataCombo.CreateTime = timeNow
- _, err := o.Insert(&dataCombo)
- if err != nil {
- return errors.DataBaseError
- }
- }
- }
- return nil
- }
- tasks := []storage.DbaTasker{}
- tasks = append(tasks, storage.GenerateDbaTask(task))
- storage.ExecTrans(tasks...)
- return nil
- }
|