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

AfterSaleController.cs 72KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703
  1. /* =============================================
  2. -- Author: <Author,,zhangkun>
  3. -- Create date: <Create Date,,20200713>
  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.Linq.Expressions;
  14. using System.Model;
  15. using System.Repositories;
  16. using System.Security.Claims;
  17. using System.Threading.Tasks;
  18. using System.Utility.Http;
  19. using Microsoft.AspNetCore.Mvc;
  20. using Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure;
  21. using Microsoft.Extensions.Configuration;
  22. using SqlSugar;
  23. using TVShoppingCallCenter_ZLJ.Models.Inputs;
  24. using Utility;
  25. namespace TVShoppingCallCenter_ZLJ.Controllers.Order
  26. {
  27. [Route("api/[controller]")]
  28. public class AfterSaleController : BaseController
  29. {
  30. private readonly IBus_OrderDetailRepository bus_OrderDetailRepository;
  31. private readonly IBus_OrderRepository bus_OrderRepository;
  32. private readonly OrderFunctionController busOrderFunctionController;
  33. private readonly IBus_ProductRepository bus_productRepository;
  34. private readonly ICus_VipInfoRepository cus_vip_infoRepository;
  35. private readonly IBus_OrderMergeRepository busOrderMergeRepository;
  36. private readonly ICus_ScoreSetRepository cus_score_setRepository;
  37. private readonly IBus_AfterSaleRepository busAfterSaleRepository;
  38. public AfterSaleController(OrderFunctionController _OrderFunctionController, ICus_ScoreSetRepository _cus_score_setRepository, IBus_OrderMergeRepository _busOrderMergeRepository, IBus_OrderRepository _bus_OrderRepository, IBus_OrderDetailRepository _bus_OrderDetailRepository, IBus_ProductRepository _productRepository, ICus_VipInfoRepository _cus_vip_infoRepository, IBus_AfterSaleRepository _busAfterSaleRepository)
  39. {
  40. bus_OrderDetailRepository = _bus_OrderDetailRepository;
  41. bus_OrderRepository = _bus_OrderRepository;
  42. busOrderFunctionController = _OrderFunctionController;
  43. bus_productRepository = _productRepository;
  44. cus_vip_infoRepository = _cus_vip_infoRepository;
  45. busOrderMergeRepository = _busOrderMergeRepository;
  46. cus_score_setRepository = _cus_score_setRepository;
  47. busAfterSaleRepository = _busAfterSaleRepository;
  48. }
  49. #region 销售操作
  50. ///// <summary>
  51. ///// 销售申请售后
  52. ///// </summary>
  53. ///// <param name="input"></param>
  54. ///// <returns></returns>
  55. //[HttpPost("addaftersalexs")]
  56. //public async Task<IActionResult> AddAfterSaleXS(AfterSaleInput input)
  57. //{
  58. // try
  59. // {
  60. // #region 验证参数 必填项
  61. // if (string.IsNullOrEmpty(input.F_OrderId))
  62. // return Error("请选择订单");
  63. // if (input.F_Type <= 0)
  64. // return Error("申请类型不符合售后");
  65. // #endregion
  66. // #region 验证逻辑
  67. // if (input.F_Type == 1)
  68. // { }
  69. // else if (input.F_Type == 2)
  70. // { }
  71. // else if (input.F_Type == 3)
  72. // { }
  73. // else if (input.F_Type == 4)
  74. // { }
  75. // #endregion
  76. // T_Bus_Order modeOrder = await bus_OrderRepository.GetSingle(q => q.F_Id == input.F_OrderId);
  77. // if (modeOrder == null)
  78. // {
  79. // return Error("订单不存在");
  80. // }
  81. // else if (modeOrder.F_Status == -1)
  82. // {
  83. // //物流状态0 未发出 1物流运送中2签收3改代收4拒收
  84. // return Error("状态不符合售后");
  85. // }
  86. // T_Bus_AfterSale modelAfterSale = new T_Bus_AfterSale();
  87. // modelAfterSale.F_AddTime = DateTime.Now;
  88. // modelAfterSale.F_CheckTimeXS = DateTime.Now;
  89. // modelAfterSale.F_CheckStateXS = input.F_CheckStateXS;
  90. // modelAfterSale.F_CheckUserXS = UserLogin.UserId.ObjToInt();
  91. // modelAfterSale.F_CheckUserNameXS = UserLogin.UserName;
  92. // modelAfterSale.F_DetailList = input.F_DetailList;
  93. // modelAfterSale.F_Type = input.F_Type;
  94. // modelAfterSale.F_Money = input.F_Money;
  95. // modelAfterSale.F_OrderId = input.F_OrderId;
  96. // modelAfterSale.F_AboutOrderId = "";
  97. // modelAfterSale.F_Id = Guid.NewGuid().ToString().Replace("-", "");
  98. // //modelAfterSale.F_OurTrackingNo = input.F_OurTrackingNo;
  99. // //modelAfterSale.F_OurTrackDes = input.F_OurTrackDes;
  100. // //modelAfterSale.F_TrackingNo = input.F_TrackingNo;
  101. // //modelAfterSale.F_TrackDes = input.F_TrackDes;
  102. // if (!string.IsNullOrEmpty(input.F_Remark))
  103. // modelAfterSale.F_Remark = " 销售:" + input.F_Remark;
  104. // if (await busAfterSaleRepository.AddReturnCount(modelAfterSale))
  105. // {
  106. // if (input.F_State == 0)
  107. // return Success("售后申请已保存");
  108. // else if (input.F_State == 1)
  109. // { return Success("售后申请已提交审核"); }
  110. // }
  111. // return Error("申请失败,请重试!");
  112. // }
  113. // catch (Exception ex)
  114. // { return Error(ex.Message); }
  115. //}
  116. ///// <summary>
  117. ///// 销售编辑售后
  118. ///// </summary>
  119. ///// <param name="input"></param>
  120. ///// <returns></returns>
  121. //[HttpPost("editaftersalexs")]
  122. //public async Task<IActionResult> EditAfterSaleXS(AfterSaleInput input)
  123. //{
  124. // try
  125. // {
  126. // #region 验证参数 必填项
  127. // if (string.IsNullOrEmpty(input.F_Id))
  128. // return Error("参数缺失Id");
  129. // if (string.IsNullOrEmpty(input.F_OrderId))
  130. // return Error("请选择订单");
  131. // if (input.F_Type <= 0)
  132. // return Error("申请类型不符合售后");
  133. // #endregion
  134. // #region 验证逻辑
  135. // if (input.F_Type == 1)
  136. // { }
  137. // else if (input.F_Type == 2)
  138. // { }
  139. // else if (input.F_Type == 3)
  140. // { }
  141. // else if (input.F_Type == 4)
  142. // { }
  143. // #endregion
  144. // T_Bus_AfterSale modelAfterSale = await busAfterSaleRepository.GetSingle(q => q.F_Id == input.F_Id);
  145. // if (modelAfterSale.F_CheckStateSH == 1 && modelAfterSale.F_CheckStateXS == 1)
  146. // {
  147. // return Error("双审核通过不能编辑");
  148. // }
  149. // modelAfterSale.F_CheckTimeXS = DateTime.Now;
  150. // modelAfterSale.F_CheckStateXS = input.F_CheckStateXS;
  151. // modelAfterSale.F_CheckUserXS = UserLogin.UserId.ObjToInt();
  152. // modelAfterSale.F_CheckUserNameXS = UserLogin.UserName;
  153. // modelAfterSale.F_DetailList = input.F_DetailList;
  154. // modelAfterSale.F_Type = input.F_Type;
  155. // modelAfterSale.F_Money = input.F_Money;
  156. // modelAfterSale.F_CheckStateSH = 0;//需要售后重新审核
  157. // //modelAfterSale.F_OurTrackingNo = input.F_OurTrackingNo;
  158. // //modelAfterSale.F_OurTrackDes = input.F_OurTrackDes;
  159. // //modelAfterSale.F_TrackingNo = input.F_TrackingNo;
  160. // //modelAfterSale.F_TrackDes = input.F_TrackDes;
  161. // if (!string.IsNullOrEmpty(input.F_Remark))
  162. // modelAfterSale.F_Remark = modelAfterSale.F_Remark + "\\r\\n 销售:" + input.F_Remark;
  163. // if (await busAfterSaleRepository.AddReturnCount(modelAfterSale))
  164. // {
  165. // if (input.F_State == 0)
  166. // return Success("售后申请已保存");
  167. // else if (input.F_State == 1)
  168. // { return Success("售后申请已提交审核"); }
  169. // }
  170. // return Error("申请失败,请重试!");
  171. // }
  172. // catch (Exception ex)
  173. // { return Error(ex.Message); }
  174. //}
  175. ///// <summary>
  176. ///// 销售删除
  177. ///// </summary>
  178. ///// <param name="input"></param>
  179. ///// <returns></returns>
  180. //[HttpPost("deleteaftersalexs")]
  181. //public async Task<IActionResult> DeleteAfterSaleXS(string ids)
  182. //{
  183. // try
  184. // {
  185. // if (string.IsNullOrEmpty(ids))
  186. // {
  187. // return Error("参数缺失:" + ids);
  188. // }
  189. // string[] idlist = ids.Split(',');
  190. // if (await busAfterSaleRepository.Delete(q => idlist.Contains(q.F_Id) && new[] { 0, 2 }.Contains(q.F_CheckStateXS)))
  191. // {
  192. // return Success("删除成功/已审核通过不能删除");
  193. // }
  194. // return Error("删除失败,请重试!");
  195. // }
  196. // catch (Exception ex)
  197. // { return Error(ex.Message); }
  198. //}
  199. ///// <summary>
  200. ///// 根据分页获取列表
  201. ///// </summary>
  202. ///// <param name="input"></param>
  203. ///// <returns></returns>
  204. //[HttpPost("getaftersalebypagexs")]
  205. //public async Task<IActionResult> GetAfterSaleByPageXS(AfterSaleInput input)
  206. //{
  207. // #region 拼接条件
  208. // Expression<Func<T_Bus_AfterSale, bool>> eq = a => a.F_CheckUserXS == UserLogin.UserId.ObjToInt();
  209. // if (input.F_CheckStateXS > -1)
  210. // {
  211. // eq = eq.And(a => a.F_CheckStateXS == input.F_CheckStateXS);
  212. // }
  213. // if (input.F_CheckStateSH > -1)
  214. // {
  215. // eq = eq.And(a => a.F_CheckStateSH == input.F_CheckStateSH);
  216. // }
  217. // if (input.F_Type > -1)
  218. // {
  219. // eq = eq.And(a => a.F_Type == input.F_Type);
  220. // }
  221. // if (!string.IsNullOrEmpty(input.F_Id))
  222. // {
  223. // eq = eq.And(a => a.F_Id == input.F_Id);
  224. // }
  225. // if (input.F_State >= -1)
  226. // {
  227. // eq = eq.And(a => a.F_State == input.F_State);
  228. // }
  229. // #endregion
  230. // RefAsync<int> count = 0;
  231. // PageData<T_Bus_AfterSale> list = await busAfterSaleRepository.GetListByPage(eq, new MyPageModel() { PageIndex = input.pageindex, PageSize = input.pagesize, PageCount = count }, " F_AddTime DESC");
  232. // return Success("成功", list);
  233. //}
  234. #endregion
  235. /// <summary>
  236. /// 获取订单分页列表(所有订单都可查,与来电相关)
  237. /// </summary>
  238. /// <param name="input"></param>
  239. /// <returns></returns>
  240. [HttpPost("getorderlistbypage")]
  241. public async Task<IActionResult> GetOrderListByPage(OrderInput input)
  242. {
  243. List<IConditionalModel> conModels = new List<IConditionalModel>();
  244. #region 条件筛选
  245. conModels.Add(new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.GreaterThanOrEqual, FieldValue = "6" });
  246. if (!string.IsNullOrEmpty(input.F_ADFrom))
  247. {
  248. conModels.Add(new ConditionalModel() { FieldName = "F_ADFrom", ConditionalType = ConditionalType.Equal, FieldValue = input.F_ADFrom });
  249. }
  250. if (!string.IsNullOrEmpty(input.F_Type))
  251. {
  252. conModels.Add(new ConditionalModel() { FieldName = "F_Type", ConditionalType = ConditionalType.Equal, FieldValue = input.F_Type });
  253. }
  254. if (!string.IsNullOrEmpty(input.F_Id))
  255. {
  256. conModels.Add(new ConditionalModel() { FieldName = "F_Id", ConditionalType = ConditionalType.Equal, FieldValue = input.F_Id });
  257. }
  258. if (!string.IsNullOrEmpty(input.F_Customer))
  259. {
  260. conModels.Add(new ConditionalModel() { FieldName = "F_Customer", ConditionalType = ConditionalType.Equal, FieldValue = input.F_Customer });
  261. }
  262. if (!string.IsNullOrEmpty(input.F_CustomerPhone))
  263. {
  264. conModels.Add(new ConditionalModel() { FieldName = "F_CustomerPhone", ConditionalType = ConditionalType.Equal, FieldValue = input.F_CustomerPhone });
  265. }
  266. if (!string.IsNullOrEmpty(input.F_TrackingNo))
  267. {
  268. conModels.Add(new ConditionalModel() { FieldName = "F_TrackingNo", ConditionalType = ConditionalType.Equal, FieldValue = input.F_TrackingNo });
  269. }
  270. if (!string.IsNullOrEmpty(input.F_AddProvince))
  271. {
  272. conModels.Add(new ConditionalModel() { FieldName = "F_AddProvince", ConditionalType = ConditionalType.Equal, FieldValue = input.F_AddProvince });
  273. }
  274. if (!string.IsNullOrEmpty(input.F_AddCity))
  275. {
  276. conModels.Add(new ConditionalModel() { FieldName = "F_AddCity", ConditionalType = ConditionalType.Equal, FieldValue = input.F_AddCity });
  277. }
  278. if (!string.IsNullOrEmpty(input.F_AddArea))
  279. {
  280. conModels.Add(new ConditionalModel() { FieldName = "F_AddArea", ConditionalType = ConditionalType.Equal, FieldValue = input.F_AddArea });
  281. }
  282. if (!string.IsNullOrEmpty(input.F_AddTown))
  283. {
  284. conModels.Add(new ConditionalModel() { FieldName = "F_AddTown", ConditionalType = ConditionalType.Equal, FieldValue = input.F_AddTown });
  285. }
  286. if (!string.IsNullOrEmpty(input.F_Express))
  287. {
  288. conModels.Add(new ConditionalModel() { FieldName = "F_Express", ConditionalType = ConditionalType.Equal, FieldValue = input.F_Express });
  289. }
  290. if (!string.IsNullOrEmpty(input.F_PayType))
  291. {
  292. conModels.Add(new ConditionalModel() { FieldName = "F_PayType", ConditionalType = ConditionalType.Equal, FieldValue = input.F_PayType });
  293. }
  294. if (input.F_PayState > -1)
  295. {
  296. conModels.Add(new ConditionalModel() { FieldName = "F_PayState", ConditionalType = ConditionalType.Equal, FieldValue = input.F_PayState.ToString() });
  297. }
  298. if (input.SearchEndTime != null)
  299. {
  300. conModels.Add(new ConditionalModel() { FieldName = "F_AddTime", ConditionalType = ConditionalType.LessThan, FieldValue = input.SearchEndTime.GetValueOrDefault().ToString("yyyy-MM-dd 23:59:59") });
  301. }
  302. if (input.SearchStartTime != null)
  303. {
  304. conModels.Add(new ConditionalModel() { FieldName = "F_AddTime", ConditionalType = ConditionalType.GreaterThan, FieldValue = input.SearchStartTime.GetValueOrDefault().ToString("yyyy-MM-dd 00:00:01") });
  305. }
  306. #endregion
  307. RefAsync<int> recordCount = 0;
  308. PageData<T_Bus_Order> list = await bus_OrderRepository.GetListByPage(conModels, new MyPageModel() { PageIndex = input.pageindex, PageSize = input.pagesize, PageCount = recordCount }, " F_AddTime DESC");
  309. PageData<OrderInput> returnobj = new PageData<OrderInput>() { Totals = list.Totals };
  310. List<OrderInput> returnlist = new List<OrderInput>();
  311. foreach (T_Bus_Order t in list.Rows)
  312. {
  313. OrderInput m = new OrderInput();
  314. ModelConvertHelper<OrderInput, T_Bus_Order>.ModeToModel(m, t);
  315. List<OrderDetailInput> orderDetailInputs = new List<OrderDetailInput>();
  316. #region 遍历订单商品
  317. List<T_Bus_OrderDetail> orderDetails = await bus_OrderDetailRepository.GetListALL(q => q.F_OrderId == t.F_Id);
  318. if (orderDetails != null)
  319. {
  320. foreach (T_Bus_OrderDetail t1 in orderDetails)
  321. {
  322. OrderDetailInput m1 = new OrderDetailInput();
  323. ModelConvertHelper<OrderDetailInput, T_Bus_OrderDetail>.ModeToModel(m1, t1);
  324. orderDetailInputs.Add(m1);
  325. }
  326. }
  327. #endregion
  328. m.OrderDetailList = orderDetailInputs;
  329. returnlist.Add(m);
  330. }
  331. returnobj.Rows = returnlist;
  332. return Success("成功", returnobj);
  333. }
  334. #region 售后操作
  335. /// <summary>
  336. /// 添加售后
  337. /// </summary>
  338. /// <param name="input"></param>
  339. /// <returns></returns>
  340. [HttpPost("addaftersalesh")]
  341. public async Task<IActionResult> AddAfterSaleSH(AfterSaleInput input)
  342. {
  343. try
  344. {
  345. bool dgs = false;//代改收标识
  346. #region 验证参数 必填项
  347. if (string.IsNullOrEmpty(input.F_OrderId))
  348. return Error("请选择订单");
  349. if (input.F_Type <= 0)
  350. return Error("请选择售后类型");
  351. if (string.IsNullOrEmpty(input.F_ReturnType))
  352. return Error("请选择售后原因类型");
  353. #endregion
  354. T_Bus_Order modelOrder = await bus_OrderRepository.GetSingle(q => q.F_Id == input.F_OrderId);
  355. if (modelOrder == null)
  356. {
  357. return Error("订单不存在");
  358. }
  359. else if (!(modelOrder.F_Status == 3|| modelOrder.F_Status == 2||(modelOrder.F_Status <2&& input.F_ReturnType== "改代收")))
  360. {
  361. //物流状态0 未发出 1物流运送中2签收3改代收4拒收
  362. return Error("状态不符合售后");
  363. }
  364. if(input.F_ReturnType == "改代收"&& input.F_Type!=3)
  365. {
  366. return Error("改代收只能选择部分退货");
  367. }
  368. T_Bus_AfterSale modelAfterSale = new T_Bus_AfterSale();
  369. #region 退回商品展示 更新售后流程的退货商品
  370. List<T_Bus_OrderDetail> modelOldDetailList = new List<T_Bus_OrderDetail>();
  371. if (input.F_CheckStateSH == 2)
  372. {
  373. //从0开始,相当于添加 目前不会出现
  374. }
  375. else
  376. {
  377. if (!string.IsNullOrEmpty(input.F_OldDetailList))
  378. {
  379. foreach (string product in input.F_OldDetailList.Split('|'))
  380. {
  381. string productid = product.Split(',')[0];
  382. int count = product.Split(',')[1].ObjToInt();
  383. T_Bus_OrderDetail modelDetail = await bus_OrderDetailRepository.GetSingle(q => q.F_OrderId == modelOrder.F_Id && q.F_ProductId == productid);
  384. if (count > (modelDetail.F_Count - modelDetail.F_State))
  385. {
  386. return Error("此商品部分已参加售后:" + modelDetail.F_ProductName);
  387. }
  388. modelDetail.F_State = modelDetail.F_State + count;
  389. modelOldDetailList.Add(modelDetail);
  390. }
  391. }
  392. }
  393. #endregion
  394. if (input.F_ReturnType.Contains("仓库错发") || input.F_ReturnType.Contains("仓库漏发"))
  395. {
  396. modelAfterSale.F_AboutUserId = modelOrder.F_SendUser;
  397. modelAfterSale.F_AboutName = modelOrder.F_SendUserName;
  398. }
  399. else
  400. {
  401. modelAfterSale.F_AboutUserId = modelOrder.F_AddUser;
  402. modelAfterSale.F_AboutName = modelOrder.F_AddUserName;
  403. }
  404. if (!string.IsNullOrEmpty(input.F_Customer))
  405. { modelAfterSale.F_CustomerPhone = input.F_CustomerPhone; }
  406. else
  407. { modelAfterSale.F_CustomerPhone = modelOrder.F_CustomerPhone; }
  408. if (!string.IsNullOrEmpty(input.F_Customer))
  409. { modelAfterSale.F_Customer = input.F_Customer; }
  410. else
  411. { modelAfterSale.F_Customer = modelOrder.F_Customer; }
  412. if (!string.IsNullOrEmpty(input.F_ReturnDes))
  413. { modelAfterSale.F_ReturnDes = input.F_ReturnDes; }
  414. if (!string.IsNullOrEmpty(input.F_ReturnType))
  415. { modelAfterSale.F_ReturnType = input.F_ReturnType; }
  416. if (!string.IsNullOrEmpty(input.F_ProductStatus))
  417. { modelAfterSale.F_ProductStatus = input.F_ProductStatus; }
  418. if (!string.IsNullOrEmpty(input.F_DetailList))
  419. { modelAfterSale.F_DetailList = input.F_DetailList; }
  420. if (!string.IsNullOrEmpty(input.F_OldDetailList))
  421. { modelAfterSale.F_OldDetailList = input.F_OldDetailList; }
  422. modelAfterSale.F_AddTime = DateTime.Now;
  423. modelAfterSale.F_CheckTimeSH = DateTime.Now;
  424. modelAfterSale.F_CheckStateSH = input.F_CheckStateSH;
  425. modelAfterSale.F_CheckUserSH = UserLogin.UserId.ObjToInt();
  426. modelAfterSale.F_CheckUserNameSH = UserLogin.UserName;
  427. modelAfterSale.F_CheckUserXS = modelOrder.F_AddUser;
  428. modelAfterSale.F_Type = input.F_Type;
  429. modelAfterSale.F_Money = input.F_Money;
  430. modelAfterSale.F_OrderId = input.F_OrderId;
  431. modelAfterSale.F_AboutOrderId = "";
  432. modelAfterSale.F_Id = Guid.NewGuid().ToString().Replace("-", "");
  433. modelAfterSale.F_TrackingNo = input.F_TrackingNo;
  434. modelAfterSale.F_TrackDes = input.F_TrackDes;
  435. if (!string.IsNullOrEmpty(input.F_Remark))
  436. modelAfterSale.F_Remark = " 售后:" + input.F_Remark;
  437. if (new int[] { 1, 2, 3, 4 }.Contains(input.F_Type))
  438. {
  439. //客户需要发货
  440. if (modelOldDetailList == null || modelOldDetailList.Count == 0)
  441. {
  442. //但是客户没发货
  443. return Error("请选择客户退回商品");
  444. }
  445. }
  446. if (new int[] { 1,5, 4 }.Contains(input.F_Type))
  447. {
  448. //我们需要发货
  449. if (string.IsNullOrEmpty(modelAfterSale.F_DetailList))
  450. {
  451. //但是我们没发
  452. return Error("请选择新/补发商品");
  453. }
  454. }
  455. if (input.F_Type == 4)
  456. {
  457. if (input.F_CheckStateSH == 1)
  458. {
  459. modelAfterSale.F_AboutOrderId = "BJ" + UserLogin.UserCode + "T" + DateTimeConvert.ToTimetag(DateTime.Now);
  460. string addResult = await AddOrder(modelAfterSale, modelOrder);
  461. if (addResult != "1")
  462. {
  463. return Error("订单无法创建:" + addResult);
  464. }
  465. }
  466. }
  467. else if (input.F_Type == 2 )
  468. {
  469. }
  470. else if (input.F_Type == 3)
  471. {
  472. //售后提交
  473. if (input.F_CheckStateSH == 1)
  474. {
  475. //如果是改代收
  476. if (input.F_ReturnType == "代改收")
  477. {
  478. dgs = true;
  479. decimal tempShouldPrice = modelOrder.F_ShouldPrice;
  480. modelOrder.F_ShouldPrice = modelOrder.F_ShouldPrice + input.F_Money;
  481. modelOrder.F_Tag += ",代改收";
  482. modelOrder.F_Tag = modelOrder.F_Tag.Trim(',');
  483. if (tempShouldPrice > 0)
  484. {
  485. if (modelOrder.F_ShouldPrice == modelOrder.F_RealPrice)
  486. {
  487. modelOrder.F_PayState = 1;
  488. }
  489. if (modelOrder.F_ShouldPrice > modelOrder.F_RealPrice)
  490. {
  491. modelOrder.F_PayState = 0;
  492. }
  493. if (modelOrder.F_ShouldPrice < modelOrder.F_RealPrice)
  494. {
  495. modelOrder.F_PayState = 2;
  496. }
  497. }
  498. else
  499. {
  500. if (modelOrder.F_ShouldPrice == modelOrder.F_RealPrice)
  501. {
  502. modelOrder.F_PayState = 3;
  503. }
  504. if (modelOrder.F_ShouldPrice > modelOrder.F_RealPrice)
  505. {
  506. modelOrder.F_PayState = 0;
  507. }
  508. if (modelOrder.F_ShouldPrice < modelOrder.F_RealPrice)
  509. {
  510. modelOrder.F_PayState = 2;
  511. }
  512. }
  513. modelAfterSale.F_Money = 0;
  514. }
  515. }
  516. }
  517. else if (input.F_Type == 1)
  518. {
  519. }
  520. if (modelOldDetailList != null && modelOldDetailList.Count > 0&& new int[] { 1, 2, 3, 4 }.Contains(input.F_Type))
  521. {
  522. //批量更新售后的数量状态
  523. await bus_OrderDetailRepository.UpdateListToColumns(modelOldDetailList,s=> new{ s.F_State});
  524. }
  525. if (await busAfterSaleRepository.AddReturnCount(modelAfterSale))
  526. {
  527. if (input.F_CheckStateSH == 1)
  528. {
  529. string dgsstr = "";
  530. if (dgs)
  531. {
  532. if (await bus_OrderRepository.UpdateListToColumns(new List<T_Bus_Order>() { modelOrder }, s => new { s.F_PayState, s.F_ShouldPrice, s.F_Tag }))
  533. {
  534. dgsstr = ":改代收修改成功";
  535. }
  536. else { dgsstr = ":改代收修改失败,请记录手动修改原订单 应付金额值/实际支付"; }
  537. }
  538. return Success("售后已提交"+ dgsstr);
  539. }
  540. else
  541. {
  542. return Success("售后已保存");
  543. }
  544. }
  545. return Error("申请失败,请重试!");
  546. }
  547. catch (Exception ex)
  548. { return Error(ex.Message + "===" + ex.StackTrace); }
  549. }
  550. /// <summary>
  551. /// 售后编辑售后
  552. /// </summary>
  553. /// <param name="input"></param>
  554. /// <returns></returns>
  555. [HttpPost("editaftersalesh")]
  556. public async Task<IActionResult> EditAfterSaleSH(AfterSaleInput input)
  557. {
  558. try
  559. {
  560. bool dgs = false;//代改收标识
  561. #region 验证参数 必填项
  562. if (string.IsNullOrEmpty(input.F_OrderId))
  563. return Error("请选择订单");
  564. if (string.IsNullOrEmpty(input.F_Id))
  565. return Error("请选择售后单");
  566. if (input.F_Type <= 0)
  567. return Error("申请类型不符合售后");
  568. #endregion
  569. T_Bus_Order modelOrder = await bus_OrderRepository.GetSingle(q => q.F_Id == input.F_OrderId);
  570. if (modelOrder == null)
  571. {
  572. return Error("订单不存在");
  573. }
  574. else if (!(modelOrder.F_Status == 3 || modelOrder.F_Status == 2 || (modelOrder.F_Status < 2 && input.F_ReturnType == "改代收")))
  575. {
  576. //物流状态0 未发出 1物流运送中2签收3改代收4拒收
  577. return Error("状态不符合售后");
  578. }
  579. if (input.F_ReturnType == "改代收" && input.F_Type != 3)
  580. {
  581. return Error("改代收只能选择部分退货");
  582. }
  583. T_Bus_AfterSale modelAfterSale = await busAfterSaleRepository.GetSingle(q => q.F_Id == input.F_Id);
  584. if (modelAfterSale.F_CheckStateSH == 1)
  585. {
  586. return Error("审核通过的不能操作");
  587. }
  588. if (input.F_ReturnType.Contains("仓库错发") || input.F_ReturnType.Contains("仓库漏发"))
  589. {
  590. modelAfterSale.F_AboutUserId = modelOrder.F_SendUser;
  591. modelAfterSale.F_AboutName = modelOrder.F_SendUserName;
  592. }
  593. else
  594. {
  595. modelAfterSale.F_AboutUserId = modelOrder.F_AddUser;
  596. modelAfterSale.F_AboutName = modelOrder.F_AddUserName;
  597. }
  598. if (!string.IsNullOrEmpty(input.F_Customer))
  599. { modelAfterSale.F_CustomerPhone = input.F_CustomerPhone; }
  600. else
  601. { modelAfterSale.F_CustomerPhone = modelOrder.F_CustomerPhone; }
  602. if (!string.IsNullOrEmpty(input.F_Customer))
  603. { modelAfterSale.F_Customer = input.F_Customer; }
  604. else
  605. { modelAfterSale.F_Customer = modelOrder.F_Customer; }
  606. if (!string.IsNullOrEmpty(input.F_ReturnDes))
  607. { modelAfterSale.F_ReturnDes = input.F_ReturnDes; }
  608. if (!string.IsNullOrEmpty(input.F_ReturnType))
  609. { modelAfterSale.F_ReturnType = input.F_ReturnType; }
  610. if (!string.IsNullOrEmpty(input.F_ProductStatus))
  611. { modelAfterSale.F_ProductStatus = input.F_ProductStatus; }
  612. if (!string.IsNullOrEmpty(input.F_DetailList))
  613. { modelAfterSale.F_DetailList = input.F_DetailList; }
  614. if (!string.IsNullOrEmpty(input.F_TrackingNo))
  615. { modelAfterSale.F_TrackingNo = input.F_TrackingNo; }
  616. if (!string.IsNullOrEmpty(input.F_TrackDes))
  617. { modelAfterSale.F_TrackDes = input.F_TrackDes; }
  618. if (!string.IsNullOrEmpty(input.F_Remark))
  619. modelAfterSale.F_Remark = " 售后:" + input.F_Remark;
  620. List<T_Bus_OrderDetail> modelOldDetailList = new List<T_Bus_OrderDetail>();
  621. #region 退回商品展示 更新售后流程的退货商品
  622. if (modelAfterSale.F_CheckStateSH == 2)
  623. {
  624. //从0开始,相当于添加
  625. if (input.F_CheckStateSH == 2)
  626. { }
  627. else
  628. {
  629. if (!string.IsNullOrEmpty(input.F_OldDetailList))
  630. {
  631. foreach (string product in input.F_OldDetailList.Split('|'))
  632. {
  633. string productid = product.Split(',')[0];
  634. int count = product.Split(',')[1].ObjToInt();
  635. T_Bus_OrderDetail modelDetail = await bus_OrderDetailRepository.GetSingle(q => q.F_OrderId == modelOrder.F_Id && q.F_ProductId == productid);
  636. if (count > (modelDetail.F_Count - modelDetail.F_State))
  637. {
  638. return Error("此商品部分已参加售后:" + modelDetail.F_ProductName);
  639. }
  640. modelDetail.F_State = modelDetail.F_State+ count;
  641. modelOldDetailList.Add(modelDetail);
  642. }
  643. }
  644. }
  645. }
  646. else
  647. {
  648. if (input.F_CheckStateSH == 2)
  649. {
  650. //解锁之前的
  651. if (string.IsNullOrEmpty(modelAfterSale.F_OldDetailList))
  652. {
  653. foreach (string product in modelAfterSale.F_OldDetailList.Split('|'))
  654. {
  655. string productid = product.Split(',')[0];
  656. int count = product.Split(',')[1].ObjToInt();
  657. T_Bus_OrderDetail modelDetail = await bus_OrderDetailRepository.GetSingle(q => q.F_OrderId == modelOrder.F_Id && q.F_ProductId == productid);
  658. modelDetail.F_State = modelDetail.F_State- count;
  659. modelOldDetailList.Add(modelDetail);
  660. }
  661. }
  662. }
  663. else
  664. {
  665. if (!string.IsNullOrEmpty(input.F_OldDetailList))
  666. {
  667. foreach (string product in input.F_OldDetailList.Split('|'))
  668. {
  669. string productid = product.Split(',')[0];
  670. int count = product.Split(',')[1].ObjToInt();
  671. T_Bus_OrderDetail modelDetail = await bus_OrderDetailRepository.GetSingle(q => q.F_OrderId == modelOrder.F_Id && q.F_ProductId == productid);
  672. foreach (string productold in modelAfterSale.F_OldDetailList.Split('|'))
  673. {
  674. string productidold = product.Split(',')[0];
  675. if (productidold == productid)
  676. {
  677. int countold = product.Split(',')[1].ObjToInt();
  678. count = count - countold;
  679. }
  680. }
  681. if (count > (modelDetail.F_Count - modelDetail.F_State))
  682. {
  683. return Error("此商品部分已参加售后:" + modelDetail.F_ProductName);
  684. }
  685. modelDetail.F_State = modelDetail.F_State + count;
  686. modelOldDetailList.Add(modelDetail);
  687. }
  688. }
  689. }
  690. }
  691. #endregion
  692. if (!string.IsNullOrEmpty(input.F_OldDetailList))
  693. { modelAfterSale.F_OldDetailList = input.F_OldDetailList; }
  694. modelAfterSale.F_CheckTimeSH = DateTime.Now;
  695. modelAfterSale.F_CheckStateSH = input.F_CheckStateSH;
  696. modelAfterSale.F_CheckUserSH = UserLogin.UserId.ObjToInt();
  697. modelAfterSale.F_CheckUserNameSH = UserLogin.UserName;
  698. modelAfterSale.F_CheckUserXS = modelOrder.F_AddUser;
  699. modelAfterSale.F_Type = input.F_Type;
  700. modelAfterSale.F_Money = input.F_Money;
  701. modelAfterSale.F_OrderId = input.F_OrderId;
  702. if (new int[] { 1, 2, 3, 4 }.Contains(input.F_Type))
  703. {
  704. //客户需要发货
  705. if (modelOldDetailList == null || modelOldDetailList.Count == 0)
  706. {
  707. //但是客户没发货
  708. return Error("请选择客户退回商品");
  709. }
  710. }
  711. if (new int[] { 1, 5, 4 }.Contains(input.F_Type))
  712. {
  713. //我们需要发货
  714. if (string.IsNullOrEmpty(modelAfterSale.F_DetailList))
  715. {
  716. //但是我们没发
  717. return Error("请选择新/补发商品");
  718. }
  719. }
  720. #region 不通售后类型的处理
  721. if (modelAfterSale.F_Type == 4)
  722. {
  723. if (modelAfterSale.F_CheckStateSH == 1)
  724. {
  725. modelAfterSale.F_AboutOrderId = "BJ" + UserLogin.UserCode + "T" + DateTimeConvert.ToTimetag(DateTime.Now);
  726. string addResult = await AddOrder(modelAfterSale, modelOrder);
  727. if (addResult != "1")
  728. {
  729. return Error("订单无法创建:" + addResult);
  730. }
  731. }
  732. }
  733. else if (input.F_Type == 2)
  734. {
  735. }
  736. else if (input.F_Type == 3)
  737. {
  738. //售后提交
  739. if (input.F_CheckStateSH == 1)
  740. {
  741. //如果是改代收
  742. if (input.F_ReturnType == "代改收")
  743. {
  744. dgs = true;
  745. decimal tempShouldPrice = modelOrder.F_ShouldPrice;
  746. modelOrder.F_ShouldPrice = modelOrder.F_ShouldPrice + input.F_Money;
  747. modelOrder.F_Tag += ",代改收";
  748. modelOrder.F_Tag = modelOrder.F_Tag.Trim(',');
  749. if (tempShouldPrice > 0)
  750. {
  751. if (modelOrder.F_ShouldPrice == modelOrder.F_RealPrice)
  752. {
  753. modelOrder.F_PayState = 1;
  754. }
  755. if (modelOrder.F_ShouldPrice > modelOrder.F_RealPrice)
  756. {
  757. modelOrder.F_PayState = 0;
  758. }
  759. if (modelOrder.F_ShouldPrice < modelOrder.F_RealPrice)
  760. {
  761. modelOrder.F_PayState = 2;
  762. }
  763. }
  764. else
  765. {
  766. if (modelOrder.F_ShouldPrice == modelOrder.F_RealPrice)
  767. {
  768. modelOrder.F_PayState = 3;
  769. }
  770. if (modelOrder.F_ShouldPrice > modelOrder.F_RealPrice)
  771. {
  772. modelOrder.F_PayState = 0;
  773. }
  774. if (modelOrder.F_ShouldPrice < modelOrder.F_RealPrice)
  775. {
  776. modelOrder.F_PayState = 2;
  777. }
  778. }
  779. modelAfterSale.F_Money = 0;
  780. }
  781. }
  782. }
  783. else if (input.F_Type == 1)
  784. {
  785. }
  786. #endregion
  787. if (modelOldDetailList != null && modelOldDetailList.Count > 0 && new int[] { 1, 2, 3, 4 }.Contains(input.F_Type))
  788. {
  789. //批量更新状态 数量
  790. await bus_OrderDetailRepository.UpdateListToColumns(modelOldDetailList, s => new { s.F_State });
  791. }
  792. if (await busAfterSaleRepository.Update(modelAfterSale))
  793. {
  794. if (input.F_CheckStateSH == 0)
  795. return Success("售后已保存");
  796. else if (input.F_CheckStateSH == 1)
  797. {
  798. string dgsstr = "";
  799. if (dgs)
  800. {
  801. if (await bus_OrderRepository.UpdateListToColumns(new List<T_Bus_Order>() { modelOrder }, s => new { s.F_PayState, s.F_ShouldPrice, s.F_Tag }))
  802. {
  803. dgsstr = ":改代收修改成功";
  804. }
  805. else { dgsstr = ":改代收修改失败,请记录手动修改原订单 应付金额值/实际支付"; }
  806. }
  807. return Success("售后已提交" + dgsstr);
  808. }
  809. }
  810. return Error("申请失败,请重试!");
  811. }
  812. catch (Exception ex)
  813. { return Error(ex.Message); }
  814. }
  815. /// <summary>
  816. /// 售后删除
  817. /// </summary>
  818. /// <param name="input"></param>
  819. /// <returns></returns>
  820. [HttpPost("deleteaftersalesh")]
  821. public async Task<IActionResult> DeleteAfterSaleSH(string ids)
  822. {
  823. try
  824. {
  825. if (string.IsNullOrEmpty(ids))
  826. {
  827. return Error("参数缺失:" + ids);
  828. }
  829. string[] idlist = ids.Split(',');
  830. //TODO 删除售后 暂时还未还原之前状态 暂时不能删除
  831. foreach (string id in idlist)
  832. {
  833. T_Bus_AfterSale modelAfterSale = await busAfterSaleRepository.GetSingle(q => q.F_Id == id);
  834. if (modelAfterSale.F_CheckStateSH > 1)
  835. {
  836. return Error("此售后的状态不允许删除:" + modelAfterSale.F_Id);
  837. }
  838. if (new int[] { 1, 2, 3, 4 }.Contains(modelAfterSale.F_Type))
  839. {
  840. if (!string.IsNullOrEmpty(modelAfterSale.F_OldDetailList))
  841. {
  842. List<T_Bus_OrderDetail> modelOldDetailList = new List<T_Bus_OrderDetail>();
  843. foreach (string product in modelAfterSale.F_OldDetailList.Split('|'))
  844. {
  845. string productid = product.Split(',')[0];
  846. int count = product.Split(',')[1].ObjToInt();
  847. T_Bus_OrderDetail modelDetail = await bus_OrderDetailRepository.GetSingle(q => q.F_OrderId == modelAfterSale.F_OrderId && q.F_ProductId == productid);
  848. if (count > modelDetail.F_State)
  849. {
  850. modelDetail.F_State = 0;
  851. }
  852. else {
  853. modelDetail.F_State = modelDetail.F_State - count;
  854. }
  855. modelOldDetailList.Add(modelDetail);
  856. }
  857. if(!await bus_OrderDetailRepository.UpdateListToColumns(modelOldDetailList,s=>new { s.F_State}))
  858. {
  859. return Error("更新售后商品数量失败,请手工操作:"+ modelAfterSale.F_Id);
  860. }
  861. }
  862. }
  863. if (await busAfterSaleRepository.Update(s => new T_Bus_AfterSale { F_State = -1 }, q => q.F_Id == id && q.F_CheckStateSH != 1))
  864. {
  865. return Success("删除成功");
  866. }
  867. }
  868. return Error("删除失败,请重试!");
  869. }
  870. catch (Exception ex)
  871. { return Error(ex.Message); }
  872. }
  873. /// <summary>
  874. /// 根据分页获取列表
  875. /// </summary>
  876. /// <param name="input"></param>
  877. /// <returns></returns>
  878. [HttpPost("getaftersalebypagesh")]
  879. public async Task<IActionResult> GetAfterSaleByPageSH(AfterSaleInput input)
  880. {
  881. #region 拼接条件
  882. Expression<Func<T_Bus_AfterSale, bool>> eq = a => a.F_CheckUserSH == UserLogin.UserId.ObjToInt()&&a.F_State>-1;
  883. //if (input.F_CheckStateXS > -2)
  884. //{
  885. // eq = eq.And(a => a.F_CheckStateXS == input.F_CheckStateXS);
  886. //}
  887. if (input.F_CheckStateSH > -2)
  888. {
  889. eq = eq.And(a => a.F_CheckStateSH == input.F_CheckStateSH);
  890. }
  891. if (input.F_State > -2)
  892. {
  893. eq = eq.And(a => a.F_State == input.F_State);
  894. }
  895. if (input.F_Type > 0)
  896. {
  897. eq = eq.And(a => a.F_Type == input.F_Type);
  898. }
  899. if (!string.IsNullOrEmpty(input.F_Id))
  900. {
  901. eq = eq.And(a => a.F_Id == input.F_Id); }
  902. if (!string.IsNullOrEmpty(input.F_ReturnType))
  903. {
  904. eq = eq.And(a => a.F_ReturnType == input.F_ReturnType);
  905. }
  906. #endregion
  907. RefAsync<int> count = 0;
  908. PageData<T_Bus_AfterSale> list = await busAfterSaleRepository.GetListByPage(eq, new MyPageModel() { PageIndex = input.pageindex, PageSize = input.pagesize, PageCount = count }, " F_AddTime DESC");
  909. return Success("成功", list);
  910. }
  911. /// <summary>
  912. /// 获取售后详情
  913. /// </summary>
  914. /// <param name="input"></param>
  915. /// <returns></returns>
  916. [HttpPost("getshdetail")]
  917. public async Task<IActionResult> GetSHDetail(AfterSaleInput input)
  918. {
  919. if (string.IsNullOrEmpty(input.F_Id))
  920. {
  921. return Error("请选择售后单");
  922. }
  923. T_Bus_AfterSale model = await busAfterSaleRepository.GetSingle(a =>a.F_Id== input.F_Id&& a.F_CheckUserSH == UserLogin.UserId.ObjToInt() && a.F_State > -1);
  924. if (model != null)
  925. {
  926. if (!string.IsNullOrEmpty(model.F_DetailList))
  927. {
  928. string[] F_DetailList = model.F_DetailList.Split("|");
  929. model.F_DetailList = "";
  930. foreach (string a1 in F_DetailList)
  931. {
  932. string[] F_Detail= a1.Split(",");
  933. string productid = F_Detail[0];
  934. string count = F_Detail[1];
  935. var modelProduct =await bus_productRepository.GetSingle(q => q.F_ProductId == productid);
  936. if (modelProduct != null)
  937. {
  938. model.F_DetailList = $"{model.F_DetailList}|{productid},{count},{modelProduct.F_ProductName}";
  939. }
  940. else
  941. {
  942. model.F_DetailList = $"{model.F_DetailList}|{productid},{count},空货";
  943. }
  944. }
  945. }
  946. //if (!string.IsNullOrEmpty(model.F_OldDetailList))
  947. //{
  948. // string[] F_OldDetailList = model.F_OldDetailList.Split("|");
  949. // model.F_OldDetailList = "";
  950. // foreach (string a1 in F_OldDetailList)
  951. // {
  952. // string[] F_OldDetail = a1.Split(",");
  953. // string productid = F_OldDetail[0];
  954. // string count = F_OldDetail[1];
  955. // var modelProduct = await bus_productRepository.GetSingle(q => q.F_ProductId == productid);
  956. // if (modelProduct != null)
  957. // {
  958. // model.F_OldDetailList = $"{model.F_DetailList}|{productid},{count},{modelProduct.F_ProductName}";
  959. // }
  960. // else
  961. // {
  962. // model.F_OldDetailList = $"{model.F_DetailList}|{productid},{count},空货";
  963. // }
  964. // }
  965. //}
  966. }
  967. return Success("成功", model);
  968. }
  969. /// <summary>
  970. /// 获取订单分页列表 售后
  971. /// </summary>
  972. /// <param name="input"></param>
  973. /// <returns></returns>
  974. [HttpPost("getorderlistbyshpage")]
  975. public async Task<IActionResult> GetSHOrderListByPage(OrderInput input)
  976. {
  977. List<IConditionalModel> conModels = new List<IConditionalModel>();
  978. #region 条件筛选
  979. conModels.Add(new ConditionalModel() { FieldName = "F_Type", ConditionalType = ConditionalType.Equal, FieldValue = "售后订单" });
  980. //状态
  981. if (input.F_State > -2)
  982. {
  983. conModels.Add(new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.Equal, FieldValue = input.F_State.ToString() });
  984. }
  985. //根据角色展示列表
  986. if (UserLogin.RoleCode == "SH")
  987. {
  988. conModels.Add(new ConditionalModel() { FieldName = "F_AddUser", ConditionalType = ConditionalType.Equal, FieldValue = UserLogin.UserId });
  989. }
  990. else if (UserLogin.RoleCode == "KF" && input.F_State != 1)
  991. {
  992. conModels.Add(new ConditionalModel() { FieldName = "F_CheckUser", ConditionalType = ConditionalType.Equal, FieldValue = UserLogin.UserId });
  993. }
  994. else if (UserLogin.RoleCode == "KG" && input.F_State != 3)
  995. {
  996. conModels.Add(new ConditionalModel() { FieldName = "F_StockUser", ConditionalType = ConditionalType.Equal, FieldValue = UserLogin.UserId });
  997. //OR conModels.Add(new ConditionalModel() { FieldName = "F_SendUser", ConditionalType = ConditionalType.Equal, FieldValue = UserLogin.UserId });
  998. }
  999. if (!string.IsNullOrEmpty(input.F_ADFrom))
  1000. {
  1001. conModels.Add(new ConditionalModel() { FieldName = "F_ADFrom", ConditionalType = ConditionalType.Equal, FieldValue = input.F_ADFrom });
  1002. }
  1003. if (!string.IsNullOrEmpty(input.F_Type))
  1004. {
  1005. conModels.Add(new ConditionalModel() { FieldName = "F_Type", ConditionalType = ConditionalType.Equal, FieldValue = input.F_Type });
  1006. }
  1007. if (!string.IsNullOrEmpty(input.F_Id))
  1008. {
  1009. conModels.Add(new ConditionalModel() { FieldName = "F_Id", ConditionalType = ConditionalType.Equal, FieldValue = input.F_Id });
  1010. }
  1011. if (!string.IsNullOrEmpty(input.F_Customer))
  1012. {
  1013. conModels.Add(new ConditionalModel() { FieldName = "F_Customer", ConditionalType = ConditionalType.Equal, FieldValue = input.F_Customer });
  1014. }
  1015. if (!string.IsNullOrEmpty(input.F_CustomerPhone))
  1016. {
  1017. conModels.Add(new ConditionalModel() { FieldName = "F_CustomerPhone", ConditionalType = ConditionalType.Equal, FieldValue = input.F_CustomerPhone });
  1018. }
  1019. if (!string.IsNullOrEmpty(input.F_TrackingNo))
  1020. {
  1021. conModels.Add(new ConditionalModel() { FieldName = "F_TrackingNo", ConditionalType = ConditionalType.Equal, FieldValue = input.F_TrackingNo });
  1022. }
  1023. if (!string.IsNullOrEmpty(input.F_AddProvince))
  1024. {
  1025. conModels.Add(new ConditionalModel() { FieldName = "F_AddProvince", ConditionalType = ConditionalType.Equal, FieldValue = input.F_AddProvince });
  1026. }
  1027. if (!string.IsNullOrEmpty(input.F_AddCity))
  1028. {
  1029. conModels.Add(new ConditionalModel() { FieldName = "F_AddCity", ConditionalType = ConditionalType.Equal, FieldValue = input.F_AddCity });
  1030. }
  1031. if (!string.IsNullOrEmpty(input.F_AddArea))
  1032. {
  1033. conModels.Add(new ConditionalModel() { FieldName = "F_AddArea", ConditionalType = ConditionalType.Equal, FieldValue = input.F_AddArea });
  1034. }
  1035. if (!string.IsNullOrEmpty(input.F_AddTown))
  1036. {
  1037. conModels.Add(new ConditionalModel() { FieldName = "F_AddTown", ConditionalType = ConditionalType.Equal, FieldValue = input.F_AddTown });
  1038. }
  1039. if (!string.IsNullOrEmpty(input.F_Express))
  1040. {
  1041. conModels.Add(new ConditionalModel() { FieldName = "F_Express", ConditionalType = ConditionalType.Equal, FieldValue = input.F_Express });
  1042. }
  1043. if (!string.IsNullOrEmpty(input.F_PayType))
  1044. {
  1045. conModels.Add(new ConditionalModel() { FieldName = "F_PayType", ConditionalType = ConditionalType.Equal, FieldValue = input.F_PayType });
  1046. }
  1047. if (!string.IsNullOrEmpty(input.F_Stock))
  1048. {
  1049. conModels.Add(new ConditionalModel() { FieldName = "F_Stock", ConditionalType = ConditionalType.Equal, FieldValue = input.F_Stock });
  1050. }
  1051. if (input.F_PayState > -1)
  1052. {
  1053. conModels.Add(new ConditionalModel() { FieldName = "F_PayState", ConditionalType = ConditionalType.Equal, FieldValue = input.F_PayState.ToString() });
  1054. }
  1055. if (input.SearchEndTime != null)
  1056. {
  1057. conModels.Add(new ConditionalModel() { FieldName = "F_AddTime", ConditionalType = ConditionalType.LessThan, FieldValue = input.SearchEndTime.GetValueOrDefault().ToString("yyyy-MM-dd 23:59:59") });
  1058. }
  1059. if (input.SearchStartTime != null)
  1060. {
  1061. conModels.Add(new ConditionalModel() { FieldName = "F_AddTime", ConditionalType = ConditionalType.GreaterThan, FieldValue = input.SearchStartTime.GetValueOrDefault().ToString("yyyy-MM-dd 00:00:01") });
  1062. }
  1063. #endregion
  1064. RefAsync<int> recordCount = 0;
  1065. PageData<T_Bus_Order> list = await bus_OrderRepository.GetListByPage(conModels, new MyPageModel() { PageIndex = input.pageindex, PageSize = input.pagesize, PageCount = recordCount }, " F_AddTime DESC");
  1066. PageData<OrderInput> returnobj = new PageData<OrderInput>() { Totals = list.Totals };
  1067. List<OrderInput> returnlist = new List<OrderInput>();
  1068. foreach (T_Bus_Order t in list.Rows)
  1069. {
  1070. OrderInput m = new OrderInput();
  1071. ModelConvertHelper<OrderInput, T_Bus_Order>.ModeToModel(m, t);
  1072. List<OrderDetailInput> orderDetailInputs = new List<OrderDetailInput>();
  1073. #region 遍历订单商品
  1074. List<T_Bus_OrderDetail> orderDetails = await bus_OrderDetailRepository.GetListALL(q => q.F_OrderId == t.F_Id);
  1075. if (orderDetails != null)
  1076. {
  1077. foreach (T_Bus_OrderDetail t1 in orderDetails)
  1078. {
  1079. OrderDetailInput m1 = new OrderDetailInput();
  1080. ModelConvertHelper<OrderDetailInput, T_Bus_OrderDetail>.ModeToModel(m1, t1);
  1081. orderDetailInputs.Add(m1);
  1082. }
  1083. }
  1084. #endregion
  1085. m.OrderDetailList = orderDetailInputs;
  1086. returnlist.Add(m);
  1087. }
  1088. returnobj.Rows = returnlist;
  1089. return Success("成功", returnobj);
  1090. }
  1091. /// <summary>
  1092. /// 修改订单
  1093. /// </summary>
  1094. /// <param name="input"></param>
  1095. /// <returns></returns>
  1096. [HttpPost("editorder")]
  1097. public async Task<IActionResult> EditOrder([FromBody]OrderInput input)
  1098. {
  1099. T_Cus_VipInfo modelvip = new T_Cus_VipInfo();
  1100. #region 验证参数 必填项
  1101. if (string.IsNullOrEmpty(input.F_ADFrom))
  1102. return Error("请输入选择广告来源");
  1103. if (string.IsNullOrEmpty(input.F_Type))
  1104. return Error("请输入选择订单类型");
  1105. if (string.IsNullOrEmpty(input.F_Id))
  1106. return Error("请输入订单编号");
  1107. if (string.IsNullOrEmpty(input.F_Customer))
  1108. return Error("请输入客户姓名");
  1109. if (string.IsNullOrEmpty(input.F_CustomerPhone))
  1110. return Error("请输入客户电话");
  1111. #endregion
  1112. T_Bus_Order modelOrder = await bus_OrderRepository.GetSingle(q => q.F_Id == input.F_Id);
  1113. if (modelOrder == null)
  1114. {
  1115. return Error("此订单号不存在");
  1116. }
  1117. //保存 审退回 仓退回
  1118. if (!(new int[] { 0, 2 }.Contains(modelOrder.F_State)))
  1119. {
  1120. return Error("已提交订单不允许修改,先撤回订单");
  1121. }
  1122. #region 数据绑定
  1123. //必填
  1124. modelOrder.F_ADFrom = input.F_ADFrom;
  1125. modelOrder.F_Type = input.F_Type;
  1126. modelOrder.F_Id = input.F_Id;
  1127. modelOrder.F_Customer = input.F_Customer;
  1128. modelOrder.F_CustomerPhone = input.F_CustomerPhone;
  1129. //选填 快递属性
  1130. modelOrder.F_TrackingNo = input.F_TrackingNo;
  1131. modelOrder.F_Addressee = input.F_Addressee;
  1132. modelOrder.F_AddPhone = input.F_AddPhone;
  1133. modelOrder.F_AddProvince = input.F_AddProvince;
  1134. modelOrder.F_AddCity = input.F_AddCity;
  1135. modelOrder.F_AddArea = input.F_AddArea;
  1136. modelOrder.F_AddTown = input.F_AddTown;
  1137. modelOrder.F_AddDes = input.F_AddDes;
  1138. modelOrder.F_Address = input.F_Address;
  1139. modelOrder.F_PostalCode = input.F_PostalCode;
  1140. modelOrder.F_Express = input.F_Express;
  1141. modelOrder.F_PayType = input.F_PayType;
  1142. modelOrder.F_Stock = input.F_Stock;
  1143. modelOrder.F_Remark = input.F_Remark;
  1144. modelOrder.F_RealPrice = input.F_RealPrice;
  1145. modelOrder.F_UseScore = input.F_UseScore;
  1146. //选填 关联属性
  1147. modelOrder.F_VipId = input.F_VipId;
  1148. modelOrder.F_State = input.F_State;
  1149. modelOrder.F_Status = 0;
  1150. //必须属性 系统生成
  1151. modelOrder.F_AddTime = DateTime.Now;
  1152. modelOrder.F_AddUser = UserLogin.UserId.ObjToInt();
  1153. modelOrder.F_AddUserName = UserLogin.UserName;
  1154. #endregion
  1155. List<T_Bus_OrderDetail> modelDetailList = new List<T_Bus_OrderDetail>();
  1156. foreach (var product in input.OrderDetailList)
  1157. {
  1158. int Count = product.ObjToInt();
  1159. T_Bus_Product modelProduct = await bus_productRepository.GetSingle(b => b.F_ProductId == product .F_ProductId );
  1160. if (modelProduct == null)
  1161. return Error ( "商品不存在:" + product.F_ProductId);
  1162. T_Bus_OrderDetail modelDetail = new T_Bus_OrderDetail();
  1163. modelDetail.F_ProductName = modelProduct.F_ProductName;
  1164. modelDetail.F_ProductId = modelProduct.F_ProductId;
  1165. modelDetail.F_Id = Guid.NewGuid().ToString().Replace("-", "");
  1166. modelDetail.F_OrderId = modelOrder.F_Id;
  1167. modelDetail.F_Count = Count;
  1168. modelDetail.F_Price = modelProduct.F_MemberPrice;
  1169. modelDetail.F_DealPrice = modelProduct.F_MemberPrice;
  1170. modelDetail.F_Remark = input.F_Remark;
  1171. modelDetail.F_Sort = modelDetail.F_Sort;
  1172. modelDetail.F_AddTime = DateTime.Now;
  1173. modelDetail.F_AddUser = modelOrder.F_AddUser;
  1174. modelDetail.F_AddUserName = modelOrder.F_AddUserName;
  1175. modelDetail.F_TotlePrice = modelDetail.F_DealPrice * modelDetail.F_Count;
  1176. modelDetail.F_Activity = 0;
  1177. modelDetailList.Add(modelDetail);
  1178. }
  1179. //直接提交 锁库存
  1180. #region 提交 更改状态 库存 积分
  1181. if (input.F_State == 1)
  1182. {
  1183. if (string.IsNullOrEmpty(input.F_Stock))
  1184. {
  1185. return Error("请选择货仓");
  1186. }
  1187. modelOrder.F_FlowNum = DateTime.Now.ToString("yyMMddHHmmss") + "U" + UserLogin.UserId + "R" + new Random().Next(9);
  1188. string strStock = await busOrderFunctionController.ChangeStockOne(modelOrder, 1, modelDetailList);
  1189. if (strStock != "1")
  1190. { return Error(strStock); }
  1191. modelOrder.F_SubmitTime = DateTime.Now;
  1192. }
  1193. #endregion
  1194. if (await bus_OrderRepository.Update(modelOrder))
  1195. {
  1196. return Success("成功");
  1197. }
  1198. return Error("失败,请重试!");
  1199. }
  1200. #endregion
  1201. #region 仓库操作
  1202. /// <summary>
  1203. /// 更新状态
  1204. /// </summary>
  1205. /// <param name="input"></param>
  1206. /// <returns></returns>
  1207. [HttpPost("updatestatekg")]
  1208. public async Task<IActionResult> UpdateState(AfterSaleInput input)
  1209. {
  1210. try
  1211. {
  1212. #region 验证参数 必填项
  1213. if (string.IsNullOrEmpty(input.F_Id))
  1214. return Error("请选择售后单");
  1215. #endregion
  1216. T_Bus_AfterSale modelAfterSale = await busAfterSaleRepository.GetSingle(q => q.F_Id == input.F_Id);
  1217. T_Bus_Order modeOrder = await bus_OrderRepository.GetSingle(q => q.F_Id == modelAfterSale.F_OrderId);
  1218. if (modeOrder == null)
  1219. {
  1220. return Error("订单不存在");
  1221. }
  1222. if (modelAfterSale.F_CheckStateKG == 1 || modelAfterSale.F_CheckStateKG == 2)
  1223. {
  1224. //1收到货(根据状态自动创建订单)2货物不符3未收到货
  1225. return Error("不能重复审核提交");
  1226. }
  1227. modelAfterSale.F_CheckStateKG = input.F_CheckStateKG;
  1228. modelAfterSale.F_CheckTimeKG = DateTime.Now;
  1229. modelAfterSale.F_CheckUserKG = UserLogin.UserId.ObjToInt();
  1230. modelAfterSale.F_CheckUserNameKG = UserLogin.UserName;
  1231. modelAfterSale.F_CheckUserXS = modeOrder.F_AddUser;
  1232. List<T_Bus_OrderDetail> modelOldDetailList = new List<T_Bus_OrderDetail>();
  1233. //1收到货(根据状态自动创建订单)2货物不符3未收到货
  1234. if (modelAfterSale.F_CheckStateKG == 1)
  1235. {
  1236. if (modelAfterSale.F_Type == 4)
  1237. {
  1238. modelAfterSale.F_State = 1;
  1239. }
  1240. else if (modelAfterSale.F_Type == 2 || modelAfterSale.F_Type == 3)
  1241. {
  1242. }
  1243. else if (modelAfterSale.F_Type == 1)
  1244. {
  1245. modelAfterSale.F_AboutOrderId = "BJ" + UserLogin.UserCode + "T" + DateTimeConvert.ToTimetag(DateTime.Now);
  1246. string addResult = await AddOrder(modelAfterSale, modeOrder);
  1247. if (addResult != "1")
  1248. {
  1249. return Error("订单无法创建:" + addResult);
  1250. }
  1251. modelAfterSale.F_State = 1;
  1252. }
  1253. }
  1254. else if (modelAfterSale.F_CheckStateKG == 2)
  1255. {
  1256. //时间长自动作废
  1257. //如果没有对发货 货物不符则标记为无效
  1258. #region 更新用户快递商品
  1259. if (modelAfterSale.F_Type != 1)
  1260. {
  1261. if (string.IsNullOrEmpty(modelAfterSale.F_OldDetailList))
  1262. {
  1263. foreach (string product in modelAfterSale.F_DetailList.Split('|'))
  1264. {
  1265. string productid = product.Split(',')[0];
  1266. int count = product.Split(',')[1].ObjToInt();
  1267. T_Bus_OrderDetail modelDetail = await bus_OrderDetailRepository.GetSingle(q => q.F_OrderId == modeOrder.F_Id && q.F_ProductId == productid);
  1268. modelDetail.F_State = modelDetail.F_State - count;
  1269. modelOldDetailList.Add(modelDetail);
  1270. }
  1271. }
  1272. }
  1273. #endregion
  1274. }
  1275. else if (modelAfterSale.F_CheckStateKG == 3)
  1276. { //时间长自动作废
  1277. //如果没有对发货 未收到货则标记为无效
  1278. }
  1279. if (modelOldDetailList != null && modelOldDetailList.Count > 0)
  1280. {
  1281. //批量更新状态 为已售后
  1282. await bus_OrderDetailRepository.UpdateList(modelOldDetailList);
  1283. }
  1284. if (await busAfterSaleRepository.Update(modelAfterSale))
  1285. {
  1286. if (input.F_CheckStateSH == 0)
  1287. return Success("售后已保存");
  1288. else if (input.F_CheckStateSH == 1)
  1289. { return Success("售后已提交"); }
  1290. }
  1291. return Error("申请失败,请重试!");
  1292. }
  1293. catch (Exception ex)
  1294. { return Error(ex.Message); }
  1295. }
  1296. /// <summary>
  1297. /// 根据分页获取列表(库管)
  1298. /// </summary>
  1299. /// <param name="input"></param>
  1300. /// <returns></returns>
  1301. [HttpPost("getaftersalebypagekg")]
  1302. public async Task<IActionResult> GetAfterSaleByPageKG(AfterSaleInput input)
  1303. {
  1304. #region 拼接条件
  1305. Expression<Func<T_Bus_AfterSale, bool>> eq = a => a.F_CheckStateSH == 1;
  1306. eq = eq.And(a=>(a.F_CheckStateKG > 0 && a.F_CheckUserKG == UserLogin.UserId.ObjToInt()) || a.F_CheckStateKG == 0);
  1307. if (input.F_CheckStateKG > -2)
  1308. {
  1309. eq = eq.And(a => a.F_CheckStateKG == input.F_CheckStateKG);
  1310. }
  1311. if (input.F_Type > 0)
  1312. {
  1313. eq = eq.And(a => a.F_Type == input.F_Type);
  1314. }
  1315. if (!string.IsNullOrEmpty(input.F_Id))
  1316. {
  1317. eq = eq.And(a => a.F_Id == input.F_Id);
  1318. }
  1319. if (input.F_State > -2)
  1320. {
  1321. eq = eq.And(a => a.F_State == input.F_State);
  1322. }
  1323. #endregion
  1324. RefAsync<int> count = 0;
  1325. PageData<T_Bus_AfterSale> list = await busAfterSaleRepository.GetListByPage(eq, new MyPageModel() { PageIndex = input.pageindex, PageSize = input.pagesize, PageCount = count }, " F_AddTime DESC");
  1326. return Success("成功", list);
  1327. }
  1328. #endregion
  1329. #region 方法
  1330. /// <summary>
  1331. /// 仓库确认后创建订单 对发货直接创建订单
  1332. /// </summary>
  1333. /// <param name="newOrderlist">12,3|</param>
  1334. /// <param name="OldModelOrder"></param>
  1335. /// <param name="money"></param>
  1336. /// <returns></returns>
  1337. private async Task<string> AddOrder(T_Bus_AfterSale ModelAfterSale, T_Bus_Order OldModelOrder)
  1338. {
  1339. try
  1340. {
  1341. string newOrderlist = ModelAfterSale.F_DetailList;
  1342. T_Bus_Order modelOrder = OldModelOrder;
  1343. #region 订单属性
  1344. //必填
  1345. modelOrder.F_Type = "售后订单";
  1346. modelOrder.F_Id = ModelAfterSale.F_AboutOrderId;
  1347. modelOrder.F_TrackingNo = "";
  1348. //选填 快递属性
  1349. modelOrder.F_ExpressFee = 0;
  1350. //modelOrder.F_Stock = input.F_Stock;
  1351. modelOrder.F_Remark = "售后订单";
  1352. modelOrder.F_RealPrice = 0.00M;
  1353. modelOrder.F_UseScore = 0.00M;
  1354. //选填 关联属性
  1355. modelOrder.F_State = 0;
  1356. modelOrder.F_Status = 0;
  1357. //必须属性 系统生成
  1358. modelOrder.F_AddTime = DateTime.Now;
  1359. modelOrder.F_AddUser = UserLogin.UserId.ObjToInt();
  1360. modelOrder.F_AddUserName = UserLogin.UserName;
  1361. modelOrder.F_Belong = OldModelOrder.F_Belong;
  1362. modelOrder.F_BelongName = OldModelOrder.F_BelongName;
  1363. #endregion
  1364. //计算属性 商品计算
  1365. decimal totle = 0.00M;
  1366. List<T_Bus_OrderDetail> modelDetailList = new List<T_Bus_OrderDetail>();
  1367. #region 订单详情列表核算
  1368. if (!string.IsNullOrEmpty(newOrderlist))
  1369. {
  1370. int n = 1;
  1371. #region 商品核算
  1372. foreach (string product in newOrderlist.Split('|'))
  1373. {
  1374. string productid = product.Split(',')[0];
  1375. int Count = product.Split(',')[1].ObjToInt();
  1376. T_Bus_Product modelProduct = await bus_productRepository.GetSingle(b => b.F_ProductId == productid);
  1377. if (modelProduct == null)
  1378. return "商品不存在:" + productid;
  1379. T_Bus_OrderDetail modelDetail = new T_Bus_OrderDetail();
  1380. modelDetail.F_ProductName = modelProduct.F_ProductName;
  1381. modelDetail.F_ProductId = modelProduct.F_ProductId;
  1382. modelDetail.F_Id = Guid.NewGuid().ToString().Replace("-", "");
  1383. modelDetail.F_OrderId = modelOrder.F_Id;
  1384. modelDetail.F_Count = Count;
  1385. modelDetail.F_Price = modelProduct.F_MemberPrice;
  1386. modelDetail.F_DealPrice = modelProduct.F_MemberPrice;
  1387. modelDetail.F_Remark = "售后订单:";
  1388. modelDetail.F_Sort = n;
  1389. modelDetail.F_AddTime = DateTime.Now;
  1390. modelDetail.F_AddUser = modelOrder.F_AddUser;
  1391. modelDetail.F_AddUserName = modelOrder.F_AddUserName;
  1392. modelDetail.F_TotlePrice = modelDetail.F_DealPrice * modelDetail.F_Count;
  1393. modelDetail.F_Activity = 0;
  1394. modelDetailList.Add(modelDetail);
  1395. totle += modelDetail.F_TotlePrice;
  1396. n++;
  1397. }
  1398. #endregion
  1399. modelOrder.F_TotlePrice = totle;
  1400. modelOrder.F_ActivityMoney = 0.00M;
  1401. modelOrder.F_UseActivity = "";
  1402. }
  1403. else
  1404. {
  1405. return "0";
  1406. }
  1407. #endregion
  1408. #region 直接提交 锁库存log 锁积分log
  1409. modelOrder.F_FlowNum = DateTime.Now.ToString("yyMMddHHmmss") + "U" + UserLogin.UserId + "R" + new Random().Next(9);
  1410. string strStock = await busOrderFunctionController.ChangeStockOne(modelOrder, 1, modelDetailList);
  1411. if (strStock != "1")
  1412. { modelOrder.F_State = 0; }
  1413. else
  1414. { modelOrder.F_SubmitTime = DateTime.Now; }
  1415. #endregion
  1416. //计算结果 积分有规则
  1417. modelOrder.F_ShouldPrice = ModelAfterSale.F_Money;
  1418. modelOrder.F_RealPrice = 0.00M;
  1419. if (await bus_OrderRepository.AddReturnCount(modelOrder))
  1420. {
  1421. if (await bus_OrderDetailRepository.AddMany(modelDetailList))
  1422. return "1";
  1423. else
  1424. return "订单添加失败,请重试!";
  1425. }
  1426. else
  1427. {
  1428. return "订单添加失败,请重试!";
  1429. }
  1430. }
  1431. catch (Exception ex)
  1432. { return ex.Message; }
  1433. }
  1434. /// <summary>
  1435. /// 获取未售后的订单详情
  1436. /// </summary>
  1437. /// <param name="input"></param>
  1438. /// <returns></returns>
  1439. [HttpPost("getorderdetail")]
  1440. public async Task<IActionResult> GetOrderDetail(string orderid)
  1441. {
  1442. if (string.IsNullOrEmpty(orderid))
  1443. return Error("请输入订单号");
  1444. List<T_Bus_OrderDetail> detaillist = await bus_OrderDetailRepository.GetListALL(q => q.F_OrderId == orderid, o => o.F_Sort, OrderByType.Asc);
  1445. return Success("成功", detaillist);
  1446. }
  1447. #endregion
  1448. }
  1449. }