Пример #1
0
        public object Do_PayOrder(BaseApi baseApi)
        {
            PayOrderParam payOrderParam = JsonConvert.DeserializeObject <PayOrderParam>(baseApi.param.ToString());

            if (payOrderParam == null)
            {
                throw new ApiException(CodeMessage.InvalidParam, "InvalidParam");
            }

            PreOrder preOrder = Utils.GetCache <PreOrder>(payOrderParam.preOrderId);

            if (preOrder == null)
            {
                throw new ApiException(CodeMessage.InvalidPreOrderId, "InvalidPreOrderId");
            }
            string memberId  = Utils.GetMemberID(baseApi.token);
            string orderCode = preOrder.storeCode + memberId.PadLeft(6, '0') + DateTime.Now.ToString("yyyyMMddHHmmss");

            OrderDao orderDao = new OrderDao();

            if (orderDao.InsertOrder(memberId, orderCode, preOrder, payOrderParam.remark, preOrder.addr, 0))
            {
                Utils.DeleteCache(payOrderParam.preOrderId);
                Order order = orderDao.GetOrderInfoByCode(orderCode);
                if (order == null)
                {
                    throw new ApiException(CodeMessage.CreateOrderError, "CreateOrderError");
                }
                return(order);
            }
            else
            {
                throw new ApiException(CodeMessage.CreateOrderError, "CreateOrderError");
            }
        }
Пример #2
0
        public object Do_PayOrderV2(BaseApi baseApi)
        {
            PayOrderParamV2 payOrderParamV2 = JsonConvert.DeserializeObject <PayOrderParamV2>(baseApi.param.ToString());

            if (payOrderParamV2 == null)
            {
                throw new ApiException(CodeMessage.InvalidParam, "InvalidParam");
            }

            PreOrder preOrder = Utils.GetCache <PreOrder>(payOrderParamV2.preOrderId);

            if (preOrder == null)
            {
                throw new ApiException(CodeMessage.InvalidPreOrderId, "InvalidPreOrderId");
            }
            string memberId = Utils.GetMemberID(baseApi.token);


            MallDao  mallDao  = new MallDao();
            OrderDao orderDao = new OrderDao();
            Store    store    = mallDao.GetStoreListV2(memberId).Find
                                (
                item => item.storeId.Equals(payOrderParamV2.storeBranchId)
                                );

            if (store == null)
            {
                throw new ApiException(CodeMessage.InvalidStore, "InvalidStore");
            }
            preOrder.total    += store.expFee;
            preOrder.storeCode = store.storeCode;
            string orderCode = preOrder.storeCode + memberId.PadLeft(6, '0') + DateTime.Now.ToString("yyyyMMddHHmmss");

            if (orderDao.InsertOrder(memberId, orderCode, preOrder, payOrderParamV2.remark, payOrderParamV2.expAddr, store.expFee))
            {
                Utils.DeleteCache(payOrderParamV2.preOrderId);
                Order order = orderDao.GetOrderInfoByCode(orderCode);
                if (order == null)
                {
                    throw new ApiException(CodeMessage.CreateOrderError, "CreateOrderError");
                }
                return(order);
            }
            else
            {
                throw new ApiException(CodeMessage.CreateOrderError, "CreateOrderError");
            }
        }
Пример #3
0
        public object Do_PreOrder(BaseApi baseApi)
        {
            List <PreOrderParam> preOrderParamList = JsonConvert.DeserializeObject <List <PreOrderParam> >(baseApi.param.ToString());

            if (preOrderParamList == null || preOrderParamList.Count == 0)
            {
                throw new ApiException(CodeMessage.InvalidParam, "InvalidParam");
            }

            PreOrder preOrder = new PreOrder();
            OrderDao orderDao = new OrderDao();

            string memberId = Utils.GetMemberID(baseApi.token);
            Store  store    = orderDao.GetStoreByMemberId(memberId);

            if (store == null)
            {
                throw new ApiException(CodeMessage.BindStoreFirst, "BindStoreFirst");
            }
            preOrder.addr = store.storeAddr;

            string[] goodsIds = new string[preOrderParamList.Count];
            for (int i = 0; i < preOrderParamList.Count; i++)
            {
                goodsIds[i] = preOrderParamList[i].goodsId;
            }
            List <Goods> goodsList = orderDao.GetGoodsByGoodsIds(goodsIds);

            int total = 0;
            List <PreOrderGoods> list = new List <PreOrderGoods>();

            foreach (Goods goods in goodsList)
            {
                var preOrderParam = preOrderParamList.Find
                                    (
                    item => item.goodsId.Equals(goods.goodsId)
                                    );
                if (preOrderParam == null)
                {
                    throw new ApiException(CodeMessage.InvalidGoods, "InvalidGoods");
                }
                if (preOrderParam.goodsNum < 0)
                {
                    throw new ApiException(CodeMessage.ErrorNum, "ErrorNum");
                }
                if (preOrderParam.goodsNum <= goods.goodsStock)
                {
                    total += goods.goodsPrice * preOrderParam.goodsNum;
                    PreOrderGoods preOrderGoods = new PreOrderGoods
                    {
                        cartId     = preOrderParam.cartId,
                        goodsNum   = preOrderParam.goodsNum,
                        goodsId    = goods.goodsId,
                        goodsImg   = goods.goodsImg,
                        goodsName  = goods.goodsName,
                        goodsPrice = goods.goodsPrice,
                    };
                    list.Add(preOrderGoods);
                }
                else
                {
                    throw new ApiException(CodeMessage.NotEnoughGoods, "NotEnoughGoods");
                }
            }
            preOrder.list       = list;
            preOrder.total      = total;
            preOrder.storeCode  = store.storeCode;
            preOrder.preOrderId = Guid.NewGuid().ToString();

            Utils.SetCache(preOrder.preOrderId, preOrder, 0, 5, 0);
            return(preOrder);
        }
