Exemplo n.º 1
0
        public static object ApiPaySetAddressAndDelivery(IRequest context)
        {
            var siteId     = context.GetPostInt("siteId");
            var sessionId  = context.GetPostString("sessionId");
            var addressId  = context.GetPostInt("addressId");
            var deliveryId = context.GetPostInt("deliveryId");

            AddressDao.SetDefault(context.UserName, sessionId, addressId);

            var cartInfoList = CartDao.GetCartInfoList(siteId, context.UserName, sessionId);
            var addressInfo  = AddressDao.GetAddressInfo(addressId);
            var deliveryInfo = DeliveryDao.GetDeliveryInfo(deliveryId);

            var deliveryFee = Utils.GetDeliveryFee(cartInfoList, addressInfo, deliveryInfo);

            return(new
            {
                deliveryFee
            });
        }
Exemplo n.º 2
0
        public static object ApiPay(IRequest context)
        {
            var siteId      = context.GetPostInt("siteId");
            var sessionId   = context.GetPostString("sessionId");
            var addressId   = context.GetPostInt("addressId");
            var channel     = context.GetPostString("channel");
            var totalFee    = context.GetPostDecimal("totalFee");
            var deliveryFee = context.GetPostDecimal("deliveryFee");
            var totalCount  = context.GetPostInt("totalCount");
            var message     = context.GetPostString("message");
            var cartIdList  = context.GetPostObject <List <string> >("cartIdList").Select(cartId => Utils.ParseInt(cartId)).ToList();
            var isMobile    = context.GetPostBool("isMobile");
            var successUrl  = context.GetPostString("successUrl");

            if (string.IsNullOrEmpty(successUrl))
            {
                successUrl = Context.SiteApi.GetSiteUrl(siteId);
            }

            var guid       = Regex.Replace(Convert.ToBase64String(Guid.NewGuid().ToByteArray()), "[/+=]", "");
            var paymentApi = new PaymentApi(siteId);

            var siteInfo = Context.SiteApi.GetSiteInfo(siteId);

            var addressInfo = AddressDao.GetAddressInfo(addressId);
            var orderInfo   = new OrderInfo
            {
                SiteId      = siteId,
                Guid        = guid,
                AddDate     = DateTime.Now,
                Address     = addressInfo.Address,
                ZipCode     = addressInfo.ZipCode,
                Location    = addressInfo.Location,
                Message     = message,
                Mobile      = addressInfo.Mobile,
                Channel     = channel,
                TotalFee    = totalFee,
                ExpressCost = deliveryFee,
                RealName    = addressInfo.RealName,
                UserName    = context.UserName,
                SessionId   = sessionId,
                IsPaied     = false,
                State       = string.Empty,
                Tel         = addressInfo.Tel,
                TotalCount  = totalCount
            };

            orderInfo.Id = OrderDao.Insert(orderInfo);

            var cartInfoList  = CartDao.GetCartInfoList(siteId, context.UserName, sessionId);
            var newCardIdList = new List <int>();

            foreach (var newCardInfo in cartInfoList)
            {
                newCardIdList.Add(newCardInfo.Id);
            }

            //CartDao.UpdateOrderId(cartIdList, orderInfo.Id);
            CartDao.UpdateOrderId(newCardIdList, orderInfo.Id);

            var amount  = totalFee + deliveryFee;
            var orderNo = guid;

            successUrl = $"{successUrl}?guid={guid}";
            if (channel == "alipay")
            {
                return(isMobile
                    ? paymentApi.ChargeByAlipayMobi(siteInfo.SiteName, amount, orderNo, successUrl)
                    : paymentApi.ChargeByAlipayPc(siteInfo.SiteName, amount, orderNo, successUrl));
            }
            if (channel == "weixin")
            {
                var apiUrl = Context.PluginApi.GetPluginApiUrl(Main.PluginId);

                var notifyUrl = $"{apiUrl}/{nameof(ApiPayWeixinNotify)}/{orderNo}";
                var url       = HttpUtility.UrlEncode(paymentApi.ChargeByWeixin(siteInfo.SiteName, amount, orderNo, notifyUrl));
                var qrCodeUrl =
                    $"{apiUrl}/{nameof(ApiPayQrCode)}?qrcode={url}";
                return(new
                {
                    qrCodeUrl,
                    orderNo
                });
            }
            if (channel == "jdpay")
            {
                return(paymentApi.ChargeByJdpay(siteInfo.SiteName, amount, orderNo, successUrl));
            }

            return(new
            {
                guid,
                amount
            });
        }