Exemple #1
0
        /// <summary>
        /// 后台同意骑手取消
        /// </summary>
        /// <returns></returns>
        public string AgreeRiderCancel(webReq req)
        {
            var orderId = req.orderId;
            //var orderId = Convert.ToInt32(Request["orderId"]);
            var order = OrderInfoOper.Instance.GetById(orderId);

            if (order.status != 99)
            {
                return(JsonHelperHere.JsonMsg(false, "订单状态已改变"));
            }
            order.status = 5;

            OrderInfoOper.Instance.Update(order);

            OrderInfoOper.Instance.OrderCancelDoMoney(order);

            UPushHelper.Instance.PushUserOrderCancel(order);

            //用户取消订单,菜品返还给骑手
            var list      = OrderFoodsOper.Instance.GetByOrderId(order.id);
            var listFoods = new List <foodId_Amount>();

            foreach (var item in list)
            {
                foodId_Amount fa = new foodId_Amount(item);
                listFoods.Add(fa);
            }
            RiderStockOper.Instance.AddRs((int)order.riderId, listFoods);


            return(JsonHelperHere.JsonMsg(true, ""));
        }
Exemple #2
0
        public string Update(webReq req)
        {
            ResultForWeb r = new ResultForWeb
            {
                HttpCode = 200,
                Message  = "",
                data     = "{}"
            };
            var createTime   = req.createTime;
            var status       = req.status;
            var isActual     = Convert.ToBoolean(req.isActual);
            var remarks      = req.remarks;
            var riderId      = req.riderId;
            var orderAreaId  = req.orderAreaId;
            var endTime      = req.endTime;
            var riderComment = req.riderComment;
            var useBalance   = req.useBalance;
            var useCoupon    = req.useCoupon;
            var deposit      = req.deposit;
            var payTime      = req.payTime;
            var payType      = req.payType;
            var payMoney     = req.payMoney;

            var foodIds = req.foodIds;
            var amounts = req.amounts;

            var       orderId = req.orderId;
            OrderInfo order   = new OrderInfo();

            order.createTime  = Convert.ToDateTime(createTime);
            order.status      = Convert.ToInt32(status);
            order.isActual    = isActual;
            order.remarks     = remarks;
            order.riderId     = riderId;
            order.orderAreaId = orderAreaId;
            if (endTime < new DateTime(2017, 1, 1))
            {
                order.endTime = Convert.ToDateTime(endTime);
            }
            order.riderComment = riderComment;
            order.useBalance   = useBalance;
            order.useCoupon    = useCoupon;
            order.deposit      = deposit;
            order.payTime      = Convert.ToDateTime(payTime);
            order.payType      = payType;
            order.payMoney     = payMoney;
            order.id           = orderId;
            OrderInfoOper.Instance.Update(order);
            var listFoods = new List <foodId_Amount>();

            for (int i = 0; i < foodIds.Length; i++)
            {
                foodId_Amount fa = new foodId_Amount(Convert.ToInt32(foodIds[i]), Convert.ToInt32(amounts[i]));
                listFoods.Add(fa);
            }
            OrderFoodsOper.Instance.UpdateOrderFoodsForWeb(orderId, listFoods);
            return(JsonConvert.SerializeObject(r));
        }
