474 lines
19 KiB
C#
474 lines
19 KiB
C#
using CRM.Core.DTO.Ord;
|
||
using Ninject;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Web.Mvc;
|
||
using WX.CRM.Common;
|
||
using WX.CRM.Common.Layui;
|
||
using WX.CRM.Common.WxPay;
|
||
using WX.CRM.IBLL.Res;
|
||
using WX.CRM.IBLL.Util;
|
||
using WX.CRM.IBLL.Wx;
|
||
using WX.CRM.WebHelper;
|
||
|
||
namespace WX.CRM.WEB.Controllers.WeiXin
|
||
{
|
||
public class OrderPayController : BaseController
|
||
{
|
||
[Inject]
|
||
public ISecurityHelper sHelper { get; set; }
|
||
[Inject]
|
||
public ICACHE_Q _CacheQ { get; set; }
|
||
[Inject]
|
||
public IWX_SZZYORDERPAY _orderPay { get; set; }
|
||
[Inject]
|
||
public IWX_SZZYORDER wx_SzzyOrder_BL { get; set; }
|
||
[Inject]
|
||
public IRES_CUSTOMER_Q _customerQ { get; set; }
|
||
[Inject]
|
||
public IWX_SZZYORDERDEPOSIT _orderDepoist { get; set; }
|
||
[Inject]
|
||
public IWX_SZZYORDER _order { get; set; }
|
||
|
||
public NativePay _nativePay = new NativePay();
|
||
|
||
[HttpGet]
|
||
[AuthorizeRedirect(Roles = InitRights.CONST_订单支付记录)]
|
||
public ActionResult Index()
|
||
{
|
||
Pager pager = new Pager() { page = 1, rows = 20 };
|
||
string tableId = "tablist";
|
||
Table tab = new Table(tableId);
|
||
tab.AddHiddenHeadCol("ID", "ID");
|
||
tab.AddHeadCol("ORDERID", "", "订单ID");
|
||
tab.AddHeadCol("PAYTYPENAME", "", "支付类型");
|
||
tab.AddHeadCol("PAYDATE", "", "到账时间");
|
||
tab.AddHeadCol("PAYPRICE", "", "使用金额");
|
||
tab.AddHeadCol("depositPrice", "", "流水金额");
|
||
tab.AddHeadCol("PAYNO", "", "流水号");
|
||
tab.AddHeadCol("PAYNAME", "", "付款人姓名");
|
||
tab.AddHeadCol("REMARK", "", "备注");
|
||
tab.AddHeadCol("AUDITSTATUS", "", "审核状态");
|
||
tab.AddHeadCol("AUDITTIME", "", "审核时间");
|
||
tab.AddHeadCol("REJECTREMARK", "", "说明");
|
||
//tab.AddHeadCol("", "", "操作");
|
||
tab.AddHeadRow();
|
||
ViewBag.gridTable = tab.GetHead() + Pagination.GetPage(pager, tableId, "20,50,100");
|
||
return View();
|
||
}
|
||
|
||
[HttpPost]
|
||
[AuthorizeRedirect(Roles = InitRights.CONST_订单支付记录)]
|
||
public JsonResult Index(Pager pager, string columns, OrderPayUseListReqDto dto)
|
||
{
|
||
dto.channel = int.Parse(Utility.GetSettingOrNullByKey("Channel"));
|
||
var ret = _orderDepoist.GetCorePayList(pager, dto);
|
||
Table tab = new Table("tablist");
|
||
ToolBar tool = new ToolBar();
|
||
string[] toolbtn = new ToolButtonView().ToolButtonRight(InitRights.订单支付记录, userRightId);
|
||
tool.AllowButton(toolbtn);
|
||
ViewBag.ToolBar = tool;
|
||
|
||
Table table = new Table(columns, true);
|
||
if (ret.result)
|
||
{
|
||
if (ret.infolist.Count > 0)
|
||
{
|
||
foreach (var model in ret.infolist)
|
||
{
|
||
table.AddCol(model.orderid);
|
||
table.AddCol(model.paytypename);
|
||
table.AddCol(model.paydate);
|
||
if (model.auditstatus == 1)
|
||
{
|
||
table.AddCol(model.payprice);
|
||
}
|
||
else
|
||
{
|
||
table.AddCol("");
|
||
}
|
||
table.AddCol(model.depositPrice);
|
||
table.AddCol(model.payno);
|
||
table.AddCol(model.payname);
|
||
table.AddCol(model.remark);
|
||
if (model.auditstatus == 1)
|
||
{
|
||
table.AddCol("color:green", "", "已审核");
|
||
}
|
||
else if (model.auditstatus == -1)
|
||
{
|
||
table.AddCol("color:red", "", "驳回");
|
||
}
|
||
else
|
||
{
|
||
table.AddCol("未审核");
|
||
}
|
||
table.AddCol(model.audittime);
|
||
table.AddCol(model.rejectremark);
|
||
table.AddRow();
|
||
}
|
||
//table.AddCol("合计:");
|
||
//table.AddCol("");
|
||
//table.AddCol("");
|
||
//table.AddCol(ret.sumInfo.usePriceSum);
|
||
//table.AddCol("");
|
||
//table.AddCol("");
|
||
//table.AddCol("");
|
||
//table.AddCol("");
|
||
//table.AddCol("");
|
||
//table.AddCol("");
|
||
//table.AddCol("");
|
||
//table.AddRow();
|
||
}
|
||
}
|
||
else
|
||
{
|
||
table.AddHiddenCol("");
|
||
table.AddErrCol("加载错误");
|
||
table.AddRow();
|
||
}
|
||
var json = new
|
||
{
|
||
totalPages = ret.pageinfo.totalPages,
|
||
totalRows = ret.pageinfo.count,
|
||
rowsList = table.GetRows()
|
||
};
|
||
return Json(json, JsonRequestBehavior.AllowGet);
|
||
}
|
||
|
||
[AuthorizeRedirect(Roles = InitRights.CONST_订单支付记录)]
|
||
public ActionResult Export(OrderPayUseListReqDto dto)
|
||
{
|
||
|
||
dto.channel = int.Parse(Utility.GetSettingOrNullByKey("Channel"));
|
||
var ret = _orderDepoist.GetCorePayList(new Pager { page = 1, rows = int.MaxValue }, dto);
|
||
|
||
string checkedFilds = PageRequest.GetQueryString("checkedFilds").Replace("[]", "");
|
||
string checkedTitles = PageRequest.GetQueryString("checkedTitles");
|
||
if (ret.result)
|
||
{
|
||
return File(ExcelHelper.ExportListModelToExcel<OrderPayUseListRspDto>(ret.infolist, "支付申请列表", 10000, checkedFilds, checkedTitles, DataFormart), "application/ms-excel", PageRequest.GetDlownLoadName("支付申请列表.xls"));
|
||
}
|
||
else
|
||
{
|
||
return Json(new { message = "数据获取错误!" }, JsonRequestBehavior.AllowGet);
|
||
}
|
||
|
||
}
|
||
|
||
|
||
[HttpGet]
|
||
public ActionResult List(int orderId)
|
||
{
|
||
var order = _order.Get(p => p.ORDERID == orderId);
|
||
|
||
//var customerId = _customerQ.getResCustomerByResId(order.RESID).CUSTOMERID;
|
||
//string[] resids = _customerQ.GetAllResidByCustomerId(customerId);
|
||
//var orderDepositList = _orderDepoist.GetList(p => resids.Contains(p.RESID) && p.AUDITSTATUS == 1 && p.ISUSE == 0);
|
||
//ViewBag.OrderDepositList = orderDepositList;
|
||
|
||
ViewBag.OrderStatus = order.ORDERSTATUS;
|
||
string umid = _customerQ.getResCustomerByResId(order.RESID).UMID;
|
||
var ret = _orderDepoist.GetCoreDepositLastPay(new LastPriceReqDto() { resid = umid, channel = int.Parse(Utility.GetSettingOrNullByKey("Channel")) });
|
||
ViewBag.Ret = ret;
|
||
|
||
return View();
|
||
}
|
||
|
||
[HttpPost]
|
||
public JsonResult List(int orderId, string act)
|
||
{
|
||
|
||
OrderPayUseListReqDto dto = new OrderPayUseListReqDto() { orderid = orderId };
|
||
dto.channel = int.Parse(Utility.GetSettingOrNullByKey("Channel"));
|
||
var ret = _orderDepoist.GetCorePayList(new Pager { page = 1, rows = int.MaxValue }, dto);
|
||
|
||
var data = new LayuiData<OrderPayUseListRspDto>()
|
||
{
|
||
msg = "数据加载成功!",
|
||
count = 0,
|
||
code = 0,
|
||
data = ret.infolist
|
||
};
|
||
return Json(data, JsonRequestBehavior.AllowGet);
|
||
}
|
||
/// <summary>
|
||
/// 我的订单=》关联订单添加 二维码支付
|
||
/// </summary>
|
||
/// <param name="orderId"></param>
|
||
/// <returns></returns>
|
||
[HttpGet]
|
||
public ActionResult Add(int orderId)
|
||
{
|
||
var order = wx_SzzyOrder_BL.Get(p => p.ORDERID == orderId);
|
||
var needpay = (order.NEEDPAY ?? 0) - (order.ARRIVALPAY ?? 0);//需要的金额
|
||
var model = new OrderPayDto
|
||
{
|
||
orderid = Convert.ToInt32(order.ORDERID),
|
||
needpay = needpay < 0 ? 0 : needpay
|
||
};
|
||
|
||
var deptList = _CacheQ.GetList_SalesDepartMent().Where(p => p.CHANNELDEF != null);
|
||
var selectList = new List<SelectListItem>();
|
||
foreach (var item in deptList)
|
||
{
|
||
selectList.Add(new SelectListItem() { Text = item.DEPTNAME, Value = item.SALEDEPTCODE });
|
||
}
|
||
ViewBag.DeptList = selectList;
|
||
|
||
var quota = _CacheQ.GetValue_Parameter("QuoTa");
|
||
ViewBag.QuoTa = quota;
|
||
return View(model);
|
||
}
|
||
|
||
public ActionResult Bank(int orderId)
|
||
{
|
||
var order = wx_SzzyOrder_BL.Get(p => p.ORDERID == orderId);
|
||
var model = new OrderPayDto
|
||
{
|
||
orderid = Convert.ToInt32(order.ORDERID),
|
||
needpay = order.NEEDPAY.GetValueOrDefault()
|
||
};
|
||
|
||
var deptList = _CacheQ.GetList_SalesDepartMent().Where(p => p.CHANNELDEF != null);
|
||
var selectList = new List<SelectListItem>();
|
||
foreach (var item in deptList)
|
||
{
|
||
selectList.Add(new SelectListItem() { Text = item.DEPTNAME, Value = item.SALEDEPTCODE });
|
||
}
|
||
ViewBag.DeptList = selectList;
|
||
|
||
return View(model);
|
||
}
|
||
|
||
//[HttpPost]
|
||
//public JsonResult Add(OrderPayDto dto)
|
||
//{
|
||
// try
|
||
// {
|
||
// //LogHelper.Info(dto.ToJson());
|
||
// if (!ModelState.IsValid)
|
||
// {
|
||
// return JsonHandler.ManageMessage("参数有误,请确认!", false);
|
||
// }
|
||
// var noId = string.Empty;
|
||
// if (dto.paytype == 1)
|
||
// {
|
||
// var alpayId = _CacheQ.GetValue_Parameter("alpayId");
|
||
// if (string.IsNullOrEmpty(alpayId))
|
||
// {
|
||
// return JsonHandler.ManageMessage("请先配置商户号!", false);
|
||
// }
|
||
// noId = alpayId;
|
||
// }
|
||
// else
|
||
// {
|
||
// var mchId = _CacheQ.GetValue_Parameter("mchId");
|
||
// if (string.IsNullOrEmpty(mchId))
|
||
// {
|
||
// return JsonHandler.ManageMessage("请先配置商户号!", false);
|
||
// }
|
||
// noId = mchId;
|
||
// }
|
||
|
||
// if (dto.paytype != 3)
|
||
// {
|
||
// //如果不是银行转账
|
||
// dto.tradeno = WxPayApi.GenerateTradePayNo("P", noId);
|
||
// }
|
||
// var orderPay = new WX_SZZYORDERPAY()
|
||
// {
|
||
// ID = new SEQUENCES_BL().Seq_base_get(),
|
||
// ORDERID = dto.orderid,
|
||
// NEEDPAY = dto.needpay,
|
||
// PAYTYPE = dto.paytype,
|
||
// PAYTYPENAME = GetPayTypeName(dto.paytype),
|
||
// PAYDATE = dto.paydate,
|
||
// PAYPRICE = dto.payprice,
|
||
// PAYNAME = dto.payname,
|
||
// REMARK = dto.remark,
|
||
// AUDITSTATUS = 0,
|
||
// CTIME = DateTime.Now,
|
||
// PAYNO = string.IsNullOrEmpty(dto.payno) ? string.Empty : dto.payno.Trim(),
|
||
// TRADENO = dto.tradeno,
|
||
// //SID = decimal.Parse(retmessage.retmsg)
|
||
// };
|
||
|
||
// dto.companycode = Utility.GetSettingOrNullByKey("DataClientCode");
|
||
// var url = _CacheQ.GetValue_Parameter(Parameter.Core_ZxdService_OrderPay);
|
||
// var json = sHelper.createSignEncodingStr(dto.ToJson(), SecurityHelper.OrderClientIdKey);
|
||
|
||
// string retmsg = Utility.PostData(url + "?" + json, Encoding.UTF8);
|
||
// retmsg = sHelper.decyptData(SecurityHelper.OrderClientIdKey, retmsg);
|
||
// var retmessage = WebHelper.JsonHelper.JsonDivertToObj<retMsg>(retmsg);
|
||
|
||
// if (retmessage.result)
|
||
// {
|
||
// orderPay.SID = decimal.Parse(retmessage.retmsg);
|
||
|
||
// _orderPay.Add(orderPay);
|
||
|
||
// return JsonHandler.ManageMessage(orderPay.ID.ToString(), true);
|
||
// }
|
||
// else
|
||
// {
|
||
// return JsonHandler.ManageMessage("提交失败,请稍后重试!", false);
|
||
// }
|
||
// }
|
||
// catch (Exception ex)
|
||
// {
|
||
// LogHelper.Error(ex.ToString());
|
||
// return JsonHandler.ManageMessage("出错了,请稍后再试!", false);
|
||
// }
|
||
//}
|
||
|
||
//public FileResult GetQRCode(int id)
|
||
//{
|
||
// var webPath = "~/UploadFile/PayQRCode/";
|
||
// var okPath = webPath + "ok.png";
|
||
// var gqPath = webPath + "gq.png";
|
||
|
||
|
||
// //byte[] bytes = QRCodeHelper.Create(url);
|
||
// var payInfo = _orderPay.Get(p => p.ID == id);
|
||
// if (payInfo.AUDITSTATUS == 1)
|
||
// {
|
||
// return File(okPath, @"image/jpeg");
|
||
// }
|
||
// if (!string.IsNullOrEmpty(payInfo.QRCODE) && payInfo.QRCODETIME > DateTime.Now)
|
||
// {
|
||
// return File(payInfo.QRCODE, @"image/jpeg");
|
||
// }
|
||
// else if (!string.IsNullOrEmpty(payInfo.QRCODE) && payInfo.QRCODETIME <= DateTime.Now)
|
||
// {
|
||
// return File(gqPath, @"image/jpeg");
|
||
// }
|
||
|
||
// var bytes = GenQRCode(id);
|
||
|
||
// return File(bytes, @"image/jpeg");
|
||
//}
|
||
//[HttpPost]
|
||
//public JsonResult Gen(int id)
|
||
//{
|
||
// var ret = GenQRCode(id);
|
||
// if (ret == null)
|
||
// {
|
||
// return Json(new { result = false }, JsonRequestBehavior.AllowGet);
|
||
// }
|
||
// return Json(new { result = true }, JsonRequestBehavior.AllowGet);
|
||
//}
|
||
|
||
//private byte[] GenQRCode(int id)
|
||
//{
|
||
// try
|
||
// {
|
||
// var webPath = "~/UploadFile/PayQRCode/";
|
||
// var dicPath = Server.MapPath(webPath);
|
||
// var fileName = Guid.NewGuid() + ".jpg";
|
||
// var webFilePaht = webPath + fileName;
|
||
// var filePath = dicPath + fileName;
|
||
|
||
// var payInfo = _orderPay.Get(p => p.ID == id);
|
||
// LogHelper.Info("payInfo.TRADENO:" + payInfo.TRADENO);
|
||
// var order = wx_SzzyOrder_BL.Get(p => p.ORDERID == payInfo.ORDERID);
|
||
// var url = string.Empty;
|
||
// var paytype = string.Empty;
|
||
// if (payInfo.PAYTYPE == 1)
|
||
// {
|
||
// paytype = "ali";
|
||
|
||
// var alpayId = _CacheQ.GetValue_Parameter("alpayId");
|
||
// if (string.IsNullOrEmpty(alpayId))
|
||
// {
|
||
// return null;
|
||
// }
|
||
|
||
// var client = new DefaultAopClient(AliPayConfig.gatewayUrl, AliPayConfig.app_id(alpayId), AliPayConfig.private_key(alpayId), "json", "1.0", AliPayConfig.sign_type);
|
||
// var request = new AlipayTradePrecreateRequest();
|
||
// request.SetNotifyUrl(AliPayConfig.notify_url);
|
||
// request.BizContent = "{" +
|
||
// "\"out_trade_no\":\"" + payInfo.TRADENO + "\"," +
|
||
// "\"total_amount\":" + payInfo.PAYPRICE + "," +
|
||
// "\"subject\":\"" + order.SUBPRODUCTNAME + "\"," +
|
||
// "\"enable_pay_channels\":\"balance,bankPay,debitCardExpress\"" +
|
||
// " }";
|
||
// LogHelper.Info("aliPayRqeust:" + request.ToJson());
|
||
// var response = client.Execute(request);
|
||
|
||
// LogHelper.Info("aliPayUrl:" + response.ToJson());
|
||
|
||
// url = response.QrCode;
|
||
// }
|
||
// else
|
||
// {
|
||
// paytype = "wx";
|
||
|
||
// var mchId = _CacheQ.GetValue_Parameter("mchId");
|
||
// if (string.IsNullOrEmpty(mchId))
|
||
// {
|
||
// return null;
|
||
// }
|
||
// //微信支付url生成,目前使用
|
||
|
||
|
||
// //url = _nativePay.GetPayQRCode(order.SUBPRODUCTID.ToString(), payInfo.TRADENO, order.SUBPRODUCTNAME, (double)payInfo.PAYPRICE * 100, mchId);//被禁用了
|
||
|
||
|
||
// string myurl = _CacheQ.GetValue_Parameter(Parameter.uppay_h5url);// "https://yigohouse.51vip.biz/unifiedpay/wxpay/${dgAccessCode}/${payData}/i";
|
||
// myurl = myurl.Replace("${dgAccessCode}", ConfigurationManager.AppSettings["wx_pay_interface_account"]);
|
||
// var time = DateTimeTool.ConvertDateTimeInt(DateTime.Now.AddHours(2));//两个小时候过期
|
||
// var option = new { description = order.SUBPRODUCTNAME, out_trade_no = payInfo.TRADENO, time_expire = time, total_amount = payInfo.PAYPRICE*100, currency = "CNY", pay_source = Convert.ToInt32(ConfigurationManager.AppSettings["wx_pay_currypay_source"]) };
|
||
|
||
// var payData = sHelper.encyptDataNew(Utility.ObjectToJson(option), ConfigurationManager.AppSettings["wx_pay_interface_accesskey"], ConfigurationManager.AppSettings["wx_pay_interface_iv"]);
|
||
// var xx = System.Net.WebUtility.UrlEncode(payData);
|
||
// myurl = myurl.Replace("${payData}", xx);
|
||
|
||
// url = myurl;
|
||
// LogHelper.Info("wxPayUrl:" + url);
|
||
// }
|
||
|
||
// var bytes = QRCodeHelper.GetQrCode(payInfo.PAYNAME, "¥" + payInfo.PAYPRICE.ToString(), order.SUBPRODUCTNAME, filePath, url, paytype);
|
||
|
||
// payInfo.QRCODE = webFilePaht;
|
||
// payInfo.QRCODETIME = DateTime.Now.AddHours(2);
|
||
|
||
// _orderPay.Update(payInfo);
|
||
|
||
// return bytes;
|
||
// }
|
||
// catch (Exception ex)
|
||
// {
|
||
// LogHelper.Error(ex);
|
||
// return null;
|
||
// }
|
||
//}
|
||
private string DataFormart(string key, object value)
|
||
{
|
||
string formartValue = string.Empty;
|
||
switch (key)
|
||
{
|
||
case "auditstatus":
|
||
formartValue = (value != null && value.ToString() == "1") ? "已审核" : "未审核"; break;
|
||
default: formartValue = string.Format("{0}", value); break;
|
||
}
|
||
return formartValue;
|
||
}
|
||
|
||
private string GetPayTypeName(decimal typeId)
|
||
{
|
||
var name = "未知";
|
||
switch (int.Parse(typeId.ToString()))
|
||
{
|
||
case 1: name = "支付宝"; break;
|
||
case 3: name = "银行转账"; break;
|
||
case 5: name = "微信支付"; break;
|
||
}
|
||
return name;
|
||
}
|
||
|
||
}
|
||
|
||
}
|