Exemplo n.º 1
0
        public void FlowService_Add_Returns_ParamaterItself()
        {
            // Arrange
            var service  = new FlowService(mockFlowRepo.Object);
            var flowData = new FlowDto
            {
                Id    = Guid.NewGuid(),
                Title = "Test Flow"
            };

            // Act
            var flow = service.Add(flowData);

            // Assert
            Assert.IsNotNull(flow);
            Assert.AreEqual(flowData.Id, flow.Id);
            Assert.AreEqual(flowData.Title, flow.Title);
        }
Exemplo n.º 2
0
        //退款
        public JsonResult Refund(long id)
        {
            var modelOrder = serviceOrder.GetModel(id);

            if (modelOrder.UserId == currentUser.UserId)
            {
                modelOrder.Items = serviceDetail.GetListDtoByOrderId(id);
                var minTime = modelOrder.Items[0].ReserveTimes.Min();
                if (modelOrder.Status == Enums.OrderStatus.Unused && minTime > DateTime.Now.AddMinutes(30))
                {
                    //获取支付订单
                    var modelPay = servicePay.GetModelBySourceId(Enums.PaySourceType.Order, id);
                    //创建退款订单
                    var modelRefund = new Pay
                    {
                        PayNo      = Common.CreateNo(),
                        UserId     = currentUser.UserId,
                        PayType    = Enums.PayType.Refund,
                        Total      = modelOrder.Total * -1,
                        Status     = Enums.PayStatus.Wait,
                        SourceType = Enums.PaySourceType.Order,
                        SourceIds  = id.ToString(),
                        Remark     = "订单:" + modelOrder.OrderNo,
                        AddTime    = DateTime.Now,
                        LastTime   = DateTime.Now
                    };
                    try
                    {
                        db.BeginTransaction();
                        //修改订单状态
                        serviceOrder.UpdateStatus(id, Enums.OrderStatus.Refund, Enums.OrderStatus.Unused);
                        serviceDetail.UpdateStatusByOrderId(id, id * -1);
                        modelRefund.PayId = servicePay.Add(modelRefund);
                        if (modelPay.PayType == Enums.PayType.Balance)
                        {
                            //修改退款状态
                            servicePay.UpdateStatus(modelRefund.PayId, Enums.PayStatus.Success, Enums.PayStatus.Wait);
                            //创建余额进账流水
                            serviceFlow.Add(new Flow
                            {
                                Currency   = Enums.Currency.Balance,
                                Total      = modelOrder.Total,
                                SourceType = Enums.FlowSourceType.Consume,
                                SourceIds  = modelRefund.PayId.ToString(),
                                UserId     = modelRefund.UserId,
                                AddTime    = DateTime.Now,
                                Remark     = "退款编号:" + modelRefund.PayNo
                            });
                        }
                        db.CommitTransaction();
                        result.code = 1;
                    }
                    catch (Exception ex)
                    {
                        db.RollbackTransaction();
                        result.mes = ex.Message;
                    }
                    if (result.code == 1)
                    {
                        //调用退款接口
                        if (modelPay.PayType == Enums.PayType.WeChatMP)
                        {
                            WeChatService.Refund(modelPay.PayNo, modelRefund.PayNo, modelPay.Total, modelRefund.Total * -1);
                        }
                    }
                }
                else
                {
                    result.mes = "订单开始前的30之前才可退款!";
                }
            }
            return(Json(result));
        }