Exemple #3
0
        public void Update(webReq req)
        {
            var       createTime   = Request["createTime"];
            var       status       = req.status;
            var       isActual     = Convert.ToBoolean(Request["isActual"]);
            var       remarks      = Request["remarks"];
            var       riderId      = req.riderId;
            var       orderAreaId  = req.orderAreaId;
            var       endTime      = Request["endTime"];
            var       riderComment = Request["riderComment"];
            var       useBalance   = req.useBalance;
            var       useCoupon    = req.useCoupon;
            var       deposit      = req.deposit;
            var       payTime      = Request["payTime"];
            var       payType      = req.payType;
            var       payMoney     = req.payMoney;
            var       foodIds      = Request.Form.GetValues("foodIds[]");
            var       amounts      = Request.Form.GetValues("amounts[]");
            var       orderId      = req.orderId;
            OrderInfo order        = new OrderInfo();

            order.createTime  = Convert.ToDateTime(createTime);
            order.status      = Convert.ToInt32(status);
            order.isActual    = isActual;
            order.remarks     = remarks;
            order.riderId     = riderId;
            order.orderAreaId = orderAreaId;
            if (endTime != "")
            {
                order.endTime = Convert.ToDateTime(endTime);
            }
            order.riderComment = riderComment;
            order.useBalance   = useBalance;
            order.useCoupon    = useCoupon;
            order.deposit      = deposit;
            order.payTime      = Convert.ToDateTime(payTime);
            order.payType      = payType;
            order.payMoney     = payMoney;
            order.id           = orderId;
            OrderInfoOper.Instance.Update(order);
            var listFoods = new List <foodId_Amount>();

            for (int i = 0; i < foodIds.Length; i++)
            {
                foodId_Amount fa = new foodId_Amount(Convert.ToInt32(foodIds[i]), Convert.ToInt32(amounts[i]));
                listFoods.Add(fa);
            }
            OrderFoodsOper.Instance.UpdateOrderFoodsForWeb(orderId, listFoods);
            //OrderInfo type = new OrderInfo();
            ////type.comment = Request["comment"];

            //type.id = Convert.ToInt32(Request["foodTypeId"]);
            //DoUpdate(type);
        }
        public HttpResponseMessage AgreeApply(AgreeApplyReq req)
        {
            var riderId = Convert.ToInt32(req.riderId);

            var   tokenStr = req.Token;
            Token token    = CacheHelper.GetRiderToken(tokenStr);

            if (token == null)
            {
                return(ControllerHelper.Instance.JsonResult(400, "token失效"));
            }
            if (token.Payload.UserID != riderId)
            {
                return(ControllerHelper.Instance.JsonResult(400, "token错误"));
            }

            //此处的两个骑手id要换一下
            var targetRiderId = Convert.ToInt32(req.targetRiderId);
            var listAr        = AllocateRecordOper.Instance.GetByRiderId(targetRiderId);

            var listArTemp = new List <AllocateRecord>();


            foreach (var item in listAr)
            {
                if (item.status != 1)//防止连点
                {
                    item.status = 1;
                    listArTemp.Add(item);
                    foodId_Amount fa        = new foodId_Amount((int)item.foodId, (int)item.amount);
                    var           listFoods = new List <foodId_Amount>
                    {
                        fa
                    };
                    if (RiderStockOper.Instance.RemoveRs((int)item.targetRiderId, listFoods))
                    {
                        RiderStockOper.Instance.AddRs((int)item.riderId, listFoods);
                    }
                    else
                    {
                        return(ControllerHelper.Instance.JsonResult(500, "您的库存不足"));
                    }
                }
            }

            foreach (var item in listArTemp)
            {
                AllocateRecordOper.Instance.Update(item);
            }

            UPushHelper.Instance.PushRiderAgree(riderId, targetRiderId);
            return(ControllerHelper.Instance.JsonResult(200, "调配成功"));
        }
