Ejemplo n.º 1
0
        public object GetCancelDadaExpress(long orderId, int reasonId, string cancelReason)
        {
            CheckUserLogin();
            long shopid = CurrentShop.Id;
            var  order  = OrderApplication.GetOrder(orderId);

            if (order == null || order.ShopId != shopid || order.ShopBranchId > 0 || order.OrderStatus != Entities.OrderInfo.OrderOperateStatus.WaitReceiving || order.DeliveryType != DeliveryType.CityExpress)
            {
                throw new HimallApiException("错误的订单编号");
            }
            if (order.DadaStatus > DadaStatus.WaitTake.GetHashCode())
            {
                throw new HimallApiException("订单配送不可取消!");
            }
            var    dadaconfig = CityExpressConfigApplication.GetDaDaCityExpressConfig(shopid);
            string json       = ExpressDaDaHelper.orderFormalCancel(shopid, orderId.ToString(), reasonId, cancelReason);
            var    resultObj  = JsonConvert.DeserializeObject(json) as JObject;
            string status     = resultObj["status"].ToString();

            if (status != "success")
            {
                throw new HimallApiException(resultObj["msg"].ToString());
            }
            ExpressDaDaApplication.SetOrderCancel(orderId, "商家主动取消");
            var result = JsonConvert.DeserializeObject(resultObj["result"].ToString()) as JObject;

            return(new
            {
                success = true,
                deduct_fee = result["deduct_fee"].ToString()
            });
        }
