1562 lines
66 KiB
C#
1562 lines
66 KiB
C#
using Aop.Api;
|
||
using Aop.Api.Request;
|
||
using CRM.Core.DTO;
|
||
using CRM.Core.DTO.Ord;
|
||
using Ninject;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Configuration;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Net;
|
||
using System.Runtime.Remoting.Messaging;
|
||
using System.Security.Policy;
|
||
using System.Text;
|
||
using System.Web;
|
||
using System.Web.Mvc;
|
||
using WX.CRM.BLL;
|
||
using WX.CRM.BLL.Base;
|
||
using WX.CRM.BLL.Deliver;
|
||
using WX.CRM.BLL.Res;
|
||
using WX.CRM.BLL.Util;
|
||
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.Model.Entity;
|
||
using WX.CRM.Model.Enum;
|
||
using WX.CRM.WebHelper;
|
||
|
||
namespace WX.CRM.WEB.Controllers.WeiXin
|
||
{
|
||
public class OrderDepositController : BaseController
|
||
{
|
||
[Inject]
|
||
public CACHE_BL cache_BL { get; set; }
|
||
[Inject]
|
||
public ISecurityHelper sHelper { get; set; }
|
||
[Inject]
|
||
public IWX_SZZYORDERDEPOSIT _orderDepoist { get; set; }
|
||
|
||
[Inject]
|
||
public IWX_SZZYORDERREFUND _orderRefund { get; set; }
|
||
[Inject]
|
||
public IWX_SZZYORDERPAY _orderPay { get; set; }
|
||
[Inject]
|
||
public IRES_CUSTOMER_Q _customerQ { get; set; }
|
||
|
||
[Inject]
|
||
public IWX_SZZYORDER _order { get; set; }
|
||
[Inject]
|
||
public IWX_ORDEREXT _orderext { get; set; }
|
||
|
||
public NativePay _nativePay = new NativePay();
|
||
|
||
[Inject]
|
||
public IRES_MYALLOCATERES _myRes { get; set; }
|
||
|
||
[Inject]
|
||
public IBAS_BUSINESSLINE_Q _businessLine_q { get; set; }
|
||
|
||
[Inject]
|
||
public IRES_SCENE _resScene { get; set; }
|
||
|
||
[HttpGet]
|
||
[AuthorizeRedirect(Roles = InitRights.CONST_订金列表)]
|
||
public ActionResult Index()
|
||
{
|
||
Pager pager = new Pager() { page = 1, rows = 20 };
|
||
ToolBar tool = new ToolBar();
|
||
string[] toolbtn = new ToolButtonView().ToolButtonRight(InitRights.订金列表, userRightId);
|
||
tool.AllowButton(toolbtn);
|
||
ViewBag.ToolBar = tool;
|
||
string tableId = "tablist";
|
||
Table tab = new Table(tableId);
|
||
tab.AddHeadCol("id", "", "ID");
|
||
tab.AddHeadCol("resid", "", "客户ID");
|
||
tab.AddHeadCol("paytypename", "", "支付类型");
|
||
tab.AddHeadCol("paydate", "", "到账时间");
|
||
tab.AddHeadCol("payprice", "", "订金金额");
|
||
tab.AddHeadCol("payname", "", "付款人姓名");
|
||
tab.AddHeadCol("remark", "", "说明");
|
||
tab.AddHeadCol("creator", "120px", "创建人");
|
||
tab.AddHeadCol("auditstatus", "", "审核状态");
|
||
tab.AddHeadCol("audittime", "", "审核时间");
|
||
tab.AddHeadCol("lastprice", "", "剩余金额");
|
||
tab.AddHeadCol("payno", "", "流水号");
|
||
//tab.AddHeadCol("ISUSE", "", "是否使用");
|
||
//tab.AddHeadCol("USETIME", "", "使用时间");
|
||
tab.AddHeadCol("orderid", "", "关联订单号");
|
||
tab.AddHeadCol("rejectremark", "", "备注");
|
||
tab.AddHeadCol("", "", "操作");
|
||
tab.AddHeadRow();
|
||
ViewBag.gridTable = tab.GetHead() + Pagination.GetPage(pager, tableId, "20,50,100");
|
||
|
||
var myBusinessLine = _businessLine_q.GetBusineeLine(UserId);
|
||
var deptList = cache_BL.GetList_BusinessLines().ToList();
|
||
var selectList = new List<SelectListItem>();
|
||
foreach (var item in deptList)
|
||
{
|
||
if (myBusinessLine != null && myBusinessLine.BUSINESSID == item.BUSINESSID)
|
||
{
|
||
selectList.Add(new SelectListItem() { Text = item.BUSINESSNAME, Value = item.BUSINESSID.ToString(), Selected = true });
|
||
|
||
}
|
||
else
|
||
{
|
||
selectList.Add(new SelectListItem() { Text = item.BUSINESSNAME, Value = item.BUSINESSID.ToString() });
|
||
}
|
||
}
|
||
ViewBag.DeptList = selectList;
|
||
|
||
return View();
|
||
}
|
||
|
||
[HttpPost]
|
||
[AuthorizeRedirect(Roles = InitRights.CONST_订金列表)]
|
||
public JsonResult Index(Pager pager, string columns, OrderPayListReqDto dto)
|
||
{
|
||
//dto.channel = int.Parse(Utility.GetSettingOrNullByKey("Channel"));
|
||
var ret = _orderDepoist.GetCoreDepositList(pager, dto);
|
||
|
||
//var listAll = _orderDepoist.GetList(where, p => p.ID, 1, int.MaxValue, out totalRecords);
|
||
//var payPrices = listAll.Sum(p => p.PAYPRICE);
|
||
|
||
Table table = new Table(columns, true);
|
||
if (ret.result)
|
||
{
|
||
if (ret.infolist.Count > 0)
|
||
{
|
||
foreach (var model in ret.infolist)
|
||
{
|
||
//model.PAYTYPENAME = GetPayTypeName(model.PAYTYPE);
|
||
table.AddCol(model.id);
|
||
table.AddCol(model.resid);
|
||
table.AddCol(model.paytypename);
|
||
table.AddCol(model.paydate);
|
||
table.AddCol(model.payprice);
|
||
table.AddCol(model.payname);
|
||
table.AddCol(model.remark);
|
||
if (model.creator.HasValue)
|
||
{
|
||
table.AddCol(model.creatorname + $"({model.creator})");
|
||
}
|
||
else
|
||
{
|
||
table.AddCol("系统");
|
||
}
|
||
//table.AddCol(model.AUDITSTATUS == 1 ? "已审核" : "未审核");
|
||
if (model.auditstatus == 1)
|
||
{
|
||
table.AddCol("color:green", "", "已审核");
|
||
}
|
||
else if (model.auditstatus == -1)
|
||
{
|
||
|
||
table.AddCol("color:red", "", "<span title='" + model.rejectremark + "' class='bohuiremark' >驳回</span>");
|
||
}
|
||
else
|
||
{
|
||
table.AddCol("未审核");
|
||
}
|
||
table.AddCol(model.audittime);
|
||
table.AddCol(model.lastprice);
|
||
table.AddCol(model.payno);
|
||
//table.AddCol(model.USETIME);
|
||
table.AddCol(model.orderid);
|
||
table.AddCol(model.rejectremark);
|
||
table.AddCol(model.auditstatus == 1 ? (model.lastprice.HasValue && model.lastprice.Value > 0 ? string.Format("<a href='javascript:void(0)' onclick='ApplyDepositRefund({0})'>{1}</a>", model.id, "退款申请") : "") : "");
|
||
table.AddRow();
|
||
}
|
||
}
|
||
table.AddCol("合计:");
|
||
table.AddCol("");
|
||
table.AddCol("");
|
||
table.AddCol("");
|
||
table.AddCol(ret.sumInfo.paypriceSum);
|
||
table.AddCol("");
|
||
table.AddCol("");
|
||
table.AddCol("");
|
||
table.AddCol("");
|
||
table.AddCol(ret.sumInfo.lastpriceSum);
|
||
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);
|
||
}
|
||
|
||
[HttpGet]
|
||
[AuthorizeRedirect(Roles = InitRights.CONST_支付列表)]
|
||
public ActionResult BindList(string sgin, string createTime, int eid = 0)
|
||
{
|
||
var myBusinessLine = _businessLine_q.GetBusineeLine(UserId);
|
||
var deptList = cache_BL.GetList_BusinessLines().ToList();
|
||
var selectList = new List<SelectListItem>();
|
||
foreach (var item in deptList)
|
||
{
|
||
if (myBusinessLine != null && myBusinessLine.BUSINESSID == item.BUSINESSID)
|
||
{
|
||
selectList.Add(new SelectListItem() { Text = item.BUSINESSNAME, Value = item.BUSINESSID.ToString(), Selected = true });
|
||
|
||
}
|
||
else
|
||
{
|
||
selectList.Add(new SelectListItem() { Text = item.BUSINESSNAME, Value = item.BUSINESSID.ToString() });
|
||
}
|
||
}
|
||
ViewBag.DeptList = selectList;
|
||
|
||
var webapi = cache_BL.GetValue_Parameter(Parameter.ZXD_CORE_WEBAPI);
|
||
ViewBag.webapi = webapi;
|
||
return View();
|
||
}
|
||
|
||
[HttpPost]
|
||
[AuthorizeRedirect(Roles = InitRights.CONST_支付列表)]
|
||
public string BindList(SearchBindListDto dto)
|
||
{
|
||
//var deliver_bll = new DELIVER_BLL();
|
||
//var EIds = deliver_bll.GetEIds(dto.txt_deptId, dto.txt_userId);
|
||
//var webapi = cache_BL.GetValue_Parameter(Parameter.ZXD_CORE_WEBAPI);
|
||
//webapi = $"{webapi}/Api/Order/bind/page";
|
||
//var para = $"pageIndex={dto.PageIndex}&pageSize={dto.PageSize}&txt_userId={dto.txt_userId}&BindType={dto.BindType}&PayType={dto.PayType}&ResId={dto.ResId}&Phone={dto.Phone}&UnionId={dto.UnionId}&PayNo={dto.PayNo}&EId={dto.EId}&EIds={string.Join(",", EIds)}";
|
||
//var result = Utility.GetData(webapi, para, Encoding.UTF8);
|
||
//var rsp = Newtonsoft.Json.JsonConvert.DeserializeObject<WX.CRM.Common.StockHelper.ApiResult<WX.CRM.Common.StockHelper.PageResult<BindListDto>>>(result);
|
||
//if (rsp.Data!=null && rsp.Data.Data!=null && rsp.Data.Data.Any())
|
||
//{
|
||
// var eid_items = rsp.Data.Data.Select(o => o.EId.GetValueOrDefault()).ToArray();
|
||
// var info_items = deliver_bll.GetInfoByEid(eid_items);
|
||
// foreach (var item in rsp.Data.Data)
|
||
// {
|
||
// var info = info_items.Where(w => w.EId== item.EId).FirstOrDefault();
|
||
// if (info!=null)
|
||
// {
|
||
// item.EName = info.EName;
|
||
// }
|
||
// }
|
||
//}
|
||
//var jss = new Newtonsoft.Json.JsonSerializerSettings();
|
||
//jss.ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver();
|
||
//return Newtonsoft.Json.JsonConvert.SerializeObject(rsp, jss);
|
||
|
||
var ch = new List<int>();
|
||
var businessChannel = _CacheQ.GetList_BusinessChannels();
|
||
if (dto.businessId.HasValue)
|
||
{
|
||
businessChannel = businessChannel.Where(p => p.BUSINESSID == dto.businessId).ToList();
|
||
}
|
||
foreach (var item in businessChannel)
|
||
{
|
||
ch.Add(item.MINCHANNEL);
|
||
}
|
||
|
||
var webapi = cache_BL.GetValue_Parameter(Parameter.ZXD_CORE_WEBAPI);
|
||
webapi = $"{webapi}/Api/Order/bind/page";
|
||
var para = $"pageIndex={dto.PageIndex}&pageSize={dto.PageSize}&txt_userId={dto.txt_userId}&BindType={dto.BindType}&PayType={dto.PayType}&ResId={dto.ResId}&Phone={dto.Phone}&UnionId={dto.UnionId}&PayNo={dto.PayNo}&EId={dto.EId}&Channel={string.Join(",", ch)}";
|
||
var result = Utility.GetData(webapi, para, Encoding.UTF8);
|
||
return result;
|
||
}
|
||
|
||
[HttpPost]
|
||
[AuthorizeRedirect(Roles = InitRights.CONST_支付列表)]
|
||
public string BindDetail(int? id)
|
||
{
|
||
var webapi = cache_BL.GetValue_Parameter(Parameter.ZXD_CORE_WEBAPI);
|
||
webapi = $"{webapi}/Api/Order/bind/detail";
|
||
var para = $"id={id}";
|
||
var result = Utility.GetData(webapi, para, Encoding.UTF8);
|
||
return result;
|
||
}
|
||
|
||
[HttpPost]
|
||
[AuthorizeRedirect(Roles = InitRights.CONST_支付列表)]
|
||
public string EditBind(int? id, string resId, string remark)
|
||
{
|
||
var webapi = cache_BL.GetValue_Parameter(Parameter.ZXD_CORE_WEBAPI);
|
||
webapi = $"{webapi}/Api/Order/bind/edit";
|
||
var para = $"id={id}&resId={resId}&remark={remark}";
|
||
var result = Utility.GetData(webapi, para, Encoding.UTF8);
|
||
return result;
|
||
}
|
||
|
||
[HttpPost]
|
||
[AuthorizeRedirect(Roles = InitRights.CONST_支付列表)]
|
||
public string GetUserSelect(string unionId)
|
||
{
|
||
var webapi = cache_BL.GetValue_Parameter(Parameter.ZXD_CORE_WEBAPI);
|
||
webapi = $"{webapi}/Api/Order/bind/userselect";
|
||
var para = $"unionId={unionId}";
|
||
var result = Utility.GetData(webapi, para, Encoding.UTF8);
|
||
return result;
|
||
}
|
||
|
||
[HttpPost]
|
||
[AuthorizeRedirect(Roles = InitRights.CONST_支付列表)]
|
||
public string GetUserItem(string resId)
|
||
{
|
||
var webapi = cache_BL.GetValue_Parameter(Parameter.ZXD_CORE_WEBAPI);
|
||
webapi = $"{webapi}/Api/Order/bind/useritem";
|
||
var para = $"resId={resId}";
|
||
var result = Utility.GetData(webapi, para, Encoding.UTF8);
|
||
return result;
|
||
}
|
||
|
||
#region 使用本地数据的老方式
|
||
//[HttpPost]
|
||
//[AuthorizeRedirect(Roles = InitRights.CONST_订金列表)]
|
||
//public JsonResult Index(Pager pager, string columns, string resid, DateTime? aTime, DateTime? zTime, decimal? status, DateTime? sTime, DateTime? eTime, decimal? isUse, decimal? paytype, DateTime? use1Time, DateTime? use2Time, decimal? id, string payno)
|
||
//{
|
||
// var where = PredicateExtensionses.True<WX_SZZYORDERDEPOSIT>();
|
||
// if (!string.IsNullOrEmpty(resid))
|
||
// where = where.And(p => p.RESID == resid);
|
||
// if (aTime.HasValue)
|
||
// where = where.And(p => p.CTIME >= aTime.Value);
|
||
// if (zTime.HasValue)
|
||
// {
|
||
// zTime = zTime.Value.AddDays(1);
|
||
// where = where.And(p => p.CTIME < zTime.Value);
|
||
// }
|
||
// if (status.HasValue)
|
||
// {
|
||
// if (status == 0)
|
||
// {
|
||
// where = where.And(p => p.AUDITSTATUS == null);
|
||
// }
|
||
// else
|
||
// {
|
||
// where = where.And(p => p.AUDITSTATUS == status.Value);
|
||
// }
|
||
// }
|
||
// if (sTime.HasValue)
|
||
// where = where.And(p => p.PAYDATE >= sTime.Value);
|
||
// if (eTime.HasValue)
|
||
// {
|
||
// eTime = eTime.Value.AddDays(1);
|
||
// where = where.And(p => p.PAYDATE < eTime.Value);
|
||
// }
|
||
// if (isUse.HasValue)
|
||
// where = where.And(p => p.ISUSE == isUse.Value);
|
||
// if (paytype.HasValue)
|
||
// where = where.And(p => p.PAYTYPE == paytype.Value);
|
||
// if (id.HasValue)
|
||
// {
|
||
// where = where.And(p => p.ID == id.Value);
|
||
// }
|
||
// if (!string.IsNullOrEmpty(payno))
|
||
// {
|
||
// where = where.And(p => p.PAYNO == payno);
|
||
// }
|
||
// where = where.And(p => p.ISDELETE != 1);
|
||
|
||
// var list = _orderDepoist.GetList(where, p => p.ID, pager);
|
||
// var orders = list.Where(p => p.ORDERID != null).Select(p => p.ORDERID);
|
||
// var payList = _orderPay.GetList(p => orders.Contains(p.ORDERID));
|
||
// var totalRecords = 0;
|
||
// var listAll = _orderDepoist.GetList(where, p => p.ID, 1, int.MaxValue, out totalRecords);
|
||
// var payPrices = listAll.Sum(p => p.PAYPRICE);
|
||
|
||
// var data = new List<WX_SZZYORDERDEPOSITVIEW>();
|
||
// foreach (var item in list)
|
||
// {
|
||
// var payModel = payList.Where(p => p.ORDERID == item.ORDERID && p.PAYNO != item.PAYNO).OrderByDescending(p => p.PAYDATE).FirstOrDefault();
|
||
// var useTime = payModel != null ? payModel.PAYDATE : (DateTime?)null;
|
||
// data.Add(new WX_SZZYORDERDEPOSITVIEW()
|
||
// {
|
||
// ID = item.ID,
|
||
// RESID = item.RESID,
|
||
// PAYTYPENAME = GetPayTypeName(item.PAYTYPE),
|
||
// PAYDATE = item.PAYDATE,
|
||
// PAYPRICE = item.PAYPRICE,
|
||
// PAYNAME = item.PAYNAME,
|
||
// REMARK = item.REMARK,
|
||
// AUDITSTATUS = item.AUDITSTATUS,
|
||
// PAYNO = item.PAYNO,
|
||
// ISUSE = item.ISUSE,
|
||
// USETIME = useTime,
|
||
// ORDERID = item.ORDERID,
|
||
// REJECTREMARK = item.REJECTREMARK,
|
||
// LASTPRICE = item.LASTPRICE
|
||
// });
|
||
// }
|
||
// if (use1Time.HasValue && use2Time.HasValue)
|
||
// {
|
||
// data = data.Where(p => p.USETIME >= use1Time.Value && p.USETIME < use2Time.Value.AddDays(1)).ToList();
|
||
// }
|
||
// else if (use1Time.HasValue && !use2Time.HasValue)
|
||
// {
|
||
// data = data.Where(p => p.USETIME >= use1Time.Value).ToList();
|
||
// }
|
||
// else if (!use1Time.HasValue && use2Time.HasValue)
|
||
// {
|
||
// data = data.Where(p => p.USETIME < use2Time.Value.AddDays(1)).ToList();
|
||
// }
|
||
|
||
// Table table = new Table(columns, true);
|
||
// foreach (var model in data)
|
||
// {
|
||
// //model.PAYTYPENAME = GetPayTypeName(model.PAYTYPE);
|
||
// table.AddCol(model.ID);
|
||
// table.AddCol(model.RESID);
|
||
// table.AddCol(model.PAYTYPENAME);
|
||
// table.AddCol(model.PAYDATE);
|
||
// table.AddCol(model.PAYPRICE);
|
||
// table.AddCol(model.PAYNAME);
|
||
// table.AddCol(model.REMARK);
|
||
// //table.AddCol(model.AUDITSTATUS == 1 ? "已审核" : "未审核");
|
||
// if (model.AUDITSTATUS == 1)
|
||
// {
|
||
// table.AddCol("color:green", "", "已审核");
|
||
// }
|
||
// else if (model.AUDITSTATUS == -1)
|
||
// {
|
||
// table.AddCol("color:red", "", "驳回");
|
||
// }
|
||
// else
|
||
// {
|
||
// table.AddCol("未审核");
|
||
// }
|
||
// table.AddCol(model.LASTPRICE);
|
||
// table.AddCol(model.PAYNO);
|
||
// //table.AddCol(model.ISUSE == 0 ? "未使用" : (model.ISUSE == 1 ? "已使用" : (model.ISUSE == 2 ? "已退款" : "已开通")));
|
||
// //if (model.ORDERID.HasValue)
|
||
// //{
|
||
// // var payModel = payList.Where(p => p.ORDERID == model.ORDERID && p.PAYNO != model.PAYNO).OrderByDescending(p => p.PAYDATE).FirstOrDefault();
|
||
// // if (payModel != null)
|
||
// // {
|
||
// // table.AddCol(payModel.PAYDATE);
|
||
// // }
|
||
// // else
|
||
// // {
|
||
// // table.AddCol("");
|
||
// // }
|
||
// //}
|
||
// //else
|
||
// //{
|
||
// // table.AddCol("");
|
||
// //}
|
||
// table.AddCol(model.USETIME);
|
||
// table.AddCol(model.ORDERID);
|
||
// table.AddCol(model.REJECTREMARK);
|
||
// table.AddCol(model.AUDITSTATUS == 1 ? (model.LASTPRICE.HasValue && model.LASTPRICE.Value > 0 ? string.Format("<a href='javascript:void(0)' onclick='ApplyDepositRefund({0})'>{1}</a>", model.ID, "退款申请") : "") : "");
|
||
// table.AddRow();
|
||
// }
|
||
// table.AddHiddenCol("");
|
||
// table.AddCol("合计:");
|
||
// table.AddCol("");
|
||
// table.AddCol("");
|
||
// table.AddCol(payPrices);
|
||
// table.AddCol("");
|
||
// table.AddCol("");
|
||
// table.AddCol("");
|
||
// table.AddCol("");
|
||
// table.AddCol("");
|
||
// table.AddCol("");
|
||
// table.AddCol("");
|
||
// table.AddCol("");
|
||
// table.AddRow();
|
||
// var json = new
|
||
// {
|
||
// totalPages = pager.totalPages,
|
||
// totalRows = pager.totalRows,
|
||
// rowsList = table.GetRows()
|
||
// };
|
||
// return Json(json, JsonRequestBehavior.AllowGet);
|
||
//}
|
||
#endregion
|
||
|
||
[HttpGet]
|
||
public ActionResult Info()
|
||
{
|
||
Pager pager = new Pager() { page = 1, rows = int.MaxValue };
|
||
string tableId = "tablist";
|
||
Table tab = new Table(tableId);
|
||
tab.AddHeadCol("ID", "", "ID");
|
||
tab.AddHeadCol("RESID", "", "客户ID");
|
||
tab.AddHeadCol("PAYTYPENAME", "", "支付类型");
|
||
tab.AddHeadCol("PAYDATE", "", "付款时间");
|
||
tab.AddHeadCol("PAYPRICE", "", "订金金额");
|
||
tab.AddHeadCol("PAYNAME", "", "付款人姓名");
|
||
tab.AddHeadCol("REMARK", "", "说明");
|
||
tab.AddHeadCol("AUDITSTATUS", "", "审核状态");
|
||
tab.AddHeadCol("PAYNO", "", "流水号");
|
||
tab.AddHeadCol("ISUSE", "", "是否使用");
|
||
tab.AddHeadCol("ORDERID", "", "关联订单号");
|
||
tab.AddHeadCol("ACTION", "", "操作");
|
||
tab.AddHeadRow();
|
||
ViewBag.gridTable = tab.GetHead();
|
||
return View();
|
||
}
|
||
|
||
[HttpPost]
|
||
public JsonResult Info(string resid, string columns)
|
||
{
|
||
var where = PredicateExtensionses.True<WX_SZZYORDERDEPOSIT>();
|
||
if (!string.IsNullOrEmpty(resid))
|
||
{
|
||
var customerId = _customerQ.getResCustomerByResId(resid).CUSTOMERID;
|
||
string[] resids = _customerQ.GetAllResidByCustomerId(customerId);
|
||
where = where.And(p => resids.Contains(p.RESID));
|
||
}
|
||
var list = _orderDepoist.GetList(where);
|
||
|
||
Table table = new Table(columns, true);
|
||
foreach (var model in list)
|
||
{
|
||
table.AddCol(model.ID);
|
||
table.AddCol(model.RESID);
|
||
table.AddCol(model.PAYTYPENAME);
|
||
table.AddCol(model.PAYDATE);
|
||
table.AddCol(model.PAYPRICE);
|
||
table.AddCol(model.PAYNAME);
|
||
table.AddCol(model.REMARK);
|
||
table.AddCol(model.AUDITSTATUS == 1 ? "已审核" : "未审核");
|
||
table.AddCol(model.PAYNO);
|
||
table.AddCol(model.ISUSE == 0 ? "未使用" : (model.ISUSE == 1 ? "已使用" : (model.ISUSE == 2 ? "已退款" : "已开通")));
|
||
table.AddCol(model.ORDERID);
|
||
table.AddCol(model.AUDITSTATUS == 1 ? (model.ISUSE == 0 ? string.Format("<a href='javascrpt:void(0)' onclick='ApplyDepositRefund({0})'>{1}</a>", model.ID, "退款申请") : "") : "");
|
||
table.AddRow();
|
||
}
|
||
var json = new
|
||
{
|
||
rowsList = table.GetRows()
|
||
};
|
||
return Json(json, JsonRequestBehavior.AllowGet);
|
||
}
|
||
|
||
[HttpGet]
|
||
public ActionResult List()
|
||
{
|
||
string CustomerId = Request.QueryString["CustomerId"];
|
||
string umid = _customerQ.getResCustomerByResId(CustomerId).UMID;
|
||
var ret = _orderDepoist.GetCoreDepositLastPay(new LastPriceReqDto() { resid = umid, channel = int.Parse(Utility.GetSettingOrNullByKey("Channel")) });
|
||
ViewBag.Ret = ret;
|
||
return View();
|
||
}
|
||
|
||
[HttpPost]
|
||
public JsonResult List(string resid)
|
||
{
|
||
//var where = PredicateExtensionses.True<WX_SZZYORDERDEPOSIT>();
|
||
//if (!string.IsNullOrEmpty(resid))
|
||
//{
|
||
// var customerId = _customerQ.getResCustomerByResId(resid).CUSTOMERID;
|
||
// string[] resids = _customerQ.GetAllResidByCustomerId(customerId);
|
||
// where = where.And(p => resids.Contains(p.RESID));
|
||
//}
|
||
//where = where.And(p => p.ISDELETE != 1);
|
||
//var list = _orderDepoist.GetList(where).ToList();
|
||
var umid = _customerQ.getResCustomerByResId(resid).UMID;
|
||
OrderPayListReqDto dto = new OrderPayListReqDto() { resid = umid };
|
||
Pager pager = new Pager() { page = 1, rows = int.MaxValue };
|
||
var ret = _orderDepoist.GetCoreDepositList(pager, dto);
|
||
|
||
var data = new LayuiData<OrderPayListRspDto, OrderPayListSumRspInfo>()
|
||
{
|
||
msg = "数据加载成功!",
|
||
count = 0,
|
||
code = 0,
|
||
data = ret.infolist,
|
||
suminfo = ret.sumInfo,
|
||
};
|
||
if (ret.result == false)
|
||
{
|
||
data.SetFail(-1, "数据拉取错误!");
|
||
}
|
||
|
||
return Json(data, JsonRequestBehavior.AllowGet);
|
||
}
|
||
|
||
[HttpGet]
|
||
public ActionResult Add()
|
||
{
|
||
var deptList = cache_BL.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();
|
||
}
|
||
//手工添加支付
|
||
[HttpPost]
|
||
public JsonResult Add(OrderDepositDto dto)
|
||
{
|
||
try
|
||
{
|
||
if (!ModelState.IsValid)
|
||
{
|
||
return JsonHandler.ManageMessage("参数有误,请确认!", false);
|
||
}
|
||
var roleCodes = DataCacheHelper.GetCache().Get_RoleCodes(userRoleId);
|
||
//if (!(roleCodes.Contains("[GLY]") || roleCodes.Contains("[ZJZL]")))
|
||
//{
|
||
// return JsonHandler.ManageMessage("请联系助理添加!", false);
|
||
//}
|
||
if (!string.IsNullOrEmpty(dto.payno))
|
||
{
|
||
dto.payno = dto.payno.Trim();
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(dto.resid))
|
||
{
|
||
//umid转resid
|
||
dto.resid = _customerQ.getResCustomerByUmid(dto.resid).RESID;
|
||
}
|
||
//dto.companycode = companyCode;
|
||
dto.companycode = Utility.GetSettingOrNullByKey("DataClientCode");
|
||
|
||
//var groups = _CacheQ.GetGroupList();
|
||
//var ug = _CacheQ.GetList_InnerUserGroup();
|
||
var depment = _CacheQ.GetList_SalesDepartMent();
|
||
|
||
//var myRes = _myRes.Get(p => p.RESID == dto.resid);
|
||
//if (myRes != null)
|
||
//{
|
||
// var uginfo = ug.Find(p => p.INNERUSERID == myRes.INNERUSERID);
|
||
// if (uginfo != null)
|
||
// {
|
||
// var group = groups.Find(p => p.GID == uginfo.GID);
|
||
// if (group != null)
|
||
// {
|
||
// var dep = depment.Find(p => p.SALEDEPTID == group.SALEDEPTID);
|
||
// if (dep != null)
|
||
// {
|
||
// if (dep.CHANNELDEF.HasValue)
|
||
// dto.channel = Convert.ToInt32(dep.CHANNELDEF);
|
||
// }
|
||
// }
|
||
// }
|
||
//}
|
||
|
||
if (!string.IsNullOrEmpty(dto.deptcode))
|
||
{
|
||
//如果传了部门编号
|
||
var dep = depment.Find(p => p.SALEDEPTCODE == dto.deptcode);
|
||
if (dep != null)
|
||
{
|
||
if (dep.CHANNELDEF.HasValue)
|
||
dto.channel = Convert.ToInt32(dep.CHANNELDEF);
|
||
}
|
||
}
|
||
|
||
if (!dto.channel.HasValue)
|
||
{
|
||
dto.channel = int.Parse(Utility.GetSettingOrNullByKey("Channel"));
|
||
}
|
||
|
||
dto.creator = Convert.ToInt32(Eid);
|
||
dto.creatorname = UserName;
|
||
var url = cache_BL.GetValue_Parameter(Parameter.Core_ZxdService_OrderDeposit);
|
||
var json = sHelper.createSignEncodingStr(dto.ToJson(), SecurityHelper.OrderClientIdKey);
|
||
|
||
string retmsg = Utility.PostData(url + "?" + json, Encoding.UTF8);
|
||
var retmessage = WebHelper.JsonHelper.JsonDivertToObj<retMsg>(retmsg);
|
||
if (retmessage.result)
|
||
{
|
||
try
|
||
{
|
||
var orderDeposit = new WX_SZZYORDERDEPOSIT()
|
||
{
|
||
ID = decimal.Parse(retmessage.retmsg),
|
||
RESID = dto.resid,
|
||
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 = dto.payno.Trim(),
|
||
CREATOR = Eid,
|
||
CREATORNAME = UserName,
|
||
DEPTCODE = dto.deptcode
|
||
};
|
||
_orderDepoist.Add(orderDeposit);
|
||
}
|
||
catch (Exception xx)
|
||
{
|
||
LogHelper.Error("订金记录添加到本地库异常:" + xx.ToString());
|
||
}
|
||
return JsonHandler.ManageMessage("提交成功", true);
|
||
}
|
||
else
|
||
return JsonHandler.ManageMessage("提交失败,请稍后重试或者联系管理员!", false);
|
||
//return JsonHandler.ManageMessage("提交成功", true);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Error(ex.ToString());
|
||
return JsonHandler.ManageMessage("提交失败,请稍后重试或者联系管理员!", false);
|
||
}
|
||
}
|
||
|
||
[HttpGet]
|
||
public ActionResult Add2()
|
||
{
|
||
var deptList = cache_BL.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 = cache_BL.GetValue_Parameter("QuoTa");
|
||
ViewBag.QuoTa = quota;
|
||
return View();
|
||
}
|
||
|
||
[HttpGet]
|
||
public ActionResult Bank()
|
||
{
|
||
var deptList = cache_BL.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();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 客户资料页面,订金二维码添加,我的订单提交也在这里
|
||
/// </summary>
|
||
/// <param name="dto"></param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
public JsonResult Add2(OrderDepositDto dto)
|
||
{
|
||
try
|
||
{
|
||
if (!ModelState.IsValid)
|
||
{
|
||
return JsonHandler.ManageMessage("参数有误,请确认!", false);
|
||
}
|
||
//var mchId = cache_BL.GetValue_Parameter("mchId");
|
||
//if(string.IsNullOrEmpty(mchId))
|
||
//{
|
||
// 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("D", noId);
|
||
}
|
||
|
||
dto.companycode = Utility.GetSettingOrNullByKey("DataClientCode");
|
||
|
||
var depment = _CacheQ.GetList_SalesDepartMent();
|
||
|
||
if (string.IsNullOrEmpty(dto.orderid))
|
||
{
|
||
if (!string.IsNullOrEmpty(dto.deptcode))
|
||
{
|
||
//如果传了部门编号
|
||
var dep = depment.Find(p => p.SALEDEPTCODE == dto.deptcode);
|
||
if (dep != null)
|
||
{
|
||
if (dep.CHANNELDEF.HasValue)
|
||
dto.channel = Convert.ToInt32(dep.CHANNELDEF);
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (!string.IsNullOrEmpty(dto.deptcode))
|
||
{
|
||
//如果传了部门编号
|
||
var dep = depment.Find(p => p.SALEDEPTCODE == dto.deptcode);
|
||
if (dep != null)
|
||
{
|
||
if (dep.CHANNELDEF.HasValue)
|
||
dto.channel = Convert.ToInt32(dep.CHANNELDEF);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
var orderidsArr = dto.orderid.Split(',');
|
||
var orderid = Convert.ToInt32(orderidsArr[0]);
|
||
var orderext = _orderext.Get(p => p.ORDERID == orderid);
|
||
if (orderext != null)
|
||
{
|
||
if (!string.IsNullOrEmpty(orderext.CHANNEL))
|
||
dto.channel = Convert.ToInt32(orderext.CHANNEL);
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
if (!dto.channel.HasValue)
|
||
{
|
||
dto.channel = int.Parse(Utility.GetSettingOrNullByKey("Channel"));
|
||
}
|
||
if (string.IsNullOrEmpty(dto.resid))
|
||
{
|
||
if (!string.IsNullOrEmpty(dto.orderid))
|
||
{
|
||
var orderidsArr = dto.orderid.Split(',');
|
||
var orderid = Convert.ToInt32(orderidsArr[0]);
|
||
var order = _order.Get(p => p.ORDERID == orderid);
|
||
if (order != null)
|
||
{
|
||
dto.resid = order.RESID;
|
||
}
|
||
}
|
||
}
|
||
|
||
//var url = cache_BL.GetValue_Parameter(Parameter.Core_ZxdService_OrderDeposit);
|
||
//var json = sHelper.createSignEncodingStr(dto.ToJson(), SecurityHelper.OrderClientIdKey);
|
||
|
||
|
||
|
||
PayDto newdto = new PayDto();
|
||
newdto.orderuselist = new List<OrderuseDto>() { };
|
||
if (!string.IsNullOrEmpty(dto.orderid))
|
||
{
|
||
decimal orderid = Convert.ToDecimal(dto.orderid);
|
||
var myorder = _order.Get(m => m.ORDERID == orderid);
|
||
var needpay = (myorder.NEEDPAY ?? 0) - (myorder.ARRIVALPAY ?? 0);
|
||
if (needpay > 0)
|
||
{
|
||
newdto.orderuselist.Add(new OrderuseDto() { orderid = Convert.ToInt32(dto.orderid), needpay = needpay });//添加需要支付多少钱
|
||
}
|
||
}
|
||
|
||
//umid转resid
|
||
dto.resid = _customerQ.getResCustomerByUmid(dto.resid).RESID;
|
||
|
||
var paylist = new List<PayInfoDto>
|
||
{
|
||
new PayInfoDto()
|
||
{
|
||
//id = dto.id,
|
||
resid = dto.resid,
|
||
paytype = dto.paytype,
|
||
paytypename = GetPayTypeName(dto.paytype),
|
||
paydate = dto.paydate,
|
||
payprice = dto.payprice,
|
||
payname = dto.payname,
|
||
remark = dto.remark,
|
||
payno = dto.payno,
|
||
isuse = dto.isuse,
|
||
companycode = Utility.GetSettingOrNullByKey("DataClientCode"),
|
||
tradeno = dto.tradeno,
|
||
creator = Convert.ToInt32(Eid),
|
||
creatorname = UserName
|
||
}
|
||
};
|
||
var dto2 = new PayDto2
|
||
{
|
||
orderuselist = newdto.orderuselist,
|
||
resid = dto.resid,
|
||
channel = dto.channel,
|
||
deptcode = dto.deptcode,//部门编码
|
||
//depprice = dto.depprice,
|
||
paylist = paylist,//需要添加的支付记录
|
||
};
|
||
|
||
var ret2 = _orderDepoist.Pay2(dto2);//然后提交金额
|
||
if (!ret2.result)
|
||
{
|
||
return Json(new { type = 0, retcode = 500, msgretmsg = "支付流水提交失败!" }, JsonRequestBehavior.AllowGet);
|
||
}
|
||
return Json(new { type = 1, retcode = 200, message = ret2.retmsg.FirstOrDefault().id }, JsonRequestBehavior.AllowGet);
|
||
|
||
//string retmsg = Utility.PostData(url + "?" + json, Encoding.UTF8);
|
||
//var retmessage = WebHelper.JsonHelper.JsonDivertToObj<retMsg>(retmsg);
|
||
//if (retmessage.result)
|
||
//{
|
||
// try
|
||
// {
|
||
// _orderDepoist.Add(dto);
|
||
// }
|
||
// catch (Exception xx)
|
||
// {
|
||
// LogHelper.Error("订金记录添加到本地库异常:" + xx.ToString());
|
||
// }
|
||
// return JsonHandler.ManageMessage("success", true);
|
||
//}
|
||
//else
|
||
// return JsonHandler.ManageMessage("提交失败,请稍后重试或者联系管理员!", false);
|
||
//return JsonHandler.ManageMessage("提交成功", true);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Error(ex.ToString());
|
||
return JsonHandler.ManageMessage("提交失败,请稍后重试或者联系管理员!", false);
|
||
}
|
||
}
|
||
|
||
[HttpGet]
|
||
public ActionResult Use(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;
|
||
return View();
|
||
}
|
||
|
||
[HttpPost]
|
||
public JsonResult Use(UseOrderDepositDto dto)
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(dto.deposit))
|
||
{
|
||
var url = cache_BL.GetValue_Parameter(Parameter.Core_ZxdService_OrderDeposit_Use);
|
||
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)
|
||
{
|
||
var arr = dto.deposit.Split(',');
|
||
foreach (var item in arr)
|
||
{
|
||
var id = decimal.Parse(item);
|
||
|
||
var info = _orderDepoist.Get(p => p.ID == id);
|
||
if (info != null)
|
||
{
|
||
info.ISUSE = 1;
|
||
info.ORDERID = dto.orderid;
|
||
_orderDepoist.Update(info);
|
||
}
|
||
|
||
var orderPay2 = _orderPay.Get(p => p.ORDERID == id);
|
||
if (orderPay2 != null)
|
||
{
|
||
orderPay2.ORDERID = dto.orderid;
|
||
_orderPay.Update(orderPay2);
|
||
}
|
||
|
||
var order = _order.Get(p => p.ORDERID == dto.orderid);
|
||
if (order != null)
|
||
{
|
||
var arrivalPayList = _orderPay.GetList(p => p.ORDERID == dto.orderid && p.AUDITSTATUS == 1);
|
||
var payDate = arrivalPayList.OrderByDescending(p => p.PAYDATE).First().PAYDATE;
|
||
|
||
order.ARRIVALPAY = arrivalPayList.Sum(p => p.PAYPRICE);
|
||
order.ARRIVALTIME = payDate;
|
||
|
||
order.FINALPAY = order.ARRIVALPAY;
|
||
|
||
if (order.ARRIVALPAY >= order.NEEDPAY)
|
||
{
|
||
order.ORDERSTATUS = "200";
|
||
order.ORDERSTATUSNAME = "已支付";
|
||
}
|
||
else
|
||
{
|
||
order.ORDERSTATUS = "190";
|
||
order.ORDERSTATUSNAME = "已提交支付";
|
||
}
|
||
|
||
_order.Update(order);
|
||
}
|
||
}
|
||
return Json(new { result = true }, JsonRequestBehavior.AllowGet);
|
||
}
|
||
else
|
||
{
|
||
return Json(new { result = false }, JsonRequestBehavior.AllowGet);
|
||
}
|
||
}
|
||
return Json(new { result = false }, JsonRequestBehavior.AllowGet);
|
||
}
|
||
|
||
[HttpGet]
|
||
public ActionResult Use2(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;
|
||
string umid = _customerQ.getResCustomerByResId(order.RESID).UMID;
|
||
var ret = _orderDepoist.GetCoreDepositLastPay(new LastPriceReqDto() { resid = umid, channel = int.Parse(Utility.GetSettingOrNullByKey("Channel")) });
|
||
ViewBag.CorePayInfo = ret;
|
||
|
||
ViewBag.OrderNedPay = ((order.NEEDPAY ?? 0) - (order.ARRIVALPAY ?? 0));
|
||
return View();
|
||
}
|
||
|
||
[HttpPost]
|
||
public JsonResult Use2(int orderId, decimal usePrice)
|
||
{
|
||
try
|
||
{
|
||
var order = _order.Get(p => p.ORDERID == orderId);
|
||
if (usePrice > ((order.NEEDPAY ?? 0) - (order.ARRIVALPAY ?? 0)))
|
||
{
|
||
return Json(new retMsg { result = false, retcode = 500, retmsg = "使用的金额不能超过订单应付金额!" }, JsonRequestBehavior.AllowGet);
|
||
}
|
||
var usePayList = new List<OrderuseDto>() { new OrderuseDto() { orderid = orderId, needpay = order.NEEDPAY.Value } };
|
||
|
||
var ret = _orderDepoist.Use(new PayUseDto() { resid = order.RESID, depprice = usePrice, orderuselist = usePayList, channel = int.Parse(Utility.GetSettingOrNullByKey("Channel")) });
|
||
|
||
return Json(ret, JsonRequestBehavior.AllowGet);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Error(ex);
|
||
}
|
||
|
||
return Json(new { result = false }, JsonRequestBehavior.AllowGet);
|
||
}
|
||
|
||
[HttpGet]
|
||
public ActionResult Pay(string orderId, string resid)
|
||
{
|
||
var orderArr = orderId.Split(',').Select(decimal.Parse);
|
||
var order = _order.GetList(p => orderArr.Contains(p.ORDERID));
|
||
var needpay = order.Sum(p => p.NEEDPAY);
|
||
var arrivalpay = order.Sum(p => p.ARRIVALPAY);
|
||
ViewBag.needpay = needpay;
|
||
ViewBag.arrivalpay = arrivalpay;
|
||
ViewBag.Name = order.FirstOrDefault()?.CNAME;
|
||
//var customerId = _customerQ.getResCustomerByResId(resid).CUSTOMERID;
|
||
//string[] resids = _customerQ.GetAllResidByCustomerId(customerId);
|
||
//var orderDepositList = _orderDepoist.GetList(p => resids.Contains(p.RESID) && p.AUDITSTATUS == 1);
|
||
//var deppay = orderDepositList.Sum(p => p.LASTPRICE);
|
||
|
||
|
||
decimal? deppay = 0;
|
||
var ret = _orderDepoist.GetCoreDepositLastPay(new LastPriceReqDto() { resid = resid, channel = int.Parse(Utility.GetSettingOrNullByKey("Channel")) });
|
||
if (ret.result)
|
||
{
|
||
deppay = ret.retmsg.lastprice;
|
||
}
|
||
|
||
ViewBag.alldeppay = deppay;
|
||
var diffpay = needpay - (arrivalpay ?? 0) - (deppay ?? 0);
|
||
if (diffpay < 0)
|
||
{
|
||
//需付款金额小于0,说明钱超出了,只需要使用一部分
|
||
deppay += diffpay;
|
||
}
|
||
//LogHelper.Info("diffpay:" + diffpay.ToString());
|
||
//LogHelper.Info("deppay:" + deppay.ToString());
|
||
var justpay = needpay - (arrivalpay ?? 0) - (deppay ?? 0);
|
||
//LogHelper.Info("justpay:" + justpay.ToString());
|
||
ViewBag.deppay = deppay;
|
||
ViewBag.justpay = justpay;
|
||
return View();
|
||
}
|
||
|
||
[HttpPost]
|
||
public JsonResult Pay(PayDto dto, string orderId)
|
||
{
|
||
try
|
||
{
|
||
var deptcode = string.Empty;
|
||
|
||
dto.paytypename = GetPayTypeName(dto.paytype);
|
||
|
||
//umid转resid
|
||
dto.resid = _customerQ.getResCustomerByUmid(dto.resid).RESID;
|
||
|
||
var orderArr = orderId.Split(',').Select(decimal.Parse);
|
||
var order = _order.GetList(p => orderArr.Contains(p.ORDERID));
|
||
if (!order.Any())
|
||
{
|
||
return Json(new retMsg { result = false, retcode = 100 }, JsonRequestBehavior.AllowGet);
|
||
}
|
||
foreach (var item in order)
|
||
{
|
||
if (dto.orderuselist == null)
|
||
dto.orderuselist = new List<OrderuseDto>();
|
||
dto.orderuselist.Add(new OrderuseDto() { orderid = Convert.ToInt32(item.ORDERID), needpay = item.NEEDPAY.Value });
|
||
|
||
deptcode = item.DEPTCODE;
|
||
}
|
||
var paylist = new List<PayInfoDto>();
|
||
if (!string.IsNullOrEmpty(dto.payno))
|
||
{
|
||
paylist.Add(new PayInfoDto()
|
||
{
|
||
//id = dto.id,
|
||
resid = dto.resid,
|
||
paytype = dto.paytype,
|
||
paytypename = dto.paytypename,
|
||
paydate = dto.paydate,
|
||
payprice = dto.payprice,
|
||
payname = dto.payname,
|
||
remark = dto.remark,
|
||
payno = dto.payno,
|
||
isuse = dto.isuse,
|
||
companycode = Utility.GetSettingOrNullByKey("DataClientCode"),
|
||
tradeno = dto.tradeno,
|
||
creator = dto.creator,
|
||
creatorname = dto.creatorname
|
||
});
|
||
}
|
||
if (dto.depprice > 0)
|
||
{
|
||
var dto1 = new PayUseDto
|
||
{
|
||
resid = dto.resid,
|
||
depprice = dto.depprice,
|
||
orderuselist = dto.orderuselist,
|
||
channel = int.Parse(Utility.GetSettingOrNullByKey("Channel"))
|
||
};
|
||
var ret1 = _orderDepoist.Use(dto1);//使用订金
|
||
if (!ret1.result)//使用订金失败
|
||
{
|
||
return Json(new { result = false, retcode = 500, msgretmsg = "余额使用失败!" }, JsonRequestBehavior.AllowGet);
|
||
}
|
||
}
|
||
if (paylist.Count() == 0)
|
||
{
|
||
return Json(new { result = true, retcode = 200 }, JsonRequestBehavior.AllowGet);
|
||
}
|
||
var dto2 = new PayDto2
|
||
{
|
||
orderuselist = dto.orderuselist,
|
||
resid = dto.resid,
|
||
//depprice = dto.depprice,
|
||
deptcode = deptcode,
|
||
paylist = paylist,//需要添加的支付记录
|
||
};
|
||
|
||
var ret2 = _orderDepoist.Pay2(dto2);//然后提交金额
|
||
if (!ret2.result)
|
||
{
|
||
return Json(new { result = true, retcode = 500, msgretmsg = "余额使用成功,支付流水提交失败!" }, JsonRequestBehavior.AllowGet);
|
||
}
|
||
return Json(new { result = true, retcode = 200 }, JsonRequestBehavior.AllowGet);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Error(ex);
|
||
}
|
||
|
||
return Json(new { result = false }, JsonRequestBehavior.AllowGet);
|
||
}
|
||
|
||
[HttpGet]
|
||
public ActionResult Refund(int id)
|
||
{
|
||
//var deposit = _orderDepoist.Get(p => p.ID == id);
|
||
|
||
OrderPayListReqDto dto = new OrderPayListReqDto() { id = id };
|
||
Pager pager = new Pager() { page = 1, rows = int.MaxValue };
|
||
var ret = _orderDepoist.GetCoreDepositList(pager, dto);
|
||
decimal refprice = 0;
|
||
if (ret.result)
|
||
{
|
||
refprice = ret.infolist.FirstOrDefault().lastprice ?? 0;
|
||
}
|
||
//if (deposit.LASTPRICE.HasValue)
|
||
//{
|
||
// refprice = deposit.LASTPRICE.Value;
|
||
//}
|
||
var model = new OrderRefundDto
|
||
{
|
||
orderid = id,
|
||
refundprice = refprice
|
||
};
|
||
return View(model);
|
||
}
|
||
|
||
[HttpPost]
|
||
public JsonResult Refund(OrderRefundDto dto)
|
||
{
|
||
try
|
||
{
|
||
if (!ModelState.IsValid)
|
||
{
|
||
return JsonHandler.ManageMessage("参数有误,请确认!", false);
|
||
}
|
||
if (dto.refundprice <= 0)
|
||
{
|
||
return JsonHandler.ManageMessage("退款金额不能低于0", false);
|
||
}
|
||
var url = cache_BL.GetValue_Parameter(Parameter.Core_ZxdService_OrderRefund);
|
||
|
||
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
|
||
request.Method = "POST";
|
||
//request.ContentType = "application/x-www-form-urlencoded";
|
||
// request.ContentType = "application/json";
|
||
|
||
if (Request.Files.Count > 0)
|
||
{
|
||
var file = Request.Files[0];
|
||
var fileExt = Path.GetExtension(file.FileName);
|
||
var fileName = Path.Combine("att", Guid.NewGuid().ToString() + Path.GetExtension(file.FileName));
|
||
dto.att = Path.Combine("UploadFile", fileName);
|
||
}
|
||
//dto.companycode = companyCode;
|
||
dto.companycode = Utility.GetSettingOrNullByKey("DataClientCode");
|
||
|
||
var jiami = sHelper.encyptData("UPWEBSITE", dto.ToJson());
|
||
var content = HttpUtility.UrlEncode(jiami);
|
||
var sing = HttpUtility.UrlEncode(sHelper.signData("UPWEBSITE", jiami));
|
||
|
||
request.Headers.Add("content", content);
|
||
request.Headers.Add("clientid", "UPWEBSITE");
|
||
request.Headers.Add("sign", sing);
|
||
|
||
//如果需要POST数据
|
||
if (Request.Files.Count > 0)
|
||
{
|
||
var fileStream = Request.Files[0].InputStream;
|
||
byte[] data = null;
|
||
byte[] buffer = new byte[16 * 1024];
|
||
using (MemoryStream ms = new MemoryStream())
|
||
{
|
||
int read;
|
||
while ((read = fileStream.Read(buffer, 0, buffer.Length)) > 0)
|
||
{
|
||
ms.Write(buffer, 0, read);
|
||
}
|
||
data = ms.ToArray();
|
||
}
|
||
using (Stream stream = request.GetRequestStream())
|
||
{
|
||
stream.Write(data, 0, data.Length);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
//没有参数的时候必须加上这句,这个是HTTP POST要求必须带参数,不然就需要说明长度是0
|
||
request.ContentLength = 0;
|
||
}
|
||
|
||
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
|
||
{
|
||
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
|
||
string result = reader.ReadToEnd();
|
||
LogHelper.Info(result);
|
||
var retmsg = sHelper.decyptData(SecurityHelper.OrderClientIdKey, result);
|
||
var retmessage = WebHelper.JsonHelper.JsonDivertToObj<retMsgNew<RefundDeptDto>>(retmsg);
|
||
if (retmessage.result)
|
||
{
|
||
try
|
||
{
|
||
var deptcode = string.Empty;
|
||
|
||
if(retmessage.data != null)
|
||
{
|
||
if(retmessage.data.channel.HasValue)
|
||
{
|
||
var deptList = cache_BL.GetList_SalesDepartMent().Where(p => p.CHANNELDEF != null);
|
||
var dept = deptList.FirstOrDefault(p => p.CHANNELMIN <= retmessage.data.channel.Value && p.CHANNELMAX >= retmessage.data.channel.Value);
|
||
if(dept != null)
|
||
{
|
||
deptcode = dept.SALEDEPTCODE;
|
||
}
|
||
}
|
||
}
|
||
|
||
var orderRefund = new WX_SZZYORDERREFUND()
|
||
{
|
||
ID = new SEQUENCES_BL().Seq_base_get(),
|
||
SID = decimal.Parse(retmessage.retmsg),
|
||
ORDERID = dto.orderid,
|
||
REFUNDPRICE = dto.refundprice,
|
||
ACCOUNT = dto.account,
|
||
USERNAME = dto.username,
|
||
REFUNDTYPE = dto.refundtype,
|
||
REFUNDTYPENAME = string.Empty,
|
||
REFUNDDATE = dto.refunddate,
|
||
REMARK = dto.remark,
|
||
ATT = dto.att,
|
||
CTIME = DateTime.Now,
|
||
ISDELETE = 0,
|
||
CREATOR = Eid,
|
||
CREATORNAME = UserName,
|
||
ISACTURALREFUND = dto.isacturalrefund,
|
||
DEPTCODE = deptcode,
|
||
DEPTID = retmessage.data?.deptid,
|
||
DEPTNAME = retmessage.data?.deptName,
|
||
GROUPID = retmessage.data?.groupid,
|
||
REFUNDREASONTYPE = dto.RefundReasonType,
|
||
RETRACE_REFUND_FILE = dto.Retrace_refund_file
|
||
};
|
||
_orderRefund.Add(orderRefund);
|
||
}
|
||
catch (Exception xx)
|
||
{
|
||
LogHelper.Error("提交总部成功,但本地提交异常,请重新提交:" + xx.ToString());
|
||
return JsonHandler.ManageMessage("提交总部成功,但本地提交异常,请重新提交", false);
|
||
}
|
||
|
||
return JsonHandler.ManageMessage("提交成功", true);
|
||
}
|
||
else
|
||
return JsonHandler.ManageMessage("提交失败,请稍后重试或者联系管理员!", false);
|
||
}
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Error(ex.ToString());
|
||
return JsonHandler.ManageMessage("提交失败,请稍后重试或者联系管理员!", false);
|
||
}
|
||
}
|
||
|
||
[AuthorizeRedirect(Roles = InitRights.CONST_订金列表)]
|
||
public ActionResult Export(OrderPayListReqDto dto)
|
||
{
|
||
//dto.channel = int.Parse(Utility.GetSettingOrNullByKey("Channel"));
|
||
var ret = _orderDepoist.GetCoreDepositList(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<OrderPayListRspDto>(ret.infolist, "订金列表", 10000, checkedFilds, checkedTitles, DataFormart), "application/ms-excel", PageRequest.GetDlownLoadName("订金列表.xls"));
|
||
}
|
||
else
|
||
{
|
||
return Json(new { message = "数据获取错误!" }, JsonRequestBehavior.AllowGet);
|
||
}
|
||
|
||
}
|
||
|
||
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 = _orderDepoist.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);
|
||
}
|
||
[Inject]
|
||
public ICACHE_Q _CacheQ { get; set; }
|
||
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 = _orderDepoist.Get(p => p.ID == id);
|
||
LogHelper.Info("payInfo.TRADENO:" + payInfo.TRADENO);
|
||
var url = string.Empty;
|
||
LogHelper.Info("url:" + url);
|
||
var paytype = string.Empty;
|
||
if (payInfo.PAYTYPE == 1)
|
||
{
|
||
paytype = "ali";
|
||
|
||
var alpayId = cache_BL.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\":\"订金\"," +
|
||
"\"enable_pay_channels\":\"balance,bankPay,debitCardExpress,creditCard,creditCardExpress,creditCardCartoon\"" +
|
||
" }";
|
||
LogHelper.Info("aliPayRqeust:" + request.ToJson());
|
||
var response = client.Execute(request);
|
||
|
||
LogHelper.Info("aliPayUrl:" + response.ToJson());
|
||
|
||
url = response.QrCode;
|
||
}
|
||
else
|
||
{
|
||
paytype = "wx";
|
||
|
||
var mchId = cache_BL.GetValue_Parameter("mchId");
|
||
if (string.IsNullOrEmpty(mchId))
|
||
{
|
||
return null;
|
||
}
|
||
|
||
//url = _nativePay.GetPayQRCode("1", payInfo.TRADENO, "订金", (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 = "订金", 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(), "", filePath, url, paytype);
|
||
|
||
payInfo.QRCODE = webFilePaht;
|
||
payInfo.QRCODETIME = DateTime.Now.AddHours(2);
|
||
|
||
//_orderPay.Update(payInfo);
|
||
_orderDepoist.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;
|
||
case "ISUSE":
|
||
formartValue = value.ToString() == "0" ? "未使用" : (value.ToString() == "1" ? "已使用" : (value.ToString() == "2" ? "已退款" : "已开通"));
|
||
break;
|
||
//case "ACTION":
|
||
// formartValue = string.Empty;
|
||
// break;
|
||
default: formartValue = string.Format("{0}", value); break;
|
||
}
|
||
return formartValue;
|
||
}
|
||
|
||
public class WX_SZZYORDERDEPOSIT_EXPORT
|
||
{
|
||
public decimal ID { get; set; }
|
||
public string RESID { get; set; }
|
||
public decimal PAYTYPE { get; set; }
|
||
public string PAYTYPENAME { get; set; }
|
||
public DateTime? PAYDATE { get; set; }
|
||
public decimal PAYPRICE { get; set; }
|
||
public string PAYNAME { get; set; }
|
||
public string REMARK { get; set; }
|
||
public decimal? AUDITSTATUS { get; set; }
|
||
public decimal? AUDITOR { get; set; }
|
||
public string AUDITORNAME { get; set; }
|
||
public DateTime? AUDITTIME { get; set; }
|
||
public DateTime? CTIME { get; set; }
|
||
public string PAYNO { get; set; }
|
||
public decimal ISUSE { get; set; }
|
||
public string COMPANYCODE { get; set; }
|
||
public decimal? ORDERID { get; set; }
|
||
public DateTime? USETIME { get; set; }
|
||
}
|
||
|
||
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;
|
||
}
|
||
|
||
private class WX_SZZYORDERDEPOSITVIEW
|
||
{
|
||
public decimal ID { get; set; }
|
||
public string RESID { get; set; }
|
||
public decimal PAYTYPE { get; set; }
|
||
public string PAYTYPENAME { get; set; }
|
||
public DateTime? PAYDATE { get; set; }
|
||
public decimal PAYPRICE { get; set; }
|
||
public string PAYNAME { get; set; }
|
||
public string REMARK { get; set; }
|
||
public decimal? AUDITSTATUS { get; set; }
|
||
public decimal? AUDITOR { get; set; }
|
||
public string AUDITORNAME { get; set; }
|
||
public DateTime? AUDITTIME { get; set; }
|
||
public DateTime? CTIME { get; set; }
|
||
public string PAYNO { get; set; }
|
||
public decimal ISUSE { get; set; }
|
||
public string COMPANYCODE { get; set; }
|
||
public decimal? ORDERID { get; set; }
|
||
public DateTime? USETIME { get; set; }
|
||
public string REJECTREMARK { get; set; }
|
||
|
||
public decimal? LASTPRICE { get; set; }
|
||
}
|
||
|
||
}
|
||
}
|