Exemple #5
0
        /// <summary>
        /// 后台同意骑手取消
        /// </summary>
        /// <returns></returns>
        public string AgreeRiderCancel(webReq req)
        {
            ResultForWeb r = new ResultForWeb
            {
                HttpCode = 200,
                Message  = "",
                data     = "{}"
            };
            var orderId = req.orderId;
            var order   = OrderInfoOper.Instance.GetById(orderId);

            if (order.status != 99)
            {
                r.Message  = "订单状态已改变,不再需要取消";
                r.HttpCode = 500;
                return(JsonConvert.SerializeObject(r));
            }
            order.status = 5;

            OrderInfoOper.Instance.Update(order);

            OrderInfoOper.Instance.OrderCancelDoMoney(order);

            UPushHelper.Instance.PushUserOrderCancel(order);

            //用户取消订单,菜品返还给骑手
            var list      = OrderFoodsOper.Instance.GetByOrderId(order.id);
            var listFoods = new List <foodId_Amount>();

            foreach (var item in list)
            {
                foodId_Amount fa = new foodId_Amount(item);
                listFoods.Add(fa);
            }
            RiderStockOper.Instance.AddRs((int)order.riderId, listFoods);


            r.data = JsonHelperHere.JsonMsg(true, "");
            return(JsonConvert.SerializeObject(r));
        }
