Пример #1
0
        public async Task <int> AddAsync(ExchangeEventDto dto)
        {
            var model = new ExchangeEvent()
            {
                AddTime   = DateTime.Now,
                AddressId = dto.AddressId,
                Deposit   = dto.Deposit,
                ExId      = dto.ExId,
                Examine   = dto.Examine,
                OrderNo   = dto.OrderNo,
                Status    = 0,
                UserId    = dto.UserId,
                VouId     = dto.VouId,
                ShenJia   = dto.ShenJia,
                Postage   = dto.Postage
            };

            model = await this.ExchangeEventRepository.AddAsync(model);

            return(model.Id);
        }
Пример #2
0
        public async Task <object> Post([FromBody] ExchangeEventViewModel model)
        {
            MessageBase2 result = new MessageBase2();

            var dto = await _exchangeService.FindAsync(model.ExId);

            decimal postage = dto.Postage == 0 ? await _postageService.GetPostageAsync() : dto.Postage; //邮费

            string  totalAmount = "";                                                                   //金额
            string  outTradeNo  = SysHelper.GenerateTradeNo();
            int     dep         = 0;                                                                    //押金
            decimal shenJia     = 0;

            switch (model.Examine)
            {
            case "身家兑换":
                shenJia = dto.Official.ToDecimal();;
                if (shenJia - (await _memberService.FindAsync(model.UserId)).ShenJia > 0)
                {
                    result.Success  = Permanent.FAILED;
                    result.Error    = (int)StatusCodeEnum.FORBIDDEN;
                    result.ErrorMsg = "身家不足";
                    return(result);
                }
                totalAmount = postage.ToString(CultureInfo.InvariantCulture);      //邮费
                break;

            case "会员租赁":
                dep = await _memberService.GetDepositAsync(model.UserId, dto.Official.ToInt32()); //总押金

                totalAmount = (postage + dep).ToString("0.00");                                   //邮费+押金
                break;

            case "单次租赁":
                decimal price = dto.Rent == 0 ? 30 : dto.Rent;
                dep = await _memberService.GetDepositAsync(model.UserId, dto.Official.ToInt32()); //总押金

                totalAmount = (postage + dep + price).ToString("0.00");                           //邮费+押金+30
                break;

            case "兑换券":
                postage = 0;
                dep     = await _memberService.GetDepositAsync(model.UserId, dto.Official.ToInt32()); //总押金

                totalAmount = (postage + dep).ToString("0.00");                                       //邮费+押金
                break;
            }

            ExchangeEventDto eedto = new ExchangeEventDto()
            {
                Deposit   = dep,
                UserId    = model.UserId,
                OrderNo   = outTradeNo,
                Examine   = model.Examine,
                AddressId = model.AddressId,
                ExId      = model.ExId,
                VouId     = model.VoucherId,
                Postage   = postage.ToDecimal(),
                ShenJia   = shenJia
            };
            int eeId = await _exchangeEventService.AddAsync(eedto);

            string passbackParams = "merchantType=兑换租赁&id=" + eeId;

            if (model.PayType == "Ali")
            {
                result.Data = AliPaySdk.Signature(dto.Title, model.Examine, totalAmount, outTradeNo, passbackParams);
            }
            if (model.PayType == "Wx")
            {
                result.Data = WxPaySdk.UnifiedOrder(dto.Title, model.Examine, totalAmount, outTradeNo, HttpContext.GetUserIp(), passbackParams);
            }



            return(result);
            //页面输出的response.Body就是orderString 可以直接给客户端请求,无需再做处理。
        }