/// <summary> /// 处理餐饮快跑者配送回调 /// </summary> /// <param name="orderid"></param> /// <param name="state"></param> /// <returns></returns> public bool KPZToFoodReturn(KPZOrder order) { bool isSuccess = false; string updatesql = "status"; FoodGoodsOrder foodGoodOrder = FoodGoodsOrderBLL.SingleModel.GetModel(order.OrderId);// and OrderType ={(int)miniAppFoodOrderType.店内点餐 } "); if (foodGoodOrder == null) { LogHelper.WriteInfo(this.GetType(), "快跑者配送:找不到餐饮订单"); return(isSuccess); } string msg = string.Empty; switch (order.status) { case (int)KPZOrderEnum.已撤销: isSuccess = base.Update(order, updatesql); if (!isSuccess) { LogHelper.WriteInfo(this.GetType(), "快跑者配送:修改系统订单状态出错," + JsonConvert.SerializeObject(order)); return(isSuccess); } //退款接口 abel //判断是否是取消订单,取消订单则要执行退款 if (foodGoodOrder.BuyMode == (int)miniAppBuyMode.微信支付) { isSuccess = FoodGoodsOrderBLL.SingleModel.outOrder(foodGoodOrder, foodGoodOrder.State); } else if (foodGoodOrder.BuyMode == (int)miniAppBuyMode.储值支付) { SaveMoneySetUser userSaveMoney = SaveMoneySetUserBLL.SingleModel.getModelByUserId(foodGoodOrder.UserId) ?? new SaveMoneySetUser(); isSuccess = FoodGoodsOrderBLL.SingleModel.outOrderBySaveMoneyUser(foodGoodOrder, userSaveMoney, foodGoodOrder.State); } #region 餐饮退款成功通知 模板消息 if (isSuccess) { object postData2 = FoodGoodsOrderBLL.SingleModel.getTemplateMessageData(foodGoodOrder.Id, SendTemplateMessageTypeEnum.餐饮退款成功通知); TemplateMsg_Miniapp.SendTemplateMessage(foodGoodOrder.UserId, SendTemplateMessageTypeEnum.餐饮退款成功通知, (int)TmpType.小程序餐饮模板, postData2); } #endregion return(isSuccess); case (int)KPZOrderEnum.待发单: case (int)KPZOrderEnum.待抢单: case (int)KPZOrderEnum.待接单: foodGoodOrder.State = (int)miniAppFoodOrderState.待接单; break; case (int)KPZOrderEnum.取单中: updatesql += ",courier,tel"; foodGoodOrder.State = (int)miniAppFoodOrderState.待送餐; #region 发送餐饮订单配送通知 模板消息 C_UserInfo userinfo = C_UserInfoBLL.SingleModel.GetModel(foodGoodOrder.UserId) ?? new C_UserInfo(); object postData = FoodGoodsOrderBLL.SingleModel.getTemplateMessageData(foodGoodOrder.Id, SendTemplateMessageTypeEnum.餐饮订单配送通知); TemplateMsg_Miniapp.SendTemplateMessage(userinfo.Id, SendTemplateMessageTypeEnum.餐饮订单配送通知, (int)TmpType.小程序餐饮模板, postData); #endregion break; case (int)KPZOrderEnum.送单中: foodGoodOrder.State = (int)miniAppFoodOrderState.待确认送达; break; case (int)KPZOrderEnum.已送达: foodGoodOrder.State = (int)miniAppFoodOrderState.已完成; break; } isSuccess = base.Update(order, updatesql); if (!isSuccess) { LogHelper.WriteInfo(this.GetType(), "快跑者配送:修改系统订单状态出错," + JsonConvert.SerializeObject(order)); return(isSuccess); } isSuccess = FoodGoodsOrderBLL.SingleModel.Update(foodGoodOrder, "State"); return(isSuccess); }
/// <summary> /// 砍价退款(照搬后台的) /// </summary> /// <param name="bargainUser"></param> /// <param name="bargain"></param> /// <param name="appId"></param> /// <param name="msg"></param> /// <returns></returns> public bool OutOrder(BargainUser bargainUser, Bargain bargain, string appId, out string msg) { bargainUser.State = 2; bargainUser.outOrderDate = DateTime.Now; if (bargainUser.PayType == (int)miniAppBuyMode.储值支付) { bargainUser.refundFee = bargainUser.CurrentPrice + bargain.GoodsFreight; bargainUser.State = 3; var saveMoneyUser = SaveMoneySetUserBLL.SingleModel.getModelByUserId(appId, bargainUser.UserId); TransactionModel tran = new TransactionModel(); tran.Add(SaveMoneySetUserLogBLL.SingleModel.BuildAddSql(new SaveMoneySetUserLog() { AppId = appId, UserId = bargainUser.UserId, MoneySetUserId = saveMoneyUser.Id, Type = 1, BeforeMoney = saveMoneyUser.AccountMoney, AfterMoney = saveMoneyUser.AccountMoney + bargainUser.refundFee, ChangeMoney = bargainUser.refundFee, ChangeNote = $"小程序砍价购买商品[{bargainUser.BName}]退款,订单号:{bargainUser.OrderId} ", CreateDate = DateTime.Now, State = 1 })); tran.Add($" update SaveMoneySetUser set AccountMoney = AccountMoney + {bargainUser.refundFee} where id = {saveMoneyUser.Id} ; "); string updateBargainUser = BuildUpdateSql(bargainUser, "State,outOrderDate,refundFee"); tran.Add(updateBargainUser); bool isok = BargainBLL.SingleModel.ExecuteTransactionDataCorect(tran.sqlArray); if (isok) { object orderData = TemplateMsg_Miniapp.BargainGetTemplateMessageData(bargainUser, SendTemplateMessageTypeEnum.价订单退款通知, "商家操作退款"); TemplateMsg_Miniapp.SendTemplateMessage(bargainUser, SendTemplateMessageTypeEnum.价订单退款通知, orderData); msg = "退款成功,请查看账户余额!"; } else { msg = "退款异常!";//返回订单信息 } return(isok); } else { bool isok = false; CityMorders order = new CityMordersBLL().GetModel(bargainUser.CityMordersId); if (order == null) { msg = "订单信息有误!"; return(isok); } bargainUser.refundFee = bargainUser.CurrentPrice + bargain.GoodsFreight; if (new BargainUserBLL().Update(bargainUser, "State,outOrderDate,refundFee")) { ReFundQueue reModel = new ReFundQueue { minisnsId = -5, money = bargainUser.refundFee, orderid = order.Id, traid = order.trade_no, addtime = DateTime.Now, note = "小程序砍价订单退款", retype = 1 }; try { int funid = Convert.ToInt32(new ReFundQueueBLL().Add(reModel)); if (funid > 0) { object orderData = TemplateMsg_Miniapp.BargainGetTemplateMessageData(bargainUser, SendTemplateMessageTypeEnum.价订单退款通知, "商家操作退款"); TemplateMsg_Miniapp.SendTemplateMessage(bargainUser, SendTemplateMessageTypeEnum.价订单退款通知, orderData); isok = true; msg = "操作成功,已提交退款申请!"; return(isok); // return Json(new { isok = true, msg = "", obj = funid }); } else { isok = false; msg = "退款异常插入队列小于0!"; return(isok); } } catch (Exception ex) { log4net.LogHelper.WriteInfo(GetType(), $"{ex.Message} xxxxxxxxxxxxxxxx小程序砍价退款订单插入队列失败 ID={order.Id}"); isok = false; msg = "退款异常(插入队列失败)!"; return(isok); } } else { isok = false; msg = "退款异常!"; return(isok); } } }
/// <summary> /// 砍价发货 /// </summary> /// <param name="bargainUser"></param> /// <param name="bargain"></param> /// <param name="appId"></param> /// <param name="msg"></param> /// <returns></returns> public bool SendGoods(BargainUser bargainUser, Bargain bargain, int aid, out string msg, string attachData = "") { bool result = false; bool addExpressResult = false; if (bargainUser.State == 6) { msg = "已经发货了,不能修改!"; return(result); } //if (!string.IsNullOrEmpty(bargainUser.WayBillNo) || !string.IsNullOrEmpty(bargainUser.SendGoodsName)) //{ // msg = "已经发货了,不能修改!"; // return result; //} //if (string.IsNullOrEmpty(WayBillNo) || string.IsNullOrEmpty(SendGoodsName)) //{ // return Json(new { code = -1, msg = "快递单号或者名称不能为空!" }); //} //if (SendGoodsName.Length > 8) //{ // return Json(new { code = -1, msg = "快递名称过长" }); //} if (!string.IsNullOrEmpty(attachData)) { DeliveryUpdatePost DeliveryInfo = System.Web.Helpers.Json.Decode <DeliveryUpdatePost>(attachData); if (DeliveryInfo != null) { addExpressResult = DeliveryFeedbackBLL.SingleModel.AddOrderFeed(bargainUser.Id, DeliveryInfo, DeliveryOrderType.专业版砍价发货); if (!addExpressResult) { msg = "物流信息添加失败,发货失败!"; return(result); } } } bargainUser.State = 6; //bargainUser.WayBillNo = WayBillNo; //bargainUser.SendGoodsName = SendGoodsName; bargainUser.SendGoodsTime = DateTime.Now; if (Update(bargainUser, "SendGoodsTime,State")) { var storeName = ""; if (bargain != null) { switch (bargain.BargainType) { case 0: var store = StoreBLL.SingleModel.GetModel(bargain.StoreId); if (store != null) { var paramslist = ConfParamBLL.SingleModel.GetListByRId(aid) ?? new List <ConfParam>(); storeName = paramslist.Where(w => w.Param == "nparam").FirstOrDefault()?.Value; } break; case 1: storeName = OpenAuthorizerConfigBLL.SingleModel.GetModel($" rid = {aid} ")?.nick_name; break; default: storeName = ""; break; } } #region 模板消息 try { XcxAppAccountRelation app = XcxAppAccountRelationBLL.SingleModel.GetModel(aid); if (app == null) { throw new Exception($"发送砍价发货模板消息参数错误 app_null :aid = {aid}"); } XcxTemplate xcxTemp = XcxTemplateBLL.SingleModel.GetModel(app.TId); if (xcxTemp == null) { throw new Exception($"发送砍价发货模板消息参数错误 xcxTemp_null :xcxTempId = {app.TId}"); } Account account = AccountBLL.SingleModel.GetModel(app.AccountId); if (account == null) { throw new Exception($"发送砍价发货模板消息参数错误 account_null :accountId = {app.AccountId}"); } //电商为旧做法,兼容电商 switch (xcxTemp.Type) { case (int)TmpType.小程序电商模板: #region 购买者模板消息 var postData = new BargainUserBLL().GetTemplateMessageData_SendGoods(bargainUser.Id, storeName); TemplateMsg_Miniapp.SendTemplateMessage(bargainUser.UserId, SendTemplateMessageTypeEnum.电商订单配送通知, (int)TmpType.小程序电商模板, postData); #endregion 购买者模板消息 break; default: object orderData = TemplateMsg_Miniapp.BargainGetTemplateMessageData(bargainUser, SendTemplateMessageTypeEnum.价订单发货提醒); TemplateMsg_Miniapp.SendTemplateMessage(bargainUser.UserId, SendTemplateMessageTypeEnum.价订单发货提醒, xcxTemp.Type, orderData); break; } } catch (Exception ex) { log4net.LogHelper.WriteError(GetType(), ex); } #endregion 模板消息 result = true; msg = "发货成功!"; return(result); } else { result = false; msg = "发货异常!"; return(result); } }
public bool RefundOne(GroupUser item, ref string msg, int type = 0) { //0:微信支付,1:储值卡支付 int paytype = item.PayType; TransactionModel tranmodel = new MiniApp.TransactionModel(); Groups csg = GroupsBLL.SingleModel.GetModel(item.GroupId); if (csg == null) { msg = "小程序拼团商品不存在啦=" + item.GroupId; item.State = (int)MiniappPayState.已失效; Update(item, "State"); return(false); } GroupSponsor gsinfo = GroupSponsorBLL.SingleModel.GetModel(item.GroupSponsorId); if (gsinfo == null)//&& item.IsGroup == 1) { msg = "小程序拼团团购不存在啦=" + item.GroupSponsorId; item.State = (int)MiniappPayState.已失效; Update(item, "State"); return(false); } if (item.BuyPrice <= 0) { msg = "xxxxxxxxxxxxx小程序拼团价格为0不需要退款=" + item.Id; return(false); } if (item.PayState == (int)MiniappPayState.已退款) { msg = "xxxxxxxxxxxxx小程序拼团状态有误,不能退款=" + item.Id + ",paystate=" + item.PayState + "," + (int)MiniappPayState.已退款; return(false); } item.State = (int)MiniappPayState.已退款; //更新用户订单状态 tranmodel.Add($"update GroupUser set State={item.State} where id={item.Id}"); //判断是否是微信支付 if (paytype == 0) { CityMordersBLL mbll = new CityMordersBLL(); CityMorders order = mbll.GetModel(item.OrderId); if (order == null) { msg = "xxxxxxxxxxxxxxxxxx小程序拼团退款查不到支付订单 ID=" + item.Id; item.State = (int)MiniappPayState.已失效; Update(item, "State"); return(false); } //插入退款队列 ReFundQueue reModel = new ReFundQueue(); reModel.minisnsId = -5; reModel.money = item.BuyPrice; reModel.orderid = item.OrderId; reModel.traid = order.trade_no; reModel.addtime = DateTime.Now; reModel.note = "小程序拼团退款"; reModel.retype = 1; tranmodel.Add(new ReFundQueueBLL().BuildAddSql(reModel)); } else if (paytype == 1) { //储值卡退款 tranmodel.Add(SaveMoneySetUserBLL.SingleModel.GetCommandCarPriceSql(item.AppId, item.ObtainUserId, item.BuyPrice, 1, item.OrderId, item.OrderNo).ToArray()); if (tranmodel.sqlArray.Length <= 0) { msg = "xxxxxxxxxxxxxxxxxx拼团储值卡退款失败,ID=" + item.Id; return(false); } } //是店主手动退款不加库存 --统一,只要是退款就加库存 //if (type == 0) { if (gsinfo.State == 2 && item.IsGroup == 1) { msg = "小程序团购成功,不能退款=" + item.GroupSponsorId; return(false); } //退款成功,更新剩余数量 tranmodel.Add($"update groups set RemainNum ={(csg.RemainNum + item.BuyNum)} where id={csg.Id}"); } if (tranmodel.sqlArray.Length <= 0) { msg = "xxxxxxxxxxxxxxxxxx拼团退款失败,ID=" + item.Id; return(false); } if (!base.ExecuteTransaction(tranmodel.sqlArray, tranmodel.ParameterArray)) { msg = "xxxxxxxxxxxxxxxxxx拼团退款事务执行失败,ID=" + item.Id + "sql:" + string.Join(";", tranmodel.sqlArray); return(false); } XcxAppAccountRelation xcx = XcxAppAccountRelationBLL.SingleModel.GetModelByAppid(item.AppId); if (xcx == null) { log4net.LogHelper.WriteError(GetType(), new Exception($"发送模板消息,参数不足,XcxAppAccountRelation_null:appId = {item.AppId}")); return(true); } //发给用户发货通知 object groupData = TemplateMsg_Miniapp.GroupGetTemplateMessageData("商家操作退款", item, SendTemplateMessageTypeEnum.拼团基础版订单退款通知); TemplateMsg_Miniapp.SendTemplateMessage(item.ObtainUserId, SendTemplateMessageTypeEnum.拼团基础版订单退款通知, xcx.Type, groupData); msg = "xxxxxxxxxxxxxxxxxx拼团退款成功,ID=" + item.Id; return(true); }
/// <summary> /// 修改订单状态 /// </summary> /// <returns></returns> public ActionResult updateState() { int appId = Context.GetRequestInt("appId", 0); if (appId <= 0) { return(Json(new { isok = false, msg = "系统繁忙appid_null" }, JsonRequestBehavior.AllowGet)); } if (dzaccount == null) { return(Json(new { isok = false, msg = "系统繁忙auth_null" })); } var appAcountRelation = XcxAppAccountRelationBLL.SingleModel.GetModel($"id ={appId}"); if (appAcountRelation == null) { return(Json(new { isok = false, msg = "系统繁忙relation_null" })); } int storeId = Context.GetRequestInt("storeid", -1); if (storeId < 0) { return(Json(new { isok = false, msg = "系统繁忙storeId_null" })); } string storeSqlwhere = $"appid={appId}"; if (storeId > 0) { storeSqlwhere = $"id={storeId}"; } FootBath storeModel = FootBathBLL.SingleModel.GetModel(storeSqlwhere); if (storeModel == null) { return(Json(new { isok = false, msg = "系统繁忙model_null" })); } string msg = "操作失败"; bool isok = false; int state = Context.GetRequestInt("state", -999); int orderId = Context.GetRequestInt("id", 0); if (orderId <= 0) { return(Json(new { isok = false, msg = "系统繁忙orderId_null" })); } EntGoodsOrder orderInfo = EntGoodsOrderBLL.SingleModel.GetModel($"aId={appId} and id={orderId}"); if (orderInfo == null) { return(Json(new { isok = false, msg = "系统繁忙order_null" })); } SendTemplateMessageTypeEnum templateType = new SendTemplateMessageTypeEnum(); switch (state) { case (int)MiniAppEntOrderState.已取消: templateType = SendTemplateMessageTypeEnum.多门店订单取消通知; orderInfo.State = (int)MiniAppEntOrderState.已取消; break; case (int)MiniAppEntOrderState.待接单: templateType = SendTemplateMessageTypeEnum.多门店反馈处理结果通知; orderInfo.State = (int)MiniAppEntOrderState.待接单; break; case (int)MiniAppEntOrderState.待配送: templateType = SendTemplateMessageTypeEnum.多门店订单确认通知; orderInfo.State = (int)MiniAppEntOrderState.待配送; break; case (int)MiniAppEntOrderState.待确认送达: templateType = SendTemplateMessageTypeEnum.多门店订单配送通知; orderInfo.State = (int)MiniAppEntOrderState.待确认送达; break; case (int)MiniAppEntOrderState.交易成功: if (orderInfo.GetWay == (int)multiStoreOrderType.城配送) { templateType = SendTemplateMessageTypeEnum.多门店订单配送通知; } orderInfo.AcceptDate = DateTime.Now; orderInfo.State = (int)MiniAppEntOrderState.交易成功; break; case (int)MiniAppEntOrderState.待收货: templateType = SendTemplateMessageTypeEnum.多门店订单发货提醒; orderInfo.State = (int)MiniAppEntOrderState.待收货; break; } isok = EntGoodsOrderBLL.SingleModel.Update(orderInfo, "state,AcceptDate"); if (isok) { if (state == (int)MiniAppEntOrderState.交易成功) { VipRelationBLL.SingleModel.updatelevel(orderInfo.UserId, "multistore"); } msg = "操作成功"; var data = TemplateMsg_Miniapp.MutilStoreGetTemplateMessageData(orderInfo, templateType); TemplateMsg_Miniapp.SendTemplateMessage(orderInfo.UserId, templateType, TmpType.小程序多门店模板, data); } return(Json(new { isok = isok, msg = msg })); }
/// <summary> /// 取消预订 /// </summary> /// <returns></returns> public ActionResult UpdateState() { int appId = Context.GetRequestInt("appId", 0); if (appId <= 0) { return(Json(new { isok = false, msg = "系统繁忙appid_null" }, JsonRequestBehavior.AllowGet)); } if (dzaccount == null) { return(Json(new { isok = false, msg = "系统繁忙auth_null" })); } XcxAppAccountRelation appAcountRelation = XcxAppAccountRelationBLL.SingleModel.GetModelByaccountidAndAppid(appId, dzaccount.Id.ToString()); if (appAcountRelation == null) { return(Json(new { isok = false, msg = "系统繁忙relation_null" })); } FootBath storeModel = FootBathBLL.SingleModel.GetModel($"appId={appId}"); if (storeModel == null) { return(Json(new { isok = false, msg = "系统繁忙model_null" })); } int id = Context.GetRequestInt("id", 0); if (id <= 0) { return(Json(new { isok = false, msg = "系统繁忙orderId_null" })); } int state = Context.GetRequestInt("state", -7); if (state <= -7) { return(Json(new { isok = false, msg = "系统繁忙state_null" })); } EntGoodsOrder orderInfo = EntGoodsOrderBLL.SingleModel.GetModelByAidAndId(appId, id, 1); if (orderInfo == null) { return(Json(new { isok = false, msg = "系统繁忙model_null" })); } //是否是要直接取消的订单<未支付的订单取消订单都是直接取消> bool isCanncleOrder = orderInfo.PayDate == Convert.ToDateTime("0001-01-01 00:00:00"); if (isCanncleOrder) { orderInfo.State = (int)MiniAppEntOrderState.已取消; } else { orderInfo.State = state; } EntGoodsCart cart = EntGoodsCartBLL.SingleModel.GetModelByGoodsOrderId(orderInfo.Id); if (cart == null) { return(Json(new { isok = false, msg = "服务项目不存在" })); } ServiceTime serviceTime = ServiceTimeBLL.SingleModel.GetModel(storeModel.appId, cart.technicianId, storeModel.Id, cart.reservationTime.ToShortDateString()); //取消已预订的技师服务时间 if (serviceTime != null && !string.IsNullOrEmpty(serviceTime.time)) { List <string> timeList = serviceTime.time.Split(',').ToList(); timeList.Remove(cart.reservationTime.ToString("HH:mm")); serviceTime.time = string.Join(",", timeList); } bool isok = false; if (isCanncleOrder) { isok = EntGoodsOrderBLL.SingleModel.Update(orderInfo, "State"); } else { isok = EntGoodsOrderBLL.SingleModel.outOrder(appAcountRelation.AppId, orderInfo, serviceTime); } #region 取消预约通知 模板消息 if (isok && !isCanncleOrder) { object objData = TemplateMsg_Miniapp.FootbathGetTemplateMessageData(orderInfo, SendTemplateMessageTypeEnum.足浴预约取消通知); TemplateMsg_Miniapp.SendTemplateMessage(orderInfo.UserId, SendTemplateMessageTypeEnum.足浴预约取消通知, TmpType.小程序足浴模板, objData); } #endregion string msg = isok ? "操作成功" : "操作失败"; return(Json(new { isok = isok, msg = msg })); }