public AccountServiceResponse InnerExecute(Func <IAccountDealService, AccountServiceResponse> func) { try { var database = new Database("ecard"); using (var instance = new DatabaseInstance(database)) { instance.BeginTransaction(); IAccountDealService accountDealService = GetAccountDealService(instance); AccountServiceResponse rsp = func(accountDealService); if (rsp.Code == ResponseCode.Success) { instance.Commit(); } return(rsp); } } catch (Exception ex) { Log.Error("error", ex); return(new AccountServiceResponse(ResponseCode.SystemError) { CodeText = ex.Message }); } }
protected void Page_Load(object sender, EventArgs e) { WxPayAPI.Log.Info(this.GetType().ToString(), "--异步回调处理开始--"); Dictionary <string, string> data = GetRequestPost(); string notify_id = Request.Form["notify_id"]; //获取notify_id string sign = Request.Form["sign"]; //获取sign string SerialNo = Request.Form["out_trade_no"]; string TradeNo = Request.Form["trade_no"]; string price = Request.Form["buyer_pay_amount"]; string trade_status = Request.Form["trade_status"]; string gmt_payment = Request.Form["notify_time"]; WxPayAPI.Log.Info("Form:", AlipaySignature.GetSignContent(data)); if (notify_id == null || notify_id == "") { WxPayAPI.Log.Info("", "参数错误"); return; } Notify aliNotify = new Notify(); if (aliNotify.GetResponseTxt(notify_id) != "true") { WxPayAPI.Log.Info("", "参数错误"); return; } WxPayAPI.Log.Info("订单号:", SerialNo); bool flag = aliNotify.GetSignVeryfy(data, sign); //AlipaySignature.RSACheckV1(sPara, AlipayConfig.ALIPAY_PUBLIC_KEY, AlipayConfig.CHARSET, "RSA", false); // bool checkSign = AlipaySignature.RSACheckV2(data, AlipayConfig.ALIPAY_PUBLIC_KEY); if (flag) { WxPayAPI.Log.Info("", "验签成功"); _database = new Database("ecard"); using (var _databaseInstance = new DatabaseInstance(_database)) { var sql = "select * from fz_Orders where orderNo=@orderNo"; var item = new QueryObject <Ecard.Models.Order>(_databaseInstance, sql, new { orderNo = SerialNo }).FirstOrDefault(); if (item != null) { if (item.payState == Ecard.Models.PayStates.non_payment && item.orderState == Ecard.Models.OrderStates.awaitPay) { WxPayAPI.Log.Info("payAmount", item.payAmount.ToString()); WxPayAPI.Log.Info("price", price); decimal amount = 0; decimal.TryParse(price, out amount); WxPayAPI.Log.Info("amount", amount.ToString()); if (item.payAmount == amount) { WxPayAPI.Log.Info("金额", "成功"); _databaseInstance.BeginTransaction(); item.payState = Ecard.Models.PayStates.paid; item.orderState = Ecard.Models.OrderStates.paid; item.payType = PayTypes.Alipay; item.submitTime = DateTime.Now; _databaseInstance.Update(item, "fz_Orders"); var sql2 = "select * from fz_Accounts where accountId=@accountId"; var item2 = new QueryObject <Ecard.Models.Account>(_databaseInstance, sql2, new { accountId = item.userId }).FirstOrDefault(); if (item2 != null) { if (!string.IsNullOrWhiteSpace(item2.openID)) { var message = new Fz_Messages(); message.accountId = item2.accountId; message.openId = item2.openID; message.state = MessagesState.staySend; message.submitTime = DateTime.Now; message.keyword1 = item.orderNo; message.keyword2 = "已付款"; message.msgType = MsgType.orderState; _databaseInstance.Insert(message, "Fz_Messages"); } } _databaseInstance.Commit(); } } } } WxPayAPI.Log.Info("交易", "成功"); //交易成功 Response.Write("success"); } else { WxPayAPI.Log.Info("", "验签失败"); } }
public void Execute() { _instance.BeginTransaction(); // state preview month data var reportSetting = _instance.Query <ReportSetting>("select * from reportsettings where reportType='shopDeals'", null).FirstOrDefault() ?? new ReportSetting() { ReportType = "shopDeals", Value = "2009-1-1" }; var lastTime = DateTime.Parse(reportSetting.Value); while (lastTime.Date < DateTime.Now.Date) { var start = lastTime.Date; var end = lastTime.Date.AddDays(1); // 1, pay, 4 doneprepay, 3, cancel, 6, canceldoneprepay var sql = string.Format( @"select 0 ShopDealsReportId, ShopId, isnull((select sum(t1.amount) from deallogs t1 where t1.shopId = t.shopId and t1.state <> {0} and t1.dealtype = 1 and t1.submittime >= @start and t1.submittime < @end), 0.0) as PayAmount, isnull((select count(t1.amount) from deallogs t1 where t1.shopId = t.shopId and t1.state <> {0} and t1.dealtype = 1 and t1.submittime >= @start and t1.submittime < @end), 0.0) as PayCount, isnull((select sum(t1.amount) from deallogs t1 where t1.shopId = t.shopId and t1.state <> {0} and t1.dealtype = 4 and t1.submittime >= @start and t1.submittime < @end), 0.0) as DonePrepayAmount, isnull((select count(t1.amount) from deallogs t1 where t1.shopId = t.shopId and t1.state <> {0} and t1.dealtype = 4 and t1.submittime >= @start and t1.submittime < @end), 0.0) as DonePrepayCount, isnull((select sum(t1.amount) from deallogs t1 where t1.shopId = t.shopId and t1.state <> {0} and t1.dealtype = 2 and t1.submittime >= @start and t1.submittime < @end), 0.0) as CancelAmount, isnull((select count(t1.amount) from deallogs t1 where t1.shopId = t.shopId and t1.state <> {0} and t1.dealtype = 2 and t1.submittime >= @start and t1.submittime < @end), 0.0) as CancelCount, isnull((select sum(t1.amount) from deallogs t1 where t1.shopId = t.shopId and t1.state <> {0} and t1.dealtype = 6 and t1.submittime >= @start and t1.submittime < @end), 0.0) as CancelDonePrepayAmount, isnull((select count(t1.amount) from deallogs t1 where t1.shopId = t.shopId and t1.state <> {0} and t1.dealtype = 6 and t1.submittime >= @start and t1.submittime < @end), 0.0) as CancelDonePrepayCount, isnull((select count(*) from deallogs t1 where t1.shopId = t.shopId and t1.state = {0} and t1.submittime >= @start and t1.submittime < @end), 0) as UnPayCount, isnull((select sum(t1.amount) from shopdeallogs t1 where t1.shopId = t.shopId and t1.state <> {0} and t1.dealtype = {1} and t1.submittime >= @start and t1.submittime < @end), 0.0) as ShopDealLogDoneAmount, isnull((select sum(t1.amount) from shopdeallogs t1 where t1.shopId = t.shopId and t1.state <> {0} and t1.dealtype = {2} and t1.submittime >= @start and t1.submittime < @end), 0.0) as ShopDealLogChargeAmount, name shopName from shops t group by Name, ShopId", DealLogStates.Normal_, CashDealLogTypes.ShopDealLogDone, CashDealLogTypes.ShopDealLogCharging); var parameters = new { start = start, end = end, }; var reports = _instance.Query <ShopDeal>(sql, parameters).ToList(); reports.ForEach(x => x.SubmitDate = start); _instance.ExecuteNonQuery("delete ReportShopDeals where submitdate = @submitdate", new { submitdate = start }); foreach (var report in reports) { _instance.Insert(report, "ReportShopDeals"); } lastTime = (DateTime.Now.Date < end) ? DateTime.Now.Date : end; reportSetting.Value = lastTime.ToString("yyyy-MM-dd"); if (reportSetting.ReportSettingId == 0) { reportSetting.ReportSettingId = _instance.Insert(reportSetting, "reportsettings"); } else { _instance.Update(reportSetting, "reportsettings"); } } _instance.Commit(); }
public override void ProcessNotify() { WxPayData notifyData = GetNotifyData(); //检查支付结果中transaction_id是否存在 if (!notifyData.IsSet("transaction_id")) { //若transaction_id不存在,则立即返回结果给微信支付后台 WxPayData res = new WxPayData(); res.SetValue("return_code", "FAIL"); res.SetValue("return_msg", "支付结果中微信订单号不存在"); Log.Error(this.GetType().ToString(), "The Pay result is error : " + res.ToXml()); page.Response.Write(res.ToXml()); page.Response.End(); } string transaction_id = notifyData.GetValue("transaction_id").ToString(); //查询订单,判断订单真实性 if (!QueryOrder(transaction_id)) { //若订单查询失败,则立即返回结果给微信支付后台 WxPayData res = new WxPayData(); res.SetValue("return_code", "FAIL"); res.SetValue("return_msg", "订单查询失败"); Log.Error(this.GetType().ToString(), "订单查询失败 : " + res.ToXml()); page.Response.Write(res.ToXml()); page.Response.End(); } //查询订单成功 else { WxPayData res = new WxPayData(); try { Log.Debug(this.GetType().ToString(), "订单状态 : " + notifyData.GetValue("result_code").ToString()); if (notifyData.GetValue("result_code").ToString() == "SUCCESS") { string orderNo = notifyData.GetValue("out_trade_no").ToString(); Log.Debug(this.GetType().ToString(), "订单号 : " + orderNo); if (!string.IsNullOrWhiteSpace(orderNo)) { using (_databaseInstance = new DatabaseInstance(_database)) { _databaseInstance.BeginTransaction(); var sql = "select * from fz_Orders where orderNo=@orderNo"; var order = new QueryObject <Orders>(_databaseInstance, sql, new { orderNo = orderNo }).FirstOrDefault(); if (order != null && order.orderState == OrderStates.awaitPay) { order.orderState = OrderStates.paid; order.payTime = DateTime.Now; _databaseInstance.Update(order, "fz_Orders"); var list = orderDetialService.GetOrderNo(orderNo); if (list != null) { if (order.type == OrderTypes.ticket) { foreach (var item in list) { var admissionTicket = admissionTicketService.GetById(item.sourceId); for (var i = 0; i < item.num; i++) { var ticket = new Tickets(); ticket.AdmissionTicketId = admissionTicket.id; ticket.orderNo = orderNo; ticket.Price = item.amount; ticket.State = TicketsState.NotUse; ticket.UserId = order.userId; ticket.useScope = order.useScope; ticket.adultNum = admissionTicket.adultNum; ticket.BuyTime = DateTime.Now; ticket.childNum = admissionTicket.childNum; ticket.Code = string.Format("{0:yyyyMMddHHmmssffff}", DateTime.Now) + i.ToString() + order.userId.ToString(); ticket.ExpiredDate = DateTime.Now.Date; _databaseInstance.Insert(ticket, "Tickets"); } } } else if (order.type == OrderTypes.card) { string sqlSite = "select * from Sites"; var site = new QueryObject <Site>(_databaseInstance, sqlSite, null).FirstOrDefault(); string cardNo = ""; int minxCode = 1; Int32.TryParse(site.MixCode, out minxCode); int i = 1; while (true) { minxCode = minxCode + i; cardNo = string.Format("60000000{0}", minxCode.ToString().PadLeft(8, '0')); string sqlCard = "select * from Accounts where Name=@Name"; var card = new QueryObject <Account>(_databaseInstance, sqlCard, new { Name = cardNo }).FirstOrDefault(); if (card == null) { break; } i++; } int shopId = 0; if (!string.IsNullOrWhiteSpace(order.useScope)) { string sqlShop = "select * from shops where Name=@Name"; var shop = new QueryObject <Account>(_databaseInstance, sqlShop, new { Name = order.useScope }).FirstOrDefault(); if (shop != null) { shopId = shop.ShopId; } } var item = list.FirstOrDefault(); var accountType = _databaseInstance.GetById <AccountType>("AccountTypes", item.sourceId); var account = new Account(); account.AccountLevel = 0; account.AccountToken = "11111111"; account.AccountTypeId = accountType.AccountTypeId; account.Amount = 0; account.ExpiredDate = DateTime.Now.AddMonths(accountType.ExpiredMonths); account.Frequency = accountType.Frequency; account.FrequencyUsed = 0; account.LastDealTime = DateTime.Now; account.Name = cardNo; account.OpenTime = DateTime.Now; account.OwnerId = order.userId; account.ShopId = shopId; account.useScope = order.useScope; account.SaleAmount = order.payAmount; account.TotalTimes = accountType.Frequency; if (order.payAmount > 0 && accountType.Frequency > 0) { account.SinglePrice = Convert.ToInt32(order.payAmount / accountType.Frequency); } else { account.SinglePrice = 0; } account.State = AccountStates.Normal; _databaseInstance.Insert(account, "Accounts"); site.MixCode = minxCode.ToString(); _databaseInstance.Update(site, "Sites"); } } } _databaseInstance.Commit(); } } } res.SetValue("return_code", "SUCCESS"); res.SetValue("return_msg", "OK"); Log.Info(this.GetType().ToString(), "order query success : " + res.ToXml()); page.Response.Write(res.ToXml()); page.Response.End(); } catch (Exception ex) { if (!(ex is System.Threading.ThreadAbortException)) { res.SetValue("return_code", "FAIL"); res.SetValue("return_msg", "订单状态修改失败"); Log.Error(this.GetType().ToString(), "Order query failure : " + res.ToXml() + ex); page.Response.Write(res.ToXml()); page.Response.End(); } } finally { if (_databaseInstance != null) { _databaseInstance.Dispose(); } } } }
public bool Rebate(int orderId) { var Transaction = _databaseInstance.BeginTransaction(); //try //{ WxPayAPI.Log.Debug("Ecard.SqlServices.SqlRebateService.Rebate", "开始返利"); var order = _databaseInstance.GetById <Order>("fz_Orders", orderId); if (order == null) { return(false); } if (order.orderState != OrderStates.complete) { return(false); } string sql = "select * from fz_OrderDetails where OrderId=@OrderId"; var orderDeal = new QueryObject <OrderDetail>(_databaseInstance, sql, new { OrderId = orderId }); if (orderDeal == null) { return(false); } if (orderDeal.ToList().Count <= 0) { return(false); } var account = IAccountService.GetById(order.userId); if (account == null) { return(false); } Account one = IAccountService.GetById(account.salerId); Account two = null; Account three = null; if (one != null) { //WxPayAPI.Log.Debug("Ecard.SqlServices.SqlRebateService.Rebate", "第一层:"+one.name); two = IAccountService.GetById(one.salerId); } if (two != null) { three = IAccountService.GetById(two.salerId); } var site = ISiteService.Query(null).FirstOrDefault(); if (site == null) { return(false); } foreach (var item in orderDeal.ToList()) { if (one != null) { var oneAmount = item.amount * site.OneRebate; // WxPayAPI.Log.Debug("Ecard.SqlServices.SqlRebateService.Rebate", "第一层金额:" + oneAmount.ToString()); if (oneAmount > 0) { one.amount += oneAmount; var fzRebate = new fz_Rebate(); fzRebate.accountId = one.accountId; fzRebate.orderDetailId = item.orderDetailId; fzRebate.payAmount = item.amount; fzRebate.reateAmount = oneAmount; fzRebate.reateRatio = site.OneRebate; fzRebate.state = RebateState.normal; fzRebate.submitTime = DateTime.Now; fzRebate.type = RebateType.one; fzRebate.rebateId = _databaseInstance.Insert(fzRebate, "fz_Rebate"); if (fzRebate.accountId > 0) { var operationAmountLog = new fz_OperationAmountLogs(); operationAmountLog.amount = oneAmount; operationAmountLog.source = fzRebate.rebateId.ToString(); operationAmountLog.userId = fzRebate.accountId; operationAmountLog.type = OperationAmountType.Income; operationAmountLog.category = OperationAmountCategory.rebate; operationAmountLog.submitTime = DateTime.Now; if (_databaseInstance.Insert(operationAmountLog, "fz_OperationAmountLogs") <= 0) { return(false); } } else { return(false); } //WxPayAPI.Log.Debug("Ecard.SqlServices.SqlRebateService.Rebate", "第一层返利成功:" + fzRebate.rebateId.ToString()); } } if (two != null) { var twoAmount = item.amount * site.TwoRebate; if (twoAmount > 0) { two.amount += twoAmount; var fzRebate = new fz_Rebate(); fzRebate.accountId = two.accountId; fzRebate.orderDetailId = item.orderDetailId; fzRebate.payAmount = item.amount; fzRebate.reateAmount = twoAmount; fzRebate.reateRatio = site.TwoRebate; fzRebate.state = RebateState.normal; fzRebate.submitTime = DateTime.Now; fzRebate.type = RebateType.two; fzRebate.rebateId = _databaseInstance.Insert(fzRebate, "fz_Rebate"); if (fzRebate.accountId > 0) { var operationAmountLog = new fz_OperationAmountLogs(); operationAmountLog.amount = twoAmount; operationAmountLog.source = fzRebate.rebateId.ToString(); operationAmountLog.userId = fzRebate.accountId; operationAmountLog.type = OperationAmountType.Income; operationAmountLog.category = OperationAmountCategory.rebate; operationAmountLog.submitTime = DateTime.Now; if (_databaseInstance.Insert(operationAmountLog, "fz_OperationAmountLogs") <= 0) { return(false); } } else { return(false); } } } if (three != null) { var threeAmount = item.amount * site.ThreeRebate; if (threeAmount > 0) { three.amount += threeAmount; var fzRebate = new fz_Rebate(); fzRebate.accountId = three.accountId; fzRebate.orderDetailId = item.orderDetailId; fzRebate.payAmount = item.amount; fzRebate.reateAmount = threeAmount; fzRebate.reateRatio = site.ThreeRebate; fzRebate.state = RebateState.normal; fzRebate.submitTime = DateTime.Now; fzRebate.type = RebateType.three; fzRebate.rebateId = _databaseInstance.Insert(fzRebate, "fz_Rebate"); if (fzRebate.accountId > 0) { var operationAmountLog = new fz_OperationAmountLogs(); operationAmountLog.amount = threeAmount; operationAmountLog.source = fzRebate.rebateId.ToString(); operationAmountLog.userId = fzRebate.accountId; operationAmountLog.type = OperationAmountType.Income; operationAmountLog.category = OperationAmountCategory.rebate; operationAmountLog.submitTime = DateTime.Now; if (_databaseInstance.Insert(operationAmountLog, "fz_OperationAmountLogs") <= 0) { return(false); } } else { return(false); } } } item.IsRebate = true; if (_databaseInstance.Update(item, "fz_OrderDetails") <= 0) { return(false); } } if (one != null) { _databaseInstance.Update(one, "fz_Accounts"); } if (two != null) { _databaseInstance.Update(two, "fz_Accounts"); } if (three != null) { _databaseInstance.Update(three, "fz_Accounts"); } Transaction.Commit(); Transaction.Dispose(); return(true); //} //catch (Exception ex) //{ // ILog4netService.Insert(ex); // Transaction.Rollback(); // return false; //} //finally //{ // Transaction.Dispose(); //} }
public override void ProcessNotify() { WxPayData notifyData = GetNotifyData(); //检查支付结果中transaction_id是否存在 if (!notifyData.IsSet("transaction_id")) { //若transaction_id不存在,则立即返回结果给微信支付后台 WxPayData res = new WxPayData(); res.SetValue("return_code", "FAIL"); res.SetValue("return_msg", "支付结果中微信订单号不存在"); Log.Error(this.GetType().ToString(), "The Pay result is error : " + res.ToXml()); page.Response.Write(res.ToXml()); page.Response.End(); } string transaction_id = notifyData.GetValue("transaction_id").ToString(); //查询订单,判断订单真实性 if (!QueryOrder(transaction_id)) { //若订单查询失败,则立即返回结果给微信支付后台 WxPayData res = new WxPayData(); res.SetValue("return_code", "FAIL"); res.SetValue("return_msg", "订单查询失败"); Log.Error(this.GetType().ToString(), "订单查询失败 : " + res.ToXml()); page.Response.Write(res.ToXml()); page.Response.End(); } //查询订单成功 else { WxPayData res = new WxPayData(); try { Log.Debug(this.GetType().ToString(), "订单状态 : " + notifyData.GetValue("result_code").ToString()); if (notifyData.GetValue("result_code").ToString() == "SUCCESS") { string orderNo = notifyData.GetValue("out_trade_no").ToString(); Log.Debug(this.GetType().ToString(), "订单号 : " + orderNo); if (!string.IsNullOrWhiteSpace(orderNo)) { using (_databaseInstance = new DatabaseInstance(_database)) { var sql = "select * from fz_Orders where orderNo=@orderNo"; var item = new QueryObject <Ecard.Models.Order>(_databaseInstance, sql, new { orderNo = orderNo }).FirstOrDefault(); if (item != null) { #region 商城订单 if (item.payState == Ecard.Models.PayStates.non_payment && item.orderState == Ecard.Models.OrderStates.awaitPay) { decimal amount = 0; if (int.Parse(notifyData.GetValue("total_fee").ToString()) > 0) { amount = decimal.Parse(notifyData.GetValue("total_fee").ToString()) / 100; } if (item.payAmount == amount) { _databaseInstance.BeginTransaction(); item.payState = Ecard.Models.PayStates.paid; item.orderState = Ecard.Models.OrderStates.paid; item.payType = PayTypes.weChatPayment; item.submitTime = DateTime.Now; _databaseInstance.Update(item, "fz_Orders"); //var sql2 = "select * from fz_Accounts where accountId=@accountId"; //var item2 = new QueryObject<Ecard.Models.Account>(_databaseInstance, sql2, new { accountId = item.userId }).FirstOrDefault(); //if (item2 !=null) //{ // if (!string.IsNullOrWhiteSpace(item2.openID)) // { // var message = new Fz_Messages(); // message.accountId = item2.accountId; // message.openId = item2.openID; // message.state = MessagesState.staySend; // message.submitTime = DateTime.Now; // message.keyword1 = item.orderNo; // message.keyword2 = "已付款"; // message.msgType = MsgType.orderState; // _databaseInstance.Insert(message, "Fz_Messages"); // } //} _databaseInstance.Commit(); Log.Debug(this.GetType().ToString(), "开始返利 : " + orderNo); if (item.orderType == OrderType.normal) { IRebateService.Rebate3(item.orderId); } Log.Debug(this.GetType().ToString(), "返利结束 : " + orderNo); } else { res.SetValue("return_code", "FAIL"); res.SetValue("return_msg", "金额错误,支付金额于订单金额不一致"); Log.Error(this.GetType().ToString(), "订单金额失败 : " + res.ToXml()); page.Response.Write(res.ToXml()); page.Response.End(); } } #endregion } else { #region payorder 订单 var sqlPayOrder = "select * from PayOrder where orderNo=@orderNo"; var payOrder = new QueryObject <Ecard.Models.PayOrder>(_databaseInstance, sqlPayOrder, new { orderNo = orderNo }).FirstOrDefault(); if (payOrder != null) { if (payOrder.orderState == PayOrderStates.awaitPay) { _databaseInstance.BeginTransaction(); payOrder.orderState = PayOrderStates.paid; payOrder.payTime = DateTime.Now; _databaseInstance.Update(payOrder, "PayOrder"); var account = IAccountService.GetByUserId(payOrder.userId); if (account != null) { int grade = -1; if (payOrder.item == PayOrderItems.member) { grade = AccountGrade.Member; } else if (payOrder.item == PayOrderItems.shopowner) { grade = AccountGrade.Manager; } else if (payOrder.item == PayOrderItems.shopkeeper) { grade = AccountGrade.GoldMedalManager; } if (account.grade < grade) { account.grade = grade; } _databaseInstance.Update(account, "fz_Accounts"); } _databaseInstance.Commit(); if (payOrder.orderType == PayOrderTypes.MmeberUp) { Log.Debug(this.GetType().ToString(), "开始推荐返利 : " + orderNo); IRebateService.Rebate4(payOrder.Id); Log.Debug(this.GetType().ToString(), "返利推荐结束 : " + orderNo); } } } #endregion } } } } res.SetValue("return_code", "SUCCESS"); res.SetValue("return_msg", "OK"); Log.Info(this.GetType().ToString(), "order query success : " + res.ToXml()); page.Response.Write(res.ToXml()); page.Response.End(); } catch (Exception ex) { if (!(ex is System.Threading.ThreadAbortException)) { res.SetValue("return_code", "FAIL"); res.SetValue("return_msg", "订单状态修改失败"); Log.Error(this.GetType().ToString(), "Order query failure : " + res.ToXml() + ex); page.Response.Write(res.ToXml()); page.Response.End(); } } } }
public void hd(string orderNo) { _databaseInstance.BeginTransaction(); var sql = "select * from fz_Orders where orderNo=@orderNo"; var order = new QueryObject <Orders>(_databaseInstance, sql, new { orderNo = orderNo }).FirstOrDefault(); if (order != null && order.orderState == OrderStates.awaitPay) { order.orderState = OrderStates.paid; order.payTime = DateTime.Now; _databaseInstance.Update(order, "fz_Orders"); var list = orderDetialService.GetOrderNo(orderNo); if (list != null) { if (order.type == OrderTypes.ticket) { foreach (var item in list) { var admissionTicket = admissionTicketService.GetById(item.sourceId); for (var i = 0; i < item.num; i++) { var ticket = new Tickets(); ticket.AdmissionTicketId = admissionTicket.id; ticket.orderNo = orderNo; ticket.Price = item.amount; ticket.State = TicketsState.NotUse; ticket.UserId = order.userId; ticket.useScope = order.useScope; ticket.adultNum = admissionTicket.adultNum; ticket.BuyTime = DateTime.Now; ticket.childNum = admissionTicket.childNum; ticket.Code = string.Format("{0:yyyyMMddHHmmssffff}", DateTime.Now) + i.ToString() + order.userId.ToString(); ticket.ExpiredDate = DateTime.Now.Date; _databaseInstance.Insert(ticket, "Tickets"); } } } else if (order.type == OrderTypes.card) { string sqlSite = "select * from Sites"; var site = new QueryObject <Site>(_databaseInstance, sqlSite, null).FirstOrDefault(); string cardNo = ""; int minxCode = 1; Int32.TryParse(site.MixCode, out minxCode); int i = 1; while (true) { minxCode = minxCode + i; cardNo = string.Format("60000000{0}", minxCode.ToString().PadLeft(8, '0')); string sqlCard = "select * from Accounts where Name=@Name"; var card = new QueryObject <Account>(_databaseInstance, sqlCard, new { Name = cardNo }).FirstOrDefault(); if (card == null) { break; } i++; } int shopId = 0; if (!string.IsNullOrWhiteSpace(order.useScope)) { string sqlShop = "select * from shops where Name=@Name"; var shop = new QueryObject <Account>(_databaseInstance, sqlShop, new { Name = order.useScope }).FirstOrDefault(); if (shop != null) { shopId = shop.ShopId; } } var item = list.FirstOrDefault(); var accountType = _databaseInstance.GetById <AccountType>("AccountTypes", item.sourceId); var account = new Account(); account.AccountLevel = 0; account.AccountToken = "11111111"; account.AccountTypeId = accountType.AccountTypeId; account.Amount = 0; account.ExpiredDate = DateTime.Now.AddMonths(accountType.ExpiredMonths); account.Frequency = accountType.Frequency; account.FrequencyUsed = 0; account.LastDealTime = DateTime.Now; account.Name = cardNo; account.OpenTime = DateTime.Now; account.OwnerId = order.userId; account.ShopId = shopId; account.useScope = order.useScope; account.SaleAmount = order.payAmount; account.TotalTimes = accountType.Frequency; if (order.payAmount > 0 && accountType.Frequency > 0) { account.SinglePrice = Convert.ToInt32(order.payAmount / accountType.Frequency); } else { account.SinglePrice = 0; } account.State = AccountStates.Normal; _databaseInstance.Insert(account, "Accounts"); site.MixCode = minxCode.ToString(); _databaseInstance.Update(site, "Sites"); } } } _databaseInstance.Commit(); }