コード例 #1
0
        public static object ApiCartGet(IRequest context)
        {
            var siteId    = context.GetPostInt("siteId");
            var sessionId = context.GetPostString("sessionId");

            var cartInfoList = CartDao.GetCartInfoList(siteId, context.UserName, sessionId);

            var     totalCount = 0;
            decimal totalFee   = 0;

            foreach (var cartInfo in cartInfoList)
            {
                totalCount += cartInfo.Count;
                totalFee   += cartInfo.Fee * cartInfo.Count;
            }

            var configInfo = Context.ConfigApi.GetConfig <ConfigInfo>(Main.PluginId, siteId) ?? new ConfigInfo();

            return(new
            {
                context.IsUserLoggin,
                configInfo.IsForceLogin,
                cartInfoList,
                totalCount,
                totalFee
            });
        }
コード例 #2
0
        public static object ApiPaySaveAddress(IRequest context)
        {
            var siteId      = context.GetPostInt("siteId");
            var sessionId   = context.GetPostString("sessionId");
            var deliveryId  = context.GetPostInt("deliveryId");
            var addressInfo = context.GetPostObject <AddressInfo>("addressInfo");
            var isEdit      = context.GetPostBool("isEdit");

            addressInfo.UserName  = context.UserName;
            addressInfo.SessionId = sessionId;

            if (isEdit)
            {
                AddressDao.Update(addressInfo);
            }
            else
            {
                addressInfo.Id = AddressDao.Insert(addressInfo);
            }

            AddressDao.SetDefault(context.UserName, sessionId, addressInfo.Id);

            var cartInfoList = CartDao.GetCartInfoList(siteId, context.UserName, sessionId);
            var deliveryInfo = DeliveryDao.GetDeliveryInfo(deliveryId);
            var deliveryFee  = Utils.GetDeliveryFee(cartInfoList, addressInfo, deliveryInfo);

            return(new
            {
                addressInfo,
                deliveryFee
            });
        }
コード例 #3
0
        public static object ApiAddSuccessGet(IRequest context)
        {
            var siteId    = context.GetPostInt("siteId");
            var sessionId = context.GetPostString("sessionId");

            var cartInfoList = CartDao.GetCartInfoList(siteId, context.UserName, sessionId);

            var     productName = string.Empty;
            decimal productFee  = 0;
            var     totalCount  = 0;
            decimal totalFee    = 0;

            foreach (var cartInfo in cartInfoList)
            {
                if (string.IsNullOrEmpty(productName))
                {
                    productName = cartInfo.ProductName;
                    productFee  = cartInfo.Fee;
                }
                totalCount += cartInfo.Count;
                totalFee   += cartInfo.Fee * cartInfo.Count;
            }

            return(new
            {
                productName,
                productFee = "¥" + productFee.ToString("N"),
                totalCount,
                totalFee = "¥" + totalFee.ToString("N")
            });
        }
コード例 #4
0
        public static object ApiPayGet(IRequest context)
        {
            var siteId    = context.GetPostInt("siteId");
            var sessionId = context.GetPostString("sessionId");

            if (context.IsUserLoggin)
            {
                CartDao.UpdateUserName(siteId, sessionId, context.UserName);
            }

            var addressInfoList = AddressDao.GetAddressInfoList(context.UserName, sessionId);
            var cartInfoList    = CartDao.GetCartInfoList(siteId, context.UserName, sessionId);

            AddressInfo addressInfo = null;

            foreach (var addInfo in addressInfoList)
            {
                if (addInfo.IsDefault)
                {
                    addressInfo = addInfo;
                }
            }
            if (addressInfo == null && addressInfoList.Count > 0)
            {
                addressInfo = addressInfoList[0];
            }

            var          deliveryInfoList = DeliveryDao.GetDeliveryInfoList(siteId);
            DeliveryInfo deliveryInfo     = null;

            if (deliveryInfoList.Count > 0)
            {
                deliveryInfo = deliveryInfoList[0];
            }

            var     totalCount  = 0;
            decimal totalFee    = 0;
            var     deliveryFee = Utils.GetDeliveryFee(cartInfoList, addressInfo, deliveryInfo);

            foreach (var cartInfo in cartInfoList)
            {
                totalCount += cartInfo.Count;
                totalFee   += cartInfo.Fee * cartInfo.Count;
            }

            return(new
            {
                addressInfoList,
                addressId = addressInfo?.Id ?? 0,
                deliveryInfoList,
                deliveryId = deliveryInfo?.Id ?? 0,
                cartInfoList,
                totalCount,
                totalFee,
                deliveryFee
            });
        }
