package merchant_order

import (
	"context"
	"kami/internal/consts"
	"kami/internal/dao"
	"kami/internal/model/do"
	"kami/internal/model/entity"
	"kami/utility/config"

	"github.com/gogf/gf/v2/database/gdb"
)

func (s *sOrderSummary) SetBlockStatus(ctx context.Context, orderNo string, isBlock consts.RestrictStatus, tx gdb.TX) (err error) {
	status := 0 // 正常
	if isBlock == consts.RestrictStatus_Disable {
		status = 1
	}
	db := dao.V1OrderInfo.Ctx(ctx).DB(config.GetDatabaseV1())
	if tx != nil {
		db = db.TX(tx)
	}
	_, err = db.Where(dao.V1OrderInfo.Columns().BankOrderId, orderNo).Update(do.V1OrderInfo{
		IsBlock: status,
	})
	return
}

// GetOneById 返回指定id的数据
func (s *sOrderSummary) GetOneById(ctx context.Context, merchantOrderId string) (data *entity.V1OrderInfo, err error) {
	data = &entity.V1OrderInfo{}
	err = dao.V1OrderInfo.Ctx(ctx).DB(config.GetDatabaseV1()).Where(dao.V1OrderInfo.Columns().MerchantOrderId, merchantOrderId).Scan(&data)
	return
}

// GetOneByMerchantUid 返回指定uid的数据
func (s *sOrderSummary) GetOneByMerchantUid(ctx context.Context, merchantUid string) (data *entity.V1OrderInfo, err error) {
	data = &entity.V1OrderInfo{}
	err = dao.V1OrderInfo.Ctx(ctx).DB(config.GetDatabaseV1()).Where(dao.V1OrderInfo.Columns().MerchantOrderId, merchantUid).Scan(&data)
	return
}

func (s *sOrderSummary) GetOneByBankOrderId(ctx context.Context, bankOrderId string) (data *entity.V1OrderInfo, err error) {
	data = &entity.V1OrderInfo{}
	err = dao.V1OrderInfo.Ctx(ctx).DB(config.GetDatabaseV1()).Where(dao.V1OrderInfo.Columns().BankOrderId, bankOrderId).Scan(&data)
	return
}
