public bool AddDadaMerchant(DadaMerchant model, int aid, int storeid = 0) { TransactionModel tran = new TransactionModel(); DadaMerchant merchantmodel = new DadaMerchant(); merchantmodel.city_name = model.city_name; merchantmodel.enterprise_name = model.enterprise_name; merchantmodel.mobile = model.mobile; merchantmodel.sourceid = model.sourceid.ToString(); tran.Add(base.BuildAddSql(merchantmodel)); DadaRelation dadarelationmodel = new DadaRelation(); dadarelationmodel.addtime = DateTime.Now; dadarelationmodel.rid = aid; dadarelationmodel.StoreId = storeid; tran.Add(Utils.BuildAddSqlS(dadarelationmodel, "merchantid", "(select LAST_INSERT_ID())", DadaRelationBLL.SingleModel.TableName, DadaRelationBLL.SingleModel.arrProperty)); DadaShop dadashopmodel = new DadaShop(); dadashopmodel.origin_shop_id = model.origin_shop_id; tran.Add(Utils.BuildAddSqlS(dadashopmodel, "merchantid", $"(select merchantid from DadaRelation where rid={aid} and storeid={storeid} LIMIT 1)", DadaShopBLL.SingleModel.TableName, DadaShopBLL.SingleModel.arrProperty)); bool success = base.ExecuteTransaction(tran.sqlArray); return(success); }
public bool UpdateDadaMerchant(DadaMerchant model, ref string msg) { TransactionModel tran = new TransactionModel(); DadaMerchant merchantmodel = base.GetModel(model.id); if (merchantmodel == null) { msg = "商户号数据失效了,请刷新重试"; return(false); } merchantmodel.city_name = model.city_name; merchantmodel.enterprise_name = model.enterprise_name; merchantmodel.mobile = model.mobile; merchantmodel.sourceid = model.sourceid.ToString(); tran.Add(base.BuildUpdateSql(merchantmodel, "city_name,enterprise_name,mobile,sourceid")); DadaShop dadashopmodel = DadaShopBLL.SingleModel.GetModelByMId(model.id); if (dadashopmodel == null) { msg = "达达店铺数据失效了,请刷新重试"; return(false); } dadashopmodel.origin_shop_id = model.origin_shop_id; tran.Add(DadaShopBLL.SingleModel.BuildUpdateSql(dadashopmodel, "origin_shop_id")); bool success = base.ExecuteTransaction(tran.sqlArray); return(success); }
/// <summary> /// 用户扫描代理分销二维码进行注册时,有可能已存在账号,该方法是修改用户一些信息 /// </summary> /// <param name="accountid"></param> /// <param name="phone"></param> /// <param name="password"></param> /// <param name="address"></param> /// <returns></returns> public bool UpdateUserInfo(string accountid, string phone, string password, string address) { TransactionModel tran = new TransactionModel(); string passwordMd = DESEncryptTools.GetMd5Base32(password); Member membermodel = MemberBLL.SingleModel.GetMemberByAccountId(accountid); MySqlParameter[] param = new MySqlParameter[] { new MySqlParameter("@ConsigneePhone", phone), new MySqlParameter("@Password", passwordMd), new MySqlParameter("@id", accountid), }; tran.Add($"update Account set ConsigneePhone=@ConsigneePhone,Password=@Password where id=@id", param); if (membermodel != null) { MySqlParameter[] param2 = new MySqlParameter[] { new MySqlParameter("@ConsigneePhone1", phone), new MySqlParameter("@CompanyRemark", address), new MySqlParameter("@AccountId", accountid), }; tran.Add($"update Member set ConsigneePhone1=@ConsigneePhone1,CompanyRemark=@CompanyRemark where AccountId=@AccountId", param2); } return(base.ExecuteTransaction(tran.sqlArray, tran.ParameterArray)); }
/// <summary> /// 注册赠送模板 /// </summary> /// <param name="accountModel"></param> public void AddFreeTemplate(Account accountModel) { string typeids = $"{(int)TmpType.小程序单页模板},{(int)TmpType.小程序企业模板},{(int)TmpType.小程序专业模板}"; List <XcxTemplate> templist = XcxTemplateBLL.SingleModel.GetListByTypes(typeids); if (templist == null || templist.Count <= 0 || accountModel == null) { return; } XcxAppAccountRelation usertemplate = GetModelByaccound(accountModel.Id.ToString()); if (usertemplate != null) { return; } TransactionModel tran = new TransactionModel(); DateTime nowtime = DateTime.Now; int version = 0; int month = 100 * 12; foreach (XcxTemplate item in templist) { version = 0; if (item.Type == (int)TmpType.小程序专业模板) { version = 3; month = 3; } else { month = 100 * 12; } tran.Add($@"insert into XcxAppAccountRelation(TId,AccountId,AddTime,Url,price,outtime,agentid,VersionId) values({item.Id}, '{accountModel.Id}', '{nowtime}', '{item.Link}', {item.Price}, '{nowtime.AddMonths(month)}',0,{version})"); AgentdepositLog pricemodellog = new AgentdepositLog(); pricemodellog.addtime = DateTime.Now; pricemodellog.afterDeposit = 0; pricemodellog.agentid = 0; pricemodellog.beforeDeposit = 0; pricemodellog.cost = 0; pricemodellog.costdetail = $"客户免费使用小程序模板:{(version == 3 ? "专业基础版" : item.TName)}"; pricemodellog.type = 0; pricemodellog.tid = item.Id; tran.Add(AgentdepositLogBLL.SingleModel.BuildAddSql(pricemodellog)); } if (!ExecuteTransactionDataCorect(tran.sqlArray, tran.ParameterArray)) { log4net.LogHelper.WriteInfo(this.GetType(), "赠送免费版:失败," + Newtonsoft.Json.JsonConvert.SerializeObject(tran)); } }
/// <summary> /// 赠送代理平台模板 /// </summary> /// <param name="accountModel"></param> public void AddTemplate(Account accountModel, Agentinfo agentInfo) { if (agentInfo == null && agentInfo.userLevel == 0) { return; } string typeids = $"{(int)TmpType.小未平台}"; List <XcxTemplate> templist = XcxTemplateBLL.SingleModel.GetListByTypes(typeids); if (templist == null || templist.Count <= 0 || accountModel == null) { return; } List <XcxAppAccountRelation> usertemplate = GetListByTidAccountId($"'{accountModel.Id.ToString()}'", templist[0].Id); if (usertemplate != null && usertemplate.Count > 0) { return; } TransactionModel tran = new TransactionModel(); DateTime nowtime = DateTime.Now; foreach (XcxTemplate item in templist) { tran.Add($@"insert into XcxAppAccountRelation(TId,AccountId,AddTime,Url,price,outtime,agentid) values({item.Id}, '{accountModel.Id}', '{nowtime}', '{item.Link}', {item.Price}, '{agentInfo.addtime.AddYears(1)}',0)"); AgentdepositLog pricemodellog = new AgentdepositLog(); pricemodellog.addtime = DateTime.Now; pricemodellog.afterDeposit = 0; pricemodellog.agentid = 0; pricemodellog.beforeDeposit = 0; pricemodellog.cost = 0; pricemodellog.costdetail = $"客户免费使用小程序模板:" + item.TName; pricemodellog.type = 0; pricemodellog.tid = item.Id; tran.Add(AgentdepositLogBLL.SingleModel.BuildAddSql(pricemodellog)); } if (!ExecuteTransactionDataCorect(tran.sqlArray, tran.ParameterArray)) { log4net.LogHelper.WriteInfo(this.GetType(), "赠送免费版:失败," + Newtonsoft.Json.JsonConvert.SerializeObject(tran)); } }
/// <summary> /// 生成UU配送订单 /// </summary> /// <returns></returns> public string AddUUOrder(DistributionApiModel model) { string msg = ""; UUCustomerRelation customerRelation = UUCustomerRelationBLL.SingleModel.GetModelByAid(model.aid, model.storeid, 0); if (customerRelation == null) { msg = "请先配置UU配送"; return(msg); } UUOrderFee feeResult = GetUUFee(model.storeid, model.aid, model.address, ref msg); if (msg.Length > 0) { return(msg); } string orderNum = CommonCore.GetOrderNumByUserId(model.userid.ToString()); string appid = UUApi._appid; string timestamp = UUApi.GetTimestamp(); //店铺信息 ShopInfo shopInfo = GetStoreAddressPoint(customerRelation.AId, customerRelation.StoreId, model.temptype); //生成订单实体类对象 UUOrder data = new UUOrder(appid, timestamp, customerRelation.OpenId, feeResult.price_token, feeResult.total_money, feeResult.need_paymoney, model.accepterName, model.accepterTelePhone, model.remark, UUApi._notisUrl, customerRelation.AId, customerRelation.StoreId, model.temptype, model.ordertype, model.orderid, orderNum); TransactionModel tran = new TransactionModel(); tran.Add(base.BuildAddSql(data)); if (!ExecuteTransactionDataCorect(tran.sqlArray, tran.ParameterArray)) { msg = "添加UU配送订单出错"; } return(msg); }
/// <summary> /// 多门店退款 /// </summary> /// <param name="orderInfo"></param> /// <returns></returns> public bool MultiStoreReFundQueue(List <EntGoodsCart> goodsCar, FootBath storeMaterial, EntGoodsOrder orderInfo) { bool result = false; orderInfo.outOrderDate = DateTime.Now; orderInfo.State = (int)MiniAppEntOrderState.退款中; if (orderInfo.BuyMode == (int)miniAppBuyMode.微信支付) { try { if (orderInfo.BuyPrice == 0) { orderInfo.State = (int)MiniAppEntOrderState.退款成功; EntGoodsOrderBLL.SingleModel.Update(orderInfo, "State,outOrderDate"); } else { CityMorders order = _cityMordersBLL.GetModel(orderInfo.OrderId); orderInfo.State = (int)MiniAppEntOrderState.退款中; if (order == null) { orderInfo.State = (int)MiniAppEntOrderState.退款失败; EntGoodsOrderBLL.SingleModel.Update(orderInfo, "State,outOrderDate"); return(result); } //微信支付 ReFundQueue reModel = new ReFundQueue { minisnsId = -5, money = orderInfo.BuyPrice, orderid = order.Id, traid = order.trade_no, addtime = DateTime.Now, note = "小程序多门店退款", retype = 1 }; base.Add(reModel); } TransactionModel tranModel = new TransactionModel(); tranModel.Add(EntGoodsOrderBLL.SingleModel.BuildUpdateSql(orderInfo, "State,outOrderDate")); if (!EntGoodsOrderBLL.SingleModel.HandleStockSql_MultiStore(goodsCar, storeMaterial, tranModel, -1)) { log4net.LogHelper.WriteInfo(GetType(), "生成库存处理sql失败 HandleStockSql_MultiStore_error"); return(false); } result = ExecuteTransactionDataCorect(tranModel.sqlArray, tranModel.ParameterArray); return(result); } catch (Exception ex) { log4net.LogHelper.WriteInfo(GetType(), $"{ex.Message} xxxxxxxxxxxxxxxx小程序多门店退款订单插入队列失败 ID={orderInfo.Id}"); log4net.LogHelper.WriteError(GetType(), ex); } } return(result); }
/// <summary> /// 餐饮储值支付 退款 /// </summary> /// <param name="dbOrder"></param> /// <param name="saveMoneyUser"></param> /// <returns></returns> public bool FoodSaveMoneyReFundQueue(FoodGoodsOrder dbOrder, SaveMoneySetUser saveMoneyUser, int oldState) { if (saveMoneyUser == null || saveMoneyUser.Id <= 0) { return(false); } //回退库存 if (!FoodGoodsOrderBLL.SingleModel.updateStock(dbOrder, oldState)) { return(false); } TransactionModel tran = new TransactionModel(); tran.Add(SaveMoneySetUserLogBLL.SingleModel.BuildAddSql(new SaveMoneySetUserLog() { AppId = saveMoneyUser.AppId, UserId = dbOrder.UserId, MoneySetUserId = saveMoneyUser.Id, Type = 1, BeforeMoney = saveMoneyUser.AccountMoney, AfterMoney = saveMoneyUser.AccountMoney + dbOrder.BuyPrice, ChangeMoney = dbOrder.BuyPrice, ChangeNote = $" 购买商品,订单号:{dbOrder.OrderNum} ", CreateDate = DateTime.Now, State = 1 })); saveMoneyUser.AccountMoney += dbOrder.BuyPrice; tran.Add($" update SaveMoneySetUser set AccountMoney = AccountMoney + {dbOrder.BuyPrice} where id = {saveMoneyUser.Id} ; "); tran.Add($" update foodgoodsorder set state = {(int)miniAppFoodOrderState.已退款 },outOrderDate = '{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}',Remark = @Remark where Id = {dbOrder.Id} and state <> {(int)miniAppFoodOrderState.已退款 } ; ", new MySqlParameter[] { new MySqlParameter("@Remark", dbOrder.Remark) });//防止重复退款 //记录订单退款日志 tran.Add(FoodGoodsOrderLogBLL.SingleModel.BuildAddSql(new FoodGoodsOrderLog() { GoodsOrderId = dbOrder.Id, UserId = dbOrder.UserId.ToString(), LogInfo = $" 订单储值支付,退款成功:{dbOrder.BuyPrice * 0.01} 元 ", CreateDate = DateTime.Now })); return(ExecuteTransaction(tran.sqlArray, tran.ParameterArray)); }
/// <summary> /// 跟进 退款状态 (退款是否成功) /// </summary> /// <returns></returns> public bool UpdateEntReFundQueueOrderState() { TransactionModel tranModel = new TransactionModel(); List <EntGoodsOrder> itemList = EntGoodsOrderBLL.SingleModel.GetList($" State = {(int)MiniAppEntOrderState.退款中} and templatetype in ({(int)TmpType.小程序专业模板},{(int)TmpType.小程序足浴模板},{(int)TmpType.小程序多门店模板}) and outOrderDate <= (NOW()-interval 17 second) ", 1000, 1) ?? new List <EntGoodsOrder>(); List <CityMorders> orderList = new List <CityMorders>(); List <ReFundResult> outOrderList = new List <ReFundResult>(); if (itemList.Any()) { orderList = _cityMordersBLL.GetList($" Id in ({string.Join(",", itemList.Select(x => x.OrderId))}) ", 1000, 1) ?? new List <CityMorders>(); if (orderList.Any()) { outOrderList = RefundResultBLL.SingleModel.GetList($" transaction_id in ('{string.Join("','", orderList.Select(x => x.trade_no))}') and retype = 1") ?? new List <ReFundResult>(); itemList.ForEach(x => { var curOrder = orderList.Where(y => y.Id == x.OrderId).FirstOrDefault(); if (curOrder != null) { //退款是排程处理,故无法确定何时执行退款,而现阶段退款操作成败与否都会记录在系统内 var curOutOrder = outOrderList.Where(y => y.transaction_id == curOrder.trade_no).FirstOrDefault(); if (curOutOrder != null && curOutOrder.result_code.Equals("SUCCESS")) { x.State = (int)MiniAppEntOrderState.退款成功; tranModel.Add(EntGoodsOrderBLL.SingleModel.BuildUpdateSql(x, "State")); } else if (curOutOrder != null && !curOutOrder.result_code.Equals("SUCCESS")) { x.State = (int)MiniAppEntOrderState.退款失败; tranModel.Add(EntGoodsOrderBLL.SingleModel.BuildUpdateSql(x, "State")); } } }); } } var isSuccess = ExecuteTransactionDataCorect(tranModel.sqlArray, tranModel.ParameterArray); return(isSuccess); }
/// <summary> /// 获取修改达达订单状态sql /// </summary> /// <param name="orderid">小程序订单表ID</param> /// <param name="rid"></param> /// <param name="ordertype">看枚举TmpType</param> /// <param name="tran"></param> /// <returns></returns> public string GetDadaOrderUpdateSql(int orderid, int rid, int ordertype, ref TransactionModel tran, bool gettransql = false) { DadaOrderRelation model = DadaOrderRelationBLL.SingleModel.GetModelOrder(rid, orderid, ordertype); if (model == null) { return("达达配送:没有找到订单关联数据"); } DadaOrder order = GetModelByOrderNo(model.uniqueorderno); if (order == null) { return("达达配送:订单不存在"); } DadaMerchant merchant = DadaMerchantBLL.SingleModel.GetModelByRId(rid); if (merchant == null || merchant.id <= 0) { return("达达配送:找不到商户数据"); } DadaApiReponseModel <ResultReponseModel> result = AddOrder(order, merchant.sourceid, 0); if (result == null) { return("达达配送:新增订单接口异常"); } //log4net.LogHelper.WriteInfo(this.GetType(),JsonConvert.SerializeObject(result)); if (result.status == "success") { order.state = (int)DadaOrderEnum.推单中; if (gettransql) { return(base.ExecuteNonQuery($"update dadaorder set state={order.state} where id={order.id}") > 0?"":"修改达达订单状态出错"); } else { tran.Add($"update dadaorder set state={order.state} where id={order.id}"); } return(""); } return(result.msg); }
/// <summary> /// UU配送推单 /// </summary> /// <param name="orderId">小程序订单表ID</param> /// <param name="rid"></param> /// <param name="tran"></param> /// <returns></returns> public string GetUUOrderUpdateSql(int orderId, int aid, int storeId, ref TransactionModel tran, bool getTranSql = false) { UUOrder order = GetModelByOrerId(aid, storeId, orderId); if (order == null) { return("UU配送:订单不存在(推单)"); } UUCustomerRelation customerRelation = UUCustomerRelationBLL.SingleModel.GetModelByAid(aid, storeId, 0); if (customerRelation == null) { return("UU配送:未设置UU配置(推单)"); } UUBaseResult result = UUApi.AddOrder(order); if (result == null) { return("UU配送:推送订单接口异常(推单)"); } if (result.return_code == "ok") { order.State = (int)UUOrderEnum.单成功; if (result == null || string.IsNullOrEmpty(result.ordercode)) { LogHelper.WriteInfo(this.GetType(), "UU配送:推送订单接口返回值异常(推单)" + JsonConvert.SerializeObject(result)); return("UU配送:推送订单接口返回值异常(推单)"); } order.order_code = result.ordercode; if (getTranSql) { return(base.ExecuteNonQuery($"update UUOrder set state={order.State},order_code='{order.order_code}' where id={order.Id}") > 0 ? "" : "UU配送:修改UU订单状态出错(推单)"); } else { tran.Add($"update UUOrder set state={order.State},order_code='{order.order_code}' where id={order.Id}"); } return(""); } return(result.return_msg); }
/// <summary> /// 快跑者配送推单 /// </summary> /// <param name="orderid">小程序订单表ID</param> /// <param name="rid"></param> /// <param name="tran"></param> /// <returns></returns> public string GetKPZOrderUpdateSql(int orderid, int aid, int storeid, ref TransactionModel tran, bool gettransql = false) { KPZOrder order = GetModelByOrerId(aid, storeid, orderid); if (order == null) { return("快跑者配送:订单不存在"); } KPZStoreRelation kpzstore = KPZStoreRelationBLL.SingleModel.GetModel(order.shop_id); if (kpzstore == null) { return("快跑者配送:关联店铺不存在"); } KPZResult <OrderTradeNo> result = KPZApi.CreateOrder(order, kpzstore.TeamToken); if (result == null) { return("快跑者配送:新增订单接口异常"); } if (result.code == 200) { order.status = (int)KPZOrderEnum.待发单; if (result.data == null || string.IsNullOrEmpty(result.data.trade_no)) { LogHelper.WriteInfo(this.GetType(), "快跑者新增订单接口返回值异常" + JsonConvert.SerializeObject(result)); return("快跑者新增订单接口返回值异常"); } order.trade_no = result.data.trade_no; if (gettransql) { return(base.ExecuteNonQuery($"update KPZOrder set status={order.status},trade_no='{order.trade_no}' where id={order.id}") > 0 ? "" : "修改快跑者订单状态出错"); } else { tran.Add($"update KPZOrder set status={order.status},trade_no='{order.trade_no}' where id={order.id}"); } return(""); } return(result.message); }
/// <summary> /// 获取修改蜂鸟订单状态sql /// </summary> /// <param name="orderid">小程序订单表ID</param> /// <param name="rid"></param> /// <param name="ordertype">TmpType枚举</param> /// <param name="tran"></param> /// <returns></returns> public string GetFNOrderUpdateSql(int orderid, int rid, int ordertype, ref TransactionModel tran, bool gettransql = false) { FNOrderRelation model = FNOrderRelationBLL.SingleModel.GetModelOrder(rid, orderid, ordertype); if (model == null) { return("没有找到蜂鸟订单关联数据"); } FNOrder order = GetModelByOrderNo(model.uniqueorderno); if (order == null) { return("蜂鸟订单不存在"); } FNApiReponseModel <object> result = AddOrderToFN(order); if (result == null) { return("蜂鸟新增订单接口异常"); } if (result.code == 200) { order.state = (int)FNOrderEnum.推单中; if (gettransql) { return(base.ExecuteNonQuery($"update fnorder set state={order.state},updatetime=now() where id={order.id}") > 0 ? "" : "修改蜂鸟订单状态出错"); } else { tran.Add($"update fnorder set state={order.state},updatetime=now() where id={order.id}"); } return(""); } return(result.msg); }
/// <summary> /// 生成快跑者配送订单 /// </summary> /// <param name="rid">权限表ID</param> /// <param name="userinfo">用户信息</param> /// <param name="orderid">订单ID</param> /// <param name="price">订单价格</param> /// <param name="receviename">收货人姓名</param> /// <param name="receviephone">收货人电话</param> /// <param name="address">收货人地址</param> /// <param name="lat">纬度</param> /// <param name="lnt">经度</param> /// <param name="ordertype">看枚举TmpType</param> /// <returns></returns> public string AddKPZOrder(DistributionApiModel model) { string msg = ""; KPZStoreRelation storerelation = KPZStoreRelationBLL.SingleModel.GetModelBySidAndAid(model.aid, model.storeid); if (storerelation == null) { msg = "请先配置快跑者配送"; return(msg); } //再请求一次腾讯地图,获取准确的坐标 AddressApi addressModel = AddressHelper.GetLngAndLatByAddress(model.address); if (addressModel != null && addressModel.result != null && addressModel.result.location != null) { model.lnt = addressModel.result.location.lng; model.lat = addressModel.result.location.lat; } TransactionModel tran = new TransactionModel(); string orderno = CommonCore.GetOrderNumByUserId(model.userid.ToString()); float buyprice = model.buyprice / 100.0f; float payfee = model.fee / 100.0f; int paystatus = 0; //店铺信息 ShopInfo shopinfo = GetStoreAddressPoint(storerelation.AId, storerelation.StoreId, model.temptype); //生成订单实体类对象 KPZOrder data = new KPZOrder(storerelation.Id, shopinfo.ShopName, storerelation.TelePhone, shopinfo.ShopAddress, shopinfo.ShopTag, model.ordercontent, model.remark, orderno, model.accepterName, model.accepterTelePhone, model.address, model.lnt + "," + model.lat, buyprice, buyprice, paystatus, payfee, model.orderid, model.aid, model.temptype, model.storeid); tran.Add(base.BuildAddSql(data)); if (!ExecuteTransactionDataCorect(tran.sqlArray, tran.ParameterArray)) { msg = "添加快跑者配送订单出错"; } return(msg); }
/// <summary> /// 普通用户开通体验版 /// </summary> /// <param name="agentInfo"></param> /// <param name="tIds"></param> /// <param name="userAccount"></param> /// <param name="erroMsg"></param> /// <param name="dayLength"></param> /// <returns></returns> public bool OpenExperience(string tIds, Account userAccount, ref string erroMsg, int dayLength = 3) { TransactionModel tranModel = new TransactionModel(); //判断要开通的模板是否还没体验过 bool canOpen = IsOpenExperience(tIds, userAccount.Id.ToString()); if (canOpen) { erroMsg = "模板已开通过,请刷新重试"; return(false); } List <XcxTemplate> xcxList = XcxTemplateBLL.SingleModel.GetListByIds(tIds); //添加模板记录 foreach (XcxTemplate xcx in xcxList) { AgentdepositLog agentLog = new AgentdepositLog(); agentLog.agentid = 0; agentLog.addtime = DateTime.Now; agentLog.templateCount = 1; agentLog.customerid = userAccount.Id.ToString(); agentLog.tid = xcx.Id; agentLog.type = 2; agentLog.templateCount = 1; agentLog.costdetail = $"开通体验{xcx.TName}模板"; tranModel.Add(AgentdepositLogBLL.SingleModel.BuildAddSql(agentLog)); XcxAppAccountRelation xcxappaccountrelation = new XcxAppAccountRelation() { TId = xcx.Id, AccountId = userAccount.Id, AddTime = DateTime.Now, agentId = 0, Url = xcx.Link, price = xcx.Price, TimeLength = xcx.year, outtime = DateTime.Now.AddDays(dayLength), SCount = xcx.SCount, IsExperience = true, }; xcxappaccountrelation.Id = Convert.ToInt32(base.Add(xcxappaccountrelation)); if (xcx.Type == (int)TmpType.小程序多门店模板) { tranModel.Add(FootBathBLL.SingleModel.GetAddFootbathSQL(xcxappaccountrelation.AccountId, xcx.SCount - 1, xcxappaccountrelation.Id, xcxappaccountrelation.outtime).ToArray()); } } //执行事务 bool success = false; try { success = base.ExecuteTransactionDataCorect(tranModel.sqlArray, tranModel.ParameterArray); } catch (Exception ex) { erroMsg = ex.Message; } return(success); }
/// <summary> /// 添加达达订单 /// </summary> /// <param name="rid">权限表ID</param> /// <param name="userid">用户ID</param> /// <param name="orderid">订单ID</param> /// <param name="cityname">订单所在城市名</param> /// <param name="price">价格(分)</param> /// <param name="receivername">收货人姓名</param> /// <param name="receivertel">收货人电话</param> /// <param name="address">收货地址</param> /// <param name="lat">收货地址纬度</param> /// <param name="lnt">收货地址经度</param> /// <param name="desc">备注</param> /// <param name="ordertype">看枚举TmpType</param> /// <returns></returns> public string AddDadaOrder(DistributionApiModel model) { string msg = ""; DadaRelation relation = DadaRelationBLL.SingleModel.GetModelByRid(model.aid); if (relation != null) { DadaMerchant merchant = DadaMerchantBLL.SingleModel.GetModel(relation.merchantid); if (merchant != null) { DadaCity city = DadaCityBLL.SingleModel.GetModelName(model.cityname); if (city == null) { msg = "物流到不了城市" + model.cityname; return(msg); } DadaShop shop = DadaShopBLL.SingleModel.GetModelByMId(merchant.id); if (shop == null) { msg = "物流到不了城市" + model.cityname; return(msg); } TransactionModel tran = new TransactionModel(); string timestamp = _dadaapi.GetTimeStamp(); string callback = _dadaapi._ordercallback; string order_id = model.userid + DateTime.Now.ToString("yyyyMMddHHmmss"); string shopno = shop.origin_shop_id; float buyprice = model.buyprice / 100.0f; DadaOrder data = new DadaOrder(order_id, city.cityCode, shopno, buyprice, model.accepterName, model.accepterTelePhone, model.address, model.lat, model.lnt, model.remark, timestamp, callback); //data.id = Convert.ToInt32(base.Add(data)); tran.Add(base.BuildAddSql(data)); DadaOrderRelation orderrelation = new DadaOrderRelation(); orderrelation.dataid = model.aid; orderrelation.orderid = model.orderid; orderrelation.ordertype = model.temptype; orderrelation.uniqueorderno = order_id; //orderrelation.id = Convert.ToInt32(DadaOrderRelationBLL.SingleModel.Add(orderrelation)); tran.Add(DadaOrderRelationBLL.SingleModel.BuildAddSql(orderrelation)); if (!ExecuteTransactionDataCorect(tran.sqlArray, tran.ParameterArray)) { msg = "添加达达物流出错"; } } else { msg = "找不到商户号"; } } else { msg = "找不到管理表"; } return(msg); }
/// <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); }
/// <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="item"></param> /// <param name="oldState"></param> /// <param name="BuyMode">默认微信支付</param> /// <param name="isPartOut">是否部分退款</param> /// <returns></returns> public bool EntReFundQueue(EntGoodsOrder item, int oldState, int BuyMode = (int)miniAppBuyMode.微信支付, int?newState = null, bool isPartOut = false) { //重新加回库存 if (EntGoodsOrderBLL.SingleModel.updateStock(item, oldState)) { int money = isPartOut ? item.refundFee : item.BuyPrice;//兼容多版本,目前只有专业版订单有部分退款 item.refundFee = money; if (BuyMode == (int)miniAppBuyMode.微信支付) { try { item.outOrderDate = DateTime.Now; if (item.BuyPrice == 0) //金额为0时,回滚库存后,默认退款成功 { item.State = (int)MiniAppEntOrderState.退款成功; } else { CityMorders order = _cityMordersBLL.GetModel(item.OrderId); item.State = (int)MiniAppEntOrderState.退款中; if (newState.HasValue) { item.State = newState.Value; } if (order == null) { item.State = (int)MiniAppEntOrderState.退款失败; EntGoodsOrderBLL.SingleModel.Update(item, "State,outOrderDate,Remark,refundFee"); return(false); } //微信支付 ReFundQueue reModel = new ReFundQueue { minisnsId = -5, money = item.refundFee, orderid = order.Id, traid = order.trade_no, addtime = DateTime.Now, note = "小程序行业版退款", retype = 1 }; base.Add(reModel); } bool isSuccess = EntGoodsOrderBLL.SingleModel.Update(item, "State,outOrderDate,Remark,refundFee"); if (isSuccess) { //发给用户退款通知 object orderData = TemplateMsg_Miniapp.EnterpriseGetTemplateMessageData(item, SendTemplateMessageTypeEnum.专业版订单退款通知, "商家操作退款"); TemplateMsg_Miniapp.SendTemplateMessage(item.UserId, SendTemplateMessageTypeEnum.专业版订单退款通知, TmpType.小程序专业模板, orderData); } } catch (Exception ex) { log4net.LogHelper.WriteInfo(GetType(), $"{ex.Message} xxxxxxxxxxxxxxxx小程序餐饮退款订单插入队列失败 ID={item.Id}"); } } else { XcxAppAccountRelation r = XcxAppAccountRelationBLL.SingleModel.GetModel(item.aId); if (r == null) { return(false); } SaveMoneySetUser saveMoneyUser = SaveMoneySetUserBLL.SingleModel.getModelByUserId(r.AppId, item.UserId); TransactionModel tran = new TransactionModel(); tran.Add(SaveMoneySetUserLogBLL.SingleModel.BuildAddSql(new SaveMoneySetUserLog() { AppId = r.AppId, UserId = item.UserId, MoneySetUserId = saveMoneyUser.Id, Type = 1, BeforeMoney = saveMoneyUser.AccountMoney, AfterMoney = saveMoneyUser.AccountMoney + item.refundFee, ChangeMoney = item.refundFee, ChangeNote = $"专业版购买商品退款,订单号:{item.OrderNum} ", CreateDate = DateTime.Now, State = 1 })); item.State = (int)MiniAppEntOrderState.退款成功; if (newState.HasValue) { item.State = newState.Value; } tran.Add($" update SaveMoneySetUser set AccountMoney = AccountMoney + {item.refundFee} where id = {saveMoneyUser.Id} ; "); tran.Add($" update EntGoodsOrder set State = {item.State },outOrderDate = '{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}',Remark = @Remark where Id = {item.Id} and state <> {item.State} ; ", new MySqlParameter[] { new MySqlParameter("@Remark", item.Remark) });//防止重复退款 //记录订单储值支付退款日志 tran.Add(EntGoodsOrderLogBLL.SingleModel.BuildAddSql(new EntGoodsOrderLog() { GoodsOrderId = item.Id, UserId = item.UserId, LogInfo = $" 储值支付订单退款成功:{item.refundFee * 0.01} 元 ", CreateDate = DateTime.Now })); bool isSuccess = ExecuteTransaction(tran.sqlArray, tran.ParameterArray); if (isSuccess) { //发给用户退款通知 object orderData = TemplateMsg_Miniapp.EnterpriseGetTemplateMessageData(item, SendTemplateMessageTypeEnum.专业版订单退款通知, "商家操作退款"); TemplateMsg_Miniapp.SendTemplateMessage(item.UserId, SendTemplateMessageTypeEnum.专业版订单退款通知, TmpType.小程序专业模板, orderData); } return(isSuccess); } } else { return(false); } return(true); }
/// <summary> /// 足浴版退款 /// </summary> /// <param name="appId"></param> /// <param name="orderInfo"></param> /// <returns></returns> public bool ZYReFundQueue(string appId, EntGoodsOrder orderInfo, ServiceTime serviceTime) { bool result = false; if (orderInfo == null || orderInfo.Id <= 0) { return(result); } orderInfo.outOrderDate = DateTime.Now; if (orderInfo.BuyMode == (int)miniAppBuyMode.储值支付) { var saveMoneyUser = new SaveMoneySetUser(); saveMoneyUser = SaveMoneySetUserBLL.SingleModel.getModelByUserId(appId, orderInfo.UserId); if (saveMoneyUser == null || saveMoneyUser.Id <= 0) { return(result); } TransactionModel tran = new TransactionModel(); tran.Add(SaveMoneySetUserLogBLL.SingleModel.BuildAddSql(new SaveMoneySetUserLog() { AppId = saveMoneyUser.AppId, UserId = orderInfo.UserId, MoneySetUserId = saveMoneyUser.Id, Type = 1, BeforeMoney = saveMoneyUser.AccountMoney, AfterMoney = saveMoneyUser.AccountMoney + orderInfo.BuyPrice, ChangeMoney = orderInfo.BuyPrice, ChangeNote = $" 购买商品,订单号:{orderInfo.OrderNum} ", CreateDate = DateTime.Now, State = 1 })); saveMoneyUser.AccountMoney += orderInfo.BuyPrice; tran.Add($" update SaveMoneySetUser set AccountMoney = AccountMoney + {orderInfo.BuyPrice} where id = {saveMoneyUser.Id} ; "); tran.Add($" update EntGoodsOrder set state = {(int)MiniAppEntOrderState.退款成功 },outOrderDate = '{orderInfo.outOrderDate.ToString("yyyy-MM-dd HH:mm:ss")}',Remark = @Remark where Id = {orderInfo.Id} and state <> {(int)MiniAppEntOrderState.退款成功 } ; ", new MySqlParameter[] { new MySqlParameter("@Remark", orderInfo.Remark) });//防止重复退款 if (serviceTime != null) { tran.Add($"update servicetime set time='{serviceTime.time}' where id={serviceTime.Id}");//取消已预订的技师服务时间 } //记录订单退款日志 tran.Add(EntGoodsOrderLogBLL.SingleModel.BuildAddSql(new EntGoodsOrderLog() { GoodsOrderId = orderInfo.Id, UserId = orderInfo.UserId, LogInfo = $" 订单储值支付,退款成功:{orderInfo.BuyPrice * 0.01} 元 ", CreateDate = DateTime.Now })); result = ExecuteTransaction(tran.sqlArray, tran.ParameterArray); if (result) { object objData = TemplateMsg_Miniapp.FootbathGetTemplateMessageData(orderInfo, SendTemplateMessageTypeEnum.足浴退款通知); TemplateMsg_Miniapp.SendTemplateMessage(orderInfo.UserId, SendTemplateMessageTypeEnum.足浴退款通知, TmpType.小程序足浴模板, objData); } return(result); } if (orderInfo.BuyMode == (int)miniAppBuyMode.微信支付) { CityMorders order = new CityMordersBLL().GetModel(orderInfo.OrderId); orderInfo.State = (int)MiniAppEntOrderState.退款中; if (order == null) { orderInfo.State = (int)MiniAppEntOrderState.退款失败; EntGoodsOrderBLL.SingleModel.Update(orderInfo, "State,outOrderDate,Remark"); return(result); } //微信支付 ReFundQueue reModel = new ReFundQueue { minisnsId = -5, money = orderInfo.BuyPrice, orderid = order.Id, traid = order.trade_no, addtime = DateTime.Now, note = "小程序足浴版退款", retype = 1 }; try { base.Add(reModel); result = EntGoodsOrderBLL.SingleModel.Update(orderInfo, "State,outOrderDate"); return(result); } catch (Exception ex) { log4net.LogHelper.WriteInfo(GetType(), $"{ex.Message} xxxxxxxxxxxxxxxx小程序足浴退款订单插入队列失败 ID={orderInfo.Id}"); } } return(result); }
/// <summary> /// 生成蜂鸟物流订单 /// </summary> /// <param name="rid">权限表ID</param> /// <param name="userinfo">用户信息</param> /// <param name="orderid">订单ID</param> /// <param name="goodcars">购物车</param> /// <param name="price">订单价格</param> /// <param name="receviename">收货人姓名</param> /// <param name="receviephone">收货人电话</param> /// <param name="address">收货人地址</param> /// <param name="lat">纬度</param> /// <param name="lnt">经度</param> /// <param name="ordertype">看枚举TmpType</param> /// <returns></returns> public string AddFNOrder(List <elegood> fngoods, DistributionApiModel model) { string msg = ""; FNStoreRelation relation = FNStoreRelationBLL.SingleModel.GetModelByRid(model.aid); if (relation != null) { msg = "请先配置蜂鸟门店"; return(msg); } FNStore fnstore = FNStoreBLL.SingleModel.GetModel(relation.fnstoreid); if (fnstore != null) { msg = "没有找到蜂鸟门店信息"; return(msg); } if (fngoods == null || fngoods.Count <= 0) { msg = "商品信息不能为空"; return(msg); } TransactionModel tran = new TransactionModel(); long timestamp = Convert.ToInt64(FNApi.SingleModel.GetTimeStamp()); string callback = FNApi._callbackurl; string orderno = model.userid + DateTime.Now.ToString("yyyyMMddHHmmss"); string storecode = fnstore.chain_store_code; float buyprice = model.buyprice / 100.0f; int goodcount = 0; //收货人信息 FNReceiverInfo reciverifo = new FNReceiverInfo() { receiver_name = model.accepterName, receiver_primary_phone = model.accepterTelePhone, receiver_address = model.address, receiver_longitude = model.lnt, receiver_latitude = model.lat, }; //门店信息 FNStoreInfo storeinfo = new FNStoreInfo() { transport_name = fnstore.chain_store_name, transport_address = fnstore.address, transport_longitude = Convert.ToDouble(fnstore.longitude), transport_latitude = Convert.ToDouble(fnstore.latitude), transport_tel = fnstore.contact_phone, }; //生成订单实体类对象 FNOrder data = new FNOrder(storecode, goodcount, callback, buyprice, timestamp, buyprice, orderno, model.remark, fngoods, reciverifo, storeinfo); tran.Add(base.BuildAddSql(data)); //订单与系统订单关联 FNOrderRelation orderrelation = new FNOrderRelation(); orderrelation.dataid = model.aid; orderrelation.orderid = model.orderid; orderrelation.ordertype = model.temptype; orderrelation.uniqueorderno = orderno; tran.Add(FNOrderRelationBLL.SingleModel.BuildAddSql(orderrelation)); if (!ExecuteTransactionDataCorect(tran.sqlArray, tran.ParameterArray)) { msg = "添加蜂鸟物流出错"; } return(msg); }