package summary

import (
	"context"
	"time"

	"bsm/full/module/ec/order/internal/impl"
	"bsm/full/module/ec/order/internal/models"
	pb "bsm/full/module/ec/order/pb"

	"git.apinb.com/bsm-sdk/core/errcode"
	"git.apinb.com/bsm-sdk/core/printer"
	"git.apinb.com/bsm-sdk/core/service"
)

// 检测是否有未确认及付款的订单
func Check(ctx context.Context, in *pb.Empty) (reply *pb.OrderStatusReply, err error) {
	// parse authorization meta.
	auth, err := service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
	if err != nil {
		return nil, err
	}
	var (
		summary = new(models.OrderSummary)
	)
	err = impl.DBService.Where("passport_id = ?", auth.ID).First(&summary).Error
	if err != nil {
		printer.Error(err.Error())
		return nil, errcode.ErrDB
	}

	return &pb.OrderStatusReply{
		Code:     0,
		Identity: summary.OrderNo,
		Message:  "OK",
		Timeseq:  time.Now().UnixNano(),
	}, nil

}