Ejemplo n.º 2
0
        public JsonResult DaDaConfig(ShopBranchDaDaConfigModel model)
        {
            long   shopId = CurrentShop.Id;
            Result result = new Result
            {
                success = false,
                msg     = "未知错误"
            };

            if (ModelState.IsValid)
            {
                if (model.IsEnable)
                {
                    if (string.IsNullOrWhiteSpace(model.app_key) || string.IsNullOrWhiteSpace(model.app_secret) || string.IsNullOrWhiteSpace(model.source_id))
                    {
                        result.success = false;
                        result.msg     = "数据错误,请填写必填信息";
                        return(Json(result));
                    }
                }
                var data = CityExpressConfigApplication.GetDaDaCityExpressConfig(shopId);
                data.IsEnable   = model.IsEnable;
                data.app_key    = model.app_key;
                data.app_secret = model.app_secret;
                data.source_id  = model.source_id;
                CityExpressConfigApplication.Update(CurrentShop.Id, data);
                result.msg = "";
                //同步开通达达门店
                var sblist = ShopBranchApplication.GetShopBranchByShopId(shopId).Where(d => string.IsNullOrWhiteSpace(d.DaDaShopId));
                foreach (var item in sblist)
                {
                    var    dada_shop_id = GetNewDadaStoreId(CurrentShop.Id, item.Id);
                    var    _area        = RegionApplication.GetRegion(item.AddressId);
                    var    _city        = GetCity(_area);
                    var    json         = ExpressDaDaHelper.shopAdd(shopId, item.ShopBranchName, 5, _city.ShortName, _area.Parent.Name, item.AddressDetail, item.Longitude, item.Latitude, item.ContactUser, item.ContactPhone, dada_shop_id);
                    var    resultObj    = JsonConvert.DeserializeObject(json) as JObject;
                    string status       = resultObj["status"].ToString();
                    int    code         = int.Parse(resultObj["code"].ToString());
                    if (status == "fail" && code != 7718)
                    {
                        result.msg = "但部份同步门店失败,可能所在城市达达不支持";
                    }
                    if (string.IsNullOrWhiteSpace(item.DaDaShopId) && (status == "success" || code == 7718))
                    {
                        item.DaDaShopId = dada_shop_id;
                        ShopBranchApplication.UpdateShopBranch(item);
                    }
                }
                result.success = true;
            }
            else
            {
                result.success = false;
                result.msg     = "数据错误,请填写必填信息";
            }

            return(Json(result));
        }
        /// <summary>
        /// 获取订单信息
        /// </summary>
        /// <param name="orderId"></param>
        /// <returns></returns>
        public object GetOrderInfo(long orderId)
        {
            AutoMapper.Mapper.CreateMap <DTO.Order, ShopBranchOrderGetOrderModel>();
            var data = Application.OrderApplication.GetOrder(orderId);
            ShopBranchOrderGetOrderModel result = AutoMapper.Mapper.Map <DTO.Order, ShopBranchOrderGetOrderModel>(data);

            result.CanDaDaExpress = CityExpressConfigApplication.GetStatus(data.ShopId);
            return(result);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 达达物流配置
        /// </summary>
        /// <returns></returns>
        public ActionResult DaDaConfig()
        {
            var data   = CityExpressConfigApplication.GetDaDaCityExpressConfig(CurrentShop.Id);
            var result = new ShopBranchDaDaConfigModel
            {
                IsEnable   = data.IsEnable,
                app_key    = data.app_key,
                app_secret = data.app_secret,
                source_id  = data.source_id
            };

            return(View(result));
        }
        /// <summary>
        /// 门店发货
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public object PostShopSendGood(OrderDeliveryModel model)
        {
            CheckUserLogin();
            string shopkeeperName = "";
            long   shopid         = CurrentShopBranch.ShopId;
            long   sbid           = CurrentUser.ShopBranchId;

            shopkeeperName = CurrentShopBranch.UserName;
            var returnurl = String.Format("{0}/Common/ExpressData/SaveExpressData", CurrentUrlHelper.CurrentUrlNoPort());

            if (model.deliveryType == DeliveryType.CityExpress.GetHashCode())  //同城物流
            {
                var dadaconfig = CityExpressConfigApplication.GetDaDaCityExpressConfig(shopid);
                if (!dadaconfig.IsEnable)
                {
                    throw new HimallApiException("未开启同城合作物流");
                }
                var order = OrderApplication.GetOrder(model.orderId);
                if (order == null || order.ShopId != shopid || !(order.ShopBranchId > 0) || order.OrderStatus != Entities.OrderInfo.OrderOperateStatus.WaitDelivery)
                {
                    throw new HimallApiException("错误的订单编号");
                }
                //Log.Error("达达发货ShopBranchOrder-开始01:orderId:" + model.orderId);

                var sbdata = ShopBranchApplication.GetShopBranchById(sbid);

                string json      = ExpressDaDaHelper.addAfterQuery(shopid, sbdata.DaDaShopId, model.shipOrderNumber);
                var    resultObj = JsonConvert.DeserializeObject(json) as JObject;
                string status    = resultObj["status"].ToString();

                //Log.Error("达达发货ShopBranchOrder-开始02:status:" + status);
                if (status != "success")
                {
                    //订单码过期,重发单
                    json = SendDaDaExpress(model.orderId, shopid, sbid, false);
                    var    rObj2   = JsonConvert.DeserializeObject(json) as JObject;
                    string status2 = rObj2["status"].ToString();
                    if (status2 != "success")
                    {
                        string msg = rObj2["msg"].ToString();
                        return(ErrorResult(msg));
                    }
                }
            }
            OrderApplication.ShopSendGood(model.orderId, model.deliveryType, shopkeeperName, model.companyName, model.shipOrderNumber, returnurl);
            return(SuccessResult("发货成功"));
        }
        private string SendDaDaExpress(long orderId, long shopid, long sbid, bool isQueryOrder)
        {
            //Log.Error("达达发货ShopBranchOrder-01:orderId:" + orderId);
            var order = OrderApplication.GetOrder(orderId);

            if (order == null || order.ShopBranchId != sbid || order.OrderStatus != Entities.OrderInfo.OrderOperateStatus.WaitDelivery)
            {
                throw new HimallApiException("错误的订单编号");
            }
            var dadaconfig = CityExpressConfigApplication.GetDaDaCityExpressConfig(shopid);

            if (!dadaconfig.IsEnable)
            {
                throw new HimallApiException("未开启同城合作物流");
            }
            //Log.Error("达达发货ShopBranchOrder-02:OrderStatus:" + order.OrderStatus + "--RegionId:" + order.RegionId);
            if (order.ReceiveLatitude <= 0 || order.ReceiveLongitude <= 0)
            {
                throw new HimallApiException("未获取到客户收货地址坐标信息,无法使用该配送方式");
            }
            var sbdata = ShopBranchApplication.GetShopBranchById(sbid);

            if (sbdata == null || string.IsNullOrWhiteSpace(sbdata.DaDaShopId))
            {
                throw new HimallApiException("门店未在达达注册,或所在城市达达不支持配送,无法发单,请商家在后台进行设置");
            }
            //Log.Error("达达发货ShopBranchOrder-03:Latitude:" + sbdata.DaDaShopId);
            string cityCode  = "";
            var    _adregion = RegionApplication.GetRegion(order.RegionId);
            var    _city     = GetCity(_adregion);

            try
            {
                string cityJson = ExpressDaDaHelper.cityCodeList(shopid);
                var    cityObj  = JsonConvert.DeserializeObject(cityJson) as JObject;
                JArray citylist = (JArray)cityObj["result"];
                foreach (JToken item in citylist)
                {
                    if (_city.ShortName == item["cityName"].ToString())
                    {
                        cityCode = item["cityCode"].ToString();
                        break;
                    }
                }
            }
            catch
            {
            }
            //达达不支持的城市
            if (cityCode == "")
            {
                throw new HimallApiException("配送范围超区,无法配送");
            }
            string callback     = CurrentUrlHelper.CurrentUrl() + "/pay/dadaOrderNotify/";
            bool   isreaddorder = (order.DadaStatus == DadaStatus.Cancel.GetHashCode());

            if (isQueryOrder)
            {
                isreaddorder = false;
            }

            //Log.Error(DateTime.Now + "ShopBranchOrder-0:callback:" + callback + "|shopid:" + shopid + "|DaDaShopId:" + sbdata.DaDaShopId + "|orderId:" + order.Id + "|cityCode:" + cityCode + "|isreaddorder:" + isreaddorder);
            string json = ExpressDaDaHelper.addOrder(shopid, sbdata.DaDaShopId, order.Id.ToString()
                                                     , cityCode, (double)order.TotalAmount, 0, ExpressDaDaHelper.DateTimeToUnixTimestamp(DateTime.Now.AddMinutes(15))
                                                     , order.ShipTo, order.Address, order.ReceiveLatitude, order.ReceiveLongitude
                                                     , callback, order.CellPhone, order.CellPhone, isQueryDeliverFee: isQueryOrder
                                                     , isReAddOrder: isreaddorder);

            //Log.Error(DateTime.Now + "达达发货ShopBranchOrder-1:json:" + json);
            return(json);
        }
Ejemplo n.º 7
0
        public ActionResult Add(ShopBranch shopBranch)
        {
            try
            {
                if (!string.Equals(shopBranch.PasswordOne, shopBranch.PasswordTwo))
                {
                    throw new MallException("两次密码输入不一致!");
                }
                if (string.IsNullOrWhiteSpace(shopBranch.PasswordOne) || string.IsNullOrWhiteSpace(shopBranch.PasswordTwo))
                {
                    throw new MallException("密码不能为空!");
                }
                if (shopBranch.ShopBranchName.Length > 15)
                {
                    throw new MallException("门店名称不能超过15个字!");
                }
                if (shopBranch.AddressDetail.Length > 50)
                {
                    throw new MallException("详细地址不能超过50个字!");
                }
                if (shopBranch.Latitude <= 0 || shopBranch.Longitude <= 0)
                {
                    throw new MallException("请搜索地址地图定位!");
                }
                if (!shopBranch.IsAboveSelf && !shopBranch.IsStoreDelive)
                {
                    throw new MallException("至少需要选择一种配送方式!");
                }
                if (shopBranch.IsStoreDelive && shopBranch.IsFreeMail && shopBranch.FreeMailFee <= 0)
                {
                    throw new MallException("满额包邮金额必须大于0!");
                }
                if (!shopBranch.IsStoreDelive)
                {
                    shopBranch.IsFreeMail = false;
                }
                if (!shopBranch.IsFreeMail)
                {
                    shopBranch.FreeMailFee = 0;
                }
                shopBranch.ShopId     = CurrentSellerManager.ShopId;
                shopBranch.CreateDate = DateTime.Now;
                long shopBranchId;
                ShopBranchApplication.AddShopBranch(shopBranch, out shopBranchId);

                if (!string.IsNullOrWhiteSpace(shopBranch.ShopBranchTagId))
                {
                    var tags = shopBranch.ShopBranchTagId.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(p => long.Parse(p)).ToList();
                    ShopBranchApplication.SetShopBrandTagInfos(new List <long> {
                        shopBranch.Id
                    }, tags);
                }

                //门店标签
                var shopBranchTagInfos        = ShopBranchApplication.GetAllShopBranchTagInfos();
                List <SelectListItem> tagList = new List <SelectListItem>();
                foreach (var item in shopBranchTagInfos)
                {
                    tagList.Add(new SelectListItem
                    {
                        Selected = (shopBranch.ShopBranchTagId == null ? false : shopBranch.ShopBranchTagId.Split(',').Contains(item.Id.ToString()) ? true : false),
                        Value    = item.Id.ToString(),
                        Text     = item.Title
                    });
                }
                ViewBag.ShopBranchTags = tagList;

                if (CityExpressConfigApplication.GetDaDaCityExpressConfig(CurrentShop.Id).IsEnable)
                {
                    var    dada_shop_id = GetNewDadaStoreId(CurrentShop.Id, shopBranch.Id);
                    var    _area        = RegionApplication.GetRegion(shopBranch.AddressId);
                    var    _city        = GetCity(_area);
                    var    json         = ExpressDaDaHelper.shopAdd(CurrentShop.Id, shopBranch.ShopBranchName, 5, _city.ShortName, _area.Parent.Name, shopBranch.AddressDetail, shopBranch.Longitude, shopBranch.Latitude, shopBranch.ContactUser, shopBranch.ContactPhone, dada_shop_id);
                    var    resultObj    = JsonConvert.DeserializeObject(json) as JObject;
                    string status       = resultObj["status"].ToString();
                    int    code         = int.Parse(resultObj["code"].ToString());
                    if (status == "fail" && code != 7718)
                    {
                        return(Json(new Result()
                        {
                            success = true, msg = "但同步门店至达达物流失败,可能所在城市达达不支持"
                        }));
                    }
                    if (string.IsNullOrWhiteSpace(shopBranch.DaDaShopId) && (status == "success" || code == 7718))
                    {
                        shopBranch.DaDaShopId = dada_shop_id;
                        ShopBranchApplication.UpdateShopBranch(shopBranch);
                    }
                }
            }
            catch (Exception ex)
            {
                return(Json(new Result()
                {
                    success = false, msg = ex.Message
                }));
            }
            return(Json(new Result()
            {
                success = true
            }));
        }
Ejemplo n.º 8
0
        public ActionResult Edit(ShopBranch shopBranch)
        {
            try
            {
                if (!string.Equals(shopBranch.PasswordOne, shopBranch.PasswordTwo))
                {
                    throw new MallException("两次密码输入不一致!");
                }
                if (shopBranch.ShopBranchName.Length > 15)
                {
                    throw new MallException("门店名称不能超过15个字!");
                }
                if (shopBranch.AddressDetail.Length > 50)
                {
                    throw new MallException("详细地址不能超过50个字!");
                }
                if (shopBranch.Latitude <= 0 || shopBranch.Longitude <= 0)
                {
                    throw new MallException("请搜索地址地图定位!");
                }
                if (!shopBranch.IsAboveSelf && !shopBranch.IsStoreDelive)
                {
                    throw new MallException("至少需要选择一种配送方式!");
                }
                if (shopBranch.IsStoreDelive && shopBranch.IsFreeMail && shopBranch.FreeMailFee <= 0)
                {
                    throw new MallException("满额包邮金额必须大于0!");
                }
                if (!shopBranch.IsStoreDelive)
                {
                    shopBranch.IsFreeMail = false;
                }
                if (!shopBranch.IsFreeMail)
                {
                    shopBranch.FreeMailFee = 0;
                }
                //判断是否编辑自己的门店
                shopBranch.ShopId = CurrentSellerManager.ShopId;//当前登录商家
                //门店所属商家
                var oldBranch = ShopBranchApplication.GetShopBranchById(shopBranch.Id);
                if (oldBranch != null && oldBranch.ShopId != shopBranch.ShopId)
                {
                    throw new MallException("不能修改其他商家的门店!");
                }

                if (!shopBranch.IsFreeMail)
                {
                    shopBranch.FreeMailFee = 0;
                }

                if (!string.IsNullOrWhiteSpace(shopBranch.ShopBranchTagId))
                {
                    var tags = shopBranch.ShopBranchTagId.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(p => long.Parse(p)).ToList();
                    ShopBranchApplication.SetShopBrandTagInfos(new List <long> {
                        shopBranch.Id
                    }, tags);
                }

                ShopBranchApplication.UpdateShopBranch(shopBranch);

                if (CityExpressConfigApplication.GetDaDaCityExpressConfig(CurrentShop.Id).IsEnable)
                {
                    var    _area        = RegionApplication.GetRegion(shopBranch.AddressId);
                    var    _city        = GetCity(_area);
                    string json         = "";
                    var    dada_shop_id = GetNewDadaStoreId(CurrentShop.Id, shopBranch.Id);
                    if (string.IsNullOrWhiteSpace(shopBranch.DaDaShopId))
                    {
                        json = ExpressDaDaHelper.shopAdd(CurrentShop.Id, shopBranch.ShopBranchName, 5, _city.ShortName, _area.Parent.Name, shopBranch.AddressDetail, shopBranch.Longitude, shopBranch.Latitude, shopBranch.ContactUser, shopBranch.ContactPhone, dada_shop_id);
                    }
                    else
                    {
                        json = ExpressDaDaHelper.shopUpdate(CurrentShop.Id, shopBranch.DaDaShopId, shopBranch.ShopBranchName, 5, _city.ShortName, _area.Parent.Name, shopBranch.AddressDetail, shopBranch.Longitude, shopBranch.Latitude, shopBranch.ContactUser, shopBranch.ContactPhone);
                    }
                    var    resultObj = JsonConvert.DeserializeObject(json) as JObject;
                    string status    = resultObj["status"].ToString();
                    int    code      = int.Parse(resultObj["code"].ToString());
                    if (status == "fail" && code != 7718)
                    {
                        return(Json(new Result()
                        {
                            success = true, msg = "但同步门店至达达物流失败,可能所在城市达达不支持"
                        }));
                    }
                    if (string.IsNullOrWhiteSpace(shopBranch.DaDaShopId) && (status == "success" || code == 7718))
                    {
                        shopBranch.DaDaShopId = dada_shop_id;
                        ShopBranchApplication.UpdateShopBranch(shopBranch);
                    }
                }
            }
            catch (Exception ex)
            {
                return(Json(new Result()
                {
                    success = false, msg = ex.Message
                }));
            }
            return(Json(new Result()
            {
                success = true
            }));
        }