コード例 #5
0
        public static object ApiOrderGet(IRequest context)
        {
            var guid      = context.GetPostString("guid");
            var orderInfo = OrderDao.GetOrderInfo(guid);

            if (orderInfo != null)
            {
                orderInfo.CartInfoList = CartDao.GetCartInfoList(orderInfo.Id);
            }

            return(new
            {
                context.IsUserLoggin,
                orderInfo
            });
        }
コード例 #6
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
            });
        }
コード例 #7
0
        public static object ApiOrdersGet(IRequest context)
        {
            var type = context.GetPostString("type");

            var orderInfoList = new List <OrderInfo>();

            if (context.IsUserLoggin)
            {
                orderInfoList = string.IsNullOrEmpty(type)
                    ? OrderDao.GetOrderInfoList(context.UserName, string.Empty)
                    : OrderDao.GetOrderInfoList(context.UserName, Convert.ToBoolean(type));

                foreach (var orderInfo in orderInfoList)
                {
                    orderInfo.CartInfoList = CartDao.GetCartInfoList(orderInfo.Id);
                }
            }

            return(new
            {
                context.IsUserLoggin,
                orderInfoList
            });
        }
コード例 #8
0
        public void Page_Load(object sender, EventArgs e)
        {
            var request = SiteServer.Plugin.Context.GetCurrentRequest();

            _siteId  = request.GetQueryInt("siteId");
            _isPaied = request.GetQueryBool("isPaied");
            _state   = request.GetQueryString("state");
            _keyword = request.GetQueryString("keyword");

            if (!request.AdminPermissions.HasSitePermissions(_siteId, Main.PluginId))
            {
                Response.Write("<h1>未授权访问</h1>");
                Response.End();
                return;
            }

            if (!string.IsNullOrEmpty(Request.QueryString["delete"]) &&
                !string.IsNullOrEmpty(Request.QueryString["idCollection"]))
            {
                var array = Request.QueryString["idCollection"].Split(',');
                var list  = array.Select(s => Utils.ParseInt(s)).ToList();
                OrderDao.Delete(list);
                LtlMessage.Text = Utils.GetMessageHtml("删除成功!", true);
            }

            SpContents.ControlToPaginate = RptContents;
            SpContents.ItemsPerPage      = 30;
            SpContents.SelectCommand     = OrderDao.GetSelectStringBySearch(_siteId, _isPaied, _state, _keyword);
            SpContents.SortField         = nameof(OrderInfo.Id);
            SpContents.SortMode          = "DESC";
            RptContents.ItemDataBound   += RptContents_ItemDataBound;

            if (IsPostBack)
            {
                return;
            }

            LtlPageTitle.Text = Utils.GetStateText(_isPaied, _state) + "订单管理";

            DdlSearchState.Items.Add(new ListItem(Utils.GetStateText(false, string.Empty), $"{false}_"));
            DdlSearchState.Items.Add(new ListItem(Utils.GetStateText(true, string.Empty), $"{true}_"));
            DdlSearchState.Items.Add(new ListItem(Utils.GetStateText(true, nameof(OrderState.Done)), $"{true}_{nameof(OrderState.Done)}"));
            Utils.SelectListItems(DdlSearchState, $"{_isPaied}_{_state}");
            TbSearchKeyword.Text = _keyword;

            SpContents.DataBind();

            BtnDelete.Attributes.Add("onclick", Utils.ReplaceNewline($@"
var ids = [];
$(""input[name='idCollection']:checked"").each(function () {{
    ids.push($(this).val());}}
);
if (ids.length > 0){{
    {Utils.SwalWarning("删除订单", "此操作将删除所选订单,确定吗?", "取 消", "删 除",
                $"location.href='{GetRedirectUrl(_siteId, _isPaied, _state, _keyword)}&delete={true}&idCollection=' + ids.join(',')")}
}} else {{
    {Utils.SwalError("请选择需要删除的订单!", string.Empty)}
}}
;return false;", string.Empty));

            BtnStateAll.Attributes.Add("onclick", Utils.ReplaceNewline($@"
var ids = [];
$(""input[name='idCollection']:checked"").each(function () {{
    ids.push($(this).val());}}
);
if (ids.length > 0){{
    location.href = '{GetRedirectUrl(_siteId, _isPaied, _state, _keyword)}&state={true}&idCollection=' + ids.join(',')
}} else {{
    {Utils.SwalError("请选择需要更改状态的订单!", string.Empty)}
}}
;return false;", string.Empty));

            if (!string.IsNullOrEmpty(Request.QueryString["view"]))
            {
                PhModalView.Visible = true;

                var id = Utils.ParseInt(Request.QueryString["id"]);

                var orderInfo = OrderDao.GetOrderInfo(id);
                if (!string.IsNullOrEmpty(orderInfo.Message))
                {
                    LtlModalViewMessage.Text = Utils.GetMessageHtml(orderInfo.Message);
                }

                LtlGuid.Text     = orderInfo.Guid;
                LtlRealName.Text = orderInfo.RealName;
                LtlMobile.Text   = orderInfo.Mobile;
                LtlTel.Text      = orderInfo.Tel;
                LtlLocation.Text = orderInfo.Location;
                LtlAddress.Text  = orderInfo.Address;
                LtlZipCode.Text  = orderInfo.ZipCode;
                LtlChannel.Text  = Utils.GetChannelText(orderInfo.Channel);
                LtlAmount.Text   =
                    $@"商品金额:¥{orderInfo.TotalFee:N2}元 运费:¥{orderInfo.ExpressCost:N2}元 合计:¥{orderInfo.TotalFee +
	                                                                                       orderInfo.ExpressCost:N2}元"    ;
                LtlAddDate.Text = orderInfo.AddDate.ToString("yyyy-MM-dd HH:mm:ss");
                LtlState.Text   = Utils.GetStateText(orderInfo.IsPaied, orderInfo.State);

                RptCarts.DataSource     = CartDao.GetCartInfoList(orderInfo.Id);
                RptCarts.ItemDataBound += RptCarts_ItemDataBound;
                RptCarts.DataBind();

                BtnState.Attributes.Add("onclick", Utils.ReplaceNewline($@"
location.href = '{GetRedirectUrl(_siteId, _isPaied, _state, _keyword)}&setState={true}&idCollection={id}';
return false;", string.Empty));
            }
            else if (!string.IsNullOrEmpty(Request.QueryString["setState"]) &&
                     !string.IsNullOrEmpty(Request.QueryString["idCollection"]))
            {
                PhModalState.Visible = true;
                DdlState.Items.Add(new ListItem(Utils.GetStateText(false, string.Empty), $"{false}_"));
                DdlState.Items.Add(new ListItem(Utils.GetStateText(true, string.Empty), $"{true}_"));
                DdlState.Items.Add(new ListItem(Utils.GetStateText(true, nameof(OrderState.Done)),
                                                $"{true}_{nameof(OrderState.Done)}"));
            }
        }
コード例 #9
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
            });
        }