/// <summary> /// 新增美团订单 add by caoheyang 20150421 /// </summary> /// <param name="paramodel">paraModel</param> public void AddOrder(CreatePM_OpenApi paramodel) { string orderNo = Helper.generateOrderCode(paramodel.businessId); RedisCache redis = new RedisCache(); try { using (IUnitOfWork tran = EdsUtilOfWorkFactory.GetUnitOfWorkOfEDS()) { OrderDao orderDao = new OrderDao(); paramodel.OrderNo = orderNo; //将当前订单插入到缓存中,设置过期时间30天 redis.Set(string.Format(RedissCacheKey.OtherOrderInfo, paramodel.orderfrom.ToString(), paramodel.order_id.ToString()), orderNo, DateTime.Now.AddDays(30)); //先加入缓存,相当于加锁 int orderId = orderDao.CreateToSql(paramodel); //插入订单返回订单id orderDao.CreateToSqlAddOrderOther(paramodel.businessId, orderId); //操作插入OrderOther表 orderDao.CreateToSqlAddOrderDetail(paramodel, orderNo); //操作插入OrderDetail表 orderDao.CreateToSqlAddOrderChild(paramodel, orderId); //插入订单子表 tran.Complete(); } } catch (Exception ex) { redis.Delete(string.Format(RedissCacheKey.OtherOrderInfo, //同步失败,清除缓存内的订单信息信息 paramodel.store_info.group.ToString(), paramodel.order_id.ToString())); throw ex; } }
public ResultModelToString PullOrderInfo() { try { //实体类赋值 MeiTuanOrdeModel paramodel = HTTPHelper.BindeModel <MeiTuanOrdeModel>(HttpContext.Current.Request); MeiTuanGroup meituan = new MeiTuanGroup(); if (meituan.PostGetSig(HttpContext.Current.Request) == paramodel.sig) { CreatePM_OpenApi model = meituan.TranslateModel(paramodel); if (model == null) //商户在E代送不存在等情况下导致实体translate失败 { return(new ResultModelToString(data: "fail")); } meituan.AddOrder(model); return(new ResultModelToString(data: "ok")); } return(new ResultModelToString(data: "fail")); //推送失败 } catch (Exception ex) { LogHelper.LogWriterFromFilter(ex); //记录日志 return(new ResultModelToString(data: "fail")); //推送失败 } }
/// <summary> /// 新增商铺时根据集团id为店铺设置外送费,结算比例等财务相关信息 caoheyang 20150527 /// </summary> /// <param name="paramodel"></param> /// <returns></returns> public CreatePM_OpenApi SetCommissonInfo(CreatePM_OpenApi paramodel) { paramodel.store_info.delivery_fee = 0; paramodel.store_info.businesscommission = 10; paramodel.websitesubsidy = 6; //网站补贴 return(paramodel); }
/// <summary> /// 新增商铺时根据集团id为店铺设置外送费,结算比例等财务相关信息 add by caoheyang 20150417 /// </summary> /// <param name="paramodel"></param> /// <returns></returns> public CreatePM_OpenApi SetCommissonInfo(CreatePM_OpenApi paramodel) { paramodel.store_info.delivery_fee = 0; //万达目前外送费统一0 paramodel.store_info.businesscommission = 12; //万达目前结算比例统一12 return(paramodel); }
/// <summary> /// 美团的订单数据转成通用的openapi接入订单数据实体类型 20150421 /// </summary> /// <param name="fromModel">美团数据实体</param> public CreatePM_OpenApi TranslateModel(MeiTuanOrdeModel fromModel) { #region 订单基础数据 CreatePM_OpenApi model = new CreatePM_OpenApi(); model.order_id = fromModel.order_id; //订单ID //店铺信息 店铺是已经在E代送存在的,这里没有任何实际意义,数据用不到 Store store = new Store(); store.store_id = fromModel.app_poi_code; //对接方店铺id store.store_name = fromModel.wm_poi_name; //店铺名称 store.address = fromModel.wm_poi_address; //店铺地址 store.phone = fromModel.wm_poi_phone; //店铺电话 store.group = GroupType.Group4.GetHashCode(); //店铺电话 model.remark = fromModel.caution; //备注 model.status = OrderStatus.Status30.GetHashCode(); //初始化订单状态 第三方代接入 model.create_time = DateTime.Now; //订单发单时间 创建时间 model.payment = fromModel.pay_type; //支付类型 model.is_pay = fromModel.pay_type != 1; //目前货到付款时取未支付,在线支付取已支付 model.total_price = fromModel.total; //订单金额 model.store_info = store; //店铺 model.invoice_title = fromModel.invoice_title; //发票标题 //订单明细不为空时做处理 if (!string.IsNullOrWhiteSpace(fromModel.detail) && fromModel.detail != "") { MeiTuanOrdeDetailModel[] meituandetails = JsonHelper.JsonConvertToObject <MeiTuanOrdeDetailModel[]>(fromModel.detail); OrderDetail[] details = new OrderDetail[meituandetails.Length]; for (int i = 0; i < meituandetails.Length; i++) { OrderDetail tempdetail = new OrderDetail(); tempdetail.product_name = meituandetails[i].food_name; //菜品名称 tempdetail.quantity = meituandetails[i].quantity; //菜品数量 tempdetail.unit_price = meituandetails[i].price; //菜品单价 tempdetail.detail_id = 0; //美团不传递明细id,明细id为0 details[i] = tempdetail; } model.order_details = details; //订单ID } model.orderfrom = GroupType.Group4.GetHashCode(); // 订单来源 美团订单的订单来源是 4 model.receive_time = TimeHelper.TimeStampToDateTime(fromModel.ctime); //美团不传递,E代送必填 要求送餐时间 #endregion #region 订单商户相关信息 var redis = new ETS.NoSql.RedisCache.RedisCache(); int businessId = ParseHelper.ToInt(redis.Get <string>(string.Format(ETS.Const.RedissCacheKey.OtherBusinessIdInfo, model.orderfrom, model.store_info.store_id.ToString()))); //缓存中取E代送商户id if (businessId == 0) { return(null); } else { model.businessId = businessId; } BusListResultModel business = new BusinessDao().GetBusiness(businessId); if (business.Status != BusinessStatus.Status1.GetHashCode())//商户非审核通过不允许接单 { return(null); } model.store_info.delivery_fee = ParseHelper.ToDecimal(business.DistribSubsidy); //外送费 model.store_info.businesscommission = ParseHelper.ToDecimal(business.BusinessCommission); //结算比例 model.CommissionType = business.CommissionType; model.CommissionFixValue = business.CommissionFixValue; model.BusinessGroupId = business.BusinessGroupId; model.MealsSettleMode = business.MealsSettleMode; #endregion #region 订单地址信息 Address address = new Address(); address.address = fromModel.recipient_address; //用户收货地址 address.user_phone = fromModel.recipient_phone; //用户联系电话 address.user_name = fromModel.recipient_name; //用户姓名 address.longitude = fromModel.longitude; //经度 address.latitude = fromModel.latitude; //纬度 address.city_code = business.CityId; //市 address.city = business.City; address.area_code = business.districtId; //区 address.area = business.district; address.province = business.Province; //省 address.province_code = business.ProvinceCode; model.address = address; //订单ID #endregion #region 佣金相关 model.package_count = 1; //订单份数 //佣金计算规则 //model.CommissionFormulaMode = ParseHelper.ToInt(Ets.Dao.GlobalConfig.GlobalConfigDao.GlobalConfigGet(1).CommissionFormulaMode); model.CommissionFormulaMode = business.StrategyId; //计算获得订单骑士佣金 OrderCommission orderComm = new OrderCommission() { Amount = model.total_price, /*订单金额*/ DistribSubsidy = model.store_info.delivery_fee, /*外送费*/ OrderCount = model.package_count, /*订单数量*/ BusinessCommission = model.store_info.businesscommission, /*商户结算比例*/ BusinessGroupId = model.BusinessGroupId, StrategyId = model.CommissionFormulaMode } /*网站补贴*/; //OrderPriceProvider commissonPro = CommissionFactory.GetCommission(); OrderPriceProvider commissonPro = CommissionFactory.GetCommission(business.StrategyId); model.ordercommission = commissonPro.GetCurrenOrderCommission(orderComm); //骑士佣金 model.websitesubsidy = commissonPro.GetOrderWebSubsidy(orderComm); //网站补贴 model.commissionrate = commissonPro.GetCommissionRate(orderComm); //订单佣金比例 model.settlemoney = commissonPro.GetSettleMoney(orderComm); //订单结算金额 model.adjustment = commissonPro.GetAdjustment(orderComm); //订单额外补贴金额 #endregion if (!(bool)model.is_pay && model.MealsSettleMode == MealsSettleMode.LineOn.GetHashCode()) //未付款且线上支付 { //paramodel.BusinessReceivable = Decimal.Round(ParseHelper.ToDecimal(paramodel.total_price) + // ParseHelper.ToDecimal(paramodel.store_info.delivery_fee) * ParseHelper.ToInt(paramodel.package_count), 2); //只有一个子订单 model.BusinessReceivable = Decimal.Round(ParseHelper.ToDecimal(model.total_price) + ParseHelper.ToDecimal(model.store_info.delivery_fee), 2); } //fromModel.extras 说明,暂时不用 return(model); }
/// <summary> /// 新增商铺时根据集团id为店铺设置外送费,结算比例等财务相关信息 add by caoheyang 20150420 /// </summary> /// <param name="paramodel"></param> /// <returns></returns> public CreatePM_OpenApi SetCommissonInfo(CreatePM_OpenApi paramodel) { return(paramodel); }