/// <summary> /// 指定时间内未支付 取消订单变为已经关闭 /// </summary> /// <param name="timeoutlength"></param> public void updateOrderStateForCancle(int timeoutlength = -1) { TransactionModel tranModel = new TransactionModel(); //找出15分钟内未支付的订单 tranModel = new TransactionModel(); //从参与砍价商品领取记录里筛选已经生成订单并且1小时未支付的的订单 List <BargainUser> orderList = GetList($"(State=0 or State=5) and CreateOrderTime <= (NOW()+INTERVAL {timeoutlength} HOUR) and CreateOrderTime!='0001-01-01 00:00:00'"); if (orderList != null && orderList.Count > 0) { //找出需要增加库存的砍价商品 List <Bargain> goodlist = BargainBLL.SingleModel.GetList($"Id in ({string.Join(",", orderList.Select(s => s.BId).Distinct())})"); if (goodlist != null && goodlist.Count > 0) { foreach (var item in orderList) { BargainUser _BargainUser = item; _BargainUser.State = -1;//订单超过时间未支付 Bargain Bargain = goodlist.Where(x => x.Id == _BargainUser.BId).FirstOrDefault(); Bargain.RemainNum++;//库存加1 tranModel.Add(BuildUpdateSql(_BargainUser, "State")); tranModel.Add(BargainBLL.SingleModel.BuildUpdateSql(Bargain, "RemainNum")); //事务内某行sql执行受影响行数为0,会回滚整个事务 if (ExecuteTransactionDataCorect(tranModel.sqlArray)) { log4net.LogHelper.WriteInfo(GetType(), item.Id + "CityMorders订单超过15分钟未支付取消成功"); } else { log4net.LogHelper.WriteInfo(GetType(), item.Id + "CityMorders订单超过15分钟未支付取消失败"); } #region 发送 砍价订单取消通知 模板消息 => 通知用户 object orderData = TemplateMsg_Miniapp.BargainGetTemplateMessageData(item, SendTemplateMessageTypeEnum.价订单取消通知); TemplateMsg_Miniapp.SendTemplateMessage(item, SendTemplateMessageTypeEnum.价订单取消通知, orderData); #endregion 发送 砍价订单取消通知 模板消息 => 通知用户 } } } }
/// <summary> /// 砍价退款(照搬后台的) /// </summary> /// <param name="bargainUser"></param> /// <param name="bargain"></param> /// <param name="appId"></param> /// <param name="msg"></param> /// <returns></returns> public bool BargainReFundQueue(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; SaveMoneySetUser 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 = BargainUserBLL.SingleModel.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 = _cityMordersBLL.GetModel(bargainUser.CityMordersId); if (order == null) { msg = "订单信息有误!"; return(isok); } bargainUser.refundFee = bargainUser.CurrentPrice + bargain.GoodsFreight; if (BargainUserBLL.SingleModel.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(base.Add(reModel)); if (funid > 0) { object orderData = TemplateMsg_Miniapp.BargainGetTemplateMessageData(bargainUser, SendTemplateMessageTypeEnum.价订单退款通知, "商家操作退款"); TemplateMsg_Miniapp.SendTemplateMessage(bargainUser, SendTemplateMessageTypeEnum.价订单退款通知, orderData); isok = true; msg = "操作成功,已提交退款申请!"; return(isok); } 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); } }