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

KFOrderController.cs 36KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857
  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 (state == 3)
  125. {
  126. if (string.IsNullOrEmpty(modelOrder.F_Stock))
  127. {
  128. return Error("出货仓不能为空");
  129. }
  130. if (string.IsNullOrEmpty(modelOrder.F_Express))
  131. {
  132. return Error("快递不能为空");
  133. }
  134. if (string.IsNullOrEmpty(modelOrder.F_AddPhone))
  135. {
  136. return Error("收件人电话不能为空");
  137. }
  138. if (string.IsNullOrEmpty(modelOrder.F_AddTown))
  139. {
  140. return Error("收件人地址不能为空");
  141. }
  142. if (string.IsNullOrEmpty(modelOrder.F_Address))
  143. {
  144. return Error("收件人详细地址不能为空");
  145. }
  146. }
  147. modelOrder.F_CheckTime = DateTime.Now;
  148. modelOrder.F_CheckUser = UserLogin.UserId.ObjToInt();
  149. modelOrder.F_CheckUserName = UserLogin.UserName;
  150. if (!string.IsNullOrEmpty(remark))
  151. modelOrder.F_CheckRemark = remark;
  152. if (state == 2)
  153. {
  154. string strStock = await busOrderFunctionController.ChangeStockOne(modelOrder, 2, null);
  155. modelOrder.F_State = 2;
  156. modelOrder.F_Score = 0.00M;
  157. }
  158. else if (state == 3)
  159. {
  160. #region 判断积分
  161. bool blScore = false;
  162. if (modelOrder.F_UseScore > 0)
  163. {
  164. //退回积分 查询批次号核算积分是否已经解冻
  165. modelvip = await cus_vip_infoRepository.GetSingle(q => q.F_ID == modelOrder.F_VipId);
  166. modelvip.F_Score = modelvip.F_Score + modelOrder.F_UseScore;
  167. if (await cus_vip_infoRepository.Update(modelvip))
  168. {
  169. //log 或者解冻积分
  170. blScore = true;
  171. }
  172. }
  173. else
  174. {
  175. blScore = true;
  176. }
  177. if (!blScore)
  178. {
  179. return Error("积分处理失败");
  180. }
  181. #endregion
  182. //库存不做处理
  183. modelOrder.F_State = 3;
  184. }
  185. if (await bus_OrderRepository.Update(modelOrder))
  186. return Success("订单成功审核!");
  187. return Error("订单审核失败,请汇报技术支持!");
  188. }
  189. catch (Exception ex)
  190. { return Error(ex.Message); }
  191. }
  192. /// <summary>
  193. /// 获取订单分页列表
  194. /// </summary>
  195. /// <param name="input"></param>
  196. /// <returns></returns>
  197. [HttpPost("/api/order/getorderlistbykfpage")]
  198. public async Task<IActionResult> GetOrderListByKFPage(OrderInput input,int PayState=0,int state=-1)
  199. {
  200. List<IConditionalModel> conModels = new List<IConditionalModel>();
  201. #region 条件筛选
  202. // conModels.Add(new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.GreaterThan, FieldValue = "0" });
  203. //状态
  204. if (input.F_State > -2)
  205. {
  206. conModels.Add(new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.Equal, FieldValue = input.F_State.ToString() });
  207. }
  208. else
  209. {
  210. if (state > -1)
  211. {
  212. conModels.Add(new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.GreaterThanOrEqual , FieldValue ="3" });
  213. }
  214. }
  215. //根据角色展示列表
  216. if (UserLogin.RoleCode == "XS")
  217. {
  218. conModels.Add(new ConditionalModel() { FieldName = "F_AddUser", ConditionalType = ConditionalType.Equal, FieldValue = UserLogin.UserId });
  219. }
  220. else if (UserLogin.RoleCode == "KF")
  221. {
  222. conModels.Add(new ConditionalCollections()
  223. {
  224. ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>()
  225. {
  226. new KeyValuePair<WhereType, ConditionalModel>( WhereType.And , new ConditionalModel() { FieldName = "F_CheckUser", ConditionalType = ConditionalType.Equal, FieldValue = UserLogin.UserId }),
  227. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or, new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.Equal, FieldValue = "1" })
  228. }
  229. });
  230. // conModels.Add(new ConditionalModel() { FieldName = "", ConditionalType = ConditionalType.Equal, FieldValue = UserLogin.UserId });
  231. }
  232. else if (UserLogin.RoleCode == "KG")
  233. {
  234. //conModels.Add(new ConditionalModel() { FieldName = "F_StockUser", ConditionalType = ConditionalType.Equal, FieldValue = UserLogin.UserId });
  235. conModels.Add(new ConditionalCollections()
  236. {
  237. ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>()
  238. {
  239. new KeyValuePair<WhereType, ConditionalModel>( WhereType.And , new ConditionalModel() { FieldName = "F_StockUser", ConditionalType = ConditionalType.Equal, FieldValue = UserLogin.UserId }),
  240. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_SendUser", ConditionalType = ConditionalType.Equal, FieldValue = UserLogin.UserId }),
  241. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or, new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.Equal, FieldValue = "3" })
  242. }
  243. });
  244. }
  245. if (!string.IsNullOrEmpty(input.F_ADFrom))
  246. {
  247. conModels.Add(new ConditionalModel() { FieldName = "F_ADFrom", ConditionalType = ConditionalType.Equal, FieldValue = input.F_ADFrom });
  248. }
  249. if (!string.IsNullOrEmpty(input.F_Type))
  250. {
  251. conModels.Add(new ConditionalModel() { FieldName = "F_Type", ConditionalType = ConditionalType.Equal, FieldValue = input.F_Type });
  252. }
  253. if (!string.IsNullOrEmpty(input.F_Id))
  254. {
  255. conModels.Add(new ConditionalModel() { FieldName = "F_Id", ConditionalType = ConditionalType.Equal, FieldValue = input.F_Id });
  256. }
  257. if (!string.IsNullOrEmpty(input.F_Customer))
  258. {
  259. conModels.Add(new ConditionalModel() { FieldName = "F_Customer", ConditionalType = ConditionalType.Equal, FieldValue = input.F_Customer });
  260. }
  261. if (!string.IsNullOrEmpty(input.F_CustomerPhone))
  262. {
  263. conModels.Add(new ConditionalModel() { FieldName = "F_CustomerPhone", ConditionalType = ConditionalType.Equal, FieldValue = input.F_CustomerPhone });
  264. }
  265. if (!string.IsNullOrEmpty(input.F_TrackingNo))
  266. {
  267. conModels.Add(new ConditionalModel() { FieldName = "F_TrackingNo", ConditionalType = ConditionalType.Equal, FieldValue = input.F_TrackingNo });
  268. }
  269. if (!string.IsNullOrEmpty(input.F_AddProvince))
  270. {
  271. conModels.Add(new ConditionalModel() { FieldName = "F_AddProvince", ConditionalType = ConditionalType.Equal, FieldValue = input.F_AddProvince });
  272. }
  273. if (!string.IsNullOrEmpty(input.F_AddCity))
  274. {
  275. conModels.Add(new ConditionalModel() { FieldName = "F_AddCity", ConditionalType = ConditionalType.Equal, FieldValue = input.F_AddCity });
  276. }
  277. if (!string.IsNullOrEmpty(input.F_AddArea))
  278. {
  279. conModels.Add(new ConditionalModel() { FieldName = "F_AddArea", ConditionalType = ConditionalType.Equal, FieldValue = input.F_AddArea });
  280. }
  281. if (!string.IsNullOrEmpty(input.F_AddTown))
  282. {
  283. conModels.Add(new ConditionalModel() { FieldName = "F_AddTown", ConditionalType = ConditionalType.Equal, FieldValue = input.F_AddTown });
  284. }
  285. if (!string.IsNullOrEmpty(input.F_Express))
  286. {
  287. conModels.Add(new ConditionalModel() { FieldName = "F_Express", ConditionalType = ConditionalType.Equal, FieldValue = input.F_Express });
  288. }
  289. if (!string.IsNullOrEmpty(input.F_PayType))
  290. {
  291. conModels.Add(new ConditionalModel() { FieldName = "F_PayType", ConditionalType = ConditionalType.Equal, FieldValue = input.F_PayType });
  292. }
  293. if (!string.IsNullOrEmpty(input.F_Stock))
  294. {
  295. conModels.Add(new ConditionalModel() { FieldName = "F_Stock", ConditionalType = ConditionalType.Equal, FieldValue = input.F_Stock });
  296. }
  297. if (input.F_PayState > -1)
  298. {
  299. if (PayState>0)
  300. {
  301. conModels.Add(new ConditionalModel() { FieldName = "F_PayState", ConditionalType = ConditionalType.Equal, FieldValue = input.F_PayState.ToString() });
  302. }
  303. else
  304. {
  305. if (input.F_PayState == 1 || input.F_PayState == 3)
  306. {
  307. conModels.Add(new ConditionalCollections()
  308. {
  309. ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>()
  310. {
  311. new KeyValuePair<WhereType, ConditionalModel>( WhereType.And , new ConditionalModel() { FieldName = "F_PayState", ConditionalType = ConditionalType.Equal, FieldValue = "1" }),
  312. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_PayState", ConditionalType = ConditionalType.Equal, FieldValue ="3" })
  313. }
  314. });
  315. }
  316. else
  317. {
  318. conModels.Add(new ConditionalModel() { FieldName = "F_PayState", ConditionalType = ConditionalType.Equal, FieldValue = input.F_PayState.ToString() });
  319. }
  320. }
  321. }
  322. if (input.SearchEndTime != null)
  323. {
  324. conModels.Add(new ConditionalModel() { FieldName = "F_AddTime", ConditionalType = ConditionalType.LessThan, FieldValue = input.SearchEndTime.GetValueOrDefault().ToString("yyyy-MM-dd 23:59:59") });
  325. }
  326. if (input.SearchStartTime != null)
  327. {
  328. conModels.Add(new ConditionalModel() { FieldName = "F_AddTime", ConditionalType = ConditionalType.GreaterThan, FieldValue = input.SearchStartTime.GetValueOrDefault().ToString("yyyy-MM-dd 00:00:01") });
  329. }
  330. if (input.F_IsExpress > -1)
  331. {
  332. conModels.Add(new ConditionalModel() { FieldName = "F_IsExpress", ConditionalType = ConditionalType.Equal, FieldValue = input.F_IsExpress.ToString() });
  333. }
  334. #endregion
  335. RefAsync<int> recordCount = 0;
  336. PageData<T_Bus_Order> list = await bus_OrderRepository.GetListByPage(conModels, new MyPageModel() { PageIndex = input.pageindex, PageSize = input.pagesize, PageCount = recordCount }, " F_AddTime DESC");
  337. PageData<OrderInput> returnobj = new PageData<OrderInput>() { Totals = list.Totals };
  338. List<OrderInput> returnlist = new List<OrderInput>();
  339. foreach (T_Bus_Order t in list.Rows)
  340. {
  341. OrderInput m = new OrderInput();
  342. ModelConvertHelper<OrderInput, T_Bus_Order>.ModeToModel(m, t);
  343. List<OrderDetailInput> orderDetailInputs = new List<OrderDetailInput>();
  344. #region 遍历订单商品
  345. List<T_Bus_OrderDetail> orderDetails = await bus_OrderDetailRepository.GetListALL(q => q.F_OrderId == t.F_Id);
  346. if (orderDetails != null)
  347. {
  348. foreach (T_Bus_OrderDetail t1 in orderDetails)
  349. {
  350. OrderDetailInput m1 = new OrderDetailInput();
  351. ModelConvertHelper<OrderDetailInput, T_Bus_OrderDetail>.ModeToModel(m1, t1);
  352. orderDetailInputs.Add(m1);
  353. }
  354. }
  355. #endregion
  356. m.OrderDetailList = orderDetailInputs;
  357. returnlist.Add(m);
  358. }
  359. returnobj.Rows = returnlist;
  360. return Success("成功", returnobj);
  361. }
  362. /// <summary>
  363. /// 修改订单
  364. /// </summary>
  365. /// <param name="input"></param>
  366. /// <returns></returns>
  367. [HttpPost("/api/order/editorderkf")]
  368. public async Task<IActionResult> EditOrderKF([FromBody]OrderInput input)
  369. {
  370. T_Cus_VipInfo modelvip = new T_Cus_VipInfo();
  371. #region 验证参数 必填项
  372. if (string.IsNullOrEmpty(input.F_ADFrom))
  373. return Error("请输入选择广告来源");
  374. if (string.IsNullOrEmpty(input.F_Type))
  375. return Error("请输入选择订单类型");
  376. if (string.IsNullOrEmpty(input.F_Id))
  377. return Error("请输入订单编号");
  378. if (string.IsNullOrEmpty(input.F_Customer))
  379. return Error("请输入客户姓名");
  380. if (string.IsNullOrEmpty(input.F_CustomerPhone))
  381. return Error("请输入客户电话");
  382. #endregion
  383. T_Bus_Order modelOrder = await bus_OrderRepository.GetSingle(q => q.F_Id == input.F_Id);
  384. if (modelOrder == null)
  385. {
  386. return Error("此订单号不存在");
  387. }
  388. //保存 审退回 仓退回
  389. if (!(new int[] { 1, 3 ,4}.Contains(modelOrder.F_State)))
  390. {
  391. return Error("此状态订单不允许修改,先撤回订单");
  392. }
  393. #region 数据绑定
  394. //必填
  395. modelOrder.F_ADFrom = input.F_ADFrom;
  396. modelOrder.F_Type = input.F_Type;
  397. modelOrder.F_Id = input.F_Id;
  398. if (input.F_CustomerType > 0)
  399. { modelOrder.F_CustomerType = input.F_CustomerType; }
  400. if (!string.IsNullOrEmpty(input.F_CustomerTel))
  401. { modelOrder.F_CustomerTel = input.F_CustomerTel; }
  402. //选填 快递属性
  403. if (!string.IsNullOrEmpty(input.F_TrackingNo))
  404. { modelOrder.F_TrackingNo = input.F_TrackingNo; }
  405. if (!string.IsNullOrEmpty(input.F_Addressee))
  406. { modelOrder.F_Addressee = input.F_Addressee; }
  407. if (!string.IsNullOrEmpty(input.F_AddPhone))
  408. { modelOrder.F_AddPhone = input.F_AddPhone; }
  409. if (!string.IsNullOrEmpty(input.F_AddProvince))
  410. { modelOrder.F_AddProvince = input.F_AddProvince; }
  411. if (!string.IsNullOrEmpty(input.F_AddCity))
  412. { modelOrder.F_AddCity = input.F_AddCity; }
  413. if (!string.IsNullOrEmpty(input.F_AddArea))
  414. { modelOrder.F_AddArea = input.F_AddArea; }
  415. if (!string.IsNullOrEmpty(input.F_AddTown))
  416. { modelOrder.F_AddTown = input.F_AddTown; }
  417. if (!string.IsNullOrEmpty(input.F_AddDes))
  418. { modelOrder.F_AddDes = input.F_AddDes; }
  419. if (!string.IsNullOrEmpty(input.F_Address))
  420. { modelOrder.F_Address = input.F_Address; }
  421. if (!string.IsNullOrEmpty(input.F_PostalCode))
  422. { modelOrder.F_PostalCode = input.F_PostalCode; }
  423. if (!string.IsNullOrEmpty(input.F_Express))
  424. { modelOrder.F_Express = input.F_Express; }
  425. if (!string.IsNullOrEmpty(input.F_Remark))
  426. { modelOrder.F_Remark = input.F_Remark; }
  427. if (!string.IsNullOrEmpty(input.F_PayType))
  428. { modelOrder.F_PayType = input.F_PayType; }
  429. if (input.F_VipId > 0)
  430. { modelOrder.F_VipId = input.F_VipId; }
  431. if (!string.IsNullOrEmpty(modelOrder.F_Express))
  432. modelOrder.F_IsExpress = 1;
  433. //选填 关联属性
  434. modelOrder.F_ExpressFee = input.F_ExpressFee;
  435. modelOrder.F_State = input.F_State;
  436. modelOrder.F_Status = 0;
  437. //必须属性 系统生成
  438. modelOrder.F_CheckTime = DateTime.Now;
  439. modelOrder.F_CheckUser = UserLogin.UserId.ObjToInt();
  440. modelOrder.F_CheckUserName = UserLogin.UserName;
  441. if (string.IsNullOrEmpty(modelOrder.F_Express))
  442. {
  443. return Error("快递不能为空");
  444. }
  445. if (string.IsNullOrEmpty(modelOrder.F_AddPhone))
  446. {
  447. return Error("收件人电话不能为空");
  448. }
  449. if (string.IsNullOrEmpty(modelOrder.F_AddTown))
  450. {
  451. return Error("收件人地址不能为空");
  452. }
  453. if (string.IsNullOrEmpty(modelOrder.F_Address))
  454. {
  455. return Error("收件人详细地址不能为空");
  456. }
  457. #endregion
  458. modelOrder.F_ShouldPrice = modelOrder.F_TotlePrice - modelOrder.F_ActivityMoney + modelOrder.F_ExpressFee + modelOrder.F_MergeMoney;
  459. if (await bus_OrderRepository.Update(modelOrder))
  460. {
  461. return Success("成功");
  462. }
  463. return Error("订单添加失败,请重试!");
  464. }
  465. /// <summary>
  466. /// 订单打标签
  467. /// </summary>
  468. /// <param name="orderids"></param>
  469. /// <param name="tags"></param>
  470. /// <returns></returns>
  471. [HttpPost("addordertag")]
  472. public async Task<IActionResult> AddOrderTag(string orderids, string tags)
  473. {
  474. #region 验证参数 必填项
  475. if (string.IsNullOrEmpty(orderids))
  476. return Error("请选择订单号");
  477. if (string.IsNullOrEmpty(tags))
  478. return Error("请选择标签");
  479. #endregion
  480. string[] ids = orderids.Split(',');
  481. if (await bus_OrderRepository.Update(s => new T_Bus_Order() { F_Tag = tags }, q => ids.Contains(q.F_Id)))
  482. {
  483. return Success("成功");
  484. }
  485. return Error("失败,请重试!");
  486. }
  487. /// <summary>
  488. /// 更新物流状态
  489. /// </summary>
  490. /// <param name="orderids"></param>
  491. /// <param name="status">0 未发出 1未签收2签收3改代收4拒收</param>
  492. /// <returns></returns>
  493. [HttpPost("updatestatus")]
  494. public async Task<IActionResult> UpdateStatus(string orderids, int status)
  495. {
  496. #region 验证参数 必填项
  497. if (string.IsNullOrEmpty(orderids))
  498. return Error("请选择订单号");
  499. if (status == 0)
  500. return Error("请选择状态");
  501. #endregion
  502. string[] ids = orderids.Split(',');
  503. if (await bus_OrderRepository.Update(s => new T_Bus_Order() { F_Status = status }, q => ids.Contains(q.F_Id)))
  504. {
  505. return Success("成功");
  506. }
  507. return Error("失败,请重试!");
  508. }
  509. [HttpPost("updateexpress")]
  510. public async Task<IActionResult> UpdateExpress(string orderids, string express)
  511. {
  512. #region 验证参数 必填项
  513. if (string.IsNullOrEmpty(orderids))
  514. return Error("请选择订单号");
  515. if (string.IsNullOrEmpty(express))
  516. return Error("请选择快递");
  517. #endregion
  518. //更新所选订单的快递,并标记为客服已分配快递
  519. string[] ids = orderids.Split(',');
  520. if (await bus_OrderRepository.Update(s => new T_Bus_Order() { F_Express = express, F_IsExpress = 1 }, q => ids.Contains(q.F_Id)))
  521. {
  522. return Success("成功");
  523. }
  524. return Error("失败,请重试!");
  525. }
  526. [HttpPost("checkordermoney")]
  527. public async Task<IActionResult> CheckOrderMoney(OrderMoneyInput input)
  528. {
  529. try
  530. {
  531. #region 验证参数 必填项
  532. if (string.IsNullOrEmpty(input.F_Id))
  533. return Error("请选择条目");
  534. if (string.IsNullOrEmpty(input.F_RemarkKF))
  535. input.F_RemarkKF = "";
  536. if (string.IsNullOrEmpty(input.F_RemarkXS))
  537. input.F_RemarkXS = "";
  538. if (input.F_Money <= 0)
  539. return Error("请输入金额");
  540. #endregion
  541. T_Bus_OrderMoney modelOrderMoeny = await busOrderMoneyRepository.GetSingle(q => q.F_Id == input.F_Id);
  542. modelOrderMoeny.F_CheckUserId = UserLogin.UserId.ObjToInt();
  543. modelOrderMoeny.F_CheckUserName = UserLogin.UserName;
  544. modelOrderMoeny.F_Money = modelOrderMoeny.F_Money;
  545. modelOrderMoeny.F_State = input.F_State;
  546. modelOrderMoeny.F_RemarkKF = input.F_RemarkKF;
  547. if (modelOrderMoeny.F_State == 1)
  548. {
  549. T_Bus_Order modelOrder = await bus_OrderRepository.GetSingle(q => q.F_Id == modelOrderMoeny.F_OrderId);
  550. if (modelOrder.F_PayState == 1 || modelOrder.F_PayState == 3)
  551. {
  552. return Error("此单已结算!");
  553. }
  554. modelOrder.F_RealPrice = modelOrder.F_RealPrice + modelOrderMoeny.F_Money;
  555. if (modelOrder.F_PayState == 0)
  556. {
  557. if (modelOrder.F_ShouldPrice <= modelOrder.F_RealPrice)
  558. {
  559. //0待回款1已支付 2待退款3已退款
  560. modelOrder.F_PayState = 1;
  561. }
  562. }
  563. else if (modelOrder.F_PayState == 2)
  564. {
  565. if (modelOrder.F_ShouldPrice <= modelOrder.F_RealPrice)
  566. {
  567. //0待回款1已支付 2待退款3已退款
  568. modelOrder.F_PayState = 3;
  569. }
  570. }
  571. await bus_OrderRepository.UpdateListToColumns(new List<T_Bus_Order>() { modelOrder }, s => new { s.F_PayState, s.F_RealPrice });
  572. }
  573. if (await busOrderMoneyRepository.Update(modelOrderMoeny))
  574. return Success("成功!");
  575. return Error("失败!");
  576. }
  577. catch (Exception ex)
  578. { return Error(ex.Message); }
  579. }
  580. [HttpPost("ordermoney")]
  581. public async Task<IActionResult> OrderMoney(OrderMoneyInput input)
  582. {
  583. try
  584. {
  585. #region 验证参数 必填项
  586. if (string.IsNullOrEmpty(input.F_OrderId))
  587. return Error("请输入订单号");
  588. if (string.IsNullOrEmpty(input.F_PayUser))
  589. return Error("请输入打款人");
  590. if (string.IsNullOrEmpty(input.F_PayType))
  591. return Error("请输入打款方式");
  592. if (string.IsNullOrEmpty(input.F_RemarkKF))
  593. input.F_RemarkKF = "";
  594. if (string.IsNullOrEmpty(input.F_RemarkXS))
  595. input.F_RemarkXS = "";
  596. if (input.F_PayTime == null)
  597. return Error("请输入打款时间");
  598. if (input.F_Money >= 0)
  599. return Error("退款金额只能为负数");
  600. #endregion
  601. T_Bus_OrderMoney modelOrderMoeny = new T_Bus_OrderMoney();
  602. ModelConvertHelper<T_Bus_OrderMoney, OrderMoneyInput>.ModeToModelDefault(modelOrderMoeny, input);
  603. modelOrderMoeny.F_AddUserId = UserLogin.UserId.ObjToInt();
  604. modelOrderMoeny.F_UserName = UserLogin.UserName;
  605. modelOrderMoeny.F_Money = input.F_Money;
  606. modelOrderMoeny.F_MoneyBak = modelOrderMoeny.F_Money;
  607. modelOrderMoeny.F_State = 1;
  608. modelOrderMoeny.F_Id = Guid.NewGuid().ToString().Replace("-", "");
  609. T_Bus_Order modelOrder = await bus_OrderRepository.GetSingle(q => q.F_Id == modelOrderMoeny.F_OrderId);
  610. if (modelOrder.F_PayState == 1 || modelOrder.F_PayState == 3)
  611. {
  612. return Error("此单已结算!");
  613. }
  614. modelOrder.F_RealPrice = modelOrder.F_RealPrice + modelOrderMoeny.F_Money;
  615. if (modelOrder.F_PayState == 2)
  616. {
  617. if (modelOrder.F_ShouldPrice >= modelOrder.F_RealPrice)
  618. {
  619. //0待回款1已支付 2待退款3已退款
  620. modelOrder.F_PayState = 3;
  621. }
  622. }
  623. await bus_OrderRepository.UpdateListToColumns(new List<T_Bus_Order>() { modelOrder }, s => new { s.F_PayState, s.F_RealPrice });
  624. if (await busOrderMoneyRepository.AddReturnCount(modelOrderMoeny))
  625. return Success("成功!");
  626. return Error("失败!");
  627. }
  628. catch (Exception ex)
  629. { return Error(ex.Message); }
  630. }
  631. /// <summary>
  632. /// 根据分页获取售后列表 待退款 退货 仓库确认收到货 补差额 不需要仓库确认
  633. /// </summary>
  634. /// <param name="input"></param>
  635. /// <returns></returns>
  636. [HttpPost("getaftersalebypage")]
  637. public async Task<IActionResult> GetAfterSaleByPage(AfterSaleInput input)
  638. {
  639. #region 拼接条件
  640. 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);
  641. if (!string.IsNullOrEmpty(input.F_Id))
  642. {
  643. eq = eq.And(a => a.F_Id == input.F_Id);
  644. }
  645. if (input.F_State > 0)
  646. {
  647. eq = eq.And(a => a.F_State == input.F_State);
  648. }
  649. if (input.F_Type > 0)
  650. {
  651. eq = eq.And(a => a.F_Type == input.F_Type);
  652. }
  653. if (!string.IsNullOrEmpty(input.F_ReturnType))
  654. {
  655. eq = eq.And(a => a.F_ReturnType == input.F_ReturnType);
  656. }
  657. #endregion
  658. RefAsync<int> count = 0;
  659. PageData<T_Bus_AfterSale> list = await busAfterSaleRepository.GetListByPage(eq, new MyPageModel() { PageIndex = input.pageindex, PageSize = input.pagesize, PageCount = count }, " F_AddTime DESC");
  660. return Success("成功", list);
  661. }
  662. /// <summary>
  663. /// 更新售后退款状态
  664. /// </summary>
  665. /// <param name="input"></param>
  666. /// <returns></returns>
  667. [HttpPost("updatestate")]
  668. public async Task<IActionResult> UpdateState(AfterSaleInput input)
  669. {
  670. try
  671. {
  672. #region 验证参数 必填项
  673. if (string.IsNullOrEmpty(input.F_Id))
  674. return Error("请选择售后单");
  675. if (input.F_CheckTimeXS == null)
  676. return Error("请选择退款时间");
  677. if (input.F_State == 0)
  678. return Error("更新状态不正确");
  679. #endregion
  680. T_Bus_AfterSale modelAfterSale = await busAfterSaleRepository.GetSingle(q => q.F_Id == input.F_Id);
  681. if (modelAfterSale.F_State != 0)
  682. { return Error("此售后状态不支持退款"); }
  683. if (modelAfterSale.F_Type != 2 && modelAfterSale.F_Type != 3 && modelAfterSale.F_Type != 6)
  684. {
  685. return Error("售后类型不支持退款");
  686. }
  687. //1收到货(根据状态自动创建订单)2货物不符3未收到货
  688. if ((modelAfterSale.F_Type == 2 || modelAfterSale.F_Type == 3) && modelAfterSale.F_CheckStateKG != 1)
  689. {
  690. return Error("仓库暂未确认收到退货");
  691. }
  692. if (modelAfterSale.F_Money >= 0)
  693. {
  694. return Error("此金额不需要退款");
  695. }
  696. modelAfterSale.F_CheckTimeXS = input.F_CheckTimeXS;
  697. modelAfterSale.F_State = 1;
  698. if (await busAfterSaleRepository.Update(modelAfterSale))
  699. {
  700. return Success("成功");
  701. }
  702. return Error("失败,请重试!");
  703. }
  704. catch (Exception ex)
  705. { return Error(ex.Message); }
  706. }
  707. /// <summary>
  708. /// 根据订单获取相应支付记录
  709. /// </summary>
  710. /// <param name="input"></param>
  711. /// <returns></returns>
  712. [HttpPost("getordermoney")]
  713. public async Task<IActionResult> GetOrderMoneyList(OrderMoneyInput input)
  714. {
  715. if (string.IsNullOrEmpty(input.F_OrderId))
  716. {
  717. return Error("请输入订单号");
  718. }
  719. #region 拼接条件
  720. Expression<Func<T_Bus_OrderMoney, bool>> eq = a => a.F_OrderId== input.F_OrderId;
  721. #endregion
  722. List<T_Bus_OrderMoney> list = await busOrderMoneyRepository.GetListALL(eq,o=>o.F_AddTime,OrderByType.Asc);
  723. return Success("成功", list);
  724. }
  725. }
  726. }