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

KFOrderController.cs 33KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  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.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. namespace TVShoppingCallCenter_ZLJ.Controllers.Order
  25. {
  26. [Route("api/[controller]")]
  27. public class KFOrderController : BaseController
  28. {
  29. private readonly IBus_OrderDetailRepository bus_OrderDetailRepository;
  30. private readonly IBus_OrderRepository bus_OrderRepository;
  31. private readonly ISys_MarketingRepository bus_MarketingRepository;
  32. private readonly IBus_ProductRepository bus_productRepository;
  33. private readonly ICus_VipInfoRepository cus_vip_infoRepository;
  34. private readonly IBus_StockLogRepository bus_StockLogRepository;
  35. private readonly ICus_ScoreSetRepository cus_score_setRepository;
  36. private readonly IBus_OrderMoneyRepository busOrderMoneyRepository;
  37. private readonly IConfiguration config;
  38. private readonly OrderFunctionController busOrderFunctionController;
  39. private readonly IBus_AfterSaleRepository busAfterSaleRepository;
  40. public KFOrderController(IBus_AfterSaleRepository _busAfterSaleRepository, 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)
  41. {
  42. busAfterSaleRepository = _busAfterSaleRepository;
  43. bus_OrderDetailRepository = _bus_OrderDetailRepository;
  44. bus_OrderRepository = _bus_OrderRepository;
  45. bus_MarketingRepository = _bus_MarketingRepository;
  46. bus_productRepository = _productRepository;
  47. cus_vip_infoRepository = _cus_vip_infoRepository;
  48. bus_StockLogRepository = _bus_StockLogRepository;
  49. cus_score_setRepository = _cus_score_setRepository;
  50. busOrderMoneyRepository = _busOrderMoneyRepository;
  51. config = _configuration;
  52. busOrderFunctionController = _OrderFunctionController;
  53. }
  54. /// <summary>
  55. /// 导入订单跟踪
  56. /// </summary>
  57. /// <param name="input"></param>
  58. /// <returns></returns>
  59. [HttpPost("importordertrack")]
  60. public async Task<IActionResult> ImportOrderTrack()
  61. {
  62. Microsoft.AspNetCore.Http.IFormFile _upfile = Request.Form.Files[0];
  63. if (!_upfile.ContentType.Equals("application/vnd.ms-excel") && !_upfile.ContentType.Equals("application/x-xls") && !_upfile.ContentType.Equals("application/x-xlsx") && !_upfile.ContentType.Equals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") && !_upfile.ContentType.Equals("application/octet-stream"))
  64. return Error($"请正确上传Excel文件:file.ContentType={_upfile.ContentType}");
  65. //将数据导入数据库
  66. int headrow = 0;
  67. NPOIHelper npoi = new NPOIHelper();
  68. DataTable dtExcel = npoi.ExcelToTable1(_upfile, headrow);
  69. if (dtExcel.Rows.Count > 0)
  70. {
  71. Dictionary<string, string> dirList = new Dictionary<string, string>();
  72. string[] arrykey = config["Import:ordertrackkey"].ToString().ToLower().Split(',');
  73. string[] arryvalue = config["Import:ordertracktvalue"].ToString().Split(',');
  74. for (int i = 0; i < arrykey.Length; i++)
  75. {
  76. dirList.Add(arrykey[i], arryvalue[i]);
  77. }
  78. IList<T_Bus_Order> IModels = ModelConvertHelper<T_Bus_Order>.ConvertToModelByColumns(dtExcel, dirList);
  79. List<T_Bus_Order> models = ModelConvertHelper<T_Bus_Order>.ConvertIListToList(IModels);
  80. if (models != null && models.Count > 0)
  81. {
  82. int num = models.Count;
  83. //foreach (T_Bus_Order model in models)
  84. //{
  85. //状态如果需要更新 下面加F_State 如果需要验证之前状态,这里要循环查询
  86. //}
  87. if (await bus_OrderRepository.UpdateListToColumns(models, s => new { s.F_TrackingNo, s.F_Status }))
  88. {
  89. return Success("成功");
  90. }
  91. }
  92. else
  93. {
  94. return Success("内容为空");
  95. }
  96. }
  97. return Success("请选择要导入的文件");
  98. }
  99. /// <summary>
  100. /// 订单二审 审完 走发货
  101. /// </summary>
  102. /// <param name="orderid">订单号</param>
  103. /// <param name="state">订单状态 -1无效 0暂存 1提交 2KF退回 3通过 4KG退回 5已分拣 6已发货</param>
  104. /// <param name="remark">客服备注</param>
  105. /// <returns></returns>
  106. [HttpPost("/api/order/checkorderbykf")]
  107. public async Task<IActionResult> CheckOrderKF(string orderid, int state, string remark)
  108. {
  109. try
  110. {
  111. //状态变化 积分变化 处理时间人变化 库存变化 备注
  112. T_Cus_VipInfo modelvip = new T_Cus_VipInfo();
  113. #region 验证参数 必填项
  114. if (string.IsNullOrEmpty(orderid))
  115. return Error("请输入订单号");
  116. if (state <= 0)
  117. return Error("请选择操作类型");
  118. #endregion
  119. T_Bus_Order modelOrder = await bus_OrderRepository.GetSingle(q => q.F_Id == orderid && q.F_State == 1);
  120. if (modelOrder == null)
  121. {
  122. return Error("订单已审核");
  123. }
  124. if (string.IsNullOrEmpty(modelOrder.F_Express))
  125. {
  126. return Error("快递不能为空");
  127. }
  128. if (string.IsNullOrEmpty(modelOrder.F_AddPhone))
  129. {
  130. return Error("收件人电话不能为空");
  131. }
  132. if (string.IsNullOrEmpty(modelOrder.F_AddTown))
  133. {
  134. return Error("收件人地址不能为空");
  135. }
  136. if (string.IsNullOrEmpty(modelOrder.F_Address))
  137. {
  138. return Error("收件人详细地址不能为空");
  139. }
  140. modelOrder.F_CheckTime = DateTime.Now;
  141. modelOrder.F_CheckUser = int.Parse(User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.PrimarySid).Value, 0);
  142. modelOrder.F_CheckUserName = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Name).Value;
  143. if (!string.IsNullOrEmpty(remark))
  144. modelOrder.F_CheckRemark = remark;
  145. if (state == 2)
  146. {
  147. string strStock = await busOrderFunctionController.ChangeStockOne(modelOrder, 2, null);
  148. modelOrder.F_State = 2;
  149. modelOrder.F_Score = 0.00M;
  150. }
  151. else if (state == 3)
  152. {
  153. #region 判断积分
  154. bool blScore = false;
  155. if (modelOrder.F_UseScore > 0)
  156. {
  157. //退回积分 查询批次号核算积分是否已经解冻
  158. modelvip = await cus_vip_infoRepository.GetSingle(q => q.F_ID == modelOrder.F_VipId);
  159. modelvip.F_Score = modelvip.F_Score + modelOrder.F_UseScore;
  160. if (await cus_vip_infoRepository.Update(modelvip))
  161. {
  162. //log 或者解冻积分
  163. blScore = true;
  164. }
  165. }
  166. else
  167. {
  168. blScore = true;
  169. }
  170. if (!blScore)
  171. {
  172. return Error("积分处理失败");
  173. }
  174. #endregion
  175. //库存不做处理
  176. modelOrder.F_State = 3;
  177. }
  178. if (await bus_OrderRepository.Update(modelOrder))
  179. return Success("订单成功审核!");
  180. return Error("订单审核失败,请汇报技术支持!");
  181. }
  182. catch (Exception ex)
  183. { return Error(ex.Message); }
  184. }
  185. /// <summary>
  186. /// 获取订单分页列表
  187. /// </summary>
  188. /// <param name="input"></param>
  189. /// <returns></returns>
  190. [HttpPost("/api/order/getorderlistbykfpage")]
  191. public async Task<IActionResult> GetOrderListByKFPage(OrderInput input)
  192. {
  193. List<IConditionalModel> conModels = new List<IConditionalModel>();
  194. #region 条件筛选
  195. conModels.Add(new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.GreaterThanOrEqual, FieldValue = "0" });
  196. //状态
  197. if (input.F_State > -1)
  198. {
  199. conModels.Add(new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.Equal, FieldValue = input.F_State.ToString() });
  200. }
  201. //根据角色展示列表
  202. if (UserLogin.RoleCode == "XS")
  203. {
  204. conModels.Add(new ConditionalModel() { FieldName = "F_AddUser", ConditionalType = ConditionalType.Equal, FieldValue = UserLogin.UserId });
  205. }
  206. else if (UserLogin.RoleCode == "KF")
  207. {
  208. conModels.Add(new ConditionalCollections()
  209. {
  210. ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>()
  211. {
  212. new KeyValuePair<WhereType, ConditionalModel>( WhereType.And , new ConditionalModel() { FieldName = "F_CheckUser", ConditionalType = ConditionalType.Equal, FieldValue = UserLogin.UserId }),
  213. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or, new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.Equal, FieldValue = "1" })
  214. }
  215. });
  216. // conModels.Add(new ConditionalModel() { FieldName = "", ConditionalType = ConditionalType.Equal, FieldValue = UserLogin.UserId });
  217. }
  218. else if (UserLogin.RoleCode == "KG")
  219. {
  220. //conModels.Add(new ConditionalModel() { FieldName = "F_StockUser", ConditionalType = ConditionalType.Equal, FieldValue = UserLogin.UserId });
  221. conModels.Add(new ConditionalCollections()
  222. {
  223. ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>()
  224. {
  225. new KeyValuePair<WhereType, ConditionalModel>( WhereType.And , new ConditionalModel() { FieldName = "F_StockUser", ConditionalType = ConditionalType.Equal, FieldValue = UserLogin.UserId }),
  226. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_SendUser", ConditionalType = ConditionalType.Equal, FieldValue = UserLogin.UserId }),
  227. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or, new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.Equal, FieldValue = "3" })
  228. }
  229. });
  230. }
  231. if (!string.IsNullOrEmpty(input.F_ADFrom))
  232. {
  233. conModels.Add(new ConditionalModel() { FieldName = "F_ADFrom", ConditionalType = ConditionalType.Equal, FieldValue = input.F_ADFrom });
  234. }
  235. if (!string.IsNullOrEmpty(input.F_Type))
  236. {
  237. conModels.Add(new ConditionalModel() { FieldName = "F_Type", ConditionalType = ConditionalType.Equal, FieldValue = input.F_Type });
  238. }
  239. if (!string.IsNullOrEmpty(input.F_Id))
  240. {
  241. conModels.Add(new ConditionalModel() { FieldName = "F_Id", ConditionalType = ConditionalType.Equal, FieldValue = input.F_Id });
  242. }
  243. if (!string.IsNullOrEmpty(input.F_Customer))
  244. {
  245. conModels.Add(new ConditionalModel() { FieldName = "F_Customer", ConditionalType = ConditionalType.Equal, FieldValue = input.F_Customer });
  246. }
  247. if (!string.IsNullOrEmpty(input.F_CustomerPhone))
  248. {
  249. conModels.Add(new ConditionalModel() { FieldName = "F_CustomerPhone", ConditionalType = ConditionalType.Equal, FieldValue = input.F_CustomerPhone });
  250. }
  251. if (!string.IsNullOrEmpty(input.F_TrackingNo))
  252. {
  253. conModels.Add(new ConditionalModel() { FieldName = "F_TrackingNo", ConditionalType = ConditionalType.Equal, FieldValue = input.F_TrackingNo });
  254. }
  255. if (!string.IsNullOrEmpty(input.F_AddProvince))
  256. {
  257. conModels.Add(new ConditionalModel() { FieldName = "F_AddProvince", ConditionalType = ConditionalType.Equal, FieldValue = input.F_AddProvince });
  258. }
  259. if (!string.IsNullOrEmpty(input.F_AddCity))
  260. {
  261. conModels.Add(new ConditionalModel() { FieldName = "F_AddCity", ConditionalType = ConditionalType.Equal, FieldValue = input.F_AddCity });
  262. }
  263. if (!string.IsNullOrEmpty(input.F_AddArea))
  264. {
  265. conModels.Add(new ConditionalModel() { FieldName = "F_AddArea", ConditionalType = ConditionalType.Equal, FieldValue = input.F_AddArea });
  266. }
  267. if (!string.IsNullOrEmpty(input.F_AddTown))
  268. {
  269. conModels.Add(new ConditionalModel() { FieldName = "F_AddTown", ConditionalType = ConditionalType.Equal, FieldValue = input.F_AddTown });
  270. }
  271. if (!string.IsNullOrEmpty(input.F_Express))
  272. {
  273. conModels.Add(new ConditionalModel() { FieldName = "F_Express", ConditionalType = ConditionalType.Equal, FieldValue = input.F_Express });
  274. }
  275. if (!string.IsNullOrEmpty(input.F_PayType))
  276. {
  277. conModels.Add(new ConditionalModel() { FieldName = "F_PayType", ConditionalType = ConditionalType.Equal, FieldValue = input.F_PayType });
  278. }
  279. if (!string.IsNullOrEmpty(input.F_Stock))
  280. {
  281. conModels.Add(new ConditionalModel() { FieldName = "F_Stock", ConditionalType = ConditionalType.Equal, FieldValue = input.F_Stock });
  282. }
  283. if (input.F_PayState > -1)
  284. {
  285. if (input.F_PayState == 1 || input.F_PayState == 3)
  286. {
  287. conModels.Add(new ConditionalCollections()
  288. {
  289. ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>()
  290. {
  291. new KeyValuePair<WhereType, ConditionalModel>( WhereType.And , new ConditionalModel() { FieldName = "F_PayState", ConditionalType = ConditionalType.Equal, FieldValue = "1" }),
  292. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_PayState", ConditionalType = ConditionalType.Equal, FieldValue ="3" })
  293. }
  294. });
  295. }
  296. else
  297. {
  298. conModels.Add(new ConditionalModel() { FieldName = "F_PayState", ConditionalType = ConditionalType.Equal, FieldValue = input.F_PayState.ToString() });
  299. }
  300. }
  301. if (input.SearchEndTime != null)
  302. {
  303. conModels.Add(new ConditionalModel() { FieldName = "F_AddTime", ConditionalType = ConditionalType.LessThan, FieldValue = input.SearchEndTime.GetValueOrDefault().ToString("yyyy-MM-dd 23:59:59") });
  304. }
  305. if (input.SearchStartTime != null)
  306. {
  307. conModels.Add(new ConditionalModel() { FieldName = "F_AddTime", ConditionalType = ConditionalType.GreaterThan, FieldValue = input.SearchStartTime.GetValueOrDefault().ToString("yyyy-MM-dd 00:00:01") });
  308. }
  309. if (input.F_IsExpress > -1)
  310. {
  311. conModels.Add(new ConditionalModel() { FieldName = "F_IsExpress", ConditionalType = ConditionalType.Equal, FieldValue = input.F_IsExpress.ToString() });
  312. }
  313. #endregion
  314. RefAsync<int> recordCount = 0;
  315. PageData<T_Bus_Order> list = await bus_OrderRepository.GetListByPage(conModels, new MyPageModel() { PageIndex = input.pageindex, PageSize = input.pagesize, PageCount = recordCount }, " F_AddTime DESC");
  316. PageData<OrderInput> returnobj = new PageData<OrderInput>() { Totals = list.Totals };
  317. List<OrderInput> returnlist = new List<OrderInput>();
  318. foreach (T_Bus_Order t in list.Rows)
  319. {
  320. OrderInput m = new OrderInput();
  321. ModelConvertHelper<OrderInput, T_Bus_Order>.ModeToModel(m, t);
  322. List<OrderDetailInput> orderDetailInputs = new List<OrderDetailInput>();
  323. #region 遍历订单商品
  324. List<T_Bus_OrderDetail> orderDetails = await bus_OrderDetailRepository.GetListALL(q => q.F_OrderId == t.F_Id);
  325. if (orderDetails != null)
  326. {
  327. foreach (T_Bus_OrderDetail t1 in orderDetails)
  328. {
  329. OrderDetailInput m1 = new OrderDetailInput();
  330. ModelConvertHelper<OrderDetailInput, T_Bus_OrderDetail>.ModeToModel(m1, t1);
  331. orderDetailInputs.Add(m1);
  332. }
  333. }
  334. #endregion
  335. m.OrderDetailList = orderDetailInputs;
  336. returnlist.Add(m);
  337. }
  338. returnobj.Rows = returnlist;
  339. return Success("成功", returnobj);
  340. }
  341. /// <summary>
  342. /// 修改订单
  343. /// </summary>
  344. /// <param name="input"></param>
  345. /// <returns></returns>
  346. [HttpPost("/api/order/editorderkf")]
  347. public async Task<IActionResult> EditOrderKF([FromBody]OrderInput input)
  348. {
  349. T_Cus_VipInfo modelvip = new T_Cus_VipInfo();
  350. #region 验证参数 必填项
  351. if (string.IsNullOrEmpty(input.F_ADFrom))
  352. return Error("请输入选择广告来源");
  353. if (string.IsNullOrEmpty(input.F_Type))
  354. return Error("请输入选择订单类型");
  355. if (string.IsNullOrEmpty(input.F_Id))
  356. return Error("请输入订单编号");
  357. if (string.IsNullOrEmpty(input.F_Customer))
  358. return Error("请输入客户姓名");
  359. if (string.IsNullOrEmpty(input.F_CustomerPhone))
  360. return Error("请输入客户电话");
  361. #endregion
  362. T_Bus_Order modelOrder = await bus_OrderRepository.GetSingle(q => q.F_Id == input.F_Id);
  363. if (modelOrder == null)
  364. {
  365. return Error("此订单号不存在");
  366. }
  367. //保存 审退回 仓退回
  368. if (!(new int[] { 1, 3 }.Contains(modelOrder.F_State)))
  369. {
  370. return Error("已提交订单不允许修改,先撤回订单");
  371. }
  372. #region 数据绑定
  373. //必填
  374. modelOrder.F_ADFrom = input.F_ADFrom;
  375. modelOrder.F_Type = input.F_Type;
  376. modelOrder.F_Id = input.F_Id;
  377. if (input.F_CustomerType > 0)
  378. { modelOrder.F_CustomerType = input.F_CustomerType; }
  379. if (!string.IsNullOrEmpty(input.F_CustomerTel))
  380. { modelOrder.F_CustomerTel = input.F_CustomerTel; }
  381. //选填 快递属性
  382. if (!string.IsNullOrEmpty(input.F_TrackingNo))
  383. { modelOrder.F_TrackingNo = input.F_TrackingNo; }
  384. if (!string.IsNullOrEmpty(input.F_Addressee))
  385. { modelOrder.F_Addressee = input.F_Addressee; }
  386. if (!string.IsNullOrEmpty(input.F_AddPhone))
  387. { modelOrder.F_AddPhone = input.F_AddPhone; }
  388. if (!string.IsNullOrEmpty(input.F_AddProvince))
  389. { modelOrder.F_AddProvince = input.F_AddProvince; }
  390. if (!string.IsNullOrEmpty(input.F_AddCity))
  391. { modelOrder.F_AddCity = input.F_AddCity; }
  392. if (!string.IsNullOrEmpty(input.F_AddArea))
  393. { modelOrder.F_AddArea = input.F_AddArea; }
  394. if (!string.IsNullOrEmpty(input.F_AddTown))
  395. { modelOrder.F_AddTown = input.F_AddTown; }
  396. if (!string.IsNullOrEmpty(input.F_AddDes))
  397. { modelOrder.F_AddDes = input.F_AddDes; }
  398. if (!string.IsNullOrEmpty(input.F_Address))
  399. { modelOrder.F_Address = input.F_Address; }
  400. if (!string.IsNullOrEmpty(input.F_PostalCode))
  401. { modelOrder.F_PostalCode = input.F_PostalCode; }
  402. if (!string.IsNullOrEmpty(input.F_Express))
  403. { modelOrder.F_Express = input.F_Express; }
  404. if (!string.IsNullOrEmpty(input.F_Remark))
  405. { modelOrder.F_Remark = input.F_Remark; }
  406. if (!string.IsNullOrEmpty(input.F_PayType))
  407. { modelOrder.F_PayType = input.F_PayType; }
  408. if (input.F_VipId > 0)
  409. { modelOrder.F_VipId = input.F_VipId; }
  410. if (!string.IsNullOrEmpty(modelOrder.F_Express))
  411. modelOrder.F_IsExpress = 1;
  412. //选填 关联属性
  413. modelOrder.F_ExpressFee = input.F_ExpressFee;
  414. modelOrder.F_State = input.F_State;
  415. modelOrder.F_Status = 0;
  416. //必须属性 系统生成
  417. modelOrder.F_CheckTime = DateTime.Now;
  418. modelOrder.F_CheckUser = UserLogin.UserId.ObjToInt();
  419. modelOrder.F_CheckUserName = UserLogin.UserName;
  420. #endregion
  421. modelOrder.F_ShouldPrice = modelOrder.F_TotlePrice - modelOrder.F_ActivityMoney + modelOrder.F_ExpressFee + modelOrder.F_MergeMoney;
  422. if (await bus_OrderRepository.Update(modelOrder))
  423. {
  424. return Success("成功");
  425. }
  426. return Error("订单添加失败,请重试!");
  427. }
  428. /// <summary>
  429. /// 订单打标签
  430. /// </summary>
  431. /// <param name="orderids"></param>
  432. /// <param name="tags"></param>
  433. /// <returns></returns>
  434. [HttpPost("addordertag")]
  435. public async Task<IActionResult> AddOrderTag(string orderids, string tags)
  436. {
  437. #region 验证参数 必填项
  438. if (string.IsNullOrEmpty(orderids))
  439. return Error("请选择订单号");
  440. if (string.IsNullOrEmpty(tags))
  441. return Error("请选择标签");
  442. #endregion
  443. if (await bus_OrderRepository.Update(s => new T_Bus_Order() { F_Tag = tags }, q => orderids.Contains(q.F_Id)))
  444. {
  445. return Success("成功");
  446. }
  447. return Error("失败,请重试!");
  448. }
  449. [HttpPost("updateexpress")]
  450. public async Task<IActionResult> UpdateExpress(string orderids, string express)
  451. {
  452. #region 验证参数 必填项
  453. if (string.IsNullOrEmpty(orderids))
  454. return Error("请选择订单号");
  455. if (string.IsNullOrEmpty(express))
  456. return Error("请选择标签");
  457. #endregion
  458. //更新所选订单的快递,并标记为客服已分配快递
  459. if (await bus_OrderRepository.Update(s => new T_Bus_Order() { F_Express = express, F_IsExpress = 1 }, q => orderids.Contains(q.F_Id)))
  460. {
  461. return Success("成功");
  462. }
  463. return Error("失败,请重试!");
  464. }
  465. [HttpPost("checkordermoney")]
  466. public async Task<IActionResult> CheckOrderMoney(OrderMoneyInput input)
  467. {
  468. try
  469. {
  470. #region 验证参数 必填项
  471. if (string.IsNullOrEmpty(input.F_Id))
  472. return Error("请选择条目");
  473. if (string.IsNullOrEmpty(input.F_RemarkKF))
  474. input.F_RemarkKF = "";
  475. if (string.IsNullOrEmpty(input.F_RemarkXS))
  476. input.F_RemarkXS = "";
  477. if (input.F_Money <= 0)
  478. return Error("请输入金额");
  479. #endregion
  480. T_Bus_OrderMoney modelOrderMoeny = await busOrderMoneyRepository.GetSingle(q => q.F_Id == input.F_Id);
  481. modelOrderMoeny.F_CheckUserId = UserLogin.UserId.ObjToInt();
  482. modelOrderMoeny.F_CheckUserName = UserLogin.UserName;
  483. modelOrderMoeny.F_Money = modelOrderMoeny.F_Money;
  484. modelOrderMoeny.F_State = input.F_State;
  485. modelOrderMoeny.F_RemarkKF = input.F_RemarkKF;
  486. if (modelOrderMoeny.F_State == 1)
  487. {
  488. T_Bus_Order modelOrder = await bus_OrderRepository.GetSingle(q => q.F_Id == modelOrderMoeny.F_OrderId);
  489. if (modelOrder.F_PayState == 1 || modelOrder.F_PayState == 3)
  490. {
  491. return Error("此单已结算!");
  492. }
  493. modelOrder.F_RealPrice = modelOrder.F_RealPrice + modelOrderMoeny.F_Money;
  494. if (modelOrder.F_PayState == 0)
  495. {
  496. if (modelOrder.F_ShouldPrice <= modelOrder.F_RealPrice)
  497. {
  498. //0待回款1已支付 2待退款3已退款
  499. modelOrder.F_PayState = 1;
  500. }
  501. }
  502. else if (modelOrder.F_PayState == 2)
  503. {
  504. if (modelOrder.F_ShouldPrice <= modelOrder.F_RealPrice)
  505. {
  506. //0待回款1已支付 2待退款3已退款
  507. modelOrder.F_PayState = 3;
  508. }
  509. }
  510. await bus_OrderRepository.UpdateListToColumns(new List<T_Bus_Order>() { modelOrder }, s => new { s.F_PayState, s.F_RealPrice });
  511. }
  512. if (await busOrderMoneyRepository.AddReturnCount(modelOrderMoeny))
  513. return Success("成功!");
  514. return Error("失败!");
  515. }
  516. catch (Exception ex)
  517. { return Error(ex.Message); }
  518. }
  519. [HttpPost("ordermoney")]
  520. public async Task<IActionResult> OrderMoney(OrderMoneyInput input)
  521. {
  522. try
  523. {
  524. #region 验证参数 必填项
  525. if (string.IsNullOrEmpty(input.F_OrderId))
  526. return Error("请输入订单号");
  527. if (string.IsNullOrEmpty(input.F_PayUser))
  528. return Error("请输入打款人");
  529. if (string.IsNullOrEmpty(input.F_PayType))
  530. return Error("请输入打款方式");
  531. if (string.IsNullOrEmpty(input.F_RemarkKF))
  532. input.F_RemarkKF = "";
  533. if (string.IsNullOrEmpty(input.F_RemarkXS))
  534. input.F_RemarkXS = "";
  535. if (input.F_PayTime == null)
  536. return Error("请输入打款时间");
  537. if (input.F_Money < 0)
  538. return Error("请输入金额");
  539. #endregion
  540. T_Bus_OrderMoney modelOrderMoeny = new T_Bus_OrderMoney();
  541. ModelConvertHelper<T_Bus_OrderMoney, OrderMoneyInput>.ModeToModelDefault(modelOrderMoeny, input);
  542. modelOrderMoeny.F_AddUserId = UserLogin.UserId.ObjToInt();
  543. modelOrderMoeny.F_UserName = UserLogin.UserName;
  544. modelOrderMoeny.F_Money = -input.F_Money;
  545. modelOrderMoeny.F_MoneyBak = modelOrderMoeny.F_Money;
  546. modelOrderMoeny.F_State = 1;
  547. modelOrderMoeny.F_Id = Guid.NewGuid().ToString().Replace(",", "");
  548. T_Bus_Order modelOrder = await bus_OrderRepository.GetSingle(q => q.F_Id == modelOrderMoeny.F_OrderId);
  549. if (modelOrder.F_PayState == 1 || modelOrder.F_PayState == 3)
  550. {
  551. return Error("此单已结算!");
  552. }
  553. modelOrder.F_RealPrice = modelOrder.F_RealPrice + modelOrderMoeny.F_Money;
  554. if (modelOrder.F_PayState == 2)
  555. {
  556. if (modelOrder.F_ShouldPrice >= modelOrder.F_RealPrice)
  557. {
  558. //0待回款1已支付 2待退款3已退款
  559. modelOrder.F_PayState = 3;
  560. }
  561. }
  562. await bus_OrderRepository.UpdateListToColumns(new List<T_Bus_Order>() { modelOrder }, s => new { s.F_PayState, s.F_RealPrice });
  563. if (await busOrderMoneyRepository.AddReturnCount(modelOrderMoeny))
  564. return Success("成功!");
  565. return Error("失败!");
  566. }
  567. catch (Exception ex)
  568. { return Error(ex.Message); }
  569. }
  570. /// <summary>
  571. /// 根据分页获取售后列表 待退款 退货 仓库确认收到货 补差额 不需要仓库确认
  572. /// </summary>
  573. /// <param name="input"></param>
  574. /// <returns></returns>
  575. [HttpPost("getaftersalebypage")]
  576. public async Task<IActionResult> GetAfterSaleByPage(AfterSaleInput input)
  577. {
  578. #region 拼接条件
  579. Expression<Func<T_Bus_AfterSale, bool>> eq = a => a.F_Money<0&& a.F_CheckStateSH==1 && ((a.F_CheckStateKG == 1&&(a.F_Type==2|| a.F_Type == 3))|| a.F_Type == 6);
  580. if (!string.IsNullOrEmpty(input.F_Id))
  581. {
  582. eq = eq.And(a => a.F_Id == input.F_Id);
  583. }
  584. if (input.F_State > 0)
  585. {
  586. eq = eq.And(a => a.F_State == input.F_State);
  587. }
  588. if (input.F_Type > 0)
  589. {
  590. eq = eq.And(a => a.F_Type == input.F_Type);
  591. }
  592. if (!string.IsNullOrEmpty(input.F_ReturnType))
  593. {
  594. eq = eq.And(a => a.F_ReturnType == input.F_ReturnType);
  595. }
  596. #endregion
  597. RefAsync<int> count = 0;
  598. PageData<T_Bus_AfterSale> list = await busAfterSaleRepository.GetListByPage(eq, new MyPageModel() { PageIndex = input.pageindex, PageSize = input.pagesize, PageCount = count }, " F_AddTime DESC");
  599. return Success("成功", list);
  600. }
  601. /// <summary>
  602. /// 更新售后退款状态
  603. /// </summary>
  604. /// <param name="input"></param>
  605. /// <returns></returns>
  606. [HttpPost("updatestate")]
  607. public async Task<IActionResult> UpdateState(AfterSaleInput input)
  608. {
  609. try
  610. {
  611. #region 验证参数 必填项
  612. if (string.IsNullOrEmpty(input.F_Id))
  613. return Error("请选择售后单");
  614. if (input.F_CheckTimeXS==null)
  615. return Error("请选择退款时间");
  616. if (input.F_State==0)
  617. return Error("更新状态不正确");
  618. #endregion
  619. T_Bus_AfterSale modelAfterSale = await busAfterSaleRepository.GetSingle(q => q.F_Id == input.F_Id);
  620. if (modelAfterSale.F_Type != 2 && modelAfterSale.F_Type != 3 && modelAfterSale.F_Type != 6)
  621. {
  622. return Error("售后类型不支持退款");
  623. }
  624. //1收到货(根据状态自动创建订单)2货物不符3未收到货
  625. if ((modelAfterSale.F_Type == 2 || modelAfterSale.F_Type == 3)&&modelAfterSale.F_CheckStateKG != 1)
  626. {
  627. return Error("仓库暂未确认收到退货");
  628. }
  629. if (modelAfterSale.F_Money >= 0)
  630. {
  631. return Error("此金额不需要退款");
  632. }
  633. modelAfterSale.F_CheckTimeXS = input.F_CheckTimeXS;
  634. modelAfterSale.F_State = 1;
  635. if (await busAfterSaleRepository.Update(modelAfterSale))
  636. {
  637. return Success("成功");
  638. }
  639. return Error("失败,请重试!");
  640. }
  641. catch (Exception ex)
  642. { return Error(ex.Message); }
  643. }
  644. }
  645. }