Exemple #6
0
        public Price_Deposit GetFoodPriceAndDepositByAFA(List <AreaId_foodId_amount> listafa, int areaId)
        {
            Price_Deposit result = new Price_Deposit();

            listafa = listafa.Where(p => p.areaId == areaId).ToList();
            if (listafa.Count < 1)
            {
                result.price   = 0;
                result.deposit = 0;
            }
            else
            {
                var listFoods = new List <foodId_Amount>();
                foreach (var item in listafa)
                {
                    foodId_Amount fa = new foodId_Amount();
                    fa.foodId = item.foodId;
                    fa.amount = item.amount;
                    listFoods.Add(fa);
                }
                result = GetFoodPriceAndDeposit(listFoods);
            }
            return(result);
        }
        public HttpResponseMessage GetFoods(GetFoodsReq req)
        {
            var tagId  = Convert.ToInt32(req.tagId);
            var userId = Convert.ToInt32(req.userId);
            var areaId = Convert.ToInt32(req.areaId);

            List <RiderStockJoin> listRs = RiderStockOper.Instance.GetMainRSByAreaId(areaId);

            if (listRs.Count == 0)
            {
                return(ControllerHelper.Instance.JsonEmptyArr(200, "该区域无菜品"));
            }
            var foodIdsInArea = listRs.Select(p => (int)p.foodId).Distinct().ToArray();

            var listTempFoods = new List <foodId_Amount>();//用户点过的菜

            if (userId != 0)
            {
                var listafa = CacheHelper.GetTempFoods2(userId);
                listafa = listafa.Where(p => p.areaId == areaId).ToList();
                if (listafa.Count > 0)
                {
                    foreach (var item in listafa)
                    {
                        foodId_Amount fa = new foodId_Amount();
                        fa.amount = item.amount;
                        fa.foodId = item.foodId;
                        listTempFoods.Add(fa);
                    }
                }
            }
            //如果点过的菜不在区域中,删掉。数量为0的也删掉
            listTempFoods = listTempFoods.Where(p => foodIdsInArea.Contains(p.foodId) && p.amount > 0).ToList();

            //点过的菜的总价
            var money = new Decimal();

            if (listTempFoods.Count > 0)
            {
                money = FoodInfoOper.Instance.GetFoodPriceAndDeposit(listTempFoods).price;
            }

            var foodIdsStr = string.Join(",", foodIdsInArea);

            var condition = " id in (" + foodIdsStr + ")";

            if (tagId != 0)
            {
                condition += " and foodTagId=@tagId";
            }
            var dict = new Dictionary <string, string>();

            dict.Add("@tagId", tagId.ToString());
            var listFoodView = CacheHelper.GetByCondition <FoodView>("foodview", condition, dict);

            if (listFoodView.Count > 0)
            {
                List <FoodsOnMapRes> listR = new List <FoodsOnMapRes>();

                if (listTempFoods.Count > 0)//如果缓存里有点过的菜 去库存里找
                {
                    foreach (var item in listFoodView)
                    {
                        var listHere = listTempFoods.Where(p => p.foodId == item.id).FirstOrDefault();//如果库存里有 缓存中的菜 就改上去
                        if (listHere == null)
                        {
                            listR.Add(new FoodsOnMapRes(item, apiHost, 0));
                        }
                        else
                        {
                            listR.Add(new FoodsOnMapRes(item, apiHost, listHere.amount));
                        }
                    }
                }
                else
                {
                    foreach (var item in listFoodView)
                    {
                        listR.Add(new FoodsOnMapRes(item, apiHost));
                    }
                }

                List_FoodsOnMapRes res = new List_FoodsOnMapRes();
                res.foods = listR;
                res.money = money.ToString();

                return(ControllerHelper.Instance.JsonResult(200, JsonConvert.SerializeObject(res), ""));
            }
            else
            {
                return(ControllerHelper.Instance.JsonEmptyArr(200, "该区域无菜品"));
            }
        }
        public HttpResponseMessage ToReservePayPage(ToReservePayPage req)
        {
            var   userId   = Convert.ToInt32(req.userId);
            var   tokenStr = req.Token;
            Token token    = CacheHelper.GetUserToken(tokenStr);

            if (token == null)
            {
                return(ControllerHelper.Instance.JsonResult(400, "token失效"));
            }
            if (token.Payload.UserID != userId)
            {
                return(ControllerHelper.Instance.JsonResult(400, "token错误"));
            }

            ReserveOrderRes res = new ReserveOrderRes();

            var foodId = Convert.ToInt32(req.foodId);
            var amount = Convert.ToInt32(req.amount);

            //获取最近使用过的地址
            var list_addr = UserAddressOper.Instance.GetRecentlyAddr(userId);

            if (list_addr.Count < 1)
            {
                res.userAddress = null;
            }
            else
            {
                res.userAddress = new UserAddressForOrderRes(list_addr.First());
            }

            var user    = UserInfoOper.Instance.GetById(userId);//获取用户信息
            var balance = (decimal)user.userBalance;
            var coupon  = (decimal)user.coupon;

            var           listFoods = new List <foodId_Amount>();
            foodId_Amount fa1       = new foodId_Amount(foodId, amount);

            listFoods.Add(fa1);

            var listWeekNotMainFoods = FoodInfoOper.Instance.GetReserveNotMainFood();

            if (listWeekNotMainFoods.Count > 0)
            {
                foreach (var item in listWeekNotMainFoods)
                {
                    foodId_Amount fa = new foodId_Amount(item.id, 0);
                    listFoods.Add(fa);
                }
            }
            var fd         = FoodInfoOper.Instance.GetFoodPriceAndDeposit(listFoods);
            var deposit    = fd.deposit;
            var foodsPrice = fd.price;

            //var sumMoney = foodsPrice + deposit;
            var priceRes = ControllerHelper.Instance.GetThreePriceWithDeposit(balance, coupon, foodsPrice, deposit);

            res.balance = balance.ToString();
            res.coupon  = coupon.ToString();
            PriceAll pa = new PriceAll();

            pa.payMoney  = priceRes.payMoney.ToString();
            pa.price     = (priceRes.payMoney + priceRes.useBalance).ToString();
            res.priceAll = pa;

            res.listFoods = FoodInfoOper.Instance.GetFoodINAPI(listFoods);

            res.deposit = deposit.ToString();

            res.isUseBalance = balance <= 0 ? false : true;
            res.isUseCoupon  = coupon <= 0 ? false : true;

            return(ControllerHelper.Instance.JsonResult(200, JsonConvert.SerializeObject(res), ""));
        }
        public HttpResponseMessage ToPayPage(ToPayPageReq req)
        {
            OrderRes res      = new OrderRes();
            var      userId   = Convert.ToInt32(req.userId);
            var      tokenStr = req.Token;

            Token token = CacheHelper.GetUserToken(tokenStr);

            if (token == null)
            {
                return(ControllerHelper.Instance.JsonResult(400, "token失效"));
            }
            if (token.Payload.UserID != userId)
            {
                return(ControllerHelper.Instance.JsonResult(400, "token错误"));
            }

            var areaId = Convert.ToInt32(req.areaId);
            List <RiderStockJoin> listRs = RiderStockOper.Instance.GetRSJoinByAreaId(areaId);

            var foodIdsInArea = listRs.Select(p => p.foodId).Distinct().ToArray();//区域内存在的菜品的id
            var list_foods    = new List <foodId_Amount>();
            var listafa       = CacheHelper.GetTempFoods2(userId);

            listafa = listafa.Where(p => p.areaId == areaId).ToList();//-txy
            foreach (var item in listafa)
            {
                foodId_Amount fa = new foodId_Amount();
                fa.amount = item.amount;
                fa.foodId = item.foodId;
                list_foods.Add(fa);
            }

            #region 根据库存调整菜品数量
            //点过的菜,不属于区域内的去掉
            list_foods = list_foods.Where(p => foodIdsInArea.Contains(p.foodId)).ToList();

            var listTempFoods = new List <foodId_Amount>();
            foreach (var item in list_foods)
            {
                var rsAmount = listRs.Where(p => p.foodId == item.foodId).ToList().Sum(p => p.amount);
                item.amount = item.amount > rsAmount ? (int)rsAmount : item.amount;
                listTempFoods.Add(item);
            }
            #endregion

            var list_addr = UserAddressOper.Instance.GetRecentlyAddr(userId);
            if (list_addr.Count < 1)
            {
                res.userAddress = null;
            }
            else
            {
                res.userAddress = new UserAddressForOrderRes(list_addr.First());
            }

            var user    = UserInfoOper.Instance.GetById(userId);//获取用户信息
            var balance = (decimal)user.userBalance;
            var coupon  = (decimal)user.coupon;

            var ids = listTempFoods.Select(p => p.foodId).ToArray();

            var tempList = CacheHelper.GetByIds <FoodView>("foodView", ids);

            var f_d        = FoodInfoOper.Instance.GetFoodPriceAndDeposit(listTempFoods);
            var deposit    = f_d.deposit;
            var foodsPrice = f_d.price;
            var priceRes   = ControllerHelper.Instance.GetThreePriceWithDeposit(balance, coupon, foodsPrice, deposit);

            res.balance = balance.ToString();
            res.coupon  = coupon.ToString();
            PriceAll pa = new PriceAll();
            pa.payMoney  = priceRes.payMoney.ToString();
            pa.price     = (priceRes.payMoney + priceRes.useBalance).ToString();
            res.priceAll = pa;

            List <foodId_name_amount_price_isMain> foodListRes = new List <foodId_name_amount_price_isMain>();
            foreach (var item in tempList)
            {
                foodId_name_amount_price_isMain a = new foodId_name_amount_price_isMain(item);
                foodListRes.Add(a);
            }

            foreach (var item in listTempFoods)
            {
                foodListRes.Where(p => p.foodId == item.foodId).FirstOrDefault().amount = item.amount;
            }

            var list = RiderStockOper.Instance.GetStockNotMain(areaId);

            var extraFoodIdList = list.OrderByDescending(p => p.id).GroupBy(p => new { p.foodId, p.foodName, p.foodPrice }).Select(g => new foodId_name_amount_price_isMain
            {
                foodId    = (int)g.Key.foodId,
                foodName  = g.Key.foodName,
                foodPrice = g.Key.foodPrice.ToString(),
                amount    = 0,
                isMain    = false
            }).ToList();
            foreach (var item in extraFoodIdList)
            {
                foodListRes.Add(item);
            }

            res.listFoods = foodListRes.OrderByDescending(p => p.foodId).ToList();

            res.isUseBalance = balance <= 0 ? false : true;
            res.isUseCoupon  = coupon <= 0 ? false : true;
            res.deposit      = deposit.ToString();
            return(ControllerHelper.Instance.JsonResult(200, JsonConvert.SerializeObject(res), ""));
        }