足力健后端,使用.netcore版本,合并1个项目使用

OrderController.cs 55KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188
  1. /* =============================================
  2. -- Author: <Author,,zhangkun>
  3. -- Create date: <Create Date,,20200618>
  4. -- Description: <Description,,订单相关操作)>
  5. -- ============================================*/
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Common;
  9. using System.Common.Helpers;
  10. using System.Data;
  11. using System.IRepositories;
  12. using System.Linq;
  13. using System.Model;
  14. using System.Repositories;
  15. using System.Security.Claims;
  16. using System.Threading.Tasks;
  17. using System.Utility.Http;
  18. using Microsoft.AspNetCore.Mvc;
  19. using Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure;
  20. using Microsoft.Extensions.Configuration;
  21. using SqlSugar;
  22. using TVShoppingCallCenter_ZLJ.Models.Inputs;
  23. namespace TVShoppingCallCenter_ZLJ.Controllers.Order
  24. {
  25. [Route("api/[controller]")]
  26. public class OrderController : BaseController
  27. {
  28. private readonly IBus_OrderDetailRepository bus_OrderDetailRepository;
  29. private readonly IBus_OrderRepository bus_OrderRepository;
  30. private readonly ISys_MarketingRepository bus_MarketingRepository;
  31. private readonly IBus_ProductRepository bus_productRepository;
  32. private readonly ICus_VipInfoRepository cus_vip_infoRepository;
  33. private readonly IBus_StockLogRepository bus_StockLogRepository;
  34. private readonly ICus_ScoreSetRepository cus_score_setRepository;
  35. private readonly IBus_OrderMoneyRepository busOrderMoneyRepository;
  36. private readonly IConfiguration config;
  37. private readonly OrderFunctionController busOrderFunctionController;
  38. public OrderController(IBus_OrderMoneyRepository _busOrderMoneyRepository,OrderFunctionController _OrderFunctionController,ICus_ScoreSetRepository _cus_score_setRepository, IBus_StockLogRepository _bus_StockLogRepository, IBus_OrderRepository _bus_OrderRepository, IBus_OrderDetailRepository _bus_OrderDetailRepository, ISys_MarketingRepository _bus_MarketingRepository, IBus_ProductRepository _productRepository, ICus_VipInfoRepository _cus_vip_infoRepository, IConfiguration _configuration)
  39. {
  40. bus_OrderDetailRepository = _bus_OrderDetailRepository;
  41. bus_OrderRepository = _bus_OrderRepository;
  42. bus_MarketingRepository = _bus_MarketingRepository;
  43. bus_productRepository = _productRepository;
  44. cus_vip_infoRepository = _cus_vip_infoRepository;
  45. bus_StockLogRepository = _bus_StockLogRepository;
  46. cus_score_setRepository = _cus_score_setRepository;
  47. config = _configuration;
  48. busOrderFunctionController = _OrderFunctionController;
  49. busOrderMoneyRepository = _busOrderMoneyRepository;
  50. }
  51. /// <summary>
  52. /// 创建订单
  53. /// </summary>
  54. /// <param name="input"></param>
  55. /// <returns></returns>
  56. [HttpPost("addorder")]
  57. public async Task<IActionResult> AddOrder([FromBody]OrderInput input)
  58. {
  59. try {
  60. T_Cus_VipInfo modelvip = new T_Cus_VipInfo();
  61. #region 验证参数 必填项
  62. if (string.IsNullOrEmpty(input.F_ADFrom))
  63. return Error("请输入选择广告来源");
  64. if (string.IsNullOrEmpty(input.F_Type))
  65. return Error("请输入选择订单类型");
  66. if (string.IsNullOrEmpty(input.F_Id))
  67. return Error("请输入订单编号");
  68. if (string.IsNullOrEmpty(input.F_Customer))
  69. return Error("请输入客户姓名");
  70. if (string.IsNullOrEmpty(input.F_CustomerPhone))
  71. return Error("请输入客户电话");
  72. if (input.F_Type=="售后订单")
  73. return Error("售后订单只能根据售后单自动创建");
  74. #endregion
  75. int exist = await bus_OrderRepository.GetCount(q => q.F_Id == input.F_Id);
  76. if (exist > 0)
  77. {
  78. return Error("此订单号已存在");
  79. }
  80. T_Bus_Order modelOrder = new T_Bus_Order();
  81. #region 订单属性
  82. //必填
  83. modelOrder.F_ADFrom = input.F_ADFrom;
  84. modelOrder.F_Type = input.F_Type;
  85. modelOrder.F_Id = input.F_Id;
  86. modelOrder.F_Customer = input.F_Customer;
  87. modelOrder.F_CustomerPhone = input.F_CustomerPhone;
  88. if (input.F_RecommendId>0)
  89. {
  90. modelOrder.F_RecommendId = input.F_RecommendId;
  91. modelOrder.F_RecommendName = input.F_RecommendName;
  92. }
  93. if (input.F_CustomerType > 0)
  94. { modelOrder.F_CustomerType = input.F_CustomerType; }
  95. if (!string.IsNullOrEmpty(input.F_CustomerTel))
  96. { modelOrder.F_CustomerTel = input.F_CustomerTel; }
  97. //选填 快递属性
  98. modelOrder.F_TrackingNo = "";
  99. if (!string.IsNullOrEmpty(input.F_Addressee))
  100. { modelOrder.F_Addressee = input.F_Addressee; }
  101. if (!string.IsNullOrEmpty(input.F_AddPhone))
  102. { modelOrder.F_AddPhone = input.F_AddPhone; }
  103. if (!string.IsNullOrEmpty(input.F_AddProvince))
  104. { modelOrder.F_AddProvince = input.F_AddProvince; }
  105. if (!string.IsNullOrEmpty(input.F_AddCity))
  106. { modelOrder.F_AddCity = input.F_AddCity; }
  107. if (!string.IsNullOrEmpty(input.F_AddArea))
  108. { modelOrder.F_AddArea = input.F_AddArea; }
  109. if (!string.IsNullOrEmpty(input.F_AddTown))
  110. { modelOrder.F_AddTown = input.F_AddTown; }
  111. if (!string.IsNullOrEmpty(input.F_AddDes))
  112. { modelOrder.F_AddDes = input.F_AddDes; }
  113. if (!string.IsNullOrEmpty(input.F_Address))
  114. { modelOrder.F_Address = input.F_Address; }
  115. if (!string.IsNullOrEmpty(input.F_PostalCode))
  116. { modelOrder.F_PostalCode = input.F_PostalCode; }
  117. if (!string.IsNullOrEmpty(input.F_Express))
  118. { modelOrder.F_Express = input.F_Express; }
  119. if (!string.IsNullOrEmpty(input.F_Remark))
  120. { modelOrder.F_Remark = input.F_Remark; }
  121. if (!string.IsNullOrEmpty(input.F_PayType))
  122. { modelOrder.F_PayType = input.F_PayType; }
  123. if (input.F_VipId > 0)
  124. { modelOrder.F_VipId = input.F_VipId; }
  125. if (input.F_Belong > 0)
  126. {
  127. modelOrder.F_Belong = input.F_Belong;
  128. modelOrder.F_BelongName = input.F_BelongName;
  129. }
  130. else
  131. {
  132. modelOrder.F_Belong = UserLogin.UserId.ObjToInt();
  133. modelOrder.F_BelongName = UserLogin.UserName;
  134. }
  135. modelOrder.F_ExpressFee = input.F_ExpressFee;
  136. modelOrder.F_Stock = input.F_Stock;
  137. modelOrder.F_RealPrice = input.F_RealPrice;
  138. modelOrder.F_UseScore = input.F_UseScore;
  139. //选填 关联属性
  140. modelOrder.F_State = input.F_State;
  141. modelOrder.F_Status = 0;
  142. //必须属性 系统生成
  143. modelOrder.F_AddTime = DateTime.Now;
  144. modelOrder.F_AddUser = UserLogin.UserId.ObjToInt();
  145. modelOrder.F_AddUserName = UserLogin.UserName;
  146. #endregion
  147. if (input.F_State == 1)
  148. {
  149. if (input.OrderDetailList != null && input.OrderDetailList.Count > 0)
  150. { }
  151. else
  152. { return Error("请选择订购商品"); }
  153. if (string.IsNullOrEmpty(input.F_Stock))
  154. {
  155. return Error("请选择出库货仓");
  156. }
  157. if (string.IsNullOrEmpty(modelOrder.F_Express))
  158. {
  159. return Error("快递不能为空");
  160. }
  161. if (string.IsNullOrEmpty(modelOrder.F_AddPhone))
  162. {
  163. return Error("收件人电话不能为空");
  164. }
  165. if (string.IsNullOrEmpty(modelOrder.F_AddTown))
  166. {
  167. return Error("收件人地址不能为空");
  168. }
  169. if (string.IsNullOrEmpty(modelOrder.F_Address))
  170. {
  171. return Error("收件人详细地址不能为空");
  172. }
  173. }
  174. decimal totle = 0.00M;
  175. decimal ActivityMoney = 0.00M;
  176. string UseActivity = "";
  177. string UseActivity4 = ",";
  178. string UseActivity2 = ",";
  179. List<T_Bus_OrderDetail> modelDetailList = new List<T_Bus_OrderDetail>();
  180. #region 订单详情列表核算
  181. if (input.OrderDetailList != null && input.OrderDetailList.Count > 0)
  182. {
  183. int n = 1;
  184. int n2 = input.OrderDetailList.Count + 1;
  185. #region 活动核算
  186. if (input.UseActList != null && input.UseActList.Count > 0)
  187. {
  188. //遍历所有选中的活动
  189. foreach (UseActInput act in input.UseActList)
  190. {
  191. UseActivity += act.id + ",";
  192. //满赠
  193. if (act.type == 1)
  194. {
  195. string[] productidlist = act.gift.Split(',');
  196. foreach (string giftid in productidlist)
  197. {
  198. T_Bus_Product m = await bus_productRepository.GetSingle(b => ("," + giftid + ",").Contains("," + b.F_ProductId + ",") && b.F_IsSale == 0);
  199. if (m != null)
  200. {
  201. T_Bus_OrderDetail modelDetail = new T_Bus_OrderDetail();
  202. modelDetail.F_ProductName = m.F_ProductName;
  203. modelDetail.F_ProductId = m.F_ProductId;
  204. modelDetail.F_Id = Guid.NewGuid().ToString().Replace("-", "");
  205. modelDetail.F_OrderId = input.F_Id;
  206. modelDetail.F_Count = 1;
  207. modelDetail.F_Price = 0.00M;
  208. modelDetail.F_DealPrice = 0.00M;
  209. modelDetail.F_Sort = n2;
  210. modelDetail.F_Remark = "赠品-活动:" + act.id;
  211. modelDetail.F_AddUser = modelOrder.F_AddUser;
  212. modelDetail.F_AddUserName = modelOrder.F_AddUserName;
  213. modelDetail.F_TotlePrice = 0.00M;
  214. modelDetail.F_Activity = act.id;
  215. modelDetail.F_AddTime = DateTime.Now;
  216. modelDetailList.Add(modelDetail);
  217. n2++;
  218. }
  219. }
  220. }
  221. //生日赠
  222. else if (act.type == 2)
  223. {
  224. UseActivity2 += act.gift + ",";
  225. }
  226. //满减
  227. else if (act.type == 3)
  228. {
  229. ActivityMoney += act.money;
  230. }
  231. else if (act.type == 4)
  232. {
  233. UseActivity4 += act.gift + ",";
  234. }
  235. }
  236. UseActivity = UseActivity.Trim(',');
  237. }
  238. #endregion
  239. #region 商品核算
  240. foreach (OrderDetailInput m in input.OrderDetailList)
  241. {
  242. T_Bus_Product modelProduct = await bus_productRepository.GetSingle(b => b.F_ProductId == m.F_ProductId);
  243. if (modelProduct == null)
  244. return Error("商品不存在:" + m.F_ProductId);
  245. T_Bus_OrderDetail modelDetail = new T_Bus_OrderDetail();
  246. modelDetail.F_ProductName = modelProduct.F_ProductName;
  247. modelDetail.F_ProductId = modelProduct.F_ProductId;
  248. modelDetail.F_Id = Guid.NewGuid().ToString().Replace("-", "");
  249. modelDetail.F_OrderId = input.F_Id;
  250. modelDetail.F_Count = m.F_Count;
  251. modelDetail.F_Price = modelProduct.F_MemberPrice;
  252. //参加活动特价
  253. if (UseActivity4.Contains("," + modelProduct.F_ProductId + ","))
  254. modelDetail.F_DealPrice = modelProduct.F_SpecialPrice;
  255. else
  256. modelDetail.F_DealPrice = modelProduct.F_MemberPrice;
  257. //参加生日
  258. if (UseActivity2.Contains("," + modelProduct.F_ProductId + ","))
  259. {
  260. modelDetail.F_DealPrice = 0.00M;
  261. modelDetail.F_Remark = "生日赠品-活动:";
  262. }
  263. modelDetail.F_Sort = n;
  264. modelDetail.F_AddTime = DateTime.Now;
  265. modelDetail.F_AddUser = modelOrder.F_AddUser;
  266. modelDetail.F_AddUserName = modelOrder.F_AddUserName;
  267. modelDetail.F_TotlePrice = modelDetail.F_DealPrice * modelDetail.F_Count;
  268. modelDetail.F_Activity = 0;
  269. if (modelProduct.F_Tag.IndexOf(".") > -1&& !string.IsNullOrEmpty(UseActivity))
  270. {
  271. string[] tagarry = modelProduct.F_Tag.Split(',');
  272. string[] actlist = UseActivity.Split(',');
  273. string tag = tagarry.First(a => a.StartsWith(".")).ToString();
  274. T_Sys_Marketing modelactive = await bus_MarketingRepository.GetFirst(b => actlist.Contains(b.F_ID.ToString())&& b.F_EndTime >= DateTime.Now && b.F_StartTime <= DateTime.Now && b.F_IsDelete == 0 && ("," + b.F_Commodity + ",").Contains(("," + tag + ",")));
  275. //此商品参加活动
  276. if (modelactive != null)
  277. {
  278. modelDetail.F_Activity = modelactive.F_ID;
  279. }
  280. }
  281. else { modelDetail.F_Activity = 0; }
  282. totle += modelDetail.F_TotlePrice;
  283. modelDetailList.Add(modelDetail);
  284. n++;
  285. }
  286. #endregion
  287. modelOrder.F_TotlePrice = totle;
  288. modelOrder.F_ActivityMoney = ActivityMoney;
  289. modelOrder.F_UseActivity = UseActivity;
  290. }
  291. else
  292. {
  293. //不改变订单
  294. }
  295. #endregion
  296. //订单完成后也不计算积分
  297. modelOrder.F_Score = 0.00M;
  298. T_Cus_ScoreSet modelscore = await cus_score_setRepository.GetSingle(x => x.F_State == 1);
  299. if (modelscore == null)
  300. {
  301. modelscore = new T_Cus_ScoreSet();
  302. modelscore.F_Start = 0;
  303. modelscore.F_StartDebit = 1;
  304. modelscore.F_DebitPercent = 1000;
  305. }
  306. #region 直接提交 锁库存log 锁积分log
  307. if (input.F_State == 1)
  308. {
  309. if (modelscore.F_StartDebit == 1)
  310. {
  311. modelOrder.F_UseScore = 0;
  312. }
  313. modelOrder.F_FlowNum = DateTime.Now.ToString("yyMMddHHmmss")+"U" + UserLogin.UserId +"R"+ new Random().Next(9);
  314. string strStock = await busOrderFunctionController.ChangeStockOne(modelOrder, 1, modelDetailList);
  315. if (strStock != "1")
  316. { return Error(strStock); }
  317. if (modelscore.F_Start == 1)
  318. {
  319. //订单完成后计算积分
  320. modelOrder.F_Score = -0.01M;
  321. }
  322. modelOrder.F_SubmitTime = DateTime.Now;
  323. }
  324. #endregion
  325. //计算结果 积分有规则
  326. modelOrder.F_ShouldPrice = modelOrder.F_TotlePrice - ActivityMoney + modelOrder.F_ExpressFee- modelOrder.F_UseScore / modelscore.F_DebitPercent;
  327. modelOrder.F_PayState = 0;
  328. if (await bus_OrderRepository.AddReturnCount(modelOrder))
  329. {
  330. if (modelDetailList != null && modelDetailList.Count > 0)
  331. {
  332. if (await bus_OrderDetailRepository.AddMany(modelDetailList))
  333. return Success("订单添加成功2");
  334. else
  335. return Error("订单添加失败,请重试!1");
  336. }
  337. return Success("订单添加成功1");
  338. }
  339. else
  340. {
  341. return Error("订单添加失败,请重试!2");
  342. }
  343. }
  344. catch (Exception ex)
  345. { return Error(ex.Message); }
  346. }
  347. /// <summary>
  348. /// 修改订单
  349. /// </summary>
  350. /// <param name="input"></param>
  351. /// <returns></returns>
  352. [HttpPost("editorder")]
  353. public async Task<IActionResult> EditOrder([FromBody]OrderInput input)
  354. {
  355. T_Cus_VipInfo modelvip = new T_Cus_VipInfo();
  356. #region 验证参数 必填项
  357. if (string.IsNullOrEmpty(input.F_ADFrom))
  358. return Error("请输入选择广告来源");
  359. if (string.IsNullOrEmpty(input.F_Type))
  360. return Error("请输入选择订单类型");
  361. if (string.IsNullOrEmpty(input.F_Id))
  362. return Error("请输入订单编号");
  363. if (string.IsNullOrEmpty(input.F_Customer))
  364. return Error("请输入客户姓名");
  365. if (string.IsNullOrEmpty(input.F_CustomerPhone))
  366. return Error("请输入客户电话");
  367. if (input.F_Type == "售后订单")
  368. return Error("售后订单销售不能修改");
  369. #endregion
  370. T_Bus_Order modelOrder = await bus_OrderRepository.GetSingle(q => q.F_Id == input.F_Id);
  371. if (modelOrder == null)
  372. {
  373. return Error("此订单号不存在");
  374. }
  375. //保存 审退回 仓退回
  376. if (!(new int[] { 0, 2 }.Contains(modelOrder.F_State)))
  377. {
  378. return Error("已提交订单不允许修改,先撤回订单");
  379. }
  380. #region 数据绑定
  381. //必填
  382. modelOrder.F_ADFrom = input.F_ADFrom;
  383. modelOrder.F_Type = input.F_Type;
  384. modelOrder.F_Customer = input.F_Customer;
  385. modelOrder.F_CustomerPhone = input.F_CustomerPhone;
  386. if (input.F_RecommendId > 0)
  387. {
  388. modelOrder.F_RecommendId = input.F_RecommendId;
  389. modelOrder.F_RecommendName = input.F_RecommendName;
  390. }
  391. if (input.F_CustomerType > 0)
  392. { modelOrder.F_CustomerType = input.F_CustomerType; }
  393. if (!string.IsNullOrEmpty(input.F_CustomerTel))
  394. { modelOrder.F_CustomerTel = input.F_CustomerTel; }
  395. //选填 快递属性
  396. modelOrder.F_TrackingNo = "";
  397. if (!string.IsNullOrEmpty(input.F_Addressee))
  398. { modelOrder.F_Addressee = input.F_Addressee; }
  399. if (!string.IsNullOrEmpty(input.F_AddPhone))
  400. { modelOrder.F_AddPhone = input.F_AddPhone; }
  401. if (!string.IsNullOrEmpty(input.F_AddProvince))
  402. { modelOrder.F_AddProvince = input.F_AddProvince; }
  403. if (!string.IsNullOrEmpty(input.F_AddCity))
  404. { modelOrder.F_AddCity = input.F_AddCity; }
  405. if (!string.IsNullOrEmpty(input.F_AddArea))
  406. { modelOrder.F_AddArea = input.F_AddArea; }
  407. if (!string.IsNullOrEmpty(input.F_AddTown))
  408. { modelOrder.F_AddTown = input.F_AddTown; }
  409. if (!string.IsNullOrEmpty(input.F_AddDes))
  410. { modelOrder.F_AddDes = input.F_AddDes; }
  411. if (!string.IsNullOrEmpty(input.F_Address))
  412. { modelOrder.F_Address = input.F_Address; }
  413. if (!string.IsNullOrEmpty(input.F_PostalCode))
  414. { modelOrder.F_PostalCode = input.F_PostalCode; }
  415. if (!string.IsNullOrEmpty(input.F_Express))
  416. { modelOrder.F_Express = input.F_Express; }
  417. if (!string.IsNullOrEmpty(input.F_Remark))
  418. { modelOrder.F_Remark = input.F_Remark; }
  419. if (!string.IsNullOrEmpty(input.F_PayType))
  420. { modelOrder.F_PayType = input.F_PayType; }
  421. if (input.F_Belong > 0)
  422. {
  423. modelOrder.F_Belong = input.F_Belong;
  424. modelOrder.F_BelongName = input.F_BelongName;
  425. }
  426. else
  427. {
  428. modelOrder.F_Belong = UserLogin.UserId.ObjToInt();
  429. modelOrder.F_BelongName = UserLogin.UserName;
  430. }
  431. modelOrder.F_ExpressFee = input.F_ExpressFee;
  432. modelOrder.F_Stock = input.F_Stock;
  433. modelOrder.F_RealPrice = input.F_RealPrice;
  434. modelOrder.F_UseScore = input.F_UseScore;
  435. //选填 关联属性
  436. modelOrder.F_VipId = input.F_VipId;
  437. modelOrder.F_State = input.F_State;
  438. modelOrder.F_Status = 0;
  439. //必须属性 系统生成
  440. modelOrder.F_AddTime = DateTime.Now;
  441. modelOrder.F_AddUser = UserLogin.UserId.ObjToInt();
  442. modelOrder.F_AddUserName = UserLogin.UserName;
  443. #endregion
  444. //计算属性 商品计算
  445. decimal totle = 0.00M;
  446. decimal ActivityMoney = 0.00M;
  447. string UseActivity = "";
  448. string UseActivity4 = ",";
  449. string UseActivity2 = ",";
  450. List<T_Bus_OrderDetail> modelDetailList = new List<T_Bus_OrderDetail>();
  451. if (input.OrderDetailList != null && input.OrderDetailList.Count > 0)
  452. {
  453. #region 核算活动
  454. int n2 = input.OrderDetailList.Count + 1;
  455. if (input.UseActList != null && input.UseActList.Count > 0)
  456. {
  457. //遍历所有选中的活动
  458. foreach (UseActInput act in input.UseActList)
  459. {
  460. UseActivity += act.id + ",";
  461. //满赠
  462. if (act.type == 1)
  463. {
  464. string[] productidlist = act.gift.Split(',');
  465. foreach (string giftid in productidlist)
  466. {
  467. T_Bus_Product m = await bus_productRepository.GetSingle(b => ("," + giftid + ",").Contains("," + b.F_ProductId + ",") && b.F_IsSale == 0);
  468. if (m != null)
  469. {
  470. T_Bus_OrderDetail modelDetail = new T_Bus_OrderDetail();
  471. modelDetail.F_ProductName = m.F_ProductName;
  472. modelDetail.F_ProductId = m.F_ProductId;
  473. modelDetail.F_Id = Guid.NewGuid().ToString().Replace("-", "");
  474. modelDetail.F_OrderId = input.F_Id;
  475. modelDetail.F_Count = 1;
  476. modelDetail.F_Price = 0.00M;
  477. modelDetail.F_DealPrice = 0.00M;
  478. modelDetail.F_Sort = n2;
  479. modelDetail.F_Remark = "赠品-活动:" + act.id;
  480. modelDetail.F_AddUser = modelOrder.F_AddUser;
  481. modelDetail.F_AddUserName = modelOrder.F_AddUserName;
  482. modelDetail.F_TotlePrice = 0.00M;
  483. modelDetail.F_Activity = act.id;
  484. modelDetail.F_AddTime = DateTime.Now.AddSeconds(30);
  485. modelDetailList.Add(modelDetail);
  486. n2++;
  487. }
  488. }
  489. }
  490. //生日赠
  491. else if (act.type == 2)
  492. {
  493. UseActivity2 += act.gift + ",";
  494. }
  495. //满减
  496. else if (act.type == 3)
  497. {
  498. ActivityMoney += act.money;
  499. }
  500. else if (act.type == 4)
  501. {
  502. UseActivity4 += act.gift + ",";
  503. }
  504. }
  505. UseActivity = UseActivity.Trim(',');
  506. }
  507. #endregion
  508. #region 核算商品
  509. int n = 1;
  510. foreach (OrderDetailInput m in input.OrderDetailList)
  511. {
  512. T_Bus_Product modelProduct = await bus_productRepository.GetSingle(b => b.F_ProductId == m.F_ProductId);
  513. if (modelProduct == null) return Error("在售商品不存在");
  514. T_Bus_OrderDetail modelDetail = new T_Bus_OrderDetail();
  515. modelDetail.F_ProductName = modelProduct.F_ProductName;
  516. modelDetail.F_ProductId = modelProduct.F_ProductId;
  517. modelDetail.F_Id = Guid.NewGuid().ToString().Replace("-", "");
  518. modelDetail.F_OrderId = input.F_Id;
  519. modelDetail.F_Count = m.F_Count;
  520. modelDetail.F_Price = modelProduct.F_MemberPrice;
  521. //参加活动特价
  522. if (UseActivity4.Contains("," + modelProduct.F_ProductId + ","))
  523. modelDetail.F_DealPrice = modelProduct.F_SpecialPrice;
  524. else
  525. modelDetail.F_DealPrice = modelProduct.F_MemberPrice;
  526. //参加生日
  527. if (UseActivity2.Contains("," + modelProduct.F_ProductId + ","))
  528. {
  529. modelDetail.F_DealPrice = 0.00M;
  530. modelDetail.F_Remark = "生日赠品-活动:";
  531. }
  532. modelDetail.F_Sort = n;
  533. modelDetail.F_AddTime = DateTime.Now;
  534. modelDetail.F_AddUser = modelOrder.F_AddUser;
  535. modelDetail.F_AddUserName = modelOrder.F_AddUserName;
  536. modelDetail.F_TotlePrice = modelDetail.F_DealPrice * modelDetail.F_Count;
  537. modelDetail.F_Activity = 0;
  538. if (modelProduct.F_Tag.IndexOf(".") > -1 && !string.IsNullOrEmpty(UseActivity))
  539. {
  540. string[] tagarry = modelProduct.F_Tag.Split(',');
  541. string[] actlist = UseActivity.Split(',');
  542. string tag = tagarry.First(a => a.StartsWith(".")).ToString();
  543. T_Sys_Marketing modelactive = await bus_MarketingRepository.GetFirst(b => actlist.Contains(b.F_ID.ToString()) && b.F_EndTime >= DateTime.Now && b.F_StartTime<=DateTime.Now && b.F_IsDelete==0&&("," + b.F_Commodity + ",").Contains(("," + tag + ",")));
  544. //此商品参加活动
  545. if (modelactive != null)
  546. {
  547. modelDetail.F_Activity = modelactive.F_ID;
  548. }
  549. }
  550. totle += modelDetail.F_TotlePrice;
  551. modelDetailList.Add(modelDetail);
  552. n++;
  553. }
  554. #endregion
  555. modelOrder.F_TotlePrice = totle;
  556. modelOrder.F_ActivityMoney = ActivityMoney;
  557. modelOrder.F_UseActivity = UseActivity;
  558. }
  559. else
  560. {
  561. //不传商品 表明不修改商品信息 不重新计算商品
  562. }
  563. //直接提交 锁库存
  564. T_Cus_ScoreSet modelscore = await cus_score_setRepository.GetSingle(x => x.F_State == 1);
  565. if (modelscore == null)
  566. {
  567. modelscore = new T_Cus_ScoreSet();
  568. modelscore.F_Start = 0;
  569. modelscore.F_StartDebit = 1;
  570. modelscore.F_DebitPercent = 1000;
  571. }
  572. #region 提交 更改状态 库存 积分
  573. if (input.F_State == 1)
  574. {
  575. if (string.IsNullOrEmpty(input.F_Stock))
  576. {
  577. return Error("请选择出库货仓");
  578. }
  579. if (string.IsNullOrEmpty(modelOrder.F_Express))
  580. {
  581. return Error("快递不能为空");
  582. }
  583. if (string.IsNullOrEmpty(modelOrder.F_AddPhone))
  584. {
  585. return Error("收件人电话不能为空");
  586. }
  587. if (string.IsNullOrEmpty(modelOrder.F_AddTown))
  588. {
  589. return Error("收件人地址不能为空");
  590. }
  591. if (string.IsNullOrEmpty(modelOrder.F_Address))
  592. {
  593. return Error("收件人详细地址不能为空");
  594. }
  595. modelOrder.F_FlowNum = DateTime.Now.ToString("yyMMddHHmmss") + "U" + UserLogin.UserId + "R" + new Random().Next(9);
  596. if (modelscore.F_Start == 1)
  597. {
  598. //订单完成后计算积分
  599. modelOrder.F_Score = -0.01M;
  600. }
  601. else
  602. { //订单完成后也不计算积分
  603. modelOrder.F_Score = 0.00M;
  604. }
  605. if (modelscore.F_StartDebit == 1)
  606. {
  607. modelOrder.F_UseScore = 0;
  608. }
  609. string strStock = await busOrderFunctionController.ChangeStockOne(modelOrder, 1, modelDetailList);
  610. if (strStock != "1")
  611. { return Error(strStock); }
  612. modelOrder.F_SubmitTime = DateTime.Now;
  613. }
  614. #endregion
  615. if (!modelOrder.F_Type.Contains("售后"))
  616. { modelOrder.F_ShouldPrice = modelOrder.F_TotlePrice - modelOrder.F_ActivityMoney + modelOrder.F_ExpressFee - modelOrder.F_UseScore / modelscore.F_DebitPercent;
  617. }
  618. DataTable dt=await busOrderMoneyRepository.GetTableSugar(string.Format("SELECT IFNULL(SUM(F_Money),0) FROM T_Bus_OrderMoney WHERE F_OrderId='{0}' AND F_State=1", modelOrder.F_Id));
  619. modelOrder.F_RealPrice = dt.Rows[0][0].ObjToDecimal() ;
  620. if (modelOrder.F_ShouldPrice > 0)
  621. {
  622. if (modelOrder.F_ShouldPrice <= modelOrder.F_RealPrice)
  623. modelOrder.F_PayState = 1;
  624. else
  625. modelOrder.F_PayState = 0;
  626. }
  627. else
  628. {
  629. if (modelOrder.F_ShouldPrice >= modelOrder.F_RealPrice)
  630. modelOrder.F_PayState = 3;
  631. else
  632. modelOrder.F_PayState = 2;
  633. }
  634. //待付款 客服审核付款情况后改为已付款
  635. if (await bus_OrderRepository.Update(modelOrder))
  636. {
  637. if (input.OrderDetailList != null && input.OrderDetailList.Count > 0)
  638. {
  639. //删除之前订单商品,重新添加
  640. if (await bus_OrderDetailRepository.Delete(q => q.F_OrderId == modelOrder.F_Id))
  641. {
  642. if (await bus_OrderDetailRepository.AddMany(modelDetailList))
  643. return Success("订单生成成功");
  644. else
  645. return Error("订单操作失败,请重试1!");
  646. }
  647. else {
  648. if (await bus_OrderDetailRepository.AddMany(modelDetailList))
  649. return Success("订单生成成功2");
  650. else
  651. return Error("订单操作失败,请重试2!");
  652. }
  653. }
  654. else { return Success("成功"); }
  655. }
  656. return Error("订单添加失败,请重试!");
  657. }
  658. /// <summary>
  659. /// 根据商品组合 获取符合的所有活动
  660. /// </summary>
  661. /// <param name="input"></param>
  662. /// <returns></returns>
  663. [HttpPost("getact")]
  664. public async Task<IActionResult> GetAct([FromBody]List<OrderDetailInput> input)
  665. {
  666. decimal def = 0.00M;
  667. if (input.Count < 1)
  668. return Error("请选择商品/数量");
  669. //统计活动金额是否符合条件 满减
  670. Dictionary<int, decimal> acttype3 = new Dictionary<int, decimal>();
  671. //内部计算
  672. Dictionary<int, decimal> innerCompute = new Dictionary<int, decimal>();
  673. //选择活动
  674. Dictionary<int, string> chooseact = new Dictionary<int, string>();
  675. List<UseActInput> actlist = new List<UseActInput>();
  676. foreach (OrderDetailInput m in input)
  677. {
  678. T_Bus_Product modelProduct = await bus_productRepository.GetSingle(b => b.F_ProductId == m.F_ProductId);
  679. if (modelProduct != null)
  680. {
  681. //是否有活动标签
  682. if (modelProduct.F_Tag.IndexOf(".") > -1)
  683. {
  684. string[] tagarry = modelProduct.F_Tag.Split(',');
  685. string tag = tagarry.First(a => a.StartsWith(".")).ToString();
  686. //标签内有效期
  687. var Marketing = await bus_MarketingRepository.GetListALL(b => ("," + b.F_Commodity + ",").Contains("," + tag + ",") && b.F_StartTime <= DateTime.Now && b.F_EndTime >= DateTime.Now && b.F_IsDelete == 0);
  688. //此商品参加活动
  689. if (Marketing != null)
  690. {
  691. T_Sys_Marketing modelactive = Marketing.FirstOrDefault();
  692. if (modelactive.F_Type == 1)
  693. {
  694. //满赠
  695. //判断此人是否有参与活动的资格 默认暂不筛选
  696. if (chooseact.ContainsKey(modelactive.F_ID))
  697. continue;
  698. if (innerCompute.ContainsKey(modelactive.F_ID))
  699. {
  700. innerCompute[modelactive.F_ID] = (decimal)modelProduct.F_MemberPrice * m.F_Count + innerCompute[modelactive.F_ID].ObjToDecimal();
  701. }
  702. else
  703. {
  704. innerCompute.Add(modelactive.F_ID, (decimal)modelProduct.F_MemberPrice * m.F_Count);
  705. }
  706. if (modelactive.F_Money.ObjToDecimal() <= (decimal)innerCompute[modelactive.F_ID])
  707. {
  708. chooseact.Add(modelactive.F_ID, "1_" + modelactive.F_Gift);
  709. actlist.Add(new UseActInput { id = modelactive.F_ID, type = 1, gift = modelactive.F_Gift, money = def, actname = modelactive.F_Name, actdes = modelactive.F_PromotionRules });
  710. }
  711. }
  712. else if (modelactive.F_Type == 2)
  713. {
  714. // 生日
  715. //TODO 判断此人是否有参与活动的资格 默认暂不筛选
  716. if (chooseact.ContainsKey(modelactive.F_ID))
  717. continue;
  718. chooseact.Add(modelactive.F_ID, "2_" + modelactive.F_Commodity);
  719. actlist.Add(new UseActInput { id = modelactive.F_ID, type = 2, gift = modelactive.F_Gift, money = def, actname = modelactive.F_Name, actdes = modelactive.F_PromotionRules });
  720. }
  721. else if (modelactive.F_Type == 3)
  722. {
  723. //满减
  724. //判断此人是否有参与活动的资格 默认暂不筛选
  725. if (innerCompute.ContainsKey(modelactive.F_ID))
  726. {
  727. innerCompute[modelactive.F_ID] = (decimal)modelProduct.F_MemberPrice * m.F_Count + innerCompute[modelactive.F_ID];
  728. }
  729. else
  730. {
  731. innerCompute.Add(modelactive.F_ID, (decimal)modelProduct.F_MemberPrice * m.F_Count);
  732. }
  733. string[] AmountRange = modelactive.F_AmountRange.Split(',');
  734. for (int i = 0; i < AmountRange.Length; i++)
  735. {
  736. //符合满减某个条件
  737. if (innerCompute[modelactive.F_ID] >= AmountRange[i].ObjToDecimal())
  738. {
  739. if (acttype3.ContainsKey(modelactive.F_ID))
  740. {
  741. //当前减免金额大于之前发赋值,替换掉
  742. if (modelactive.F_Money.Split(',')[i].ObjToDecimal() > acttype3[modelactive.F_ID])
  743. {
  744. acttype3[modelactive.F_ID] = modelactive.F_Money.Split(',')[i].ObjToDecimal();
  745. actlist.ForEach(q => { if (q.id == modelactive.F_ID) { q.money = modelactive.F_Money.Split(',')[i].ObjToDecimal(); } });
  746. }
  747. }
  748. else
  749. {
  750. //满足条件,赋值满减金额 减的金额
  751. acttype3.Add(modelactive.F_ID, modelactive.F_Money.Split(',')[i].ObjToDecimal());
  752. actlist.Add(new UseActInput { id = modelactive.F_ID, type = 3, gift = "", money = modelactive.F_Money.Split(',')[i].ObjToDecimal(), actname = modelactive.F_Name, actdes = modelactive.F_PromotionRules });
  753. }
  754. }
  755. }
  756. }
  757. else if (modelactive.F_Type == 4)
  758. {
  759. //限时特惠
  760. //判断此人是否有参与活动的资格 默认暂不筛选
  761. if (chooseact.ContainsKey(modelactive.F_ID))
  762. {
  763. chooseact[modelactive.F_ID] = chooseact[modelactive.F_ID] + "," + m.F_ProductId.ToString();
  764. actlist.ForEach(q => { if (q.id == modelactive.F_ID) { q.gift = q.gift + m.F_ProductId.ToString(); } });
  765. }
  766. else
  767. {
  768. chooseact.Add(modelactive.F_ID, "4_" + m.F_ProductId.ToString());
  769. actlist.Add(new UseActInput { id = modelactive.F_ID, type = 4, gift = m.F_ProductId.ToString(), money = modelactive.F_Money.ObjToDecimal(), actname = modelactive.F_Name, actdes = modelactive.F_PromotionRules });
  770. }
  771. }
  772. }
  773. }
  774. }
  775. }
  776. return Success("参与活动", actlist);
  777. }
  778. /// <summary>
  779. /// 获取订单详情
  780. /// </summary>
  781. /// <param name="input"></param>
  782. /// <returns></returns>
  783. [HttpPost("getorderdetail")]
  784. public async Task<IActionResult> GetOrderDetail(string orderid)
  785. {
  786. if (string.IsNullOrEmpty(orderid))
  787. return Error("请输入订单号");
  788. T_Bus_Order modelOrder = await bus_OrderRepository.GetSingle(q => q.F_Id == orderid);
  789. OrderInput modelreturn = new OrderInput();
  790. if (modelOrder != null)
  791. {
  792. ModelConvertHelper<OrderInput, T_Bus_Order>.ModeToModel(modelreturn, modelOrder);
  793. List<OrderDetailInput> modeldetailreturn = new List<OrderDetailInput>();
  794. List<T_Bus_OrderDetail> detaillist = await bus_OrderDetailRepository.GetListALL(q => q.F_OrderId == modelOrder.F_Id, o => o.F_Sort, OrderByType.Asc);
  795. if (detaillist != null)
  796. {
  797. foreach (T_Bus_OrderDetail m in detaillist)
  798. {
  799. OrderDetailInput model = new OrderDetailInput();
  800. model.F_ProductName = m.F_ProductName;
  801. model.F_ProductId = m.F_ProductId;
  802. model.F_Id = m.F_Id;
  803. model.F_OrderId = m.F_OrderId;
  804. model.F_Count = m.F_Count;
  805. model.F_Price = m.F_Price;
  806. model.F_DealPrice = m.F_DealPrice;
  807. model.F_Sort = m.F_Sort;
  808. model.F_AddTime = m.F_AddTime;
  809. model.F_Remark = m.F_Remark;
  810. model.F_AddUser = m.F_AddUser;
  811. model.F_AddUserName = m.F_ProductName;
  812. model.F_TotlePrice = m.F_TotlePrice;
  813. model.F_Activity = m.F_Activity;
  814. modeldetailreturn.Add(model);
  815. }
  816. }
  817. modelreturn.OrderDetailList = modeldetailreturn;
  818. List<UseActInput> actlist = new List<UseActInput>();
  819. List<T_Sys_Marketing> modelactiveList = await bus_MarketingRepository.GetListALL(b => ("," + modelOrder.F_UseActivity + ",").Contains(("," + b.F_ID.ToString() + ",")));
  820. if (modelactiveList != null && modelactiveList.Count > 0)
  821. {
  822. foreach (T_Sys_Marketing modelactive in modelactiveList)
  823. {
  824. actlist.Add(new UseActInput { id = modelactive.F_ID, type = modelactive.F_Type, gift = modelactive.F_Gift, money = modelactive.F_Money.ObjToDecimal(), actname = modelactive.F_Name, actdes = modelactive.F_PromotionRules });
  825. }
  826. }
  827. modelreturn.UseActList = actlist;
  828. }
  829. return Success("成功", modelreturn);
  830. }
  831. /// <summary>
  832. /// 获取订单分页列表
  833. /// </summary>
  834. /// <param name="input"></param>
  835. /// <returns></returns>
  836. [HttpPost("getorderlistbypage")]
  837. public async Task<IActionResult> GetXSOrderListByPage(OrderInput input)
  838. {
  839. List<IConditionalModel> conModels = new List<IConditionalModel>();
  840. #region 条件筛选
  841. conModels.Add(new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.GreaterThanOrEqual, FieldValue = "0" });
  842. //状态
  843. if (input.F_State > -2)
  844. {
  845. conModels.Add(new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.Equal, FieldValue = input.F_State.ToString() });
  846. }
  847. //根据角色展示列表
  848. if (UserLogin.RoleCode == "XS")
  849. {
  850. conModels.Add(new ConditionalCollections()
  851. {
  852. ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>()
  853. {
  854. new KeyValuePair<WhereType, ConditionalModel>( WhereType.And , new ConditionalModel() { FieldName = "F_AddUser", ConditionalType = ConditionalType.Equal, FieldValue = UserLogin.UserId }),
  855. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or, new ConditionalModel() { FieldName = "F_Belong", ConditionalType = ConditionalType.Equal, FieldValue = UserLogin.UserId })
  856. }
  857. } );
  858. }
  859. else if (UserLogin.RoleCode == "KF" && input.F_State != 1)
  860. {
  861. conModels.Add(new ConditionalModel() { FieldName = "F_CheckUser", ConditionalType = ConditionalType.Equal, FieldValue = UserLogin.UserId });
  862. }
  863. else if (UserLogin.RoleCode == "KG" && input.F_State != 3)
  864. {
  865. conModels.Add(new ConditionalModel() { FieldName = "F_StockUser", ConditionalType = ConditionalType.Equal, FieldValue = UserLogin.UserId });
  866. //OR conModels.Add(new ConditionalModel() { FieldName = "F_SendUser", ConditionalType = ConditionalType.Equal, FieldValue = UserLogin.UserId });
  867. }
  868. if (!string.IsNullOrEmpty(input.F_ADFrom))
  869. {
  870. conModels.Add(new ConditionalModel() { FieldName = "F_ADFrom", ConditionalType = ConditionalType.Equal, FieldValue = input.F_ADFrom });
  871. }
  872. if (!string.IsNullOrEmpty(input.F_Type))
  873. {
  874. conModels.Add(new ConditionalModel() { FieldName = "F_Type", ConditionalType = ConditionalType.Equal, FieldValue = input.F_Type });
  875. }
  876. if (!string.IsNullOrEmpty(input.F_Id))
  877. {
  878. conModels.Add(new ConditionalModel() { FieldName = "F_Id", ConditionalType = ConditionalType.Equal, FieldValue = input.F_Id });
  879. }
  880. if (!string.IsNullOrEmpty(input.F_Customer))
  881. {
  882. conModels.Add(new ConditionalModel() { FieldName = "F_Customer", ConditionalType = ConditionalType.Equal, FieldValue = input.F_Customer });
  883. }
  884. if (!string.IsNullOrEmpty(input.F_CustomerPhone))
  885. {
  886. conModels.Add(new ConditionalModel() { FieldName = "F_CustomerPhone", ConditionalType = ConditionalType.Equal, FieldValue = input.F_CustomerPhone });
  887. }
  888. if (!string.IsNullOrEmpty(input.F_TrackingNo))
  889. {
  890. conModels.Add(new ConditionalModel() { FieldName = "F_TrackingNo", ConditionalType = ConditionalType.Equal, FieldValue = input.F_TrackingNo });
  891. }
  892. if (!string.IsNullOrEmpty(input.F_AddProvince))
  893. {
  894. conModels.Add(new ConditionalModel() { FieldName = "F_AddProvince", ConditionalType = ConditionalType.Equal, FieldValue = input.F_AddProvince });
  895. }
  896. if (!string.IsNullOrEmpty(input.F_AddCity))
  897. {
  898. conModels.Add(new ConditionalModel() { FieldName = "F_AddCity", ConditionalType = ConditionalType.Equal, FieldValue = input.F_AddCity });
  899. }
  900. if (!string.IsNullOrEmpty(input.F_AddArea))
  901. {
  902. conModels.Add(new ConditionalModel() { FieldName = "F_AddArea", ConditionalType = ConditionalType.Equal, FieldValue = input.F_AddArea });
  903. }
  904. if (!string.IsNullOrEmpty(input.F_AddTown))
  905. {
  906. conModels.Add(new ConditionalModel() { FieldName = "F_AddTown", ConditionalType = ConditionalType.Equal, FieldValue = input.F_AddTown });
  907. }
  908. if (!string.IsNullOrEmpty(input.F_Express))
  909. {
  910. conModels.Add(new ConditionalModel() { FieldName = "F_Express", ConditionalType = ConditionalType.Equal, FieldValue = input.F_Express });
  911. }
  912. if (!string.IsNullOrEmpty(input.F_PayType))
  913. {
  914. conModels.Add(new ConditionalModel() { FieldName = "F_PayType", ConditionalType = ConditionalType.Equal, FieldValue = input.F_PayType });
  915. }
  916. if (!string.IsNullOrEmpty(input.F_Stock))
  917. {
  918. conModels.Add(new ConditionalModel() { FieldName = "F_Stock", ConditionalType = ConditionalType.Equal, FieldValue = input.F_Stock });
  919. }
  920. if (input.F_PayState > -1)
  921. {
  922. conModels.Add(new ConditionalModel() { FieldName = "F_PayState", ConditionalType = ConditionalType.Equal, FieldValue = input.F_PayState.ToString() });
  923. }
  924. if (input.SearchEndTime != null)
  925. {
  926. conModels.Add(new ConditionalModel() { FieldName = "F_AddTime", ConditionalType = ConditionalType.LessThan, FieldValue = input.SearchEndTime.GetValueOrDefault().ToString("yyyy-MM-dd 23:59:59") });
  927. }
  928. if (input.SearchStartTime != null)
  929. {
  930. conModels.Add(new ConditionalModel() { FieldName = "F_AddTime", ConditionalType = ConditionalType.GreaterThan, FieldValue = input.SearchStartTime.GetValueOrDefault().ToString("yyyy-MM-dd 00:00:01") });
  931. }
  932. #endregion
  933. RefAsync<int> recordCount = 0;
  934. PageData<T_Bus_Order> list = await bus_OrderRepository.GetListByPage(conModels, new MyPageModel() { PageIndex = input.pageindex, PageSize = input.pagesize, PageCount = recordCount }, " F_AddTime DESC");
  935. PageData<OrderInput> returnobj = new PageData<OrderInput>() { Totals = list.Totals };
  936. List<OrderInput> returnlist = new List<OrderInput>();
  937. foreach (T_Bus_Order t in list.Rows)
  938. {
  939. OrderInput m = new OrderInput();
  940. ModelConvertHelper<OrderInput, T_Bus_Order>.ModeToModel(m, t);
  941. List<OrderDetailInput> orderDetailInputs = new List<OrderDetailInput>();
  942. #region 遍历订单商品
  943. List<T_Bus_OrderDetail> orderDetails = await bus_OrderDetailRepository.GetListALL(q => q.F_OrderId == t.F_Id);
  944. if (orderDetails != null)
  945. {
  946. foreach (T_Bus_OrderDetail t1 in orderDetails)
  947. {
  948. OrderDetailInput m1 = new OrderDetailInput();
  949. ModelConvertHelper<OrderDetailInput, T_Bus_OrderDetail>.ModeToModel(m1, t1);
  950. orderDetailInputs.Add(m1);
  951. }
  952. }
  953. #endregion
  954. m.OrderDetailList = orderDetailInputs;
  955. returnlist.Add(m);
  956. }
  957. returnobj.Rows = returnlist;
  958. return Success("成功", returnobj);
  959. }
  960. /// <summary>
  961. /// 撤回未审核订单
  962. /// </summary>
  963. /// <param name="orderid">订单号</param>
  964. /// <param name="state">订单状态 -1无效 0暂存 1提交 2KF退回 3通过 4KG退回 5已分拣 6已发货</param>
  965. /// <param name="remark">客服备注</param>
  966. /// <returns></returns>
  967. [HttpPost("cancelorder")]
  968. public async Task<IActionResult> CancelOrder(string orderid, int state = 0)
  969. {
  970. try
  971. {
  972. //状态变化 积分变化 处理时间人变化 库存变化 备注
  973. T_Cus_VipInfo modelvip = new T_Cus_VipInfo();
  974. #region 验证参数 必填项
  975. if (string.IsNullOrEmpty(orderid))
  976. return Error("请输入订单号");
  977. if (state != 0)
  978. return Error("请选择操作类型");
  979. #endregion
  980. T_Bus_Order modelOrder = await bus_OrderRepository.GetSingle(q => q.F_Id == orderid &&new int[] { 1,3,4}.Contains(q.F_State));
  981. if (modelOrder == null)
  982. {
  983. return Error("订单已审核");
  984. }
  985. string strStock = await busOrderFunctionController.ChangeStockOne(modelOrder, 0, null);
  986. if (strStock != "1")
  987. return Error(strStock);
  988. modelOrder.F_State = 0;
  989. modelOrder.F_Score = 0.00M;
  990. if (await bus_OrderRepository.Update(modelOrder))
  991. return Success("订单成功审核!");
  992. return Error("订单审核失败,请汇报技术支持!");
  993. }
  994. catch (Exception ex)
  995. { return Error(ex.Message); }
  996. }
  997. [HttpPost("ordermoney")]
  998. public async Task<IActionResult> OrderMoney(OrderMoneyInput input)
  999. {
  1000. try
  1001. {
  1002. #region 验证参数 必填项
  1003. if (string.IsNullOrEmpty(input.F_OrderId))
  1004. return Error("请输入订单号");
  1005. if (string.IsNullOrEmpty(input.F_PayUser))
  1006. return Error("请输入打款人");
  1007. if (string.IsNullOrEmpty(input.F_PayType))
  1008. return Error("请输入打款方式");
  1009. if (string.IsNullOrEmpty(input.F_RemarkKF))
  1010. input.F_RemarkKF = "";
  1011. if (string.IsNullOrEmpty(input.F_RemarkXS))
  1012. input.F_RemarkXS = "";
  1013. if (input.F_PayTime==null)
  1014. return Error("请输入打款时间");
  1015. if (input.F_Money <= 0)
  1016. return Error("请输入金额");
  1017. #endregion
  1018. T_Bus_OrderMoney modelOrderMoeny = new T_Bus_OrderMoney();
  1019. ModelConvertHelper<T_Bus_OrderMoney, OrderMoneyInput>.ModeToModelDefault(modelOrderMoeny, input);
  1020. modelOrderMoeny.F_AddUserId =UserLogin.UserId.ObjToInt();
  1021. modelOrderMoeny.F_UserName = UserLogin.UserName;
  1022. modelOrderMoeny.F_MoneyBak= modelOrderMoeny.F_Money;
  1023. modelOrderMoeny.F_State= 0;
  1024. modelOrderMoeny.F_Id = Guid.NewGuid().ToString().Replace("-","");
  1025. if (await busOrderMoneyRepository.AddReturnCount(modelOrderMoeny))
  1026. return Success("成功!");
  1027. return Error("失败!");
  1028. }
  1029. catch (Exception ex)
  1030. { return Error(ex.Message); }
  1031. }
  1032. }
  1033. }