123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572 |
- using JCSoft.WX.Framework.Api;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.Http;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using Common.Wechat;
- using Common;
- using System.Data;
- using ZcPeng.PublicLibrary;
- using CoreEntity.Entity;
- using Common.Model;
- using Newtonsoft.Json.Converters;
- using Newtonsoft.Json;
- using CoreEntity.DAL;
- using System.Data.SqlClient;
- using System.Reflection;
- using SupplierWeb.Codes.Auth;
- using Microsoft.Extensions.Caching.Memory;
- using CoreEntity.BAL;
- namespace SupplierWeb.Controllers
- {
- [Route("web/supplymobile")]
- public class SupplyMobileController : BaseController
- {
- public SupplyMobileController(IMemoryCache cache, IApiClient client) : base(cache, client)
- {
- }
- ////绑定手机号
- [HttpGet, Route("bindphone")]
- public ActionResult BindPhone()
- {
- WechatHelper.ReGetOpenId(HttpContext);
- string WxOpenId = HttpContext.Session.GetString("openid");
- #region 获取user
- if (WxOpenId != null&& !WxOpenId.Equals(""))
- {
- string commandTextUser = "Select accountName,accountPassword,AccountPhone,Id,RoleId From "
- + Config.TablePrefix + "Account join contactDoc on FocusMicNo = WxOpenId Where WxOpenId=@WxOpenId and Beactive = 'Y'";
- string resultUser;
- DataTable dt = new DataTable();
- List<List<Object>> parametersUser = new List<List<Object>>();
- parametersUser.Add(new List<Object>() { "WxOpenId", WxOpenId });
- DataAccess.GetValues(commandTextUser, ref dt, DataAccess.ToParameters(parametersUser).ToArray(), out resultUser);
- IList<Account> users = new List<Account>();
- //openId已存在不能添加
- if (dt != null && dt.Rows.Count>0)
- {
- users = ModelConvertHelper<Account>.ConvertToModel(dt);
- Account user = users.ToArray()[0];
- ViewData["WxOpenId"] = user.WxOpenId;
- ViewData["AccountName"] = user.AccountName;
- ViewData["AccountPassword"] = user.AccountPassWord;
- ViewData["Id"] = user.Id;
- return View("hasbindphone");
- }
- return View();
- }
- else
- {
- return new EmptyResult();
- }
- #endregion
- }
- ////绑定手机号
- [HttpPost, Route("bindphone")]
- public ActionResult BindPhonePost(string AccountPhone, string AccountName, string AccountPassword, string nonce)
- {
- WechatHelper.ReGetOpenId(HttpContext);
- string WxOpenId = HttpContext.Session.GetString("openid");
- if (WxOpenId != null && WxOpenId != "")
- {
-
- #region 绑定手机号
- string commandTextAccount = "Select AccountName,AccountPassword,AccountPhone,Id,RoleId From "
- + Config.TablePrefix + "Account Where AccountName=@AccountName and AccountPassword=@AccountPassword";
- string resultAccount;
- DataTable dtAccount = new DataTable();
- List<List<Object>> parametersAccount = new List<List<Object>>();
- parametersAccount.Add(new List<Object>() { "AccountName", AccountName });
- parametersAccount.Add(new List<Object>() { "AccountPassword", AccountPassword });
- DataAccess.GetValues(commandTextAccount, ref dtAccount, DataAccess.ToParameters(parametersAccount).ToArray(), out resultAccount);
- IList<Account> Accounts = new List<Account>();
- //账户密码错误
- if (dtAccount == null || dtAccount.Rows.Count == 0)
- {
- ViewData["msg"] = "账户名或密码错误";
- return View("bindphoneError");
- }
- else
- {
- int roleId = (int)dtAccount.Rows[0]["RoleId"];
- if(roleId != 3) {
-
- ViewData["msg"] = "供应商账户才能绑定";
- return View("bindphoneError");
- }
- }
- string commandTextUser = "Select accountName,AccountPassword,AccountPhone,Id From "
- + Config.TablePrefix + "Account join contactDoc on FocusMicNo = WxOpenId Where WxOpenId=@WxOpenId and Beactive = 'Y'";
- string resultUser;
- DataTable dt = new DataTable();
- List<List<Object>> parametersUser = new List<List<Object>>();
- parametersUser.Add(new List<Object>() { "WxOpenId", WxOpenId });
- DataAccess.GetValues(commandTextUser, ref dt, DataAccess.ToParameters(parametersUser).ToArray(), out resultUser);
- IList<Account> users = new List<Account>();
- //openId已存在不能添加
- if (dt != null && dt.Rows.Count > 0)
- {
- users = ModelConvertHelper<Account>.ConvertToModel(dt);
- Account user = users.ToArray()[0];
- ViewData["WxOpenId"] = user.WxOpenId;
- ViewData["AccountName"] = user.AccountName;
- ViewData["AccountPassword"] = user.AccountPassWord;
- return View("hasbindphone");
- }
- #endregion
- List<DataAccessCommand> list = new List<DataAccessCommand>(2);
- #region 绑定openid 到account
- string commandTextAcc = "Update " + Config.TablePrefix + "Account set WxOpenId = @WxOpenId " +
- " Where AccountPhone=@AccountPhone ";
- //string resultAcc;
- List<List<Object>> parameters = new List<List<Object>>();
- parameters.Add(new List<Object>() { "WxOpenId", WxOpenId });
- parameters.Add(new List<Object>() { "AccountPhone", AccountPhone });
- //int successAcc = DataAccess.ExecuteCommand(commandTextAcc, DataAccess.ToParameters(parameters), out resultAcc);
- list.Add(new DataAccessCommand(commandTextAcc, DataAccess.ToParameters(parameters),CommandType.Text ,true));
- #endregion
- #region 绑定openid 到coantacdoc
- string commandText = "Update contactDoc set FocusMicNo = @WxOpenId " +
- " Where exists ( select 1 from " + Config.TablePrefix + "Account where Id = UserId and AccountPhone=@AccountPhone and Beactive = 'Y') ";
- string result;
- //int success = DataAccess.ExecuteCommand(commandText, DataAccess.ToParameters(parameters), out result);
- list.Add(new DataAccessCommand(commandText, DataAccess.ToParameters(parameters), CommandType.Text, true));
- #endregion
- bool success = DataAccess.ExecuteBatchCommands(list,out result);
- if (success) {
- ViewData["WxOpenId"] = WxOpenId;
- ViewData["AccountName"] = AccountName;
- ViewData["AccountPassword"] = AccountPassword;
- return View("hasbindphone");
- }
- else
- ViewData["result"] = result;
- return View("bindphoneNeedWx");
- }
- else
- return View("bindphoneNeedWx");
- }
- ////采购品种列表
- [HttpGet, Route("listdata")]
- public ActionResult listData(string RecordId)
- {
- WechatHelper.ReGetOpenId(HttpContext, "?RecordId=" + RecordId);
- string WxOpenId = HttpContext.Session.GetString("openid");
- //var WxOpenId = "oCzgS1fzaxA3nGpu5pnldkSar1pA";
- //var WxOpenId = "oCzgS1RSy_nTGVkxgpluAdOUtKsw";
- //var WxOpenId = "oCzgS1XfcqvJkiKozn-oWUgSDoZQ";
- if (WxOpenId != null && WxOpenId != "")
- {
- string commandTextUser = "Select * From "
- + Config.TablePrefix + "Account join contactDoc on FocusMicNo = WxOpenId Where WxOpenId=@WxOpenId and Beactive = 'Y'";
- string resultUser;
- DataTable dt = new DataTable();
- List<List<Object>> parametersUser = new List<List<Object>>();
- parametersUser.Add(new List<Object>() { "WxOpenId", WxOpenId });
- DataAccess.GetValues(commandTextUser, ref dt, DataAccess.ToParameters(parametersUser).ToArray(), out resultUser);
- IList<Account> users = new List<Account>();
- List<Dictionary<String, Object>> data = new List<Dictionary<String, Object>>(0);
- if (dt.Rows.Count > 0) {
- users = ModelConvertHelper<Account>.ConvertToModel(dt);
- Account user = users.ToArray()[0];
- ViewData["WxOpenId"] = WxOpenId;
- ViewData["AccountName"] = user.AccountName;
- ViewData["AccountPassword"] = user.AccountPassWord;
- int UserId = user.Id;
- Token token = SupplierWeb.Codes.Auth.Token.genAndSaveToken(users, _cache, out var roleName);
- ViewData["staffId"] = token.StaffId;
- #region 获取Goods
- DataTable dtAccount = new DataTable();
- string commandTextAccount = "Select A.*," +
- "E.Unit,F.WmsMeas From " +
- Config.TablePrefix + "PushFeedback A " +
- " left join PGPrice E on E.EntId = A.EntId and E.GoodsId = A.GoodsId " +
- " left join GoodsAttr F on F.EntId = A.EntId and F.GoodsId = A.GoodsId " +
- "Where A.PushRecordId=@RecordId " +
- " and A.PushAccountId = " + UserId;
- string resultAccount;
- List<List<Object>> parametersAccount = new List<List<Object>>();
- parametersAccount.Add(new List<Object>() { "RecordId", RecordId });
- DataAccess.GetValues(commandTextAccount, ref dtAccount, DataAccess.ToParameters(parametersAccount).ToArray(), out resultAccount);
- IList<PushFeedback> Accounts = new List<PushFeedback>();
- if (dtAccount != null && dtAccount.Rows.Count > 0)
- {
- Accounts = ModelConvertHelper<PushFeedback>.ConvertToModel(dtAccount);
- }
- #endregion
- foreach (PushFeedback pfb in Accounts)
- {
- Dictionary<string,object> maps= ToMap(pfb);
- maps["PurchaseTotalNum"] = decimal.ToInt64(pfb.PurchaseTotalNum);
- data.Add(maps);
- }
- }
- else
- {
- return Redirect("/web/supplymobile/bindphone");
- }
- ViewData["data"] = data;
- return View();
- }
- else
- {
- return new EmptyResult();
- }
-
- }
- /// <summary>
- ///
- /// 将对象属性转换为key-value对
- /// </summary>
- /// <param name="o"></param>
- /// <returns></returns>
- public static Dictionary<String, Object> ToMap(Object o)
- {
- Dictionary<String, Object> map = new Dictionary<string, object>();
- Type t = o.GetType();
- PropertyInfo[] pi = t.GetProperties(BindingFlags.Public | BindingFlags.Instance);
- foreach (PropertyInfo p in pi)
- {
- MethodInfo mi = p.GetGetMethod();
- if (mi != null && mi.IsPublic && !map.ContainsKey(p.Name))
- {
- map.Add(p.Name, mi.Invoke(o, new Object[] { }));
- }
- }
- return map;
- }
- ////查询已提交的采购单-web版
- [HttpGet,Route("purchaseorder")]
- public ActionResult PurchaseOrder(string echostr, string signature, string timestamp, string nonce)
- {
- #region 获取Openid
- //WechatHelper.ReGetOpenId(HttpContext);
- #endregion
- return View();
- }
- ////确认订单
- [HttpGet, Route("confirmorder")]
- public ActionResult confirmorder(string RecordId)
- {
- WechatHelper.ReGetOpenId(HttpContext, "?RecordId=" + RecordId);
- string WxOpenId = HttpContext.Session.GetString("openid");
- //string WxOpenId = "oCzgS1fzaxA3nGpu5pnldkSar1pA";
- //string WxOpenId = "oCzgS1fzaxA3nGpu5pnldkSar1pA";
- if (WxOpenId != null && WxOpenId != "")
- {
- //string commandTextUser = "Select accountName,AccountPassword,AccountPhone,Id From "
- //+ Config.TablePrefix + "Account join contactDoc on FocusMicNo = WxOpenId Where WxOpenId=@WxOpenId and Beactive = 'Y'";
- string commandTextUser = "Select * From "
- + Config.TablePrefix + "Account Where WxOpenId=@WxOpenId " +
- " and Id in (select userid from contactDoc where Beactive = 'Y' and FocusMicNo=@WxOpenId) ";
- string resultUser;
- DataTable dt = new DataTable();
- List<List<Object>> parametersUser = new List<List<Object>>();
- parametersUser.Add(new List<Object>() { "WxOpenId", WxOpenId });
- DataAccess.GetValues(commandTextUser, ref dt, DataAccess.ToParameters(parametersUser).ToArray(), out resultUser);
- IList<Account> users = new List<Account>();
- Dictionary<string, object> mapsrd = new Dictionary<String, Object>();
- List<Dictionary<String, Object>> data = new List<Dictionary<String, Object>>(0);
- if (dt.Rows.Count > 0)
- {
- users = ModelConvertHelper<Account>.ConvertToModel(dt);
- Account user = users.ToArray()[0];
- ViewData["WxOpenId"] = WxOpenId;
- ViewData["AccountName"] = user.AccountName;
- ViewData["AccountPassword"] = user.AccountPassWord;
- Token token = SupplierWeb.Codes.Auth.Token.genAndSaveToken(users, _cache, out var roleName);
- ViewData["staffId"] = token.StaffId;
- int UserId = user.Id;
- #region 获取Goods
- DataTable dtAccount = new DataTable();
- string commandTextAccount = "Select A.* From " +
- Config.TablePrefix + "PushFeedback A " +
- "Where A.PushRecordId=@RecordId " +
- " and A.PushAccountId = " + UserId;
- string resultAccount;
- List<List<Object>> parametersAccount = new List<List<Object>>();
- parametersAccount.Add(new List<Object>() { "RecordId", RecordId });
- DataAccess.GetValues(commandTextAccount, ref dtAccount, DataAccess.ToParameters(parametersAccount).ToArray(), out resultAccount);
- IList<PushFeedback> Accounts = new List<PushFeedback>();
- if (dtAccount != null && dtAccount.Rows.Count > 0)
- {
- Accounts = ModelConvertHelper<PushFeedback>.ConvertToModel(dtAccount);
- }
- #endregion
- foreach (PushFeedback pfb in Accounts)
- {
- Dictionary<string, object> maps = ToMap(pfb);
- maps["StoreGapNum"] = decimal.ToInt64(pfb.StoreGapNum);
- maps["PurchaseTotalNum"] = decimal.ToInt64(pfb.PurchaseTotalNum);
- maps["GoodsName"] = pfb.GoodsName.Replace("/", "_");
- maps["GoodsSpec"] = pfb.GoodsSpec.Replace("/", "_");
- data.Add(maps);
- }
- DataTable dtAccount2 = new DataTable();
- string commandTextAccount2 = "Select A.* From " +
- Config.TablePrefix + "PushRecord A " +
- "Where A.Id=@RecordId " +
- " and A.PushAccountId = " + UserId;
- string resultAccount2;
- List<List<Object>> parametersAccount2 = new List<List<Object>>();
- parametersAccount2.Add(new List<Object>() { "RecordId", RecordId });
- DataAccess.GetValues(commandTextAccount2, ref dtAccount2, DataAccess.ToParameters(parametersAccount2).ToArray(), out resultAccount2);
- IList<PushRecord> Accounts2 = new List<PushRecord>();
- if (dtAccount2 != null && dtAccount2.Rows.Count > 0)
- {
- Accounts2 = ModelConvertHelper<PushRecord>.ConvertToModel(dtAccount2);
- var prd = Accounts2[0];
- prd.Id = Guid.Parse(RecordId);
- mapsrd = ToMap(prd);
- mapsrd["pfbs"] = data;
- }
- }
- else
- {
- return Redirect("/web/supplymobile/bindphone");
- }
- IsoDateTimeConverter timejson = new IsoDateTimeConverter
- {
- DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"
- };
- //var jsonData = JsonConvert.SerializeObject(mapsrd, timejson);
- ViewData["data"] = data;
- ViewData["rddata"] = mapsrd;
- return View();
- }
- else
- {
- return new EmptyResult();
- }
- }
- [HttpPost, Route("mt")]
- public JsonResult mt(string RecordId)
- {
- string UserId = getStaff("userid");
- string RoleId = getStaff("roleid");
- //判断参数是否合法
- if (string.IsNullOrEmpty(UserId))
- {
- return Json(new
- {
- items = new string[] { },
- sum = new { },
- totalCount = 0
- });
- }
- Dictionary<string, object> mapsrd = new Dictionary<String, Object>();
- List<Dictionary<String, Object>> data = new List<Dictionary<String, Object>>(0);
- #region
- DataTable dtAccount = new DataTable();
- string commandTextAccount = "Select A.* From " +
- Config.TablePrefix + "PushFeedback A " +
- "Where A.PushRecordId=@RecordId " +
- " and A.PushAccountId = " + UserId;
- string resultAccount;
- List<List<Object>> parametersAccount = new List<List<Object>>();
- parametersAccount.Add(new List<Object>() { "RecordId", RecordId });
- DataAccess.GetValues(commandTextAccount, ref dtAccount, DataAccess.ToParameters(parametersAccount).ToArray(), out resultAccount);
- IList<PushFeedback> Accounts = new List<PushFeedback>();
- if (dtAccount != null && dtAccount.Rows.Count > 0)
- {
- Accounts = ModelConvertHelper<PushFeedback>.ConvertToModel(dtAccount);
- }
- foreach (PushFeedback pfb in Accounts)
- {
- Dictionary<string, object> maps = ToMap(pfb);
- maps["StoreGapNum"] = decimal.ToInt64(pfb.StoreGapNum);
- maps["PurchaseTotalNum"] = decimal.ToInt64(pfb.PurchaseTotalNum);
- data.Add(maps);
- }
- DataTable dtAccount2 = new DataTable();
- string commandTextAccount2 = "Select A.* From " +
- Config.TablePrefix + "PushRecord A " +
- "Where A.Id=@RecordId " +
- " and A.PushAccountId = " + UserId;
- string resultAccount2;
- List<List<Object>> parametersAccount2 = new List<List<Object>>();
- parametersAccount2.Add(new List<Object>() { "RecordId", RecordId });
- DataAccess.GetValues(commandTextAccount2, ref dtAccount2, DataAccess.ToParameters(parametersAccount2).ToArray(), out resultAccount2);
- IList<PushRecord> Accounts2 = new List<PushRecord>();
- if (dtAccount2 != null && dtAccount2.Rows.Count > 0)
- {
- Accounts2 = ModelConvertHelper<PushRecord>.ConvertToModel(dtAccount2);
- var prd = Accounts2[0];
- prd.Id = Guid.Parse(RecordId);
- mapsrd = ToMap(prd);
- mapsrd["pfbs"] = data;
- }
- #endregion
- return Json(mapsrd);
- }
- [HttpGet, Route("listorder")]
- public ActionResult ListOrder(int OrderBillNo,string TypeId = null,string picUrl=null )
- {
- WechatHelper.ReGetOpenId(HttpContext, "?OrderBillNo=" + OrderBillNo);
- string WxOpenId = HttpContext.Session.GetString("openid");
- //var WxOpenId = "oCzgS1fzaxA3nGpu5pnldkSar1pA";
- if (WxOpenId != null && WxOpenId != "")
- {
- string commandTextUser = "Select accountName,AccountPassword,AccountPhone,Id From "
- + Config.TablePrefix + "Account join contactDoc on FocusMicNo = WxOpenId Where WxOpenId=@WxOpenId and Beactive = 'Y'";
- string resultUser;
- DataTable dt = new DataTable();
- List<List<Object>> parametersUser = new List<List<Object>>();
- parametersUser.Add(new List<Object>() { "WxOpenId", WxOpenId });
- DataAccess.GetValues(commandTextUser, ref dt, DataAccess.ToParameters(parametersUser).ToArray(), out resultUser);
- IList<Account> users = new List<Account>();
- List<Dictionary<String, Object>> data = new List<Dictionary<String, Object>>(0);
- if (dt.Rows.Count > 0)
- {
- users = ModelConvertHelper<Account>.ConvertToModel(dt);
- Account user = users.ToArray()[0];
- ViewData["WxOpenId"] = WxOpenId;
- ViewData["AccountName"] = user.AccountName;
- ViewData["AccountPassword"] = user.AccountPassWord;
- int UserId = user.Id;
- if(TypeId != null && TypeId.Equals(PushBAL.OPaidTypeId)) {
- var Orderdts = PushPaidBackMsgDAL.GetPaidBackMsgDT(OrderBillNo);
- Dictionary<string, object> maps = new Dictionary<string, object>();
- List <Dictionary<String, Object>> dataDT = new List<Dictionary<String, Object>>(0);
- foreach (PurOrderDTEx orderDT in Orderdts)
- {
- Dictionary<string, object> mapOrderDT = ToMap(orderDT);
- dataDT.Add(mapOrderDT);
- }
- maps["Orderdts"] = dataDT;
- data.Add(maps);
- }
- else {
- #region 获取Goods
- DataTable dtAccount = new DataTable();
- string commandTextAccount = "Select A.* From " +
- "PurOrderMT A " +
- "Where A.BillNo=@OrderBillNo ";
- string resultAccount;
- List<List<Object>> parametersAccount = new List<List<Object>>(1);
- parametersAccount.Add(new List<Object>() { "OrderBillNo", OrderBillNo });
- DataAccess.GetValues(commandTextAccount, ref dtAccount, DataAccess.ToParameters(parametersAccount).ToArray(), out resultAccount);
- IList<PurOrderMTEx> Accounts = new List<PurOrderMTEx>();
- if (dtAccount != null && dtAccount.Rows.Count > 0)
- {
- Accounts = ModelConvertHelper<PurOrderMTEx>.ConvertToModel(dtAccount);
- }
- #endregion
- foreach (PurOrderMTEx pfb in Accounts)
- {
- var sql1 = "select A.*,B.AccountRealName as Contact,C.GoodsName,C.GoodsSpec,C.GoodsCode,C.Manufacturer" +
- ",D.ApprovalNo,E.BusinessName from PurOrderDT A " +
- " left join PurOrderMT A1 on A1.BillNo = A.BillNo " +
- " left join sup_Account B on B.PurStaffId = A1.SaleManId " +
- " left join GoodsDoc C on C.EntId = A.EntId and C.GoodsId = A.GoodsId " +
- " left join GoodsAttr D on D.GoodsId = C.GoodsId and D.EntId = C.EntId " +
- " left join BusinessDoc E on E.BusinessId = A1.SuppliersId and E.EntId = A1.EntId " +
- " where A.BillNo = @BillNo ";
- List<SqlParameter> param1 = new List<SqlParameter>(1);
- param1.Add(new SqlParameter("BillNo", pfb.BillNo));
- pfb.Orderdts = DataAccess.GetValues<PurOrderDTEx>(sql1, param1, out var msg);
- Dictionary<string, object> maps = ToMap(pfb);
- List<Dictionary<String, Object>> dataDT = new List<Dictionary<String, Object>>(0);
- foreach (PurOrderDTEx orderDT in pfb.Orderdts)
- {
- Dictionary<string, object> mapOrderDT = ToMap(orderDT);
- dataDT.Add(mapOrderDT);
- }
- maps["Orderdts"] = dataDT;
- data.Add(maps);
- }
- }
- }
- else
- {
- return Redirect("/web/supplymobile/bindphone");
- }
- ViewData["data"] = data;
- if (TypeId == null)
- return View();
- else {
- ViewData["picUrl"] = picUrl;
- return View("listPaid");
- }
- }
- else
- {
- return new EmptyResult();
- }
- }
- }
- }
|