public ActionResult SendGoods(int appId, int id, string storeremark) { GroupUser groupuser = GroupUserBLL.SingleModel.GetModel(id); if (groupuser == null) { return(Json(new { isok = -1, msg = "团购信息异常 , 请刷新页面后重试" }, JsonRequestBehavior.AllowGet)); } if (groupuser.State != (int)MiniappPayState.待发货) { return(Json(new { isok = -1, msg = "此团购信息异常,请刷新后重试" }, JsonRequestBehavior.AllowGet)); } groupuser.State = (int)MiniappPayState.已发货; groupuser.SendGoodTime = DateTime.Now; groupuser.StorerRemark = storeremark; if (!GroupUserBLL.SingleModel.Update(groupuser)) { return(Json(new { isok = -1, msg = "发货失败" }, JsonRequestBehavior.AllowGet)); } XcxAppAccountRelation xcx = XcxAppAccountRelationBLL.SingleModel.GetModelByAppid(groupuser.AppId); if (xcx == null) { log4net.LogHelper.WriteError(GetType(), new Exception($"发送模板消息,参数不足,XcxAppAccountRelation_null:appId = {groupuser.AppId}")); return(Json(new { isok = 1, msg = "发货成功" }, JsonRequestBehavior.AllowGet)); } //发给用户发货通知 object groupData = TemplateMsg_Miniapp.GroupGetTemplateMessageData(string.Empty, groupuser, SendTemplateMessageTypeEnum.拼团基础版订单发货提醒); TemplateMsg_Miniapp.SendTemplateMessage(groupuser.ObtainUserId, SendTemplateMessageTypeEnum.拼团基础版订单发货提醒, xcx.Type, groupData); return(Json(new { isok = 1, msg = "发货成功" }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 拼团退款 /// </summary> /// <param name="item"></param> /// <param name="type">0:拼团失败退款,1:店主手动退款</param> /// <returns></returns> public bool GroupReFundQueue(GroupUser item, ref string msg, int type = 0) { //0:微信支付,1:储值卡支付 int paytype = item.PayType; TransactionModel tranmodel = new TransactionModel(); Groups csg = GroupsBLL.SingleModel.GetModel(item.GroupId); if (csg == null) { msg = "小程序拼团商品不存在啦=" + item.GroupId; item.State = (int)MiniappPayState.已失效; GroupUserBLL.SingleModel.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.已失效; GroupUserBLL.SingleModel.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) { CityMorders order = _cityMordersBLL.GetModel(item.OrderId); if (order == null) { msg = "xxxxxxxxxxxxxxxxxx小程序拼团退款查不到支付订单 ID=" + item.Id; item.State = (int)MiniappPayState.已失效; GroupUserBLL.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 == 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}"); //LogHelper.WriteInfo(GetType(), $"修改拼团失败库存: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 (!ExecuteTransactionDataCorect(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); }