/// <summary> /// 拼团退款 /// </summary> /// <param name="item"></param> /// <param name="type">0:拼团失败退款,1:店主手动退款</param> /// <returns></returns> public bool EntGroupReFundQueue(EntGoodsOrder item, ref string msg) { int paytype = item.BuyMode; TransactionModel tranmodel = new MiniApp.TransactionModel(); EntGroupSponsor csg = EntGroupSponsorBLL.SingleModel.GetModel(item.GroupId); if (csg == null) { msg = "小程序拼团商品不存在啦=" + item.GroupId; item.State = (int)MiniAppEntOrderState.已取消; EntGoodsOrderBLL.SingleModel.Update(item, "State"); return(false); } EntGroupSponsor gsinfo = EntGroupSponsorBLL.SingleModel.GetModel(item.GroupId); if (gsinfo == null) { msg = "小程序拼团团购不存在啦=" + item.GroupId; item.State = (int)MiniAppEntOrderState.已取消; EntGoodsOrderBLL.SingleModel.Update(item, "State"); return(false); } if (item.BuyPrice <= 0) { msg = "xxxxxxxxxxxxx小程序拼团价格为0不需要退款=" + item.Id; return(false); } if (item.State == (int)MiniAppEntOrderState.退款成功) { msg = "xxxxxxxxxxxxx小程序拼团状态有误,不能退款=" + item.Id + ",paystate=" + item.State + "," + (int)MiniAppEntOrderState.退款成功; return(false); } item.State = (int)MiniAppEntOrderState.退款成功; //更新用户订单状态 tranmodel.Add($"update EntGoodsOrder set State={item.State} where id={item.Id}"); //判断是否是微信支付 if (paytype == (int)miniAppBuyMode.微信支付) { CityMorders order = _cityMordersBLL.GetModel(item.OrderId); if (order == null) { msg = "xxxxxxxxxxxxxxxxxx小程序拼团退款查不到支付订单 ID=" + item.Id; item.State = (int)MiniappPayState.已失效; EntGoodsOrderBLL.SingleModel.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(base.BuildAddSql(reModel)); } else if (paytype == (int)miniAppBuyMode.储值支付) { //储值卡退款 tranmodel.Add(SaveMoneySetUserBLL.SingleModel.GetCommandCarPriceSql(item.AppId, item.UserId, item.BuyPrice, 1, item.OrderId, item.OrderNum).ToArray()); if (tranmodel.sqlArray.Length <= 0) { msg = "xxxxxxxxxxxxxxxxxx专业版拼团储值卡退款失败,ID=" + item.Id; return(false); } } if (tranmodel.sqlArray.Length <= 0) { msg = "xxxxxxxxxxxxxxxxxx专业版拼团退款失败,ID=" + item.Id; return(false); } if (!ExecuteTransactionDataCorect(tranmodel.sqlArray, tranmodel.ParameterArray)) { msg = "xxxxxxxxxxxxxxxxxx专业版拼团退款事务执行失败,ID=" + item.Id + "sql:" + string.Join(";", tranmodel.sqlArray); return(false); } if (!EntGoodsOrderBLL.SingleModel.updateStock(item, (int)MiniAppEntOrderState.退款成功)) { msg = "xxxxxxxxxxxxxxxxxx专业版拼团退款更新库存失败,ID=" + item.Id; return(false); } msg = "xxxxxxxxxxxxxxxxxx专业版拼团退款成功,ID=" + item.Id; //根据订单释放库存 return(true); }
/// <summary> /// 根据AppId修改modelid /// </summary> /// <param name="relationid"></param> /// <returns></returns> public bool UpdateModelAppid(string appid, int rid, int type) { if (!string.IsNullOrEmpty(appid)) { TransactionModel tran = new MiniApp.TransactionModel(); //先判断是否有需要修改的数据存在,如果没有不要包含该sql,不然事务会回滚 var miniappcount = GetCount($"modelid = '{appid}'"); if (type == (int)TmpType.小程序企业模板 && miniappcount > 0) { tran.Add($"update miniapp set modelid='' where modelid='{appid}'"); } //先清除所有appid tran.Add($"update xcxappaccountrelation set appid='' where appid = '{appid}'"); //根据授权表返回的RId判断哪个才是真正绑定的 if (rid > 0) { tran.Add($"update xcxappaccountrelation set appid='{appid}' where id={rid}"); } try { if (!base.ExecuteTransactionDataCorect(tran.sqlArray, tran.ParameterArray)) { log4net.LogHelper.WriteInfo(this.GetType(), $"执行清除重复appid事务出错_sql:" + Newtonsoft.Json.JsonConvert.SerializeObject(tran.sqlArray)); return(false); } //企业版 if (type == (int)TmpType.小程序企业模板) { Miniapp listtemp = GetModelByRelationId(rid); if (listtemp != null) { listtemp.ModelId = appid; if (!Update(listtemp)) { log4net.LogHelper.WriteInfo(this.GetType(), $"修改企业版appid重复出错_{appid}_{rid}"); return(false); } } else { listtemp = new Miniapp(); listtemp.CreateDate = DateTime.Now; listtemp.Description = "官网小程序"; listtemp.xcxRelationId = rid; listtemp.State = 1; listtemp.ModelId = appid; listtemp.Id = Convert.ToInt32(Add(listtemp)); if (listtemp.Id <= 0) { log4net.LogHelper.WriteInfo(this.GetType(), $"新增企业版数据出错_{appid}_{rid}"); return(false); } } } //清除缓存 XcxAppAccountRelationBLL.SingleModel.RemoveRedis(rid); } catch (Exception ex) { log4net.LogHelper.WriteError(this.GetType(), ex); return(false); } } return(true); }
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); }