You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2903 lines
122 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using Common.Logging;
using DSWeb.Common.Model;
using System;
using System.Linq;
using System.Web.Mvc;
using System.Net.Http;
using DSWeb.Common.Helper;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using DSWeb.Common.DB;
using DSWeb.Areas.Mobile.Models.WechatApplet;
using System.Runtime.Caching;
using DSWeb.MvcShipping.DAL.MsOpSeaeEdiDAL;
using DSWeb.Areas.CompanyManage.Helper;
using DSWeb.Areas.CompanyManage.Models;
using DSWeb.Areas.CommMng.DAL;
using DSWeb.DLL.SendEdiToYard;
using DSWeb.MvcShipping.Models.MsOpSeaeEdi;
using HcUtility.Comm;
using DSWeb.MvcShipping.Helper;
using System.IO;
using DSWeb.MvcShipping.DAL.MsCodeFtpSet;
using DSWeb.MvcShipping.Models.FtpSet;
using System.Data.Entity.Validation;
using DSWeb.Areas.MvcShipping.DAL.Message.vgm;
using DSWeb.MvcShipping.DAL.MsOpSeaeEdiVGM;
using System.Text;
using System.Net.Mail;
using System.Net.Mime;
using System.Net;
using System.Configuration;
using DSWeb.MvcShipping.DAL.MsOpSeaeYardDAL;
namespace DSWeb.Areas.Mobile.Controllers
{
public class WechatAppletController : Controller
{
private ILog log = LogManager.GetLogger("WechatApplet");
private CompanyDataContext companyData = new CompanyDataContext();
private EdiDataContext edi = new EdiDataContext();
private VgmDataContext vgm = new VgmDataContext();
private MskSubscribeDataContext msk = new MskSubscribeDataContext();
private BookingDB booking = new BookingDB();
private CommonDataContext common = new CommonDataContext();
public static string userid = null;
public static string showname = null;
public static string companyid = null;
public static string company = null;
public static string codename = null;
public void getinfo(string token)
{
var Url = ConfigurationManager.AppSettings["IdentServerUrl"].ToString();
Dictionary<string, string> dicHead = new Dictionary<string, string>();
dicHead.Add("Authorization", token);
string json = WebRequestHelper.DoGet(Url + "user/info", 3000, dicHead);
JObject jobjRtn = JObject.Parse(json);
var data = jobjRtn.GetValue("data").ToString();
JObject da = JObject.Parse(data);
userid = da.GetValue("gid").ToString();
showname = da.GetValue("showname").ToString();
companyid = da.GetValue("compId").ToString();
company = da.GetValue("comname").ToString();
codename = da.GetValue("codename").ToString();
}
#region 基础信息
/// <summary>
/// 消费记录
/// </summary>
[HttpGet]
public ActionResult GetConsumptionDataList(int page = 1, int limit = 10, string MBLNO = null, string HBLNO = null, string BCreate = null, string ECreate = null, int? BSTYPE = null)
{
RespPageData resp = new RespPageData();
if (Request.Headers.AllKeys.Contains("Authorization"))
{
getinfo(Request.Headers["Authorization"]);
var query = companyData.Cust_Fee.AsNoTracking().AsQueryable();
if (!string.IsNullOrWhiteSpace(MBLNO))
{
query = query.Where(x => x.MBLNO.IndexOf(MBLNO.Trim()) > -1);
}
if (!string.IsNullOrWhiteSpace(HBLNO))
{
query = query.Where(x => x.HBLNO.IndexOf(HBLNO.Trim()) > -1);
}
if (BSTYPE != null)
{
query = query.Where(x => x.BSTYPE == BSTYPE);
}
if (!string.IsNullOrWhiteSpace(BCreate))
{
var dtStart = DateTime.Parse(BCreate);
query = query.Where(o => o.CREATETIME >= dtStart);
}
if (!string.IsNullOrWhiteSpace(ECreate))
{
var dtEnd = DateTime.Parse(ECreate).AddDays(1);
query = query.Where(o => o.CREATETIME <= dtEnd);
}
query = query.OrderByDescending(x => x.CREATETIME);
#region 权限范围
var qAuth = from ur in common.UserAuthorityRanges.AsNoTracking()
join ua in common.UserAuthorityInfo.AsNoTracking() on ur.AUTHORITYID equals ua.GID
where ua.NAME == "modCustFee" && ur.USERID == userid
select ur;
var uaObj = qAuth.FirstOrDefault();
if (uaObj == null || uaObj.VISIBLERANGE == 3)
{
query = query.Where(u => u.SENDUSERID == userid);
}
else
if (uaObj.VISIBLERANGE == 1 || uaObj.VISIBLERANGE == 2 || uaObj.VISIBLERANGE == 7) //本公司
{
var ulist = common.Users.AsNoTracking()
.Where(uc => uc.CompId == companyid)
.Select(x => x.COMNAME)
.ToList();
query = query.Where(q => ulist.Contains(q.COMNAME));
}
else if (uaObj.VISIBLERANGE == 2) //本部门
{
query = query.Where(x => false); //不实现
}
else if (uaObj.VISIBLERANGE == 4) //无
{
query = query.Where(x => false);
}
else if (uaObj.VISIBLERANGE == 5) //选择公司
{
query = query.Where(x => false); //不实现
}
else if (uaObj.VISIBLERANGE == 6) //选择人员
{
query = query.Where(x => false); //不实现
}
#endregion
int count = query.Count();
var list = query.Skip(limit * (page - 1)).Take(limit).ToList();
var op_seae_edi_ctn = edi.EdiCtns.AsNoTracking().AsQueryable();
var op_seae_vgm_ctn = vgm.Ctns.AsNoTracking().AsQueryable();
var msk_subscribe_booking = msk.Bookings.AsNoTracking().AsQueryable();
var edis = edi.Edis.AsNoTracking().AsQueryable();
var vgms = vgm.Vgms.AsNoTracking().AsQueryable();
var datalist = (from m in list
select new CustFeeDto
{
GID = m.GID,
BSNO = m.BSNO,
PRICE = m.PRICE,
BSTYPE = m.BSTYPE,
SENDTYPE = m.SENDTYPE,
SENDTIME = m.SENDTIME != null ? Convert.ToDateTime(m.SENDTIME).ToString("yyyy-MM-dd HH:mm:ss") : "",
MBLNO = m.MBLNO,
HBLNO = m.HBLNO,
VESSEL = m.VESSEL,
VOYNO = m.VOYNO,
ETD = m.ETD != null ? Convert.ToDateTime(m.ETD).ToString("yyyy-MM-dd HH:mm:ss") : "",
CARRIER = m.CARRIER,
FORWARDER = m.FORWARDER,
SENDUSERID = m.SENDUSERID,
LURURENID = m.LURURENID,
LURUREN = m.LURUREN,
SENDUSER = m.SENDUSER,
SENDCOM = m.SENDCOM,
COMNAME = m.COMNAME,
COMID = m.COMID,
CANGKU = m.CANGKU,
BSSTATUS = m.BSSTATUS,
PORTDISCHARGE = m.PORTDISCHARGE,
DESTINATION = m.DESTINATION,
DESCRIPTION = m.DESCRIPTION,
MARKS = m.MARKS,
PKGS = m.PKGS,
KINDPKGS = m.KINDPKGS,
KGS = m.KGS,
CBM = m.CBM,
BEIZHU = m.BEIZHU,
BEIZHU2 = m.BEIZHU2,
CREATETIME = m.CREATETIME != null ? Convert.ToDateTime(m.CREATETIME).ToString("yyyy-MM-dd HH:mm:ss") : "",
CtnrCount = m.BSTYPE == 0 ? op_seae_edi_ctn.Where(x => x.MFNO == m.BSNO).Count() : m.BSTYPE == 1 ? op_seae_vgm_ctn.Where(x => x.MFNO == m.BSNO).Count() : m.BSTYPE == 4 ? msk_subscribe_booking.Where(x => x.BookingCode == m.MBLNO).Select(x => x.Quantity).FirstOrDefault() : m.CtnrCount,
CtnrInfo = m.CtnrInfo,
WeiTuoFaSongFang = m.BSTYPE == 0 ? edis.Where(x => x.MFNO == m.BSNO).Select(x => x.WeiTuoFaSongFang).FirstOrDefault() : m.BSTYPE == 1 ? vgms.Where(x => x.MFNO == m.BSNO).Select(x => x.WeiTuoFaSongFang).FirstOrDefault() : ""
}).ToList();
resp.Total = count;
resp.Success = true;
resp.Message = "查询成功";
resp.Code = 200;
resp.DataList = datalist;
}
else
{
resp.Success = false;
resp.Message = "非法访问";
resp.Code = -100;
}
return Json(resp, JsonRequestBehavior.AllowGet);
}
/// <summary>
/// 充值记录
/// </summary>
[HttpGet]
public ActionResult GetRechargeDataList(int page = 1, int limit = 10, string BCreate = null, string ECreate = null)
{
RespPageData resp = new RespPageData();
if (Request.Headers.AllKeys.Contains("Authorization"))
{
getinfo(Request.Headers["Authorization"]);
var query = companyData.Cust_CZ.AsNoTracking().AsQueryable();
if (!string.IsNullOrWhiteSpace(BCreate))
{
var dtStart = DateTime.Parse(BCreate);
query = query.Where(o => o.CZTIME >= dtStart);
}
if (!string.IsNullOrWhiteSpace(ECreate))
{
var dtEnd = DateTime.Parse(ECreate).AddDays(1);
query = query.Where(o => o.CZTIME <= dtEnd);
}
#region 权限范围
var qAuth = from ur in common.UserAuthorityRanges.AsNoTracking()
join ua in common.UserAuthorityInfo.AsNoTracking() on ur.AUTHORITYID equals ua.GID
where ua.NAME == "modCustCZJL" && ur.USERID == userid
select ur;
var uaObj = qAuth.FirstOrDefault();
if (uaObj.VISIBLERANGE == 1 || uaObj.VISIBLERANGE == 7 || uaObj.VISIBLERANGE == 3) //本公司
{
var ulist = common.Users.AsNoTracking()
.Where(uc => uc.CompId == companyid)
.Select(x => x.COMNAME)
.ToList();
query = query.Where(q => ulist.Contains(q.CZCOM));
}
else if (uaObj.VISIBLERANGE == 2) //本部门
{
query = query.Where(x => false); //不实现
}
else if (uaObj.VISIBLERANGE == 4) //无
{
query = query.Where(x => false);
}
else if (uaObj.VISIBLERANGE == 5) //选择公司
{
query = query.Where(x => false); //不实现
}
else if (uaObj.VISIBLERANGE == 6) //选择人员
{
query = query.Where(x => false); //不实现
}
#endregion
query = query.OrderByDescending(x => x.CZTIME);
int count = query.Count();
var list = query.Skip(limit * (page - 1)).Take(limit).ToList();
var datalist = from c in list
select new CustCZDto
{
GID = c.GID,
CZCOM = c.CZCOM,
COMID = c.COMID,
CZJE = c.CZJE,
CZYE = c.CZYE,
CZTIME = c.CZTIME != null ? Convert.ToDateTime(c.CZTIME).ToString("yyyy-MM-dd HH:mm:ss") : "",
FPPath = c.FPPath
};
resp.Total = count;
resp.Success = true;
resp.Message = "查询成功";
resp.Code = 200;
resp.DataList = datalist;
}
else
{
resp.Success = false;
resp.Message = "非法访问";
resp.Code = -100;
}
return Json(resp, JsonRequestBehavior.AllowGet);
}
//获取当前用户手机验证码
[HttpPost]
public ActionResult GetCurrentUserMobileCode()
{
RespCommon resp = new RespCommon();
if (Request.Headers.AllKeys.Contains("Authorization"))
{
getinfo(Request.Headers["Authorization"]);
var usr = companyData.UserBases.AsNoTracking().FirstOrDefault(c => c.USERID == userid);
if (usr != null)
{
if (MemoryCache.Default.Contains(usr.MOBILE))
{
resp.Success = false;
resp.Message = "获取验证码过于频繁";
}
else
{
Random rnd = new Random();
string code = rnd.Next(100000, 999999).ToString();
MemoryCache.Default.Add(new CacheItem(usr.MOBILE, code), new CacheItemPolicy() { AbsoluteExpiration = DateTime.Now.AddMinutes(1) });
AliMessageTools.SendSignCodeMsg(usr.MOBILE, code);
resp.Success = true;
resp.Message = "验证码发送成功";
}
}
else
{
resp.Success = false;
resp.Message = "未找到用户信息";
}
}
else
{
resp.Success = false;
resp.Message = "非法访问";
resp.Code = -100;
}
return Json(resp);
}
//获取手机号验证码
[HttpPost]
public ActionResult GetMobileCode(string mobile)
{
RespCommon resp = new RespCommon();
if (Request.Headers.AllKeys.Contains("Authorization"))
{
if (MemoryCache.Default.Contains(mobile))
{
resp.Success = false;
resp.Message = "获取验证码过于频繁";
}
else
{
Random rnd = new Random();
string code = rnd.Next(100000, 999999).ToString();
MemoryCache.Default.Add(new CacheItem(mobile, code), new CacheItemPolicy() { AbsoluteExpiration = DateTime.Now.AddMinutes(1) });
AliMessageTools.SendSignCodeMsg(mobile, code);
resp.Success = true;
resp.Message = "验证码发送成功";
}
}
else
{
resp.Success = false;
resp.Message = "非法访问";
resp.Code = -100;
}
return Json(resp);
}
//提交离职
[HttpPost]
public ActionResult _LeaveSubmit(string mobileCode)
{
RespCommon resp = new RespCommon();
if (Request.Headers.AllKeys.Contains("Authorization"))
{
getinfo(Request.Headers["Authorization"]);
var user = companyData.Users.FirstOrDefault(u => u.GID == userid);
var usrbase = companyData.UserBases.FirstOrDefault(c => c.USERID == userid);
var comp = companyData.CompanyNew.AsNoTracking().FirstOrDefault(c => c.CompId == user.CompId);
if (MemoryCache.Default.Contains(usrbase.MOBILE))
{
string val = MemoryCache.Default[usrbase.MOBILE].ToString();
if (val == mobileCode)
{
EmployeeHelper.Leave(userid);
resp.Success = true;
resp.Message = "离职成功";
}
else
{
resp.Success = false;
resp.Message = "验证码错误";
}
}
else
{
resp.Success = false;
resp.Message = "验证码错误";
}
}
else
{
resp.Success = false;
resp.Message = "非法访问";
resp.Code = -100;
}
return Json(resp);
}
/// 修改密码
[HttpPost]
public ActionResult ChgPwdSubmit(ChangePasswordModel model)
{
RespCommon resp = new RespCommon();
if (Request.Headers.AllKeys.Contains("Authorization"))
{
getinfo(Request.Headers["Authorization"]);
var usr = companyData.Users.FirstOrDefault(c => c.GID == model.GID);
var usrbase = companyData.UserBases.FirstOrDefault(c => c.USERID == model.GID);
if (usr != null && usrbase != null)
{
if (usr.PASSWORD == model.PwdSrc)
{
if (model.PwdSrc != model.PwdNew)
{
if (MemoryCache.Default.Contains(usrbase.MOBILE))
{
string val = MemoryCache.Default[usrbase.MOBILE].ToString();
if (val == model.MobileCode)
{
usr.PASSWORD = model.PwdNew;
usr.IsAlterPass = false;
companyData.SaveChanges();
resp.Success = true;
resp.Message = "修改成功";
}
else
{
resp.Success = false;
resp.Message = "验证码错误";
}
}
else
{
resp.Success = false;
resp.Message = "验证码错误";
}
}
else
{
resp.Success = false;
resp.Message = "新旧密码一致!不能更改";
}
}
else
{
resp.Success = false;
resp.Message = "原始密码输入错误";
}
}
else
{
resp.Success = false;
resp.Message = "未找到用户";
}
}
else
{
resp.Success = false;
resp.Message = "非法访问";
resp.Code = -100;
}
return Json(resp);
}
/// <summary>
/// 更换手机号
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
[HttpPost]
public ActionResult _ChangeMobileSubmit(ChangeMobileModel model)
{
RespCommon resp = new RespCommon();
if (Request.Headers.AllKeys.Contains("Authorization"))
{
getinfo(Request.Headers["Authorization"]);
var usr = companyData.UserBases.AsNoTracking().FirstOrDefault(c => c.USERID == userid);
var usrbase = companyData.UserBases.FirstOrDefault(c => c.USERID == userid);
if (usr != null && usrbase != null)
{
if (MemoryCache.Default.Contains(usrbase.MOBILE) && MemoryCache.Default.Contains(model.MobileNew))
{
string valSrc = MemoryCache.Default[usrbase.MOBILE].ToString();
string valNew = MemoryCache.Default[model.MobileNew].ToString();
if (valSrc == model.CodeSrc && valNew == model.CodeNew)
{
usrbase.MOBILE = model.MobileNew;
companyData.SaveChanges();
resp.Success = true;
resp.Message = "修改成功";
}
else
{
resp.Success = false;
resp.Message = "验证码错误";
}
}
else
{
resp.Success = false;
resp.Message = "验证码错误";
}
}
else
{
resp.Success = false;
resp.Message = "未找到用户";
}
}
else
{
resp.Success = false;
resp.Message = "未找到用户信息";
}
return Json(resp);
}
//获取个人信息
[HttpGet]
public ActionResult GetInfo()
{
RespCommonData resp = new RespCommonData();
if (Request.Headers.AllKeys.Contains("Authorization"))
{
getinfo(Request.Headers["Authorization"]);
var query = (from user in companyData.Users
join userbase in companyData.UserBases on user.GID equals userbase.USERID
into ml
from c in ml.DefaultIfEmpty()
join balan in companyData.Cust_Balance on user.COMNAME equals balan.COMNAME
into ml1
from c1 in ml1.DefaultIfEmpty()
join com in companyData.CompanyNew on user.CompId equals com.CompId
into com1
from cc1 in com1.DefaultIfEmpty()
where user.GID == userid
select new
{
SHOWNAME = user.SHOWNAME,
USERNAME = user.USERNAME,
MOBILE = c.MOBILE,
OFFICEPHONE = c.OFFICEPHONE,
EMAIL1 = c.EMAIL1,
QQ = c.QQ,
Balance = user.IsLeave ? c1.Balance : 0,
Isleave = user.IsLeave,
CompName = cc1.CompName,
AuditStatus = cc1.AuditStatus,
IsAdminUser = cc1.AdminUser == user.GID ? true : false,
}).FirstOrDefault();
resp.Success = true;
resp.Message = "获取成功";
resp.Code = 200;
resp.Data = query;
}
else
{
resp.Success = false;
resp.Message = "非法访问";
resp.Code = -100;
}
return Json(resp, JsonRequestBehavior.AllowGet);
}
//修改个人信息
[HttpPost]
public ActionResult EditSubmit(UserEditModel model)
{
RespCommon resp = new RespCommon();
if (Request.Headers.AllKeys.Contains("Authorization"))
{
getinfo(Request.Headers["Authorization"]);
var user = companyData.Users.FirstOrDefault(c => c.GID == userid);
var usrbase = companyData.UserBases.FirstOrDefault(c => c.USERID == userid);
if (user != null && usrbase != null && model.GID != null)
{
if (usrbase.EMAIL1 != model.EMAIL1)
{
var emailOtherUse = companyData.UserBases.Where(ub => ub.EMAIL1 == model.EMAIL1 && ub.USERID != model.GID).Count();
if (emailOtherUse > 0)
{
resp.Success = false;
resp.Message = "邮箱已被使用,请更换其他邮箱";
resp.Code = 201;
return Json(resp);
}
}
usrbase.OFFICEPHONE = model.OFFICEPHONE;
usrbase.EMAIL1 = model.EMAIL1;
usrbase.QQ = model.QQ;
if (string.IsNullOrEmpty(model.USERNAME))
{
user.USERNAME = string.Empty;
}
else
{
user.USERNAME = model.USERNAME;
}
if (string.IsNullOrEmpty(model.SHOWNAME))
{
user.SHOWNAME = string.Empty;
}
else
{
user.SHOWNAME = model.SHOWNAME;
}
companyData.SaveChanges();
resp.Success = true;
resp.Message = "保存成功";
resp.Code = 200;
}
else
{
resp.Success = false;
resp.Message = "未接收到有效数据";
resp.Code = 201;
}
}
else
{
resp.Success = false;
resp.Message = "非法访问";
resp.Code = -100;
}
return Json(resp);
}
#endregion
#region 舱单
[HttpGet]
public ActionResult GetMsOpSeaeEdiList(int page = 1, int limit = 10, string MBLNO = null, string HBLNO = null, string EDISTATUS = null, string BCreate = null, string ECreate = null,string BSNO = null)
{
RespPageData resp = new RespPageData();
if (Request.Headers.AllKeys.Contains("Authorization"))
{
getinfo(Request.Headers["Authorization"]);
string[] sta = { "接受申报", "运抵正常", "报关单放行", "装载放行", "回执异常", "船未备案", "港内换船未办好", "正在换关区", "船舶已离港", "未找到相应船舶", "船舶取消挂靠青岛", "无效提单号" };
var status_qdport = edi.op_seae_edi_status_qdport.AsNoTracking().AsQueryable();
var status_qdportdanchuan = edi.op_seae_edi_status_qdportdanchuan.AsNoTracking().AsQueryable();
var mainlist = edi.Edis.AsNoTracking().AsQueryable();
if (!string.IsNullOrEmpty(MBLNO))
{
mainlist = mainlist.Where(x => x.MBLNO == MBLNO);
}
if (!string.IsNullOrEmpty(HBLNO))
{
mainlist = mainlist.Where(x => x.HBLNO == HBLNO);
}
if (!string.IsNullOrEmpty(EDISTATUS))
{
mainlist = mainlist.Where(x => x.EDISTATUS == EDISTATUS);
}
if (!string.IsNullOrEmpty(BCreate))
{
mainlist = mainlist.Where(x => Convert.ToDateTime(x.EDISTATUS) >= Convert.ToDateTime(BCreate));
}
if (!string.IsNullOrEmpty(ECreate))
{
mainlist = mainlist.Where(x => Convert.ToDateTime(x.EDISTATUS) <= Convert.ToDateTime(ECreate));
}
if (!string.IsNullOrEmpty(BSNO))
{
mainlist = mainlist.Where(x =>x.BSNO==BSNO);
}
mainlist = mainlist.OrderByDescending(x => x.INPUTDATE);
#region 权限范围
var qAuth = from ur in common.UserAuthorityRanges.AsNoTracking()
join ua in common.UserAuthorityInfo.AsNoTracking() on ur.AUTHORITYID equals ua.GID
where ua.NAME == "modCDList" && ur.USERID == userid
select ur;
var uaObj = qAuth.FirstOrDefault();
if (uaObj == null || uaObj.VISIBLERANGE == 3)
{
mainlist = mainlist.Where(u => u.INPUTBYID == userid);
}
else if (uaObj.VISIBLERANGE == 1 || uaObj.VISIBLERANGE == 2 || uaObj.VISIBLERANGE == 7) //本公司
{
var ulist = common.Users.AsNoTracking()
.Where(uc => uc.CompId == companyid)
.Select(x => x.GID)
.ToList();
mainlist = mainlist.Where(q => ulist.Contains(q.INPUTBYID));
}
else if (uaObj.VISIBLERANGE == 2) //本部门
{
mainlist = mainlist.Where(x => false); //不实现
}
else if (uaObj.VISIBLERANGE == 4) //无
{
mainlist = mainlist.Where(x => false);
}
else if (uaObj.VISIBLERANGE == 5) //选择公司
{
mainlist = mainlist.Where(x => false); //不实现
}
else if (uaObj.VISIBLERANGE == 6) //选择人员
{
mainlist = mainlist.Where(x => false); //不实现
}
#endregion
int count = mainlist.Count();
var list = mainlist.Skip(limit * (page - 1)).Take(limit).ToList();
var statuslist = edi.op_seae_edi_status.AsNoTracking().AsQueryable().Where(x => sta.Contains(x.statustext)).ToList();
var op_seae_edi_ctn = edi.EdiCtns.AsNoTracking().AsQueryable();
var OP_SEAE_EDI_TIPS = edi.OP_SEAE_EDI_TIPS.AsNoTracking().AsQueryable();
var query = (from main in list
select new MsOpSeaeEdiDto
{
MFNO = main.MFNO,
BSNO = main.BSNO,
EDISTATUS = main.EDISTATUS,
MBLNO = main.MBLNO,
HBLNO = main.HBLNO,
VESSEL = main.VESSEL,
FORWARDER = main.FORWARDER,
VOYNO = main.VOYNO,
ETD = main.ETD == null ? null : main.ETD.Value.ToShortDateString(),
PORTLOAD = main.PORTLOAD,
PORTLOADID = main.PORTLOADID,
PORTDISCHARGE = main.PORTDISCHARGE,
statustext = statuslist.Where(x => x.mfno == main.MFNO).Select(x => x.statustext).FirstOrDefault(),
statustime = statuslist.Where(x => x.mfno == main.MFNO).Count() == 0 ? null :
statuslist.Where(x => x.mfno == main.MFNO).Select(x => x.statustime).FirstOrDefault().ToShortDateString(),
ShenBaoXiangShu = statuslist.Where(x => x.mfno == main.MFNO).Select(x => x.ShenBaoXiangShu).FirstOrDefault(),
statusMTFX = status_qdport.Where(x => x.statustext == "码头放行" && x.mblno == main.MFNO).Count() == 1 ? 1 : status_qdport.Where(x => x.statustext == "码头未放行" && x.mblno == main.MFNO).Count() == 1 ? 0 : 2,
statusWLFX = status_qdport.Where(x => x.statustext == "外理放行" && x.mblno == main.MFNO).Count(),
YJDGSJ = status_qdportdanchuan.Where(x => x.mblno == main.MFNO).Select(x => x.etatime).FirstOrDefault(),
YJLGSJ = status_qdportdanchuan.Where(x => x.mblno == main.MFNO).Select(x => x.etdtime).FirstOrDefault(),
INPUTBY = main.INPUTBY,
INPUTDATE = main.INPUTDATE == null ? null : main.INPUTDATE.Value.ToShortDateString(),
PKGS = main.PKGS == null ? null : main.PKGS,
KGS = main.KGS == null ? null : main.KGS,
CBM = main.CBM == null ? null : main.CBM,
REMARKS = main.REMARKS,
WeiTuoFaSongFang = main.WeiTuoFaSongFang,
CARRIER = main.CARRIER,
comname = company,
QueRenWanCheng = main.QueRenWanCheng,
DESCRIPTION = main.DESCRIPTION,
SHIPPERNAME = main.SHIPPERNAME,
SHIPPERADDR1 = main.SHIPPERADDR1,
SHIPPERCOUNTRY = main.SHIPPERCOUNTRY,
SHIPPERCODE = main.SHIPPERCODE,
LeiXingFa = main.LeiXingFa,
CONSIGNEENAME = main.CONSIGNEENAME,
CONSIGNEEADDR1 = main.CONSIGNEEADDR1,
CONSIGNEECOUNTRY = main.CONSIGNEECOUNTRY,
CONSIGNEETEL = main.CONSIGNEETEL,
CONSIGNEECODE = main.CONSIGNEECODE,
LeiXingshou = main.LeiXingShou,
NOTIFYPARTYName = main.NOTIFYPARTYNAME,
NOTIFYPARTYADDR1 = main.NOTIFYPARTYADDR1,
NOTIFYPARTYCOUNTRY = main.NOTIFYPARTYCOUNTRY,
NOTIFYPARTYTEL = main.NOTIFYPARTYTEL,
NOTIFYPARTYCODE = main.NOTIFYPARTYCODE,
LeiXingTong = main.LeiXingTong,
PLACEDELIVERYID = main.PLACEDELIVERYID,
PLACEDELIVERY = main.PLACEDELIVERY,
PORTDISCHARGEID = main.PORTDISCHARGEID,
DESTINATIONID = main.DESTINATIONID,
DESTINATION = main.DESTINATION,
MARKS = main.MARKS,
CARGOID = main.CARGOID,
KINDPKGS = main.KINDPKGS,
TEMPSET = main.TEMPSET,
TEMPID = main.TEMPID,
REEFERF = main.REEFERF,
JiZhuangXiang = main.JiZhuangXiang,
DCLASS = main.DCLASS,
DUNNO = main.DUNNO,
DATTN = main.DATTN,
DTEL = main.DTEL,
ISNOR = main.ISNOR,
SHIPIMO = main.SHIPIMO,
ORDERNO = main.ORDERNO,
EdiCtns = op_seae_edi_ctn.Where(x => x.MFNO == main.MFNO).ToList(),
OP_SEAE_EDI_TIPS = OP_SEAE_EDI_TIPS.Where(x => x.MFNO == main.MFNO).ToList()
}).ToList();
resp.Total = count;
resp.Success = true;
resp.Message = "查询成功";
resp.Code = 200;
resp.DataList = query;
}
else
{
resp.Success = false;
resp.Message = "非法访问";
resp.Code = -100;
}
return Json(resp, JsonRequestBehavior.AllowGet);
}
//获取船名
[HttpGet]
public ActionResult GetVesselList(int page = 1, int limit = 10)
{
RespPageData resp = new RespPageData();
var query = edi.codevessel.AsNoTracking().AsQueryable().OrderBy(x=>x.vessel);
resp.Total = query.Count();
resp.Success = true;
resp.Message = "查询成功";
resp.Code = 200;
resp.DataList = query.Skip(limit * (page - 1)).Take(limit).ToList();
return Json(resp, JsonRequestBehavior.AllowGet);
}
//获取船代
[HttpGet]
public ActionResult GetCustomRefListSHIPAGENCY()
{
RespPageData resp = new RespPageData();
var query = common.InfoClients.AsNoTracking().AsQueryable().Where(x => x.ISSHIPAGENCY == true && x.LOADPORT == "QINGDAO,CHINA").OrderBy(x => x.CODENAME).Select(x => new CustomRefListSHIPAGENCYDto
{
Gid = x.GID,
CustCode = x.CODENAME,
CustName = x.SHORTNAME,
CodeAndName = x.CODENAME + "-" + x.CODENAME,
BillRises1 = x.BillRises1,
UNITPRICE = x.UNITPRICE,
Description = x.DESCRIPTION,
KFCodename = x.SHORTNAME + "-" + x.DESCRIPTION,
SALE = x.SALE,
FEEFRT = x.FEEFRT,
BSSOURCE = x.BSSOURCE,
EMAIL = x.EMAIL,
TEL = x.TEL,
SALECORPID = x.SALECORPID
});
resp.Total = query.Count();
resp.Success = true;
resp.Message = "查询成功";
resp.Code = 200;
resp.DataList = query.ToList();
return Json(resp, JsonRequestBehavior.AllowGet);
}
//船公司
[HttpGet]
public ActionResult GetCustomRefListCARRIER(int page = 1, int limit = 10)
{
RespPageData resp = new RespPageData();
var query = common.InfoClients.AsNoTracking().AsQueryable().Where(x => x.ISCARRIER == true).OrderBy(x => x.CODENAME).Select(x => new CustomRefListSHIPAGENCYDto
{
Gid = x.GID,
CustCode = x.CODENAME,
CustName = x.SHORTNAME,
CodeAndName = x.CODENAME + "-" + x.CODENAME,
BillRises1 = x.BillRises1,
UNITPRICE = x.UNITPRICE,
Description = x.DESCRIPTION,
KFCodename = x.SHORTNAME + "-" + x.DESCRIPTION,
SALE = x.SALE,
FEEFRT = x.FEEFRT,
BSSOURCE = x.BSSOURCE,
EMAIL = x.EMAIL,
TEL = x.TEL,
SALECORPID = x.SALECORPID
});
resp.Total = query.Count();
resp.Success = true;
resp.Message = "查询成功";
resp.Code = 200;
resp.DataList = query.Skip(limit * (page - 1)).Take(limit).ToList();
return Json(resp, JsonRequestBehavior.AllowGet);
}
//国家
[HttpGet]
public ActionResult GetCountryList(int page = 1, int limit = 10)
{
RespPageData resp = new RespPageData();
var query = common.syscountrycode.AsNoTracking().AsQueryable().Select(x => new CountryDto
{
CodeAndName = x.CountryCode + "-" + x.CountryName,
CountryCode = x.CountryCode,
CountryName = x.CountryName,
CountryNameEn = x.CountryNameEn
}).Distinct().OrderBy(x=>x.CountryCode);
resp.Total = query.Count();
resp.Success = true;
resp.Message = "查询成功";
resp.Code = 200;
resp.DataList = query.Skip(limit * (page - 1)).Take(limit).ToList();
return Json(resp, JsonRequestBehavior.AllowGet);
}
/// <summary>
/// 国家类型
/// </summary>
/// <returns></returns>
[HttpGet]
public ActionResult GetCountryTypeList(string code)
{
RespPageData resp = new RespPageData();
var query = common.syscountrycode.AsNoTracking().AsQueryable().Where(x => x.CountryCode == code).Select(x => new
{
CompanyCodeType = x.CompanyCodeType
}).Distinct();
resp.Total = query.Count();
resp.Success = true;
resp.Message = "查询成功";
resp.Code = 200;
resp.DataList = query.ToList();
return Json(resp, JsonRequestBehavior.AllowGet);
}
/// <summary>
/// 收发通
/// </summary>
/// <returns></returns>
[HttpGet]
public ActionResult GetSFTDataList(string Type)
{
RespPageData resp = new RespPageData();
if (Request.Headers.AllKeys.Contains("Authorization"))
{
getinfo(Request.Headers["Authorization"]);
var query = edi.EDI_TEMPLATE.AsNoTracking().AsQueryable().Where(x => x.TYPE == Type && x.USERID == userid).Distinct();
resp.Total = query.Count();
resp.Success = true;
resp.Message = "查询成功";
resp.Code = 200;
resp.DataList = query.ToList();
}
return Json(resp, JsonRequestBehavior.AllowGet);
}
/// <summary>
/// 委托方
/// </summary>
/// <returns></returns>
[HttpGet]
public ActionResult GetWTFDataList()
{
RespPageData resp = new RespPageData();
if (Request.Headers.AllKeys.Contains("Authorization"))
{
getinfo(Request.Headers["Authorization"]);
var query = booking.Clients.AsNoTracking().AsQueryable().Where(x => x.CompId == companyid).Select(x => new
{
CodeName = x.CODENAME,
ShowName = x.SHORTNAME,
}).Distinct();
resp.Total = query.Count();
resp.Success = true;
resp.Message = "查询成功";
resp.Code = 200;
resp.DataList = query.ToList();
}
return Json(resp, JsonRequestBehavior.AllowGet);
}
/// <summary>
/// 装货港
/// </summary>
/// <returns></returns>
[HttpGet]
public ActionResult GetCodeLoadportList()
{
RespPageData resp = new RespPageData();
var query = common.Loadports.AsNoTracking().AsQueryable().Select(x => new
{
PORTID = x.PORTID,
PORT = x.PORT,
CNAME = x.CNAME,
EDICODE = x.EDICODE,
CodeAndName = x.PORT + "-" + x.CNAME
}).Distinct();
resp.Total = query.Count();
resp.Success = true;
resp.Message = "查询成功";
resp.Code = 200;
resp.DataList = query.ToList();
return Json(resp, JsonRequestBehavior.AllowGet);
}
/// <summary>
/// 收货地 卸货港 目的地
/// </summary>
/// <returns></returns>
[HttpGet]
public ActionResult GetCodeDisportListRm(int page = 1, int limit = 10,string strlink=null)
{
RespPageData resp = new RespPageData();
if (strlink == null)
{
var query = from m in common.Disports.AsNoTracking().AsQueryable()
join n in common.CodeLanes.AsNoTracking().AsQueryable() on m.LANEGID equals n.GID
into ml1
from c1 in ml1.DefaultIfEmpty()
orderby m.EDICODE
select new
{
EDICODE = m.EDICODE,
CodeAndName = m.PORT + "-" + m.EDICODE
};
resp.Total = query.Count();
resp.Success = true;
resp.Message = "查询成功";
resp.Code = 200;
resp.DataList = query.Skip(limit * (page - 1)).Take(limit).ToList();
}
else {
var query = from m in common.Disports.AsNoTracking().AsQueryable()
join n in common.CodeLanes.AsNoTracking().AsQueryable() on m.LANEGID equals n.GID
into ml1
from c1 in ml1.DefaultIfEmpty()
where m.PORT.StartsWith(strlink)
orderby m.EDICODE
select new
{
EDICODE = m.EDICODE,
CodeAndName = m.PORT + "-" + m.EDICODE
};
resp.Total = query.Count();
resp.Success = true;
resp.Message = "查询成功";
resp.Code = 200;
resp.DataList = query.Skip(limit * (page - 1)).Take(limit).ToList();
}
return Json(resp, JsonRequestBehavior.AllowGet);
}
/// <summary>
/// 箱型
/// </summary>
/// <returns></returns>
[HttpGet]
public ActionResult GetCodeCtnList()
{
RespPageData resp = new RespPageData();
var query = edi.Code_Ctn.AsNoTracking().AsQueryable().Distinct();
resp.Total = query.Count();
resp.Success = true;
resp.Message = "查询成功";
resp.Code = 200;
resp.DataList = query.ToList();
return Json(resp, JsonRequestBehavior.AllowGet);
}
/// <summary>
/// 包装
/// </summary>
/// <returns></returns>
[HttpGet]
public ActionResult GetCodePackageList()
{
RespPageData resp = new RespPageData();
var query = common.Packages.AsNoTracking().AsQueryable().Distinct();
resp.Total = query.Count();
resp.Success = true;
resp.Message = "查询成功";
resp.Code = 200;
resp.DataList = query.ToList();
return Json(resp, JsonRequestBehavior.AllowGet);
}
/// <summary>
/// 场站
/// </summary>
/// <param name="CODENAME"></param>
/// <returns></returns>
[HttpGet]
public ContentResult GetCustomRefListYARD()
{
var condition = " ISYARD=1 ";
var evList = BasicDataRefDAL.GetCustomRefList(condition);
if (evList.Count == 0)
{
var json = JsonConvert.Serialize(new { success = false });
return new ContentResult() { Content = json };
}
else
{
var json = JsonConvert.Serialize(new { success = true, data = evList.ToList() });
return new ContentResult() { Content = json };
}
}
/// <summary>
///新增/编辑
/// </summary>
/// <param name="Dto"></param>
/// <returns></returns>
[HttpPost]
public ActionResult SaveOpSeaeEdi(string json)
{
MsOpSeaeEdiDto Dto = JsonConvert.Deserialize<MsOpSeaeEdiDto>(json);
RespCommon resp = new RespCommon();
if (Request.Headers.AllKeys.Contains("Authorization"))
{
getinfo(Request.Headers["Authorization"]);
////校验规则
if (string.IsNullOrWhiteSpace(Dto.MBLNO))
{
resp.Success = false;
resp.Message = "主提单号不能为空";
resp.Code = 201;
return Json(resp);
}
if (string.IsNullOrWhiteSpace(Dto.ETD))
{
resp.Success = false;
resp.Message = "开船日期不能为空";
resp.Code = 201;
return Json(resp);
}
else if (Convert.ToDateTime(Dto.ETD) < BasicDataRefDAL.GetDateZero(1))
{
resp.Success = false;
resp.Message = "请检查开船日期";
resp.Code = 201;
return Json(resp);
}
//分单号主单号不能重复
if (Dto.HBLNO.Equals(Dto.MBLNO))
{
resp.Message = "主单号与分单号不能一致";
resp.Code = 201;
return Json(resp);
}
var opse = edi.Edis.AsNoTracking().AsQueryable();
String BSNO = null;
if (!string.IsNullOrWhiteSpace(Dto.HBLNO))
{
BSNO = opse.Where(x => x.MBLNO == Dto.MBLNO && (x.HBLNO == null || x.HBLNO == "")).Select(x => x.MFNO).FirstOrDefault();
}
if (string.IsNullOrWhiteSpace(Dto.MFNO))
{
if (opse.Where(x => x.MBLNO == Dto.MBLNO).Count() > 0)
{
resp.Message = "主提单号已存在";
resp.Code = 201;
return Json(resp);
}
if (!string.IsNullOrWhiteSpace(Dto.HBLNO))
{
if (opse.Where(x => x.HBLNO == Dto.HBLNO).Count() > 0)
{
resp.Message = "分提单号已存在";
resp.Code = 201;
return Json(resp);
}
}
string guid = Guid.NewGuid().ToString("D");
OpSeaeEdi opSeaeEdi = new OpSeaeEdi();
opSeaeEdi.MFNO = guid;
opSeaeEdi.BSNO = BSNO;
opSeaeEdi.EDISTATUS = "已录入";
opSeaeEdi.INPUTBY = showname;
opSeaeEdi.INPUTDATE = DateTime.Now;
opSeaeEdi.CORPID = companyid;
opSeaeEdi.MBLNO = Dto.MBLNO;
opSeaeEdi.HBLNO = Dto.HBLNO;
opSeaeEdi.ETD = Convert.ToDateTime(Dto.ETD);
opSeaeEdi.FORWARDER = Dto.FORWARDER;
opSeaeEdi.VESSEL = Dto.VESSEL;
opSeaeEdi.VOYNO = Dto.VOYNO;
opSeaeEdi.SHIPIMO = Dto.SHIPIMO;
opSeaeEdi.CARRIER = Dto.CARRIER;
if (string.IsNullOrWhiteSpace(Dto.ETA))
{
opSeaeEdi.ETA = null;
}
opSeaeEdi.ETA = Convert.ToDateTime(Dto.ETA);
opSeaeEdi.WeiTuoFaSongFang = Dto.WeiTuoFaSongFang;
opSeaeEdi.ORDERNO = Dto.ORDERNO;
opSeaeEdi.REMARKS = Dto.REMARKS;
opSeaeEdi.SHIPPERNAME = Dto.SHIPPERNAME;
opSeaeEdi.SHIPPERADDR1 = Dto.SHIPPERADDR1;
opSeaeEdi.SHIPPERCOUNTRY = Dto.SHIPPERCOUNTRY;
opSeaeEdi.SHIPPERTEL = Dto.SHIPPERTEL;
opSeaeEdi.SHIPPERCODE = Dto.SHIPPERCODE;
opSeaeEdi.LeiXingFa = Dto.LeiXingFa;
opSeaeEdi.CONSIGNEENAME = Dto.CONSIGNEENAME;
opSeaeEdi.CONSIGNEEADDR1 = Dto.CONSIGNEEADDR1;
opSeaeEdi.CONSIGNEECOUNTRY = Dto.CONSIGNEECOUNTRY;
opSeaeEdi.CONSIGNEETEL = Dto.CONSIGNEETEL;
opSeaeEdi.CONSIGNEECODE = Dto.CONSIGNEECODE;
opSeaeEdi.LeiXingShou = Dto.LeiXingshou;
opSeaeEdi.NOTIFYPARTYNAME = Dto.NOTIFYPARTYName;
opSeaeEdi.NOTIFYPARTYADDR1 = Dto.NOTIFYPARTYADDR1;
opSeaeEdi.NOTIFYPARTYCOUNTRY = Dto.NOTIFYPARTYCOUNTRY;
opSeaeEdi.NOTIFYPARTYTEL = Dto.NOTIFYPARTYTEL;
opSeaeEdi.NOTIFYPARTYCODE = Dto.NOTIFYPARTYCODE;
opSeaeEdi.LeiXingTong = Dto.LeiXingTong;
opSeaeEdi.PORTLOAD = Dto.PORTLOAD;
opSeaeEdi.PORTLOADID = Dto.PORTLOADID;
opSeaeEdi.PLACEDELIVERYID = Dto.PLACEDELIVERYID;
opSeaeEdi.PLACEDELIVERY = Dto.PLACEDELIVERY;
opSeaeEdi.PORTDISCHARGE = Dto.PORTDISCHARGE;
opSeaeEdi.PORTDISCHARGEID = Dto.PORTDISCHARGEID;
opSeaeEdi.DESTINATIONID = Dto.DESTINATIONID;
opSeaeEdi.DESTINATION = Dto.DESTINATION;
opSeaeEdi.MARKS = Dto.MARKS;
opSeaeEdi.DESCRIPTION = Dto.DESCRIPTION;
opSeaeEdi.ISNOR = Dto.ISNOR;
opSeaeEdi.QueRenWanCheng = Dto.QueRenWanCheng;
int? PKGS = 0;
decimal? KGS = 0;
decimal? CBM = 0;
string ctnTemp = "";
//bool IsDongGui = false;
string ctnStr = "";
foreach (var item in Dto.EdiCtns)
{
OpSeaeEdiCtn opSeaeEdictn = new OpSeaeEdiCtn();
opSeaeEdictn.CTNCODE = item.CTNCODE;
opSeaeEdictn.CTNALL = item.CTNALL;
opSeaeEdictn.CNTRNO = item.CNTRNO;
opSeaeEdictn.SEALNO = item.SEALNO;
opSeaeEdictn.PKGS = item.PKGS;
PKGS += item.PKGS;
opSeaeEdictn.KINDPKGS = item.KINDPKGS;
opSeaeEdictn.KGS = item.KGS;
KGS += item.KGS;
opSeaeEdictn.CBM = item.CBM;
CBM += item.CBM;
opSeaeEdictn.PIZHONG = item.PIZHONG;
opSeaeEdictn.ShiFengRen = item.ShiFengRen;
opSeaeEdictn.ZhongKongBiaoShi = item.ZhongKongBiaoShi;
opSeaeEdictn.ChengZhongFangShi = item.ChengZhongFangShi;
opSeaeEdictn.ChengZhongZhongLiang = item.ChengZhongZhongLiang;
opSeaeEdictn.ChengZhongShiJian = item.ChengZhongShiJian;
ctnTemp = item.CTNALL;
List<OpSeaeEdiCtn> list = Dto.EdiCtns.FindAll(b => b.CTNALL == ctnTemp).ToList();
if (list.Count != 0)
{
ctnStr += ctnTemp + "*" + list.Count.ToString() + ",";
Dto.EdiCtns.RemoveAll(a => a.CTNALL == ctnTemp);
}
//if (item.CTNALL.Contains("RH") || item.CTNALL.Contains("RF") || item.CTNALL.Contains("RQ"))
//{
// IsDongGui = true;
//}
edi.EdiCtns.Add(opSeaeEdictn);
}
//if (IsDongGui)
//{
// opSeaeEdi.CARGOID = "R";
//}
//else
//{
opSeaeEdi.CARGOID = Dto.CARGOID;
// }
if (ctnStr.Length > 0)
{
ctnStr = ctnStr.Substring(0, ctnStr.Length - 1);
}
opSeaeEdi.JiZhuangXiang = ctnStr;
opSeaeEdi.PKGS = PKGS;
opSeaeEdi.KGS = KGS;
opSeaeEdi.CBM = CBM;
edi.Edis.Add(opSeaeEdi);
OP_SEAE_EDI_TIPS_md tipe = new OP_SEAE_EDI_TIPS_md();
tipe.GID = Guid.NewGuid().ToString("D");
tipe.MFNO = guid;
tipe.TIPSTIME = DateTime.Now;
tipe.TIPS = "新建舱单保存";
tipe.CREATETIME = DateTime.Now;
tipe.MBLNO = Dto.MBLNO;
tipe.HBLNO = Dto.HBLNO;
tipe.OPERATOR = showname;
tipe.OPTYPE = "新增";
tipe.FORWARDER = Dto.FORWARDER;
edi.OP_SEAE_EDI_TIPS.Add(tipe);
}
else
{
if (opse.Where(x => x.MBLNO == Dto.MBLNO && x.MFNO != Dto.MFNO).Count() > 0)
{
resp.Message = "主提单号已存在";
resp.Code = 201;
return Json(resp);
}
if (!string.IsNullOrWhiteSpace(Dto.HBLNO))
{
if (opse.Where(x => x.HBLNO == Dto.HBLNO && x.MFNO != Dto.MFNO).Count() > 0)
{
resp.Message = "分提单号已存在";
resp.Code = 201;
return Json(resp);
}
}
var oplist = opse.Where(x => x.MFNO == Dto.MFNO).First();
var opctnlist = edi.EdiCtns.AsNoTracking().AsQueryable().Where(x => x.MFNO.Contains(Dto.MFNO));
edi.EdiCtns.RemoveRange(opctnlist);
string guid = Dto.MFNO;
oplist.MFNO = guid;
oplist.BSNO = BSNO;
oplist.EDISTATUS = "已录入";
oplist.INPUTBY = showname;
oplist.INPUTDATE = DateTime.Now;
oplist.CORPID = companyid;
oplist.MBLNO = Dto.MBLNO;
oplist.HBLNO = Dto.HBLNO;
oplist.ETD = Convert.ToDateTime(Dto.ETD);
oplist.FORWARDER = Dto.FORWARDER;
oplist.VESSEL = Dto.VESSEL;
oplist.VOYNO = Dto.VOYNO;
oplist.SHIPIMO = Dto.SHIPIMO;
oplist.CARRIER = Dto.CARRIER;
if (string.IsNullOrWhiteSpace(Dto.ETA))
{
oplist.ETA = null;
}
oplist.ETA = Convert.ToDateTime(Dto.ETA);
oplist.WeiTuoFaSongFang = Dto.WeiTuoFaSongFang;
oplist.ORDERNO = Dto.ORDERNO;
oplist.REMARKS = Dto.REMARKS;
oplist.SHIPPERNAME = Dto.SHIPPERNAME;
oplist.SHIPPERADDR1 = Dto.SHIPPERADDR1;
oplist.SHIPPERCOUNTRY = Dto.SHIPPERCOUNTRY;
oplist.SHIPPERTEL = Dto.SHIPPERTEL;
oplist.SHIPPERCODE = Dto.SHIPPERCODE;
oplist.LeiXingFa = Dto.LeiXingFa;
oplist.CONSIGNEENAME = Dto.CONSIGNEENAME;
oplist.CONSIGNEEADDR1 = Dto.CONSIGNEEADDR1;
oplist.CONSIGNEECOUNTRY = Dto.CONSIGNEECOUNTRY;
oplist.CONSIGNEETEL = Dto.CONSIGNEETEL;
oplist.CONSIGNEECODE = Dto.CONSIGNEECODE;
oplist.LeiXingShou = Dto.LeiXingshou;
oplist.NOTIFYPARTYNAME = Dto.NOTIFYPARTYName;
oplist.NOTIFYPARTYADDR1 = Dto.NOTIFYPARTYADDR1;
oplist.NOTIFYPARTYCOUNTRY = Dto.NOTIFYPARTYCOUNTRY;
oplist.NOTIFYPARTYTEL = Dto.NOTIFYPARTYTEL;
oplist.NOTIFYPARTYCODE = Dto.NOTIFYPARTYCODE;
oplist.LeiXingTong = Dto.LeiXingTong;
oplist.PORTLOAD = Dto.PORTLOAD;
oplist.PORTLOADID = Dto.PORTLOADID;
oplist.PLACEDELIVERYID = Dto.PLACEDELIVERYID;
oplist.PLACEDELIVERY = Dto.PLACEDELIVERY;
oplist.PORTDISCHARGE = Dto.PORTDISCHARGE;
oplist.PORTDISCHARGEID = Dto.PORTDISCHARGEID;
oplist.DESTINATIONID = Dto.DESTINATIONID;
oplist.DESTINATION = Dto.DESTINATION;
oplist.MARKS = Dto.MARKS;
oplist.DESCRIPTION = Dto.DESCRIPTION;
oplist.ISNOR = Dto.ISNOR;
oplist.QueRenWanCheng = Dto.QueRenWanCheng;
int? PKGS = 0;
decimal? KGS = 0;
decimal? CBM = 0;
string ctnTemp = "";
bool IsDongGui = false;
string ctnStr = "";
foreach (var item in Dto.EdiCtns)
{
OpSeaeEdiCtn opSeaeEdictn = new OpSeaeEdiCtn();
opSeaeEdictn.CTNCODE = item.CTNCODE;
opSeaeEdictn.CTNALL = item.CTNALL;
opSeaeEdictn.CNTRNO = item.CNTRNO;
opSeaeEdictn.SEALNO = item.SEALNO;
opSeaeEdictn.PKGS = item.PKGS;
PKGS += item.PKGS;
opSeaeEdictn.KINDPKGS = item.KINDPKGS;
opSeaeEdictn.KGS = item.KGS;
KGS += item.KGS;
opSeaeEdictn.CBM = item.CBM;
CBM += item.CBM;
opSeaeEdictn.PIZHONG = item.PIZHONG;
opSeaeEdictn.ShiFengRen = item.ShiFengRen;
opSeaeEdictn.ZhongKongBiaoShi = item.ZhongKongBiaoShi;
opSeaeEdictn.ChengZhongFangShi = item.ChengZhongFangShi;
opSeaeEdictn.ChengZhongZhongLiang = item.ChengZhongZhongLiang;
opSeaeEdictn.ChengZhongShiJian = item.ChengZhongShiJian;
ctnTemp = item.CTNALL;
List<OpSeaeEdiCtn> list = Dto.EdiCtns.FindAll(b => b.CTNALL == ctnTemp).ToList();
if (list.Count != 0)
{
ctnStr += ctnTemp + "*" + list.Count.ToString() + ",";
Dto.EdiCtns.RemoveAll(a => a.CTNALL == ctnTemp);
}
if (item.CTNALL.Contains("RH") || item.CTNALL.Contains("RF") || item.CTNALL.Contains("RQ"))
{
IsDongGui = true;
}
edi.EdiCtns.Add(opSeaeEdictn);
}
if (IsDongGui)
{
oplist.CARGOID = "R";
}
else
{
oplist.CARGOID = Dto.CARGOID;
}
if (ctnStr.Length > 0)
{
ctnStr = ctnStr.Substring(0, ctnStr.Length - 1);
}
oplist.JiZhuangXiang = ctnStr;
oplist.PKGS = PKGS;
oplist.KGS = KGS;
oplist.CBM = CBM;
edi.Edis.Add(oplist);
OP_SEAE_EDI_TIPS_md tipe = new OP_SEAE_EDI_TIPS_md();
tipe.GID = Guid.NewGuid().ToString("D");
tipe.MFNO = guid;
tipe.TIPSTIME = DateTime.Now;
tipe.TIPS = "新建舱单修改";
tipe.CREATETIME = DateTime.Now;
tipe.MBLNO = Dto.MBLNO;
tipe.HBLNO = Dto.HBLNO;
tipe.OPERATOR = showname;
tipe.OPTYPE = "编辑";
tipe.FORWARDER = Dto.FORWARDER;
edi.OP_SEAE_EDI_TIPS.Add(tipe);
}
edi.SaveChanges();
resp.Success = true;
resp.Message = "保存成功";
resp.Code = 200;
}
else
{
resp.Success = false;
resp.Message = "非法访问";
resp.Code = 401;
}
return Json(resp);
}
///// <summary>
///// 删除明细
///// </summary>
///// <returns></returns>
//[HttpPost]
//public ActionResult DeleteOpsectn(string Ids)
//{
// RespCommon resp = new RespCommon();
// if (Request.Headers.AllKeys.Contains("Authorization"))
// {
// getinfo(Request.Headers["Authorization"]);
// if (string.IsNullOrEmpty(Ids))
// {
// resp.Success = false;
// resp.Message = "未接收到相关参数";
// return Json(resp);
// }
// var arr = Ids.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
// var list = edi.EdiCtns.Where(i => arr.Contains(i.ctn_id)).ToList();
// edi.EdiCtns.RemoveRange(list);
// edi.SaveChanges();
// resp.Success = true;
// resp.Message = "删除成功";
// }
// else {
// resp.Success = false;
// resp.Message = "非法访问";
// resp.Code = 401;
// }
// return Json(resp);
//}
#region 直发
[HttpPost]
public ContentResult CustomEdiSendToYard_PingTai(string bsnos, string dcarrier, string type, string remarks)
{
if (Request.Headers.AllKeys.Contains("Authorization"))
{
getinfo(Request.Headers["Authorization"]);
EdiDataContext edc = new EdiDataContext();
return CustomEdiSendToYard(bsnos, dcarrier, type, remarks, userid, codename, showname, companyid, company);
}
else
{
return null;
}
}
public ContentResult CustomEdiSendToYard(string bsnos, string dcarrier, string type, string remarks, string userid, string usercode, string showname, string companyid, string companyfullname)
{
EdiDataContext edc = new EdiDataContext();
var uid = userid;
var sendtype = ChangeInfo.getSendType(type);
int cnt = 0;
var sqlbsnos = CheckData.GetBSNOsInSql(bsnos);
var headList = MsOpSeaeEdiDAL.GetDataList("MFNO IN ('" + sqlbsnos + "')", userid, showname, companyid, 0, 100, out cnt);
if (string.IsNullOrWhiteSpace(dcarrier))
{
foreach (var item in headList)
{
if (!string.IsNullOrWhiteSpace(item.FORWARDER))
{
dcarrier = item.FORWARDER;
break;
}
}
}
var headData = headList[0];
var checkresult = CheckSave(headData);
if (!checkresult.Success)
{
var jr = new JsonResponse { Success = false, Message = checkresult.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jr) };
}
string msg = "";
bool = false;
bool is = headList[0].CARGOID == "D";
bool HasZhifaPower = CheckData.CheckHasZhiFaPower(userid);
//bool 直发 = true;
if (HasZhifaPower && type == "新增")
{
//如有舱单直发权限 则对新增类型的仓单进行直接发送
if (CheckData.CarrierCanSend(dcarrier))
= true;
}
else
{
}
var path = Server.MapPath("../../EDIFiles/CustomEdi");
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
var relativeXmlPath = "../../EDIFiles/ExportXmlManifest";
var xmlPath = Server.MapPath(relativeXmlPath);
if (!Directory.Exists(xmlPath))
{
Directory.CreateDirectory(xmlPath);
}
var result = new DBResult();
var ftpset = MsCodeFtpSetDAL.GetData("EDINAME=''", companyid);
//是否允许保存
var error = CheckData.CheckCanSave(bsnos, false, type, checkCtnNum: false);
//选择分单时 是否选择了所有分单
//以及是否是同一个主单下的分单
//20210719 增加判断 如果该用户具有一个特定权限 则允许并非全部分单直接发送
error += CheckData.CheckCanSend(bsnos, type, userid);
if (error != "")
{
result.Success = false;
result.Message = error;
var jsonRespose2 = new JsonResponse { Success = result.Success, Message = result.Message, Data = result.Data };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose2) };
}
//合计数是否正确
error += CheckData.CheckSum(bsnos);
if (error != "")
{
result.Success = false;
result.Message = error;
var jsonRespose3 = new JsonResponse { Success = result.Success, Message = result.Message, Data = result.Data };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose3) };
}
if (error == "")
{
//20210118 重新编写舱单发送逻辑
var Mblnolist = new List<string>();
foreach (var item in headList)
{
Mblnolist.Add(item.MFNO);
}
var edilist = edc.Edis.Where(x => Mblnolist.Contains(x.MFNO)).ToList();
//20221206采用新的逻辑发出
//var BillSendHelper = new EdiSenderHelper(edilist);
//var _r = BillSendHelper.DoSend();
//var jsonRespose2 = new JsonResponse { Success = _r.Success, Message = _r.Message, Data = _r.Data };
//return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose2) };
#region 将此次选中的业务分为三类
var List = new List<string>();
var List = new List<string>();
var List = new List<string>();
var List = new List<string>();
foreach (var item in edilist)
{
if (!string.IsNullOrWhiteSpace(item.HBLNO))
{
if (edilist.Exists(e => e.MBLNO == item.MBLNO && (e.HBLNO == null || e.HBLNO.Trim() == "")))
{
if (!List.Contains(item.MBLNO))
{
List.Add(item.MBLNO);
}
}
else
{
if (!List.Contains(item.MBLNO))
{
List.Add(item.MBLNO);
}
}
}
else
{
if (!List.Contains(item.MBLNO))
{
List.Add(item.MBLNO);
}
}
if (!List.Contains(item.MBLNO))
{
List.Add(item.MBLNO);
}
}
var List = edilist.Where(x => List.Contains(x.MBLNO) && (x.HBLNO == null || x.HBLNO.Trim() == "")).ToList();
var List = edilist.Where(x => List.Contains(x.MBLNO)).ToList();
var List = edilist.Where(x => List.Contains(x.MBLNO)).ToList();
#endregion
foreach (var MBLNO in List)
{
var is = false;
var is = false;
var is = false;
var = new List<OpSeaeEdi>();
var tempheadlist = new List<MsOpSeaeEdi>();
var Ms = new List<MsOpSeaeEdi>();
if (List.Select(s => s.MBLNO).Contains(MBLNO))
{
is = true;
tempheadlist = headList.Where(x => x.MBLNO == MBLNO && (x.HBLNO == null || x.HBLNO.Trim() == "")).ToList();
is= List[0].CARGOID == "D";
}
if (List.Select(s => s.MBLNO).Contains(MBLNO))
{
is = true;
tempheadlist = headList.Where(x => x.MBLNO == MBLNO).ToList();
is = List[0].CARGOID == "D";
}
if (List.Select(s => s.MBLNO).Contains(MBLNO))
{
is = true;
is = false;
tempheadlist = headList.Where(x => x.MBLNO == MBLNO && (x.HBLNO == null || x.HBLNO.Trim() == "")).ToList();
= edilist.Where(x => x.MBLNO == MBLNO && !(x.HBLNO == null || x.HBLNO.Trim() == "")).ToList();
Ms = headList.Where(x => x.MBLNO == MBLNO && !(x.HBLNO == null || x.HBLNO.Trim() == "")).ToList();
is = tempheadlist[0].CARGOID == "D";
}
//判断是否要用到 船代直发 的费率
//判断依据1发主单时如果该用户具备直发权限且是新增且该票业务的船代支持船代直发
// 2发分单时如果该用户具备直发权限且是新增
//20210611 3 发分单时,有船代直发权限的用户,如果分单下存在任意一个分单的状态是已直发,则剩下的分单允许单独发送,不走直发通道,走原来的通道。
//20221206 修改【危化品 危险品】直发逻辑
//主单改为 船代中远的 危险品不直发 其他直发;分单均改为直发处理
var withZhifa = (
((is || is) && && type == "新增" )//&& !is危化品
|| (is && HasZhifaPower && type == "新增")
);
if (withZhifa && is)
{
var MFNO = List[0].BSNO;
var List = edc.Edis.Where(x => x.BSNO == MFNO).ToList();
var = UserActionHelper.(userid);
if (List.Exists(x => x.EDISTATUS == "已直发")
&& !
) withZhifa = false;
}
//1.看是否维护单价 如无单价则返回错误
if (!(showname, companyfullname, edilist, userid, type, withZhifa))
{
var jr_0 = new JsonResponse { Success = false, Message = $"提单号{MBLNO}的业务尚未维护单价,请联系相关业务人员!", Data = null };
return new ContentResult() { Content = JsonConvert.Serialize(jr_0) };
}
//2.看剩余费用是否足以发出此次舱单 如不足则返回错误
var edc1 = new EdiDataContext();//edc1
var type = ChangeInfo.getCustFeeType(ChangeInfo.getSendType(type), withZhifa);
var pricehead = new Cust_Price_md();
var balance = new Cust_Balance_md();
try
{
pricehead = edc1.Cust_Price.First(x => x.COMNAME == companyfullname && x.SENDTYPE == type);
}
catch (Exception e)
{
result.Success = false;
result.Message = $"[{companyfullname}]缺少[{type}]的费率";
var rr = new JsonResponse(result);
return rr.getContentReult();
}
try
{
balance = edc1.Cust_Balance.First(x => x.COMNAME == companyfullname);
}
catch (Exception e)
{
result.Success = false;
result.Message = $"[{companyfullname}]没有维护余额";
var rr = new JsonResponse(result);
return rr.getContentReult();
}
edilist.OrderBy(x => x.MBLNO).OrderBy(x => x.HBLNO);
var List = (showname, companyfullname, edilist, userid, type, withZhifa);
if (List == null || List.Count() == 0)
{
var jr_1 = new JsonResponse { Success = false, Message = $"剩余余额已不足以发送完成此次业务,请及时充值!", Data = null };
return jr_1.getContentReult();
}
dcarrier = tempheadlist[0].FORWARDER;
var mfnolist = MsOpSeaeEdiDAL.getheadListMFNO(tempheadlist);
var billList = edc.Edis.Where(x => mfnolist.Contains(x.MFNO)).ToList();
var beizhu = "";
var CustFeeList = ChangeInfo.MakeChangeList(edc1, showname,companyid, companyfullname, billList, userid, sendtype, ref beizhu, withZhifa);
BasicDataRefDAL.SaveLog_str(beizhu, userid, "舱单直发_2021", "修改内容");
var fendanFeeList = new List<Cust_Fee_md>();
void ()
{
foreach (var CustFee in CustFeeList)
{
(edc1, CustFee, ref pricehead, companyfullname);
}
}
void ()
{
fendanFeeList = ChangeInfo.MakeChangeList(edc1, showname, companyid,companyfullname, , userid, sendtype, ref beizhu, withZhifa);
foreach (var CustFee in fendanFeeList)
{
(edc1, CustFee, ref pricehead, companyfullname);
}
}
//3.如 直发==true而且是新建的 则首先执行接口直发的调用 如成功则保存变更 如果是主分单的 则将相关分单写入 再次保存;
if ( && type == "新增" && (dcarrier!="中远" || (dcarrier == "中远" && !is))) //&& !is危化品
{
BasicDataRefDAL.SaveLog_str(String.Join(",", mfnolist.ToArray()), userid, "舱单直发", "直发船代");
if (is || is)
{
var filename = MsOpSeaeEdiDAL.CreateExportManifestList_nofee(tempheadlist, userid, showname, companyid, path, companyfullname, dcarrier, 9, ftpset);
//主单或主分单业务的主单 都直接发送
var tempresult = new Result_md(true, "");
//20210727 判断 如果是青港的 而且船公司为空 则提示必须选择船公司
tempresult = DoSend.SendEdiDirect(billList, dcarrier, filename, userid, showname, type);
result = new DBResult(tempresult.Success, tempresult.Message, tempresult.Data);
if (result.Success)
{
();
edc1.SaveChanges();
if (is)
{
DoSend.(billList, showname, userid, 8);
//新增 filerole=9
var FendanFilename = DoSend.GetFenDanFileName(billList, path);
try
{
//主分单业务记录待发的分单
DoSend.(, dcarrier, type, remarks, userid, usercode, showname, companyid, companyfullname, FendanFilename, ftpset.SENDCODE);
}
catch (DbEntityValidationException dbEx)
{
var jr_3 = new JsonResponse { Success = false, Message = dbEx.Message, Data = null };
return new ContentResult() { Content = JsonConvert.Serialize(jr_3) };
}
//发送待发分单的邮件
(Ms, userid, usercode, path, companyfullname, dcarrier, type, ftpset, remarks, showname, fendanFeeList, "(自动)");
}
var _dbr = (tempheadlist, userid, usercode, path, companyfullname, dcarrier, type, ftpset, remarks, showname, CustFeeList, "(自动)");
//华港船代生成xml并发送ftp
MsOpSeaeEdiDAL.SendEdiXmlHuaGangFtp(bsnos, uid, relativeXmlPath, xmlPath);
}
else
{
var jr_2 = new JsonResponse(result);
return jr_2.getContentReult();
}
var rr = new JsonResponse(result);
return rr.getContentReult();
}
if (is)
{
var _ = (MBLNO);
if (!_.Success)
{
ChangeInfo.SetEdiStatus(billList, type, showname, dcarrier, EdiSendStatus.Fail, _.Message);
return _.getContentReult();
}
//直发 分单 调用直接发给电子口岸的逻辑 //新增 filerole=9
var FendanFilename = DoSend.MakeFenDanFile(billList, 9, ftpset.SENDCODE, path, userid);
var _dosend = new DoSend();
//分单发送测试 注销下面的部分则不发出分单
//var tempresult = new DBResult();
var tempresult = _dosend.SendFendanDirect(billList, dcarrier, FendanFilename, userid, showname, type);
//if !tempresult.Success 取消扣费
if (tempresult.Success)
{
();
edc1.SaveChanges();
var _dbr = (tempheadlist, userid, usercode, path, companyfullname, dcarrier, type, ftpset, remarks, showname, CustFeeList, "(自动)");
DoSend.(billList[0].BSNO);
//华港船代生成xml并发送ftp
MsOpSeaeEdiDAL.SendEdiXmlHuaGangFtp(bsnos, uid, relativeXmlPath, xmlPath);
}
result.Success = tempresult.Success;
result.Message = tempresult.Message;
}
}
//4.如 直发==false 或者不是新增的 则首先保存变更 然后调用邮件发送方法
JsonResponse (string _MBLNO)
{
//如果主单没有主单详细信息(headdata) 返回错误
var _r = CheckData.(_MBLNO);
if (!_r)
{
//20220524 如果没有就重读一次
var _r2 = WLXX.Read_StatusZDXX(MBLNO, userid, "");
var jr_1 = new JsonResponse { Success = false, Message = $"主提运单尚未传输成功,分提运单发送未通过!", Data = null };
return jr_1;
}
else
{
var jr_1 = new JsonResponse { Success = true, Message = "", Data = null };
return jr_1;
}
}
if (!( && type == "新增" && (dcarrier != "中远" || (dcarrier == "中远" && !is))))//&& !is危化品
{
if (is)
{
();
edc1.SaveChanges();
result = (tempheadlist, userid, usercode, path, companyfullname, dcarrier, type, ftpset, remarks, showname, CustFeeList);
if (result.Success)
{
//DoSend.记录待读状态主单(billList, showname, userid, 20);
//华港船代生成xml并发送ftp
MsOpSeaeEdiDAL.SendEdiXmlHuaGangFtp(bsnos, uid, relativeXmlPath, xmlPath);
}
var rr = new JsonResponse(result);
return rr.getContentReult();
}
if (is)
{
();
if (!(HasZhifaPower && type == "新增"))
{
();
}
result = (tempheadlist, userid, usercode, path, companyfullname, dcarrier, type, ftpset, remarks, showname, CustFeeList);
if (result.Success)
{
if (HasZhifaPower && type == "新增")
{
DoSend.(billList, showname, userid, 20);
var FendanFilename = DoSend.GetFenDanFileName(billList, path);
//主分单业务记录待发的分单
DoSend.(, dcarrier, type, remarks, userid, usercode, showname, companyid, companyfullname, FendanFilename, ftpset.SENDCODE);
//发送待发分单的邮件
(Ms, userid, usercode, path, companyfullname, dcarrier, type, ftpset, remarks, showname, fendanFeeList, "(自动)");
}
else
{
DoSend.(billList, showname, userid, 20);
(Ms, userid, usercode, path, companyfullname, dcarrier, type, ftpset, remarks, showname, fendanFeeList);
}
//华港船代生成xml并发送ftp
MsOpSeaeEdiDAL.SendEdiXmlHuaGangFtp(bsnos, uid, relativeXmlPath, xmlPath);
}
edc1.SaveChanges();
var rr = new JsonResponse(result);
return rr.getContentReult();
}
// 分单 有直发权限 是新增的 ;这些分单直接发出
//20221206 不再关注分单是否危险品 直接发出
if (is)
{
//区别在于不判断这个船公司是否具有直发权限
//因为分单不需要分船公司
if ((HasZhifaPower && type == "新增") && withZhifa)//&& !is危化品
{
var _ = (MBLNO);
if (!_.Success)
{
ChangeInfo.SetEdiStatus(billList, type, showname, dcarrier, EdiSendStatus.Fail, _.Message);
return _.getContentReult();
}
//直发 分单 调用直接发给电子口岸的逻辑 //新增 filerole=9
var FendanFilename = DoSend.MakeFenDanFile(billList, 9, ftpset.SENDCODE, path, userid);
var _dosend = new DoSend();
//分单发送测试 注销下面的部分则不发出分单
//var tempresult = new DBResult();
var tempresult = _dosend.SendFendanDirect(billList, dcarrier, FendanFilename, userid, showname, type);
if (tempresult.Success)
{
var _dbr = (tempheadlist, userid, usercode, path, companyfullname, dcarrier, type, ftpset, remarks, showname, CustFeeList, "(自动)");
();
edc1.SaveChanges();
DoSend.(billList[0].BSNO);
}
result.Success = tempresult.Success;
result.Message = tempresult.Message;
//华港船代生成xml并发送ftp
MsOpSeaeEdiDAL.SendEdiXmlHuaGangFtp(bsnos, uid, relativeXmlPath, xmlPath);
var rr = new JsonResponse(result);
return rr.getContentReult();
}
else
{
//ChangeInfo.SetEdiStatus(billList, type, showname, dcarrier, EdiSendStatus.Success, "");
//List<OpSeaeEdi> billList, string dcarrier, string type, string remarks, string userid, string usercode, string showname, string companyid, string companyname)
var _dbr = (tempheadlist, userid, usercode, path, companyfullname, dcarrier, type, ftpset, remarks, showname, CustFeeList);
();
edc1.SaveChanges();
//华港船代生成xml并发送ftp
MsOpSeaeEdiDAL.SendEdiXmlHuaGangFtp(bsnos, uid, relativeXmlPath, xmlPath);
var rr = new JsonResponse(_dbr);
return rr.getContentReult();
}
}
}
}
}
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message, Data = result.Data };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public DBResult CheckSave(MsOpSeaeEdi head)
{
var result = new DBResult(true, "", null);
result = head.CheckSaveVoid();
return result;
}
private bool (string showname, string companyname, List<OpSeaeEdi> edilist, string userid, string stype, bool withZhifa)
{
var result = true;
var edc = new EdiDataContext();
foreach (var edi in edilist)
{
var sendtype = ChangeInfo.getSendType(stype);
var beizhu = "";
var CustFee = ChangeInfo.MakeChange(edc, showname,companyid, companyname, edi, userid, sendtype, ref beizhu, withZhifa);
if (CustFee.PRICE == -1) return false;
}
return result;
}
private DBResult (List<MsOpSeaeEdi> tempedilist, string userid, string usercode, string path, string companyname, string dcarrier, string type, CodeFtpSet ftpset, string remarks, string showname, List<Cust_Fee_md> CustFeeList, string zhifa = "")
{
var result = MsOpSeaeEdiDAL.CreateCustomList_20210107(tempedilist, userid, usercode, path, companyname, dcarrier, type, ftpset, remarks, CustFeeList, showname, zhifa);
var bsnos = String.Join(",", tempedilist.Select(s => s.MFNO).ToArray());
if (!result.Success)
{
BasicDataRefDAL.SaveLog_str(bsnos, userid, "舱单直发_2021", "(自动发送)发送邮件失败:" + result.Message);
}
return result;
}
private JsonResponse (EdiDataContext edc1, Cust_Fee_md CustFee, ref Cust_Price_md pricehead, string COMPANYNAME)
{
var _r = ChangeInfo.(edc1, CustFee, ref pricehead, COMPANYNAME);
return new JsonResponse { Success = _r.Success, Message = _r.Message, Data = null };
}
private List<Cust_Fee_md> (string showname, string companyname, List<OpSeaeEdi> edilist, string userid, string stype, bool withZhifa)
{
var result = new List<Cust_Fee_md>();
var edc = new EdiDataContext();
var pricehead = edc.Cust_Price.First(x => x.COMNAME == companyname);
var balance = edc.Cust_Balance.First(x => x.COMNAME == companyname);
foreach (var edi in edilist)
{
var sendtype = ChangeInfo.getSendType(stype);
var beizhu = "";
var CustFee = ChangeInfo.MakeChange(edc, showname,companyid, companyname, edi, userid, sendtype, ref beizhu, withZhifa);
var = (edc, CustFee, ref pricehead, companyname);
if (!.Success) return new List<Cust_Fee_md>();
result.Add(CustFee);
}
return result;
}
#endregion
#region 发送VGM
[HttpPost]
public ContentResult CreateAndSendVGM(string mfno, string type, string mblno)
{
string newblno = "";
string outmsg = "";
bool allow = vgmptDAL.CheckAllowSendForCD2VGM(mfno, type, out outmsg);
if (!allow)
{
var json2 = JsonConvert.Serialize(new { Success = true, Message = outmsg, totalCount = 10, data = "" });
return new ContentResult() { Content = json2 };
}
var _hassame = MsOpSeaeEdiVGMDAL.HasSameMBLNOWithUserId(mblno, userid);
if (_hassame.Success)
{
var jsonRespose = new JsonResponse { Success = false, Message = _hassame.Message };//"主提单号已存在!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
if (MsOpSeaeEdiDAL.CopyDataIntoVGMWithMFNO(mfno, out newblno))
{
string path = Server.MapPath("../../VGMFile/");
string filepath = "";
string msg = vgmptDAL.writeAndSendVgmXml("'" + newblno + "'", userid, type, path, out filepath);
var json = JsonConvert.Serialize(new { Success = true, Message = msg, totalCount = 10, data = filepath });
return new ContentResult() { Content = json };
}
else
{
var json = JsonConvert.Serialize(new { Success = false, Message = "数据操作错误", totalCount = 10 });
return new ContentResult() { Content = json };
}
}
#endregion
/// <summary>
/// 对比场站
/// </summary>
/// <param name="bsno"></param>
/// <param name="mblno"></param>
/// <param name="yard"></param>
/// <param name="isweb"></param>
/// <returns></returns>
[HttpPost]
public ContentResult GetyardctnList(string bsno, string mblno, string yard, bool isweb = false)
{
var result = new DBResult();
string json = "";
if (Request.Headers.AllKeys.Contains("Authorization"))
{
getinfo(Request.Headers["Authorization"]);
result = MsOpSeaeYardDAL.GetYARDCTNList(bsno, mblno, yard, companyid, userid, isweb);
json = JsonConvert.Serialize(new { Success = result.Success, Message = result.Message, totalCount = 10, data = result.Data });
}
return new ContentResult() { Content = json };
}
#endregion
#region 注册
[HttpPost]
public ActionResult Regist()
{
string msg = "";
string phone = Request["phone"];
string pwd = Request["pwd"];
string pwd2 = Request["pwd2"];
string msgcode = Request["vcode"];
string email = Request["email"];
string comname = Request["comname"];
string username = Request["username"];
string realname = Request["realname"];
string yaoqingma = Request["yaoqingma"];
string gslx = Request["gslx"];
string COMTYPE = Request["COMTYPE"];
var cscode = Request["c"];
if (cscode == null || cscode == "")
{
cscode = "";
}
string imgpath = "";
if (Request.Files.Count > 0)
{
var file = Request.Files[0];
if (file != null)//验证是否包含文件
{
//取得文件的扩展名,并转换成小写
if (true)
{
//对上传文件的大小进行检测限定文件最大不超过8M
if (file.ContentLength < 8192000)
{
string timeStr = DateTime.Now.ToString("yyyyMMdd_HHmmss");
string filepath = Server.MapPath("/UserInfo/img/");
if (Directory.Exists(filepath) == false)//如果不存在就创建file文件夹
{
Directory.CreateDirectory(filepath);
}
string savePath = filepath + timeStr + ".jpg";
file.SaveAs(savePath);
imgpath = savePath;
}
else
{
msg = "文件大小超出8M请重新选择";
}
}
}
}
UserSign(phone, email, pwd, pwd2, msgcode, comname, username, realname, imgpath, yaoqingma, cscode, gslx, COMTYPE.Trim(), out msg);
return Content(msg);
}
private bool UserSign(string phone, string email, string password, string passwordRe,
string msgcode, string comname, string username, string realname, string picPath, string yaoqingma, string cscode, string authUserid, string COMTYPE, out string msg)
{
msg = "";
bool exRst = false;
if (CheckMsgCode(phone, msgcode))
{
//入库
string sql1 = "select count(*) from [user] where codename = '" + username + "'";
string sql2 = "select count(*) from user_baseinfo where mobile = '" + phone + "'";
string comid = "";
string compname = "";
bool hadYaoQingMa = GetComIdInfoWithYaoQingMa(yaoqingma, out comid, out compname);
if (Convert.ToInt32(SQLHelper.ExcuteScalarSQL(sql1)) > 0)
{
msg = "该用户名已被占用!";
return false;
}
else
{
if (Convert.ToInt32(SQLHelper.ExcuteScalarSQL(sql2)) > 0)
{
msg = "该手机号已被占用!";
return false;
}
else
{
//2020-6-11先判断是否存在已认证的同名公司如果有则comname加“未加入”后缀防止盗用别人公司的余额
var sqlCount = $"select count(1) from [user] u join company_new c on u.compid = c.compid where u.comname = '{comname}' and c.auditstatus = 'Success'";
if (Convert.ToInt32(SQLHelper.ExcuteScalarSQL(sqlCount)) > 0)
{
//已有同名的已认证的公司
comname = $"{comname} (未加入)";
}
string uid = Guid.NewGuid().ToString();
StringBuilder sbIns = new StringBuilder();
sbIns.Append("insert into [user] (gid,username,codename,password,showname,comname,yaoqingma,cscode,COMTYPE)");
sbIns.Append(" values ");
sbIns.Append("('" + uid + "',");
sbIns.Append("'',");
sbIns.Append("'" + username + "',");
sbIns.Append("'" + password + "',");
sbIns.Append("'" + realname + "',");
sbIns.Append("'" + comname + "',");
sbIns.Append("'" + yaoqingma + "',");
sbIns.Append("'" + cscode + "',");
sbIns.Append("'" + COMTYPE + "')");
if (SQLHelper.ExcuteSQL(sbIns.ToString()) > 0)
{
StringBuilder sbIns2 = new StringBuilder();
sbIns2.Append("insert into user_baseinfo (gid,userid,companyname,deptname,mobile,email1) ");
sbIns2.Append(" values ");
sbIns2.Append("('" + Guid.NewGuid().ToString() + "',");
sbIns2.Append("'" + uid + "',");
if (compname == "")
{
sbIns2.Append("'MYSHIPPING',");
}
else
{
sbIns2.Append("'" + compname + "',");
}
if (hadYaoQingMa)
{
sbIns2.Append("'操作部',");
}
else
{
sbIns2.Append("'客户部',");
}
sbIns2.Append("'" + phone + "',");
sbIns2.Append("'" + email + "')");
if (SQLHelper.ExcuteSQL(sbIns2.ToString()) > 0)
{
if (comid == "")
{
comid = "Com3d0c29b8680c4462a89cc63327cb5c1e";
}
StringBuilder sbIns3 = new StringBuilder();
sbIns3.Append("insert into user_company ");
sbIns3.Append(" values ");
sbIns3.Append("('" + Guid.NewGuid().ToString() + "',");
sbIns3.Append("'" + comid + "',");
sbIns3.Append("'" + uid + "')");
if (SQLHelper.ExcuteSQL(sbIns3.ToString()) > 0)
{
//权限
StringBuilder sbIns4 = new StringBuilder();
sbIns4.Append("insert into user_userattribute values (NEWID(),'" + uid + "','2E5E6066-1C5D-4B04-BF8C-56637C20FC8C','true')");
if (SQLHelper.ExcuteSQL(sbIns4.ToString()) > 0)
{
string tempUserId = "999999";
if (comid == "Come190e77e76d744248ccac709630c21d3")
{
//青岛华途
tempUserId = "bb4d2af2-63ea-4a1e-854a-a252cd1c301c";
}
else
{
tempUserId = authUserid;
}
StringBuilder sbIns5 = new StringBuilder();
sbIns5.Append("insert into user_action (gid,actionid,userid,createuser,createtime,modifiedtime)");
sbIns5.Append(" SELECT NEWID(),ACTIONID,'" + uid + "','1BEC90E1-9780-472F-90C2-0C6390C044A4',GETDATE(),GETDATE() from user_action where USERID='" + tempUserId + "'");
if (SQLHelper.ExcuteSQL(sbIns5.ToString()) > 0)
{
//可视范围
StringBuilder sbIns6 = new StringBuilder();
sbIns6.Append("insert into user_authority_range (GID,USERID,AUTHORITYID,VISIBLERANGE,OPERATERANGE,CREATEUSER,CREATETIME,MODIFIEDTIME)");
sbIns6.Append(" select NEWID(),'" + uid + "',AUTHORITYID,VISIBLERANGE,OPERATERANGE,CREATEUSER,GETDATE(),GETDATE() from user_authority_range where USERID = '" + tempUserId + "'");
if (SQLHelper.ExcuteSQL(sbIns6.ToString()) > 0)
{
//发送注册信息给管理员邮箱
string title = "平台注册成功 " + comname + "-" + realname;
StringBuilder sb = new StringBuilder();
sb.Append("手机:" + phone + "<br>");
sb.Append("邮箱:" + email + "<br>");
sb.Append("密码:" + password + "<br>");
sb.Append("公司名称:" + comname + "<br>");
sb.Append("用户名:" + username + "<br>");
sb.Append("真实姓名:" + realname + "<br>");
sb.Append("邀请码:" + yaoqingma + "<br>");
sb.Append("销售代码:" + cscode + "<br>");
SendMailWithInfo(title, sb.ToString(), "平台注册", "衣国豪", picPath);
string ctitle = "大简云工作平台注册成功";
string ccontent = " 您好您在大简云工作平台注册的账号已生效登陆ID" + username + "或" + phone + ",密码:" + password + ",请妥善保管,为提升您的使用体验,建议使用谷歌浏览器,谢谢支持!";
SendMailToCustWithInfo(email, ctitle, ccontent, "大简云工作平台", realname);
msg = "success";
return true;
}
else
{
msg = "注册错误,代码:6";
return false;
}
}
else
{
msg = "注册错误,代码:5";
return false;
}
}
else
{
msg = "注册错误,代码:4";
return false;
}
}
else
{
msg = "注册错误,代码:3";
return false;
}
}
else
{
msg = "注册错误,代码:2";
return false;
}
}
else
{
msg = "注册错误,代码:1";
return false;
}
}
}
}
else
{
msg = "验证码错误!";
return false;
}
}
private static void SendMailWithInfo(string title, string context, string comname, string toname, string picPath = "")
{
// SendEmail se = new SendEmail("dongshengsoft@dongshengsoft.com", "admin@dongshengsoft.com", "", "", title, context, false);
// se.SetSmtp("admin@dongshengsoft.com", "ds!@#)(*", "smtpcom.263xmail.com", 25, false,
//System.Net.Mail.MailPriority.Normal);
MailAddress mafrom = new MailAddress("dongshengcangdan@h8j.top", comname, Encoding.GetEncoding(936));
MailAddress mato = new MailAddress("register@myshipping.net", toname, Encoding.GetEncoding(936));
using (var smtp = new SmtpClient())
//TO:
using (var mail = new MailMessage(mafrom, mato))
{
//附件
if (picPath != "")
{
var attach = new Attachment(picPath, MediaTypeNames.Application.Octet);
//设置ContentId
mail.Attachments.Add(attach);
}
//标题和内容注意设置编码因为默认编码是ASCII
mail.Subject = title;
mail.SubjectEncoding = Encoding.UTF8;
//HTML内容
mail.Body = context;
mail.BodyEncoding = Encoding.UTF8;
//指示改电子邮件内容是HTML格式
mail.IsBodyHtml = true;
//SMTP设置根据邮箱类型设置这里是Live Mail的SMTP服务器地址
smtp.Host = "smtpdm.aliyun.com";
smtp.Port = 80;
smtp.EnableSsl = false;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential("dongshengcangdan@h8j.top", "A1B2C3ds040201");
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
//发送
smtp.Send(mail);
}
}
private static void SendMailToCustWithInfo(string tomail, string title, string context, string comname, string toname, string picPath = "")
{
MailAddress mafrom = new MailAddress("dongshengcangdan@h8j.top", comname, Encoding.GetEncoding(936));
MailAddress mato = new MailAddress(tomail, toname, Encoding.GetEncoding(936));
using (var smtp = new SmtpClient())
//TO:
using (var mail = new MailMessage(mafrom, mato))
{
//附件
if (picPath != "")
{
var attach = new Attachment(picPath, MediaTypeNames.Application.Octet);
//设置ContentId
mail.Attachments.Add(attach);
}
//标题和内容注意设置编码因为默认编码是ASCII
mail.Subject = title;
mail.SubjectEncoding = Encoding.UTF8;
//HTML内容
mail.Body = context;
mail.BodyEncoding = Encoding.UTF8;
//指示改电子邮件内容是HTML格式
mail.IsBodyHtml = true;
//SMTP设置根据邮箱类型设置这里是Live Mail的SMTP服务器地址
smtp.Host = "smtpdm.aliyun.com";
smtp.Port = 80;
smtp.EnableSsl = false;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential("dongshengcangdan@h8j.top", "A1B2C3ds040201");
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
//发送
smtp.Send(mail);
}
}
private bool CheckMsgCode(string phone, string code)
{
string sql = "select top 1 vcode from phone_vcode where phone = '" + phone + "' order by createtime desc";
var obj = SQLHelper.ExcuteScalarSQL(sql);
string dbcode = "";
if (obj != DBNull.Value)
{
dbcode = obj.ToString();
if (dbcode == code)
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
private bool GetComIdInfoWithYaoQingMa(string yaoqingma, out string comid, out string comname)
{
if (yaoqingma == "")
{
comid = "";
comname = "";
return false;
}
string sql = "select count(*) from company where codename = '" + yaoqingma + "'";
try
{
int cnt = Convert.ToInt32(SQLHelper.ExcuteScalarSQL(sql));
if (cnt > 0)
{
string sql2 = "select gid+','+NAME from company where codename = '" + yaoqingma + "'";
string cominfo = Convert.ToString(SQLHelper.ExcuteScalarSQL(sql2));
string gid = cominfo.Split(',')[0];
string name = cominfo.Split(',')[1];
string sql3 = "select count(*) from sys_dept where linkid = '" + gid + "' and deptname = '操作部'";
if (Convert.ToInt32(SQLHelper.ExcuteScalarSQL(sql3)) <= 0)
{
string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
string sql4 = "insert into sys_dept values('" + Guid.NewGuid().ToString() + "','" + gid + "','01','操作部','','','','1BEC90E1-9780-472F-90C2-0C6390C044A4','" + time + "','1BEC90E1-9780-472F-90C2-0C6390C044A4','" + time + "','')";
SQLHelper.ExcuteScalarSQL(sql4);
}
comid = gid;
comname = name;
return true;
}
else
{
comid = "";
comname = "";
return false;
}
}
catch (Exception)
{
comid = "";
comname = "";
return false;
throw;
}
}
[HttpPost]
public ActionResult _RegistGetMobileCode()
{
string msg = "";
string phone = Request["phone"];
string code = getAndSendCode(phone, out msg);
return Content(msg);
}
private string getCode(string phone)
{
Random r = new Random();
string code = r.Next(1000, 10000).ToString();
StringBuilder sb = new StringBuilder();
sb.Append("insert into phone_vcode (phone,vcode) values");
sb.Append("('" + phone + "','" + code + "')");
try
{
int rst = SQLHelper.ExcuteSQL(sb.ToString());
return rst > 0 ? code : "";
}
catch (Exception ex)
{
return "";
throw;
}
}
private string getAndSendCode(string phone, out string msg)
{
if (getCodeValidate(phone))
{
string code = getCode(phone);
if (code != "")
{
msg = "验证码已发送!";
AliMessageTools.SendSignCodeMsg(phone, code);
}
else
{
msg = "验证码获取失败!";
}
return code;
}
else
{
msg = "请求次数过多!";
return "";
}
}
private bool getCodeValidate(string phone)
{
string sql = "select count(*) from phone_vcode where phone = '" + phone + "' and datediff(MINUTE, createtime, getdate()) < 1";
int cnt = 0;
var obj = SQLHelper.ExcuteScalarSQL(sql);
if (obj != DBNull.Value)
{
cnt = Convert.ToInt32(obj);
return cnt <= 1;
}
else
{
return false;
}
}
#endregion
}
/// <summary>
/// 根据
/// </summary>
public class EdiSenderHelper
{
private List<OpSeaeEdi> EdiSelectSendList { get; set; }
private List<EdiSendBill> EdiSendBillList { get; set; }
private void addedi(OpSeaeEdi ediitem) {
if (EdiSendBillList.Exists(x => x.MBLNO == ediitem.MBLNO)) {
}
else {
var newbill = new EdiSendBill(ediitem.MBLNO);
EdiSendBillList.Add(newbill);
}
EdiSendBillList.First(x => x.MBLNO == ediitem.MBLNO).addedi(ediitem);
}
public EdiSenderHelper(List<OpSeaeEdi> EdiList) {
EdiSelectSendList = EdiList;
if (EdiSelectSendList != null && EdiSelectSendList.Count > 0) {
foreach (var item in EdiSelectSendList) {
this.addedi(item);
}
}
}
public DBResult DoSend() {
var result = new DBResult();
//对每个bill而言 执行发送操作
if (EdiSendBillList != null && EdiSendBillList.Count > 0) {
foreach (var bill in EdiSendBillList) {
DBResult cansend = bill.CanSend();
if (!cansend.Success) {
return result;
}
}
}
return result;
}
}
public class EdiSendBill {
public string MBLNO { get; set; }
private List<OpSeaeEdi> EdiSendList { get; set; }
public EdiSendBill(string MBLNO) {
this.MBLNO = MBLNO;
}
public void addedi(OpSeaeEdi ediitem) {
if (EdiSendList == null ) {
EdiSendList = new List<OpSeaeEdi>();
}
EdiSendList.Add(ediitem);
}
public DBResult CanSend() {
var result = new DBResult();
//1.看是否维护单价 如无单价则返回错误
//2.看剩余费用是否足以发出此次舱单 如不足则返回错误
return result;
}
public DBResult DoSend()
{
var result = new DBResult();
//对于这个业务而言
//根据 只选择发主单 只选择发分单 同时选择主分单发送
return result;
}
}
}