Пример #4
0
        public object Do_StartQBuyGoods(BaseApi baseApi)
        {
            StartQBuyGoodsParam startQBuyGoodsParam = JsonConvert.DeserializeObject <StartQBuyGoodsParam>(baseApi.param.ToString());

            if (startQBuyGoodsParam == null)
            {
                throw new ApiException(CodeMessage.InvalidParam, "InvalidParam");
            }

            ActiveDao activeDao = new ActiveDao();
            var       qBuyGoods = activeDao.GetQbuyGoodsByQBuyIdAndQBuyGoodsId(startQBuyGoodsParam.qBuyCode, startQBuyGoodsParam.qBuyGoodsId);

            PreOrder  preOrder  = new PreOrder();
            OrderDao  orderDao  = new OrderDao();
            MemberDao memberDao = new MemberDao();
            string    memberId  = Utils.GetMemberID(baseApi.token);
            Store     store     = orderDao.GetStoreByMemberId(memberId);

            if (store == null)
            {
                throw new ApiException(CodeMessage.BindStoreFirst, "BindStoreFirst");
            }
            preOrder.addr = store.storeAddr;

            string[] goodsIds = new string[1];
            goodsIds[0] = qBuyGoods.goodsId;

            List <Goods> goodsList = orderDao.GetGoodsByGoodsIds(goodsIds);

            int total = 0;
            List <PreOrderGoods> list = new List <PreOrderGoods>();

            foreach (Goods goods in goodsList)
            {
                if (qBuyGoods.goodsId != goods.goodsId)
                {
                    throw new ApiException(CodeMessage.InvalidGoods, "InvalidGoods");
                }
                if (Convert.ToInt32(qBuyGoods.num) < 0)
                {
                    throw new ApiException(CodeMessage.ErrorNum, "ErrorNum");
                }
                if (Convert.ToInt32(qBuyGoods.num) <= goods.goodsStock)
                {
                    total += Convert.ToInt32(qBuyGoods.price) * Convert.ToInt32(qBuyGoods.num);
                    PreOrderGoods preOrderGoods = new PreOrderGoods
                    {
                        goodsNum   = Convert.ToInt32(qBuyGoods.num),
                        goodsId    = goods.goodsId,
                        goodsImg   = goods.goodsImg,
                        goodsName  = goods.goodsName,
                        goodsPrice = Convert.ToInt32(qBuyGoods.price),
                    };
                    list.Add(preOrderGoods);
                }
                else
                {
                    throw new ApiException(CodeMessage.NotEnoughGoods, "NotEnoughGoods");
                }
            }
            preOrder.list      = list;
            preOrder.total     = total;
            preOrder.storeCode = store.storeCode;

            MemberInfo memberInfo = memberDao.GetMemberInfo(memberId);

            if (memberInfo.heart < Convert.ToInt32(total))
            {
                throw new ApiException(CodeMessage.NotEnoughHearts, "NotEnoughHearts");
            }

            string orderCode = preOrder.storeCode + memberId.PadLeft(6, '0') + DateTime.Now.ToString("yyyyMMddHHmmss");

            if (!activeDao.updateQBuy(startQBuyGoodsParam.qBuyCode, orderCode))
            {
                throw new ApiException(CodeMessage.PayForOrderError, "PayForOrderError");
            }
            if (!orderDao.InsertOrder(memberId, orderCode, preOrder, startQBuyGoodsParam.qBuyCode, preOrder.addr, 0))
            {
                throw new ApiException(CodeMessage.CreateOrderError, "CreateOrderError");
            }
            Order order = orderDao.GetOrderInfoByCode(orderCode);

            if (!orderDao.PayForOrder(memberId, order, memberInfo.heart))
            {
                throw new ApiException(CodeMessage.PayForOrderError, "PayForOrderError");
            }
            return("");
        }