123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.Http;
- using Microsoft.Extensions.Logging;
- using Microsoft.Extensions.Options;
- using Microsoft.AspNetCore.Authorization;
- using System.Web;
- using MySystem.MainModels;
- using LitJson;
- using Library;
- namespace MySystem.Areas.Api.Controllers.v1
- {
- [Area("Api")]
- [Route("Api/v1/[controller]/[action]")]
- public class StoreMachineApplyController : BaseController
- {
- public StoreMachineApplyController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
- {
- }
- #region 创客-首页-仓库管理-申请机具-申请记录
- [Authorize]
- public JsonResult ApplyList(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- List<Dictionary<string, object>> dataList = ApplyListDo(value);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
- }
- public List<Dictionary<string, object>> ApplyListDo(string value)
- {
- JsonData data = JsonMapper.ToObject(value);
- int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客Id
- int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
- int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
- List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
- IQueryable<StoreMachineApply> query = maindb.StoreMachineApply.Where(m => m.Status >= 0 && m.UserId == UserId);
- int TotalCount = query.Count();
- query = query.OrderByDescending(m => m.Sort).ThenByDescending(m => m.Id);
- if (PageNum == 1)
- {
- query = query.Take(PageSize);
- }
- else
- {
- int skipNum = PageSize * (PageNum - 1);
- query = query.Skip(skipNum).Take(PageSize);
- }
- var mydata = query.ToList();
- foreach (var subdata in mydata)
- {
- Dictionary<string, object> curData = new Dictionary<string, object>();
- curData.Add("ApplyNum", subdata.ApplyNum); //申请台数
- curData.Add("Id", subdata.Id); //Id
- curData.Add("Status", subdata.Status); //Status(0 待配货 1 已发货 2 已驳回)
- curData.Add("CreateDate", subdata.CreateDate == null ? "" : subdata.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //CreateDate
- dataList.Add(curData);
- }
- return dataList;
- }
- #endregion
- #region 创客-首页-仓库管理-申请机具-申请记录-详情
- [Authorize]
- public JsonResult ApplyDetail(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- Dictionary<string, object> Obj = ApplyDetailDo(value);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
- }
- public Dictionary<string, object> ApplyDetailDo(string value)
- {
- JsonData data = JsonMapper.ToObject(value);
- int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
- int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客Id
- Dictionary<string, object> Obj = new Dictionary<string, object>();
- StoreMachineApply query = new StoreMachineApply();
- query = maindb.StoreMachineApply.FirstOrDefault(m => m.Id == Id) ?? new StoreMachineApply();
- List<KqProducts> brandList = maindb.KqProducts.ToList();
- List<Dictionary<string, object>> brands = new List<Dictionary<string, object>>();
- foreach (var items in brandList)
- {
- List<StoreStockChange> mydata = maindb.StoreStockChange.Where(m => m.ToUserId == UserId && m.Sort == Id && m.BrandId == items.Id && m.Status >= 0).ToList();
- if (mydata.Count > 0)
- {
- Dictionary<string, object> brandInfo = new Dictionary<string, object>();
- KqProducts kqProducts = maindb.KqProducts.FirstOrDefault(m => m.Id == items.Id);
- brandInfo.Add("Id", items.Id);//产品类型Id
- brandInfo.Add("Name", items.Name);//产品类型名称
- List<Dictionary<string, object>> snList = new List<Dictionary<string, object>>();
- foreach (var subdata in mydata)
- {
- Dictionary<string, object> curData = new Dictionary<string, object>();
- curData.Add("Id", subdata.Id);//记录Id
- curData.Add("SnNo", subdata.SnNo); //机具SN
- snList.Add(curData);
- }
- brandInfo.Add("SnList", snList);
- brands.Add(brandInfo);
- }
- }
- // var StoreStockChange = maindb.StoreStockChange.Where(m => m.ToUserId == UserId);
- Obj.Add("CreateDate", Convert.ToDateTime(query.CreateDate).ToString("yyyy-MM-dd HH:mm:ss")); //创建时间
- Obj.Add("ApplyNum", query.ApplyNum); //申请台数
- Obj.Add("SendNum", query.SendNum); //发货台数
- Obj.Add("UseAmount", query.UseAmount); //使用额度
- Obj.Add("SendMode", query.SendMode); //发货方式
- Obj.Add("ErpCode", query.ErpCode); //快递单号
- Obj.Add("SendSn", brands); //发货SN数据
- return Obj;
- }
- #endregion
- #region 创客-首页-仓库管理-申请机具-确认申请
- [Authorize]
- public JsonResult ConfirmApply(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- AppResultJson result = ConfirmApplyDo(value);
- return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
- }
- public AppResultJson ConfirmApplyDo(string value)
- {
- JsonData data = JsonMapper.ToObject(value);
- int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客
- JsonData ApplyList = data["ApplyList"];//申请数据
- int NeedPay = int.Parse(function.CheckInt(data["NeedPay"].ToString())); //所需金额
- Dictionary<string, object> Obj = new Dictionary<string, object>();
- int ApplyNum = 0;
- for (int i = 0; i < ApplyList.Count; i++)
- {
- int num = Convert.ToInt32(ApplyList[i]["ApplyNum"].ToString());
- ApplyNum += num;
- }
- int CheckUserId = UserId;
- StoreHouse store = maindb.StoreHouse.FirstOrDefault(m => m.UserId == UserId && m.Status > -1 && m.OpId > 0 && m.Sort == 0) ?? new StoreHouse();
- StoreMachineApply query = new StoreMachineApply();
- query = maindb.StoreMachineApply.Add(new StoreMachineApply()
- {
- CreateDate = DateTime.Now, //创建时间
- SendSn = ApplyList.ToJson(),//申请机具json数据
- ApplyNo = "FC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8),//申请单号
- ApplyNum = ApplyNum,// 申请机具数量
- UserId = UserId, //创客
- QueryCount = store.OpId, //运营中心所属人Id
- }).Entity;
- UserAccount userAccount = maindb.UserAccount.FirstOrDefault(m => m.UserId == UserId);
- // if (userAccount.FixedAmount >= NeedPay)
- // {
- // userAccount.FixedAmount -= NeedPay;
- // }
- // if (userAccount.FixedAmount < NeedPay && userAccount.FixedAmount + userAccount.TempAmount >= NeedPay)
- // {
- // userAccount.FixedAmount = 0;
- // userAccount.TempAmount -= NeedPay - userAccount.FixedAmount;
- // }
- // if (userAccount.FixedAmount < NeedPay || userAccount.FixedAmount + userAccount.TempAmount < NeedPay)
- // {
- // return new AppResultJson() { Status = "-1", Info = "可用额度不足,请充值临时额度" };
- // }
- if (userAccount.ValidAmount >= NeedPay)
- {
- userAccount.ValidAmount -= NeedPay;
- query.UseAmount = NeedPay;
- }
- else
- {
- return new AppResultJson() { Status = "-1", Info = "可用额度不足,请充值临时额度" };
- }
- maindb.SaveChanges();
- return new AppResultJson() { Status = "1", Info = "", Data = Obj };
- }
- #endregion
- #region 创客-首页-仓库管理-申请机具-可选品牌列表
- [Authorize]
- public JsonResult ProductList(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- List<Dictionary<string, object>> ObjList = ProductListDo(value);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = ObjList });
- }
- public List<Dictionary<string, object>> ProductListDo(string value)
- {
- JsonData data = JsonMapper.ToObject(value);
- int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客
- List<Dictionary<string, object>> ObjList = new List<Dictionary<string, object>>();
- List<StoreHouse> storeHouse = maindb.StoreHouse.Where(m => m.UserId == UserId && m.BrandId != null && m.Status > 0 && m.Sort == 0).ToList();
- foreach (var item in storeHouse)
- {
- Dictionary<string, object> Obj = new Dictionary<string, object>();
- int Price = 0;
- KqProducts kqProducts = maindb.KqProducts.FirstOrDefault(m => m.Id == Convert.ToInt32(item.BrandId));
- if (kqProducts.Name.Contains("大POS"))
- {
- Price = 300;
- }
- if (kqProducts.Name.Contains("电签"))
- {
- Price = 200;
- }
- Obj.Add("BrandId", kqProducts.Id);
- Obj.Add("BrandName", kqProducts.Name);
- Obj.Add("Price", Price);
- ObjList.Add(Obj);
- }
- return ObjList;
- }
- #endregion
- #region 检查签名是否合法,合法返回1,不合法返回提示信息
- /// <summary>
- /// 检查签名是否合法,合法返回1,不合法返回提示信息
- /// </summary>
- /// <param name="value">请求的参数(json字符串)</param>
- /// <param name="signField">要签名的字段</param>
- /// <returns></returns>
- private string CheckSign(string value, string[] signField)
- {
- JsonData json = JsonMapper.ToObject(value);
- Dictionary<string, string> dic = new Dictionary<string, string>();
- for (int i = 0; i < signField.Length; i++)
- {
- dic.Add(signField[i], json[signField[i]].ToString());
- }
- string sign = json["sign"].ToString(); //客户端签名字符串
- return new Sign().sign(dic, sign);
- }
- #endregion
- }
- }
|