public ResultMessage Save() { TransactionHelper.BeginTransaction(); Load(); if (UserInformation == null) { return new ResultMessage() { Code = -1, Msg = "请重新登录" } } ; if (Account == null) { return new ResultMessage() { Code = -1, Msg = "账户异常" } } ; if (provinceId == 0 || cityId == 0 || string.IsNullOrWhiteSpace(detailedAddress) || string.IsNullOrWhiteSpace(recipients) || string.IsNullOrWhiteSpace(moblie)) { return new ResultMessage() { Code = -1, Msg = "请完善收货地址,收件人信息" } } ; var item = OrderService.GetOrderNo(orderNo); if (item == null) { return new ResultMessage() { Code = -1, Msg = "订单异常" } } ; if (item.orderState != OrderStates.awaitPay) { return new ResultMessage() { Code = -1, Msg = "订单已完成付款" } } ; if (payType != PayTypes.cashOnDelivery && payType != PayTypes.weChatPayment) { return new ResultMessage() { Code = -1, Msg = "支付方式异常" } } ; var point = Account.presentExp + Account.activatePoint; if (point < payPoint) { return new ResultMessage() { Code = -2, Msg = point.ToString() } } ; //积分不足 decimal payAmount = item.amount; //需要付款金额 decimal dkje = (Account.activatePoint + Account.presentExp) * PointRatio; //打算抵扣的金额 decimal dk = 0; //抵扣了多少金额 if (dkje >= item.amount) { dk = item.amount; } else { dk = dkje; } payAmount -= dk; item.payAmount = payAmount; decimal presentExp = 0; decimal activatePoint = 0; decimal dkPoint = 0; if (dk > 0) { dkPoint = dk / PointRatio; } item.point = dkPoint; if (item.payAmount == 0 || payType == PayTypes.cashOnDelivery) { if (dkPoint > 0) { if (Account.presentExp >= dkPoint) { presentExp = dkPoint; Account.presentExp -= dkPoint; } else { decimal cc = dkPoint - Account.presentExp; Account.activatePoint -= cc; activatePoint = cc; presentExp = Account.presentExp; Account.presentExp = 0; } OperationPointLog pointlog = new OperationPointLog(); pointlog.account = ""; pointlog.point = -dkPoint; pointlog.remark = string.Format("消费抵扣"); pointlog.submitTime = DateTime.Now; pointlog.userId = UserInformation.UserId; OperationPointLogService.Insert(pointlog); AccountService.Update(Account); } item.payState = PayStates.paid; item.orderState = OrderStates.paid; item.activatePoint = activatePoint; item.presentExp = presentExp; item.distributionstate = DistributionStates.unfilled; } item.UserAddressId = addessId; item.provinceId = provinceId; item.cityId = cityId; item.detailedAddress = detailedAddress; item.recipients = recipients; item.moblie = moblie; item.payType = payType; OrderService.Update(item); TransactionHelper.Commit(); return(new ResultMessage() { Code = 0, Msg = item.orderNo }); }
public ResultMsg Agree(int id) { var item = orderService.GetById(id); if (item != null && item.orderState == OrderStates.applyRefund) { var account = AccountService.GetByUserId(item.userId); if (account == null) { return new ResultMsg() { Code = -1, CodeText = "会员账户异常" } } ; JsApiPay jsApiPay = new JsApiPay(); jsApiPay.openid = account.openID; jsApiPay.total_fee = (int)(item.payAmount * 100); try { //var orderNo = WxPayApi.GenerateOutTradeNo(); if (jsApiPay.total_fee > 0 && !string.IsNullOrWhiteSpace(item.orderNo)) { WxPayData unifiedResult = jsApiPay.GetUnifiedTransferResult(item.orderNo, "", "订单取消"); if (!unifiedResult.GetValue("return_code").Equals("SUCCESS")) { WxPayAPI.Log.Error(this.GetType().ToString(), "UnifiedTransfer response error!"); return(new ResultMsg() { Code = -1, CodeText = "订单取消失败" }); } if (!unifiedResult.IsSet("mch_appid") || !unifiedResult.IsSet("mchid")) { WxPayAPI.Log.Error(this.GetType().ToString(), "UnifiedTransfer response error!"); return(new ResultMsg() { Code = -1, CodeText = "订单取消失败" }); } } item.orderState = OrderStates.refund; TransactionHelper.BeginTransaction(); if (item.point > 0) { account.presentExp += item.presentExp; account.activatePoint += item.activatePoint; OperationPointLog log = new OperationPointLog(); log.account = ""; log.point = item.point; log.remark = "订单取消"; log.submitTime = DateTime.Now; log.userId = account.userId; OperationPointLogService.Insert(log); AccountService.Update(account); } orderService.Update(item); TransactionHelper.Commit(); return(new ResultMsg() { Code = 0 }); } catch (Exception ex) { WxPayAPI.Log.Error(this.GetType().ToString(), ex.Message.ToString()); return(new ResultMsg() { Code = -1, CodeText = ex.Message.ToString() }); } } return(new ResultMsg() { Code = -1, CodeText = "订单不存在或者状态不正常" }); } }
public ResultMessage Save(int userId) { if (point <= 0) { return new ResultMessage() { Code = -1, Msg = "提现积分必须大于0" } } ; Account = AccountService.GetByUserId(userId); if (Account == null) { return new ResultMessage() { Code = -1, Msg = "请重新登录" } } ; if (Account.activatePoint < point) { return new ResultMessage() { Code = -1, Msg = "积分余额不足" } } ; if (string.IsNullOrWhiteSpace(Account.openID)) { return new ResultMessage() { Code = -1, Msg = "你还未授权,请重新登录" } } ; TransactionHelper.BeginTransaction(); Withdraw model = new Withdraw(); model.openId = Account.openID; model.point = point; model.state = WithdrawStates.notaudit; model.submitTime = DateTime.Now; model.userId = Account.userId; model.amount = point; WithdrawService.Insert(model); OperationPointLog log = new OperationPointLog(); log.account = "activatePoint"; log.point = -point; log.remark = "提现"; log.submitTime = DateTime.Now; log.userId = Account.userId; OperationPointLogService.Insert(log); Account.activatePoint -= point; //Account.withdrawPoint += point; AccountService.Update(Account); TransactionHelper.Commit(); return(new ResultMessage() { Code = 0 }); } } }