Пример #1
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
            });
        }